Commit 236ab785 by 陶湘宇

防止重复提交审批

parent cc165389
package cn.timer.api.controller.spmk; package cn.timer.api.controller.spmk;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
...@@ -10,6 +11,8 @@ import java.util.Set; ...@@ -10,6 +11,8 @@ import java.util.Set;
import cn.timer.api.bean.spmk.*; import cn.timer.api.bean.spmk.*;
import cn.timer.api.dao.spmk.*; import cn.timer.api.dao.spmk.*;
import cn.timer.api.dto.spmk.*; import cn.timer.api.dto.spmk.*;
import cn.timer.api.utils.redis.RedisUtil;
import com.baomidou.mybatisplus.core.toolkit.SerializationUtils;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -71,6 +74,8 @@ import cn.timer.api.utils.router.enums.ApproveEnum; ...@@ -71,6 +74,8 @@ import cn.timer.api.utils.router.enums.ApproveEnum;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
@Api(tags = "3.0审批模块") @Api(tags = "3.0审批模块")
@RestController @RestController
@Transactional @Transactional
...@@ -110,7 +115,8 @@ public class SpmkController { ...@@ -110,7 +115,8 @@ public class SpmkController {
private boolean ISFIRST = true; // 第一次启动审批流程 private boolean ISFIRST = true; // 第一次启动审批流程
@Resource
private RedisUtil redisUtil;
//TODO 审批模板组 //TODO 审批模板组
...@@ -555,8 +561,56 @@ public class SpmkController { ...@@ -555,8 +561,56 @@ public class SpmkController {
if(listFlowChildren.isEmpty()){ if(listFlowChildren.isEmpty()){
return ResultUtil.error("无法发起,请完善审批流程"); return ResultUtil.error("无法发起,请完善审批流程");
} }
List<FlowChildren> listFlowChildren1 = (ArrayList<FlowChildren>) SerializationUtils.clone((Serializable) listFlowChildren);
List<String> uidlist = new ArrayList<>();
int i=0;
int fsize = listFlowChildren.size();
int f=0;//listFlowChildren删除次数
for (FlowChildren flowChildrenItem: listFlowChildren) { for (FlowChildren flowChildrenItem: listFlowChildren) {
if ("audit".equals(flowChildrenItem.getClassName())) {
boolean hasAudit = false;
for (Relation relation : flowChildrenItem.getRelation()) {
if (relation.getUsers().size() > 0) {
hasAudit = true;
//审批人去重
if (relation.getUsers().size() > 1){
int j=0;
int usize=relation.getUsers().size();//
int r=0;//user list删除次数
for (User user:relation.getUsers()
) {
if (!uidlist.contains(user.getId())) {
uidlist.add(user.getId());
}else {
listFlowChildren1.get(i).getRelation().get(0).getUsers().remove(j-r);
r++;
}
j++;
}
if (usize==r){
listFlowChildren1.remove(i-f);
f++;
}
}else {
if (!uidlist.contains(relation.getUsers().get(0).getId())) {
uidlist.add(relation.getUsers().get(0).getId());
}else {
listFlowChildren1.remove(i-f);
f++;
}
}
}
}
if (!hasAudit) {
return ResultUtil.error("审批流程设置审批人为空无法发起!");
}
}
i++;
}
listFlowChildren = (ArrayList<FlowChildren>) SerializationUtils.clone((Serializable) listFlowChildren1);
/*for (FlowChildren flowChildrenItem: listFlowChildren) {
if("audit".equals(flowChildrenItem.getClassName())){ if("audit".equals(flowChildrenItem.getClassName())){
boolean hasAudit=false; boolean hasAudit=false;
for (Relation relation:flowChildrenItem.getRelation()) { for (Relation relation:flowChildrenItem.getRelation()) {
...@@ -568,7 +622,7 @@ public class SpmkController { ...@@ -568,7 +622,7 @@ public class SpmkController {
return ResultUtil.error("审批流程设置审批人为空无法发起!"); return ResultUtil.error("审批流程设置审批人为空无法发起!");
} }
} }
} }*/
Logoutput("listFlowChildren"); Logoutput("listFlowChildren");
...@@ -660,6 +714,7 @@ public class SpmkController { ...@@ -660,6 +714,7 @@ public class SpmkController {
public Result<Object> selectAd(@PathVariable(required = true) Integer id) { public Result<Object> selectAd(@PathVariable(required = true) Integer id) {
SpmkApproveDetailDto adD = spmkService.selectApproveDetailByAsId(id); SpmkApproveDetailDto adD = spmkService.selectApproveDetailByAsId(id);
System.out.println(ResultUtil.data(adD));
return ResultUtil.data(adD); return ResultUtil.data(adD);
} }
...@@ -675,8 +730,14 @@ public class SpmkController { ...@@ -675,8 +730,14 @@ public class SpmkController {
@Log(title = "审批-审批流程", businessType = BusinessType.UPDATE) @Log(title = "审批-审批流程", businessType = BusinessType.UPDATE)
// @BindingResultCtrol(title = "审批人审批") // @BindingResultCtrol(title = "审批人审批")
public Result<Object> approving(@CurrentUser UserBean userBean,@Validated @RequestBody ApprovingDto approvingDto) throws Exception { public Result<Object> approving(@CurrentUser UserBean userBean,@Validated @RequestBody ApprovingDto approvingDto) throws Exception {
Integer asId = approvingDto.getAsId(); Integer asId = approvingDto.getAsId();
//查询redis中当前有没有在被审批执行中,0是没有在执行,1是在执行
Integer approStatus=Integer.parseInt(redisUtil.get(asId.toString())==null?"0":redisUtil.get(asId.toString()).toString());
if(approStatus==1){
return ResultUtil.error("该审批已在审批中!");
}else{
redisUtil.set(asId.toString(),1,5000);
}
SpmkApproveDetailSummary ad = SpmkApproveDetailSummary.builder().build().selectOne(new QueryWrapper<SpmkApproveDetailSummary>() SpmkApproveDetailSummary ad = SpmkApproveDetailSummary.builder().build().selectOne(new QueryWrapper<SpmkApproveDetailSummary>()
.lambda() .lambda()
.select(SpmkApproveDetailSummary::getId, .select(SpmkApproveDetailSummary::getId,
...@@ -684,12 +745,13 @@ public class SpmkController { ...@@ -684,12 +745,13 @@ public class SpmkController {
SpmkApproveDetailSummary::getFlowChildren) SpmkApproveDetailSummary::getFlowChildren)
.eq(SpmkApproveDetailSummary::getApproveSummaryId, asId)); .eq(SpmkApproveDetailSummary::getApproveSummaryId, asId));
// 查询 SpmkApproveSummary 状态 // 查询 SpmkApproveSummary 状态,
SpmkApproveSummary aSummary = spmkApproveSummaryMapper.selectOne(new QueryWrapper<SpmkApproveSummary>().lambda() SpmkApproveSummary aSummary = spmkApproveSummaryMapper.selectOne(new QueryWrapper<SpmkApproveSummary>().lambda()
.select(SpmkApproveSummary::getSts) .select(SpmkApproveSummary::getSts)
.eq(SpmkApproveSummary::getId, asId)); .eq(SpmkApproveSummary::getId, asId));
if (aSummary.getSts() > SpmkEnumInterface.ApproveSummarySts.IN.ordinal()) { if (aSummary.getSts() > ApproveSummarySts.IN.ordinal()) {
redisUtil.set(asId.toString(),0,500);
return ResultUtil.error("该审批已结束!"); return ResultUtil.error("该审批已结束!");
} }
...@@ -699,13 +761,14 @@ public class SpmkController { ...@@ -699,13 +761,14 @@ public class SpmkController {
.eq(SpmkExecutor::getSts, ExecutorSts.IN_EXECUTION.ordinal())); .eq(SpmkExecutor::getSts, ExecutorSts.IN_EXECUTION.ordinal()));
if (count == 0) { if (count == 0) {
redisUtil.set(asId.toString(),0,500);
return ResultUtil.error("您已审批过!"); return ResultUtil.error("您已审批过!");
} }
if ( spmkExecutorMapper.selectCount(new QueryWrapper<SpmkExecutor>().lambda() if ( spmkExecutorMapper.selectCount(new QueryWrapper<SpmkExecutor>().lambda()
.eq(SpmkExecutor::getId, approvingDto.getExecutorId()) .eq(SpmkExecutor::getId, approvingDto.getExecutorId())
.eq(SpmkExecutor::getEmpNum, userBean.getEmpNum()) .eq(SpmkExecutor::getEmpNum, userBean.getEmpNum())
.eq(SpmkExecutor::getSts, SpmkEnumInterface.ExecutorSts.IN_EXECUTION.ordinal())) == 0) { .eq(SpmkExecutor::getSts, ExecutorSts.IN_EXECUTION.ordinal())) == 0) {
Integer adminNum = new LambdaQueryChainWrapper<QyzxEmpEntAsso>(qyzxEmpEntAssoMapper) Integer adminNum = new LambdaQueryChainWrapper<QyzxEmpEntAsso>(qyzxEmpEntAssoMapper)
.eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum()) .eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum())
...@@ -714,6 +777,7 @@ public class SpmkController { ...@@ -714,6 +777,7 @@ public class SpmkController {
.count(); .count();
if (adminNum <= 0) { if (adminNum <= 0) {
redisUtil.set(asId.toString(),0,500);
return ResultUtil.error("非当前审批人 或 管理员,无法操作!"); return ResultUtil.error("非当前审批人 或 管理员,无法操作!");
} }
...@@ -741,7 +805,7 @@ public class SpmkController { ...@@ -741,7 +805,7 @@ public class SpmkController {
.select(SpmkApproveSummary::getSts,SpmkApproveSummary::getAssoType) .select(SpmkApproveSummary::getSts,SpmkApproveSummary::getAssoType)
.eq(SpmkApproveSummary::getId, asId)); .eq(SpmkApproveSummary::getId, asId));
if (aSummary.getSts() != SpmkEnumInterface.ApproveSummarySts.REFUSE.ordinal()) { if (aSummary.getSts() != ApproveSummarySts.REFUSE.ordinal()) {
SpmkApproveSummary.builder().id(asId).currentApprover(CommonEnum.NULL_STR.getDesc()).endTime(new Date()).sts(ApproveSummarySts.FINISH.ordinal()).build().updateById(); SpmkApproveSummary.builder().id(asId).currentApprover(CommonEnum.NULL_STR.getDesc()).endTime(new Date()).sts(ApproveSummarySts.FINISH.ordinal()).build().updateById();
JSONObject jSONObject = jsonObject.parseObject(ad.getRequestData(),JSONObject.class); JSONObject jSONObject = jsonObject.parseObject(ad.getRequestData(),JSONObject.class);
...@@ -758,8 +822,10 @@ public class SpmkController { ...@@ -758,8 +822,10 @@ public class SpmkController {
} }
}else { }else {
redisUtil.set(asId.toString(),0,500);
return ResultUtil.error("该审批已结束!"); return ResultUtil.error("该审批已结束!");
} }
redisUtil.set(asId.toString(),0,500);
return ResultUtil.success(); return ResultUtil.success();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment