StudentLeaveServiceImpl.java 5.0 KB

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