|
@@ -1,7 +1,9 @@
|
|
|
package org.springblade.business.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -13,6 +15,7 @@ import org.springblade.business.entity.FixedFlowLink;
|
|
|
import org.springblade.business.entity.Task;
|
|
|
import org.springblade.business.service.IFixedFlowLinkService;
|
|
|
import org.springblade.business.service.IFixedFlowService;
|
|
|
+import org.springblade.business.service.impl.TaskServiceImpl;
|
|
|
import org.springblade.business.vo.FixedFlowVO;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
@@ -32,7 +35,9 @@ import org.springblade.manager.vo.RoleSignPfxUserVO;
|
|
|
import org.springblade.manager.vo.RoleSignPfxUserVO1;
|
|
|
import org.springblade.manager.vo.RoleSignPfxUserVO2;
|
|
|
import org.springblade.manager.vo.RoleSignPfxUserVO3;
|
|
|
+import org.springblade.meter.dto.PageFixedFlowDTO;
|
|
|
import org.springblade.meter.dto.SaveFixedFlowDTO;
|
|
|
+import org.springblade.meter.dto.UpdateFixedFlowDTO;
|
|
|
import org.springblade.system.feign.ISysClient;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
import org.springblade.system.user.feign.IUserClient;
|
|
@@ -40,6 +45,7 @@ import org.springblade.system.vo.RoleVO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -74,6 +80,8 @@ public class FixedFlowController extends BladeController {
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
private final ProjectClient projectClient;
|
|
|
+
|
|
|
+ private final TaskServiceImpl taskServiceImpl;
|
|
|
/**
|
|
|
* 获取系统所有角色划分
|
|
|
*/
|
|
@@ -473,4 +481,218 @@ public class FixedFlowController extends BladeController {
|
|
|
return R.fail("操作失败");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 自定义分页
|
|
|
+ */
|
|
|
+ @GetMapping("/getFixedFlowPage")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入fixedFlow")
|
|
|
+ public List<Map<String, Object>> getFixedFlowPage(PageFixedFlowDTO dto) {
|
|
|
+ Page<FixedFlow> page = new Page<>(dto.getCurrent(), dto.getSize());
|
|
|
+ IPage<FixedFlow> fixedFlowsPage = fixedFlowService.getBaseMapper().selectPage(page,
|
|
|
+ Wrappers.<FixedFlow>lambdaQuery()
|
|
|
+ .eq(FixedFlow::getContractId, dto.getContractId())
|
|
|
+ .eq(FixedFlow::getProjectId, dto.getProjectId()).last(" and (is_meter is null or is_meter != 1)"));
|
|
|
+ List<FixedFlow> fixedFlows = fixedFlowsPage.getRecords();
|
|
|
+ List<Long> collect = fixedFlows.stream().map(FixedFlow::getId).collect(Collectors.toList());
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
+ List<FixedFlowLink> fixedFlowLinkList = fixedFlowLinkService.getBaseMapper().selectList(
|
|
|
+ Wrappers.<FixedFlowLink>lambdaQuery()
|
|
|
+ .isNotNull(FixedFlowLink::getFixedFlowLink)
|
|
|
+ .in(FixedFlowLink::getFixedFlowId, collect)
|
|
|
+ .orderByAsc(FixedFlowLink::getFixedFlowBranchSort)
|
|
|
+ .orderByAsc(FixedFlowLink::getFixedFlowLinkSort)
|
|
|
+ );
|
|
|
+ Map<Long, List<FixedFlowLink>> group = fixedFlowLinkList.stream()
|
|
|
+ .collect(Collectors.groupingBy(FixedFlowLink::getFixedFlowId,
|
|
|
+ LinkedHashMap::new,
|
|
|
+ Collectors.toList()));
|
|
|
+ //获取当前任务中所有的流程,并且去重,如果该流程已经存在,那么则不允许编辑和删除
|
|
|
+ List<Long> ids = taskServiceImpl.list(new LambdaQueryWrapper<Task>()
|
|
|
+ .select(Task::getFixedFlowId)
|
|
|
+ .eq(Task::getContractId, dto.getContractId())
|
|
|
+ .isNotNull(Task::getFixedFlowId)
|
|
|
+ .groupBy(Task::getFixedFlowId)).stream().map(Task::getFixedFlowId).collect(Collectors.toList());
|
|
|
+ List<Map<String, Object>> result = new LinkedList<>();
|
|
|
+ for (FixedFlow fixedFlow : fixedFlows) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<FixedFlowLink> one = group.getOrDefault(fixedFlow.getId(), null);
|
|
|
+ if (one != null) {
|
|
|
+ /** 上面方法会去除同名流程*/
|
|
|
+ List<String> names = one.stream().filter(l->l.getFixedFlowLinkSort() != null).collect(Collectors.groupingBy(
|
|
|
+ FixedFlowLink::getFixedFlowLinkSort,
|
|
|
+ Collectors.collectingAndThen(
|
|
|
+ Collectors.toList(),
|
|
|
+ l -> l.isEmpty() ? null : l.get(0)
|
|
|
+ )
|
|
|
+ )).values().stream().map(FixedFlowLink::getFixedFlowLink).collect(Collectors.toList());
|
|
|
+ map.put("id", fixedFlow.getId());
|
|
|
+ map.put("isUse", ids.contains(fixedFlow.getId()) ? 1 : 0);
|
|
|
+ map.put("fixedFlowName", fixedFlow.getFixedFlowName());
|
|
|
+ map.put("linkUserJoinString", StringUtils.join(names, ","));
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ @GetMapping("/getFixedFlow")
|
|
|
+ @ApiOperationSupport(order = 25)
|
|
|
+ @ApiOperation(value = "获取预设流程信息", notes = "传入预设流程id")
|
|
|
+ public R<org.springblade.meter.vo.FixedFlowVO> getFixedFlow(@RequestParam String id) {
|
|
|
+ FixedFlow fixedFlow = jdbcTemplate.query("SELECT * FROM u_fixed_flow WHERE is_deleted = 0 AND id = ?", new Object[]{id}, new BeanPropertyRowMapper<>(FixedFlow.class)).stream().findAny().orElse(null);
|
|
|
+ if (fixedFlow != null) {
|
|
|
+ List<FixedFlowLink> fixedFlowLinkList = jdbcTemplate.query("SELECT * FROM u_fixed_flow_link WHERE is_deleted = 0 AND fixed_flow_id = ? ORDER BY fixed_flow_branch_sort,fixed_flow_link_sort", new Object[]{fixedFlow.getId()}, new BeanPropertyRowMapper<>(FixedFlowLink.class));
|
|
|
+ if (fixedFlowLinkList.size() > 0) {
|
|
|
+ Map<String, List<FixedFlowLink>> group = fixedFlowLinkList.stream().collect(Collectors.groupingBy(
|
|
|
+ obj -> obj.getFixedFlowLink() + "@@@" + obj.getFixedFlowLinkType() + "@@@"+obj.getFlowTaskType() + "@@@"+obj.getFixedFlowLinkSort(),
|
|
|
+ LinkedHashMap::new,
|
|
|
+ Collectors.toList())
|
|
|
+ );
|
|
|
+
|
|
|
+ org.springblade.meter.vo.FixedFlowVO vo = new org.springblade.meter.vo.FixedFlowVO();
|
|
|
+ vo.setFixedFlowId(fixedFlow.getId());
|
|
|
+ vo.setFixedFlowName(fixedFlow.getFixedFlowName());
|
|
|
+
|
|
|
+ List<org.springblade.meter.vo.FixedFlowVO.FixedBranchVO> fixedBranchVOList = new LinkedList<>();
|
|
|
+ for (Map.Entry<String, List<FixedFlowLink>> listEntry : group.entrySet()) {
|
|
|
+
|
|
|
+ String nameAndType = listEntry.getKey();
|
|
|
+ String name = nameAndType.split("@@@")[0];
|
|
|
+ String type = nameAndType.split("@@@")[1];
|
|
|
+ String flowTaskType = nameAndType.split("@@@")[2];
|
|
|
+
|
|
|
+ org.springblade.meter.vo.FixedFlowVO.FixedBranchVO fixedBranchVO = new org.springblade.meter.vo.FixedFlowVO.FixedBranchVO();
|
|
|
+ fixedBranchVO.setName(name);
|
|
|
+ fixedBranchVO.setType(Integer.parseInt(type));
|
|
|
+ fixedBranchVO.setFlowTaskType(Integer.valueOf(flowTaskType));
|
|
|
+
|
|
|
+ List<org.springblade.meter.vo.FixedFlowVO.FixedBranchVO.User> userListResult = new LinkedList<>();
|
|
|
+ List<FixedFlowLink> userList = listEntry.getValue();
|
|
|
+ for (FixedFlowLink fixedFlowLink : userList) {
|
|
|
+ org.springblade.meter.vo.FixedFlowVO.FixedBranchVO.User user = new org.springblade.meter.vo.FixedFlowVO.FixedBranchVO.User();
|
|
|
+ user.setUserId(fixedFlowLink.getFixedFlowLinkUser());
|
|
|
+ user.setUserName(fixedFlowLink.getFixedFlowLinkUserName());
|
|
|
+ user.setSort(ObjectUtil.isNotEmpty(fixedFlowLink.getFixedFlowLinkSort()) ? fixedFlowLink.getFixedFlowLinkSort() : null);
|
|
|
+ userListResult.add(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ fixedBranchVO.setUserList(userListResult);
|
|
|
+ fixedBranchVO.setUserIds(userListResult.stream().map(l->l.getUserId()+"").collect(Collectors.joining(",")));
|
|
|
+ fixedBranchVOList.add(fixedBranchVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setFixedBranchVOList(fixedBranchVOList);
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/updateFixedFlow")
|
|
|
+ @ApiOperationSupport(order = 26)
|
|
|
+ @ApiOperation(value = "修改预设流程", notes = "传入dto")
|
|
|
+ @Transactional(isolation = Isolation.READ_COMMITTED)
|
|
|
+ public R<Object> updateFixedFlow(@RequestBody UpdateFixedFlowDTO dto) {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getFixedBranchList()) || dto.getFixedBranchList().isEmpty()) {
|
|
|
+ return R.fail("请选择任务流程人员");
|
|
|
+ }
|
|
|
+ //校验是否被使用过
|
|
|
+ List<Task> tasks = jdbcTemplate.query("SELECT * FROM u_task WHERE contract_id = ? and is_deleted = 0 and status != 3 AND fixed_flow_id = ? ", new Object[]{dto.getContractId(), dto.getFixedFlowId()}, new BeanPropertyRowMapper<>(Task.class));
|
|
|
+ if (!tasks.isEmpty()) {
|
|
|
+ return R.fail("当前流程已经使用,不能修改");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getFixedName())) {
|
|
|
+ ProjectInfo projectInfo = projectClient.getById(dto.getProjectId() + "");
|
|
|
+ if (projectInfo == null) {
|
|
|
+ return R.fail("暂未找到项目信息,请稍后再试");
|
|
|
+ }
|
|
|
+ /*检查签字证书信息*/
|
|
|
+ List<String> userIds = dto.getFixedBranchList().stream().map(UpdateFixedFlowDTO.FixedBranch::getUserIds).collect(Collectors.toList());
|
|
|
+ List<User> users = jdbcTemplate.query("select id,name,acc_code,real_name from blade_user where is_deleted = 0 and id in (" + StringUtils.join(userIds, ",") + ")", new BeanPropertyRowMapper<>(User.class));
|
|
|
+ Map<Long, User> userMap = users.stream().collect(Collectors.toMap(User::getId, item -> item));
|
|
|
+ if (ObjectUtil.isEmpty( users)) {
|
|
|
+ return R.fail("请选择任务流程人员");
|
|
|
+ }
|
|
|
+ if (Objects.equals(projectInfo.getRemarkType(), 1)) {
|
|
|
+ //安心签,校验证书 检查签字证书信息
|
|
|
+ Set<String> notCertificateUserInfoSet = new HashSet<>();
|
|
|
+ //获取用户的证书信息
|
|
|
+ String ids = users.stream().map(user -> user.getId() + "").collect(Collectors.joining(","));
|
|
|
+ List<SignPfxFile> signPfxFiles = jdbcTemplate.query("select * from m_sign_pfx_file where is_register = 1 and certificate_user_id in ( " + ids + " )", new BeanPropertyRowMapper<>(SignPfxFile.class));
|
|
|
+ Map<String, List<SignPfxFile>> collect = signPfxFiles.stream().collect(Collectors.groupingBy(signPfxFile -> signPfxFile.getCertificateUserId() + ""));
|
|
|
+ for (String userId : userIds) {
|
|
|
+ List<SignPfxFile> userPfxList = collect.get(userId);
|
|
|
+ if (userPfxList == null || userPfxList.isEmpty()) {
|
|
|
+ notCertificateUserInfoSet.add(userId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!notCertificateUserInfoSet.isEmpty()) {
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
+ for (String userId : notCertificateUserInfoSet) {
|
|
|
+ User user = userMap.get(Long.parseLong(userId));
|
|
|
+ if (user != null && user.getName() != null && !user.getName().isEmpty()) {
|
|
|
+ names.add(user.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new ServiceException("未获取到用户【" + StringUtils.join(names, "、") + "】的签字证书信息");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 东方中讯,校验用户 accCode
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
+ for (User user : users) {
|
|
|
+ if (user.getAccCode() == null || user.getAccCode().isEmpty() || user.getAccCode().equals("null")) {
|
|
|
+ names.add(user.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!names.isEmpty()) {
|
|
|
+ throw new ServiceException("未获取到用户【" + StringUtils.join(names, "、") + "】的签字证书信息");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jdbcTemplate.update("DELETE FROM u_fixed_flow_link WHERE fixed_flow_id = ? ", dto.getFixedFlowId());
|
|
|
+ int userSort = 0;
|
|
|
+ for (int i = 0; i < dto.getFixedBranchList().size(); i++) {
|
|
|
+ UpdateFixedFlowDTO.FixedBranch fixedBranch = dto.getFixedBranchList().get(i);
|
|
|
+ if (i > 0) {
|
|
|
+ userSort += Func.toLongList(dto.getFixedBranchList().get(i - 1).getUserIds()).size();
|
|
|
+ }
|
|
|
+ List<FixedFlowLink> saveList = new ArrayList<>();
|
|
|
+ for (String userId : userIds) {
|
|
|
+ FixedFlowLink fixedFlowLink = new FixedFlowLink();
|
|
|
+ fixedFlowLink.setFixedFlowId(dto.getFixedFlowId());
|
|
|
+ fixedFlowLink.setFixedFlowLink(fixedBranch.getName());
|
|
|
+ fixedFlowLink.setFixedFlowLinkType(fixedBranch.getType());
|
|
|
+ fixedFlowLink.setFixedFlowLinkUser(Long.parseLong(userId));
|
|
|
+ fixedFlowLink.setFixedFlowLinkUserName(userMap.get(Long.parseLong(userId)).getRealName());
|
|
|
+ fixedFlowLink.setFixedFlowLinkSort(i + 1);
|
|
|
+ fixedFlowLink.setProjectId(dto.getProjectId());
|
|
|
+ fixedFlowLink.setContractId(dto.getContractId());
|
|
|
+ fixedFlowLink.setFixedFlowBranchSort(userSort+=1);
|
|
|
+ fixedFlowLink.setFlowTaskType(fixedBranch.getFlowTaskType());
|
|
|
+ saveList.add(fixedFlowLink);
|
|
|
+ }
|
|
|
+ if (!saveList.isEmpty()) {
|
|
|
+ fixedFlowLinkService.saveBatch(saveList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fixedFlowService.update(Wrappers.<FixedFlow>lambdaUpdate().set(FixedFlow::getFixedFlowName, dto.getFixedName()).eq(FixedFlow::getId, dto.getFixedFlowId()));
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+ return R.fail("操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/deleteFixedFlow")
|
|
|
+ @ApiOperationSupport(order = 27)
|
|
|
+ @ApiOperation(value = "刪除预设流程", notes = "传入预设流程id")
|
|
|
+ public R<Object> deleteFixedFlow(@RequestParam String id) {
|
|
|
+ List<Task> tasks = jdbcTemplate.query("SELECT * FROM u_task WHERE is_deleted = 0 and status != 3 AND fixed_flow_id = ? ", new Object[]{id}, new BeanPropertyRowMapper<>(Task.class));
|
|
|
+ if (tasks.size() > 0) {
|
|
|
+ return R.fail("当前流程已经使用,不能删除");
|
|
|
+ }
|
|
|
+ jdbcTemplate.update("DELETE FROM u_fixed_flow WHERE id = ?", new Object[]{id});
|
|
|
+ jdbcTemplate.update("DELETE FROM u_fixed_flow_link WHERE fixed_flow_id = ?", new Object[]{id});
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
}
|