package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi.bu3;

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxShiftProdCenterRecordService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesShiftProdCenterRecord;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesShiftProdCenterRecordRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SxShiftProdCenterRecordService implements ISxShiftProdCenterRecordService {

    @Autowired
    private MesShiftProdCenterRecordRepository shiftProdCenterRecordRepository;

    @Override
    public List<MesShiftProdCenterRecord> queryAllShiftProdCenterRecordListByModifyDatetime(MesShiftProdCenterRecord shiftProdCenterRecord) {
        DdlPackBean packBean = new DdlPackBean();
        DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue(), MesExtConstWords.IS_VALID, packBean);
        DdlPreparedPack.getStringEqualPack(shiftProdCenterRecord.getOrganizeCode(), MesExtConstWords.ORGANIZE_CODE, packBean);
        DdlPreparedPack.timeBuilder(shiftProdCenterRecord.getModifyDateTimeStart(), shiftProdCenterRecord.getModifyDateTimeEnd(), MesExtConstWords.MODIFY_DATE_TIME, packBean, true);
        return shiftProdCenterRecordRepository.findByHqlWhere(packBean);
    }

    @Override
    public List<MesShiftProdCenterRecord> queryShiftProdCenterRecordListByCreateDatetime(MesShiftProdCenterRecord shiftProdCenterRecord) {
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(shiftProdCenterRecord.getOrganizeCode());
        DdlPreparedPack.timeBuilder(shiftProdCenterRecord.getCreateDateTimeStart(), shiftProdCenterRecord.getCreateDateTimeEnd(), MesExtConstWords.CREATE_DATE_TIME, packBean, true);
        return shiftProdCenterRecordRepository.findByHqlWhere(packBean);
    }

    @Override
    public List<MesShiftProdCenterRecord> queryShiftProdCenterRecordListByAndonOrderNo(List<String> andonOrderNoList, String organizeCode) {
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getInPackList(andonOrderNoList, MesExtConstWords.ANDON_ORDER_NO, packBean);
        return shiftProdCenterRecordRepository.findByHqlWhere(packBean);
    }

}
