StudentDropOutNode.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.xjrsoft.module.liteflow.node;
  2. import cn.hutool.core.convert.Convert;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.xjrsoft.common.enums.ArchivesStatusEnum;
  6. import com.xjrsoft.common.enums.DeleteMark;
  7. import com.xjrsoft.common.enums.WorkflowApproveType;
  8. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  9. import com.xjrsoft.module.student.entity.StudentDropOut;
  10. import com.xjrsoft.module.student.mapper.StudentDropOutMapper;
  11. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  12. import com.xjrsoft.module.workflow.entity.WorkflowRecord;
  13. import com.xjrsoft.module.workflow.mapper.WorkflowRecordMapper;
  14. import com.xjrsoft.module.workflow.service.IWorkflowExecuteService;
  15. import com.yomahub.liteflow.core.NodeComponent;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.camunda.bpm.engine.history.HistoricProcessInstance;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Component;
  20. import org.springframework.transaction.support.TransactionSynchronization;
  21. import org.springframework.transaction.support.TransactionSynchronizationManager;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Optional;
  25. import java.util.concurrent.CompletableFuture;
  26. /**
  27. * 学生退学
  28. */
  29. @Component("student_drop_out_node")
  30. public class StudentDropOutNode extends NodeComponent {
  31. @Autowired
  32. private StudentDropOutMapper studentDropOutMapper;
  33. @Autowired
  34. private IBaseStudentSchoolRollService studentSchoolRollService;
  35. @Autowired
  36. private IWorkflowExecuteService workflowExecuteService;
  37. @Autowired
  38. private WorkflowRecordMapper workflowRecordMapper;
  39. @Override
  40. public void process() throws Exception {
  41. // 获取表单中数据编号
  42. Map<String, Object> params = this.getFirstContextBean();
  43. Object value = util.getFormDatKey(params, "id");
  44. Long formId = Convert.toLong(value);
  45. Object processInstanceId = params.get("processInstanceId");
  46. if (processInstanceId == null) {
  47. return;
  48. }
  49. String processInstanceIdStr = Convert.toStr(processInstanceId);
  50. if (formId != null && StringUtils.isNotEmpty(processInstanceIdStr)) {
  51. TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
  52. @Override
  53. public void afterCommit() {
  54. CompletableFuture.runAsync(() -> {
  55. Optional<HistoricProcessInstance> historicProcessInstanceOptional = workflowExecuteService.getHistoricProcessInstance(processInstanceId.toString());
  56. if (historicProcessInstanceOptional.isEmpty()) {
  57. return;
  58. }
  59. HistoricProcessInstance historicProcessInstance = historicProcessInstanceOptional.get();
  60. if (!historicProcessInstance.getState().equals(HistoricProcessInstance.STATE_ACTIVE)) {
  61. // 获取流程记录中的非正常结束
  62. LambdaQueryWrapper<WorkflowRecord> workflowRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
  63. workflowRecordLambdaQueryWrapper
  64. .and(wq -> wq.eq(WorkflowRecord::getWorkflowApproveType, WorkflowApproveType.DISAGREE.getCode())
  65. .or()
  66. .eq(WorkflowRecord::getWorkflowApproveType, WorkflowApproveType.WITHDRAW.getCode())
  67. )
  68. .eq(WorkflowRecord::getProcessId, processInstanceId)
  69. ;
  70. List<WorkflowRecord> workflowRecordList = workflowRecordMapper.selectList(workflowRecordLambdaQueryWrapper);
  71. if (!workflowRecordList.isEmpty()) {
  72. return;
  73. }
  74. }
  75. //查询出数据
  76. StudentDropOut studentDropOut = studentDropOutMapper.selectById(formId);
  77. //跟新学籍信息
  78. BaseStudentSchoolRoll schoolRoll = studentSchoolRollService.getOne(
  79. new QueryWrapper<BaseStudentSchoolRoll>().lambda()
  80. .eq(BaseStudentSchoolRoll::getClassId, studentDropOut.getClassId())
  81. .eq(BaseStudentSchoolRoll::getUserId, studentDropOut.getStudentUserId())
  82. .eq(BaseStudentSchoolRoll::getDeleteMark, DeleteMark.NODELETE.getCode())
  83. );
  84. schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2904.getCode());
  85. studentSchoolRollService.updateById(schoolRoll);
  86. });
  87. }
  88. });
  89. }
  90. }
  91. }