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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxProduceSnRepairService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProduceSnRepair;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesProduceSnRepairRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-06 13:24
 */
@Service
public class JxProduceSnRepairService implements IJxProduceSnRepairService {

    @Autowired
    private MesProduceSnRepairRepository produceSnRepairRepository;

    @Override
    public MesProduceSnRepair getProduceSnRepairByProductSn(String organizeCode, String serialNumber) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(serialNumber)) {
            return null;
        }
        List<MesProduceSnRepair> produceSnRepairList = produceSnRepairRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.SERIAL_NUMBER},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), serialNumber},
                " order by createDatetime desc ");
        return !CollectionUtils.isEmpty(produceSnRepairList) ? produceSnRepairList.get(0) : null;
    }

}
