package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.ep;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ep.IEpOutPutStatisticsService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.dao.ep.IEpOutPutStatisticsDao;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOutPutStatistics;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.ep.EpQmsOutPutStatisticsModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/1/13 9:28
 **/
@Slf4j
@Service
public class EpOutPutStatisticsService implements IEpOutPutStatisticsService {

    @Autowired
    private IEpOutPutStatisticsDao outPutStatisticsDao;

    @Override
    public List<EpQmsOutPutStatisticsModel> queryEpQmsOutPutStatisticsList(EpQmsOutPutStatisticsModel model, List<String> partNoList) {
        List<EpQmsOutPutStatisticsModel> resultList = null;

        int size = CollectionUtils.isEmpty(partNoList) ? 0 : partNoList.size() - 1;
        for (int i = 0; i <= size; i ++) {
            if (!CollectionUtils.isEmpty(partNoList)) {
                model.setPartNo(partNoList.get(i));
            }
            List<MesOutPutStatistics> outPutStatisticsList = outPutStatisticsDao.queryEpQmsOutPutStatisticsList(model);
            if (!CollectionUtils.isEmpty(outPutStatisticsList)) {
                for (MesOutPutStatistics outPutStatistics : outPutStatisticsList) {
                    if (null == outPutStatistics) {
                        continue;
                    }
                    EpQmsOutPutStatisticsModel result = new EpQmsOutPutStatisticsModel();
                    BeanUtils.copyProperties(outPutStatistics, result);
                    if (CollectionUtils.isEmpty(resultList)) {
                        resultList = new ArrayList<>();
                    }
                    resultList.add(result);
                }
            }
        }
        return resultList;
    }

}
