All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.founder.service.impl.CatalogMappingServiceImpl Maven / Gradle / Ivy

There is a newer version: 3.6.1.9
Show newest version
package com.founder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.founder.core.domain.GsCatalogMapping;
import com.founder.core.mapper.GsCatalogMappingMapper;
import com.founder.sdk.annotation.ReadTxt;
import com.founder.service.CatalogMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class CatalogMappingServiceImpl implements CatalogMappingService {

    @Autowired
    GsCatalogMappingMapper gsCatalogMappingMapper;

    /**
     * 获取字典匹配配置
     *
     * @param clazz
     * @return
     */
    @Override
    public  HashMap> getCatalogMapping(Class clazz) {
        HashMap> map = new HashMap<>();
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_class",clazz.getName());
        //queryWrapper.eq("table_class","20211101");//暂时写死
        List mappingList = gsCatalogMappingMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(mappingList)){
            mappingList = new ArrayList<>();
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                ReadTxt readTxt = field.getAnnotation(ReadTxt.class);
                if (readTxt != null) {
                    GsCatalogMapping mapping = new GsCatalogMapping();
                    String name = field.getName();
                    mapping.setField_no(readTxt.order());
                    mapping.setField_txt_index(mapping.getField_no());//默认取字段序号
                    mapping.setField_name(name);
                    mapping.setField_type(field.getType().getName());
                    mapping.setField_desc(readTxt.name());
                    mapping.setField_method("set" + name.substring(0, 1).toUpperCase() + name.substring(1));
                    mapping.setTable_class(clazz.getName());
                    gsCatalogMappingMapper.insert(mapping);
                    mappingList.add(mapping);
                }
            }
        }
        mappingList.stream().forEach(x->{
            Integer order = x.getField_no();
            ArrayList info = new ArrayList();
            info.add(0,x.getField_txt_index());
            info.add(1,x.getField_method());
            info.add(2,x.getField_type());
            info.add(3,x.getField_desc());//字段说明
            map.put(order, info);
        });
        return map;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy