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

import cn.estsh.i3plus.ext.mes.pcn.api.base.jx.IRepairJudgeService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesRepairJudgeType;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesRepairJudgeTypeRepository;
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 java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-13 14:48
 */
@Service
public class RepairJudgeService implements IRepairJudgeService {
    
    @Autowired
    private MesRepairJudgeTypeRepository repairJudgeTypeRepository;
    
    @Override
    public List<MesRepairJudgeType> queryRepairJudgeList(String organizeCode) {

        return repairJudgeTypeRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue()},
                "order by seq asc");

    }

    @Override
    public Map<String, String> queryRepairJudgeMap(String organizeCode) {
        List<MesRepairJudgeType> mesRepairJudgeTypes = queryRepairJudgeList(organizeCode);
        return CollectionUtils.isEmpty(mesRepairJudgeTypes) ? null :
                mesRepairJudgeTypes.stream().collect(Collectors.toMap(
                        MesRepairJudgeType::getRepairJudgeCode, MesRepairJudgeType::getRepairJudgeName, (x,y) -> y));
    }

}