-- 排班信息表
TRUNCATE TABLE dd_scheduling;

-- ---------排班表数据迁移------------------
INSERT INTO `dd_scheduling` (
	`org_branch_name`,
	`org_middle_branch_name`,
	`fence_name`,
	`fence_code`,
	`surveyor_code`,
	`shift_no`,
	`shift_name`,
	`day_date`,
	`month_date`,
	`year_date`,
	`work_date`,
	`scheduling_type`,
	`scheduling_type_code`,
	`is_enable`,
	`survey_car_roll`,
	`scheduling_table_type`,
	`survey_type`,
	`create_by`,
	`create_time`,
	`update_by`,
	`update_time`
) SELECT
	child_company,
	branch,
	AREA_NAME,
	AREA_CODE,
	PROVIDE_ID,
	SHIFT_NUM,
	SHIFT_NAME,
	DAY_DATE,
	MONTH_DATE,
	YEAR_DATE,
	WORK_DATE,
	'车物',
	'0',
	IS_ENABLE,
	'0',
	'1',
	'0',
	CREATE_BY,
	CREATE_DATE,
	UPDATE_BY,
	UPDATE_DATE
FROM
	sd_scheduling_table WHERE WORK_DATE>='2023-06-01';


-- ------------------------------额外处理字段------------------------------

-- -----分公司编码——org_branch_code
UPDATE dd_scheduling s ,sys_dept d
SET org_branch_code = d.dept_code
WHERE s.org_branch_name = d.dept_name;

-- -----中支编码——org_branch_code
UPDATE dd_scheduling s ,sys_dept d
SET org_middle_branch_code = d.dept_code
WHERE s.org_middle_branch_name = d.dept_name;

-- -----查勘员表相关字段
UPDATE dd_scheduling t ,sd_survey s
SET t.surveyor_code = s.USER_CODE,
t.surveyor_name = s.`NAME`
WHERE t.surveyor_code = s.ID;

UPDATE dd_scheduling t ,dd_surveyor s
SET t.org_code = s.org_code,
t.org_name = s.org_name
WHERE t.surveyor_code = s.surveyor_code;

-- -----班次表相关字段
UPDATE dd_scheduling t ,dd_scheduling_shift s
SET t.shift_no = s.scheduling_shift_id,
t.shift_time_begin = s.shift_time_begin,
t.shift_time_end = s.shift_time_end
WHERE t.shift_no = s.shift_id;


-- -----围栏相关字段------------
-- ---------1.将fence_code值更新为adcode
UPDATE dd_scheduling s ,fenceinfor f
SET s.fence_code = f.adcode
WHERE s.fence_code = f.id;

-- -- ---------2.通过adcode将fence_code值更新新围栏表的主键
UPDATE dd_scheduling s ,dd_gis_fence f
SET s.fence_code = f.gis_fence_id
WHERE s.fence_code = f.adcode;


























