From e2036397cf58c32bfeb8c6ca5516989292522d0b Mon Sep 17 00:00:00 2001 From: wangliwen Date: Sun, 26 Jun 2022 13:35:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E5=8F=91?= =?UTF-8?q?=E8=B5=B7=E8=83=BD=E5=8A=9B=E7=94=B3=E8=AF=B7=E6=97=B6=E6=8C=89?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=8F=91=E8=B5=B7=E6=89=B9=E9=87=8F=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AbilityCenterControllerV2.java | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 renren-admin/src/main/java/io/renren/common/controller/AbilityCenterControllerV2.java diff --git a/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterControllerV2.java b/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterControllerV2.java new file mode 100644 index 00000000..e149adc5 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterControllerV2.java @@ -0,0 +1,162 @@ +package io.renren.common.controller; + + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import io.renren.common.dto.AuditingBaseDTO; +import io.renren.common.page.PageData; +import io.renren.common.utils.Result; +import io.renren.common.validator.ValidatorUtils; +import io.renren.common.validator.group.AddGroup; +import io.renren.common.validator.group.DefaultGroup; +import io.renren.modules.activiti.dto.ProcessInstanceDTO; +import io.renren.modules.activiti.dto.ProcessStartDTO; +import io.renren.modules.activiti.service.ActProcessService; +import io.renren.modules.activiti.service.ActRunningService; +import io.renren.modules.processForm.dto.TAbilityApplicationDTO; +import io.renren.modules.processForm.dto.TAbilityBatchApplicationDTO; +import io.renren.modules.processForm.service.TAbilityApplicationService; +import io.renren.modules.resource.dto.ResourceDTO; +import io.renren.modules.resource.service.ResourceService; +import io.renren.modules.security.user.SecurityUser; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.codehaus.jackson.map.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +/** + * 能力集中中心 接口 + */ + +@Api(tags = "能力集中") +@RestController +@RequestMapping("/ability/center/v2") +public class AbilityCenterControllerV2 { + private static Logger logger = LoggerFactory.getLogger(AbilityCenterController.class); + @Autowired + private ActProcessService actProcessService; + @Autowired + private TAbilityApplicationService tAbilityApplicationService; + @Autowired + private ActRunningService actRunningService; + @Autowired + private ResourceService resourceService; + @Autowired + private JdbcTemplate jdbcTemplate; + private static String key = "abilityprocess_v2"; + + private static Map params = new HashMap() { + { + put("isLatestVersion", true); // 取最新版本 + put("key", key); // 限定 + } + }; + + /** + * 批量进行批量能力申请(按资源所属部门分配审核人) + * + * @param abilityBatchApplicationDTO + * @return + */ + @PostMapping(value = "/apply") + @ApiOperation("批量进行能力申请") + public Result> applyV2(@RequestBody TAbilityBatchApplicationDTO abilityBatchApplicationDTO) { + // 仿照请求接口 /act/process/lastestPage + PageData> page = actProcessService.page(params); + if (page.getTotal() <= 0) { // + return new Result().error("联系管理员添加流程"); + } + List tAbilityApplicationDTOList = + abilityBatchApplicationDTO.getSystem().stream().map(index -> { + if (tAbilityApplicationService.countUserResourceApply(SecurityUser.getUserId(), Long.valueOf(index.get("resourceId"))) > 0) { // 防止重复发起申请 + logger.error("重复发起申请"); + return null; + } + TAbilityApplicationDTO tAbilityApplicationDTO = new TAbilityApplicationDTO(); + tAbilityApplicationDTO.setArea(abilityBatchApplicationDTO.getArea()); + tAbilityApplicationDTO.setAttachment(abilityBatchApplicationDTO.getAttachment()); + tAbilityApplicationDTO.setBasis(abilityBatchApplicationDTO.getBasis()); + tAbilityApplicationDTO.setPhone(abilityBatchApplicationDTO.getPhone()); + tAbilityApplicationDTO.setScene(abilityBatchApplicationDTO.getScene()); + tAbilityApplicationDTO.setInstanceId(abilityBatchApplicationDTO.getInstanceId()); + tAbilityApplicationDTO.setUnit(abilityBatchApplicationDTO.getUnit()); + tAbilityApplicationDTO.setUser(abilityBatchApplicationDTO.getUser()); + tAbilityApplicationDTO.setResourceId(index.get("resourceId")); + tAbilityApplicationDTO.setUser(abilityBatchApplicationDTO.getUser()); + tAbilityApplicationDTO.setSystem(index.get("resourceName")); + tAbilityApplicationDTO.setEnclosure(abilityBatchApplicationDTO.getEnclosure()); // 附件 + tAbilityApplicationDTO.setUserId(abilityBatchApplicationDTO.getUserId()); + tAbilityApplicationDTO.setApproveStatus("审核中"); + tAbilityApplicationDTO.setDelFlag(0); + // 仿照请求接口 /processForm/tabilityapplication + ValidatorUtils.validateEntity(tAbilityApplicationDTO, AddGroup.class, DefaultGroup.class); + tAbilityApplicationService.save(tAbilityApplicationDTO); // 写能力申请数据 + if (tAbilityApplicationDTO.getId() == null) { + return null; + } + tAbilityApplicationDTO.setCompleteEntry(Boolean.TRUE); + return tAbilityApplicationDTO; + }).filter(index -> ObjectUtil.isNotNull(index)).collect(Collectors.toList()); // 申请入库 + if (!tAbilityApplicationDTOList.isEmpty()) { + Map> temp = + tAbilityApplicationDTOList.stream().filter(index -> StringUtils.isNotEmpty(index.getResourceId())).collect(Collectors.groupingBy(t -> { + ResourceDTO resourceDTO = resourceService.get(Long.valueOf(t.getResourceId())); + if (resourceDTO == null) { // 资源不存在时 + return 0L; + } + return resourceDTO.getDeptId(); + })); // 按部门分组 + temp.keySet().stream().distinct().forEach(deptId -> { + if (deptId == 0L) { // 部门不存在时 + return; + } + List dtoList = temp.get(deptId); + List ids = dtoList.stream().map(index -> index.getId()).collect(Collectors.toList()); + // 仿照请求接口 /act/running/startOfBusinessKey + ProcessStartDTO processStartDTO = new ProcessStartDTO(); + processStartDTO.setBusinessKey(JSON.toJSONString(ids)); // 申请的id列表 json字符 做businesskey + processStartDTO.setProcessDefinitionKey(key); //限定 + AuditingBaseDTO auditingBaseDTO = new AuditingBaseDTO(); + auditingBaseDTO.setCompleteEntry(Boolean.TRUE); // 首次录入 + ObjectMapper oMapper = new ObjectMapper(); + Map variables = oMapper.convertValue(auditingBaseDTO, Map.class); + + variables.putAll(new HashMap() { // 流程内携带属性值 + { + put("tAbilityApplicationDTOList", dtoList); // 归属该部门的申请 + put("key", processStartDTO.getBusinessKey()); // 归属该部门申请的表单id + put("deptId", deptId); // 归属部门 + } + }); + + processStartDTO.setVariables(variables); + ProcessInstanceDTO dto = actRunningService.startOfBusinessKey(processStartDTO); + + // 仿照请求接口 /processForm/tabilityapplication/updateInstanceId + CompletableFuture.runAsync(() -> { + if (Long.valueOf(dto.getBusinessKey()) != null) { + String[] sqls = + dtoList.stream().map(i -> String.format("UPDATE t_ability_application SET instance_id = %s WHERE id = %s", dto.getProcessInstanceId(), i.getId())) + .collect(Collectors.toList()).toArray(new String[dtoList.size()]); + jdbcTemplate.batchUpdate(sqls); + } + }); + }); + } + return new Result().ok(""); + } +}