-- 初始化调度历史表
TRUNCATE TABLE dd_case_dispatch;

-- ---------调度历史表数据迁移------------------

INSERT INTO `dd_case_dispatch` (
	`regist_no`,
	`dispatch_time`,
	`dispatcher_name`,
	`dispatcher_code`,
	`dispatch_remark`,
	`dispatch_type`,
	`dispatch_num`,
	`dispatch_desc`,
	`dispatch_result`,
	`loss_id`,
	`linker_name`,
	`linker_phone`,
	`surveyor_name`,
	`surveyor_code`,
	`surveyor_tel`,
	`damage_place`,
	`insurance_type`,
	`create_by`,
	`create_time`,
	`update_by`,
	`update_time`
) SELECT
	CASE_INFO_ID,
	CREATE_TIME,
	DISPATCH_NAME,
	CREATE_BY,
	DISPATCH_REMARK,
	'1',
	DISPATCH_NUM,
	DISPATCH_DESC,
	RESULT,
	LOSS_ID,
	CLIENT_NAME,
	CLIENT_MOBILE,
	SURVEY_NAME,
	SURVEY_ID,
	MOBILE,
	SURVEY_PLACE,
	'1',
	CREATE_BY,
	CREATE_TIME,
	UPDATE_BY,
	UPDATE_TIME
FROM
	sd_case_dispatch;
	
-- ------------------------------额外处理字段------------------------------

-- ------------------------------1-和案件表保持一致的字段------------------------------
-- -----报案号——regist_no
UPDATE dd_case_dispatch h,dd_case_info c SET h.regist_no = c.regist_no WHERE h.regist_no=c.case_info_id;
-- -----报案时间、机构编码、机构名称——report_time、org_code、org_name
UPDATE dd_case_dispatch h,
 dd_case_info c
SET h.report_time = c.report_time,
h.org_code=c.org_code,
h.org_name=c.org_name

WHERE
	h.regist_no = c.regist_no;

-- ------------------------------2-和任务表保持一致的字段------------------------------
UPDATE dd_case_dispatch h,
 dd_case_task t
SET h.task_type = t.task_type,
h.loss_name = t.loss_name,
h.loss_type=t.loss_type

WHERE
	h.regist_no = t.regist_no
AND h.loss_id = t.loss_id ;


-- ------------------------------3-和查勘员表保持一致的字段------------------------------
-- -----1.查勘员工号——surveyor_code
UPDATE dd_case_dispatch h,
 sd_survey s
SET h.surveyor_code = s.USER_CODE

WHERE
	h.surveyor_code = s.ID;
-- -----2.查勘员其他字段——surveyor_tel、surveyor_org_code、surveyor_org_name
UPDATE dd_case_dispatch h,
 dd_surveyor s
SET h.surveyor_org_code = s.org_code,
h.surveyor_org_name = s.org_name

WHERE
	h.surveyor_code = s.surveyor_code;
	

	
-- --------调度类型dispatch_type处理（不做处理，仅做展示，默认都显示为普通查勘）-------------
-- ---旧数据码值------------调度类型 0:修理厂查勘 1：普通查勘 2：视频查勘 3：客户自助 4：预约 5:转分公司 10：申请改派\r\n11：查勘
-- ---新数据码值------------调度类型 1-普通查勘 2-客户自助 3-转分公司 4-申请改派 5-取消




