-- 初始化任务表
TRUNCATE TABLE dd_case_task;

-- ---------1-任务表数据迁移------------------
INSERT INTO dd_case_task (
	task_uuid,
	case_info_id,
	dispatch_remark,
	dispatch_time,
	dispatch_type,
	loss_id,
	task_type,
	loss_name,
	loss_type,
	loss_desc,
	vehicle_modle,
	remark,
	linker_phone,
	loss_status,
	appoint_time,
	surveyor_name,
	surveyor_code,
	dispatcher_name,
	dispatcher_code,
	damage_place,
	damage_lng,
	damage_lat,
	resign_reason,
	linker_name,
	surveyor_receive_time,
	surveyor_contact_time,
	surveyor_arrive_time,
	surveyor_finish_time,
	is_company,
	tran_org_code,
	tran_org_name,
	resign_name,
	is_appoint,
	insurance_type,
	dispatch_start_time,
	cards_code,
	create_by,
	create_time,
	update_by,
	update_time
) SELECT
	ID,
	CASE_INFO_ID,
	DISPATCH_REMARK,
	DISPATCH_TIME,
	DISPATCH_TYPE,
	LOSS_ID,
	LOSS_NO,
	loss_name,
	loss_type,
	loss_desc,
	vehicleModle,
	remark,
	MOBILE,
	STATUS,
	SURVEY_DATE,
	SURVEY_NAME,
	SURVEY_NUMBER,
	YARDMAN_NAME,
	YARDMAN_NUMBER,
	SURVEY_PLACE,
	LONGITUDE,
	LATITUDE,
	REASON_ID,
	CONTACT,
	RECEIVE_TIME,
	CONTACT_TIME,
	ARRIVE_TIME,
	FINISH_TIME,
	IS_COMPANY,
	TRAN_COMPANY_ID,
	TRAN_COMPANY_NAME,
	reassignmentName,
	'0',
	'1',
	FIRST_DISPATCH_TIME,
	cardsCode,
	CREATE_BY,
	CREATE_TIME,
	UPDATE_BY,
	UPDATE_TIME
FROM
	sd_dispatch_item;
	
-- ------------------------------额外处理字段------------------------------

-- -----2-和案件表保持一致的字段---------------------
UPDATE dd_case_task t,
 dd_case_info c
SET t.regist_no = c.regist_no,
 t.org_code = c.org_code,
 t.org_name = c.org_name,
t.actual_org_code=c.actual_org_code,
t.actual_org_name=c.actual_org_name,
 t.report_time = c.report_time,
 t.insured_name = c.insured_name,
 t.insured_phone = c.insured_phone

WHERE
	t.case_info_id = c.case_info_id;

-- -----3-查勘员表相关字段
UPDATE dd_case_task t,
 dd_surveyor s
SET t.surveyor_tel = s.surveyor_tel,
 t.surveyor_org_code = s.org_code,
 t.surveyor_org_name = s.org_name

WHERE
	t.surveyor_code = s.surveyor_code;

-- --4-调度类型处理-------调度类型: 1-普通查勘 2-客户自助 3-转分公司 4-申请改派 5-取消
-- ------------调度类型 0:修理厂查勘 1：普通查勘 2：视频查勘 3：客户自助 4：预约 5:转分公司 10：申请改派 11：取消

-- ------客户自助-------
UPDATE dd_case_task t SET t.dispatch_type='2' WHERE t.dispatch_type='3';
-- ------申请改派-------
UPDATE dd_case_task t SET t.dispatch_type='4' WHERE t.dispatch_type='10';
-- ------客户自助-------
UPDATE dd_case_task t SET t.dispatch_type='5' WHERE t.dispatch_type='11';

-- ------5-定损任务字段统一-------
UPDATE dd_case_task t SET t.task_type='2' WHERE t.task_type='1';

-- -- 6-处理案件节点字段
UPDATE dd_case_info c , dd_case_task t SET c.claim_status='1' WHERE c.regist_no = t.regist_no AND t.loss_status='2';



-- ---------7-案件表申请改派标识处理-----------
UPDATE dd_case_info c  SET c.ressignment_flag='1' WHERE c.case_info_id in (
SELECT CASE_INFO_ID FROM sd_dispatch_item WHERE `STATUS`='3'
)


