rk
17 小时以前 2f65c9f0c9dae7c192a81a79d94b7eba614c8b23
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/JkCabinetLogServiceImpl.java
@@ -3,16 +3,19 @@
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.core.utils.DateUtil;
import com.doumee.dao.admin.response.InterestedListVO;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dto.CabinetBoardUseRecordDTO;
import com.doumee.dao.business.dto.TelecomCabinetLogDTO;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.vo.CabinetBoardUseRecordVO;
import com.doumee.dao.business.vo.TelecomJkCabinetLogVO;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemUser;
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;
@@ -49,6 +52,12 @@
    @Autowired
    private WarningPushMapper warningPushMapper;
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private WarningEventMapper warningEventMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Override
@@ -192,7 +201,11 @@
    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"));
                .eq(Warning::getIsdeleted,Constants.ZERO)
                .eq(Warning::getStatus,Constants.ONE)
                .eq(Warning::getCode,warningConfig.getKey())
                .last("limit 1")
        );
        if(Objects.isNull(warning)){
            return;
        }
@@ -213,43 +226,180 @@
                .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)){
            List<Integer> ruleIdList =  impl.processWarnFront(warningConfig);
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ruleIdList)){
                return;
            }
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ruleIdList)){
                return;
            }
            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)) {
                    return;
                }
                for (JkCabinetLog jkCabinetLog:jkCabinetLogs) {
                    WarningPush warningPush = new WarningPush();
                    warningPush.setCreateDate(new Date());
                    warningPush.setIsdeleted(Constants.ZERO);
                    warningPush.setWarningId(warning.getId());
                    warningPush.setTitle(warningConfig.getInfo());
                    SystemUser systemUser =  null;
                    if(Objects.nonNull(jkCabinetLog.getMemberId())){
                        systemUser = systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda()
                                .eq(Objects.nonNull(jkCabinetLog.getMemberId()),SystemUser::getMemberId,jkCabinetLog.getMemberId())
                                .eq(SystemUser::getDeleted,Constants.ZERO)
                                .last(" limit 1 ")
                        );
                    }
                    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);
                    //存储报警异常记录
                    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 );
                    warningEvent.setStatus(Constants.ZERO);
                    warningEvent.setRegion( StringUtils.isNotBlank(jkCabinetLog.getLocation())?jkCabinetLog.getLocation():"未知位置");
                    warningEventMapper.insert(warningEvent);
                    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()), ",")
                        );
                        //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);
                        warningEvent.setStatus(Constants.ONE);
                        warningEventMapper.updateById(warningEvent);
                    }catch (Exception e){
                        warningEvent.setStatus(Constants.TWO);
                        warningEventMapper.updateById(warningEvent);
                    }
                }
            }
        }
    }
    @Override
    public List<CabinetBoardUseRecordVO> getKeyUseRecord(CabinetBoardUseRecordDTO dto){
        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(JkCabinetLog::getCreateDate, Utils.Date.getStart(DateUtil.getCurrentDate()))
                .le(JkCabinetLog::getCreateDate, Utils.Date.getEnd(Utils.Date.getStart(DateUtil.getCurrentDate())))
                .eq(JkCabinetLog::getIsdeleted, Constants.ZERO)
                .eq(JkCabinetLog::getType,Constants.ONE)
                .eq(JkCabinetLog::getKeyStatus,Constants.TWO)
                .like(StringUtils.isNotBlank(dto.getCarCode()),JkCabinetLog::getCarCode,dto.getCarCode())
                .isNotNull(Objects.nonNull(dto.getStatus())&&Constants.equalsInteger(dto.getStatus(),Constants.ONE),JkCabinetLog::getCloseLogId)
                .isNull(Objects.nonNull(dto.getStatus())&&Constants.equalsInteger(dto.getStatus(),Constants.ZERO),JkCabinetLog::getCloseLogId)
                .orderByDesc(JkCabinetLog::getCreateDate);
        List<JkCabinetLog> jkCabinetLogs = jkCabinetLogMapper.selectJoinList(JkCabinetLog.class,wrapper);
        List<CabinetBoardUseRecordVO> cabinetBoardUseRecordList = new ArrayList<CabinetBoardUseRecordVO>();
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(jkCabinetLogs)){
            for (JkCabinetLog jkCabinetLog:jkCabinetLogs) {
                CabinetBoardUseRecordVO cabinetBoardUseRecordVO = new CabinetBoardUseRecordVO();
                BeanUtil.copyProperties(jkCabinetLog,cabinetBoardUseRecordVO);
                cabinetBoardUseRecordVO.setStatus(Objects.nonNull(jkCabinetLog.getReturnDate())?Constants.ZERO:Constants.ONE);
                cabinetBoardUseRecordVO.setRemark(Objects.isNull(jkCabinetLog.getOpenWay())?"":
                        Constants.equalsInteger(jkCabinetLog.getOpenWay(),Constants.ZERO)?"随车领取":
                                Constants.equalsInteger(jkCabinetLog.getOpenWay(),Constants.ONE)?"随派车单领取":"保洁领取"
                        );
                cabinetBoardUseRecordList.add(cabinetBoardUseRecordVO);
            }
        }
        return cabinetBoardUseRecordList;
    }
    @Override
    public List<InterestedListVO> getKeyUseStatistics(Integer type){
        List<String> weekDays = DateUtil.getBeforDays(new Date(),Objects.isNull(type)||Constants.equalsInteger(type,Constants.ZERO)?7:15);
        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 ")
                .eq(JkCabinetLog::getIsdeleted, Constants.ZERO)
                .eq(JkCabinetLog::getType,Constants.ONE)
                .ne(JkCabinetLog::getKeyStatus,Constants.ZERO)
                .apply("  CREATE_DATE >   CURDATE() - INTERVAL "+(Objects.isNull(type)||Constants.equalsInteger(type,Constants.ZERO)?7:15)+" DAY ")
                .orderByDesc(JkCabinetLog::getCreateDate);
        List<JkCabinetLog> jkCabinetLogs = jkCabinetLogMapper.selectJoinList(JkCabinetLog.class,wrapper);
        List<InterestedListVO> list = new ArrayList<>();
        for (String days:weekDays) {
            InterestedListVO vo = new InterestedListVO();
            vo.setName(days);
            vo.setNum(Constants.ZERO);
            vo.setNextNum(Constants.ZERO);
            if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(jkCabinetLogs)) {
                vo.setNum(
                        jkCabinetLogs.stream().filter(i->Constants.equalsInteger(i.getKeyStatus(),Constants.TWO)
                                                &&DateUtil.dateToString(i.getCreateDate(),"yyyy-MM-dd").equals(days))
                                .collect(Collectors.toList()).size()
                );
                vo.setNextNum(jkCabinetLogs.stream().filter(i->Constants.equalsInteger(i.getKeyStatus(),Constants.ONE)
                                &&DateUtil.dateToString(i.getCreateDate(),"yyyy-MM-dd").equals(days))
                        .collect(Collectors.toList()).size());
            }
        }
        return list;
    }
}