package org.jeecg.modules.stm.act.main.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.stm.act.main.entity.StCaMainLable;
import org.jeecg.modules.stm.act.main.mapper.StCaMainLableMapper;
import org.jeecg.modules.stm.act.main.service.IStCaMainLableService;
import org.jeecg.modules.stm.act.main.vo.StCaMainLableVo;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: yzh
 * @Date 2023/3/19 18:12
 * @Description:
 */
@Service
public class StCaMainLableServiceImpl extends ServiceImpl<StCaMainLableMapper, StCaMainLable>implements IStCaMainLableService {


    @Override
    public List<String> listByLabelCodes(List<String> labelCodes) {
        if(CollectionUtils.isEmpty(labelCodes)){
            return null;
        }
        QueryWrapper<StCaMainLable> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("LABLE_CODE",labelCodes);
        queryWrapper.select("CA_NO");
        List<StCaMainLable> stCaMainLables = this.baseMapper.selectList(queryWrapper);
        if(!CollectionUtils.isEmpty(stCaMainLables)){
            return stCaMainLables.stream().map(StCaMainLable::getCaNo).collect(Collectors.toList());
        }
        return Arrays.asList("notExist");
    }


    @Override
    public Map<String, StCaMainLableVo> queryLables(StCaMainLableVo lableVo) {
        List<StCaMainLableVo> list = this.baseMapper.queryLables(lableVo);
        Map<String,StCaMainLableVo> retMap = new HashMap<>();
        for(StCaMainLableVo vo:list) {
            retMap.put(vo.getBizNo(),vo);
        }
        return retMap;
    }

}
