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



import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.yb.production.dao.ProcessWorkingHoursDao;
import com.sw.mes.yb.production.entity.ProcessWorkingHours;
import com.sw.mes.yb.production.service.ProcessWorkingHoursService;


/**
* @Author
* @Description：
* @Date: Create in
* @Modified By:
*/
@Service
@Transactional
public class ProcessWorkingHoursServiceImpl extends BaseServiceImpl<ProcessWorkingHours> implements ProcessWorkingHoursService {
    ProcessWorkingHoursDao dao;
	@Autowired
    public void setDao(ProcessWorkingHoursDao dao) {
        super.setBaseDao(dao);
        this.dao=dao;
    }
	@Override
	public ProcessWorkingHours getByEquipmentCodeAndLotNo(String deviceCode, String lotNo) {
		List<ProcessWorkingHours> list = dao.findByEquipmentCodeAndLotNo(deviceCode,lotNo);
		if(list.size()>0) {
			return list.get(0);
		}
		return null;
	}
	@Override
	public ProcessWorkingHours getByEquipmentCodeAndLotNoIsNull(String deviceCode) {
		List<ProcessWorkingHours> list = dao.findByEquipmentCodeAndLotNoIsNull(deviceCode);
		if(list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public ProcessWorkingHours getByEquipmentCodeLast(String equipmentCode) {
		return dao.getByEquipmentCodeLast(equipmentCode);
	}

	@Override
	public List<ProcessWorkingHours> getBySeriesAndStepNameAndStartTime(String series, String workHourName, String startTime, String endTime) {
		return dao.getBySeriesAndStepNameAndStartTime(series, workHourName, startTime, endTime);
	}

	@Override
	public List<ProcessWorkingHours> getByStartTime(String startTime, String endTime) {
		return dao.getByStartTime(startTime, endTime);
	}

	@Override
	public ProcessWorkingHours findByLotNoAndStep(String lotNo, String step) {
		return dao.findTopByLotNoAndStepNameOrderByIdDesc(lotNo, step);
	}

	@Override
	public List<ProcessWorkingHours> findByStepName(String stepName) {
		return dao.findByStepName(stepName);
	}

	@Override
	public ProcessWorkingHours findTopByEquipmentCodeAndLotNoAndStartTimeAndEndTimeOrderByIdDesc(String deviceCode, String lotNo, Date startTime, Date endTime) {
		return dao.findTopByEquipmentCodeAndLotNoAndStartTimeAndEndTimeOrderByIdDesc(deviceCode, lotNo, startTime, endTime);
	}
}
