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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxOutPutStatisticsTimeSegmentService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOutPutStatisticsTimeSegment;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesOutPutStatisticsTimeSegmentRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

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

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/18 11:41 上午
 * @Description:
 **/
@Slf4j
@Service
public class JxOutPutStatisticsTimeSegmentService implements IJxOutPutStatisticsTimeSegmentService {

    @Autowired
    private MesOutPutStatisticsTimeSegmentRepository outPutStatisticsTimeSegmentRepository;

    @Override
    public List<MesOutPutStatisticsTimeSegment> getOutPutStatisticsTimeSegmentByOrderAndTsCode(String organizeCode, String workOrderNo, String workTime, String shiftCode, String timeSegmentCode) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workOrderNo) || StringUtils.isEmpty(workTime) || StringUtils.isEmpty(shiftCode) || StringUtils.isEmpty(timeSegmentCode)) return null;
        MesOutPutStatisticsTimeSegment outPutStatisticsTimeSegment = outPutStatisticsTimeSegmentRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_ORDER_NO, MesPcnExtConstWords.WORK_TIME, MesPcnExtConstWords.TIME_SEGMENT_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workOrderNo, workTime, timeSegmentCode});
        List<MesOutPutStatisticsTimeSegment> outPutStatisticsTimeSegmentList;
        if (null == outPutStatisticsTimeSegment)
            outPutStatisticsTimeSegmentList = outPutStatisticsTimeSegmentRepository.findByProperty(
                    new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_ORDER_NO, MesPcnExtConstWords.WORK_TIME, MesPcnExtConstWords.SHIFT_CODE},
                    new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workOrderNo, workTime, shiftCode});
        else {
            outPutStatisticsTimeSegmentList = new ArrayList<>();
            outPutStatisticsTimeSegmentList.add(outPutStatisticsTimeSegment);
        }
        return outPutStatisticsTimeSegmentList;
    }

}