From 4ee00850f197d769481f73acb8ed79ab1c75b84d Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 14 十一月 2025 11:41:24 +0800
Subject: [PATCH] 问题修复

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetGridServiceImpl.java |  144 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 126 insertions(+), 18 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..9140786 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
@@ -9,6 +9,7 @@
 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.*;
@@ -82,6 +83,9 @@
 
     @Autowired
     private DingTalk dingTalk;
+
+    @Autowired
+    private CarUseBookMapper carUseBookMapper;
 
     @Override
     public Integer create(JkCabinetGrid jkCabinetGrid) {
@@ -477,12 +481,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 +590,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 +696,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,9 +713,26 @@
         }
         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){

--
Gitblit v1.9.3