-- 菜单 SQL
-- 广西执行
INSERT INTO `config` ( `key`, `value`, `name`, `active`, `create_time`, `update_time`, `update_by`) VALUES ( 'LEGALCHANGETITLE', '保安服务许可证项目变更审核', '变更名称', '', '2021-09-10 16:50:17', '2021-09-10 16:52:34', 'gx_super');

INSERT INTO`module_menu` (`id`, `active`, `createTime`, `updateTime`, `updateBy`, `location`, `name`, `parentId`, `seq`, `menuType`, `description`, `iconClass`, `iconCls`, `permission`, `parentIds`, `uniqueId`, `intranetFlag`, `superAdmin`, `platform`, `rankAuth`) VALUES ('885829565465223168', '', '2020-07-20 16:48:31', '2021-09-10 10:10:04', 'gx_super', 'trainChange/list/index.do', '保安培训备案项目变更审核', '694571326551097344', '25', '0', NULL, NULL, NULL, 'trainChange:query', '694538890723196928/694571326551097344/885829565465223168/', 'trainChangeList', '2', '0', '1', '0');
INSERT INTO `module_menu` (`id`, `active`, `createTime`, `updateTime`, `updateBy`, `location`, `name`, `parentId`, `seq`, `menuType`, `description`, `iconClass`, `iconCls`, `permission`, `parentIds`, `uniqueId`, `intranetFlag`, `superAdmin`, `platform`, `rankAuth`) VALUES ('885829565472092160', '', '2020-07-20 16:48:31', '2020-07-20 16:48:31', 'system', NULL, '查询', '885829565465223168', '10000', '1', NULL, NULL, NULL, 'trainChange:query', '694538890723196928/694571326551097344/885829565465223168/885829565472092160/', NULL, '2', '0', '1', '0');
INSERT INTO `module_menu` (`id`, `active`, `createTime`, `updateTime`, `updateBy`, `location`, `name`, `parentId`, `seq`, `menuType`, `description`, `iconClass`, `iconCls`, `permission`, `parentIds`, `uniqueId`, `intranetFlag`, `superAdmin`, `platform`, `rankAuth`) VALUES ('885829565482848256', '', '2020-07-20 16:48:31', '2020-07-20 16:48:31', 'system', NULL, '查看', '885829565465223168', '10000', '1', NULL, NULL, NULL, 'trainChange:view', '694538890723196928/694571326551097344/885829565465223168/885829565482848256/', NULL, '2', '0', '1', '0');
INSERT INTO `module_menu` (`id`, `active`, `createTime`, `updateTime`, `updateBy`, `location`, `name`, `parentId`, `seq`, `menuType`, `description`, `iconClass`, `iconCls`, `permission`, `parentIds`, `uniqueId`, `intranetFlag`, `superAdmin`, `platform`, `rankAuth`) VALUES ('885829565490388992', '', '2020-07-20 16:48:31', '2020-07-20 16:48:31', 'system', NULL, '导出', '885829565465223168', '10000', '1', NULL, NULL, NULL, 'trainChange:export', '694538890723196928/694571326551097344/885829565465223168/885829565490388992/', NULL, '2', '0', '1', '0');
INSERT INTO `module_menu` (`id`, `active`, `createTime`, `updateTime`, `updateBy`, `location`, `name`, `parentId`, `seq`, `menuType`, `description`, `iconClass`, `iconCls`, `permission`, `parentIds`, `uniqueId`, `intranetFlag`, `superAdmin`, `platform`, `rankAuth`) VALUES ('885829565497257984', '', '2020-07-20 16:48:31', '2020-07-20 16:48:31', 'system', NULL, '打印详细', '885829565465223168', '10000', '1', NULL, NULL, NULL, 'trainChange:printDetail', '694538890723196928/694571326551097344/885829565465223168/885829565497257984/', NULL, '1', '0', '1', '0');
INSERT INTO `module_menu` (`id`, `active`, `createTime`, `updateTime`, `updateBy`, `location`, `name`, `parentId`, `seq`, `menuType`, `description`, `iconClass`, `iconCls`, `permission`, `parentIds`, `uniqueId`, `intranetFlag`, `superAdmin`, `platform`, `rankAuth`) VALUES ('885829565508014080', '', '2020-07-20 16:48:31', '2020-07-20 16:48:31', 'system', NULL, '打印处理签', '885829565465223168', '10000', '1', NULL, NULL, NULL, 'trainChange:printHandle', '694538890723196928/694571326551097344/885829565465223168/885829565508014080/', NULL, '1', '0', '1', '0');

INSERT INTO `sys_dict` ( `isActive`, `updateTime`, `updateflag`, `codeType`, `tableName`, `description`, `codeValue`, `label`, `seq`)
VALUES ('1', '2020-10-28 13:38:35', '', 'businessType', NULL, '业务类型', '013', '保安培训单位项目变更', '13');


insert into approve_temp (active, create_time, update_time, update_by, tempName, tempCode, iconUrl, approveType,
                          effectTime, failureTime, approveSetStatus, noticeTemp, repulseExplain, seq, approveGroupId,
                          policeId, parentPoliceId, parentTempId)
values (true, now(), now(), 'system', '保安培训单位项目变更', 'activitiTrainChangeapprovalProcess', '\\assets\\images\\ba.jpg', null, null, null, 0, null, null,
        '7', '100001', '1',
        null, null);

set @id = @@IDENTITY;


# insert into approve_temp (active, create_time, update_time, update_by, tempName, tempCode, iconUrl, approveType,
#                           effectTime, failureTime, approveSetStatus, noticeTemp, repulseExplain, seq, approveGroupId,
#                           policeId, parentPoliceId, parentTempId)
# select true, now(), now(), 'system', '保安培训单位项目变更',
#        CONCAT('activitiTrainChangeapprovalProcess-',areacode), '\\assets\\images\\ba.jpg', null, null, null, 0, null, null, 10, 100001, id,
#        1, @id
# from police where active=true and orgtype=2;



INSERT INTO `approve_temp_link_rela` ( `active`, `create_time`, `update_time`, `update_by`, `approveTempId`, `approveLinkId`, `seq`, `linkSetStatus`, `createType`, `updateflag`)
select true, now(), NULL, NULL, t3.id, t2.approveLinkId, t2.`seq`, t2.`linkSetStatus`, t2.`createType`, t2.`updateflag`
from approve_temp t1,approve_temp_link_rela t2,approve_temp t3
where t1.tempCode like 'activitilegalchangeapprovalProcess'
  and t1.active=true
  and t1.id= t2.approveTempId and t2.active=TRUE
  and t3.tempCode like 'activitiTrainChangeapprovalProcess'
  and t3.active=true and t1.policeId = t3.policeId;

INSERT INTO `approve_link_level` ( `active`, `create_time`, `update_time`, `update_by`, `approveLevel`, `parentId`, `tempLinkRelaId`, `updateflag`)
select true,now(),now(), NULL, t5.`approveLevel`, t5.`parentId`, t4.id, t5.`updateflag`
from approve_temp t1,approve_temp_link_rela t2,
     approve_temp t3,approve_temp_link_rela t4,
     approve_link_level t5
where t1.tempCode like 'activitilegalchangeapprovalProcess'
  and t1.active=true
  and t1.id= t2.approveTempId and t2.active=TRUE
  and t3.tempCode like 'activitiTrainChangeapprovalProcess'
  and t3.active=true and t1.policeId = t3.policeId
  and t3.id= t4.approveTempId and t4.active=TRUE
  and t2.approveLinkId = t4.approveLinkId
  and t2.id= t5.tempLinkRelaId and t5.active=true;


INSERT INTO approve_area_process (active,create_time,update_time,approveSetStatus,regionLevel,regionId,approveLinkLevelId,policeCode,policeId,updateflag,path)
SELECT true,SYSDATE(),SYSDATE(),t7.approveSetStatus,t7.regionLevel,t7.regionId,t6.id,t7.policeCode,t7.policeId,t7.updateflag,t7.path
from approve_temp t1,approve_temp_link_rela t2,
     approve_temp t3,approve_temp_link_rela t4,
     approve_link_level t5,approve_link_level t6,
     approve_area_process t7
where t1.tempCode like 'activitilegalchangeapprovalProcess'
  and t1.active=true
  and t1.id= t2.approveTempId and t2.active=TRUE
  and t3.tempCode like 'activitiTrainChangeapprovalProcess'
  and t3.active=true and t1.policeId = t3.policeId
  and t3.id= t4.approveTempId and t4.active=TRUE
  and t2.approveLinkId = t4.approveLinkId
  and t2.id= t5.tempLinkRelaId and t5.active=true
  and t4.id= t6.tempLinkRelaId and t6.active=true
  and t5.id = t7.approveLinkLevelId and t7.active=true;

INSERT INTO `approve_link_pro_detail`
( `active`, `create_time`, `update_time`, `regionLevel`, `regionId`, `approveAreaProId`, `tempLinkRelaId`, `policeId`, `policeCode`)
select true,now(),now(),t9.`regionLevel`, t9.`regionId`, t8.id, t4.id, t9.`policeId`, t9.`policeCode`
from approve_temp t1,approve_temp_link_rela t2,
     approve_temp t3,approve_temp_link_rela t4,
     approve_link_level t5,approve_link_level t6,
     approve_area_process t7,approve_area_process t8,
     approve_link_pro_detail t9
where t1.tempCode like 'activitilegalchangeapprovalProcess'
  and t1.active=true
  and t1.id= t2.approveTempId and t2.active=TRUE
  and t3.tempCode like 'activitiTrainChangeapprovalProcess'
  and t3.active=true and t1.policeId = t3.policeId
  and t3.id= t4.approveTempId and t4.active=TRUE
  and t2.approveLinkId = t4.approveLinkId
  and t2.id= t5.tempLinkRelaId and t5.active=true
  and t4.id= t6.tempLinkRelaId and t6.active=true
  and t5.id = t7.approveLinkLevelId and t7.active=true
  and t6.id = t8.approveLinkLevelId and t8.active=true
  and t7.policeId = t8.policeId
  and t7.id = t9.approveAreaProId
  and t2.id=t9.tempLinkRelaId and t9.active=true;

INSERT INTO `approve_area_pro_detail` ( `active`, `create_time`, `update_time`, `approveRank`,`positionName`, `approveAreaProId`)
select true, now(), now(),t9.`approveRank`,t9.`positionName`, t8.id
from approve_temp t1,approve_temp_link_rela t2,
     approve_temp t3,approve_temp_link_rela t4,
     approve_link_level t5,approve_link_level t6,
     approve_area_process t7,approve_area_process t8,
     approve_area_pro_detail t9
where t1.tempCode like 'activitilegalchangeapprovalProcess'
  and t1.active=true
  and t1.id= t2.approveTempId and t2.active=TRUE
  and t3.tempCode like 'activitiTrainChangeapprovalProcess'
  and t3.active=true and t1.policeId = t3.policeId
  and t3.id= t4.approveTempId and t4.active=TRUE
  and t2.approveLinkId = t4.approveLinkId
  and t2.id= t5.tempLinkRelaId and t5.active=true
  and t4.id= t6.tempLinkRelaId and t6.active=true
  and t5.id = t7.approveLinkLevelId and t7.active=true
  and t6.id = t8.approveLinkLevelId and t8.active=true
  and t7.policeId = t8.policeId
  and t7.id = t9.approveAreaProId
  and t9.active=true;


INSERT INTO `approve_area_pro_detail_per` (`approveAreaProDetailId`, `approvePerId`, `active`, `create_time`, `update_time`,`seq`)
select t10.id,t11.approvePerId,true,now(),now(),1
from approve_temp t1,approve_temp_link_rela t2,
     approve_temp t3,approve_temp_link_rela t4,
     approve_link_level t5,approve_link_level t6,
     approve_area_process t7,approve_area_process t8,
     approve_area_pro_detail t9,approve_area_pro_detail t10,
     approve_area_pro_detail_per t11
where t1.tempCode like 'activitilegalchangeapprovalProcess'
  and t1.active=true
  and t1.id= t2.approveTempId and t2.active=TRUE
  and t3.tempCode like 'activitiTrainChangeapprovalProcess'
  and t3.active=true and t1.policeId = t3.policeId
  and t3.id= t4.approveTempId and t4.active=TRUE
  and t2.approveLinkId = t4.approveLinkId
  and t2.id= t5.tempLinkRelaId and t5.active=true
  and t4.id= t6.tempLinkRelaId and t6.active=true
  and t5.id = t7.approveLinkLevelId and t7.active=true
  and t6.id = t8.approveLinkLevelId and t8.active=true
  and t7.policeId = t8.policeId
  and t7.id = t9.approveAreaProId
  and t9.active=true
  and t8.id = t10.approveAreaProId
  and t10.active=true
  and t9.positionName = t10.positionName
  and t9.id = t11.approveAreaProDetailId and t11.active=true;


#
# INSERT INTO `approve_temp_link_rela` ( `active`, `create_time`, `update_time`, `update_by`, `approveTempId`, `approveLinkId`, `seq`, `linkSetStatus`, `createType`, `updateflag`)
# select true, now(), NULL, NULL, t3.id, t2.approveLinkId, t2.`seq`, t2.`linkSetStatus`, t2.`createType`, t2.`updateflag`
# from approve_temp t1,approve_temp_link_rela t2,approve_temp t3
# where t1.tempCode like 'activitilegalchangeapprovalProcess-%'
#   and t1.active=true
#   and t1.id= t2.approveTempId and t2.active=TRUE
#   and t3.tempCode like 'activitiTrainChangeapprovalProcess-%'
#   and t3.active=true and t1.policeId = t3.policeId;
#
# INSERT INTO `approve_link_level` ( `active`, `create_time`, `update_time`, `update_by`, `approveLevel`, `parentId`, `tempLinkRelaId`, `updateflag`)
# select true,now(),now(), NULL, t5.`approveLevel`, t5.`parentId`, t4.id, t5.`updateflag`
# from approve_temp t1,approve_temp_link_rela t2,
#      approve_temp t3,approve_temp_link_rela t4,
#      approve_link_level t5
# where t1.tempCode like 'activitilegalchangeapprovalProcess-%'
#   and t1.active=true
#   and t1.id= t2.approveTempId and t2.active=TRUE
#   and t3.tempCode like 'activitiTrainChangeapprovalProcess-%'
#   and t3.active=true and t1.policeId = t3.policeId
#   and t3.id= t4.approveTempId and t4.active=TRUE
#   and t2.approveLinkId = t4.approveLinkId
#   and t2.id= t5.tempLinkRelaId and t5.active=true;
#
#
# INSERT INTO approve_area_process (active,create_time,update_time,approveSetStatus,regionLevel,regionId,approveLinkLevelId,policeCode,policeId,updateflag,path)
# SELECT true,SYSDATE(),SYSDATE(),t7.approveSetStatus,t7.regionLevel,t7.regionId,t6.id,t7.policeCode,t7.policeId,t7.updateflag,t7.path
# from approve_temp t1,approve_temp_link_rela t2,
#      approve_temp t3,approve_temp_link_rela t4,
#      approve_link_level t5,approve_link_level t6,
#      approve_area_process t7
# where t1.tempCode like 'activitilegalchangeapprovalProcess-%'
#   and t1.active=true
#   and t1.id= t2.approveTempId and t2.active=TRUE
#   and t3.tempCode like 'activitiTrainChangeapprovalProcess-%'
#   and t3.active=true and t1.policeId = t3.policeId
#   and t3.id= t4.approveTempId and t4.active=TRUE
#   and t2.approveLinkId = t4.approveLinkId
#   and t2.id= t5.tempLinkRelaId and t5.active=true
#   and t4.id= t6.tempLinkRelaId and t6.active=true
#   and t5.id = t7.approveLinkLevelId and t7.active=true;
#
# INSERT INTO `approve_link_pro_detail`
# ( `active`, `create_time`, `update_time`, `regionLevel`, `regionId`, `approveAreaProId`, `tempLinkRelaId`, `policeId`, `policeCode`)
# select true,now(),now(),t9.`regionLevel`, t9.`regionId`, t8.id, t4.id, t9.`policeId`, t9.`policeCode`
# from approve_temp t1,approve_temp_link_rela t2,
#      approve_temp t3,approve_temp_link_rela t4,
#      approve_link_level t5,approve_link_level t6,
#      approve_area_process t7,approve_area_process t8,
#      approve_link_pro_detail t9
# where t1.tempCode like 'activitilegalchangeapprovalProcess-%'
#   and t1.active=true
#   and t1.id= t2.approveTempId and t2.active=TRUE
#   and t3.tempCode like 'activitiTrainChangeapprovalProcess-%'
#   and t3.active=true and t1.policeId = t3.policeId
#   and t3.id= t4.approveTempId and t4.active=TRUE
#   and t2.approveLinkId = t4.approveLinkId
#   and t2.id= t5.tempLinkRelaId and t5.active=true
#   and t4.id= t6.tempLinkRelaId and t6.active=true
#   and t5.id = t7.approveLinkLevelId and t7.active=true
#   and t6.id = t8.approveLinkLevelId and t8.active=true
#   and t7.policeId = t8.policeId
#   and t7.id = t9.approveAreaProId
#   and t2.id=t9.tempLinkRelaId and t9.active=true;
#
# INSERT INTO `approve_area_pro_detail` ( `active`, `create_time`, `update_time`, `approveRank`,`positionName`, `approveAreaProId`)
# select true, now(), now(),t9.`approveRank`,t9.`positionName`, t8.id
# from approve_temp t1,approve_temp_link_rela t2,
#      approve_temp t3,approve_temp_link_rela t4,
#      approve_link_level t5,approve_link_level t6,
#      approve_area_process t7,approve_area_process t8,
#      approve_area_pro_detail t9
# where t1.tempCode like 'activitilegalchangeapprovalProcess-%'
#   and t1.active=true
#   and t1.id= t2.approveTempId and t2.active=TRUE
#   and t3.tempCode like 'activitiTrainChangeapprovalProcess-%'
#   and t3.active=true and t1.policeId = t3.policeId
#   and t3.id= t4.approveTempId and t4.active=TRUE
#   and t2.approveLinkId = t4.approveLinkId
#   and t2.id= t5.tempLinkRelaId and t5.active=true
#   and t4.id= t6.tempLinkRelaId and t6.active=true
#   and t5.id = t7.approveLinkLevelId and t7.active=true
#   and t6.id = t8.approveLinkLevelId and t8.active=true
#   and t7.policeId = t8.policeId
#   and t7.id = t9.approveAreaProId
#   and t9.active=true;
#
#
# INSERT INTO `approve_area_pro_detail_per` (`approveAreaProDetailId`, `approvePerId`, `active`, `create_time`, `update_time`,`seq`)
# select t10.id,t11.approvePerId,true,now(),now(),1
# from approve_temp t1,approve_temp_link_rela t2,
#      approve_temp t3,approve_temp_link_rela t4,
#      approve_link_level t5,approve_link_level t6,
#      approve_area_process t7,approve_area_process t8,
#      approve_area_pro_detail t9,approve_area_pro_detail t10,
#      approve_area_pro_detail_per t11
# where t1.tempCode like 'activitilegalchangeapprovalProcess-%'
#   and t1.active=true
#   and t1.id= t2.approveTempId and t2.active=TRUE
#   and t3.tempCode like 'activitiTrainChangeapprovalProcess-%'
#   and t3.active=true and t1.policeId = t3.policeId
#   and t3.id= t4.approveTempId and t4.active=TRUE
#   and t2.approveLinkId = t4.approveLinkId
#   and t2.id= t5.tempLinkRelaId and t5.active=true
#   and t4.id= t6.tempLinkRelaId and t6.active=true
#   and t5.id = t7.approveLinkLevelId and t7.active=true
#   and t6.id = t8.approveLinkLevelId and t8.active=true
#   and t7.policeId = t8.policeId
#   and t7.id = t9.approveAreaProId
#   and t9.active=true
#   and t8.id = t10.approveAreaProId
#   and t10.active=true
#   and t9.positionName = t10.positionName
#   and t9.id = t11.approveAreaProDetailId and t11.active=true;
#
#
#

INSERT INTO `module_permission` (`active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, `moduleMenuId`)
select `active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, 885829565465223168
from module_permission where moduleMenuId=732607109371265024 and active=1;
INSERT INTO `module_permission` (`active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, `moduleMenuId`)
select `active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, 885829565472092160
from module_permission where moduleMenuId=733352416837107712 and active=1;
INSERT INTO `module_permission` (`active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, `moduleMenuId`)
select `active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, 885829565482848256
from module_permission where moduleMenuId=733352417218789376 and active=1;
INSERT INTO `module_permission` (`active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, `moduleMenuId`)
select `active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, 885829565490388992
from module_permission where moduleMenuId=733352417604665344 and active=1;
INSERT INTO `module_permission` (`active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, `moduleMenuId`)
select `active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, 885829565497257984
from module_permission where moduleMenuId=733352418376417280 and active=1;
INSERT INTO `module_permission` (`active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, `moduleMenuId`)
select `active`, `updateflag`, `create_time`, `update_time`, `update_by`, `roleId`, 885829565508014080
from module_permission where moduleMenuId=733352418804236288 and active=1;