StudentLeaveServiceImpl.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.xjrsoft.module.student.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.github.yulichang.base.MPJBaseServiceImpl;
  4. import com.google.gson.JsonArray;
  5. import com.google.gson.JsonElement;
  6. import com.google.gson.JsonObject;
  7. import com.google.gson.JsonParser;
  8. import com.xjrsoft.module.attendance.dto.AttendanceStatisticDto;
  9. import com.xjrsoft.module.hikvision.entity.HikvisionData;
  10. import com.xjrsoft.module.hikvision.mapper.HikvisionDataMapper;
  11. import com.xjrsoft.module.hikvision.util.ApiUtil;
  12. import com.xjrsoft.module.outint.vo.IdCountVo;
  13. import com.xjrsoft.module.student.entity.StudentLeave;
  14. import com.xjrsoft.module.student.mapper.StudentLeaveMapper;
  15. import com.xjrsoft.module.student.service.IStudentLeaveService;
  16. import lombok.AllArgsConstructor;
  17. import org.springframework.stereotype.Service;
  18. import java.time.LocalDateTime;
  19. import java.time.format.DateTimeFormatter;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * @title: 学生请假
  25. * @Author dzx
  26. * @Date: 2024年5月21日
  27. * @Version 1.0
  28. */
  29. @Service
  30. @AllArgsConstructor
  31. public class StudentLeaveServiceImpl extends MPJBaseServiceImpl<StudentLeaveMapper, StudentLeave> implements IStudentLeaveService {
  32. private final HikvisionDataMapper hikvisionDataMapper;
  33. @Override
  34. public Boolean hikvisionLeave(Long id) {
  35. StudentLeave studentLeave = this.getById(id);
  36. //查询学生在海康的id
  37. HikvisionData hikvisionData = hikvisionDataMapper.selectOne(
  38. new QueryWrapper<HikvisionData>().lambda()
  39. .eq(HikvisionData::getSourceId, studentLeave.getStudentUserId())
  40. .eq(HikvisionData::getTableName, "base_student")
  41. );
  42. ApiUtil apiUtil = new ApiUtil();
  43. String apiPath = "/api/acps/v1/auth_config/add";
  44. String outputFormat = "yyyy-MM-dd'T'HH:mm:ss+08:00";
  45. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(outputFormat);
  46. JsonObject paramJson = new JsonObject();
  47. paramJson.addProperty("startTime", studentLeave.getStartDate().atStartOfDay().format(formatter));
  48. paramJson.addProperty("endTime", studentLeave.getEndDate().atTime(23,59,59).format(formatter));
  49. //组装人员数据
  50. JsonArray personDatas = new JsonArray();
  51. JsonObject personData = new JsonObject();
  52. personData.addProperty("personDataType", "person");
  53. JsonArray indexCodes = new JsonArray();
  54. indexCodes.add(hikvisionData.getHikvisionId());
  55. personData.add("indexCodes", indexCodes);
  56. personDatas.add(personData);
  57. paramJson.add("personDatas", personDatas);
  58. JsonArray resourceInfos = selectResource(apiUtil);
  59. paramJson.add("resourceInfos", resourceInfos);
  60. Map<String, String> header = new HashMap<>();
  61. header.put("tagId", "studentleave");
  62. //调用接口获取到返回内容,并将其存到数据库中
  63. String result = apiUtil.doPost(apiPath, paramJson.toString(), null, header);
  64. studentLeave.setHikvisionResult(result);
  65. this.updateById(studentLeave);
  66. return true;
  67. }
  68. @Override
  69. public Long getLeaveCount(LocalDateTime startTime, LocalDateTime endTime, AttendanceStatisticDto dto) {
  70. return this.baseMapper.getLeaveCount(startTime, endTime, dto);
  71. }
  72. @Override
  73. public Map<Long, Integer> getClassLeaveCount(LocalDateTime startTime, LocalDateTime endTime) {
  74. List<IdCountVo> classLeaveCount = this.baseMapper.getClassLeaveCount(startTime, endTime);
  75. Map<Long, Integer> result = new HashMap<>();
  76. for (IdCountVo idCountVo : classLeaveCount) {
  77. result.put(idCountVo.getId(), idCountVo.getCount());
  78. }
  79. return result;
  80. }
  81. @Override
  82. public Map<Long, StudentLeave> getLeaveList(LocalDateTime startTime, LocalDateTime endTime) {
  83. List<StudentLeave> leaveList = this.baseMapper.getLeaveList(startTime, endTime);
  84. Map<Long, StudentLeave> result = new HashMap<>();
  85. for (StudentLeave studentLeave : leaveList) {
  86. result.put(studentLeave.getClassId(), studentLeave);
  87. }
  88. return result;
  89. }
  90. JsonArray selectResource(ApiUtil apiUtil){
  91. String apiPath = "/api/irds/v2/resource/resourcesByParams";
  92. JsonObject jsonObject = new JsonObject();
  93. jsonObject.addProperty("pageNo", 1);
  94. jsonObject.addProperty("pageSize", 500);
  95. jsonObject.addProperty("resourceType", "door");
  96. String result = apiUtil.doPost(apiPath, jsonObject.toString(), null, null);
  97. JsonParser parser = new JsonParser();
  98. JsonObject resultJson = parser.parse(result).getAsJsonObject();
  99. JsonArray resourceInfos = new JsonArray();
  100. if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
  101. JsonArray list = resultJson.get("data").getAsJsonObject().get("list").getAsJsonArray();
  102. for (JsonElement jsonElement : list) {
  103. JsonObject listOne = jsonElement.getAsJsonObject();
  104. JsonObject resourceInfo = new JsonObject();
  105. resourceInfo.add("resourceIndexCode", listOne.get("indexCode"));
  106. resourceInfo.add("resourceType", listOne.get("resourceType"));
  107. JsonArray channelNos = new JsonArray();
  108. channelNos.add(listOne.get("channelNo"));
  109. resourceInfo.add("channelNos", channelNos);
  110. resourceInfos.add(resourceInfo);
  111. }
  112. }
  113. return resourceInfos;
  114. }
  115. }