StudentDropOutNode.java 5.9 KB

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