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

import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxCenterWorkingBoardService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesOutPutStatisticsTimeSegment;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesOutPutStatisticsTimeSegmentRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * @Author : wangjie
 * @CreateDate : 2022-02-15
 * @Modify:
 **/
@Slf4j
public class JxCenterWorkingBoardProxyTimeSegmentService implements IJxCenterWorkingBoardService {

    private MesOutPutStatisticsTimeSegmentRepository outPutStatisticsTimeSegmentRepository;

    public JxCenterWorkingBoardProxyTimeSegmentService() {
        this.outPutStatisticsTimeSegmentRepository = (MesOutPutStatisticsTimeSegmentRepository) SpringContextsUtil.getBean("mesOutPutStatisticsTimeSegmentRepository");
    }

    @Override
    public Map<String, Object> queryCenterWorkingBoardData(Map<String, Object> dataMap) {

        String orgainzeCode = (String) dataMap.get(MesExtConstWords.ORGANIZE_CODE);
        String workCenterCode = (String) dataMap.get(MesExtConstWords.WORK_CENTER_CODE);
        String workTime = (String) dataMap.get(MesExtConstWords.WORK_TIME);
        String shiftCode = (String) dataMap.get(MesExtConstWords.SHIFT_CODE);

        if (StringUtils.isEmpty(workTime) || StringUtils.isEmpty(shiftCode)) return dataMap;

        List<MesOutPutStatisticsTimeSegment> outPutStatisticsTimeSegmentList = outPutStatisticsTimeSegmentRepository.findByProperty(
                new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.WORK_CENTER_CODE, MesExtConstWords.WORK_TIME, MesExtConstWords.SHIFT_CODE, MesExtConstWords.WORK_ORDER_TYPE},
                new Object[]{orgainzeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workCenterCode, workTime, shiftCode, MesExtEnumUtil.WORK_ORDER_TYPE.STANDARD_ORDER.getValue()});

        if (CollectionUtils.isEmpty(outPutStatisticsTimeSegmentList)) return dataMap;

        dataMap.put(MesOutPutStatisticsTimeSegment.class.getSimpleName(), outPutStatisticsTimeSegmentList);

        return dataMap;

    }

}
