123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package com.ruoyi.system.service.impl;
- import com.alibaba.fastjson2.JSON;
- import com.alibaba.fastjson2.JSONArray;
- import com.alibaba.fastjson2.JSONObject;
- import com.alibaba.fastjson2.TypeReference;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.core.redis.RedisCache;
- import com.ruoyi.common.exception.ServiceException;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.SecurityUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.hkws.GetCameraPreviewURL;
- import com.ruoyi.system.domain.*;
- import com.ruoyi.system.domain.vo.CameraInfoVo;
- import com.ruoyi.system.mapper.*;
- import com.ruoyi.system.service.CameraService;
- import com.ruoyi.system.service.IClockEquipRecordService;
- import lombok.SneakyThrows;
- import org.apache.poi.ss.usermodel.DateUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.time.OffsetDateTime;
- import java.time.ZoneOffset;
- import java.time.ZonedDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import java.util.stream.Collectors;
- import static com.ruoyi.common.constant.CommonConstants.KQ_START_TIME;
- import static com.ruoyi.common.constant.CommonConstants.OPEN_DOOR;
- /**
- * 监控Service业务层处理
- *
- * @author ruoyi
- * @date 2024-06-25
- */
- @Service
- public class CameraServiceImpl implements CameraService {
- @Autowired
- private EquipmentConfigurationMapper equipmentConfigurationMapper;
- @Autowired
- private DutyScheduleMapper dutyScheduleMapper;
- @Autowired
- private IClockEquipRecordService clockEquipRecordService;
- @Autowired
- private ClockEquipRecordMapper clockEquipRecordMapper;
- @Autowired
- private ClockUserInfoMapper clockUserInfoMapper;
- @Autowired
- private RedisCache redisCache;
- @Autowired
- private ClockRecordMapper clockRecordMapper;
- @Override
- public AjaxResult selectCameraList(CameraInfoVo cameraInfoVo) {
- //Map<String,JSONObject> map = new HashMap<>();
- /**
- * STEP3:设置接口的URI地址
- */
- String url = "/api/resource/v2/camera/search";
- /**
- * STEP5:组装请求参数
- */
- String body = JSONArray.toJSONString(cameraInfoVo);
- /*JSONObject jsonBody = new JSONObject();
- jsonBody.put("cameraIndexCode", "8e59cc5559904589938be47888e5214a");
- jsonBody.put("streamType", 0);
- jsonBody.put("protocol", "httpflv");
- jsonBody.put("transmode", 1);
- jsonBody.put("expand", "streamform=ps");*/
- /* jsonBody.put("pageNo", 1);
- jsonBody.put("pageSize", 30);*/
- String result = GetCameraPreviewURL.GetCameraPreviewURL(url,body);
- JSONObject jsonObject = JSON.parseObject(result);
- //将门禁设备单独列出
- //Map<String, Object> map = jsonObject.to(new TypeReference<Map<String, Object>>() {});
- JSONObject data = (JSONObject) jsonObject.get("data");
- JSONArray itemsArray = data.getJSONArray("list");
- List<JSONObject> itemsList = itemsArray.toJavaList(JSONObject.class);
- List<JSONObject> accessList = new ArrayList<>();
- //查询门禁设备名字
- List<EquipmentConfiguration> equipmentList = equipmentConfigurationMapper.selectEquipmentConfigurationList(new EquipmentConfiguration());
- for (JSONObject object : itemsList) {
- for (EquipmentConfiguration equipmentConfiguration : equipmentList) {
- if(object.get("name").equals(equipmentConfiguration.getEquipmentName())){
- accessList.add(object);
- }
- }
- }
- data.put("access",accessList);
- return AjaxResult.success(jsonObject);
- }
- @Override
- public AjaxResult video(String cameraIndexCode) {
- if(StringUtils.isEmpty(cameraIndexCode)){
- throw new ServiceException("参数错误");
- }
- /**
- * STEP3:设置接口的URI地址
- */
- String url = "/api/video/v2/cameras/previewURLs";
- /**
- * STEP5:组装请求参数
- */
- JSONObject jsonBody = new JSONObject();
- jsonBody.put("cameraIndexCode", cameraIndexCode);
- jsonBody.put("streamType", 0);
- jsonBody.put("protocol", "httpflv");
- jsonBody.put("transmode", 1);
- jsonBody.put("expand", "streamform=ps");
- String result = GetCameraPreviewURL.GetCameraPreviewURL(url,jsonBody.toString());
- JSONObject jsonObject = JSON.parseObject(result);
- return AjaxResult.success(jsonObject);
- }
- @SneakyThrows
- @Override
- public void configureTasks() {
- //查询设备 name -> 1号楼2F-
- /**
- * STEP3:查询门禁点事件v2
- */
- String url = "/api/acs/v2/door/events";
- /**
- * STEP5:组装请求参数
- */
- /**
- * STEP3:设置接口的URI地址
- * indexCode -> c9a07d45adc247908d73d4d3a41470a4 name -> 1号楼2F-2_门_1
- * indexCode -> 86e6e58f29fe44ad80b18a0bc3a24080 name -> 1号楼2F-1_门_1
- * indexCode -> 5490b0c100dd4367a8fb548b1de33043 name -> 5号楼1F_门_1
- * indexCode -> 0e530bc2f5234929b6bf5562e1e4932c name -> 后门_门_1
- * */
- String startTime = redisCache.getCacheObject(KQ_START_TIME);
- if(StringUtils.isEmpty(startTime)){
- startTime = "2025-01-01T00:00:00+08:00";
- }
- ZoneOffset offset = ZoneOffset.of("+08:00"); // 中国时区偏移量
- ZonedDateTime now = ZonedDateTime.now(offset); // 注意这里用的是ZoneOffset而不是ZoneId
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX"); // XXX 表示时区偏移量,但不显示区域名称如Asia/Shanghai
- String formatted = now.format(formatter);
- int[] eventTypes = {196893};
- String[] doorIndexCodes = {"c9a07d45adc247908d73d4d3a41470a4","86e6e58f29fe44ad80b18a0bc3a24080"};
- JSONObject jsonBody = new JSONObject();
- jsonBody.put("pageNo", 1);
- jsonBody.put("pageSize", "1000");
- jsonBody.put("doorIndexCodes", doorIndexCodes);
- jsonBody.put("eventTypes", eventTypes);
- jsonBody.put("startTime", startTime);
- jsonBody.put("endTime", formatted);
- //jsonBody.put("doorName", "考勤");
- jsonBody.put("sort", "eventTime");
- jsonBody.put("order", "asc");
- String result = GetCameraPreviewURL.GetCameraPreviewURL(url,jsonBody.toString());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject data = (JSONObject) jsonObject.get("data");
- JSONArray itemsArray = data.getJSONArray("list");
- List<JSONObject> itemsList = itemsArray.toJavaList(JSONObject.class);
- List<JSONObject> accessList = new ArrayList<>();
- for (JSONObject object : itemsList) {
- String name = (String)object.get("personName");
- if(StringUtils.isNotEmpty(name)){
- accessList.add(object);
- }
- }
- if(accessList==null){
- return;
- }
- Map<String,List<JSONObject>> map = accessList.stream().collect(Collectors.groupingBy(obj -> obj.getString("personName")));
- //查询打卡时间
- DutySchedule dutySchedule = new DutySchedule();
- dutySchedule.setIsEquip("Y");
- List<DutySchedule> dutySchedules = dutyScheduleMapper.selectDutyScheduleList(dutySchedule);
- if(dutySchedules==null || dutySchedules.size()<1){
- return;
- }
- dutySchedule = dutySchedules.get(0);
- for (String key : map.keySet()) {
- //查询人员的信息
- ClockUserInfo clockUserInfo = clockUserInfoMapper.selectClockUserInfoByName(key);
- List<JSONObject> keyValue = map.get(key);
- for (int i = 0; i < keyValue.size(); i++) {
- JSONObject object = map.get(key).get(i);
- if(object.get("eventTime").equals(startTime)){
- continue;
- }
- String dateTime = DateUtils.bDateToString((String) object.get("eventTime"));
- ClockRecord clockEquipRecord = new ClockRecord();
- if(clockUserInfo!=null){
- clockEquipRecord.setUserId(clockUserInfo.getUserId());
- clockEquipRecord.setDeptName(clockUserInfo.getDeptName());
- clockEquipRecord.setPhonenumber(clockUserInfo.getPhonenumber());
- clockEquipRecord.setIdCard(clockUserInfo.getIdCard());
- }
- //clockEquipRecord.setUserName((String) object.get("personId"));
- clockEquipRecord.setUserName((String) object.get("personName"));
- //clockEquipRecord.setIdCard((String) object.get("certNo"));
- clockEquipRecord.setWeek(String.valueOf(DateUtils.dayForWeek(dateTime)));
- clockEquipRecord.setRecordDt(dateTime);
- String[] dt = dateTime.split(" ");
- clockEquipRecord.setRecordDate(dt[0]);
- clockEquipRecord.setRecordTime(dt[1]);
- clockEquipRecord.setRecordLocations((String) object.get("readerDevName"));
- //判断是否是正常打卡 1:正常打卡,2:外勤打卡,3:迟到,4:早退',
- //查询库里是否有key的数据,有的话就说明不是上班卡,没有的话就是第一个卡
- ClockRecord clockEquip = new ClockRecord();
- clockEquip.setUserName((String) object.get("personName"));
- clockEquip.setRecordDate(dt[0]);
- List<ClockRecord> clockEquipRecords = clockRecordMapper.selectClockRecordList(clockEquip);
- //里面存在数据
- if(clockEquipRecords!=null && clockEquipRecords.size()>0){
- //先将之前的的下班卡改为无效(名字)
- //clockEquipRecordMapper.updateClockEquipRecordEffective(dt[0],(String) object.get("personName"));
- clockEquipRecord.setType("2");
- //clockEquipRecord.setEffective("1");
- //判断下班是否早退
- int res = dt[1].compareTo(dutySchedule.getEndWorkTime());
- if(res>0 || res==0){
- //正常打卡
- clockEquipRecord.setIsOutwork("1");
- }else{
- clockEquipRecord.setIsOutwork("4");
- }
- }else{
- //不存在数据
- clockEquipRecord.setType("1");
- //clockEquipRecord.setEffective("1");
- //判断上班是否迟到
- int res = dt[1].compareTo(dutySchedule.getStartWorkTime());
- if(res>0 || res==0){
- //迟到
- clockEquipRecord.setIsOutwork("3");
- }else{
- clockEquipRecord.setIsOutwork("1");
- }
- }
- clockEquipRecord.setSource("设备");
- clockEquipRecord.setCreateTime(DateUtils.getNowDate());
- clockRecordMapper.insertClockRecord(clockEquipRecord);
- }
- }
- //将最后一条有效数据时间存入redis
- redisCache.setCacheObject(KQ_START_TIME,accessList.get(accessList.size()-1).get("eventTime"));
- }
- /*public static void main(String[] args) {
- // 获取当前时间
- ZoneOffset offset = ZoneOffset.of("+08:00"); // 中国时区偏移量
- ZonedDateTime now = ZonedDateTime.now(offset); // 注意这里用的是ZoneOffset而不是ZoneId
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX"); // XXX 表示时区偏移量,但不显示区域名称如Asia/Shanghai
- String formatted = now.format(formatter);
- System.out.println(formatted);
- // 打印ISO 8601格式的当前时间
- //System.out.println(now);
- //String url = "/api/resource/v2/door/search";
- String url = "/api/acs/v2/door/events";
- int[] eventTypes = {196893};
- String[] doorIndexCodes = {"c9a07d45adc247908d73d4d3a41470a4","86e6e58f29fe44ad80b18a0bc3a24080"};
- JSONObject jsonBody = new JSONObject();
- jsonBody.put("pageNo", 1);
- jsonBody.put("pageSize", "1000");
- jsonBody.put("doorIndexCodes", doorIndexCodes);
- jsonBody.put("eventTypes", eventTypes);
- //jsonBody.put("doorName", "考勤");
- String result = GetCameraPreviewURL.GetCameraPreviewURL(url,jsonBody.toString());
- JSONObject jsonObject = JSON.parseObject(result);
- JSONObject data = (JSONObject) jsonObject.get("data");
- JSONArray itemsArray = data.getJSONArray("list");
- List<JSONObject> itemsList = itemsArray.toJavaList(JSONObject.class);
- Map<String,List<JSONObject>> map = itemsList.stream().collect(Collectors.groupingBy(obj -> obj.getString("personId")));
- List<JSONObject> accessList = new ArrayList<>();
- for (JSONObject object : itemsList) {
- String name = (String)object.get("doorName");
- if(name.contains("考勤")){
- accessList.add(object);
- }
- }
- System.out.println(accessList.toString());
- }*/
- }
|