rk
22 小时以前 9fdd262881ef10d79e75d8e91d36fef88f774073
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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.WarningMapper;
import com.doumee.dao.business.WarningPushMapper;
import com.doumee.dao.business.WarningRuleMapper;
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.dao.business.JkCabinetLogMapper;
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 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.ZERO:Constants.ONE);
                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::getType,Constants.THREE).eq(Warning::getCode,warningConfig.getKey()).eq(Warning::getIsdeleted,Constants.ZERO).last("limt 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<Member> memberList = impl.getWarningList(warning);
 
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(memberList)){
                for (JkCabinetLog jkCabinetLog:jkCabinetLogs) {
                    WarningPush warningPush = new WarningPush();
                    warningPush.setCreateDate(new Date());
                    warningPush.setIsdeleted(Constants.ZERO);
                    warningPush.setWarningId(warning.getId());
                    warningPush.setTitle(warningConfig.getInfo());
                    String content = "【车辆-"+jkCabinetLog.getCarCode()+"钥匙】由+"+(StringUtils.isNotBlank(jkCabinetLog.getMemberName())?jkCabinetLog.getMemberName():"未知人员")+"借出,超时未归还";
                    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()),",")
                    );
                    //todo 暂时关闭 钉钉通知
 
    //            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(),content));
    //            warningPush.setStatus(noticeFlag?Constants.ONE:Constants.TWO);
                    warningPushMapper.insert(warningPush);
 
                }
            }
        }
 
 
    }
 
 
 
}