rk
昨天 4ee00850f197d769481f73acb8ed79ab1c75b84d
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){