|  |  |  | 
|---|
|  |  |  | package com.doumee.service.business.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.druid.sql.visitor.functions.Concat; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.doumee.core.constants.ResponseStatus; | 
|---|
|  |  |  | import com.doumee.core.dingTalk.DingTalk; | 
|---|
|  |  |  | import com.doumee.core.dingTalk.DingTalkStream; | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.HKConstants; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.DateUtil; | 
|---|
|  |  |  | import com.doumee.dao.business.JkKeysMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Cars; | 
|---|
|  |  |  | import com.doumee.dao.business.model.JkCabinet; | 
|---|
|  |  |  | import com.doumee.dao.business.model.JkKeys; | 
|---|
|  |  |  | 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.system.SystemUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemUser; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.service.business.third.model.PageData; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.JkCabinetGridMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.JkCabinetGrid; | 
|---|
|  |  |  | import com.doumee.service.business.JkCabinetGridService; | 
|---|
|  |  |  | 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.doumee.service.business.third.model.PageWrap; | 
|---|
|  |  |  | import com.github.yulichang.toolkit.MPJWrappers; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | import com.hikvision.artemis.sdk.config.ArtemisConfig; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * @date 2025/09/28 09:01 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class JkCabinetGridServiceImpl implements JkCabinetGridService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JkKeysMapper jkKeysMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemUserMapper systemUserMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JkCabinetMapper jkCabinetMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private JkCabinetLogMapper jkCabinetLogMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WarningMapper warningMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MemberMapper memberMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WarningRuleMapper warningRuleMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DingTalk dingTalk; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(JkCabinetGrid jkCabinetGrid) { | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | }else if(Objects.nonNull(jkCabinetGrid.getChannelCode())||Objects.nonNull(jkCabinetGrid.getBoardCode())){ | 
|---|
|  |  |  | jkCabinetGridMapper.update(new UpdateWrapper<JkCabinetGrid>().lambda() | 
|---|
|  |  |  | .set(Objects.nonNull(jkCabinetGrid.getChannelCode()),JkCabinetGrid::getChannelCode,jkCabinetGrid.getChannelCode()) | 
|---|
|  |  |  | .set(Objects.nonNull(jkCabinetGrid.getBoardCode()),JkCabinetGrid::getBoardCode,jkCabinetGrid.getBoardCode()) | 
|---|
|  |  |  | .set(JkCabinetGrid::getEditDate, DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getId,jkCabinetGrid.getId())); | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | jkCabinetGridMapper.update(new UpdateWrapper<JkCabinetGrid>().lambda() | 
|---|
|  |  |  | .set(Objects.nonNull(jkCabinetGrid.getChannelCode()),JkCabinetGrid::getChannelCode,jkCabinetGrid.getChannelCode()) | 
|---|
|  |  |  | .set(Objects.nonNull(jkCabinetGrid.getBoardCode()),JkCabinetGrid::getBoardCode,jkCabinetGrid.getBoardCode()) | 
|---|
|  |  |  | .set(JkCabinetGrid::getEditDate, DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getId,jkCabinetGrid.getId())); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"请确保钥匙柜通道号/板号唯一"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(Objects.nonNull(model.getStatus()),JkCabinetGrid::getStatus,model.getStatus()) | 
|---|
|  |  |  | .isNull(Objects.nonNull(model.getBindStatus())&&Constants.equalsInteger(model.getBindStatus(),Constants.ZERO),JkCabinetGrid::getKeyId) | 
|---|
|  |  |  | .isNotNull(Objects.nonNull(model.getBindStatus())&&Constants.equalsInteger(model.getBindStatus(),Constants.ONE),JkCabinetGrid::getKeyId) | 
|---|
|  |  |  | .like(StringUtils.isNotBlank(model.getKeyCode()),JkKeys::getCode,model.getKeyCode()); | 
|---|
|  |  |  | .like(StringUtils.isNotBlank(model.getKeyCode()),JkKeys::getCode,model.getKeyCode()) | 
|---|
|  |  |  | .orderByAsc(JkCabinetGrid::getId) | 
|---|
|  |  |  | ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IPage<JkCabinetGrid> iPage = jkCabinetGridMapper.selectJoinPage(page,JkCabinetGrid.class,wrapper); | 
|---|
|  |  |  | for (JkCabinetGrid jkCabinetGrid:iPage.getRecords()) { | 
|---|
|  |  |  | jkCabinetGrid.setBindStatus(Objects.isNull(jkCabinetGrid.getKeyId())?Constants.ZERO:Constants.ONE); | 
|---|
|  |  |  | 
|---|
|  |  |  | jkCabinetGridMapper.update(new UpdateWrapper<JkCabinetGrid>().lambda() | 
|---|
|  |  |  | .set(JkCabinetGrid::getKeyId,null) | 
|---|
|  |  |  | .set(JkCabinetGrid::getEditDate, DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getId,jkCabinetGridList.stream().map(i->i.getId()).collect(Collectors.toList()))); | 
|---|
|  |  |  | .in(JkCabinetGrid::getId,jkCabinetGridList.stream().map(i->i.getId()).collect(Collectors.toList()))); | 
|---|
|  |  |  | List<Integer> keyIdList = jkCabinetGridList.stream().filter(i->Objects.nonNull(i.getKeyId())).map(i->i.getKeyId()).collect(Collectors.toList()); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(keyIdList)){ | 
|---|
|  |  |  | jkKeysMapper.update(new UpdateWrapper<JkKeys>().lambda() | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 标记故障 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void markFault(OptGridDTO dto){ | 
|---|
|  |  |  | if(Objects.isNull(dto) | 
|---|
|  |  |  | || Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || CollectionUtils.isEmpty(dto.getGridIdList())){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | List<JkCabinetGrid> jkCabinetGridList = jkCabinetGridMapper.selectList(new QueryWrapper<JkCabinetGrid>().lambda().eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) | 
|---|
|  |  |  | .in(JkCabinetGrid::getId,dto.getGridIdList()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(jkCabinetGridList)){ | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = dto.getLoginUserInfo(); | 
|---|
|  |  |  | for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) { | 
|---|
|  |  |  | jkCabinetGrid.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | jkCabinetGrid.setEditDate(new Date()); | 
|---|
|  |  |  | jkCabinetGrid.setWorkingStatus(Constants.ONE); | 
|---|
|  |  |  | jkCabinetGridMapper.updateById(jkCabinetGrid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 标记维修保养 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void markRepair(OptGridDTO dto){ | 
|---|
|  |  |  | if(Objects.isNull(dto) | 
|---|
|  |  |  | || Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || CollectionUtils.isEmpty(dto.getGridIdList())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<JkCabinetGrid> jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, | 
|---|
|  |  |  | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) | 
|---|
|  |  |  | .selectAs(JkKeys::getCode,JkCabinetGrid::getKeyCode) | 
|---|
|  |  |  | .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode) | 
|---|
|  |  |  | .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId) | 
|---|
|  |  |  | .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkKeys::getStatus,Constants.TWO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) | 
|---|
|  |  |  | .isNotNull(JkCabinetGrid::getKeyId) | 
|---|
|  |  |  | .in(JkCabinetGrid::getId,dto.getGridIdList()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(jkCabinetGridList)){ | 
|---|
|  |  |  | for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) { | 
|---|
|  |  |  | jkKeysMapper.update(null,new UpdateWrapper<JkKeys>().lambda() | 
|---|
|  |  |  | .set(JkKeys::getEditDate,DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .set(JkKeys::getStatus,Constants.THREE) | 
|---|
|  |  |  | .eq(JkKeys::getId,jkCabinetGrid.getKeyId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 取消故障 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void cancelFault(OptGridDTO dto){ | 
|---|
|  |  |  | if(Objects.isNull(dto) | 
|---|
|  |  |  | || Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || CollectionUtils.isEmpty(dto.getGridIdList())){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<JkCabinetGrid> jkCabinetGridList = jkCabinetGridMapper.selectList(new QueryWrapper<JkCabinetGrid>().lambda().eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getWorkingStatus,Constants.ONE) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) | 
|---|
|  |  |  | .in(JkCabinetGrid::getId,dto.getGridIdList()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(jkCabinetGridList)){ | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = dto.getLoginUserInfo(); | 
|---|
|  |  |  | for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) { | 
|---|
|  |  |  | jkCabinetGrid.setEditor(loginUserInfo.getId()); | 
|---|
|  |  |  | jkCabinetGrid.setEditDate(new Date()); | 
|---|
|  |  |  | jkCabinetGrid.setWorkingStatus(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetGridMapper.updateById(jkCabinetGrid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设备管理员批量开锁 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void batchOpenGridAdmin(OptGridDTO dto){ | 
|---|
|  |  |  | if(Objects.isNull(dto) | 
|---|
|  |  |  | || Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || CollectionUtils.isEmpty(dto.getGridIdList())){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<JkCabinetGrid> jkCabinetGridList = jkCabinetGridMapper.selectList(new QueryWrapper<JkCabinetGrid>().lambda().eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) | 
|---|
|  |  |  | .in(JkCabinetGrid::getId,dto.getGridIdList()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(CollectionUtils.isNotEmpty(jkCabinetGridList)){ | 
|---|
|  |  |  | LoginUserInfo loginUserInfo = dto.getLoginUserInfo(); | 
|---|
|  |  |  | if(org.apache.commons.collections.CollectionUtils.isNotEmpty(jkCabinetGridList)){ | 
|---|
|  |  |  | List<JkCabinetLog> jkCabinetLogs = new ArrayList<>(); | 
|---|
|  |  |  | for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) { | 
|---|
|  |  |  | JkCabinetLog jkCabinetLog = new JkCabinetLog(); | 
|---|
|  |  |  | jkCabinetLog.setCreateDate(new Date()); | 
|---|
|  |  |  | jkCabinetLog.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | jkCabinetLog.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetLog.setCabinetId(dto.getCabinetId()); | 
|---|
|  |  |  | jkCabinetLog.setGridId(jkCabinetGrid.getId()); | 
|---|
|  |  |  | jkCabinetLog.setAuthType(Constants.TWO); | 
|---|
|  |  |  | jkCabinetLog.setMemberId(loginUserInfo.getMemberId()); | 
|---|
|  |  |  | jkCabinetLog.setStatus(Constants.ZERO); | 
|---|
|  |  |  | if(Objects.nonNull(jkCabinetGrid.getKeyId())){ | 
|---|
|  |  |  | jkCabinetLog.setKeyId(jkCabinetGrid.getKeyId()); | 
|---|
|  |  |  | JkKeys jkKeys = jkKeysMapper.selectById(jkCabinetGrid.getKeyId()); | 
|---|
|  |  |  | if(Objects.nonNull(jkKeys)){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(jkKeys.getStatus(),Constants.ZERO)){ | 
|---|
|  |  |  | jkCabinetLog.setCarId(jkKeys.getCarId()); | 
|---|
|  |  |  | jkCabinetLog.setKeyInfo(jkKeys.getCarCode() + "_" + jkKeys.getCode() ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLog.setRoleType(jkKeys.getRoleType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLog.setType(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetLogs.add(jkCabinetLog); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLogMapper.insert(jkCabinetLogs); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 钥匙柜关门 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void closeGrid(CloseGridDTO dto){ | 
|---|
|  |  |  | if(Objects.isNull(dto) | 
|---|
|  |  |  | || Objects.isNull(dto.getGridId()) | 
|---|
|  |  |  | || Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || Objects.isNull(dto.getKeyStatus()) | 
|---|
|  |  |  | || Objects.isNull(dto.getAuthType()) | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | JkCabinetGrid jkCabinetGrid = jkCabinetGridMapper.selectOne(new QueryWrapper<JkCabinetGrid>().lambda().eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getId,dto.getGridId()) | 
|---|
|  |  |  | .last(" limit 1 ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.nonNull(jkCabinetGrid)){ | 
|---|
|  |  |  | JkCabinetLog jkCabinetLog = new JkCabinetLog(); | 
|---|
|  |  |  | jkCabinetLog.setCreateDate(new Date()); | 
|---|
|  |  |  | jkCabinetLog.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetLog.setCabinetId(dto.getCabinetId()); | 
|---|
|  |  |  | jkCabinetLog.setGridId(jkCabinetGrid.getId()); | 
|---|
|  |  |  | jkCabinetLog.setAuthType(dto.getAuthType()); | 
|---|
|  |  |  | jkCabinetLog.setMemberId(dto.getMemberId()); | 
|---|
|  |  |  | jkCabinetLog.setKeyStatus(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetLog.setStatus(Constants.ZERO); | 
|---|
|  |  |  | if(Objects.nonNull(jkCabinetGrid.getKeyId())){ | 
|---|
|  |  |  | //只有钥匙柜绑定了钥匙信息 才会更新钥匙的信息 | 
|---|
|  |  |  | JkKeys jkKeys = jkKeysMapper.selectById(jkCabinetGrid.getKeyId()); | 
|---|
|  |  |  | jkCabinetLog.setKeyId(jkCabinetGrid.getKeyId()); | 
|---|
|  |  |  | if(Objects.nonNull(jkKeys)){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(jkKeys.getStatus(),Constants.ZERO)){ | 
|---|
|  |  |  | jkCabinetLog.setCarId(jkKeys.getCarId()); | 
|---|
|  |  |  | jkCabinetLog.setKeyInfo(jkKeys.getCarCode() + "_" + jkKeys.getCode() ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLog.setRoleType(jkKeys.getRoleType()); | 
|---|
|  |  |  | jkCabinetLog.setKeyStatus(dto.getKeyStatus()); | 
|---|
|  |  |  | //钥匙状态与当前操作状态不一致,则进行更新钥匙状态 | 
|---|
|  |  |  | if(!Constants.equalsInteger(jkKeys.getStatus(),dto.getKeyStatus()) | 
|---|
|  |  |  | && (Constants.equalsInteger(dto.getKeyStatus(),Constants.ONE)||Constants.equalsInteger(dto.getKeyStatus(),Constants.TWO))){ | 
|---|
|  |  |  | jkKeysMapper.update(null,new UpdateWrapper<JkKeys>().lambda() | 
|---|
|  |  |  | .set(JkKeys::getEditDate,DateUtil.getCurrDateTime()) | 
|---|
|  |  |  | .set(JkKeys::getStatus,dto.getKeyStatus()) | 
|---|
|  |  |  | .eq(JkKeys::getId,jkKeys.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLog.setType(Constants.ONE); | 
|---|
|  |  |  | jkCabinetLogMapper.insert(jkCabinetLog); | 
|---|
|  |  |  | //查询钥匙的开门记录 进行添加关门记录主键 | 
|---|
|  |  |  | jkCabinetLogMapper.update(null,new UpdateWrapper<JkCabinetLog>().lambda() | 
|---|
|  |  |  | .set(JkCabinetLog::getCloseLogId,jkCabinetLog.getId()) | 
|---|
|  |  |  | .eq(JkCabinetLog::getKeyId,jkCabinetLog.getKeyId()) | 
|---|
|  |  |  | .eq(JkCabinetLog::getType,Constants.ZERO) | 
|---|
|  |  |  | .isNull(JkCabinetLog::getCloseLogId)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 司机获取可操作的钥匙柜柜格 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<JkCabinetGrid> getDriverGrid(GetDriverGridDTO dto){ | 
|---|
|  |  |  | List<JkCabinetGrid> jkCabinetGridList = new ArrayList<>(); | 
|---|
|  |  |  | if(Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || Objects.isNull(dto.getCabinetId()) | 
|---|
|  |  |  | || Objects.isNull(dto.getMemberId()) | 
|---|
|  |  |  | || Objects.isNull(dto.getType())){ | 
|---|
|  |  |  | return jkCabinetGridList; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | JkCabinet jkCabinet = jkCabinetMapper.selectById(dto.getCabinetId()); | 
|---|
|  |  |  | if(Objects.isNull(jkCabinet)){ | 
|---|
|  |  |  | return jkCabinetGridList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger(jkCabinet.getDoubleAuth(),Constants.ONE)){ | 
|---|
|  |  |  | if(StringUtils.isBlank(jkCabinet.getAuthMemberId())){ | 
|---|
|  |  |  | return jkCabinetGridList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> authMemberList =  Arrays.asList(jkCabinet.getAuthMemberId().split(",")); | 
|---|
|  |  |  | Boolean flag = true; | 
|---|
|  |  |  | for (String id:authMemberList) { | 
|---|
|  |  |  | if(Arrays.asList(jkCabinet.getAuthMemberId().split(",")).contains(id)){ | 
|---|
|  |  |  | flag = false; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(flag){ | 
|---|
|  |  |  | return jkCabinetGridList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, | 
|---|
|  |  |  | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) | 
|---|
|  |  |  | .selectAs(JkKeys::getCode,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::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) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) { | 
|---|
|  |  |  | jkCabinetGrid.setBindStatus(Objects.isNull(jkCabinetGrid.getKeyId())?Constants.ZERO:Constants.ONE); | 
|---|
|  |  |  | jkCabinetGrid.setKeyStatus(Objects.isNull(jkCabinetGrid.getKeyStatus())?Constants.ZERO:jkCabinetGrid.getKeyStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return jkCabinetGridList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 司机开启柜格 | 
|---|
|  |  |  | * @param openGridDriverDTO | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void openGridDriver(OpenGridDriverDTO openGridDriverDTO){ | 
|---|
|  |  |  | JkCabinetGrid jkCabinetGrid = jkCabinetGridMapper.selectOne(new QueryWrapper<JkCabinetGrid>().lambda().eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getCabinetId,openGridDriverDTO.getCabinetId()) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getId,openGridDriverDTO.getGridId()) | 
|---|
|  |  |  | .last(" limit 1 ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(Objects.isNull(jkCabinetGrid)){ | 
|---|
|  |  |  | return ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        LoginUserInfo loginUserInfo = openGridDriverDTO.getLoginUserInfo(); | 
|---|
|  |  |  | JkCabinetLog jkCabinetLog = new JkCabinetLog(); | 
|---|
|  |  |  | jkCabinetLog.setCreateDate(new Date()); | 
|---|
|  |  |  | //        jkCabinetLog.setCreator(loginUserInfo.getId()); | 
|---|
|  |  |  | jkCabinetLog.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetLog.setCabinetId(openGridDriverDTO.getCabinetId()); | 
|---|
|  |  |  | jkCabinetLog.setGridId(jkCabinetGrid.getId()); | 
|---|
|  |  |  | jkCabinetLog.setAuthType(openGridDriverDTO.getAuthType()); | 
|---|
|  |  |  | jkCabinetLog.setMemberId(openGridDriverDTO.getMemberId()); | 
|---|
|  |  |  | jkCabinetLog.setType(Constants.ZERO); | 
|---|
|  |  |  | jkCabinetLog.setStatus(Constants.ZERO); | 
|---|
|  |  |  | if(Objects.nonNull(jkCabinetGrid.getKeyId())){ | 
|---|
|  |  |  | jkCabinetLog.setKeyId(jkCabinetGrid.getKeyId()); | 
|---|
|  |  |  | JkKeys jkKeys = jkKeysMapper.selectById(jkCabinetGrid.getKeyId()); | 
|---|
|  |  |  | if(Objects.nonNull(jkKeys)){ | 
|---|
|  |  |  | if(!Constants.equalsInteger(jkKeys.getStatus(),Constants.ZERO)){ | 
|---|
|  |  |  | jkCabinetLog.setCarId(jkKeys.getCarId()); | 
|---|
|  |  |  | jkCabinetLog.setKeyInfo(jkKeys.getCarCode() + "_" + jkKeys.getCode() ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLog.setRoleType(jkKeys.getRoleType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jkCabinetLogMapper.insert(jkCabinetLog); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void timeOutUnCloseAlarm(TimeOutCloseGridDTO dto){ | 
|---|
|  |  |  | if(Objects.nonNull(dto) | 
|---|
|  |  |  | && Objects.nonNull(dto.getGridId())){ | 
|---|
|  |  |  | JkCabinetGrid jkCabinetGrid = jkCabinetGridMapper.selectJoinOne(JkCabinetGrid.class, | 
|---|
|  |  |  | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) | 
|---|
|  |  |  | .selectAs(JkCabinet::getName,JkCabinetGrid::getCabinetName) | 
|---|
|  |  |  | .leftJoin(JkCabinet.class,JkCabinet::getId,JkCabinetGrid::getCabinetId) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(JkCabinetGrid::getId,dto.getGridId()) | 
|---|
|  |  |  | .last(" limit 1 ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(Objects.nonNull(jkCabinetGrid)){ | 
|---|
|  |  |  | log.error("柜格开门超时未关闭告警信息:{}"+JSONObject.toJSONString(jkCabinetGrid)); | 
|---|
|  |  |  | Warning warning = warningMapper.selectOne(new QueryWrapper<Warning>().lambda() | 
|---|
|  |  |  | .eq(Warning::getType,Constants.THREE).eq(Warning::getCode,Constants.WarningConfig.GRID_TIME_OUT_INFO.getKey()).eq(Warning::getIsdeleted,Constants.ZERO).last("limt 1")); | 
|---|
|  |  |  | if(Objects.isNull(warning)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Member> memberList = this.getWarningList(warning); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(memberList)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //todo 存储异常日志 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<Member> getWarningList(Warning warning){ | 
|---|
|  |  |  | if(Constants.equalsInteger(warning.getStatus(),Constants.ZERO)){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //查询通知人员 | 
|---|
|  |  |  | List<WarningRule> warningRuleList = warningRuleMapper.selectList(new QueryWrapper<WarningRule>().lambda() | 
|---|
|  |  |  | .eq(WarningRule::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .apply(" id in ( select w.RULE_ID from warning_rule_detail w where w.WARNING_ID = '"+warning.getId()+"' and w.ISDELETED = 0  ) ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Member> memberList = new ArrayList<>(); | 
|---|
|  |  |  | if(org.apache.commons.collections.CollectionUtils.isNotEmpty(warningRuleList)){ | 
|---|
|  |  |  | List<String> memberIdStr =  warningRuleList.stream().map(i->i.getMemberIds()).collect(Collectors.toList()); | 
|---|
|  |  |  | if(org.apache.commons.collections.CollectionUtils.isNotEmpty(memberIdStr)){ | 
|---|
|  |  |  | List<String> memberIdList = new ArrayList<>(); | 
|---|
|  |  |  | for (String s:memberIdStr) { | 
|---|
|  |  |  | memberIdList.addAll( | 
|---|
|  |  |  | Arrays.asList(s.split(",")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .notIn(Member::getErpId) | 
|---|
|  |  |  | .in(Member::getId,memberIdList) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return memberList; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void alcoholTestAlarm(AlcoholTestAlarmDTO dto){ | 
|---|
|  |  |  | if(Objects.nonNull(dto) | 
|---|
|  |  |  | && Objects.nonNull(dto.getMemberId())){ | 
|---|
|  |  |  | SystemUser systemUser = | 
|---|
|  |  |  | systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda() | 
|---|
|  |  |  | .eq(SystemUser::getMemberId,dto.getMemberId()) | 
|---|
|  |  |  | .eq(SystemUser::getDeleted,Constants.ZERO) | 
|---|
|  |  |  | .last(" limit 1 ") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Warning warning = warningMapper.selectOne(new QueryWrapper<Warning>().lambda() | 
|---|
|  |  |  | .eq(Warning::getType,Constants.THREE).eq(Warning::getCode,Constants.WarningConfig.KEY_TIME_OUT_BACK.getKey()).eq(Warning::getIsdeleted,Constants.ZERO).last("limt 1")); | 
|---|
|  |  |  | if(Objects.isNull(warning)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Member> memberList = this.getWarningList(warning); | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(memberList)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //todo 存储异常日志 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存储异常日志 | 
|---|
|  |  |  | if(Objects.nonNull(systemUser)){ | 
|---|
|  |  |  | log.error("司机酒精检测,超出酒精值告警信息:{}"+JSONObject.toJSONString(systemUser)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|