KeyBoxVoServiceImpl.java 6.84 KB
package com.ruoyi.service.impl.dss;

import cn.hutool.core.convert.Convert;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.caiinfo.CarInfo;
import com.ruoyi.domain.equipment.linke.log.LingangEquipmentLinkeLog;
import com.ruoyi.domain.key.info.KeyInfo;
import com.ruoyi.domain.key.info.box.dto.KeyBoxQueryDTO;
import com.ruoyi.domain.key.info.box.vo.KeyBoxVo;
import com.ruoyi.domain.lin.gang.LingangScheduling;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.service.IEquipmentService;
import com.ruoyi.in.domain.SignIn;
import com.ruoyi.in.service.ISignInService;
import com.ruoyi.service.carinfo.CarInfoService;
import com.ruoyi.service.dss.KeyBoxVoService;
import com.ruoyi.service.equipment.linke.log.LingangEquipmentLinkeLogService;
import com.ruoyi.service.key.info.KeyInfoService;
import com.ruoyi.service.lin.gang.LingangSchedulingService;
import com.ruoyi.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.MessageFormat;
import java.util.Objects;

/**
 * @author liujun
 * @date 2024年06月25日 15:18
 */
@Service
public class KeyBoxVoServiceImpl implements KeyBoxVoService {
    @Autowired
    private KeyInfoService keyInfoService;
    @Autowired
    private LingangSchedulingService lingangSchedulingService;
    @Autowired
    private ISignInService signInService;
    @Autowired
    private IEquipmentService iEquipmentService;
    @Autowired
    private CarInfoService carInfoService;
    @Autowired
    private LingangEquipmentLinkeLogService lingangEquipmentLinkeLogService;

    @Override
    public ResponseResult<KeyBoxVo> listSelect(KeyBoxQueryDTO request, LingangEquipmentLinkeLog linkeLog) {
        LingangScheduling lingangScheduling = queryScheduling(request);
        if (Objects.isNull(lingangScheduling)) {
            String msg = MessageFormat.format("工号[{0}]在[{1}]没有排班信息", request.getStaffCode(), request.getTime());
            linkeLog.setStatus(HttpStatus.ERROR);
            linkeLog.setResult(msg);
            lingangEquipmentLinkeLogService.updateByPrimaryKey(linkeLog);

            return ResponseResult.error(msg);
        }

        SignIn signIn = querySignIn(lingangScheduling.getSignInId());
        if (Objects.isNull(signIn)) {
            lingangEquipmentLinkeLogService.updateByPrimaryKey(linkeLog, MessageFormat.format("工号[{0}]在[{1}]没有签到或签退信息;[{2}]", request.getStaffCode(), request.getTime(), lingangScheduling.getSignInId()), HttpStatus.ERROR);


            return ResponseResult.error(MessageFormat.format("工号[{0}]在[{1}]没有签到或签退信息", request.getStaffCode(), request.getTime()));
        }

        KeyInfo keyInfo = queryKeyInfo(lingangScheduling.getKeyInfoId());
        if (Objects.isNull(keyInfo)) {
            lingangEquipmentLinkeLogService.updateByPrimaryKey(linkeLog, MessageFormat.format("工号[{0}]在[{1}]没有分配钥匙;[{2}]", request.getStaffCode(), request.getTime(), lingangScheduling.getKeyInfoId()), HttpStatus.ERROR);


            return ResponseResult.error(MessageFormat.format("工号[{0}]在[{1}]没有分配钥匙", request.getStaffCode(), request.getTime()));
        }


        Equipment equipment = queryEquipment(Convert.toLong(signIn.getDeviceId()));
        if (Objects.isNull(equipment)) {
            lingangEquipmentLinkeLogService.updateByPrimaryKey(linkeLog, MessageFormat.format("工号[{0}]在[{1}]找不到设备信息;[{2}]", request.getStaffCode(), request.getTime(), signIn.getDeviceId()), HttpStatus.ERROR);

            return ResponseResult.error(MessageFormat.format("工号[{0}]在[{1}]找不到设备信息", request.getStaffCode(), request.getTime()));
        }

        CarInfo carInfo = queryCarInfo(lingangScheduling.getNbbm());
        if (Objects.isNull(carInfo)) {
            lingangEquipmentLinkeLogService.updateByPrimaryKey(linkeLog, MessageFormat.format("工号[{0}]在[{1}]找不到设备信息;[{2}]", request.getStaffCode(), request.getTime(), lingangScheduling.getNbbm()), HttpStatus.ERROR);


            return ResponseResult.error(MessageFormat.format("工号[{0}]在[{1}]找不到车辆信息", request.getStaffCode(), request.getTime()));
        }
        KeyBoxVo keyBoxVo = new KeyBoxVo();
        //keyBoxVo.setCabinetNo(Convert.toStr(keyInfo.getCabinetno()));
//        keyBoxVo.setDevice("");
        keyBoxVo.setDeviceName(equipment.getName());
//        keyBoxVo.setYardId(Convert.toStr(keyInfo.getYardId()));
//        keyBoxVo.setYardName(Convert.toStr(keyInfo.getS()));
        keyBoxVo.setPlateNum(lingangScheduling.getNbbm());
        keyBoxVo.setParkingNo(carInfo.getParkingNo());
        keyBoxVo.setKeyCode(keyInfo.getKeyCode());

        lingangEquipmentLinkeLogService.updateByPrimaryKey(linkeLog, null, HttpStatus.SUCCESS);
        return ResponseResult.success(keyBoxVo);
    }


    /***
     * 根据时间和司机工号查询排班信息
     * @author liujun
     * @date 2024/6/25 14:07
     * @param request
     * @return com.ruoyi.domain.lin.gang.LingangScheduling
     */
    private LingangScheduling queryScheduling(KeyBoxQueryDTO request) {
        LingangScheduling lingangScheduling = new LingangScheduling();
        lingangScheduling.setScheduleDate(DateUtil.parseLocalDate(request.getTime()));
        lingangScheduling.setJobCode(request.getStaffCode());
        if(StringUtils.equals(request.getEventType(), "0")){
            lingangScheduling.setSignType(1);
        }else if(StringUtils.equals(request.getEventType(), "1")){
            lingangScheduling.setSignType(2);
        }

        return lingangSchedulingService.getOne(lingangScheduling);

    }

    /***
     * 查询签到信息
     * @author liujun
     * @date 2024/6/25 14:30
     * @param signInId 签到ID
     * @return com.ruoyi.in.domain.SignIn
     */
    private SignIn querySignIn(Long signInId) {
        return signInService.selectSignInById(signInId);
    }

    /***
     * 根据钥匙ID查询钥匙信息
     * @author liujun
     * @date 2024/6/25 14:39
     * @param keyInfoId
     * @return com.ruoyi.domain.keyInfo.KeyInfo
     */
    private KeyInfo queryKeyInfo(Integer keyInfoId) {
        return keyInfoService.getById(keyInfoId);
    }

    /***
     * 查询设备信息
     * @author liujun
     * @date 2024/6/25 14:43
     * @param equipmentId
     * @return com.ruoyi.equipment.domain.Equipment
     */
    private Equipment queryEquipment(long equipmentId) {
        return iEquipmentService.selectEquipmentById(equipmentId);
    }

    /***
     * 根据车牌号查询车辆信息
     * @author liujun
     * @date 2024/6/25 15:00
     * @param plateNum
     * @return com.ruoyi.domain.caiinfo.CarInfo
     */
    private CarInfo queryCarInfo(String plateNum) {
        return carInfoService.getOneByPlateNum(plateNum);
    }


}