|
@@ -19,6 +19,7 @@ import com.usky.system.domain.SysUser;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -96,7 +97,8 @@ public class OaApprovalServiceImpl extends AbstractCrudService<OaApprovalMapper,
|
|
|
|
|
|
LambdaQueryWrapper<OaApproval> queryWrapper = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<OaApproval> queryWrapper = Wrappers.lambdaQuery();
|
|
queryWrapper.eq(OaApproval::getTenantId, tenantId)
|
|
queryWrapper.eq(OaApproval::getTenantId, tenantId)
|
|
- .eq(OaApproval::getApprovalUid, userId);
|
|
|
|
|
|
+ .eq(OaApproval::getApprovalUid, userId)
|
|
|
|
+ .orderByDesc(OaApproval::getId);
|
|
|
|
|
|
switch (queryType) {
|
|
switch (queryType) {
|
|
case 1:
|
|
case 1:
|
|
@@ -122,6 +124,8 @@ public class OaApprovalServiceImpl extends AbstractCrudService<OaApprovalMapper,
|
|
.between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), OaApproval::getSubmitDate, startTime, endTime)
|
|
.between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), OaApproval::getSubmitDate, startTime, endTime)
|
|
.orderByDesc(OaApproval::getSubmitDate);
|
|
.orderByDesc(OaApproval::getSubmitDate);
|
|
break;
|
|
break;
|
|
|
|
+ case 4:
|
|
|
|
+
|
|
default:
|
|
default:
|
|
throw new RuntimeException("查询类型参数错误");
|
|
throw new RuntimeException("查询类型参数错误");
|
|
}
|
|
}
|
|
@@ -147,16 +151,30 @@ public class OaApprovalServiceImpl extends AbstractCrudService<OaApprovalMapper,
|
|
}
|
|
}
|
|
|
|
|
|
// 审批
|
|
// 审批
|
|
|
|
+ @Transactional
|
|
@Override
|
|
@Override
|
|
public void approve(Integer id, Integer approvalStatus, String opinion) {
|
|
public void approve(Integer id, Integer approvalStatus, String opinion) {
|
|
- LambdaQueryWrapper<OaApproval> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
- queryWrapper.eq(OaApproval::getId, id);
|
|
|
|
- OaApproval oaApproval = oaApprovalMapper.selectOne(queryWrapper);
|
|
|
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
|
+ String username = SecurityUtils.getUsername();
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ Integer tenantId = SecurityUtils.getTenantId();
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<SysUser> userQuery = new LambdaQueryWrapper<>();
|
|
|
|
+ userQuery.select(SysUser::getUserId, SysUser::getDeptId)
|
|
|
|
+ .eq(SysUser::getTenantId, tenantId)
|
|
|
|
+ .eq(SysUser::getDelFlag, 0)
|
|
|
|
+ .eq(SysUser::getStatus, 0);
|
|
|
|
+ Map<Long, Long> userDeptMap = sysUserMapper.selectList(userQuery).stream()
|
|
|
|
+ .collect(Collectors.toMap(SysUser::getUserId, SysUser::getDeptId));
|
|
|
|
+
|
|
|
|
+ OaApproval oaApproval = oaApprovalMapper.selectOne(Wrappers.<OaApproval>lambdaQuery().eq(OaApproval::getId, id));
|
|
|
|
|
|
|
|
+ if (oaApproval == null) {
|
|
|
|
+ throw new BusinessException("审批信息不存在!请联系管理员");
|
|
|
|
+ }
|
|
if (!oaApproval.getApprovalUid().equals(SecurityUtils.getUserId())) {
|
|
if (!oaApproval.getApprovalUid().equals(SecurityUtils.getUserId())) {
|
|
throw new BusinessException("审批权限不足,暂时无法更改!");
|
|
throw new BusinessException("审批权限不足,暂时无法更改!");
|
|
}
|
|
}
|
|
-
|
|
|
|
if (oaApproval.getApprovalStatus() != 1) {
|
|
if (oaApproval.getApprovalStatus() != 1) {
|
|
throw new BusinessException("审批状态异常,暂时无法更改!");
|
|
throw new BusinessException("审批状态异常,暂时无法更改!");
|
|
}
|
|
}
|
|
@@ -164,87 +182,19 @@ public class OaApprovalServiceImpl extends AbstractCrudService<OaApprovalMapper,
|
|
throw new BusinessException("审批类型错误,请重试!");
|
|
throw new BusinessException("审批类型错误,请重试!");
|
|
}
|
|
}
|
|
|
|
|
|
- String username = SecurityUtils.getUsername();
|
|
|
|
-
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
|
-
|
|
|
|
|
|
+ oaApproval.setApprovalUid(userId);
|
|
oaApproval.setApprovalStatus(approvalStatus);
|
|
oaApproval.setApprovalStatus(approvalStatus);
|
|
- oaApproval.setOpinion(opinion);
|
|
|
|
|
|
+ oaApproval.setOpinion(opinion == null ? "" : opinion);
|
|
oaApproval.setApprovalDate(now);
|
|
oaApproval.setApprovalDate(now);
|
|
oaApproval.setUpdateBy(username);
|
|
oaApproval.setUpdateBy(username);
|
|
oaApproval.setUpdateTime(now);
|
|
oaApproval.setUpdateTime(now);
|
|
oaApprovalMapper.updateById(oaApproval);
|
|
oaApprovalMapper.updateById(oaApproval);
|
|
|
|
|
|
- boolean isPass = approvalStatus != 3;
|
|
|
|
- Long proposerId = Long.valueOf(oaApproval.getProposer());
|
|
|
|
- List<Long> receivers = Collections.singletonList(proposerId);
|
|
|
|
- oaSendMessageCenter.sendAsyncMessage(oaApproval.getCreateBy(), proposerId, oaApproval.getId(), receivers, isPass ? 1 : 0);
|
|
|
|
-
|
|
|
|
if (approvalStatus == 2) {
|
|
if (approvalStatus == 2) {
|
|
- LambdaQueryWrapper<OaApproval> approvalLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
- approvalLambdaQueryWrapper.eq(OaApproval::getDocNo, oaApproval.getDocNo())
|
|
|
|
- .eq(OaApproval::getApprovalStatus, 1);
|
|
|
|
- List<OaApproval> oaApprovals = oaApprovalMapper.selectList(approvalLambdaQueryWrapper);
|
|
|
|
-
|
|
|
|
- if (oaApprovals.isEmpty()) {
|
|
|
|
- LambdaQueryWrapper<OaNode> nodeQuery = new LambdaQueryWrapper<>();
|
|
|
|
- nodeQuery.eq(OaNode::getParentId, oaApproval.getNodeId())
|
|
|
|
- .orderByAsc(OaNode::getId);
|
|
|
|
- List<OaNode> oaNodes = oaNodeMapper.selectList(nodeQuery);
|
|
|
|
-
|
|
|
|
- Integer tenantId = SecurityUtils.getTenantId();
|
|
|
|
- Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
|
|
|
- for (OaNode oaNode : oaNodes) {
|
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
|
- switch (oaNode.getNodeScope()) {
|
|
|
|
- case 0:
|
|
|
|
- case 1:
|
|
|
|
- case 2:
|
|
|
|
- userIds = Arrays.stream(oaNode.getProposer().split(",")).map(Long::parseLong).collect(Collectors.toList());
|
|
|
|
- break;
|
|
|
|
- case 3:
|
|
|
|
- LambdaQueryWrapper<SysUser> userQuery = new LambdaQueryWrapper<>();
|
|
|
|
- userQuery.select(SysUser::getUserId)
|
|
|
|
- .eq(SysUser::getTenantId, tenantId)
|
|
|
|
- .eq(SysUser::getDelFlag, 0)
|
|
|
|
- .eq(SysUser::getStatus, 0)
|
|
|
|
- .eq(SysUser::getDeptId, oaNode.getDeptId());
|
|
|
|
- userIds = sysUserMapper.selectList(userQuery).stream().map(SysUser::getUserId).collect(Collectors.toList());
|
|
|
|
- break;
|
|
|
|
- case 4:
|
|
|
|
- LambdaQueryWrapper<SysUserPost> userRoleQuery = new LambdaQueryWrapper<>();
|
|
|
|
- userRoleQuery.eq(SysUserPost::getPostId, oaNode.getJobId());
|
|
|
|
- userIds = sysUserPostMapper.selectList(userRoleQuery).stream().map(SysUserPost::getUserId).collect(Collectors.toList());
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (Long userId1 : userIds) {
|
|
|
|
- OaApproval approval = new OaApproval();
|
|
|
|
- approval.setDocNo(oaApproval.getDocNo());
|
|
|
|
- approval.setProposer(Math.toIntExact(userId1));
|
|
|
|
- approval.setType(oaNode.getNodeType());
|
|
|
|
- approval.setApprovalStatus(1);
|
|
|
|
- approval.setCreateTime(now);
|
|
|
|
- approval.setCreateBy(username);
|
|
|
|
- approval.setDeptId(deptId);
|
|
|
|
- approval.setTenantId(tenantId);
|
|
|
|
- approval.setNodeId(oaNode.getId());
|
|
|
|
- oaApprovalMapper.insert(approval);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- for (OaApproval approval : oaApprovals) {
|
|
|
|
- approval.setApprovalStatus(2);
|
|
|
|
- oaApprovalMapper.updateById(approval);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- LambdaQueryWrapper<OaNode> nodeQuery = new LambdaQueryWrapper<>();
|
|
|
|
- nodeQuery.eq(OaNode::getParentId, oaApproval.getNodeId())
|
|
|
|
- .orderByAsc(OaNode::getId);
|
|
|
|
- List<OaNode> oaNodes = oaNodeMapper.selectList(nodeQuery);
|
|
|
|
-
|
|
|
|
- Integer tenantId = SecurityUtils.getTenantId();
|
|
|
|
- Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
|
|
|
|
|
+ Integer nodeId = oaApprovalMapper.selectById(oaApproval.getId()).getNodeId();
|
|
|
|
+ Integer parentId = oaNodeMapper.selectById(nodeId).getParentId();
|
|
|
|
+ List<OaNode> oaNodes = oaNodeMapper.selectList(Wrappers.<OaNode>lambdaQuery().eq(OaNode::getId, parentId));
|
|
|
|
+ if (!oaNodes.isEmpty()) {
|
|
for (OaNode oaNode : oaNodes) {
|
|
for (OaNode oaNode : oaNodes) {
|
|
List<Long> userIds = new ArrayList<>();
|
|
List<Long> userIds = new ArrayList<>();
|
|
switch (oaNode.getNodeScope()) {
|
|
switch (oaNode.getNodeScope()) {
|
|
@@ -254,13 +204,13 @@ public class OaApprovalServiceImpl extends AbstractCrudService<OaApprovalMapper,
|
|
userIds = Arrays.stream(oaNode.getProposer().split(",")).map(Long::parseLong).collect(Collectors.toList());
|
|
userIds = Arrays.stream(oaNode.getProposer().split(",")).map(Long::parseLong).collect(Collectors.toList());
|
|
break;
|
|
break;
|
|
case 3:
|
|
case 3:
|
|
- LambdaQueryWrapper<SysUser> userQuery = new LambdaQueryWrapper<>();
|
|
|
|
- userQuery.select(SysUser::getUserId)
|
|
|
|
|
|
+ LambdaQueryWrapper<SysUser> userQuery1 = new LambdaQueryWrapper<>();
|
|
|
|
+ userQuery1.select(SysUser::getUserId, SysUser::getNickName, SysUser::getDeptId)
|
|
.eq(SysUser::getTenantId, tenantId)
|
|
.eq(SysUser::getTenantId, tenantId)
|
|
.eq(SysUser::getDelFlag, 0)
|
|
.eq(SysUser::getDelFlag, 0)
|
|
.eq(SysUser::getStatus, 0)
|
|
.eq(SysUser::getStatus, 0)
|
|
.eq(SysUser::getDeptId, oaNode.getDeptId());
|
|
.eq(SysUser::getDeptId, oaNode.getDeptId());
|
|
- userIds = sysUserMapper.selectList(userQuery).stream().map(SysUser::getUserId).collect(Collectors.toList());
|
|
|
|
|
|
+ userIds = sysUserMapper.selectList(userQuery1).stream().map(SysUser::getUserId).collect(Collectors.toList());
|
|
break;
|
|
break;
|
|
case 4:
|
|
case 4:
|
|
LambdaQueryWrapper<SysUserPost> userRoleQuery = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<SysUserPost> userRoleQuery = new LambdaQueryWrapper<>();
|
|
@@ -269,24 +219,70 @@ public class OaApprovalServiceImpl extends AbstractCrudService<OaApprovalMapper,
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- for (Long userId1 : userIds) {
|
|
|
|
- OaApproval approval = new OaApproval();
|
|
|
|
- approval.setDocNo(oaApproval.getDocNo());
|
|
|
|
- approval.setProposer(Math.toIntExact(userId1));
|
|
|
|
- approval.setType(oaNode.getNodeType());
|
|
|
|
- approval.setApprovalStatus(1);
|
|
|
|
- approval.setCreateTime(now);
|
|
|
|
- approval.setCreateBy(username);
|
|
|
|
- approval.setDeptId(deptId);
|
|
|
|
- approval.setTenantId(tenantId);
|
|
|
|
- approval.setNodeId(oaNode.getId());
|
|
|
|
- oaApprovalMapper.insert(approval);
|
|
|
|
|
|
+ if (userIds.isEmpty()) {
|
|
|
|
+ log.error("审批节点无用户,审批失败!");
|
|
|
|
+ } else {
|
|
|
|
+ for (Long userId1 : userIds) {
|
|
|
|
+ OaApproval approval = new OaApproval();
|
|
|
|
+ approval.setDocNo(oaApproval.getDocNo());
|
|
|
|
+ approval.setProposer(oaApproval.getProposer());
|
|
|
|
+ approval.setApprovalUid(userId1);
|
|
|
|
+ approval.setType(oaNode.getNodeType());
|
|
|
|
+ approval.setApprovalStatus(1);
|
|
|
|
+ approval.setCreateTime(now);
|
|
|
|
+ approval.setCreateBy(username);
|
|
|
|
+ approval.setDeptId(userDeptMap.get(userId1));
|
|
|
|
+ approval.setTenantId(tenantId);
|
|
|
|
+ approval.setNodeId(oaNode.getId());
|
|
|
|
+ oaApprovalMapper.insert(approval);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 发送消息通知下一步审批人
|
|
|
|
+ oaSendMessageCenter.sendAsyncMessage(
|
|
|
|
+ oaApproval.getCreateBy(),
|
|
|
|
+ Long.valueOf(oaApproval.getProposer()),
|
|
|
|
+ oaApproval.getId(),
|
|
|
|
+ userIds,
|
|
|
|
+ 3,
|
|
|
|
+ getFieldInfo(oaApproval.getDocNo())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // 后无节点,发送消息通知申请人审核通过
|
|
|
|
+ else {
|
|
|
|
+ Long proposerId = Long.valueOf(oaApproval.getProposer());
|
|
|
|
+ oaSendMessageCenter.sendAsyncMessage(
|
|
|
|
+ oaApproval.getCreateBy(),
|
|
|
|
+ proposerId,
|
|
|
|
+ oaApproval.getId(),
|
|
|
|
+ Collections.singletonList(proposerId),
|
|
|
|
+ 1,
|
|
|
|
+ getFieldInfo(oaApproval.getDocNo())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
} else if (oaApproval.getApprovalStatus() == 3) {
|
|
} else if (oaApproval.getApprovalStatus() == 3) {
|
|
|
|
+ Long proposerId = Long.valueOf(oaApproval.getProposer());
|
|
|
|
+ // 发送消息通知申请人审核不通过
|
|
|
|
+ oaSendMessageCenter.sendAsyncMessage(
|
|
|
|
+ oaApproval.getCreateBy(),
|
|
|
|
+ proposerId,
|
|
|
|
+ oaApproval.getId(),
|
|
|
|
+ Collections.singletonList(proposerId),
|
|
|
|
+ 0,
|
|
|
|
+ getFieldInfo(oaApproval.getDocNo())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public String getFieldInfo(String docNo) {
|
|
|
|
+ String sgin = docNo.split("-")[0];
|
|
|
|
+ LambdaQueryWrapper<OaFormDefinition> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.select(OaFormDefinition::getFieldInfo)
|
|
|
|
+ .eq(OaFormDefinition::getFormSign, sgin);
|
|
|
|
+ OaFormDefinition oaFormDefinition = oaFormDefinitionMapper.selectOne(queryWrapper);
|
|
|
|
+ return oaFormDefinition.getFieldInfo();
|
|
}
|
|
}
|
|
|
|
|
|
// xml 流程解析测试
|
|
// xml 流程解析测试
|