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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IWorkCenterContainerLocationService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesWorkCenterContainerLocation;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesWorkCenterContainerLocationRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesContainer;
import cn.estsh.i3plus.pojo.mes.bean.MesPartContainerCapacity;
import cn.estsh.i3plus.pojo.mes.repository.MesContainerRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesPartContainerCapacityRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/1/13 9:28
 **/
@Slf4j
@Service
public class WorkCenterContainerLocationService implements IWorkCenterContainerLocationService {

    @Autowired
    private MesWorkCenterContainerLocationRepository workCenterContainerLocationRepository;

    @Autowired
    private MesContainerRepository containerRepository;

    @Autowired
    private MesPartContainerCapacityRepository partContainerCapacityRepository;

    @Override
    public List<MesWorkCenterContainerLocation> getWcclListByCenter(String organizeCode, String workCenterCode) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workCenterCode)) {
            return null;
        }
        return workCenterContainerLocationRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_CENTER_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workCenterCode});
    }

    @Override
    public MesWorkCenterContainerLocation getWcclByCenter(String organizeCode, String workCenterCode) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workCenterCode)) {
            return null;
        }
        return workCenterContainerLocationRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_CENTER_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workCenterCode});
    }

    @Override
    public MesWorkCenterContainerLocation getWorkCenterContainerLocationByCenterAndLocation(String organizeCode, String workCenterCode, String ctLocationNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workCenterCode) || StringUtils.isEmpty(ctLocationNo)) {
            return null;
        }
        return workCenterContainerLocationRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_CENTER_CODE, MesPcnExtConstWords.CT_LOCATION_NO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workCenterCode, ctLocationNo});
    }

    @Override
    public MesContainer getContainerByCtNo(String organizeCode, String ctNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(ctNo)) {
            return null;
        }
        return containerRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.CT_NO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), ctNo});
    }

    @Override
    public MesPartContainerCapacity getPartContainerCapacity(String organizeCode, String ctCode, String partNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(ctCode) || StringUtils.isEmpty(partNo)) {
            return null;
        }
        return partContainerCapacityRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.CT_CODE, MesPcnExtConstWords.PART_NO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), ctCode, partNo});
    }
}
