From 2f65c9f0c9dae7c192a81a79d94b7eba614c8b23 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 17 十一月 2025 14:59:12 +0800
Subject: [PATCH] 钥匙柜大屏

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetGridServiceImpl.java |  202 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 183 insertions(+), 19 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetGridServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetGridServiceImpl.java
index a14b88a..3f6f205 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetGridServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetGridServiceImpl.java
@@ -1,5 +1,6 @@
 package com.doumee.service.business.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.ResponseStatus;
@@ -9,10 +10,14 @@
 import com.doumee.core.haikang.model.HKConstants;
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.DateUtil;
+import com.doumee.core.utils.HttpsUtil;
 import com.doumee.dao.business.*;
 import com.doumee.dao.business.dao.MemberMapper;
 import com.doumee.dao.business.dto.*;
 import com.doumee.dao.business.model.*;
+import com.doumee.dao.business.vo.CabinetBoardDataVO;
+import com.doumee.dao.business.vo.CabinetDetailVO;
+import com.doumee.dao.business.vo.CabinetGridInfoVO;
 import com.doumee.dao.system.SystemUserMapper;
 import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.third.model.LoginUserInfo;
@@ -82,6 +87,9 @@
 
     @Autowired
     private DingTalk dingTalk;
+
+    @Autowired
+    private CarUseBookMapper carUseBookMapper;
 
     @Override
     public Integer create(JkCabinetGrid jkCabinetGrid) {
@@ -477,12 +485,40 @@
                                 .set(JkKeys::getStatus,dto.getKeyStatus())
                                 .eq(JkKeys::getId,jkKeys.getId())
                         );
+                        //褰掕繕閽ュ寵/鍊熷嚭閽ュ寵 閮借鍘绘煡璇㈡渶鍚庝竴娆″紑闂ㄨ褰� 鑾峰彇鍏蜂綋鐨勫紑闂ㄧ殑鏂瑰紡 鏄殢杞�/娲捐溅/淇濇磥 璧嬩簣褰撳墠鍏抽棬璁板綍鍐� 濡傛灉鏄淳杞﹀崟鏁版嵁 闇�瑕佽皟璧风畝閬撲簯鎺ㄩ��
+                        JkCabinetLog lastOutLog = jkCabinetLogMapper.selectOne(new QueryWrapper<JkCabinetLog>().lambda()
+                                .eq(JkCabinetLog::getKeyId,jkCabinetLog.getKeyId())
+                                .eq(JkCabinetLog::getType,Constants.ZERO)
+                                .last( "limit 1 "));
+                        if(Objects.nonNull(lastOutLog)){
+                            if(Objects.nonNull(lastOutLog.getCarUseBookId())) {
+                                CarUseBook carUseBook = carUseBookMapper.selectById(lastOutLog.getCarUseBookId());
+                                if (Objects.nonNull(carUseBook) && Constants.equalsInteger(carUseBook.getKeyStatus(), Constants.ZERO)) {
+                                    carUseBookMapper.update(new UpdateWrapper<CarUseBook>().lambda()
+                                            .set(CarUseBook::getKeyStatus, Constants.ONE)
+                                            .eq(CarUseBook::getId, carUseBook.getId())
+                                    );
+                                    //鎺ㄩ�佺畝閬撲簯 鏍囪涓氬姟鏁版嵁宸茶棰嗗彇閽ュ寵
+                                    if (StringUtils.isNotBlank(carUseBook.getJdyId())) {
+                                        JDYKeyUseByBookDTO jdyKeyUseByBookDTO = new JDYKeyUseByBookDTO();
+                                        jdyKeyUseByBookDTO.setCreate_date(System.currentTimeMillis());
+                                        jdyKeyUseByBookDTO.setStart_date(Constants.equalsInteger(dto.getKeyStatus(),Constants.TWO)?System.currentTimeMillis():null);
+                                        jdyKeyUseByBookDTO.setEnd_date(Constants.equalsInteger(dto.getKeyStatus(),Constants.ONE)?System.currentTimeMillis():null);
+                                        jdyKeyUseByBookDTO.setType(Constants.equalsInteger(dto.getKeyStatus(),Constants.TWO)?Constants.ZERO:Constants.ONE);
+                                        jdyKeyUseByBookDTO.setId(carUseBook.getJdyId());
+                                        this.pushJDYKeyInfo(jdyKeyUseByBookDTO);
+                                    }
+                                }
+                            }
+                        }
+
                     }
                 }
             }
             jkCabinetLog.setIsNotice(Constants.ZERO);
             jkCabinetLog.setType(Constants.ONE);
             jkCabinetLogMapper.insert(jkCabinetLog);
+
             //鏌ヨ閽ュ寵鐨勫紑闂ㄨ褰� 杩涜娣诲姞鍏抽棬璁板綍涓婚敭
             if(Constants.equalsInteger(dto.getKeyStatus(),Constants.ONE)){
                 jkCabinetLogMapper.update(null,new UpdateWrapper<JkCabinetLog>().lambda()
@@ -558,23 +594,80 @@
                     return jkCabinetGridList;
                 }
             }
-            jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class,
-                    new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class)
-                            .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode)
-                            .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode)
-                            .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId)
-                            .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus)
-                            .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId)
-                            .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO)
-                            .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO)
-                            .eq(JkCabinetGrid::getStatus,Constants.ZERO)
-                            .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId())
-                            .in(Constants.equalsInteger(dto.getType(),Constants.ONE),JkKeys::getStatus,Constants.TWO,Constants.THREE)
-                            .in(Constants.equalsInteger(dto.getType(),Constants.ZERO),JkKeys::getStatus,Constants.ONE)
-                            .isNotNull(JkCabinetGrid::getKeyId)
-                            .apply(" t1.car_id in ( select c.id from  cars c  where c.ISDELETED = 0 and  c.MEMBER_ID = "+dto.getMemberId()+" ) ")
-                            .orderByAsc(JkCabinetGrid::getCode)
-            );
+
+            //濡傛灉鏄繕閽ュ寵 鍒欑洿鎺ユ煡璇㈠凡鍊熷嚭鐨勯挜鍖欑殑鏁版嵁
+            if(Constants.equalsInteger(dto.getType(),Constants.ONE)){
+                jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class,
+                        new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class)
+                                .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode)
+                                .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode)
+                                .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId)
+                                .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus)
+                                .innerJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId)
+                                .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO)
+                                .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO)
+                                .eq(JkCabinetGrid::getStatus,Constants.ZERO)
+                                .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId())
+                                .in(JkKeys::getStatus,Constants.TWO,Constants.THREE)
+                                .isNotNull(JkCabinetGrid::getKeyId)
+                                .apply("t1.car_id in ( select c.id from  cars c  where c.ISDELETED = 0 and  c.MEMBER_ID = "+dto.getMemberId()+" )")
+
+                                .orderByAsc(JkCabinetGrid::getCode)
+                );
+            }else{
+                //鍒ゆ柇褰撳墠鏃堕棿鏄惁澶勪簬淇濇磥鏃舵鍐�
+                String cleanConfig =  systemDictDataBiz.queryByCode(Constants.CABINET_CONFIG,Constants.CLEAN_TIME).getCode();
+                String earlyConfig =  systemDictDataBiz.queryByCode(Constants.CABINET_CONFIG,Constants.EARLY_CONFIG).getCode();
+                Boolean isCleanTime = Constants.betweenTimeConfig(cleanConfig);
+                List<Integer> girdIdList = new ArrayList<>();
+                //鏌ヨ鏍规嵁浠诲姟鍙互棰嗗彇鐨勬暟鎹�
+                jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class,
+                        new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class)
+                                .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode)
+                                .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode)
+                                .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId)
+                                .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus)
+                                .selectAs(CarUseBook::getId,JkCabinetGrid::getCarUseBookId)
+                                .select("1",JkCabinetGrid::getGetKeyWay)
+                                .innerJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId)
+                                .innerJoin(CarUseBook.class,CarUseBook::getCarCode,JkKeys::getCarCode)
+                                .innerJoin(Cars.class,Cars::getCode,CarUseBook::getCarCode)
+                                .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO)
+                                .eq(CarUseBook::getIsdeleted,Constants.ZERO)
+                                .eq(Cars::getIsdeleted,Constants.ZERO)
+                                .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO)
+                                .eq(JkCabinetGrid::getStatus,Constants.ZERO)
+                                .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId())
+                                .in(JkKeys::getStatus,Constants.ONE)
+                                .eq(JkKeys::getRoleType,Constants.ONE)
+                                .isNotNull(JkCabinetGrid::getKeyId)
+                                .apply("and NOW() > DATE_SUB(t2.START_TIME, INTERVAL "+earlyConfig+" MINUTE) and now() < t2.end_time and t3.MEMBER_ID = "+dto.getMemberId()+" )")
+
+                );
+                if(CollectionUtils.isNotEmpty(jkCabinetGridList)){
+                    girdIdList = jkCabinetGridList.stream().map(i->i.getId()).collect(Collectors.toList());
+                }
+                jkCabinetGridList.addAll(jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class,
+                            new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class)
+                                    .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode)
+                                    .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode)
+                                    .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId)
+                                    .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus)
+                                    .select(!isCleanTime?"0":"2",JkCabinetGrid::getGetKeyWay)
+                                    .innerJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId)
+                                    .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO)
+                                    .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO)
+                                    .eq(JkCabinetGrid::getStatus,Constants.ZERO)
+                                    .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId())
+                                    .eq(!isCleanTime,JkKeys::getRoleType,Constants.ZERO)
+                                    .in(JkKeys::getStatus,Constants.ONE)
+                                    .isNotNull(JkCabinetGrid::getKeyId)
+                                    .notIn(CollectionUtils.isNotEmpty(girdIdList),JkCabinetGrid::getId,jkCabinetGridList)
+                                    .apply("t1.car_id in ( select c.id from  cars c  where c.ISDELETED = 0 and  c.MEMBER_ID = "+dto.getMemberId()+" ) ")
+                    )
+                );
+            }
+
             for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) {
                 jkCabinetGrid.setBindStatus(Objects.isNull(jkCabinetGrid.getKeyId())?Constants.ZERO:Constants.ONE);
                 jkCabinetGrid.setKeyStatus(Objects.isNull(jkCabinetGrid.getKeyStatus())?Constants.ZERO:jkCabinetGrid.getKeyStatus());
@@ -607,7 +700,9 @@
         jkCabinetLog.setAuthType(openGridDriverDTO.getAuthType());
         jkCabinetLog.setMemberId(openGridDriverDTO.getMemberId());
         jkCabinetLog.setType(Constants.ZERO);
-        jkCabinetLog.setStatus(Constants.ZERO);
+        jkCabinetLog.setOpenWay(openGridDriverDTO.getOpenWay());
+        jkCabinetLog.setCarUseBookId(openGridDriverDTO.getCarUseBookId());
+
         jkCabinetLog.setInfo(Objects.isNull(openGridDriverDTO.getOpenType())||Constants.equalsInteger(openGridDriverDTO.getOpenType(),Constants.ZERO)?"绯荤粺寮�鍚�":"鎵嬪姩寮�鍚�");
         if(Objects.nonNull(jkCabinetGrid.getKeyId())){
             jkCabinetLog.setKeyId(jkCabinetGrid.getKeyId());
@@ -622,14 +717,41 @@
         }
         jkCabinetLog.setIsNotice(Constants.ZERO);
         jkCabinetLogMapper.insert(jkCabinetLog);
+
     }
 
+
+    public void pushJDYKeyInfo(JDYKeyUseByBookDTO dto){
+        String url = systemDictDataBiz.queryByCode(Constants.JDY_CONFIG,Constants.PUSH_URL_KEYS).getCode();
+//        JSONObject object = new JSONObject();
+//        object.put("create_date","20251104160000");
+//        object.put("start_date",System.currentTimeMillis() );
+//        object.put("end_date", System.currentTimeMillis() + 24*3600*1000);
+//        object.put("id","10000020251105");//
+//        object.put("type",1);//0=棰嗙敤锛�1=褰掕繕
+        log.error("銆愮畝閬撲簯銆戞帹閫佹淳杞﹀崟鏁版嵁棰嗙敤涓庡綊杩樹俊鎭�-璇锋眰鍏ュ弬锛�"+JSONObject.toJSONString(dto));
+        String result = HttpsUtil.postJson(url,JSONObject.toJSONString(dto));
+        log.error("銆愮畝閬撲簯銆戞帹閫佹淳杞﹀崟鏁版嵁棰嗙敤涓庡綊杩樹俊鎭�-璇锋眰缁撴灉锛�"+JSONObject.toJSONString(result));
+
+
+
+    }
 
 
     @Override
     public void timeOutUnCloseAlarm(TimeOutCloseGridDTO dto){
         if(Objects.nonNull(dto)
             && Objects.nonNull(dto.getGridId())){
+
+            SystemUser systemUser =  null;
+            if(Objects.nonNull(dto.getMemberId())){
+                systemUser = systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda()
+                        .eq(Objects.nonNull(dto.getMemberId()),SystemUser::getMemberId,dto.getMemberId())
+                        .eq(SystemUser::getDeleted,Constants.ZERO)
+                        .last(" limit 1 ")
+                );
+            }
+
             JkCabinetGrid jkCabinetGrid = jkCabinetGridMapper.selectJoinOne(JkCabinetGrid.class,
                     new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class)
                             .selectAs(JkCabinet::getName,JkCabinetGrid::getCabinetName)
@@ -638,6 +760,7 @@
                             .eq(JkCabinetGrid::getId,dto.getGridId())
                             .last(" limit 1 ")
             );
+
             if(Objects.nonNull(jkCabinetGrid)){
                 log.error("鏌滄牸寮�闂ㄨ秴鏃舵湭鍏抽棴鍛婅淇℃伅锛歿}"+JSONObject.toJSONString(jkCabinetGrid));
                 //瑙勫垯绫诲瀷
@@ -671,6 +794,7 @@
                     //瀛樺偍鎶ヨ寮傚父璁板綍
                     WarningEvent warningEvent = new WarningEvent();
                     warningEvent.setCreateDate(new Date());
+                    warningEvent.setCreator(Objects.nonNull(systemUser)?systemUser.getId():null);
                     warningEvent.setWarningId(warning.getId());
                     warningEvent.setTitle(warningConfig.getInfo());
                     warningEvent.setContent(content );
@@ -880,6 +1004,7 @@
                 //瀛樺偍鎶ヨ寮傚父璁板綍
                 WarningEvent warningEvent = new WarningEvent();
                 warningEvent.setCreateDate(new Date());
+                warningEvent.setCreator(Objects.nonNull(systemUser)?systemUser.getId():null);
                 warningEvent.setWarningId(warning.getId());
                 warningEvent.setTitle(warningConfig.getInfo());
                 warningEvent.setContent(content );
@@ -930,7 +1055,46 @@
     }
 
 
-
+    @Override
+    public CabinetBoardDataVO getCabinetGridData(){
+        CabinetBoardDataVO cabinetBoardDataVO = new CabinetBoardDataVO();
+        //鎵�鏈夋煖鏍间俊鎭�
+        List<JkCabinetGrid> jkCabinetGridList =
+                jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, new MPJLambdaWrapper<JkCabinetGrid>()
+                        .selectAll(JkCabinetGrid.class)
+                        .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode)
+                        .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode)
+                        .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus)
+                        .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId)
+                        .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) 
+                        .orderByAsc(JkCabinetGrid::getCode)
+                );
+        List<CabinetGridInfoVO> cabinetGridInfoVOList = new ArrayList<>();
+        if(CollectionUtils.isNotEmpty(jkCabinetGridList)){
+            cabinetBoardDataVO.setGridNum(jkCabinetGridList.size());
+            for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) {
+                CabinetGridInfoVO cabinetGridInfoVO = new CabinetGridInfoVO();
+                BeanUtil.copyProperties(jkCabinetGrid,cabinetGridInfoVO);
+                cabinetGridInfoVO.setBindStatus(Objects.isNull(jkCabinetGrid.getKeyId())?Constants.ZERO:Constants.ONE);
+                cabinetGridInfoVO.setKeyStatus(Objects.isNull(cabinetGridInfoVO.getKeyStatus())?Constants.ZERO:cabinetGridInfoVO.getKeyStatus());
+                cabinetGridInfoVOList.add(cabinetGridInfoVO);
+            }
+            cabinetBoardDataVO.setGridNum(jkCabinetGridList.size());
+            cabinetBoardDataVO.setOnlineKeyNum( //鍦ㄤ綅鏁伴噺
+                    cabinetGridInfoVOList.stream().filter(i->Constants.equalsInteger(i.getKeyStatus(),Constants.ONE)).collect(Collectors.toList()).size()
+            );
+            cabinetBoardDataVO.setOutKeyNum( //鍊熷嚭鏁伴噺
+                    cabinetGridInfoVOList.stream().filter(i->Constants.equalsInteger(i.getKeyStatus(),Constants.TWO)).collect(Collectors.toList()).size()
+            );
+            cabinetBoardDataVO.setServiceKeyNum( //缁存姢淇濆吇鏁伴噺
+                    cabinetGridInfoVOList.stream().filter(i->Constants.equalsInteger(i.getKeyStatus(),Constants.THREE)).collect(Collectors.toList()).size()
+            );
+            cabinetBoardDataVO.setUnBindGridNum(//绌洪棽鏁伴噺
+                    cabinetGridInfoVOList.stream().filter(i->Constants.equalsInteger(i.getBindStatus(),Constants.ZERO)).collect(Collectors.toList()).size()
+            );
+        }
+        return cabinetBoardDataVO;
+    }
 
 
 }

--
Gitblit v1.9.3