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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesStationService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesStation;
import cn.estsh.i3plus.pojo.mes.repository.MesStationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description : 站点信息
 * @Reference :
 * @Author : junsheng.li
 * @CreateDate 2024/9/12 13:56
 * @Modify:
 **/
@Service
public class MesStationServiceImpl implements IMesStationService {

    @Autowired
    private MesStationRepository mesStationRepository;


    @Override
    public MesStation getMesStationByEquipmentCode(String organizeCode, String equipmentCode) {
        if (StringUtil.isEmptyAndNull(organizeCode) || StringUtil.isEmptyAndNull(organizeCode)) {
            return null;
        }
        return mesStationRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.EQUIPMENT_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), equipmentCode});
    }

    @Override
    public MesStation checkMesStationByEquipmentCode(String organizeCode, String equipmentCode) {
        MesStation mesStation = this.getMesStationByEquipmentCode(organizeCode, equipmentCode);
        if (Objects.isNull(mesStation)) {
            MesPcnException.throwMesBusiException("设备【%s】站点信息未维护", equipmentCode);
        }
        return mesStation;
    }
}
