Commit 667b9522 by 翁国栋

管理员审批重复扣除假期余额bug

parent 78b4ac17
......@@ -51,72 +51,73 @@ import java.util.*;
@Api(tags = "3.0Admin审批模块")
@RestController
@Transactional
@RequestMapping(value = "/admin/spmk", produces = { "application/json","multipart/form-data" })
@RequestMapping(value = "/admin/spmk", produces = {"application/json", "multipart/form-data"})
public class AdminSpmkController {
@Autowired
private QyzxEmpEntAssoMapper qyzxEmpEntAssoMapper;
@Autowired
private SpmkApproveSummaryMapper spmkApproveSummaryMapper;
@Autowired
private SpmkExecutorMapper spmkExecutorMapper;
@Autowired
private SpmkAssoBusinessFactory spmkAssoBusinessFactory;
@Autowired
private SpmkApproveExecuteRecordMapper spmkApproveExecuteRecordMapper;
private static com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
@Resource
private RedisUtil redisUtil;
//TODO 管理员审批
/**
* 管理员审批
*/
@PostMapping(value = "/approving")
@ApiOperation(value = "1.审批人审批", httpMethod = "POST", notes = "审批人审批")
@Transactional(rollbackFor = Exception.class)
@ApiOperationSupport(order = 20)
@Log(title = "审批-审批流程", businessType = BusinessType.UPDATE)
public Result<Object> approving(@CurrentUser UserBean userBean,@Validated @RequestBody AdminApprovingDto approvingDto) throws Exception {
/*判断是否有权限转派*/
//if(approvingDto.getSts()==4){
QyzxEmpEntAsso ent = QyzxEmpEntAsso.builder().build().selectOne(new QueryWrapper<QyzxEmpEntAsso>().lambda().eq(QyzxEmpEntAsso::getOrgCode, userBean.getOrgCode()).eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum()));
if(ent != null) {
/*超管和管理员不受权限控制*/
if(ent.getUserType() == 2) {
ZzglAuth zzglAuth = ZzglAuth.builder().build().selectOne(new QueryWrapper<ZzglAuth>().lambda().eq(ZzglAuth::getBmgwId, userBean.getUserInfo().getBmgwId())
.eq(ZzglAuth::getMenuId, "/Approvalspbutonspbuton020102"));
if (zzglAuth == null) {
return ResultUtil.error("您没有权限");
}
}
}
//}
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,2);
}
SpmkApproveDetailSummary ad = SpmkApproveDetailSummary.builder().build().selectOne(new QueryWrapper<SpmkApproveDetailSummary>()
.lambda()
.select(SpmkApproveDetailSummary::getId,
SpmkApproveDetailSummary::getRequestData,
SpmkApproveDetailSummary::getFroms,
SpmkApproveDetailSummary::getFlowChildren)
.eq(SpmkApproveDetailSummary::getApproveSummaryId, asId));
// 查询 SpmkApproveSummary 状态,
SpmkApproveSummary aSummary = spmkApproveSummaryMapper.selectOne(new QueryWrapper<SpmkApproveSummary>().lambda()
.select(SpmkApproveSummary::getSts,SpmkApproveSummary::getAssoType,SpmkApproveSummary::getEmpNum,SpmkApproveSummary::getOrgCode)
.eq(SpmkApproveSummary::getId, asId));
@Autowired
private QyzxEmpEntAssoMapper qyzxEmpEntAssoMapper;
@Autowired
private SpmkApproveSummaryMapper spmkApproveSummaryMapper;
@Autowired
private SpmkExecutorMapper spmkExecutorMapper;
@Autowired
private SpmkAssoBusinessFactory spmkAssoBusinessFactory;
@Autowired
private SpmkApproveExecuteRecordMapper spmkApproveExecuteRecordMapper;
private static com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
@Resource
private RedisUtil redisUtil;
//TODO 管理员审批
/**
* 管理员审批
*/
@PostMapping(value = "/approving")
@ApiOperation(value = "1.审批人审批", httpMethod = "POST", notes = "审批人审批")
@Transactional(rollbackFor = Exception.class)
@ApiOperationSupport(order = 20)
@Log(title = "审批-审批流程", businessType = BusinessType.UPDATE)
public Result<Object> approving(@CurrentUser UserBean userBean, @Validated @RequestBody AdminApprovingDto approvingDto) throws Exception {
/*判断是否有权限转派*/
//if(approvingDto.getSts()==4){
QyzxEmpEntAsso ent = QyzxEmpEntAsso.builder().build().selectOne(new QueryWrapper<QyzxEmpEntAsso>().lambda().eq(QyzxEmpEntAsso::getOrgCode, userBean.getOrgCode()).eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum()));
if (ent != null) {
/*超管和管理员不受权限控制*/
if (ent.getUserType() == 2) {
ZzglAuth zzglAuth = ZzglAuth.builder().build().selectOne(new QueryWrapper<ZzglAuth>().lambda().eq(ZzglAuth::getBmgwId, userBean.getUserInfo().getBmgwId())
.eq(ZzglAuth::getMenuId, "/Approvalspbutonspbuton020102"));
if (zzglAuth == null) {
return ResultUtil.error("您没有权限");
}
}
}
//}
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, 2);
}
SpmkApproveDetailSummary ad = SpmkApproveDetailSummary.builder().build().selectOne(new QueryWrapper<SpmkApproveDetailSummary>()
.lambda()
.select(SpmkApproveDetailSummary::getId,
SpmkApproveDetailSummary::getRequestData,
SpmkApproveDetailSummary::getFroms,
SpmkApproveDetailSummary::getFlowChildren)
.eq(SpmkApproveDetailSummary::getApproveSummaryId, asId));
// 查询 SpmkApproveSummary 状态,
SpmkApproveSummary aSummary = spmkApproveSummaryMapper.selectOne(new QueryWrapper<SpmkApproveSummary>().lambda()
.select(SpmkApproveSummary::getSts, SpmkApproveSummary::getAssoType, SpmkApproveSummary::getEmpNum, SpmkApproveSummary::getOrgCode)
.eq(SpmkApproveSummary::getId, asId));
// if (aSummary.getSts() > ApproveSummarySts.IN.ordinal()) {
// redisUtil.set(asId.toString(),0,500);
......@@ -132,146 +133,151 @@ public class AdminSpmkController {
// redisUtil.set(asId.toString(),0,500);
// return ResultUtil.error("您已审批过!");
// }
//判断是否是请假审批
if(aSummary.getAssoType()==ApproveEnum.LEAVE.getType()){
if(approvingDto.getSts()==2) {
JSONObject jSONObject = jsonObject.parseObject(ad.getRequestData(), JSONObject.class);
// 请假类型 - 前端传中文
String LeaveType = ObjectUtil.isNull(jSONObject.get("__LeaveType", FromData.class)) ? null : jSONObject.get("__LeaveType", FromData.class).getValue();
// 时长
String longTime = ObjectUtil.isNull(jSONObject.get("__longTime", FromData.class)) ? null : jSONObject.get("__longTime", FromData.class).getValue();
//判断这个人假期是否足够
KqglAssoLeaveEmployeeBalance emba = KqglAssoLeaveEmployeeBalance.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveEmployeeBalance>().lambda().eq(KqglAssoLeaveEmployeeBalance::getLeaveRulesId, Convert.toInt(LeaveType))
.eq(KqglAssoLeaveEmployeeBalance::getUserid, aSummary.getEmpNum()).eq(KqglAssoLeaveEmployeeBalance::getOrgCode, aSummary.getOrgCode()));
if (emba != null) {
if (emba.getBalanceDays()!=-1&&emba.getBalanceDays() < Convert.toInt(longTime)) {
return ResultUtil.error("当前发起人假期余额不足");
}
}
}
}
if ( spmkExecutorMapper.selectCount(new QueryWrapper<SpmkExecutor>().lambda()
.eq(SpmkExecutor::getId, approvingDto.getExecutorId())
.eq(SpmkExecutor::getEmpNum, userBean.getEmpNum())
.eq(SpmkExecutor::getSts, ExecutorSts.IN_EXECUTION.ordinal())) == 0) {
Integer adminNum = new LambdaQueryChainWrapper<QyzxEmpEntAsso>(qyzxEmpEntAssoMapper)
.eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum())
.eq(QyzxEmpEntAsso::getOrgCode, userBean.getOrgCode())
.in(QyzxEmpEntAsso::getUserType, SysRoleType.U_TYPE_ADMIN,SysRoleType.U_TYPE_C_ADMIN)
.count();
if (adminNum <= 0) {
redisUtil.set(asId.toString(),0,500);
return ResultUtil.error("非当前审批人 或 管理员,无法操作!");
}
}
//如果是再次审批
SpmkApproveExecuteRecord spmkApproveExecuteRecord = SpmkApproveExecuteRecord.builder().id(approvingDto.getExecuteRecordId()).build().selectById();
if(spmkApproveExecuteRecord.getSts()>1){
spmkApproveExecuteRecordMapper.delExecuteRecord(approvingDto.getExecuteRecordId(), asId);
}
List<FlowChildren> listFlowChildren = jsonObject.parseArray(ad.getFlowChildren(),FlowChildren.class);
RouterUtils.updateRefuseToAgree(
listFlowChildren,
asId,
approvingDto.getExecuteRecordId(),
approvingDto.getExecutorId(),
approvingDto.getOpinion(),
approvingDto.getSts(),
aSummary.getSts(),
approvingDto.getUser(),
approvingDto.getSignatureImg(),
userBean.getEmpNum(),
approvingDto.getUserList(),
approvingDto.getTypeIndex(),
approvingDto.getUserIndex()
);
listFlowChildren.forEach(l->{
//如果大节点已经完成
if(l.getClassName().equals("audit")){
if(l.getExecute().equals("2")){
l.getRelation().get(0).getUsers().forEach(v->{
if(!v.getExecute().equals("2")){
v.setExecute("2");
}
});
}else if(l.getExecute().equals("1")){
//大节点未执行完
}
}
});
// 更新 flowChildren
SpmkApproveDetailSummary sadsUpdate = SpmkApproveDetailSummary.builder().id(ad.getId()).flowChildren(JSONArray.fromObject(listFlowChildren).toString()).build();
//判断是否是请假审批
if (aSummary.getAssoType() == ApproveEnum.LEAVE.getType()) {
if (approvingDto.getSts() == 2) {
JSONObject jSONObject = jsonObject.parseObject(ad.getRequestData(), JSONObject.class);
// 请假类型 - 前端传中文
String LeaveType = ObjectUtil.isNull(jSONObject.get("__LeaveType", FromData.class)) ? null : jSONObject.get("__LeaveType", FromData.class).getValue();
// 时长
String longTime = ObjectUtil.isNull(jSONObject.get("__longTime", FromData.class)) ? null : jSONObject.get("__longTime", FromData.class).getValue();
//判断这个人假期是否足够
KqglAssoLeaveEmployeeBalance emba = KqglAssoLeaveEmployeeBalance.builder().build().selectOne(new QueryWrapper<KqglAssoLeaveEmployeeBalance>().lambda().eq(KqglAssoLeaveEmployeeBalance::getLeaveRulesId, Convert.toInt(LeaveType))
.eq(KqglAssoLeaveEmployeeBalance::getUserid, aSummary.getEmpNum()).eq(KqglAssoLeaveEmployeeBalance::getOrgCode, aSummary.getOrgCode()));
if (emba != null) {
if (emba.getBalanceDays() != -1 && emba.getBalanceDays() < Convert.toInt(longTime)) {
return ResultUtil.error("当前发起人假期余额不足");
}
}
}
}
if (spmkExecutorMapper.selectCount(new QueryWrapper<SpmkExecutor>().lambda()
.eq(SpmkExecutor::getId, approvingDto.getExecutorId())
.eq(SpmkExecutor::getEmpNum, userBean.getEmpNum())
.eq(SpmkExecutor::getSts, ExecutorSts.IN_EXECUTION.ordinal())) == 0) {
Integer adminNum = new LambdaQueryChainWrapper<QyzxEmpEntAsso>(qyzxEmpEntAssoMapper)
.eq(QyzxEmpEntAsso::getEmpNum, userBean.getEmpNum())
.eq(QyzxEmpEntAsso::getOrgCode, userBean.getOrgCode())
.in(QyzxEmpEntAsso::getUserType, SysRoleType.U_TYPE_ADMIN, SysRoleType.U_TYPE_C_ADMIN)
.count();
if (adminNum <= 0) {
redisUtil.set(asId.toString(), 0, 500);
return ResultUtil.error("非当前审批人 或 管理员,无法操作!");
}
}
//如果是再次审批
SpmkApproveExecuteRecord spmkApproveExecuteRecord = SpmkApproveExecuteRecord.builder().id(approvingDto.getExecuteRecordId()).build().selectById();
if (spmkApproveExecuteRecord.getSts() > 1) {
spmkApproveExecuteRecordMapper.delExecuteRecord(approvingDto.getExecuteRecordId(), asId);
}
List<FlowChildren> listFlowChildren = jsonObject.parseArray(ad.getFlowChildren(), FlowChildren.class);
RouterUtils.updateRefuseToAgree(
listFlowChildren,
asId,
approvingDto.getExecuteRecordId(),
approvingDto.getExecutorId(),
approvingDto.getOpinion(),
approvingDto.getSts(),
aSummary.getSts(),
approvingDto.getUser(),
approvingDto.getSignatureImg(),
userBean.getEmpNum(),
approvingDto.getUserList(),
approvingDto.getTypeIndex(),
approvingDto.getUserIndex()
);
listFlowChildren.forEach(l -> {
//如果大节点已经完成
if (l.getClassName().equals("audit")) {
if (l.getExecute().equals("2")) {
l.getRelation().get(0).getUsers().forEach(v -> {
if (!v.getExecute().equals("2")) {
v.setExecute("2");
}
});
} else if (l.getExecute().equals("1")) {
//大节点未执行完
}
}
});
// 更新 flowChildren
SpmkApproveDetailSummary sadsUpdate = SpmkApproveDetailSummary.builder().id(ad.getId()).flowChildren(JSONArray.fromObject(listFlowChildren).toString()).build();
/*// 审批详情 审批时添加 附件
if(RequestDataUtils.addFileList(ad,approvingDto.getFileList())){
sadsUpdate.setRequestData(ad.getRequestData());
}*/
sadsUpdate.updateById();
sadsUpdate.updateById();
//最后一条数据
FlowChildren fc = CollUtil.getLast(listFlowChildren);
//最后一条数据
FlowChildren fc = CollUtil.getLast(listFlowChildren);
/** TODO:每次审批都校验一次json是否正确
* 1.验证当前流程是否已完成,如果已完成验证是否有子节点出现未完成的状态
* 2.验证当前节点上面的节点是否已完成,未完成的都改为已完成
* 3.验证当前流程是否全部完成,如果已经完成,修改所有的节点为已完成
* 4.验证当前节点
*/
/** TODO:每次审批都校验一次json是否正确
* 1.验证当前流程是否已完成,如果已完成验证是否有子节点出现未完成的状态
* 2.验证当前节点上面的节点是否已完成,未完成的都改为已完成
* 3.验证当前流程是否全部完成,如果已经完成,修改所有的节点为已完成
* 4.验证当前节点
*/
if (fc.getExecute() == "2") {
// 查询 SpmkApproveSummary 状态
aSummary = spmkApproveSummaryMapper.selectOne(new QueryWrapper<SpmkApproveSummary>().lambda()
.select(SpmkApproveSummary::getSts,SpmkApproveSummary::getAssoType)
.eq(SpmkApproveSummary::getId, asId));
if (fc.getExecute() == "2") {
//未更新sts前
int lastSts = aSummary.getSts();
// 查询 SpmkApproveSummary 状态
aSummary = spmkApproveSummaryMapper.selectOne(new QueryWrapper<SpmkApproveSummary>().lambda()
.select(SpmkApproveSummary::getSts, SpmkApproveSummary::getAssoType, SpmkApproveSummary::getEmpNum, SpmkApproveSummary::getOrgCode)
.eq(SpmkApproveSummary::getId, asId));
// if (aSummary.getSts() != ApproveSummarySts.REFUSE.ordinal()) {
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.set("approveId", FromData.builder().value(String.valueOf(asId)).build());
jSONObject.set("orgCode", userBean.getOrgCode());
//审批完成后 业务
SpmkAssoBusiness sab = spmkAssoBusinessFactory.createSpmkService(ApproveEnum.getEnums(aSummary.getAssoType()));
if (sab != null){
log.info("1----------{}",sab);
}
log.info("2----------{}", jSONObject);
sab.handleApprove(jSONObject);
}
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.set("approveId", FromData.builder().value(String.valueOf(asId)).build());
jSONObject.set("orgCode", userBean.getOrgCode());
//如果请假审批,并且上一次是同意这次重复同意不会扣除假期余额
if (aSummary.getAssoType() == ApproveEnum.LEAVE.getType() && Integer.parseInt(fc.getExecute()) == lastSts) {
} else {
//审批完成后 业务
SpmkAssoBusiness sab = spmkAssoBusinessFactory.createSpmkService(ApproveEnum.getEnums(aSummary.getAssoType()));
if (sab != null) {
log.info("1----------{}", sab);
}
log.info("2----------{}", jSONObject);
sab.handleApprove(jSONObject);
}
}
// }
// }else {
// redisUtil.set(asId.toString(),0,500);
// return ResultUtil.error("该审批已结束!");
// }
redisUtil.set(asId.toString(),0,500);
return ResultUtil.success();
}
/**
* 删除-考核模板
redisUtil.set(asId.toString(), 0, 500);
return ResultUtil.success();
}
/**
* 删除-考核模板
@DeleteMapping(value = "/del_appraisal_t/{id}")
@ApiOperation(value = "2.移除-审批人", httpMethod = "DELETE", notes = "移除-审批人")
@ApiOperationSupport(order = 6)
@Role
public Result<Object> delAT(@CurrentUser UserBean userBean,@Validated @RequestBody AdminApprovingDto approvingDto) throws Exception {
@DeleteMapping(value = "/del_appraisal_t/{id}")
@ApiOperation(value = "2.移除-审批人", httpMethod = "DELETE", notes = "移除-审批人")
@ApiOperationSupport(order = 6)
@Role public Result<Object> delAT(@CurrentUser UserBean userBean,@Validated @RequestBody AdminApprovingDto approvingDto) throws Exception {
jxglAppraisalTMapper.delete(new QueryWrapper<JxglAppraisalT>().lambda().eq(JxglAppraisalT::getId, id)
.eq(JxglAppraisalT::getOrgCode, userBean.getOrgCode()));
jxglAppraisalTMapper.delete(new QueryWrapper<JxglAppraisalT>().lambda().eq(JxglAppraisalT::getId, id)
.eq(JxglAppraisalT::getOrgCode, userBean.getOrgCode()));
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