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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesShippingSnUniqueService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesShippingSnUnique;
import cn.estsh.i3plus.pojo.mes.repository.MesShippingSnUniqueRepository;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description : 发运条码唯一性
 * @Reference :
 * @Author : junsheng.li
 * @CreateDate 2024/10/28 15:15
 * @Modify:
 **/
@Service
@Slf4j
public class MesShippingSnUniqueServiceImpl implements IMesShippingSnUniqueService {

    @Autowired
    private MesShippingSnUniqueRepository mesShippingSnUniqueRepository;

    @Override
    public MesShippingSnUnique getMesShippingSnUnique(String organizeCode, String productSn) {
        if(StringUtil.isEmpty(organizeCode) || StringUtil.isEmpty(productSn)) return null;
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getStringEqualPack(productSn, "productSn", packBean);
        return mesShippingSnUniqueRepository.getByProperty(packBean);
    }

    @Override
    public Boolean checkMesShippingSnUnique(String organizeCode, String productSn) {
        if(StringUtil.isEmpty(organizeCode) || StringUtil.isEmpty(productSn)) return false;
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getStringEqualPack(productSn, "productSn", packBean);
        return mesShippingSnUniqueRepository.isExitByHql(packBean);
    }

    @Override
    public void insertMesShippingSnUnique(String organizeCode, String productSn, String shippingCode,String userName) {
        MesShippingSnUnique mesShippingSnUnique = new MesShippingSnUnique();
        mesShippingSnUnique.setOrganizeCode(organizeCode);
        mesShippingSnUnique.setProductSn(productSn);
        mesShippingSnUnique.setShippingCode(shippingCode);
        ConvertBean.serviceModelInitialize(mesShippingSnUnique,userName);
        mesShippingSnUniqueRepository.insert(mesShippingSnUnique);
    }

    @Override
    public MesShippingSnUnique getMesShippingSnUnique(String organizeCode, String productSn, String shippingCode,String userName) {
        MesShippingSnUnique mesShippingSnUnique = new MesShippingSnUnique();
        mesShippingSnUnique.setOrganizeCode(organizeCode);
        mesShippingSnUnique.setProductSn(productSn);
        mesShippingSnUnique.setShippingCode(shippingCode);
        ConvertBean.serviceModelInitialize(mesShippingSnUnique,userName);
        return mesShippingSnUnique;
    }
}
