TpPPdaDaoImpl.java 7.24 KB
package com.zteits.park.dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.zteits.clouds.api.dto.pda.param.QueryEqpByPlNoAndOrtherRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.park.dto.StatisticEqpCountByEqpTypeDTO;
import com.zteits.clouds.api.dto.park.dto.StatisticEqpCountByPlNoDTO;
import com.zteits.clouds.api.dto.park.param.TpPPdaDeleteRequest;
import com.zteits.clouds.api.dto.park.param.TpPPdaPageQueryRequest;
import com.zteits.clouds.api.dto.park.param.TpPPdaRequest;
import com.zteits.clouds.api.dto.park.param.TpPPdaSRequest;
import com.zteits.park.dao.TpPPdaDao;
import com.zteits.park.domain.TpPPda;
import com.zteits.park.domain.TpPPdaExample;
import com.zteits.park.domain.TpPPdaExample.Criteria;
import com.zteits.park.mapper.TpPPdaMapper;
import com.zteits.park.mapper.smapper.TpPPdaSMapper;

@Component
public class TpPPdaDaoImpl implements TpPPdaDao {

    @Autowired
    private TpPPdaSMapper tpPPdaSMapper;

    @Autowired
    private TpPPdaMapper tpPPdaMapper;

    @Override
    public Integer insertPad(TpPPda tpPPda) {
        tpPPda.setCreateTime(new Date());
        tpPPda.setDataState(DataStatusEnum.DATA_STATUS_VALID.value());
        return tpPPdaMapper.insertSelective(tpPPda);
    }

    @Override
    public Integer deletetPda(TpPPdaDeleteRequest tpPPda) {
        //删除pda表
        TpPPdaExample example = new TpPPdaExample();
        TpPPda record = new TpPPda();
        record.setModifyTime(new Date());
        record.setModifyOp(tpPPda.getModifyOp());
        record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
        example.createCriteria().andIdIn(tpPPda.getIds());
        return tpPPdaMapper.updateByExampleSelective(record, example);
    }

    @Override
    public PageInfo<TpPPda> queryPdaInfo4pabe(TpPPdaPageQueryRequest request) {
        PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
        List<TpPPda> list = tpPPdaSMapper.queryPdaInfo(request);
        if (CollectionUtils.isNotEmpty(list)) {
            return new PageInfo<TpPPda>(list);
        }
        return new PageInfo<TpPPda>(new ArrayList<TpPPda>());
    }

    @Override
    public Integer deleteBatchPda(List<Long> list) {
        TpPPdaExample example = new TpPPdaExample();
        example.createCriteria().andIdIn(list);

		TpPPda record = new TpPPda();
		record.setModifyTime(new Date());
		record.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
		return tpPPdaMapper.updateByExampleSelective(record, example);
    }

    @Override
    public TpPPda queryPdaByid(Long id) {
        return tpPPdaMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updatePda(TpPPda record) {
        return tpPPdaMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Integer insertBatchPda(TpPPdaSRequest request) {
        List<TpPPdaRequest> requestList = request.getPadList();
        Integer i = 0;
        if (CollectionUtil.isNotEmpty(requestList)) {
            i = tpPPdaSMapper.insertBatchPda(requestList);
        }
        return i;
    }

    @Override
    public TpPPda queryPdaByPdaNo(TpPPda tpPPda) {
    	if(StringUtils.isBlank(tpPPda.getPdaNo()) && tpPPda.getId()==null){
    		throw new BizException(ErrorType.PARAM_NOT_VALID);
		}
    	TpPPdaExample example = new TpPPdaExample();
		Criteria sql = example.createCriteria();
		sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		if(!StringUtils.isBlank(tpPPda.getPdaNo())){
			sql.andPdaNoEqualTo(tpPPda.getPdaNo());
		}
		if(tpPPda.getId()!=null){
			sql.andIdEqualTo(tpPPda.getId());
		}
        List<TpPPda> pPdas = tpPPdaMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(pPdas)){
        	return null;
        }
        return pPdas.get(0);
    }

	@Override
	public List<TpPPda> queryPdaByPlNo(TpPPda tpPPda) {
		TpPPdaExample example = new TpPPdaExample();
		Criteria sql = example.createCriteria();
		sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
		.andPlNoEqualTo(tpPPda.getPlNo());
		if(!StringUtils.isBlank(tpPPda.getPdaType())){
			sql.andPdaTypeEqualTo(tpPPda.getPdaType());
		}
		if(tpPPda.getId()!=null){
			sql.andIdEqualTo(tpPPda.getId());
		}
		return tpPPdaMapper.selectByExample(example );
	}
	@Override
	public List<TpPPda> queryPdaByPlNoAndPdaType(TpPPdaRequest request) {
		TpPPdaExample example = new TpPPdaExample();
		Criteria sql = example.createCriteria();
		sql.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
		.andPlNoEqualTo(request.getPlNo());
		if(CollectionUtils.isNotEmpty(request.getPdaTypes())){
			sql.andPdaTypeIn(request.getPdaTypes());
		}
		if(!StringUtils.isBlank(request.getPdaType())){
			sql.andPdaTypeEqualTo(request.getPdaType());
		}
		return tpPPdaMapper.selectByExample(example );
	}

	@Override
	public List<TpPPda> queryPdaInfoByPlNoAndOther(QueryEqpByPlNoAndOrtherRequest request) {
		return tpPPdaSMapper.queryPdaInfoByPlNoAndOther(request);
	}

	@Override
	public int updateByExampleSelective(TpPPda record, TpPPdaExample example) {
		return tpPPdaMapper.updateByExampleSelective(record, example);
	}

	@Override
	public List<TpPPda> selectByExample(TpPPdaExample example) {
		return tpPPdaMapper.selectByExample(example);
	}

	@Override
	public TpPPda queryPdaByPdaNo(String pdaNo) {
		TpPPdaExample example = new TpPPdaExample();
		example.createCriteria().andPdaNoEqualTo(pdaNo)
		.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		List<TpPPda> tpPPdas = tpPPdaMapper.selectByExample(example );
		if(CollectionUtils.isEmpty(tpPPdas)){
			return null;
		}
		return tpPPdas.get(0);
	}

	@Override
	public int updatePDAByPdaNo(TpPPda record, String pdaNo) {
		TpPPdaExample example = new TpPPdaExample();
		example.createCriteria().andPdaNoEqualTo(pdaNo)
		.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
		return tpPPdaMapper.updateByExampleSelective(record, example );
	}
	@Override
	public Map<Integer, StatisticEqpCountByEqpTypeDTO> statisticEqpCountGroupByEqpType(TpPPdaPageQueryRequest request) {
		List<StatisticEqpCountByEqpTypeDTO> byEqpTypeDTOs = tpPPdaSMapper.statisticEqpCountGroupByEqpType(request);
		if(CollectionUtil.isEmpty(byEqpTypeDTOs)){
			return null;
		}
		return byEqpTypeDTOs.stream().collect(Collectors.toMap(StatisticEqpCountByEqpTypeDTO::getEqpType, Function.identity()));
	}

	@Override
	public Map<String, List<StatisticEqpCountByPlNoDTO>> statisticEqpCountGroupByPlNo(TpPPdaPageQueryRequest request) {
		List<StatisticEqpCountByPlNoDTO> byplNoDTOs = tpPPdaSMapper.statisticEqpCountGroupByPlNo(request);
		if(CollectionUtil.isEmpty(byplNoDTOs)){
			return null;
		}
		return byplNoDTOs.stream().collect(Collectors.groupingBy(StatisticEqpCountByPlNoDTO::getPlNo));
	}
}