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

import cn.estsh.i3plus.ext.mes.pcn.api.base.jx.IMesManageCodeService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesManageCode;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesManageCodeRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-10-13 13:46
 */
@Service
public class MesManageCodeService implements IMesManageCodeService {
    
    @Autowired
    private MesManageCodeRepository manageCodeRepository;
    
    @Override
    public MesManageCode getManageCode(String organizeCode, String manageCode) {
        return manageCodeRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.MANAGE_CODE},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue(), manageCode});
    }

    @Override
    public List<MesManageCode> getManageCodeListByManageCodeList(String organizeCode, List<String> manageCodeList) {
        if (CollectionUtils.isEmpty(manageCodeList)) return null;
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getInPackList(manageCodeList, MesPcnExtConstWords.MANAGE_CODE, ddlPackBean);
        return manageCodeRepository.findByHqlWhere(ddlPackBean);
    }
}
