-- 初始化案件表
TRUNCATE TABLE dd_case_info;

-- ---------案件表数据迁移------------------
INSERT INTO dd_case_info (
	case_info_id,
	subrogation,
	linker_name,
	linker_phone,
	damage_time,
	damage_place,
	damage_remark,
	informant,
	informant_phone,
	is_lock,
	license_no,
	is_appoint,
	report_time,
	regist_no,
	case_status,
	survey_time,
	damage_lng,
	damage_lat,
	survey_place,
	fence_id,
	survey_lat,
	survey_lng,
	insured_name,
	driver_name,
	driver_phone,
	insurance_type,
	report_type,
	delegate_mode,
	appoint_time,
	is_auto_dispatch,
	damage_province,
	damage_city,
	damage_district,
	video_user,
	video_user_name,
	sponsor_type,
	is_auto_video_flag,
	seat_code,
	forecast_case_no,
	is_new_policy_flag,
	is_black_list,
	black_list_type,
	black_list_type_desc,
	is_yzt,
	judge_charging,
	fence_org_code,
	fence_org_name,
	actual_org_code,
	actual_org_name,
	vin,
	black_list_spcustnme,
	black_list_insurednme,
	black_list_empcnm,
	black_list_empmobile,
	deal_type,
	has_commit_video,
	policy_hold_name,
	security_type,
	security_no,
	insured_addr,
	create_by,
	create_time,
	update_by,
	update_time
) SELECT
	ID,
	BEHALFTHE,
	CONTACT,
	CONTACT_PHONE,
	DAMAGE_DATE,
	DAMAGE_PLACE,
	DAMAGE_REMARK,
	INFORMANT,
	INFORMANT_PHONE,
	IS_LOCK,
	LICENSE_NO,
	'0',
	REGIST_DATE,
	REGIST_NO,
	`STATUS`,
	SURVEY_DATE,
	SURVEY_LNG,
	SURVEY_LAT,
	SURVEY_PLACE,
	SURVEY_PLACE_ID,
	SURVEY_LAT,
	SURVEY_LNG,
	USER_NAME,
	DRIVERNAME,
	DRIVERPHONE,
	isVehicleInsurance,
	reportType,
	delegateMode,
	appointTime,
	isautodispatch,
	damageProvince,
	damageCity,
	damageDistrict,
	videoUser,
	videoUserName,
	sponsor_type,
	isAutoVideoFlag,
	agentUserCode,
	forecastCaseNo,
	is_new_policy_flag,
	is_black_list,
	black_list_type,
	black_list_type_desc,
	is_yzt,
	judge_charging,
	survey_place_org_id,
	survey_place_org_Name,
	orgcode_orig,
	orig_name,
	vin,
	black_list_spcustnme,
	black_list_insurednme,
	black_list_empcnm,
	black_list_empmobile,
	deal_type,
	has_commit_video,
	policy_hold_name,
	security_type,
	security_no,
	insured_addr,
	CREATE_BY,
	CREATE_TIME,
	UPDATE_BY,
	UPDATE_TIME
FROM
	sd_case_info;
	
	
-- ------------------------------额外处理字段------------------------------

-- -----1-机构编码——org_code
UPDATE dd_case_info SET org_code = LEFT(actual_org_code,2);
-- -----2-机构名称——org_name
UPDATE dd_case_info c,sys_dept d SET c.org_name=d.dept_name WHERE c.org_code=d.dept_code;

-- -----3-案件节点——claim_status-----------数据修正：1-未调度 2- 已调度 6-完成 99-注销
-- ---案件节点（与理赔同步）：0-未调度 1-已调度未查勘 2-查勘中 3-定损中 4-定损完成 5-整案核损完成 6-结案 99-注销

UPDATE dd_case_info c
SET claim_status = '0'
WHERE
	1 = 1
AND case_status = '1';


UPDATE dd_case_info c
SET claim_status = '2'
WHERE
	1 = 1
AND case_status = '2';

UPDATE dd_case_info c
SET claim_status = '5',
 case_status = '2'
WHERE
	1 = 1
AND case_status = '6';


UPDATE dd_case_info c
SET claim_status = '99'
WHERE
	1 = 1
AND case_status = '99';



