BusinessServiceImpl.java 2.6 KB
package com.skua.modules.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skua.modules.base.service.IBaseService;
import com.skua.modules.biz.IBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:sonin
 * @Date:2025/2/18 15:35
 */
@Service
public class BusinessServiceImpl implements IBusinessService {

    @Autowired
    private IBaseService baseService;

    /**
     * table0 => (key0, value0)
     */
    private static final Map<String, String[]> DICT_MAP = new HashMap<String, String[]>() {{
        put("equipment_info", new String[]{"id", "equipment_name"});
        put("sys_user", new String[]{"id", "realname"});
        put("sys_struct_dict", new String[]{"id", "struct_name"});
        put("equipment_category", new String[]{"id", "des"});
        put("evaluate_score_desc", new String[]{"id", "score_desc"});
        put("carbon_qualitative_desc", new String[]{"id", "qualitative_desc"});
        put("sys_depart", new String[]{"id", "depart_name"});
        put("equipment_sparepart_type", new String[]{"id", "item_text"});
        put("supplies_warehouse", new String[]{"id", "warehouse_name"});
        put("inspection_working_group", new String[]{"id", "group_name"});
    }};

    @Override
    public Map<String, String> dictMap(String dictCode, Collection<?> inCol) {
        String key0, value0, table0;
        QueryWrapper<?> queryWrapper0 = new QueryWrapper<>();
        if (DICT_MAP.containsKey(dictCode)) {
            String[] dictArray = DICT_MAP.get(dictCode);
            key0 = dictArray[0];
            value0 = dictArray[1];
            table0 = dictCode;
        } else {
            // 数据字典查询
            queryWrapper0.eq("sys_dict.dict_code", dictCode);
            key0 = "sys_dict_item.item_value";
            value0 = "sys_dict_item.item_text";
            table0 = "sys_dict inner join sys_dict_item on sys_dict.id = sys_dict_item.dict_id";
        }
        String sqlSelect = "select " + key0 + " as key0, " + value0 + " as value0 from " + table0;
        if (inCol != null && !inCol.isEmpty()) {
            queryWrapper0.in(key0, inCol);
        }
        List<Map<String, Object>> queryMapList0 = baseService.queryForList(sqlSelect, queryWrapper0);
        Map<String, String> dictMap = new HashMap<>(10);
        for (Map<String, Object> item : queryMapList0) {
            dictMap.put(String.valueOf(item.get("key0")), String.valueOf(item.get("value0")));
        }
        return dictMap;
    }

}