增加批量发起能力申请时按部门发起批量审核流程
This commit is contained in:
parent
9a6358bd5d
commit
e2036397cf
|
@ -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<String, Object> params = new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put("isLatestVersion", true); // 取最新版本
|
||||||
|
put("key", key); // 限定
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量进行批量能力申请(按资源所属部门分配审核人)
|
||||||
|
*
|
||||||
|
* @param abilityBatchApplicationDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/apply")
|
||||||
|
@ApiOperation("批量进行能力申请")
|
||||||
|
public Result<List<ProcessInstanceDTO>> applyV2(@RequestBody TAbilityBatchApplicationDTO abilityBatchApplicationDTO) {
|
||||||
|
// 仿照请求接口 /act/process/lastestPage
|
||||||
|
PageData<Map<String, Object>> page = actProcessService.page(params);
|
||||||
|
if (page.getTotal() <= 0) { //
|
||||||
|
return new Result().error("联系管理员添加流程");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
// 仿照请求接口 /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<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) { // 资源不存在时
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return resourceDTO.getDeptId();
|
||||||
|
})); // 按部门分组
|
||||||
|
temp.keySet().stream().distinct().forEach(deptId -> {
|
||||||
|
if (deptId == 0L) { // 部门不存在时
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<TAbilityApplicationDTO> dtoList = temp.get(deptId);
|
||||||
|
List<Long> 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<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); // 归属部门
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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("");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue