Jelajahi Sumber

留宿申请通知家长

dzx 11 bulan lalu
induk
melakukan
0ac305d536

+ 76 - 23
src/main/java/com/xjrsoft/module/liteflow/node/WfRoomApplicantNode.java

@@ -1,23 +1,34 @@
 package com.xjrsoft.module.liteflow.node;
 
 import cn.hutool.core.convert.Convert;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.xjrsoft.common.enums.RoomApplicantTypeEnum;
 import com.xjrsoft.common.enums.StudyStatusEnum;
+import com.xjrsoft.common.enums.WorkflowApproveType;
 import com.xjrsoft.module.hikvision.entity.HikvisionData;
 import com.xjrsoft.module.hikvision.mapper.HikvisionDataMapper;
 import com.xjrsoft.module.hikvision.util.DataUtil;
 import com.xjrsoft.module.room.entity.WfRoomApplicant;
-import com.xjrsoft.module.room.mapper.WfRoomApplicantMapper;
+import com.xjrsoft.module.room.service.IWfRoomApplicantService;
 import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
 import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
+import com.xjrsoft.module.workflow.entity.WorkflowRecord;
+import com.xjrsoft.module.workflow.mapper.WorkflowRecordMapper;
+import com.xjrsoft.module.workflow.service.IWorkflowExecuteService;
 import com.yomahub.liteflow.core.NodeComponent;
+import org.apache.commons.lang.StringUtils;
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.support.TransactionSynchronization;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
 
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
 
 /**
  * 学生住宿申请后,修改学籍信息中的就读方式
@@ -25,12 +36,15 @@ import java.util.Map;
 @Component("wf_room_applicant_node")
 public class WfRoomApplicantNode extends NodeComponent {
     @Autowired
-    private WfRoomApplicantMapper wfRoomApplicantMapper;
+    private IWfRoomApplicantService wfRoomApplicantService;
     @Autowired
     private IBaseStudentSchoolRollService studentSchoolRollService;
-
     @Autowired
     private HikvisionDataMapper hikvisionDataMapper;
+    @Autowired
+    private IWorkflowExecuteService workflowExecuteService;
+    @Autowired
+    private WorkflowRecordMapper workflowRecordMapper;
 
     @Override
     public void process() throws Exception {
@@ -38,27 +52,66 @@ public class WfRoomApplicantNode extends NodeComponent {
         Map<String, Object> params = this.getFirstContextBean();
         Object value = util.getFormDatKey(params,"id");
         Long formId = Convert.toLong(value);
-        if (formId != null) {
-            //查询出数据
-            WfRoomApplicant wfRoomApplicant = wfRoomApplicantMapper.selectById(formId);
-            BaseStudentSchoolRoll schoolRoll = studentSchoolRollService.getOne(
-                new QueryWrapper<BaseStudentSchoolRoll>().lambda()
-                .eq(BaseStudentSchoolRoll::getUserId, wfRoomApplicant.getApplicantUserId())
-            );
-            if(RoomApplicantTypeEnum.ToBeBoarder.getCode().equals(wfRoomApplicant.getRecedeType())){
-                schoolRoll.setStduyStatus(StudyStatusEnum.InResidence.getCode());
-            }else if(RoomApplicantTypeEnum.ToBeDayPupil.getCode().equals(wfRoomApplicant.getRecedeType())){
-                schoolRoll.setStduyStatus(StudyStatusEnum.AttendDaySchool.getCode());
-            }
-            //修改学生班级
-            studentSchoolRollService.updateById(schoolRoll);
+        Object processInstanceId = params.get("processInstanceId");
+        if (processInstanceId == null) {
+            return;
+        }
+        String processInstanceIdStr = Convert.toStr(processInstanceId);
+        if (formId != null && StringUtils.isNotEmpty(processInstanceIdStr)) {
+            TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
+                @Override
+                public void afterCommit() {
+                    CompletableFuture.runAsync(() -> {
+                        Optional<HistoricProcessInstance> historicProcessInstanceOptional = workflowExecuteService.getHistoricProcessInstance(processInstanceId.toString());
+
+                        if (historicProcessInstanceOptional.isEmpty()) {
+                            return;
+                        }
+                        HistoricProcessInstance historicProcessInstance = historicProcessInstanceOptional.get();
+                        if (!historicProcessInstance.getState().equals(HistoricProcessInstance.STATE_ACTIVE)) {
+                            // 获取流程记录中的非正常结束
+                            LambdaQueryWrapper<WorkflowRecord> workflowRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                            workflowRecordLambdaQueryWrapper
+                                    .and(wq -> wq.eq(WorkflowRecord::getWorkflowApproveType, WorkflowApproveType.DISAGREE.getCode())
+                                            .or()
+                                            .eq(WorkflowRecord::getWorkflowApproveType, WorkflowApproveType.WITHDRAW.getCode())
+                                    )
+                                    .eq(WorkflowRecord::getProcessId, processInstanceId)
+                            ;
+                            List<WorkflowRecord> workflowRecordList = workflowRecordMapper.selectList(workflowRecordLambdaQueryWrapper);
+
+                            if (!workflowRecordList.isEmpty()) {
+                                return;
+                            }
+                        }
+                        //查询出数据
+                        WfRoomApplicant wfRoomApplicant = wfRoomApplicantService.getById(formId);
+                        BaseStudentSchoolRoll schoolRoll = studentSchoolRollService.getOne(
+                                new QueryWrapper<BaseStudentSchoolRoll>().lambda()
+                                        .eq(BaseStudentSchoolRoll::getUserId, wfRoomApplicant.getApplicantUserId())
+                        );
+                        if(RoomApplicantTypeEnum.ToBeBoarder.getCode().equals(wfRoomApplicant.getRecedeType())){
+                            schoolRoll.setStduyStatus(StudyStatusEnum.InResidence.getCode());
+                        }else if(RoomApplicantTypeEnum.ToBeDayPupil.getCode().equals(wfRoomApplicant.getRecedeType())){
+                            schoolRoll.setStduyStatus(StudyStatusEnum.AttendDaySchool.getCode());
+                        }
+                        //修改学生班级
+                        studentSchoolRollService.updateById(schoolRoll);
 
-            String tableName = "base_student";
-            List<HikvisionData> studentList = hikvisionDataMapper.selectList(
-                    new QueryWrapper<HikvisionData>().lambda().eq(HikvisionData::getTableName, tableName)
-            );
-            DataUtil dataUtil = new DataUtil();
-            dataUtil.insertStudentOne(tableName, new HashMap<>(), studentList, wfRoomApplicant.getApplicantUserId());
+                        String tableName = "base_student";
+                        List<HikvisionData> studentList = hikvisionDataMapper.selectList(
+                                new QueryWrapper<HikvisionData>().lambda().eq(HikvisionData::getTableName, tableName)
+                        );
+                        DataUtil dataUtil = new DataUtil();
+                        try {
+                            dataUtil.insertStudentOne(tableName, new HashMap<>(), studentList, wfRoomApplicant.getApplicantUserId());
+                        } catch (InterruptedException e) {
+                            throw new RuntimeException(e);
+                        }
+                        wfRoomApplicantService.noticeParents(formId);
+                    });
+                }
+            });
         }
     }
 }

+ 2 - 0
src/main/java/com/xjrsoft/module/room/service/IWfRoomApplicantService.java

@@ -12,4 +12,6 @@ import com.xjrsoft.module.room.entity.WfRoomApplicant;
 
 public interface IWfRoomApplicantService extends MPJBaseService<WfRoomApplicant> {
     Boolean dataHandle(Long formId);
+
+    Boolean noticeParents(Long id);
 }

+ 62 - 0
src/main/java/com/xjrsoft/module/room/service/impl/WfRoomApplicantServiceImpl.java

@@ -1,10 +1,21 @@
 package com.xjrsoft.module.room.service.impl;
 
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.RoomApplicantTypeEnum;
 import com.xjrsoft.common.enums.StudyStatusEnum;
+import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.base.entity.BaseClass;
+import com.xjrsoft.module.base.service.IBaseClassService;
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.entity.UserStudent;
+import com.xjrsoft.module.organization.service.IUserService;
+import com.xjrsoft.module.organization.service.IWeChatService;
 import com.xjrsoft.module.room.entity.WfRoomApplicant;
 import com.xjrsoft.module.room.mapper.WfRoomApplicantMapper;
 import com.xjrsoft.module.room.service.IWfRoomApplicantService;
@@ -14,6 +25,9 @@ import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.text.SimpleDateFormat;
+import java.util.List;
+
 /**
 * @title: 寝室申请
 * @Author dzx
@@ -25,6 +39,13 @@ import org.springframework.transaction.annotation.Transactional;
 public class WfRoomApplicantServiceImpl extends MPJBaseServiceImpl<WfRoomApplicantMapper, WfRoomApplicant> implements IWfRoomApplicantService {
 
     private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;
+
+    private final IUserService userService;
+
+    private final IBaseClassService classService;
+
+    private final IWeChatService weChatService;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean dataHandle(Long formId) {
@@ -57,4 +78,45 @@ public class WfRoomApplicantServiceImpl extends MPJBaseServiceImpl<WfRoomApplica
 
         return true;
     }
+
+    @Override
+    public Boolean noticeParents(Long id) {
+        WfRoomApplicant applicant = this.getById(id);
+        List<User> list = userService.list(
+                new MPJLambdaWrapper<User>()
+                        .select(User::getId)
+                        .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                        .innerJoin(UserStudent.class, UserStudent::getUserId, User::getId)
+                        .eq(UserStudent::getStudentId, applicant.getApplicantUserId())
+                        .isNotNull(User::getOpenId)
+        );
+        SimpleDateFormat sdf = new SimpleDateFormat("yyy年MM月dd日");
+
+        User student = userService.getById(applicant.getApplicantUserId());
+        BaseClass aClass = classService.getById(applicant.getClassName());
+        String wechatTemplate = "pbggflZY985uimp9XQ0pe3-GftuPyF7fG5jCo97_jJU";
+        for (User user : list) {
+            WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
+            weChatSendMessageDto.setUserId(user.getOpenId());
+            weChatSendMessageDto.setTemplateId(wechatTemplate);
+            weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
+
+            JSONObject data = new JSONObject();
+            // 姓名
+            data.put("thing1", new JSONObject() {{
+                put("value", student.getName());
+            }});
+            // 时间
+            data.put("time3", new JSONObject() {{
+                put("value", sdf.format(applicant.getStartTime()));
+            }});
+            //班级
+            data.put("thing2", new JSONObject() {{
+                put("value", aClass.getName());
+            }});
+            weChatSendMessageDto.setContent(data);
+            weChatService.sendTemplateMessage(weChatSendMessageDto);
+        }
+        return true;
+    }
 }