Kaynağa Gözat

学生请假功能实现

dzx 1 yıl önce
ebeveyn
işleme
030754745a

+ 5 - 6
src/main/java/com/xjrsoft/module/student/entity/StudentLeave.java

@@ -10,7 +10,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
-import java.time.LocalDateTime;
+import java.time.LocalDate;
 import java.util.Date;
 
 
@@ -77,14 +77,11 @@ public class StudentLeave implements Serializable {
     @ApiModelProperty("班级id")
     private Long classId;
 
-    @ApiModelProperty("身份证号")
-    private String IDNumber;
-
     @ApiModelProperty("开始时间")
-    private LocalDateTime startDate;
+    private LocalDate startDate;
 
     @ApiModelProperty("开始时间")
-    private LocalDateTime endDate;
+    private LocalDate endDate;
 
     @ApiModelProperty("请假原因")
     private String reason;
@@ -107,4 +104,6 @@ public class StudentLeave implements Serializable {
     @ApiModelProperty("请假类型")
     private String leaveType;
 
+    @ApiModelProperty("海康接口返回信息")
+    private String hikvisionResult;
 }

+ 50 - 1
src/main/java/com/xjrsoft/module/student/service/impl/StudentLeaveServiceImpl.java

@@ -1,12 +1,22 @@
 package com.xjrsoft.module.student.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+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.StudentLeave;
 import com.xjrsoft.module.student.mapper.StudentLeaveMapper;
 import com.xjrsoft.module.student.service.IStudentLeaveService;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.time.format.DateTimeFormatter;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * @title: 学生请假
  * @Author dzx
@@ -16,8 +26,47 @@ import org.springframework.stereotype.Service;
 @Service
 @AllArgsConstructor
 public class StudentLeaveServiceImpl extends MPJBaseServiceImpl<StudentLeaveMapper, StudentLeave> implements IStudentLeaveService {
+
+    private final HikvisionDataMapper hikvisionDataMapper;
+
     @Override
     public Boolean hikvisionLeave(Long id) {
-        return null;
+        StudentLeave studentLeave = this.getById(id);
+
+        //查询学生在海康的id
+        HikvisionData hikvisionData = hikvisionDataMapper.selectOne(
+            new QueryWrapper<HikvisionData>().lambda()
+            .eq(HikvisionData::getSourceId, studentLeave.getStudentUserId())
+            .eq(HikvisionData::getTableName, "base_student")
+        );
+        ApiUtil apiUtil = new ApiUtil();
+        String apiPath = "/api/acps/v1/auth_config/add";
+
+//        String outputFormat = "yyyy-MM-dd'T'HH:mm:ss+08:00";
+        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+        JsonObject paramJson = new JsonObject();
+
+        paramJson.addProperty("startTime", studentLeave.getStartDate().atStartOfDay().format(formatter));
+        paramJson.addProperty("endTime", studentLeave.getEndDate().atTime(23,59,59).format(formatter));
+
+        //组装人员数据
+        JsonArray personDatas = new JsonArray();
+        JsonObject personData = new JsonObject();
+        personData.addProperty("personDataType", "person");
+
+        JsonArray indexCodes = new JsonArray();
+        indexCodes.add(hikvisionData.getHikvisionId());
+        personData.add("indexCodes", indexCodes);
+
+        personDatas.add(personData);
+        paramJson.add("personDatas", personDatas);
+
+        Map<String, String> header = new HashMap<>();
+        header.put("tagId", "studentleave");
+        //调用接口获取到返回内容,并将其存到数据库中
+        String result = apiUtil.doPost(apiPath, paramJson.toString(), null, header);
+        studentLeave.setHikvisionResult(result);
+        this.updateById(studentLeave);
+        return true;
     }
 }

+ 35 - 0
src/test/java/com/xjrsoft/module/liteflow/node/StudentLeaveNodeTest.java

@@ -0,0 +1,35 @@
+package com.xjrsoft.module.liteflow.node;
+
+import cn.hutool.core.convert.Convert;
+import com.xjrsoft.XjrSoftApplication;
+import com.xjrsoft.module.student.service.IStudentLeaveService;
+import org.junit.jupiter.api.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author dzx
+ * @date 2024/5/21
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = XjrSoftApplication.class)
+class StudentLeaveNodeTest {
+    @Autowired
+    private IStudentLeaveService studentLeaveService;
+
+    @Test
+    public void process() throws Exception {
+        // 获取表单中数据编号
+        Long formId = 1779431620300816384L;
+        if (formId != null) {
+            // 数据处理
+            studentLeaveService.hikvisionLeave(formId);
+        }
+    }
+}