Merge branch 'master' into docker_package

This commit is contained in:
wangliwen 2022-07-18 16:37:08 +08:00
commit 869e3c9d4c
2 changed files with 14 additions and 110 deletions

View File

@ -109,115 +109,7 @@ public class AbilityCenterControllerV2 {
abilityBatchApplicationDTO.setApplyFlag(applyFlag); // 同一次的申请标识
final Optional<SysDeptDTO> deptDTO = Optional.ofNullable(sysDeptService.getByName(bigDateDeptName));
final UserDetail user = SecurityUser.getUser();
List<TAbilityApplicationDTO> 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") == null ? null : JSON.toJSONString(index.get("cameraId")));
tAbilityApplicationDTO.setTitle(abilityBatchApplicationDTO.getTitle());
tAbilityApplicationDTO.setApplicationBackground(abilityBatchApplicationDTO.getApplicationBackground());
tAbilityApplicationDTO.setApplicationScene(abilityBatchApplicationDTO.getApplicationScene());
tAbilityApplicationDTO.setApplicationSystem(abilityBatchApplicationDTO.getApplicationSystem());
tAbilityApplicationDTO.setEffectWish(abilityBatchApplicationDTO.getEffectWish());
tAbilityApplicationDTO.setEnclosureName(abilityBatchApplicationDTO.getEnclosureName());
tAbilityApplicationDTO.setCreateDate(new Date());
// 归为同一次申请
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()) {
codeGenerationUtils.setApplyNumber("NLSY", tAbilityApplicationDTOList.stream().map(TAbilityApplicationDTO::getId).collect(Collectors.toList()), jdbcTemplate);
Map<Long, List<TAbilityApplicationDTO>> 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;
}
final SysDeptDTO sysDeptDTO = sysDeptService.get(deptId);
if (sysDeptDTO == null) { // 部门不存在
return;
}
List<TAbilityApplicationDTO> dtoList = temp.get(deptId);
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<ResourceDTO> 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<Long> 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.setProcessDefinitionKey(key); //限定
AuditingBaseDTO auditingBaseDTO = new AuditingBaseDTO();
auditingBaseDTO.setCompleteEntry(Boolean.TRUE); // 首次录入
Map<String, Object> variables = oMapper.convertValue(auditingBaseDTO, Map.class);
variables.putAll(new HashMap<String, Object>() { // 流程内携带属性值
{
put("tAbilityApplicationDTOList", dtoList); // 归属该部门的申请
put("key", processStartDTO.getBusinessKey()); // 归属该部门申请的表单id
put("deptId", deptId); // 归属部门
put("id", applyFlag); //申请id
put("creator", user == null ? null : user.getId().toString()); // 创建人
put("userId", user == null ? null : user.getId().toString()); // 创建人
put("basic_facilities", basic_facilities); // 是否为基础设施
}
});
processStartDTO.setVariables(variables);
ProcessInstanceDTO dto = actRunningService.startOfBusinessKey(processStartDTO);
// 仿照请求接口 /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()]);
jdbcTemplate.batchUpdate(sqls);
}
}, executor);
});
}
deal(abilityBatchApplicationDTO, deptDTO, applyFlag, user);
return new Result().ok(LocalDateTime.now().toString());
}
@ -238,6 +130,11 @@ public class AbilityCenterControllerV2 {
final Optional<SysDeptDTO> deptDTO = Optional.ofNullable(sysDeptService.getByName(bigDateDeptName));
final UserDetail user = SecurityUser.getUser();
deal(abilityBatchApplicationDTO, deptDTO, applyFlag, user);
return new Result().ok(LocalDateTime.now().toString());
}
private void deal(TAbilityBatchApplicationDTO abilityBatchApplicationDTO, Optional<SysDeptDTO> deptDTO, String applyFlag, UserDetail user) {
List<TAbilityApplicationDTO> tAbilityApplicationDTOList = abilityBatchApplicationDTO.getSystem().stream().map(index -> {
if (tAbilityApplicationService.countUserResourceApply(SecurityUser.getUserId(), Long.valueOf(index.get("resourceId"))) > 0) { // 防止重复发起申请
logger.error("重复发起申请");
@ -347,6 +244,5 @@ public class AbilityCenterControllerV2 {
}, executor);
});
}
return new Result().ok(LocalDateTime.now().toString());
}
}

View File

@ -33,6 +33,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -73,6 +75,8 @@ public class TAbilityApplicationController {
private CameraChannelMapper cameraChannelMapper;
@Autowired
private SysDeptService sysDeptService;
@Autowired
protected RuntimeService runtimeService;
@Value("${project.place}")
private Integer projectPlace;
@ -120,6 +124,10 @@ public class TAbilityApplicationController {
}
});
}
ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(inStanceId + "").singleResult();
if (execution != null) {
index.setEnded(execution.isEnded()); // 流程引擎内是否已结束
}
return index;
}).collect(Collectors.toList());
page.setList(list);