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

import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxPackageExtService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesPackageExt;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesPackageExtRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesPackageDetail;
import cn.estsh.i3plus.pojo.mes.repository.MesPackageDetailRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-13 11:09
 */
@Service
public class JxPackageExtService implements IJxPackageExtService {
    
    @Autowired
    private MesPackageDetailRepository packageDetailRepository;
    
    @Autowired
    private MesPackageExtRepository packageExtRepository;

    @Override
    public MesPackageDetail getPackageDetailByProductSn(String organizeCode, String productSn) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(productSn)) {
            return null;
        }
        return packageDetailRepository.getByProperty(
                new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.PRODUCT_SN},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), productSn});
    }

    @Override
    public MesPackageExt getPackageByPackNo(String organizeCode, String packageNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(packageNo)) {
            return null;
        }
        return packageExtRepository.getByProperty(
                new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.PACKAGENO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), packageNo});
    }
    
}
