Search in sources :

Example 1 with TableCommentParse

use of com.chao.cloud.common.extra.mybatis.generator.parse.TableCommentParse in project chao-cloud by chaojunzi.

the class ZipVelocityTemplateEngine method appendTableInfo.

/**
 * 添加
 * @param tableInfo 表信息
 * @param objectMap 模板对象
 */
private void appendTableInfo(TableInfo tableInfo, Map<String, Object> objectMap) {
    // 请求路径前缀
    objectMap.put("controllerMappingPrefix", tableInfo.getName().replaceFirst("_", "/"));
    // shiroPermissionsPrefix
    objectMap.put("shiroPermissionsPrefix", tableInfo.getName().replaceFirst("_", ":"));
    // 是否存在date 数据类型
    boolean hasDate = tableInfo.getFields().stream().anyMatch(f -> DbColumnType.DATE.getType().equals(f.getPropertyType()));
    if (hasDate) {
        tableInfo.getImportPackages().add("org.springframework.format.annotation.DateTimeFormat");
        tableInfo.getImportPackages().add("cn.hutool.core.date.DatePattern");
    }
    // 版本
    objectMap.put("version", EnableMybatisGenerator.VERSION);
    // 主键名称类型
    TableField pk = tableInfo.getFields().stream().filter(f -> f.isKeyFlag()).findFirst().orElse(null);
    objectMap.put("pk", pk);
    // 弹窗大小
    long i = tableInfo.getFields().stream().filter(f -> !(f.isKeyFlag() || f.getName().equals(getConfigBuilder().getStrategyConfig().getVersionFieldName()))).count();
    // 比率
    long rate = 30 + (i - 1) * 8;
    objectMap.put("openHeight", rate > 100 ? 100 : rate);
    // 模糊查询 tableInfo
    String comment = tableInfo.getComment();
    Map<String, String> map = this.commentToMap(comment);
    TableCommentParse parse = BeanUtil.mapToBean(map, TableCommentParse.class, true);
    objectMap.put("likeFields", parse.parseLike(tableInfo.getFields()));
    // 标题
    objectMap.put("menuTitle", parse.getTitle());
    // 关键字-保留字处理
    Map<String, String> kws = tableInfo.getFields().stream().collect(Collectors.toMap(TableField::getName, t -> KeyWordConstant.contains(t.getName()) ? "`" : ""));
    objectMap.put("kws", kws);
    if (kws.values().contains("`")) {
        tableInfo.getImportPackages().add("com.baomidou.mybatisplus.annotation.TableField");
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) HtmlTemplateConfig(com.chao.cloud.common.extra.mybatis.generator.template.HtmlTemplateConfig) MapUtil(cn.hutool.core.map.MapUtil) TableCommentParse(com.chao.cloud.common.extra.mybatis.generator.parse.TableCommentParse) BeanUtil(cn.hutool.core.bean.BeanUtil) Template(org.apache.velocity.Template) InjectionConfig(com.baomidou.mybatisplus.generator.InjectionConfig) ConstVal(com.baomidou.mybatisplus.generator.config.ConstVal) VelocityEngine(org.apache.velocity.app.VelocityEngine) Map(java.util.Map) TableInfo(com.baomidou.mybatisplus.generator.config.po.TableInfo) BusinessException(com.chao.cloud.common.exception.BusinessException) CollectionUtils(com.baomidou.mybatisplus.core.toolkit.CollectionUtils) FileType(com.baomidou.mybatisplus.generator.config.rules.FileType) ZipEntry(java.util.zip.ZipEntry) KeyWordConstant(com.chao.cloud.common.extra.mybatis.constant.KeyWordConstant) FileOutConfig(com.baomidou.mybatisplus.generator.config.FileOutConfig) DbColumnType(com.baomidou.mybatisplus.generator.config.rules.DbColumnType) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) VelocityContext(org.apache.velocity.VelocityContext) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) TemplateConfig(com.baomidou.mybatisplus.generator.config.TemplateConfig) List(java.util.List) StrUtil(cn.hutool.core.util.StrUtil) Stream(java.util.stream.Stream) EnableMybatisGenerator(com.chao.cloud.common.extra.mybatis.annotation.EnableMybatisGenerator) VelocityTemplateEngine(com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine) ReflectUtil(cn.hutool.core.util.ReflectUtil) AbstractTemplateEngine(com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine) FileUtil(cn.hutool.core.io.FileUtil) TableField(com.baomidou.mybatisplus.generator.config.po.TableField) TableField(com.baomidou.mybatisplus.generator.config.po.TableField) TableCommentParse(com.chao.cloud.common.extra.mybatis.generator.parse.TableCommentParse)

Aggregations

BeanUtil (cn.hutool.core.bean.BeanUtil)1 FileUtil (cn.hutool.core.io.FileUtil)1 MapUtil (cn.hutool.core.map.MapUtil)1 ReflectUtil (cn.hutool.core.util.ReflectUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 CollectionUtils (com.baomidou.mybatisplus.core.toolkit.CollectionUtils)1 InjectionConfig (com.baomidou.mybatisplus.generator.InjectionConfig)1 ConstVal (com.baomidou.mybatisplus.generator.config.ConstVal)1 FileOutConfig (com.baomidou.mybatisplus.generator.config.FileOutConfig)1 TemplateConfig (com.baomidou.mybatisplus.generator.config.TemplateConfig)1 TableField (com.baomidou.mybatisplus.generator.config.po.TableField)1 TableInfo (com.baomidou.mybatisplus.generator.config.po.TableInfo)1 DbColumnType (com.baomidou.mybatisplus.generator.config.rules.DbColumnType)1 FileType (com.baomidou.mybatisplus.generator.config.rules.FileType)1 AbstractTemplateEngine (com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine)1 VelocityTemplateEngine (com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine)1 BusinessException (com.chao.cloud.common.exception.BusinessException)1 EnableMybatisGenerator (com.chao.cloud.common.extra.mybatis.annotation.EnableMybatisGenerator)1 KeyWordConstant (com.chao.cloud.common.extra.mybatis.constant.KeyWordConstant)1 TableCommentParse (com.chao.cloud.common.extra.mybatis.generator.parse.TableCommentParse)1