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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ep.IEpRepairTaskService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.dao.ep.IEpRepairTaskDao;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesRepairTask;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.ep.EpQmsRepirTaskModel;
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 EpRepairTaskService implements IEpRepairTaskService {

    @Autowired
    private IEpRepairTaskDao repairTaskDao;

    @Override
    public List<EpQmsRepirTaskModel> queryEpQmsRepairTaskList(EpQmsRepirTaskModel model, List<String> partNoList) {
        List<EpQmsRepirTaskModel> 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<MesRepairTask> repairTaskList = repairTaskDao.queryEpQmsRepairTaskList(model);
            if (!CollectionUtils.isEmpty(repairTaskList)) {
                for (MesRepairTask repairTask : repairTaskList) {
                    if (null == repairTask) {
                        continue;
                    }
                    EpQmsRepirTaskModel result = new EpQmsRepirTaskModel();
                    BeanUtils.copyProperties(repairTask, result);
                    if (CollectionUtils.isEmpty(resultList)) {
                        resultList = new ArrayList<>();
                    }
                    resultList.add(result);
                }
            }
        }
        return resultList;
    }

}
