package org.gyk.modules.sssj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.gyk.modules.sssj.service.IGetScpzService;
import org.gyk.modules.sz.scpz.entity.CxcScdtJldxx;
import org.gyk.modules.sz.scpz.entity.CxcScdtScpz;
import org.gyk.modules.sz.scpz.entity.CxcSssjSzScsz;
import org.gyk.modules.sz.scpz.mapper.ScszMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class GetScpzServiceImpl extends ServiceImpl<ScszMapper, CxcSssjSzScsz> implements IGetScpzService {

    @Override
//    @Cacheable(value = "sqlBj", key = "#root.methodName")
    public List<CxcSssjSzScsz> getAllScpz() {
        List<CxcSssjSzScsz> list = new ArrayList<>();
        try {
            list = baseMapper.getAllScpz();
        }
        catch (Exception e) {
            System.out.println(e);
        }
        return list;
    }

    @Override
    @Cacheable(value = "sqlBj", key = "#root.methodName+#lb")
    public List<CxcScdtScpz> getScpzByLb(String lb) {
        List<CxcScdtScpz> list = new ArrayList<>();
        try {
            list = baseMapper.getScpzByLb(lb);
        }
        catch (Exception e) {
            System.out.println(e);
        }
        return list;
    }

    @Override
    @Cacheable(value = "sqlBj", key = "#root.methodName")
    public Map<String, CxcScdtJldxx> getScdtJldId() {
        Map<String, CxcScdtJldxx> map = new HashMap<>();

        try {
            List<CxcScdtJldxx> list = baseMapper.getScdtJldId();

            map = list.stream().collect(Collectors.toMap(CxcScdtJldxx::getJldname, Function.identity(),(k1,k2)->k2));
        } catch (Exception e) {
            System.out.println(e);
        }
        return map;
    }


}
