package com.zteits.park.dao.impl; import com.clouds.common.utils.ListCopyUtil; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.dto.park.dto.ChannelInfoDTO; import com.zteits.clouds.api.dto.park.param.closecarpark.CheckChannelNumRequest; import com.zteits.clouds.api.dto.park.param.closecarpark.QueryChannelInfoByNoRequest; import com.zteits.clouds.api.dto.park.param.closecarpark.QueryChannelInfoRequest; import com.zteits.clouds.api.dto.park.param.closecarpark.QueryChannelNameByChannelNumsRequest; import com.zteits.park.dao.ChannelDao; import com.zteits.park.domain.ParkingLotChannel; import com.zteits.park.domain.ParkingLotChannelExample; import com.zteits.park.mapper.ParkingLotChannelMapper; import com.zteits.park.mapper.ParkingLotEquipmentMapper; import com.zteits.park.mapper.smapper.ParkingLotChannelSMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.util.ArrayList; import java.util.List; @Component public class ChannelDaoImpl implements ChannelDao { @Autowired private ParkingLotChannelMapper parkingLotChannelMapper; @Autowired private ParkingLotChannelSMapper parkingLotChannelSMapper; @Autowired private ParkingLotEquipmentMapper parkingLotEquipmentMapper; /** * 每一页大小. */ private static final Integer PAGE_SIZE = 500; @Override public ChannelInfoDTO QueryChannelInfo(QueryChannelInfoRequest request) { ChannelInfoDTO channelInfoDTO = new ChannelInfoDTO(); ParkingLotChannelExample example = new ParkingLotChannelExample(); example.createCriteria().andIdEqualTo(request.getId()).andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); channelInfoDTO = parkingLotChannelSMapper.selectByChannel(request); return channelInfoDTO; } @Override public int insertSelective(ParkingLotChannel record) { if (record == null) { return 0; } if (record.getDataStatus() == null) { record.setDataStatus(DataStatusEnum.DATA_STATUS_NO_VALID.value()); } return parkingLotChannelMapper.insertSelective(record); } @Override public int updateSelective(ParkingLotChannel record) { if (record == null) { return 0; } if (record.getDataStatus() == null) { record.setDataStatus(DataStatusEnum.DATA_STATUS_NO_VALID.value()); } return parkingLotChannelSMapper.updateChannelByPrimaryKey(record); } @Override public int deleteSelective(ParkingLotChannel record) { if (record == null) { return 0; } if (record.getDataStatus() == null) { record.setDataStatus(DataStatusEnum.DATA_STATUS_NO_VALID.value()); } return parkingLotChannelSMapper.deleteChannelByPrimaryKey(record); } @Override public int updateTideChannelByNum(ParkingLotChannel record) { if (record == null) { return 0; } ParkingLotChannelExample example = new ParkingLotChannelExample(); ParkingLotChannelExample.Criteria sql = example.createCriteria(); // if(!StringUtils.isEmpty(record.getId())){ sql.andIdEqualTo(record.getId()); } sql.andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); return parkingLotChannelMapper.updateByExampleSelective(record,example); } @Override public ParkingLotChannel queryChannelInfoByNo(QueryChannelInfoByNoRequest record) { if (record == null) { return null; } ParkingLotChannelExample example = new ParkingLotChannelExample(); ParkingLotChannelExample.Criteria sql = example.createCriteria(); // if(!StringUtils.isEmpty(record.getPlNo())){ sql.andPlNoEqualTo(record.getPlNo()); } if(!StringUtils.isEmpty(record.getChannelNumber())){ sql.andChannelNumberEqualTo(record.getChannelNumber()); } sql.andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List list = parkingLotChannelMapper.selectByExample(example); ParkingLotChannel parkingLotChannel = list.get(0); return parkingLotChannel; } @Override public List tideChannelChoice(ParkingLotChannel record) { ParkingLotChannelExample example = new ParkingLotChannelExample(); ParkingLotChannelExample.Criteria sql = example.createCriteria(); // if(!StringUtils.isEmpty(record.getPlNo())){ sql.andPlNoEqualTo(record.getPlNo()); } if(!StringUtils.isEmpty(record.getAreaId())){ sql.andAreaIdEqualTo(record.getAreaId()); } if(!StringUtils.isEmpty(record.getChannelDirection())){ sql.andChannelDirectionEqualTo(record.getChannelDirection()); } sql.andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List list = parkingLotChannelMapper.selectByExample(example); List dtoList = new ArrayList<>(); ListCopyUtil.listCopyProperties(list,dtoList,ChannelInfoDTO.class); return dtoList; } @Override public List queryChannelNameByChannelNums(QueryChannelNameByChannelNumsRequest request) { ParkingLotChannelExample example = new ParkingLotChannelExample(); ParkingLotChannelExample.Criteria sql = example.createCriteria(); sql.andChannelNumberIn(request.getChannelNums()).andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List list = parkingLotChannelMapper.selectByExample(example); List dtoList = new ArrayList<>(); ListCopyUtil.listCopyProperties(list,dtoList,ChannelInfoDTO.class); return dtoList; } @Override public int checkChannelNum(CheckChannelNumRequest request) { ParkingLotChannelExample example = new ParkingLotChannelExample(); ParkingLotChannelExample.Criteria sql = example.createCriteria(); if(!StringUtils.isEmpty(request.getId())){ sql.andIdNotEqualTo(request.getId()); } sql.andPlNoEqualTo(request.getPlNo()) .andChannelNumberEqualTo(request.getChannelNumber()).andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List list = parkingLotChannelMapper.selectByExample(example); int flag = 0; if(list != null){ flag = list.size(); } return flag; } /** * 根据ID 获取通道信息 */ @Override public ParkingLotChannel queryParkingLotChannelById(Long id) { ParkingLotChannelExample example = new ParkingLotChannelExample(); ParkingLotChannelExample.Criteria sql = example.createCriteria(); sql.andIdEqualTo(id); List list =parkingLotChannelMapper.selectByExample(example); if(list != null && list.size() > 0){ return list.get(0); }else{ return null; } } }