Commit 002af6b3 by 翁国栋

删除审批人

parent 2acffa17
......@@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.SerializationUtils;
import com.beust.jcommander.internal.Lists;
import net.sf.json.JSONArray;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
......@@ -1274,7 +1275,9 @@ public class SpmkController {
SpmkApproveSummary.builder().sts(0).id(spmkApproveDetailSummary.getApproveSummaryId()).build().updateById();
}
// 更新 flowChildren
SpmkApproveDetailSummary.builder().id(spmkApproveDetailDto.getId())
.flowChildren(JSONArray.fromObject(listFlowChildren).toString()).build().updateById();
} catch (Exception e) {
......@@ -1287,108 +1290,275 @@ public class SpmkController {
return ResultUtil.data(JSON.toJSONString(detailSummary));
}
//移除审批人
//移除审批人 1.0
// @Transactional(rollbackFor = Exception.class)
// @PostMapping(value = "/delteApprove")
// @ApiOperation(value = "移除审批人", httpMethod = "POST", notes = "")
// public Result<Object> delteApprove(@CurrentUser UserBean userBean, @Validated @RequestBody SpmkApproveDetailDto spmkApproveDetailDto) {
//// try {
//
// SpmkApproveDetailSummary spmkApproveDetailSummary = SpmkApproveDetailSummary.builder().id(spmkApproveDetailDto.getId()).build().selectById();
// List<FlowChildren> listFlowChildren = spmkApproveDetailDto.getFlowChildren();
// //是否执行到下一个节点
// boolean onlyOne = false;//是否只有一条
// boolean isExecute = false;//是否执行中
// boolean isAbreas = false;//是否并序
// boolean isFinal = false;//是否最终审批人
// boolean isNext = false;//是否轮到下一个节点
// User u;
// //当前节点
// FlowChildren currentChildren = listFlowChildren.get(spmkApproveDetailDto.getIndex());
// List<User> userList = currentChildren.getRelation().get(0).getUsers();
// User currentUser = userList.get(spmkApproveDetailDto.getUserIndex());
// //只有添加审批人才会有值
// if (spmkApproveDetailDto.getIndex() != null && spmkApproveDetailDto.getUserIndex() != null) {
// if (currentChildren.getClassName().equals("audit")) {
// //如果是并序
// if ("1".equals(currentChildren.getRelation().get(0).getApprovalOrder())) {
// isAbreas = true;
// }
// //如果只有一个人
// if (userList.size() == 1) {
// onlyOne = true;
// isNext=true;
// }
// if (currentChildren.getExecute().equals("1")) {
// isExecute = true;
// if (userList.get(spmkApproveDetailDto.getUserIndex()).getExecute().equals("1")) {
// //如果是最后一个
// if (userList.size() - 1 == spmkApproveDetailDto.getUserIndex() && !isAbreas) {
// isNext = true;
// }
// //出了自己其他人都审批过了
// if (isAbreas) {
// int num = currentChildren.getRelation().get(0).getUsers().stream().filter(v -> v.getExecute().equals("1") && v.getId() != currentUser.getId()).collect(Collectors.toList()).size();
// if (num == 0) {
// isNext = true;
// }
// }
// } else {
// isExecute = false;
// }
// }
// //是否最终审批人
// if (spmkApproveDetailDto.getIndex() == listFlowChildren.size() - 1) {
// if (isNext || onlyOne) {
// isFinal = true;
// }
// } else if (!listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getClassName().equals("audit")) {
// isFinal = true;
// }
//
// SpmkApproveExecuteRecord spmkApproveExecuteRecord = spmkApproveExecuteRecordMapper.selectExecuteRecordById(Integer.parseInt(currentUser.getId()), spmkApproveDetailSummary.getApproveSummaryId());
// //删除审批过的人记录
// if (spmkApproveExecuteRecord != null) {
// if (onlyOne) {
// spmkApproveExecuteRecordMapper.delExecuteRecordByRecordIds(spmkApproveExecuteRecord.getId(), Integer.parseInt(currentUser.getId()));
// } else {
// List<SpmkExecutor> spmkExecutorsList=SpmkExecutor.builder().build().selectList(new LambdaQueryWrapper<SpmkExecutor>()
// .eq(SpmkExecutor::getApproveExecuteRecordId,spmkApproveExecuteRecord.getId()));
// if(spmkExecutorsList.size()>0&&spmkExecutorsList.size()==1){
// spmkApproveExecuteRecordMapper.delExecuteRecordByRecordIds(spmkApproveExecuteRecord.getId(), Integer.parseInt(currentUser.getId()));
// }else{
// spmkExecutorsList.stream().filter(v->v.getEmpNum()==Integer.parseInt(currentUser.getId())).collect(Collectors.toList()).get(0).deleteById();
// }
// }
// }
// if (isExecute && !isFinal) {
// if (!isAbreas) {
// if (isNext) {
// listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).setExecute("1");
// listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().get(0).setExecute("1");
// //并序
// u = listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().get(0);
// } else {
// listFlowChildren.get(spmkApproveDetailDto.getIndex()).setExecute("1");
// listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().get(spmkApproveDetailDto.getUserIndex() + 1).setExecute("1");
// u = listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().get(spmkApproveDetailDto.getUserIndex() + 1);
// }
//
// if (onlyOne || isNext) {
// spmkApproveExecuteRecord = SpmkApproveExecuteRecord
// .builder()
// .approveSummaryId(spmkApproveDetailSummary.getApproveSummaryId())
// .name(SpmkEnumInterface.ParticipatorType.APPROVER.getName())
// .type(SpmkEnumInterface.ParticipatorType.APPROVER.ordinal())
// .sts(SpmkEnumInterface.ExecuteRecordSts.IN_EXECUTION.ordinal())
// .build();
// spmkApproveExecuteRecord.insert();
// }
// SpmkExecutor.builder()
// .approveExecuteRecordId(spmkApproveExecuteRecord.getId())
// .empNum(Integer.parseInt(u.getId()))
// .operatorHeaderUrl(u.getHeadUrl())
// .executorName(u.getName())
// .sts(1)
// .build().insert();
// SpmkApproveSummary.builder().currentApprover(u.getName()).id(spmkApproveDetailSummary.getApproveSummaryId()).build().updateById();
// } else {
// //并序
// if (isNext) {
// FlowChildren nextFlowChildren = listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1);
// if (nextFlowChildren.getRelation().get(0).getApprovalOrder().equals("1")) {
// listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).setExecute("1");
// listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().forEach(v -> {
// v.setExecute("1");
// SpmkApproveExecuteRecord spmkApproveExecuteRecord1 = SpmkApproveExecuteRecord
// .builder()
// .approveSummaryId(spmkApproveDetailSummary.getApproveSummaryId())
// .name(SpmkEnumInterface.ParticipatorType.APPROVER.getName())
// .type(SpmkEnumInterface.ParticipatorType.APPROVER.ordinal())
// .sts(SpmkEnumInterface.ExecuteRecordSts.IN_EXECUTION.ordinal())
// .build();
// spmkApproveExecuteRecord1.insert();
// SpmkExecutor.builder()
// .approveExecuteRecordId(spmkApproveExecuteRecord1.getId())
// .empNum(Integer.parseInt(v.getId()))
// .operatorHeaderUrl(v.getHeadUrl())
// .executorName(v.getName())
// .sts(1)
// .build().insert();
// });
// SpmkApproveSummary.builder().currentApprover(nextFlowChildren.getRelation().get(0).getUsers().get(0).getName()).id(spmkApproveDetailSummary.getApproveSummaryId()).build().updateById();
// }
// }
// }
// }
//
//
// if (isExecute && isFinal) {
// SpmkApproveSummary.builder().id(spmkApproveDetailSummary.getApproveSummaryId()).currentApprover(CommonEnum.NULL_STR.getDesc()).endTime(new Date()).sts(ApproveSummarySts.FINISH.ordinal()).build().updateById();
// }
//
// if (onlyOne) {
// listFlowChildren.removeIf(f -> f == currentChildren);
// } else {
// listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().removeIf(user -> user == currentUser);
// }
// }
// }
// // 更新 flowChildren
// SpmkApproveDetailSummary.builder().id(spmkApproveDetailDto.getId())
// .flowChildren(JSONArray.fromObject(listFlowChildren).toString()).build().updateById();
//// } catch (Exception e) {
//// return ResultUtil.error(e);
//// }
//
// SpmkApproveDetailSummary detailSummary = SpmkApproveDetailSummary.builder().build().selectOne(new QueryWrapper<SpmkApproveDetailSummary>()
// .lambda().eq(SpmkApproveDetailSummary::getId, spmkApproveDetailDto.getId()));
//
// return ResultUtil.data(JSON.toJSONString(detailSummary));
// }
@Transactional(rollbackFor = Exception.class)
@PostMapping(value = "/delteApprove")
@ApiOperation(value = "移除审批人", httpMethod = "POST", notes = "")
public Result<Object> delteApprove(@CurrentUser UserBean userBean, @Validated @RequestBody SpmkApproveDetailDto spmkApproveDetailDto) {
// try {
SpmkApproveDetailSummary spmkApproveDetailSummary = SpmkApproveDetailSummary.builder().id(spmkApproveDetailDto.getId()).build().selectById();
List<FlowChildren> listFlowChildren = spmkApproveDetailDto.getFlowChildren();
FlowChildren currentFlowChildren = listFlowChildren.get(spmkApproveDetailDto.getIndex());
List<User> currentUserList = currentFlowChildren.getRelation().get(0).getUsers();
User currentUser = currentUserList.get(spmkApproveDetailDto.getUserIndex());
//是否执行到下一个节点
boolean onlyOne = false;
boolean onlyOne = false;//是否只有一条
boolean isExecute = false;//是否执行中
boolean isAbreas = false;//是否并序
boolean isFinal = false;//是否最终审批人
boolean isNext = false;
User u;
//当前节点
FlowChildren currentChildren = listFlowChildren.get(spmkApproveDetailDto.getIndex());
List<User> userList = currentChildren.getRelation().get(0).getUsers();
User currentUser = userList.get(spmkApproveDetailDto.getUserIndex());
//只有添加审批人才会有值
if (spmkApproveDetailDto.getIndex() != null && spmkApproveDetailDto.getUserIndex() != null) {
if (currentChildren.getClassName().equals("audit")) {
boolean isNext = false;//是否轮到下一个节点
StringBuffer buffer = new StringBuffer();//新当前审批人的名字
if ("1".equals(currentFlowChildren.getRelation().get(0).getApprovalOrder())) {
isAbreas = true;
}
//如果只有一个人
if (userList.size() == 1) {
if (currentUserList.size() == 1) {
onlyOne = true;
isNext = true;
}
if (currentChildren.getExecute().equals("1")) {
//大节点在执行中
if (currentFlowChildren.getExecute().equals("1")) {
//小节点也在执行中
isExecute = true;
if (userList.get(spmkApproveDetailDto.getUserIndex()).getExecute().equals("1")) {
//如果是最后一个
if (userList.size() - 1 == spmkApproveDetailDto.getUserIndex()) {
if (currentUser.getExecute().equals("1")) {
if (isAbreas) {
if (currentUserList.stream().filter(u -> u.getId() != currentUser.getId() && u.getExecute().equals("1")).collect(Collectors.toList()).size() == 0) {
isNext = true;
}
} else {
if (currentUserList.size() - 1 == spmkApproveDetailDto.getUserIndex()) {
isNext = true;
}
}
} else {
isExecute = false;
}
}
//是否最终审批人
if (spmkApproveDetailDto.getIndex() == listFlowChildren.size() - 1) {
if (isNext || onlyOne) {
//如果属于最后一个大节点
if (listFlowChildren.size() - 1 == spmkApproveDetailDto.getIndex()) {
if (isNext) {
isFinal = true;
} else {
isFinal = false;
}
} else if (!listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getClassName().equals("audit")) {
} else if (listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getClassName().equals("copy")) {
isFinal = true;
}
//如果是并序
if ("1".equals(currentChildren.getRelation().get(0).getApprovalOrder())) {
isAbreas = true;
}
//执行中的人会存在操作记录
SpmkApproveExecuteRecord spmkApproveExecuteRecord = spmkApproveExecuteRecordMapper.selectExecuteRecordById(Integer.parseInt(currentUser.getId()), spmkApproveDetailSummary.getApproveSummaryId());
//删除审批过的人记录
//删除操作人记录
if (spmkApproveExecuteRecord != null) {
if (onlyOne||isAbreas) {
SpmkExecutor spmkExecutor =SpmkExecutor.builder().build().selectOne(new LambdaQueryWrapper<SpmkExecutor>()
.eq(SpmkExecutor::getApproveExecuteRecordId,spmkApproveExecuteRecord.getId()).eq(SpmkExecutor::getEmpNum,currentUser.getId()));
if (onlyOne) {
if(spmkExecutor.getSts()!=4) {
spmkApproveExecuteRecordMapper.delExecuteRecordByRecordIds(spmkApproveExecuteRecord.getId(), Integer.parseInt(currentUser.getId()));
}
} else {
SpmkExecutor spmkExecutor = SpmkExecutor.builder().build().selectOne(new LambdaQueryWrapper<SpmkExecutor>()
.eq(SpmkExecutor::getEmpNum, Integer.parseInt(currentUser.getId())).eq(SpmkExecutor::getApproveExecuteRecordId, spmkApproveExecuteRecord.getId()));
List<SpmkExecutor> spmkExecutorsList = SpmkExecutor.builder().build().selectList(new LambdaQueryWrapper<SpmkExecutor>()
.eq(SpmkExecutor::getApproveExecuteRecordId, spmkApproveExecuteRecord.getId()));
if (isAbreas) {
//正常的并序是一条对应一个id,转派的是同一个id
if (spmkExecutorsList.size() == 1) {
spmkApproveExecuteRecordMapper.delExecuteRecordByRecordIds(spmkApproveExecuteRecord.getId(), Integer.parseInt(currentUser.getId()));
}
}
spmkExecutor.deleteById();
}
}
if (isExecute && !isFinal) {
if (!isAbreas) {
//当前被移除的人在执行中
if (isExecute) {
//如果不是最终的就还存在下一个审批节点
if (!isFinal) {
if (isNext) {
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).setExecute("1");
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().get(0).setExecute("1");
//并序
u = listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().get(0);
} else {
listFlowChildren.get(spmkApproveDetailDto.getIndex()).setExecute("1");
listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().get(spmkApproveDetailDto.getUserIndex() + 1).setExecute("1");
u = listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().get(spmkApproveDetailDto.getUserIndex() + 1);
}
FlowChildren nextFlowChildren = listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1);
//如果下一个节点是并序的
if (nextFlowChildren.getRelation().get(0).getApprovalOrder().equals("1")) {
if (onlyOne || isNext) {
spmkApproveExecuteRecord = SpmkApproveExecuteRecord
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).setExecute("1");
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().forEach(v -> {
v.setExecute("1");
SpmkApproveExecuteRecord spmkApproveExecuteRecord1 = SpmkApproveExecuteRecord
.builder()
.approveSummaryId(spmkApproveDetailSummary.getApproveSummaryId())
.name(SpmkEnumInterface.ParticipatorType.APPROVER.getName())
.type(SpmkEnumInterface.ParticipatorType.APPROVER.ordinal())
.sts(SpmkEnumInterface.ExecuteRecordSts.IN_EXECUTION.ordinal())
.build();
spmkApproveExecuteRecord.insert();
}
spmkApproveExecuteRecord1.insert();
SpmkExecutor.builder()
.approveExecuteRecordId(spmkApproveExecuteRecord.getId())
.empNum(Integer.parseInt(u.getId()))
.operatorHeaderUrl(u.getHeadUrl())
.executorName(u.getName())
.approveExecuteRecordId(spmkApproveExecuteRecord1.getId())
.empNum(Integer.parseInt(v.getId()))
.operatorHeaderUrl(v.getHeadUrl())
.executorName(v.getName())
.sts(1)
.build().insert();
SpmkApproveSummary.builder().currentApprover(u.getName()).id(spmkApproveDetailSummary.getApproveSummaryId()).build().updateById();
buffer.append(v.getName() + ",");
});
buffer.deleteCharAt(buffer.lastIndexOf(","));
} else {
//并序
if (isNext) {
FlowChildren nextFlowChildren = listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1);
if (nextFlowChildren.getRelation().get(0).getApprovalOrder().equals("1")) {
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).setExecute("1");
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().forEach(v -> {
v.setExecute("1");
listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().get(0).setExecute("1");
User u = listFlowChildren.get(spmkApproveDetailDto.getIndex() + 1).getRelation().get(0).getUsers().get(0);
SpmkApproveExecuteRecord spmkApproveExecuteRecord1 = SpmkApproveExecuteRecord
.builder()
.approveSummaryId(spmkApproveDetailSummary.getApproveSummaryId())
......@@ -1399,44 +1569,52 @@ public class SpmkController {
spmkApproveExecuteRecord1.insert();
SpmkExecutor.builder()
.approveExecuteRecordId(spmkApproveExecuteRecord1.getId())
.empNum(Integer.parseInt(v.getId()))
.operatorHeaderUrl(v.getHeadUrl())
.executorName(v.getName())
.empNum(Integer.parseInt(u.getId()))
.operatorHeaderUrl(u.getHeadUrl())
.executorName(u.getName())
.sts(1)
.build().insert();
});
SpmkApproveSummary.builder().currentApprover(nextFlowChildren.getRelation().get(0).getUsers().get(0).getName()).id(spmkApproveDetailSummary.getApproveSummaryId()).build().updateById();
}
buffer.append(u.getName());
}
} else {
if (!isAbreas) {
//顺序有一个同一个user里面的
listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().get(spmkApproveDetailDto.getUserIndex() + 1).setExecute("1");
User u = listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().get(spmkApproveDetailDto.getUserIndex() + 1);
SpmkExecutor.builder()
.approveExecuteRecordId(spmkApproveExecuteRecord.getId())
.empNum(Integer.parseInt(u.getId()))
.operatorHeaderUrl(u.getHeadUrl())
.executorName(u.getName())
.sts(1)
.build().insert();
buffer.append(u.getName());
}
}
if (isFinal) {
SpmkApproveSummary.builder().id(spmkApproveDetailSummary.getApproveSummaryId()).currentApprover(CommonEnum.NULL_STR.getDesc()).endTime(new Date()).sts(ApproveSummarySts.FINISH.ordinal()).build().updateById();
}
if (onlyOne) {
listFlowChildren.removeIf(f -> f == currentChildren);
} else {
listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().removeIf(user -> user == currentUser);
SpmkApproveSummary.builder().currentApprover(buffer.toString()).id(spmkApproveDetailSummary.getApproveSummaryId()).build().updateById();
}
//只有一条数据或者已经到下一个大节点
if (onlyOne && isNext) {
listFlowChildren.removeIf(f -> f == currentFlowChildren);
} else {
listFlowChildren.get(spmkApproveDetailDto.getIndex()).getRelation().get(0).getUsers().removeIf(u -> u == currentUser);
}
//如果是最终执行人
if (isFinal&&isNext&&isExecute) {
SpmkApproveSummary.builder().id(spmkApproveDetailSummary.getApproveSummaryId()).currentApprover(CommonEnum.NULL_STR.getDesc()).endTime(new Date()).sts(ApproveSummarySts.FINISH.ordinal()).build().updateById();
}
// 更新 flowChildren
SpmkApproveDetailSummary.builder().id(spmkApproveDetailDto.getId())
.flowChildren(JSONArray.fromObject(listFlowChildren).toString()).build().updateById();
// } catch (Exception e) {
// return ResultUtil.error(e);
// }
SpmkApproveDetailSummary detailSummary = SpmkApproveDetailSummary.builder().build().selectOne(new QueryWrapper<SpmkApproveDetailSummary>()
.lambda().eq(SpmkApproveDetailSummary::getId, spmkApproveDetailDto.getId()));
return ResultUtil.data(JSON.toJSONString(detailSummary));
}
@PostMapping(value = "/save_drafts")
@ApiOperation(value = "存入草稿箱", httpMethod = "POST", notes = "存入草稿箱")
@Transactional(rollbackFor = Exception.class)
......
......@@ -22,4 +22,6 @@ public interface SpmkApproveExecuteRecordMapper extends BaseMapper<SpmkApproveEx
int delExecuteRecord(@Param("recordId") Integer recordId,@Param("approveSummaryId") Integer approveSummaryId);
SpmkApproveExecuteRecord selectExecuteRecordById(@Param("userId") Integer userId,@Param("approveSummaryId") Integer approveSummaryId);
int delExecuteRecordByRecordIds(@Param("id") Integer id, @Param("uid")Integer uid);
SpmkApproveExecuteRecord selectExecuteRecordReoId(@Param("reoId") Integer reoId,@Param("approveSummaryId") Integer approveSummaryId);
}
......@@ -172,6 +172,12 @@
WHERE sr.approve_summary_id = #{approveSummaryId} and se.emp_num = #{userId}
</select>
<select id="selectExecuteRecordReoId" resultType="cn.timer.api.bean.spmk.SpmkApproveExecuteRecord">
SELECT sr.id FROM spmk_approve_execute_record sr
LEFT JOIN spmk_executor se ON se.approve_execute_record_id=sr.id
WHERE sr.approve_summary_id = #{approveSummaryId} and se.uid = #{reoId}
</select>
<delete id="delExecuteRecord">
DELETE sr,se FROM spmk_approve_execute_record sr
LEFT JOIN spmk_executor se on sr.id=se.approve_execute_record_id
......
......@@ -140,5 +140,9 @@
</select>
-->
<select id="executor" resultMap="BaseResultMap">
select
</select>
</mapper>
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