package cn.cslg.report.service.business;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.utils.LogExceptionUtil;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.Report;
import cn.cslg.report.entity.SysDictItem;
import cn.cslg.report.mapper.ReportMapper;
import cn.cslg.report.mapper.SystemDictItemMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class SystemDictItemService extends ServiceImpl<SystemDictItemMapper, SysDictItem> {
    /**
     * @return 成功返回客户列表信息 失败返回错误信息
     * @title 获取部分客户
     * @author 沈永艺
     */
    private final SystemDictItemMapper systemDictItemMapper;
    public String getSystemKey() {
        try {

            Map<String, Object> lst = new HashMap<>();
            //查询所有字典
            List<SysDictItem> sysDictList = this.list();
            for (SysDictItem sysDict : sysDictList) {
                //用字典的KEY值去字典项表内查询对应字典项
                LambdaQueryWrapper<SysDictItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(SysDictItem::getDictParentKey, sysDict.getDictParentKey());
                //装填数据
                //字典格式 KEY:KEY值对应的字典项
                if(!lst.containsKey(sysDict.getDictParentKey())){
                lst.put(sysDict.getDictParentKey(), systemDictItemMapper.selectList(lambdaQueryWrapper));}
//                //数据字典格式 dataDict:查询的所有数据字典数据
//                lst.put("dataDict", dataSourceService.list());
            }
            return Response.success(lst);
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error("获得字典项失败,错误信息:" + LogExceptionUtil.getMessage(ex));
            return Response.error(Constants.NET_ERROR);
        }
    }
}
