rk
8 小时以前 2f65c9f0c9dae7c192a81a79d94b7eba614c8b23
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;
    }
}