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

io.github.wslxm.springbootplus2.manage.gc.generate.gcimpl.GcVO Maven / Gradle / Ivy

package io.github.wslxm.springbootplus2.manage.gc.generate.gcimpl;

import cn.hutool.core.util.IdUtil;
import io.github.wslxm.springbootplus2.manage.gc.config.GcConfig;
import io.github.wslxm.springbootplus2.manage.gc.constant.TpParamConstant;
import io.github.wslxm.springbootplus2.manage.gc.generate.GcSevice;
import io.github.wslxm.springbootplus2.manage.gc.generate.util.GenerateServerUtil;
import io.github.wslxm.springbootplus2.manage.gc.generate.util.GenerateUtil;
import io.github.wslxm.springbootplus2.manage.gc.model.po.DbFieldPO;
import io.github.wslxm.springbootplus2.manage.gc.utils.GcFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@SuppressWarnings("all")
@Component
@Slf4j
public class GcVO extends BaseGcImpl implements GcSevice {

    /**
     * 模板key
     */
    public static final String KEY_NAME = "X-VO";


    @Override
    public void run(GcConfig gcConfig){
          log.info("开始生成: {}", KEY_NAME);
        List dbFields = gcConfig.getDbFields();
        //数据拼接(所有字段)
        this.generateParameters(gcConfig,dbFields);
        // 开始生成文件并进行数据替换
        GcFileUtil.replacBrBwWritee(gcConfig, GcFileUtil.getBrBwPath(gcConfig, KEY_NAME));

    }


    private void generateParameters(GcConfig gcConfig,List data) {
        //数据拼接(所有字段)
        StringBuffer fields = new StringBuffer();
        int position = 0;
        for (DbFieldPO fieldMap : data) {
            // 未勾选的字段过滤
            if (!GenerateUtil.isChecked(fieldMap)) {
                continue;
            }
            String type = fieldMap.getType();
            String fieldName =fieldMap.getName();
            String desc = GenerateUtil.getDesc(fieldMap.getDesc(), fieldName);
            String typeDetail = fieldMap.getTypeDetail();
            // 1、生成注释
            Boolean entitySwagger = Boolean.valueOf(gcConfig.getDefaultTemplateParam(TpParamConstant.ENTITY_SWAGGER));
            if (entitySwagger) {
                // 字段注释信息-->  Swagger2 模式
                fields.append("\r\n    @ApiModelProperty(value = \"" + desc  + "\")");
            } else {
                // 字段注释信息-->  doc 注释
                fields.append("\r\n    /** \r\n     * " + desc + " \r\n     */");
            }
            // 3、生成字段
            fields.append("\r\n    " + GenerateServerUtil.jxModel( gcConfig,fieldName, type,false) + "\r\n");
        }

        gcConfig.setTemplateParam("entitys",fields.toString());
        gcConfig.setTemplateParam("serialVersionUID", IdUtil.getSnowflakeNextIdStr());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy