-- 初始化围栏分组、围栏关系表
TRUNCATE TABLE dd_fence_group_fence;

-- ---------围栏分组、围栏关系表数据迁移------------------
INSERT INTO `dd_fence_group_fence` (
	`create_by`,
	`create_time`,
	`group_id`,
	`area_id`
)
SELECT
	CREATE_BY,CREATE_TIME,GROUP_ID,AREA_ID
FROM
	sd_areagroup_vs_area;

-- ------------------------------额外处理字段------------------------------
-- -----分组表主键、分组名称
UPDATE dd_fence_group_fence gf,dd_fence_group g SET gf.fence_group_id=g.fence_group_id,gf.fence_group_name=g.fence_group_name WHERE gf.group_id=g.old_id;

-- -----围栏主键、围栏名称

-- ------area_id字段处理，和sd_org_vs_area.area_id一致
UPDATE dd_fence_group_fence gf,sd_org_vs_area a SET gf.area_id=a.area_id  WHERE gf.area_id=a.id;

-- ------再次处理adcode字段
UPDATE dd_fence_group_fence gf,fenceinfor f SET gf.adcode = f.adcode WHERE gf.area_id=f.id;

-- ------根据adcode处理，更新dd_gis_fence的主键gis_fence_id、city_name
UPDATE dd_fence_group_fence gf,dd_gis_fence f SET gf.gis_fence_id = f.gis_fence_id,gf.city_name=f.city_name WHERE gf.adcode=f.adcode;