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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxProduceSnMcRecordService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesManageCode;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProduceSnMcRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesManageCodeRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesProduceSnMcRecordRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
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.List;

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

    @Autowired
    private MesManageCodeRepository manageCodeRepository;

    @Autowired
    private MesProduceSnMcRecordRepository produceSnMcRecordRepository;

    @Override
    public MesManageCode getManageCodeDb(String organizeCode, String manageCode, String workCenterCode) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(manageCode) || StringUtils.isEmpty(workCenterCode)) return null;
        return manageCodeRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.MANAGE_CODE, MesPcnExtConstWords.WORK_CENTER_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), manageCode, workCenterCode});
    }

    @Override
    public List<MesProduceSnMcRecord> getProduceSnMcRecordDbList(String organizeCode, String workOrderNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workOrderNo)) return null;
        return produceSnMcRecordRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_ORDER_NO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workOrderNo});
    }

    @Override
    public MesProduceSnMcRecord getProduceSnMcRecordDb(String organizeCode, String manageCode) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(manageCode)) return null;
        return produceSnMcRecordRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.MANAGE_CODE, MesPcnExtConstWords.SN_STATUS},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), manageCode, MesPcnExtEnumUtil.MC_RECORD_SN_STATUS.LINE_ON.getValue()});
    }

}