From 93585731f9801330a783c1b72429c7c8dda80f28 Mon Sep 17 00:00:00 2001 From: CMM <2198256324@qq.com> Date: Mon, 12 Jun 2023 18:20:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/scheduler/task/InitProcessTask.java | 2 +- .../pmapi/sys/controller/SysProcDefController.java | 9 +++ .../ningdatech/pmapi/sys/manage/MenuManage.java | 68 ++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java index 3ce7d96..1f5c602 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java @@ -52,7 +52,7 @@ public class InitProcessTask { @Value("${hostname}") private String HOST_NAME; - @Scheduled(cron = "0 30 18 12 6 ?") + @Scheduled(cron = "0 10 18 12 6 ?") public void doTask() throws UnknownHostException { if (HOST_NAME.equals(InetAddress.getLocalHost().getHostName())) { log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务开始"); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcDefController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcDefController.java index 72b31d6..efc6ab1 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcDefController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/SysProcDefController.java @@ -3,6 +3,7 @@ package com.ningdatech.pmapi.sys.controller; import com.ningdatech.basic.model.PageVo; import com.ningdatech.log.annotation.WebLog; import com.ningdatech.pmapi.projectdeclared.manage.DefaultDeclaredProjectManage; +import com.ningdatech.pmapi.sys.manage.MenuManage; import com.wflow.bean.dto.WflowModelHistorysDto; import com.wflow.bean.vo.WflowModelVo; import com.wflow.service.ModelGroupService; @@ -35,6 +36,7 @@ public class SysProcDefController { private final ProcessModelService processModelService; private final DefaultDeclaredProjectManage defaultDeclaredProjectManage; + private final MenuManage menuManage; @ApiOperation(value = "系统流程配置列表", notes = "系统流程配置列表") @GetMapping("/list") @@ -70,4 +72,11 @@ public class SysProcDefController { public String deploy(@Validated @PathVariable String formId) { return processModelService.deployProcess(formId,null); } + + @ApiOperation(value = "流程初始化", notes = "流程初始化") + @PostMapping("/process/init") + @WebLog("系统流程初始化") + public String processInit() { + return menuManage.init(); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java index 8a3621d..8f6a694 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java @@ -1,14 +1,31 @@ package com.ningdatech.pmapi.sys.manage; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.StopWatch; +import cn.hutool.core.util.IdUtil; +import com.alibaba.fastjson.JSON; +import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.util.CollUtils; import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.common.constant.RegionConst; +import com.ningdatech.pmapi.common.enumeration.ProjectProcessStageEnum; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity; import com.ningdatech.pmapi.common.util.TreeUtil; +import com.ningdatech.pmapi.scheduler.contants.TaskContant; +import com.ningdatech.pmapi.sys.model.dto.RegionDTO; import com.ningdatech.pmapi.sys.model.entity.Menu; import com.ningdatech.pmapi.sys.model.vo.MenuRoleVO; import com.ningdatech.pmapi.sys.service.IMenuService; +import com.ningdatech.pmapi.sys.service.IRegionService; +import com.wflow.bean.dto.WflowModelHistorysInsertDto; +import com.wflow.workflow.bean.process.ProcessNode; +import com.wflow.workflow.service.ProcessModelService; +import com.wflow.workflow.service.WflowFormsService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import java.util.*; @@ -24,9 +41,12 @@ import java.util.stream.Collectors; */ @Component @RequiredArgsConstructor +@Slf4j public class MenuManage { private final IMenuService menuService; + private final ProcessModelService processModelService; + private final RegionCacheHelper regionCacheHelper; public List buildUserMenu(List list) { Set menuIds = new HashSet<>(); @@ -62,4 +82,52 @@ public class MenuManage { parentMenuCheck(tmpPidList, menuRoles, menuIds); } + public String init() { + log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务开始"); + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + //1.查出丽水市下的 区县 分别去初始化 表单和流程配置数据 + List regions = regionCacheHelper.listChildren(RegionConst.RC_LS, RegionConst.RL_CITY); + + if(CollUtil.isEmpty(regions)){ + throw new BizException("丽水地区数据为空 任务结束!"); + } + + for(RegionDTO region : regions){ + log.info("当前初始化的是 【{}】 流程配置",region.getRegionName()); + + Integer[] processTypeList = TaskContant.Wflow.APPLY_PROCESS_TYPE_LIST; + for(Integer processType : processTypeList){ + String formName = ProjectProcessStageEnum.getDesc(processType); + WflowModelHistorysInsertDto models = new WflowModelHistorysInsertDto(); + + models.setGroupId(1); + models.setProcessDefId("pd" + IdUtil.objectId()); + models.setFormName(formName); + models.setProcessType(processType); + models.setRegionCode(region.getRegionCode()); + String process = "{\"children\":{\"children\":{},\"id\":\"node_039152532706\",\"name\":\"审批人\",\"parentId\":\"root\",\"props\":{\"mode\":\"AND\",\"role\":[],\"refuse\":{\"type\":\"TO_END\",\"target\":\"\"},\"assignedOrg\":[{\"orgName\":\"数转办\",\"orgCode\":\"GO_3bc86256687a4884ae410af00682b762\",\"type\":\"DEFAULT\",\"processDefId\":\"\"}],\"sign\":false,\"assignedType\":\"ASSIGN_ORG\",\"assignedDept\":[]},\"type\":\"SUB\"},\"id\":\"root\",\"name\":\"发起人\",\"props\":{\"formPerms\":[],\"assignedUser\":[]},\"type\":\"ROOT\"}"; + ProcessNode processNode = JSON.parseObject(process,ProcessNode.class); + models.setProcess(processNode); + models.setSettings("{\"sign\":false,\"admin\":[],\"notify\":{},\"commiter\":[]}"); + models.setFormItems("[]"); + + String formId = processModelService.insertProcess(models); + if(StringUtils.isNotBlank(formId)){ + //初始的流程在部署表也存一份,用来查询 + if(StringUtils.isNotBlank(processModelService.deployProcess(formId,null))){ + log.info("当前区域 【{}】 流程名[{}] 流程数据已经保存成功",region.getRegionName(),formName); + }else{ + log.info("当前区域 【{}】 流程名[{}] 流程数据保存失败",region.getRegionName(),formName); + } + }else{ + log.info("当前区域 【{}】流程名[{}] 流程数据保存失败",region.getRegionName(),formName); + } + } + } + + stopWatch.stop(); + log.info("=========== 初始化丽水二期 系统表单和流程配置 ======== 任务结束 {}s",stopWatch.getTotalTimeSeconds()); + return "初始化完成"; + } }