From 3a154bdb0a5aaa2c0ac3eac95a6ba747068bd454 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 13 一月 2026 10:00:37 +0800
Subject: [PATCH] 优化

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetLogServiceImpl.java |  304 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 304 insertions(+), 0 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetLogServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetLogServiceImpl.java
new file mode 100644
index 0000000..a46ecc8
--- /dev/null
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetLogServiceImpl.java
@@ -0,0 +1,304 @@
+package com.doumee.service.business.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.utils.Constants;
+import com.doumee.dao.business.*;
+import com.doumee.dao.business.dto.TelecomCabinetLogDTO;
+import com.doumee.dao.business.model.*;
+import com.doumee.dao.business.vo.TelecomJkCabinetLogVO;
+import com.doumee.service.business.third.model.PageData;
+import com.doumee.service.business.third.model.PageWrap;
+import com.doumee.core.utils.Utils;
+import com.doumee.service.business.JkCabinetLogService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * 閽ュ寵鏌滃紑鍏抽棬璁板綍Service瀹炵幇
+ * @author 姹熻箘韫�
+ * @date 2025/09/28 09:01
+ */
+@Service
+public class JkCabinetLogServiceImpl implements JkCabinetLogService {
+
+    @Autowired
+    private JkCabinetLogMapper jkCabinetLogMapper;
+
+    @Autowired
+    private WarningMapper warningMapper;
+    @Autowired
+    private WarningRuleMapper warningRuleMapper;
+
+    @Autowired
+    private WarningPushMapper warningPushMapper;
+
+    @Autowired
+    private WarningEventMapper warningEventMapper;
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
+    @Override
+    public Integer create(JkCabinetLog jkCabinetLog) {
+        jkCabinetLogMapper.insert(jkCabinetLog);
+        return jkCabinetLog.getId();
+    }
+
+    @Override
+    public void deleteById(Integer id) {
+        jkCabinetLogMapper.deleteById(id);
+    }
+
+    @Override
+    public void delete(JkCabinetLog jkCabinetLog) {
+        UpdateWrapper<JkCabinetLog> deleteWrapper = new UpdateWrapper<>(jkCabinetLog);
+        jkCabinetLogMapper.delete(deleteWrapper);
+    }
+
+    @Override
+    public void deleteByIdInBatch(List<Integer> ids) {
+        if (CollectionUtils.isEmpty(ids)) {
+            return;
+        }
+        jkCabinetLogMapper.deleteBatchIds(ids);
+    }
+
+    @Override
+    public void updateById(JkCabinetLog jkCabinetLog) {
+        jkCabinetLogMapper.updateById(jkCabinetLog);
+    }
+
+    @Override
+    public void updateByIdInBatch(List<JkCabinetLog> jkCabinetLogs) {
+        if (CollectionUtils.isEmpty(jkCabinetLogs)) {
+            return;
+        }
+        for (JkCabinetLog jkCabinetLog: jkCabinetLogs) {
+            this.updateById(jkCabinetLog);
+        }
+    }
+
+    @Override
+    public JkCabinetLog findById(Integer id) {
+        return jkCabinetLogMapper.selectById(id);
+    }
+
+    @Override
+    public JkCabinetLog findOne(JkCabinetLog jkCabinetLog) {
+        QueryWrapper<JkCabinetLog> wrapper = new QueryWrapper<>(jkCabinetLog);
+        return jkCabinetLogMapper.selectOne(wrapper);
+    }
+
+    @Override
+    public List<JkCabinetLog> findList(JkCabinetLog jkCabinetLog) {
+        QueryWrapper<JkCabinetLog> wrapper = new QueryWrapper<>(jkCabinetLog);
+        return jkCabinetLogMapper.selectList(wrapper);
+    }
+  
+    @Override
+    public PageData<JkCabinetLog> findPage(PageWrap<JkCabinetLog> pageWrap) {
+        IPage<JkCabinetLog> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
+        Utils.MP.blankToNull(pageWrap.getModel());
+        JkCabinetLog model = pageWrap.getModel();
+        MPJLambdaWrapper<JkCabinetLog> wrapper = new MPJLambdaWrapper<JkCabinetLog>()
+                .selectAll(JkCabinetLog.class)
+                .selectAs(Member::getName,JkCabinetLog::getMemberName)
+                .selectAs(Company::getName,JkCabinetLog::getCompanyName)
+                .selectAs(JkCabinet::getName,JkCabinetLog::getCabinetName)
+                .selectAs(JkCabinetGrid::getCode,JkCabinetLog::getGridCode)
+                .leftJoin(JkCabinet.class,JkCabinet::getId,JkCabinetLog::getCabinetId)
+                .leftJoin(JkCabinetGrid.class,JkCabinetGrid::getId,JkCabinetLog::getGridId)
+                .leftJoin(Member.class,Member::getId,JkCabinetLog::getMemberId)
+                .leftJoin(Company.class,Company::getId,Member::getCompanyId)
+                .ge(Objects.nonNull(model.getStartDate()),JkCabinetLog::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getStartDate()))
+                .le(Objects.nonNull(model.getEndDate()),JkCabinetLog::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getEndDate()))
+                .like(StringUtils.isNotBlank(model.getMemberName()),Member::getName,model.getMemberName())
+                .eq(Objects.nonNull(model.getCabinetId()),JkCabinetLog::getCabinetId,model.getCabinetId())
+                .eq(Objects.nonNull(model.getKeyId()),JkCabinetLog::getKeyId,model.getKeyId())
+                .eq(Objects.nonNull(model.getAuthType()),JkCabinetLog::getAuthType,model.getAuthType())
+                .eq(Objects.nonNull(model.getStatus()),JkCabinetLog::getStatus,model.getStatus())
+                .eq(Objects.nonNull(model.getType()),JkCabinetLog::getType,model.getType())
+                .in(Objects.nonNull(model.getType())&&Constants.equalsInteger(model.getType(),Constants.ONE),JkCabinetLog::getType,"1,2")
+                .eq(JkCabinetLog::getIsdeleted, Constants.ZERO)
+                .orderByDesc(JkCabinetLog::getCreateDate);
+        IPage<JkCabinetLog>  iPage = jkCabinetLogMapper.selectJoinPage(page,JkCabinetLog.class,wrapper);
+        for (JkCabinetLog jkCabinetLog:iPage.getRecords()) {
+            if(StringUtils.isNotBlank(jkCabinetLog.getCompanyName())&&StringUtils.isNotBlank(jkCabinetLog.getMemberName())){
+                jkCabinetLog.setMemberName(jkCabinetLog.getMemberName() + " - " + jkCabinetLog.getCompanyName() );
+            }
+        }
+        return PageData.from(iPage);
+    }
+
+    @Override
+    public long count(JkCabinetLog jkCabinetLog) {
+        QueryWrapper<JkCabinetLog> wrapper = new QueryWrapper<>(jkCabinetLog);
+        return jkCabinetLogMapper.selectCount(wrapper);
+    }
+
+
+
+    @Override
+    public List<TelecomJkCabinetLogVO> getLogListForTelecom(TelecomCabinetLogDTO model){
+        MPJLambdaWrapper<JkCabinetLog> wrapper = new MPJLambdaWrapper<JkCabinetLog>()
+                .selectAll(JkCabinetLog.class)
+                .selectAs(Member::getName,JkCabinetLog::getMemberName)
+                .selectAs(Company::getName,JkCabinetLog::getCompanyName)
+                .selectAs(JkCabinet::getName,JkCabinetLog::getCabinetName)
+                .selectAs(JkCabinetGrid::getCode,JkCabinetLog::getGridCode)
+                .selectAs(JkKeys::getCarCode,JkCabinetLog::getCarCode)
+                .select("j.CREATE_DATE",JkCabinetLog::getReturnDate)
+                .leftJoin(JkCabinet.class,JkCabinet::getId,JkCabinetLog::getCabinetId)
+                .leftJoin(JkCabinetGrid.class,JkCabinetGrid::getId,JkCabinetLog::getGridId)
+                .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId)
+                .leftJoin(Member.class,Member::getId,JkCabinetLog::getMemberId)
+                .leftJoin(Company.class,Company::getId,Member::getCompanyId)
+                .leftJoin(" jk_cabinet_log j on j.id=t.CLOSE_LOG_ID ")
+                .ge(Objects.nonNull(model.getStartDate()),JkCabinetLog::getCreateDate, Utils.Date.getStart(model.getStartDate()))
+                .le(Objects.nonNull(model.getEndDate()),JkCabinetLog::getCreateDate, Utils.Date.getEnd(model.getEndDate()))
+                .eq(JkCabinetLog::getIsdeleted, Constants.ZERO)
+                .eq(JkCabinetLog::getType,Constants.ONE)
+                .eq(JkCabinetLog::getKeyStatus,Constants.TWO)
+                .orderByDesc(JkCabinetLog::getCreateDate);
+        List<JkCabinetLog> jkCabinetLogs = jkCabinetLogMapper.selectJoinList(JkCabinetLog.class,wrapper);
+        List<TelecomJkCabinetLogVO> telecomJkCabinetLogVOList = new ArrayList<TelecomJkCabinetLogVO>();
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(jkCabinetLogs)){
+            for (JkCabinetLog jkCabinetLog:jkCabinetLogs) {
+                TelecomJkCabinetLogVO telecomJkCabinetLogVO = new TelecomJkCabinetLogVO();
+                BeanUtil.copyProperties(jkCabinetLog,telecomJkCabinetLogVO);
+                telecomJkCabinetLogVO.setStatus(Objects.nonNull(jkCabinetLog.getReturnDate())?Constants.ONE:Constants.ZERO);
+                telecomJkCabinetLogVOList.add(telecomJkCabinetLogVO);
+            }
+        }
+        return telecomJkCabinetLogVOList;
+    }
+
+
+
+    @Override
+    public void timeOutUnBackAlarm(JkCabinetGridServiceImpl impl){
+        Constants.WarningConfig warningConfig = Constants.WarningConfig.KEY_TIME_OUT_BACK;
+        Warning warning = warningMapper.selectOne(new QueryWrapper<Warning>().lambda()
+                .eq(Warning::getIsdeleted,Constants.ZERO)
+                .eq(Warning::getStatus,Constants.ONE)
+                .eq(Warning::getCode,warningConfig.getKey())
+                .last("limit 1")
+        );
+        if(Objects.isNull(warning)){
+            return;
+        }
+        MPJLambdaWrapper<JkCabinetLog> wrapper = new MPJLambdaWrapper<JkCabinetLog>()
+                .selectAll(JkCabinetLog.class)
+                .selectAs(Member::getName,JkCabinetLog::getMemberName)
+                .selectAs(JkKeys::getCode,JkCabinetLog::getCarCode)
+                .selectAs(JkCabinet::getLocation,JkCabinetLog::getLocation)
+                .leftJoin(JkCabinet.class,JkCabinet::getId,JkCabinetLog::getCabinetId)
+                .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetLog::getKeyId)
+                .leftJoin(Member.class,Member::getId,JkCabinetLog::getMemberId)
+                .eq(JkCabinetLog::getIsdeleted,Constants.ZERO)
+                .eq(JkCabinetLog::getType,Constants.ONE)
+                .eq(JkCabinetLog::getIsNotice,Constants.ZERO)
+                .eq(JkKeys::getStatus,Constants.TWO)
+                .isNull(JkCabinetLog::getCloseLogId)
+                .apply(" now() >  DATE_ADD(t.CREATE_DATE, INTERVAL ifnull(t1.USE_TIME,0) MINUTE) ")
+                .orderByDesc(JkCabinetLog::getCreateDate);
+        List<JkCabinetLog> jkCabinetLogs = jkCabinetLogMapper.selectJoinList(JkCabinetLog.class,wrapper);
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(jkCabinetLogs)){
+
+            List<Integer> ruleIdList =  impl.processWarnFront(warningConfig);
+
+            for (JkCabinetLog jkCabinetLog:jkCabinetLogs) {
+                String content = "銆愯溅杈�-"+jkCabinetLog.getCarCode()+"閽ュ寵銆戠敱+"+(StringUtils.isNotBlank(jkCabinetLog.getMemberName())?jkCabinetLog.getMemberName():"鏈煡浜哄憳")+"鍊熷嚭锛岃秴鏃舵湭褰掕繕";
+                //瀛樺偍鎶ヨ寮傚父璁板綍
+                WarningEvent warningEvent = new WarningEvent();
+                warningEvent.setCreateDate(new Date());
+                warningEvent.setWarningId(warning.getId());
+                warningEvent.setTitle(warningConfig.getInfo());
+                warningEvent.setContent(content );
+                warningEvent.setStatus(Constants.ZERO);
+                warningEvent.setRegion( StringUtils.isNotBlank(jkCabinetLog.getLocation())?jkCabinetLog.getLocation():"鏈煡浣嶇疆");
+                warningEventMapper.insert(warningEvent);
+                Boolean falg = false;
+                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ruleIdList)){
+                    for (Integer ruleId:ruleIdList) {
+                        WarningRule warningRule = warningRuleMapper.selectById(ruleId);
+                        if (Objects.isNull(warningRule)) {
+                            continue;
+                        }
+                        List<Member> memberList = impl.getWarningRuleMemberList(warningRule);
+                        if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(memberList)) {
+                            continue;
+                        }
+                        try {
+                            WarningPush warningPush = new WarningPush();
+                            warningPush.setCreateDate(new Date());
+                            warningPush.setIsdeleted(Constants.ZERO);
+                            warningPush.setWarningId(warning.getId());
+                            warningPush.setTitle(warningConfig.getInfo());
+
+                            warningPush.setContent(content);
+                            warningPush.setStatus(Constants.ZERO);
+                            warningPush.setPushType(Constants.ZERO);
+                            warningPush.setRegion(StringUtils.isNotBlank(jkCabinetLog.getLocation()) ? jkCabinetLog.getLocation() : "鏈煡浣嶇疆");
+                            warningPush.setMemberIds(
+                                    StringUtils.join(memberList.stream().map(i -> i.getId()).collect(Collectors.toList()), ",")
+                            );
+                            warningPush.setMemberIds(
+                                    StringUtils.join(memberList.stream().map(i -> i.getId()).collect(Collectors.toList()), ",")
+                            );
+                            warningPush.setMemberNames(StringUtils.join(memberList.stream().map(i -> i.getName()).collect(Collectors.toList()), ",")
+                            );
+
+                            if(Constants.equalsInteger(warningRule.getMemberNotice(),Constants.ONE)){
+                                //            Boolean noticeFlag = dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()),
+                                //                    StringUtils.join(memberList.stream().filter(i->StringUtils.isNotBlank(i.getDdId())).map(i->i.getDdId()).collect(Collectors.toList()),","),
+                                //                dingTalk.getAlarmNoticeMsg(warningPush.getRegion(),DateUtil.getCurrDateTime(),warningConfig.getInfo()));
+//                          warningPush.setStatus(noticeFlag?Constants.ONE:Constants.TWO);
+                                List<String> ddUserIdList = memberList.stream().filter(i->StringUtils.isNotBlank(i.getDdId())).map(i->i.getDdId()).collect(Collectors.toList());
+                                if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ddUserIdList)){
+                                    for (String ddUserId:ddUserIdList) {
+                                        impl.getJDYData(warningEvent,ddUserId,
+                                                systemDictDataBiz.queryByCode(Constants.JDY_CONFIG,Constants.JDY_ENTRY_ID).getCode()
+
+                                        );
+                                    }
+                                }
+                            }
+                            impl.sendDeviceNotice(warningRule);
+                            warningPushMapper.insert(warningPush);
+                            falg = true;
+                        }catch (Exception e){
+                            warningEvent.setStatus(Constants.TWO);
+                            warningEventMapper.updateById(warningEvent);
+                        }
+                    }
+                }
+                if(falg){
+                    warningEvent.setStatus(Constants.ONE);
+                    warningEventMapper.updateById(warningEvent);
+                }
+
+
+
+
+            }
+        }
+
+
+    }
+
+
+
+}

--
Gitblit v1.9.3