diff --git a/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanApplyVo.java b/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanApplyVo.java index 49ff617..43a9a7f 100644 --- a/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanApplyVo.java +++ b/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanApplyVo.java @@ -137,6 +137,12 @@ public class PlanApplyVo { @JsonInclude(JsonInclude.Include.NON_NULL) private List planRecordList; + /**审核次数*/ + private int auditNum; + + /**是否具有审核按钮*/ + private boolean hasAuditBtn = true; + /** * 新增条件限制 */ diff --git a/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanAuditRecordVo.java b/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanAuditRecordVo.java index 97f5fd1..6ba34eb 100644 --- a/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanAuditRecordVo.java +++ b/src/main/java/com/bonus/aqgqj/business/backstage/entity/plan/PlanAuditRecordVo.java @@ -75,4 +75,17 @@ public class PlanAuditRecordVo { * 申请人手机号 */ private String phone; + /** + * 审核次数 + */ + private int auditNum; + /** + * 审核节点 + */ + private int statusType; + + /** + * 完结 + * */ + private boolean completed = false; } diff --git a/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanApplyMapper.java b/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanApplyMapper.java index 02e2af7..ab804f7 100644 --- a/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanApplyMapper.java +++ b/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanApplyMapper.java @@ -159,4 +159,13 @@ public interface PlanApplyMapper { * @date 2024/12/25 11:10 */ void editAuditStatus(PlanApplyVo data); + + /** + * 判断需求计划是否被修改 + * @param data + * @return Integer + * @author cwchen + * @date 2025/1/23 18:47 + */ + Integer getPlanData(PlanApplyVo data); } diff --git a/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanAuditMapper.java b/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanAuditMapper.java index f06949c..649083b 100644 --- a/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanAuditMapper.java +++ b/src/main/java/com/bonus/aqgqj/business/backstage/mapper/plan/PlanAuditMapper.java @@ -2,9 +2,11 @@ package com.bonus.aqgqj.business.backstage.mapper.plan; import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo; import com.bonus.aqgqj.business.backstage.entity.plan.PlanAuditRecordVo; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Map; /** * @className:PlanAuditMapper @@ -17,6 +19,7 @@ import java.util.List; public interface PlanAuditMapper { /** * 需求计划审核列表 + * * @param data * @return List * @author cwchen @@ -26,6 +29,7 @@ public interface PlanAuditMapper { /** * 查询计划审核节点及状态 + * * @param id * @return PlanApplyVo * @author cwchen @@ -35,6 +39,7 @@ public interface PlanAuditMapper { /** * 修改审核状态 + * * @param vo * @return void * @author cwchen @@ -44,10 +49,59 @@ public interface PlanAuditMapper { /** * 统计本次计划所需数量 + * * @param applyId * @return int * @author cwchen * @date 2024/11/29 9:35 */ int getPlanNeedNum(Integer applyId); + + /** + * 查询用户是否有审核权限 + * + * @param name + * @param statusType + * @param userId + * @return boolean + * @author cwchen + * @date 2025/1/23 15:05 + */ + int getUserPermission(@Param("name") String name, @Param("statusType") Integer statusType, @Param("userId") Long userId); + + /** + * 查询该条数据属于审核节点的审核类型:1 会签 2 或签 + * + * @param name + * @param statusType + * @return int + * @author cwchen + * @date 2025/1/23 16:00 + */ + int getAuditType(@Param("name") String name, @Param("statusType") Integer statusType); + + /** + * 查询审核记录 + * + * @param name + * @param statusType + * @param plan + * @return List> + * @author cwchen + * @date 2025/1/23 17:21 + */ + List> getUserAuditRecord(@Param("name") String name, @Param("statusType") int statusType, @Param("params") PlanApplyVo plan); + + /** + * 判断是否具有审核按钮 + * + * @param vo + * @param userId + * @param type + * @return int + * @author cwchen + * @date 2025/1/23 18:21 + */ + Integer getHasAuditBtn(@Param("params") PlanApplyVo vo, @Param("userId") Long userId, @Param("name") String name, @Param("statusType") int statusType, @Param("type") int type); + } diff --git a/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanApplyServiceImpl.java b/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanApplyServiceImpl.java index 62308c2..eaed724 100644 --- a/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanApplyServiceImpl.java +++ b/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanApplyServiceImpl.java @@ -95,12 +95,14 @@ public class PlanApplyServiceImpl implements PlanApplyService { String code = getCode(num); data.setCode(code); data.setNeedNum(needNum); + data.setAuditNum(1); // 添加计划申请数据 mapper.addPlanApply(data); // 添加安全工器具数据 mapper.addPlanDetail(details, data); // 添加需求计划申请节点 PlanAuditRecordVo vo = setPlanAuditRecordVoData(data, acount, "0"); + vo.setAuditNum(1); mapper.addPlanRecord(vo); return ServerResponse.createBySuccessMsg("新增成功"); } catch (Exception e) { @@ -114,6 +116,10 @@ public class PlanApplyServiceImpl implements PlanApplyService { @Transactional(rollbackFor = Exception.class) public ServerResponse editApplyPlan(PlanApplyVo data) { try { + Integer num = mapper.getPlanData(data); + if(num == null || num > 0){ + return ServerResponse.createBySuccessMsg("修改成功"); + } // 添加创建人信息 SelfUserEntity acount = UserUtil.getLoginUser(); String userName = UserUtil.getLoginUser().getUsername(); @@ -201,11 +207,16 @@ public class PlanApplyServiceImpl implements PlanApplyService { if (CollectionUtils.isNotEmpty(auditList) && auditList.size() > 1) { for (int i = 0; i < auditList.size(); i++) { PlanAuditRecordVo item = auditList.get(i); - if (Objects.equals(item.getAuditType(), "4") && Objects.equals(item.getAuditStatus(), "2")) { + if (Objects.equals(vo.getStatusType(),"1") && Objects.equals(vo.getStatus(),"2") && Objects.equals(item.getAuditType(), "4") && Objects.equals(item.getAuditStatus(), "2") && i == 0) { // 审核完结-->计算所有流程的时间差 Long[] timeDiff = DateTimeHelper.getTimeDiff(item.getAuditTime(), auditList.get(auditList.size() - 1).getAuditTime()); item.setHours(timeDiff[0]); item.setMinutes(timeDiff[1]); + item.setCompleted(true); + } else if (Objects.equals(vo.getStatusType(),"1") && Objects.equals(vo.getStatus(),"2") && Objects.equals(item.getAuditType(), "4") && Objects.equals(item.getAuditStatus(), "2") && i != 0) { + Long[] timeDiff = DateTimeHelper.getTimeDiff(item.getAuditTime(), auditList.get(i + 1).getAuditTime()); + item.setHours(timeDiff[0]); + item.setMinutes(timeDiff[1]); } else { // 未审核完结-计算每个流程的时间差 if (i != auditList.size() - 1) { diff --git a/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanAuditServiceImpl.java b/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanAuditServiceImpl.java index 6d48f02..284f081 100644 --- a/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanAuditServiceImpl.java +++ b/src/main/java/com/bonus/aqgqj/business/backstage/service/plan/PlanAuditServiceImpl.java @@ -5,9 +5,11 @@ import com.bonus.aqgqj.business.backstage.entity.plan.PlanAuditRecordVo; import com.bonus.aqgqj.business.backstage.mapper.plan.PlanApplyMapper; import com.bonus.aqgqj.business.backstage.mapper.plan.PlanAuditMapper; import com.bonus.aqgqj.manager.common.util.UserUtil; +import com.bonus.aqgqj.manager.constant.BusinessConstants; import com.bonus.aqgqj.manager.security.entity.SelfUserEntity; import com.bonus.aqgqj.manager.webResult.ServerResponse; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -17,6 +19,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; import javax.annotation.Resource; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -42,9 +45,25 @@ public class PlanAuditServiceImpl implements PlanAuditService { @Override public List getPlanAuditList(PlanApplyVo data) { + SelfUserEntity acount = UserUtil.getLoginUser(); List list = null; try { list = mapper.getPlanAuditList(data); + for (PlanApplyVo vo : list) { + if(Objects.equals(vo.getStatusType(),"1") && Objects.equals(vo.getStatus(),"2")){ + continue; + } + // 判断是否具有审核按钮 + Integer num = mapper.getHasAuditBtn(vo, acount.getUserId(),BusinessConstants.SAFETY_PLAN,Integer.parseInt(vo.getStatusType()) - 1,1); + if(num == null || num == 0){ + vo.setHasAuditBtn(false); + }else{ + Integer num2 = mapper.getHasAuditBtn(vo, acount.getUserId(),BusinessConstants.SAFETY_PLAN,Integer.parseInt(vo.getStatusType()) - 1,2); + if(num2 > 0){ + vo.setHasAuditBtn(false); + } + } + } } catch (Exception e) { log.error(e.toString(), e); } @@ -57,30 +76,46 @@ public class PlanAuditServiceImpl implements PlanAuditService { try { // 通过applicationContext获取代理对象 PlanAuditServiceImpl proxy = applicationContext.getBean(PlanAuditServiceImpl.class); - SelfUserEntity acount = UserUtil.getLoginUser(); + SelfUserEntity account = UserUtil.getLoginUser(); String userName = UserUtil.getLoginUser().getUsername(); Integer applyId = vo.getApplyId(); if (applyId == null) { return ServerResponse.createErroe("请选择计划进行审核"); } else { - //需要配置审核流程节点 、按照不同的用户 角色权限 进行审核 - //查询计划节点 及状态 PlanApplyVo plan = mapper.getPlanApplyData(applyId); - //目前未配置角色 全部都可以审核 String statusType = plan.getStatusType(); String status = plan.getStatus(); - if (!Objects.equals(status, "1")) { - return ServerResponse.createErroe("该计划已被审核,请刷新重试"); + //1.查询该账号是否具有审核权限 + int result = mapper.getUserPermission(BusinessConstants.SAFETY_PLAN, Integer.parseInt(statusType) - 1, account.getUserId()); + if (result == 0) { + return ServerResponse.createErroe("该账号无权限审核"); } + //2.验证是否重复审核 + if (((Integer.parseInt(statusType) > vo.getStatusType())) || Objects.equals(status, "2")) { + return ServerResponse.createBySuccessMsg("该数据已被审核请刷新后重试"); + } + int isRepeatAudit = mapper.getHasAuditBtn(plan, account.getUserId(),BusinessConstants.SAFETY_PLAN,Integer.parseInt(plan.getStatusType()) - 1,2); + if (isRepeatAudit > 0) { + return ServerResponse.createBySuccessMsg("请勿重复审核"); + } + //3.查询该条数据所属审核节点的审核类型:1 会签 2 或签 + int auditType = mapper.getAuditType(BusinessConstants.SAFETY_PLAN, Integer.parseInt(statusType) - 1); + // 审核结果 2.审核通过 3.审核不通过 String auditStatus = vo.getAuditStatus(); - //审核通过 - if (Objects.equals(auditStatus, "2")) { - proxy.auditSuccess(vo, statusType, acount, plan); - return ServerResponse.createBySuccessMsg("审核成功"); - } else { - //审核驳回 - proxy.aduitError(vo, statusType, acount); - return ServerResponse.createBySuccessMsg("驳回成功"); + if (auditType == 1) { // 会签情况 + if (Objects.equals(auditStatus, "2")) { + return proxy.countersignAuditSuccess(vo, statusType, account, plan); + } else { + return proxy.countersignAuditError(vo, statusType, account, plan); + } + } else if (auditType == 2) { // 或签情况 + if (Objects.equals(auditStatus, "2")) { + proxy.orVisaAuditSuccess(vo, statusType, account, plan); + return ServerResponse.createBySuccessMsg("审核通过"); + } else { + proxy.orVisaAuditError(vo, statusType, account, plan); + return ServerResponse.createBySuccessMsg("驳回成功"); + } } } } catch (Exception e) { @@ -88,20 +123,21 @@ public class PlanAuditServiceImpl implements PlanAuditService { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return ServerResponse.createErroe("审核失败"); } + return null; } /** - * 审核通过 + * 或签-审核通过 */ @Transactional - public void auditSuccess(PlanAuditRecordVo vo, String statusType, SelfUserEntity user, PlanApplyVo plan) { + public void orVisaAuditSuccess(PlanAuditRecordVo vo, String statusType, SelfUserEntity user, PlanApplyVo plan) { // 通过applicationContext获取代理对象 - PlanAuditServiceImpl proxy = applicationContext.getBean(PlanAuditServiceImpl.class); //添加审核记录 vo.setAuditType(statusType);//审核节点 vo.setAuditor(Integer.parseInt(user.getUserId() + "")); vo.setUpdater(Integer.parseInt(user.getUserId() + "")); vo.setAuditName(user.getUsername()); + vo.setAuditNum(plan.getAuditNum()); planApplyMapper.addPlanRecord(vo); //修改下次 审核流程 vo.setAuditStatus("1"); @@ -118,16 +154,78 @@ public class PlanAuditServiceImpl implements PlanAuditService { } /** - * 审核驳回 + * 或签-审核驳回 */ @Transactional - public void aduitError(PlanAuditRecordVo vo, String statusType, SelfUserEntity user) { + public void orVisaAuditError(PlanAuditRecordVo vo, String statusType, SelfUserEntity user, PlanApplyVo plan) { //修改审核状态 vo.setAuditType(statusType);//审核节点 mapper.updatePlanAudit(vo); vo.setAuditor(Integer.parseInt(user.getUserId() + "")); vo.setUpdater(Integer.parseInt(user.getUserId() + "")); vo.setAuditName(user.getUsername()); + vo.setAuditNum(plan.getAuditNum()); planApplyMapper.addPlanRecord(vo); } + + /** + * 会签-审核通过 + */ + @Transactional + public ServerResponse countersignAuditSuccess(PlanAuditRecordVo vo, String statusType, SelfUserEntity user, PlanApplyVo plan) { + //添加审核记录 + vo.setAuditType(statusType);//审核节点 + vo.setAuditor(Integer.parseInt(user.getUserId() + "")); + vo.setUpdater(Integer.parseInt(user.getUserId() + "")); + vo.setAuditName(user.getUsername()); + vo.setAuditNum(plan.getAuditNum()); + planApplyMapper.addPlanRecord(vo); + // 查询审核记录 + List> list = mapper.getUserAuditRecord(BusinessConstants.SAFETY_PLAN, Integer.parseInt(statusType) - 1, plan); + if (CollectionUtils.isNotEmpty(list)) { + int num = 0; + for (Map item : list) { + String auditor = item.get("auditor"); + if (!Objects.equals(auditor, "0")) { + num++; + } + } + if (num == list.size()) { + // 审核记录和审核人员数量相同时,则流转到下一审核节点 + //修改下次 审核流程 + vo.setAuditStatus("1"); + if (Objects.equals(statusType, "2")) { + vo.setAuditType("3"); + } else if (Objects.equals(statusType, "3")) { + vo.setAuditType("4"); + } else if (Objects.equals(statusType, "4")) { + vo.setAuditType("1"); + vo.setAuditStatus("2"); + } + //修改审核状态 + mapper.updatePlanAudit(vo); + return ServerResponse.createBySuccessMsg("审核通过"); + } else { + return ServerResponse.createBySuccessMsg("审核通过,请等待其他用户审核"); + } + }else{ + return ServerResponse.createErroe("未配置审核用户"); + } + } + + /** + * 会签-驳回 + */ + @Transactional + public ServerResponse countersignAuditError(PlanAuditRecordVo vo, String statusType, SelfUserEntity user, PlanApplyVo plan) { + //修改审核状态 + vo.setAuditType(statusType);//审核节点 + mapper.updatePlanAudit(vo); + vo.setAuditor(Integer.parseInt(user.getUserId() + "")); + vo.setUpdater(Integer.parseInt(user.getUserId() + "")); + vo.setAuditName(user.getUsername()); + vo.setAuditNum(plan.getAuditNum()); + planApplyMapper.addPlanRecord(vo); + return ServerResponse.createBySuccessMsg("驳回成功"); + } } diff --git a/src/main/java/com/bonus/aqgqj/manager/constant/BusinessConstants.java b/src/main/java/com/bonus/aqgqj/manager/constant/BusinessConstants.java new file mode 100644 index 0000000..37d9931 --- /dev/null +++ b/src/main/java/com/bonus/aqgqj/manager/constant/BusinessConstants.java @@ -0,0 +1,14 @@ +package com.bonus.aqgqj.manager.constant; + +/** + * @className:BusinessConstants + * @author:cwchen + * @date:2025-01-23-16:58 + * @version:1.0 + * @description:常量 + */ +public class BusinessConstants { + + /**安全工器具计划审核*/ + public static final String SAFETY_PLAN = "safety_plan"; +} diff --git a/src/main/resources/mappers/business/backstage/PlanApplyMapper.xml b/src/main/resources/mappers/business/backstage/PlanApplyMapper.xml index f12f193..4c24590 100644 --- a/src/main/resources/mappers/business/backstage/PlanApplyMapper.xml +++ b/src/main/resources/mappers/business/backstage/PlanApplyMapper.xml @@ -19,7 +19,8 @@ updater, update_time, status_type, - need_num + need_num, + audit_num #{code}, @@ -35,7 +36,8 @@ #{updater}, #{updateTime}, '2', - #{needNum} + #{needNum}, + #{auditNum} @@ -71,6 +73,7 @@ audit_type, audit_name, id, + audit_num #{applyId}, @@ -82,7 +85,8 @@ #{updateTime}, #{auditType}, #{auditName}, - null + null, + #{auditNum} @@ -114,7 +118,7 @@ UPDATE st_plan_apply SET project_id = #{projectId},project_part = #{projectPart},project_content = #{projectContent}, need_time = #{needTime},remark = #{remark},updater = #{updater},update_time = #{updateTime}, - need_num = #{needNum} WHERE id = #{id} + need_num = #{needNum},audit_num = (audit_num + 1) WHERE id = #{id} @@ -246,4 +250,10 @@ AND INSTR(mt.name,#{modelName}) > 0 + + \ No newline at end of file diff --git a/src/main/resources/mappers/business/backstage/PlanAuditMapper.xml b/src/main/resources/mappers/business/backstage/PlanAuditMapper.xml index 716b7ee..5610158 100644 --- a/src/main/resources/mappers/business/backstage/PlanAuditMapper.xml +++ b/src/main/resources/mappers/business/backstage/PlanAuditMapper.xml @@ -19,7 +19,8 @@ spa.create_time AS createTime, spa.remark, spa.status, - spa.status_type AS statusType + spa.status_type AS statusType, + spa.audit_num AS auditNum FROM st_plan_apply spa LEFT JOIN bm_project tbp ON spa.project_id = tbp.bid_id @@ -43,11 +44,57 @@ + + + + + + + + \ No newline at end of file