From 7a15f3ad92fc092bc02784ff75804f95a0fd1d8b Mon Sep 17 00:00:00 2001 From: wangliwen Date: Mon, 11 Jul 2022 14:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E4=B8=80=E6=AC=A1=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=81=9A=E5=A5=BD=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AbilityCenterControllerV2.java | 129 +++++++++--------- .../dto/TAbilityApplicationDTO.java | 8 +- .../dto/TAbilityBatchApplicationDTO.java | 8 +- .../entity/TAbilityApplicationEntity.java | 12 ++ .../db/V3.3__ability_application_add_col.sql | 2 + .../processForm/TAbilityApplicationDao.xml | 117 ++++++++-------- 6 files changed, 152 insertions(+), 124 deletions(-) create mode 100644 renren-admin/src/main/resources/db/V3.3__ability_application_add_col.sql 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 index 7dd1f3af..86857649 100644 --- a/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterControllerV2.java +++ b/renren-admin/src/main/java/io/renren/common/controller/AbilityCenterControllerV2.java @@ -88,83 +88,84 @@ public class AbilityCenterControllerV2 { if (page.getTotal() <= 0) { // return new Result().error("联系管理员添加流程"); } + abilityBatchApplicationDTO.setApplyFlag(UUID.randomUUID().toString()); // 同一次的申请标识 + final Optional deptDTO = Optional.ofNullable(sysDeptService.getByName(bigDateDeptName)); final UserDetail user = SecurityUser.getUser(); - 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); - // v2 新增字段 - tAbilityApplicationDTO.setCameraList(index.get("cameraId")); - tAbilityApplicationDTO.setTitle(abilityBatchApplicationDTO.getTitle()); - tAbilityApplicationDTO.setApplicationBackground(abilityBatchApplicationDTO.getApplicationBackground()); - tAbilityApplicationDTO.setApplicationScene(abilityBatchApplicationDTO.getApplicationScene()); - tAbilityApplicationDTO.setApplicationSystem(abilityBatchApplicationDTO.getApplicationSystem()); - tAbilityApplicationDTO.setEffectWish(abilityBatchApplicationDTO.getEffectWish()); + 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); + // v2 新增字段 + tAbilityApplicationDTO.setCameraList(index.get("cameraId")); + tAbilityApplicationDTO.setTitle(abilityBatchApplicationDTO.getTitle()); + tAbilityApplicationDTO.setApplicationBackground(abilityBatchApplicationDTO.getApplicationBackground()); + tAbilityApplicationDTO.setApplicationScene(abilityBatchApplicationDTO.getApplicationScene()); + tAbilityApplicationDTO.setApplicationSystem(abilityBatchApplicationDTO.getApplicationSystem()); + tAbilityApplicationDTO.setEffectWish(abilityBatchApplicationDTO.getEffectWish()); - // 仿照请求接口 /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(ObjectUtil::isNotNull).collect(Collectors.toList()); // 申请入库 + // 归为同一次申请 + tAbilityApplicationDTO.setApplyFlag(abilityBatchApplicationDTO.getApplyFlag()); + + // 仿照请求接口 /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(ObjectUtil::isNotNull).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 && deptDTO.isPresent()) { // 资源不存在时 - return deptDTO.get().getId(); - } - return resourceDTO.getDeptId(); - })); // 按部门分组 + 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 && deptDTO.isPresent()) { // 资源不存在时 + return deptDTO.get().getId(); + } + return resourceDTO.getDeptId(); + })); // 按部门分组 temp.keySet().stream().distinct().forEach(deptId -> { if (deptId == 0L) { // 部门id不存在时 return; } - if (sysDeptService.get(deptId) == null) { // 部门不存在 + final SysDeptDTO sysDeptDTO = sysDeptService.get(deptId); + if (sysDeptDTO == null) { // 部门不存在 return; } List dtoList = temp.get(deptId); - Boolean basic_facilities = - dtoList.stream().map(index -> { - Optional resourceDTOOptional = - Optional.ofNullable(resourceService.get(Long.valueOf(index.getResourceId()))); // 从本库内查不到 视为其它平台的基础设施资源 - return !resourceDTOOptional.isPresent() || !"基础设施".equals(resourceDTOOptional.get().getType()); - } - ) - .filter(index -> !index).findAny().orElse(Boolean.TRUE); + + CompletableFuture.runAsync(() -> { + String[] sqls_ = dtoList.stream().map(index -> String.format("UPDATE t_ability_application SET resource_owner_dept = '%s' WHERE id = %s", JSON.toJSONString(sysDeptDTO), index.getId())).collect(Collectors.toList()).toArray(new String[dtoList.size()]); + jdbcTemplate.batchUpdate(sqls_); // 批量更新资源所属部门信息 + logger.info("批量更新申请的资源的部门信息完成"); + }, executor); + + Boolean basic_facilities = dtoList.stream().map(index -> { + Optional resourceDTOOptional = Optional.ofNullable(resourceService.get(Long.valueOf(index.getResourceId()))); // 从本库内查不到 视为其它平台的基础设施资源 + return !resourceDTOOptional.isPresent() || !"基础设施".equals(resourceDTOOptional.get().getType()); + }).filter(index -> !index).findAny().orElse(Boolean.TRUE); logger.error("--------------------是否全是基础设施{}----------------------------------------------", basic_facilities); final List ids = dtoList.stream().map(TAbilityApplicationDTO::getId).collect(Collectors.toList()); // 发起申请的表单id // 仿照请求接口 /act/running/startOfBusinessKey ProcessStartDTO processStartDTO = new ProcessStartDTO(); - processStartDTO.setBusinessKey(basic_facilities ? - tAbilityApplicationDTOList.stream() - .filter(index -> StringUtils.isNotEmpty(index.getResourceId())) - .map(TAbilityApplicationDTO::getResourceId) - .findFirst() - .orElse(null) - : JSON.toJSONString(ids)); // 申请的id列表 json字符 做businesskey + processStartDTO.setBusinessKey(basic_facilities ? tAbilityApplicationDTOList.stream().filter(index -> StringUtils.isNotEmpty(index.getResourceId())).map(TAbilityApplicationDTO::getResourceId).findFirst().orElse(null) : JSON.toJSONString(ids)); // 申请的id列表 json字符 做businesskey processStartDTO.setProcessDefinitionKey(key); //限定 AuditingBaseDTO auditingBaseDTO = new AuditingBaseDTO(); auditingBaseDTO.setCompleteEntry(Boolean.TRUE); // 首次录入 @@ -190,9 +191,7 @@ public class AbilityCenterControllerV2 { // 仿照请求接口 /processForm/tabilityapplication/updateInstanceId CompletableFuture.runAsync(() -> { if (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()]); + 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); } }, executor); diff --git a/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityApplicationDTO.java b/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityApplicationDTO.java index adf8abce..415ece77 100644 --- a/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityApplicationDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityApplicationDTO.java @@ -1,7 +1,7 @@ package io.renren.modules.processForm.dto; import io.renren.common.dto.AuditingBaseDTO; -import io.renren.modules.monitor.entity.CameraChannel; +import io.renren.modules.sys.dto.SysDeptDTO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -72,4 +72,10 @@ public class TAbilityApplicationDTO extends AuditingBaseDTO implements Serializa @ApiModelProperty(value = "能力应用期望效果") private String effectWish; + @ApiModelProperty(value = "申请单标识(同一次的申请标识)") + private String applyFlag; + + @ApiModelProperty(value = "资源所属部门信息") + private SysDeptDTO resourceOwnerDept; + } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityBatchApplicationDTO.java b/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityBatchApplicationDTO.java index 28b40edd..12bf7658 100644 --- a/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityBatchApplicationDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/processForm/dto/TAbilityBatchApplicationDTO.java @@ -1,7 +1,7 @@ package io.renren.modules.processForm.dto; import io.renren.common.dto.AuditingBaseDTO; -import io.renren.modules.monitor.entity.CameraChannel; +import io.renren.modules.sys.dto.SysDeptDTO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -66,4 +66,10 @@ public class TAbilityBatchApplicationDTO extends AuditingBaseDTO implements Seri @ApiModelProperty(value = "能力应用期望效果") private String effectWish; + + @ApiModelProperty(value = "申请单标识(同一次的申请标识)") + private String applyFlag; + + @ApiModelProperty(value = "资源所属部门信息") + private SysDeptDTO resourceOwnerDept; } diff --git a/renren-admin/src/main/java/io/renren/modules/processForm/entity/TAbilityApplicationEntity.java b/renren-admin/src/main/java/io/renren/modules/processForm/entity/TAbilityApplicationEntity.java index ed39ab73..2b3de010 100644 --- a/renren-admin/src/main/java/io/renren/modules/processForm/entity/TAbilityApplicationEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/processForm/entity/TAbilityApplicationEntity.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler; +import io.renren.modules.sys.dto.SysDeptDTO; import lombok.Data; import lombok.EqualsAndHashCode; @@ -126,4 +127,15 @@ public class TAbilityApplicationEntity implements Serializable { * 能力应用期望效果 */ private String effectWish; + + /** + * 申请单标识(同一次的申请标识) + */ + private String applyFlag; + + + /** + * 资源所属部门信息 + */ + private SysDeptDTO resourceOwnerDept; } \ No newline at end of file diff --git a/renren-admin/src/main/resources/db/V3.3__ability_application_add_col.sql b/renren-admin/src/main/resources/db/V3.3__ability_application_add_col.sql new file mode 100644 index 00000000..669350e0 --- /dev/null +++ b/renren-admin/src/main/resources/db/V3.3__ability_application_add_col.sql @@ -0,0 +1,2 @@ +alter table `t_ability_application` ADD COLUMN `apply_flag` varchar(255) NULL comment '申请单标识'; +alter table `t_ability_application` ADD COLUMN `resource_owner_dept` json NULL comment '资源所属部门信息'; \ No newline at end of file diff --git a/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml b/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml index 27f04274..f368e4d6 100644 --- a/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml +++ b/renren-admin/src/main/resources/mapper/processForm/TAbilityApplicationDao.xml @@ -23,6 +23,9 @@ + + @@ -49,73 +52,73 @@