package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.ep;

import cn.estsh.i3plus.ext.mes.api.base.ep.IEpPackageService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesPackageExt;
import cn.estsh.i3plus.ext.mes.pojo.model.ep.SxEpPackageModel;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesPackageExtRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2022-02-14 9:23
 */
@Service
public class EpPackageService implements IEpPackageService {
    @Autowired
    private MesPackageExtRepository packageRepository;

    public SxEpPackageModel getPackageByNo(String organizeCode, String packageNo) {
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getStringEqualPack(packageNo, MesExtConstWords.PACKAGENO, packBean);
        MesPackageExt mesPackage = packageRepository.getByProperty(packBean);
        SxEpPackageModel epPackageModel = new SxEpPackageModel();
        if(mesPackage == null){
            return null;
        }
        BeanUtils.copyProperties(mesPackage, epPackageModel);
        return epPackageModel;
    }

    public boolean checkPackageExistByNo(String organizeCode, String packageNo) {
        SxEpPackageModel mesPackage = getPackageByNo(organizeCode, packageNo);
        if(mesPackage != null){
            return true;
        }
        return false;
    }
}
