package	com.sw.mes.yb.production.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.sw.mes.core.entity.SearchFilter;
import com.sw.mes.core.utils.DynamicSpecifications;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sw.mes.yb.production.entity.ProcessPath;
import com.sw.mes.yb.production.dao.ProcessPathDao;
import com.sw.mes.yb.production.service.ProcessPathService;


/**
* @Author
* @Description：
* @Date: Create in
* @Modified By:
*/
@Service
@Transactional
public class ProcessPathServiceImpl extends BaseServiceImpl<ProcessPath> implements ProcessPathService {
    ProcessPathDao dao;
	@Autowired
    public void setDao(ProcessPathDao dao) {
        super.setBaseDao(dao);
        this.dao=dao;
    }

	@Override
	public List<ProcessPath> findByEquipmentCodeAndLotNoAndStepNameIn(String equipmentCode, String lotNo,
			List<String> steNames) {
		return dao.findByEquipmentCodeAndLotNoAndStepNameIn(equipmentCode,lotNo,steNames);
	}

	@Override
	public List<ProcessPath> findData(String equipmentCode, String lotNo, String stepName, String startTime, String endTime, Sort sort) {
		Set<SearchFilter> searchSet = new HashSet<>(8);
		if (!StringUtils.isBlank(equipmentCode)) {
			searchSet.add(new SearchFilter("equipmentCode", SearchFilter.Operator.EQ, equipmentCode));
		}

		if (!StringUtils.isBlank(lotNo)) {
			searchSet.add(new SearchFilter("lotNo", SearchFilter.Operator.EQ, lotNo));
		}
		if (!StringUtils.isBlank(stepName)) {
			searchSet.add(new SearchFilter("stepName", SearchFilter.Operator.EQ, stepName));
		}
		if (!StringUtils.isBlank(startTime)) {
			searchSet.add(new SearchFilter("deviceStartTime", SearchFilter.Operator.GT, startTime));
		}
		if (!StringUtils.isBlank(endTime)) {
			searchSet.add(new SearchFilter("deviceStartTime", SearchFilter.Operator.LT, endTime));
		}
		Specification<ProcessPath> specification = DynamicSpecifications.bySearchFilter(ProcessPath.class, searchSet);
		List<ProcessPath> processPathList = findByExampleSort(specification, sort);
		return processPathList;
	}

	@Override
	public ProcessPath findTopByEquipmentCodeOrderByIdDesc(String equipmentCode) {
		return dao.findTopByEquipmentCodeOrderByIdDesc(equipmentCode);
	}
}
