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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.bu.bu3.IMesOuterPackageService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOuterPackage;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOuterPackageDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesOuterPackageDetailRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesOuterPackageRepository;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-bu
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-01-12 16:09
 */
@Service
public class MesOuterPackageService implements IMesOuterPackageService {

    @Autowired
    private MesOuterPackageDetailRepository outerPackageDetailRepository;

    @Autowired
    private MesOuterPackageRepository outerPackageRepository;

    @Override
    public MesOuterPackageDetail getBindingOutPackageDetailByInnerSn(String organizeCode, String packageNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(packageNo)) {
            return null;
        }
        return outerPackageDetailRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.INNER_PACKAGE_NO, MesPcnExtConstWords.BIND_STATUS},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), packageNo, MesPcnExtEnumUtil.PACKAGE_BIND_STATUS.BINGDING.getValue()});
    }

    @Override
    public MesOuterPackageDetail getOutPackageDetailByInnerSn(String organizeCode, String packageNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(packageNo)) {
            return null;
        }
        return outerPackageDetailRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.INNER_PACKAGE_NO, MesPcnExtConstWords.BIND_STATUS},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), packageNo, MesPcnExtEnumUtil.PACKAGE_BIND_STATUS.UNBIND.getValue()});
    }

    @Override
    public MesOuterPackage getOutPackageBySn(String organizeCode, String packageNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(packageNo)) {
            return null;
        }
        return outerPackageRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.OUTER_PACKAGE_NO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), packageNo});
    }

    @Override
    public List<MesOuterPackageDetail> queryPackSnByOuterPackNo(String organizeCode, String bigPackageNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(bigPackageNo)) {
            return null;
        }
        return outerPackageDetailRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.PACKAGENO, MesPcnExtConstWords.BIND_STATUS},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), bigPackageNo, MesPcnExtEnumUtil.PACKAGE_BIND_STATUS.BINGDING.getValue()});
    }

    @Override
    public List<MesOuterPackage> queryOuterPackageByWorkOrderNo(String organizeCode, String workOrderNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workOrderNo)) {
            return null;
        }
        return outerPackageRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_ORDER_NO, MesPcnExtConstWords.BIND_STATUS},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workOrderNo, MesPcnExtEnumUtil.PACKAGE_BIND_STATUS.BINGDING.getValue()});
    }

    @Override
    public List<MesOuterPackageDetail> queryOuterPackageDetailByWorkOrderNo(String organizeCode, String workOrderNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workOrderNo)) {
            return null;
        }
        return outerPackageDetailRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_ORDER_NO, MesPcnExtConstWords.BIND_STATUS},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workOrderNo, MesPcnExtEnumUtil.PACKAGE_BIND_STATUS.BINGDING.getValue()});
    }


}
