瀏覽代碼

学生出入权限调整

dzx 1 年之前
父節點
當前提交
f3af706c9c

+ 1 - 1
src/main/java/com/xjrsoft/module/job/InsertOutInRecordTask.java

@@ -27,7 +27,7 @@ public class InsertOutInRecordTask {
     @Autowired
     private IHikvisionDataService hikvisionDataService;
 
-    @Scheduled(cron = "0 30 * * * ?")
+    @Scheduled(cron = "0 */30 * * * ?")
     public void execute() {
         String active = SpringUtil.getActiveProfile();
         if(!"prod".equals(active)){

+ 120 - 0
src/main/java/com/xjrsoft/module/job/StudentDropOutTask.java

@@ -0,0 +1,120 @@
+package com.xjrsoft.module.job;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.xjrsoft.common.enums.ArchivesStatusEnum;
+import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
+import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
+import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.hikvision.entity.HikvisionData;
+import com.xjrsoft.module.hikvision.mapper.HikvisionDataMapper;
+import com.xjrsoft.module.hikvision.util.ApiUtil;
+import com.xjrsoft.module.hikvision.util.DataUtil;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.service.IUserService;
+import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
+import com.xjrsoft.module.student.entity.StudentDropOut;
+import com.xjrsoft.module.student.mapper.StudentDropOutMapper;
+import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
+import lombok.extern.slf4j.Slf4j;
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author dzx
+ * @date 2024/5/8
+ */
+@Component
+@Slf4j
+public class StudentDropOutTask {
+
+    @Autowired
+    private HikvisionDataMapper hikvisionDataMapper;
+
+    @Autowired
+    private IUserService userService;
+
+
+    @Scheduled(cron = "0 */30 * * * ?")
+    public void execute() {
+        String active = SpringUtil.getActiveProfile();
+        if(!"prod".equals(active)){
+            log.info("非正式环境,无法执行数据推送");
+            return;
+        }
+        RefreshConnectionPool();
+    }
+    public void RefreshConnectionPool() {
+        String active = SpringUtil.getActiveProfile();
+        if(!"prod".equals(active)){
+            log.info("非正式环境,无法执行数据推送");
+            return;
+        }
+        log.info("开始推送海康威视基础数据");
+        try {
+            List<User> list = userService.list(
+                    new MPJLambdaWrapper<User>()
+                            .select(User::getId)
+                            .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                            .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
+                            .ne(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901)
+            );
+            for (User user : list) {
+                //删除海康出入权限
+                String hikvisionId = hikvisionDataMapper.getStudentHikvisionId(user.getId());
+                if(StrUtil.isEmpty(hikvisionId)){
+                    continue;
+                }
+                ApiUtil apiUtil = new ApiUtil();
+                String apiPath = "/api/pmas/v1/person/batch/delete";
+                JsonObject paramJson = new JsonObject();
+                JsonArray personIndexCodes = new JsonArray();
+                personIndexCodes.add(hikvisionId);
+                paramJson.add("personIndexCodes", personIndexCodes);
+                String doPost = apiUtil.doPost(apiPath, paramJson.toString(), null);
+
+                JsonParser parser = new JsonParser();
+                JsonObject resultJson = parser.parse(doPost).getAsJsonObject();
+                if(resultJson.get("code").getAsInt() == 0){
+                    JsonArray success = resultJson.get("data").getAsJsonObject().get("success").getAsJsonArray();
+
+                    Set<String> valuesSet = new HashSet<>();
+                    String keyToExtract = "indexCode";
+                    // 遍历 JSON 数组并提取指定键的值
+                    for (JsonElement jsonElement : success) {
+                        JsonObject jsonObject = jsonElement.getAsJsonObject();
+                        if (jsonObject.has(keyToExtract)) {
+                            String value = jsonObject.get(keyToExtract).getAsString();
+                            valuesSet.add(value);
+                        }
+                    }
+                    if(valuesSet.contains(hikvisionId)){
+                        hikvisionDataMapper.delete(
+                                new QueryWrapper<HikvisionData>().lambda()
+                                        .eq(HikvisionData::getSourceId, user.getId())
+                                        .eq(HikvisionData::getHikvisionId, hikvisionId)
+                        );
+                    }
+                }
+            }
+
+            log.info("数据推送完成");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+}

+ 1 - 1
src/main/java/com/xjrsoft/module/liteflow/node/StudentDropOutNode.java

@@ -133,7 +133,7 @@ public class StudentDropOutNode extends NodeComponent {
                             if(valuesSet.contains(hikvisionId)){
                                 hikvisionDataMapper.delete(
                                         new QueryWrapper<HikvisionData>().lambda()
-                                                .eq(HikvisionData::getSourceId, studentDropOut.getClassId())
+                                                .eq(HikvisionData::getSourceId, studentDropOut.getStudentUserId())
                                                 .eq(HikvisionData::getHikvisionId, hikvisionId)
                                 );
                             }

+ 114 - 11
src/test/java/com/xjrsoft/module/liteflow/node/StudentDropOutNodeTest.java

@@ -1,15 +1,39 @@
 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.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 import com.xjrsoft.common.enums.ArchivesStatusEnum;
 import com.xjrsoft.common.enums.DeleteMark;
+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.ApiUtil;
 import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
 import com.xjrsoft.module.student.entity.StudentDropOut;
 import com.xjrsoft.module.student.mapper.StudentDropOutMapper;
 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 org.apache.commons.lang.StringUtils;
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.transaction.support.TransactionSynchronization;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 
 import static org.junit.jupiter.api.Assertions.*;
 
@@ -24,18 +48,97 @@ class StudentDropOutNodeTest {
     @Autowired
     private IBaseStudentSchoolRollService studentSchoolRollService;
 
+    @Autowired
+    private IWorkflowExecuteService workflowExecuteService;
+
+    @Autowired
+    private WorkflowRecordMapper workflowRecordMapper;
+
+    @Autowired
+    private HikvisionDataMapper hikvisionDataMapper;
+
     @Test
     void test(){
-        Long formId = 1780875585629765632L;
-        StudentDropOut studentDropOut = studentDropOutMapper.selectById(formId);
-        //跟新学籍信息
-        BaseStudentSchoolRoll schoolRoll = studentSchoolRollService.getOne(
-            new QueryWrapper<BaseStudentSchoolRoll>().lambda()
-            .eq(BaseStudentSchoolRoll::getClassId, studentDropOut.getClassId())
-            .eq(BaseStudentSchoolRoll::getUserId, studentDropOut.getStudentUserId())
-            .eq(BaseStudentSchoolRoll::getDeleteMark, DeleteMark.NODELETE.getCode())
-        );
-        schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2904.getCode());
-        studentSchoolRollService.updateById(schoolRoll);
+        Long formId = 1863523681699409920L;
+        // 获取表单中数据编号
+        Object processInstanceId = "4af1e5f0-b094-11ef-9e41-0242c8000007";
+        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;
+                            }
+                        }
+
+                        //查询出数据
+                        StudentDropOut studentDropOut = studentDropOutMapper.selectById(formId);
+                        //跟新学籍信息
+                        BaseStudentSchoolRoll schoolRoll = studentSchoolRollService.getOne(
+                                new QueryWrapper<BaseStudentSchoolRoll>().lambda()
+                                        .eq(BaseStudentSchoolRoll::getClassId, studentDropOut.getClassId())
+                                        .eq(BaseStudentSchoolRoll::getUserId, studentDropOut.getStudentUserId())
+                                        .eq(BaseStudentSchoolRoll::getDeleteMark, DeleteMark.NODELETE.getCode())
+                        );
+                        schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2904.getCode());
+                        studentSchoolRollService.updateById(schoolRoll);
+
+                        //删除海康出入权限
+                        String hikvisionId = hikvisionDataMapper.getStudentHikvisionId(studentDropOut.getStudentUserId());
+                        ApiUtil apiUtil = new ApiUtil();
+                        String apiPath = "/api/pmas/v1/person/batch/delete";
+                        JsonObject paramJson = new JsonObject();
+                        JsonArray personIndexCodes = new JsonArray();
+                        personIndexCodes.add(hikvisionId);
+                        paramJson.add("personIndexCodes", personIndexCodes);
+                        String doPost = apiUtil.doPost(apiPath, paramJson.toString(), null);
+
+                        JsonParser parser = new JsonParser();
+                        JsonObject resultJson = parser.parse(doPost).getAsJsonObject();
+                        if(resultJson.get("code").getAsInt() == 0){
+                            JsonArray success = resultJson.get("data").getAsJsonObject().get("success").getAsJsonArray();
+
+                            Set<String> valuesSet = new HashSet<>();
+                            String keyToExtract = "indexCode";
+                            // 遍历 JSON 数组并提取指定键的值
+                            for (JsonElement jsonElement : success) {
+                                JsonObject jsonObject = jsonElement.getAsJsonObject();
+                                if (jsonObject.has(keyToExtract)) {
+                                    String value = jsonObject.get(keyToExtract).getAsString();
+                                    valuesSet.add(value);
+                                }
+                            }
+                            if(valuesSet.contains(hikvisionId)){
+                                hikvisionDataMapper.delete(
+                                        new QueryWrapper<HikvisionData>().lambda()
+                                                .eq(HikvisionData::getSourceId, studentDropOut.getClassId())
+                                                .eq(HikvisionData::getHikvisionId, hikvisionId)
+                                );
+                            }
+                        }
+                    });
+                }
+            });
+        }
     }
 }