✨ 代码生成

This commit is contained in:
冷冷 committed 2018-07-30 23:34:21 +08:00
1 parent 0ff6b01bb5
commit 2438221d3b
46 files changed
+1472 -55

No files matched your search

+7
View File
@@ -64,5 +64,12 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!--mybatis-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>${mbp.boot.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
@@ -1,23 +1,21 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.admin.api.dto;
package com.pig4cloud.pigx.common.core.util;
import com.baomidou.mybatisplus.plugins.Page;
import org.apache.commons.lang.StringUtils;
@@ -45,6 +45,27 @@ ribbon:
ReadTimeout: 10000
ConnectTimeout: 10000
#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等
mybatis-plus:
mapper-locations: classpath:/mapper/*Mapper.xml
global-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type: 0
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: 1
#驼峰下划线转换
db-column-underline: true
#刷新mapper 调试神器
refresh-mapper: false
# 逻辑删除字段
logic-delete-value: 1
logic-not-delete-value: 0
#自定义SQL注入器
sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
configuration:
map-underscore-to-camel-case: true
cache-enabled: true
#swagger公共信息
swagger:
title: 'PigX Swagger API'
@@ -5,4 +5,4 @@ spring:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
@@ -0,0 +1,18 @@
# 数据源配置
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
resources:
static-locations: classpath:/static/,classpath:/views/
# mybaits 模块配置
mybatis-plus:
typeAliasesPackage: com.pig4cloud.pigx.codegen.entity
@@ -5,11 +5,11 @@ spring:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
elasticjob:
# 分布式任务协调依赖zookeeper
zookeeper:
server-lists: 127.0.0.1:2181
server-lists: 114.116.45.246:13181
namespace: pigx-daemon
# 普通任务
simples:
@@ -4,6 +4,7 @@ spring:
locator:
enabled: true
routes:
# 认证中心
- id: pigx-auth
uri: lb://pigx-auth
predicates:
@@ -14,6 +15,7 @@ spring:
# 前端密码解密
- PasswordDecoderFilter
- StripPrefix=1
#UPMS 模块
- id: pigx-upms
uri: lb://pigx-upms
predicates:
@@ -37,6 +39,13 @@ spring:
args:
name: default
fallbackUri: 'forward:/fallback'
# 代码生成模块
- id: pigx-codegen
uri: lb://pigx-codegen
predicates:
- Path=/gen/**
filters:
- StripPrefix=1
security:
encode:
@@ -15,29 +15,12 @@ spring:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等
# mybaits 模块配置
mybatis-plus:
mapper-locations: classpath:/mapper/*Mapper.xml
typeAliasesPackage: com.pig4cloud.pigx.admin.api.entity
global-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type: 0
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: 1
#驼峰下划线转换
db-column-underline: true
#刷新mapper 调试神器
refresh-mapper: true
# 逻辑删除字段
logic-delete-value: 1
logic-not-delete-value: 0
#自定义SQL注入器
sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
configuration:
map-underscore-to-camel-case: true
cache-enabled: true
# swagger相关配置,覆盖全局配置
swagger:
authorization:
-6
View File
@@ -35,12 +35,6 @@
<dependencies>
<!--mybatis-plus 依賴-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mbp.boot.version}</version>
</dependency>
<!--core 工具类-->
<dependency>
<groupId>com.pig4cloud</groupId>
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.entity.SysDict;
import com.pig4cloud.pigx.admin.service.SysDictService;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.entity.SysLog;
import com.pig4cloud.pigx.admin.service.SysLogService;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
@@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails;
import com.pig4cloud.pigx.admin.service.SysOauthClientDetailsService;
import com.pig4cloud.pigx.common.core.util.R;
@@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.dto.RoleDTO;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
import com.pig4cloud.pigx.admin.service.SysRoleMenuService;
@@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
@@ -20,7 +20,7 @@
package com.pig4cloud.pigx.admin.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
import java.util.List;
@@ -20,7 +20,7 @@
package com.pig4cloud.pigx.admin.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
import com.pig4cloud.pigx.admin.api.vo.UserVO;
import org.apache.ibatis.annotations.Param;
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.dto.RoleDTO;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
@@ -21,7 +21,7 @@ package com.pig4cloud.pigx.admin.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysUser;
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.dto.RoleDTO;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
import com.pig4cloud.pigx.admin.api.entity.SysRoleDept;
@@ -25,7 +25,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.dto.Query;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.admin.api.dto.UserDTO;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
+81
View File
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-visual</artifactId>
<version>${pigx.version}</version>
</parent>
<artifactId>pigx-codegen</artifactId>
<version>${pigx.version}</version>
<packaging>jar</packaging>
<name>pigx-codegen</name>
<description>代码生成模块</description>
<properties>
<mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
<commons.lang.version>2.6</commons.lang.version>
<commons.io.version>2.5</commons.io.version>
<commons.configuration.version>1.10</commons.configuration.version>
<velocity.version>1.7</velocity.version>
</properties>
<dependencies>
<!--配置中心客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!--mybatis-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mbp.boot.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--common-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-core</artifactId>
<version>${pigx.version}</version>
</dependency>
<!--代码生成模板引擎-->
<dependency>
<artifactId>velocity</artifactId>
<groupId>org.apache.velocity</groupId>
<version>${velocity.version}</version>
</dependency>
<!--web 模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!--排除tomcat依赖-->
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<!--undertow容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
/**
* @author lengleng
* @date 2018/07/29
* 代码生成模块
*/
@SpringCloudApplication
public class PigxCodeGenApplication {
public static void main(String[] args) {
SpringApplication.run(PigxCodeGenApplication.class, args);
}
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.config;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author lengleng
* @date 2017/10/29
*/
@Configuration
@MapperScan("com.pig4cloud.pigx.codegen.mapper")
public class MybatisPlusConfigurer {
/**
* 分页插件
*
* @return PaginationInterceptor
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.io.IoUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.codegen.service.SysGeneratorService;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
* 代码生成器
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2016年12月19日 下午9:12:58
*/
@RestController
@AllArgsConstructor
@RequestMapping("/generator")
public class SysGeneratorController {
private final SysGeneratorService sysGeneratorService;
/**
* 列表
*
* @param params 参数集
* @return 数据库表
*/
@GetMapping("/page")
public Page list(@RequestParam Map<String, Object> params) {
return sysGeneratorService.queryPage(params);
}
/**
* 生成代码
*/
@GetMapping("/code/{tableName}")
public void code(@PathVariable String tableName, HttpServletResponse response) throws IOException {
byte[] data = sysGeneratorService.generatorCode(new String[]{tableName});
response.reset();
response.setHeader("Content-Disposition", String.format("attachment; filename=%s.zip", tableName));
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data);
}
}
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import lombok.Data;
/**
* @author lengleng
* @date 2018/07/29
* 列属性: https://blog.csdn.net/lkforce/article/details/79557482
*/
@Data
public class ColumnEntity {
/**
* 列表
*/
private String columnName;
/**
* 数据类型
*/
private String dataType;
/**
* 备注
*/
private String comments;
/**
* 驼峰属性
*/
private String caseAttrName;
/**
* 普通属性
*/
private String lowerAttrName;
/**
* 属性类型
*/
private String attrType;
/**
* 其他信息。
*/
private String extra;
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import lombok.Data;
import java.util.List;
/**
* @author lengleng
* @date 2018/07/29
* 表属性: https://blog.csdn.net/lkforce/article/details/79557482
*/
@Data
public class TableEntity {
/**
* 名称
*/
private String tableName;
/**
* 备注
*/
private String comments;
/**
* 主键
*/
private ColumnEntity pk;
/**
* 列名
*/
private List<ColumnEntity> columns;
/**
* 驼峰类型
*/
private String caseClassName;
/**
* 普通类型
*/
private String lowerClassName;
}
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.common.core.util.Query;
import java.util.List;
import java.util.Map;
/**
* 代码生成器
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2016年12月19日 下午3:32:04
*/
public interface SysGeneratorMapper {
/**
* 分页查询表格
*
* @param query
* @return
*/
List<Map<String, Object>> queryList(Map query);
/**
* 查询表数量
*
* @param query
* @return
*/
int queryTotal(Map query);
Map<String, String> queryTable(String tableName);
List<Map<String, String>> queryColumns(String tableName);
}
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.common.core.util.Query;
import java.util.Map;
/**
* @author lengleng
* @date 2018/7/29
*/
public interface SysGeneratorService {
/**
* 生成代码
*
* @param tableNames 表名称
* @return
*/
byte[] generatorCode(String[] tableNames);
/**
* 分页查询表
* @param query 查询条件
* @return
*/
Page queryPage(Map<String,Object> query);
}
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.codegen.mapper.SysGeneratorMapper;
import com.pig4cloud.pigx.codegen.service.SysGeneratorService;
import com.pig4cloud.pigx.codegen.util.GenUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;
/**
* 代码生成器
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2016年12月19日 下午3:33:38
*/
@Service
@AllArgsConstructor
public class SysGeneratorServiceImpl implements SysGeneratorService {
private final SysGeneratorMapper sysGeneratorMapper;
/**
* 分页查询表
*
* @param query 查询条件
* @return
*/
@Override
public Page queryPage(Map<String, Object> query) {
Integer current = Integer.parseInt(query.getOrDefault("page", "1").toString());
Integer limit = Integer.parseInt(query.getOrDefault("limit", "1").toString());
Page page = new Page(current, limit);
List<Map<String, Object>> list = sysGeneratorMapper.queryList(query);
if (CollUtil.isEmpty(list)) {
return page;
}
page.setTotal(sysGeneratorMapper.queryTotal(query));
page.setRecords(list);
return page;
}
/**
* 生成代码
*
* @param tableNames 表名称
* @return
*/
@Override
public byte[] generatorCode(String[] tableNames) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames) {
//查询表信息
Map<String, String> table = queryTable(tableName);
//查询列信息
List<Map<String, String>> columns = queryColumns(tableName);
//生成代码
GenUtils.generatorCode(table, columns, zip);
}
IoUtil.close(zip);
return outputStream.toByteArray();
}
private Map<String, String> queryTable(String tableName) {
return sysGeneratorMapper.queryTable(tableName);
}
private List<Map<String, String>> queryColumns(String tableName) {
return sysGeneratorMapper.queryColumns(tableName);
}
}
@@ -0,0 +1,247 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.util;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import com.pig4cloud.pigx.codegen.entity.ColumnEntity;
import com.pig4cloud.pigx.codegen.entity.TableEntity;
import com.pig4cloud.pigx.common.core.exception.CheckedException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 代码生成器 工具类
*
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2016年12月19日 下午11:40:24
*/
@Slf4j
public class GenUtils {
public static List<String> getTemplates() {
List<String> templates = new ArrayList<>();
templates.add("template/Entity.java.vm" );
templates.add("template/Mapper.java.vm" );
templates.add("template/Mapper.xml.vm" );
templates.add("template/Service.java.vm" );
templates.add("template/ServiceImpl.java.vm" );
templates.add("template/Controller.java.vm" );
templates.add("template/menu.sql.vm" );
templates.add("template/index.vue.vm" );
templates.add("template/api.js.vm" );
templates.add("template/crud.js.vm" );
return templates;
}
/**
* 生成代码
*/
public static void generatorCode(Map<String, String> table,
List<Map<String, String>> columns, ZipOutputStream zip) {
//配置信息
Configuration config = getConfig();
boolean hasBigDecimal = false;
//表信息
TableEntity tableEntity = new TableEntity();
tableEntity.setTableName(table.get("tableName" ));
tableEntity.setComments(table.get("tableComment" ));
//表名转换成Java类名
String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix" ));
tableEntity.setCaseClassName(className);
tableEntity.setLowerClassName(StringUtils.uncapitalize(className));
//列信息
List<ColumnEntity> columnList = new ArrayList<>();
for (Map<String, String> column : columns) {
ColumnEntity columnEntity = new ColumnEntity();
columnEntity.setColumnName(column.get("columnName" ));
columnEntity.setDataType(column.get("dataType" ));
columnEntity.setComments(column.get("columnComment" ));
columnEntity.setExtra(column.get("extra" ));
//列名转换成Java属性名
String attrName = columnToJava(columnEntity.getColumnName());
columnEntity.setCaseAttrName(attrName);
columnEntity.setLowerAttrName(StringUtils.uncapitalize(attrName));
//列的数据类型,转换成Java类型
String attrType = config.getString(columnEntity.getDataType(), "unknowType" );
columnEntity.setAttrType(attrType);
if (!hasBigDecimal && attrType.equals("BigDecimal" )) {
hasBigDecimal = true;
}
//是否主键
if ("PRI".equalsIgnoreCase(column.get("columnKey" )) && tableEntity.getPk() == null) {
tableEntity.setPk(columnEntity);
}
columnList.add(columnEntity);
}
tableEntity.setColumns(columnList);
//没主键,则第一个字段为主键
if (tableEntity.getPk() == null) {
tableEntity.setPk(tableEntity.getColumns().get(0));
}
//设置velocity资源加载器
Properties prop = new Properties();
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" );
Velocity.init(prop);
String mainPath = config.getString("mainPath" );
mainPath = StringUtils.isBlank(mainPath) ? "com.pig4cloud.pigx" : mainPath;
//封装模板数据
Map<String, Object> map = new HashMap<>();
map.put("tableName", tableEntity.getTableName());
map.put("comments", tableEntity.getComments());
map.put("pk", tableEntity.getPk());
map.put("className", tableEntity.getCaseClassName());
map.put("classname", tableEntity.getLowerClassName());
map.put("pathName", tableEntity.getLowerClassName().toLowerCase());
map.put("columns", tableEntity.getColumns());
map.put("hasBigDecimal", hasBigDecimal);
map.put("mainPath", mainPath);
map.put("package", config.getString("package" ));
map.put("moduleName", config.getString("moduleName" ));
map.put("author", config.getString("author" ));
map.put("datetime", DateUtil.now());
VelocityContext context = new VelocityContext(map);
//获取模板列表
List<String> templates = getTemplates();
for (String template : templates) {
//渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, CharsetUtil.UTF_8);
tpl.merge(context, sw);
try {
//添加到zip
zip.putNextEntry(new ZipEntry(Objects
.requireNonNull(getFileName(template, tableEntity.getCaseClassName()
, config.getString("package" ), config.getString("moduleName" )))));
IoUtil.write(zip, CharsetUtil.UTF_8, false, sw.toString());
IoUtil.close(sw);
zip.closeEntry();
} catch (IOException e) {
throw new CheckedException("渲染模板失败,表名:" + tableEntity.getTableName(), e);
}
}
}
/**
* 列名转换成Java属性名
*/
private static String columnToJava(String columnName) {
return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "" );
}
/**
* 表名转换成Java类名
*/
private static String tableToJava(String tableName, String tablePrefix) {
if (StringUtils.isNotBlank(tablePrefix)) {
tableName = tableName.replace(tablePrefix, "" );
}
return columnToJava(tableName);
}
/**
* 获取配置信息
*/
public static Configuration getConfig() {
try {
return new PropertiesConfiguration("generator.properties" );
} catch (ConfigurationException e) {
throw new CheckedException("获取配置文件失败,", e);
}
}
/**
* 获取文件名
*/
public static String getFileName(String template, String className, String packageName, String moduleName) {
String packagePath = "pigx" + File.separator + "main" + File.separator + "java" + File.separator;
if (StringUtils.isNotBlank(packageName)) {
packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator;
}
if (template.contains("Entity.java.vm" )) {
return packagePath + "entity" + File.separator + className + ".java";
}
if (template.contains("Mapper.java.vm" )) {
return packagePath + "mapper" + File.separator + className + "Mapper.java";
}
if (template.contains("Service.java.vm" )) {
return packagePath + "service" + File.separator + className + "Service.java";
}
if (template.contains("ServiceImpl.java.vm" )) {
return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java";
}
if (template.contains("Controller.java.vm" )) {
return packagePath + "controller" + File.separator + className + "Controller.java";
}
if (template.contains("Mapper.xml.vm" )) {
return "pigx" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + moduleName + File.separator + className + "Mapper.xml";
}
if (template.contains("menu.sql.vm" )) {
return className.toLowerCase() + "_menu.sql";
}
if (template.contains("index.vue.vm" )) {
return "pigx-ui" + File.separator + "src" + File.separator + "views" +
File.separator + moduleName + File.separator + className.toLowerCase() + File.separator + "index.vue";
}
if (template.contains("api.js.vm" )) {
return "pigx-ui" + File.separator + "src" + File.separator + "api" + File.separator + className.toLowerCase() + ".js";
}
if (template.contains("crud.js.vm" )) {
return "pigx-ui" + File.separator + "src" + File.separator + "const" +
File.separator + "curd" + File.separator + className.toLowerCase() + ".js";
}
return null;
}
}
@@ -0,0 +1,26 @@
server:
port: 5003
spring:
application:
name: pigx-codegen
#配置中心
cloud:
config:
fail-fast: true
name: ${spring.application.name}
profile: dev
discovery:
enabled: true
service-id: pigx-config
# 注册中心配置
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://pig:pig@localhost:1025/eureka/
logging:
level:
root: debug
@@ -0,0 +1,34 @@
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
mainPath=com.pig4cloud.pigx
#\u5305\u540D
package=com.pig4cloud.pigx
moduleName=generator
#\u4F5C\u8005
author=pigx code generator
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
tablePrefix=tb_
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
tinyint=Integer
smallint=Integer
mediumint=Integer
int=Integer
integer=Integer
bigint=Long
float=Float
double=Double
decimal=BigDecimal
bit=Boolean
char=String
varchar=String
tinytext=String
text=String
mediumtext=String
longtext=String
date=LocalDateTime
datetime=LocalDateTime
timestamp=LocalDateTime
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.SysGeneratorMapper">
<select id="queryList" resultType="map">
select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
where table_schema = (select database())
<if test="tableName != null and tableName.trim() != ''">
and table_name like concat('%', #{tableName}, '%')
</if>
order by create_time desc
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from information_schema.tables where table_schema = (select database())
<if test="tableName != null and tableName.trim() != ''">
and table_name like concat('%', #{tableName}, '%')
</if>
</select>
<select id="queryTable" resultType="map">
select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
where table_schema = (select database()) and table_name = #{tableName}
</select>
<select id="queryColumns" resultType="map">
select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns
where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
</select>
</mapper>
@@ -0,0 +1,90 @@
package ${package}.${moduleName}.controller;
import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.util.Query;
import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.service.${className}Service;
import com.pig4cloud.pigx.common.core.util.R;
import java.util.Map;
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
@RestController
@RequestMapping("${moduleName}/${pathName}")
public class ${className}Controller {
@Autowired
private ${className}Service ${classname}Service;
/**
* 列表
* @param params
* @return
*/
@GetMapping("/page")
public Page page(@RequestParam Map<String, Object> params) {
params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
return ${classname}Service.selectPage(new Query<>(params), new EntityWrapper<>());
}
/**
* 信息
* @param ${pk.lowerAttrName}
* @return R
*/
@GetMapping("/{${pk.lowerAttrName}}")
public R info(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
${className} ${classname} = ${classname}Service.selectById(${pk.lowerAttrName});
return new R<>(${classname});
}
/**
* 保存
* @param ${classname}
* @return R
*/
@PostMapping("/save")
public R save(@RequestBody ${className} ${classname}){
${classname}Service.insert(${classname});
return new R<>(Boolean.TRUE);
}
/**
* 修改
* @param ${classname}
* @return R
*/
@PutMapping("/update")
public R update(@RequestBody ${className} ${classname}){
${classname}Service.updateById(${classname});
return new R<>(Boolean.TRUE);
}
/**
* 删除
* @param ${pk.lowerAttrName}s
* @return R
*/
@DeleteMapping("/delete")
public R delete(@RequestBody ${pk.attrType}[] ${pk.lowerAttrName}s){
${classname}Service.deleteBatchIds(Arrays.asList(${pk.lowerAttrName}s));
return new R<>(Boolean.TRUE);
}
}
@@ -0,0 +1,34 @@
package ${package}.${moduleName}.entity;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("${tableName}")
public class ${className} implements Serializable {
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
/**
* $column.comments
*/
#if($column.columnName == $pk.columnName)
@TableId
#end
private $column.attrType $column.lowerAttrName;
#end
}
@@ -0,0 +1,16 @@
package ${package}.${moduleName}.mapper;
import ${package}.${moduleName}.entity.${className};
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
@Mapper
public interface ${className}Mapper extends BaseMapper<${className}> {
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package}.${moduleName}.dao.${className}Mappper">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="${package}.${moduleName}.entity.${className}" id="${classname}Map">
#foreach($column in $columns)
<result property="${column.attrname}" column="${column.columnName}"/>
#end
</resultMap>
</mapper>
@@ -0,0 +1,14 @@
package ${package}.${moduleName}.service;
import com.baomidou.mybatisplus.service.IService;
import ${package}.${moduleName}.entity.${className};
/**
* ${comments}
*
* @author ${author}
* @date ${datetime}
*/
public interface ${className}Service extends IService<${className}> {
}
@@ -0,0 +1,17 @@
package ${package}.${moduleName}.service.impl;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import ${package}.${moduleName}.mapper.${className}Mapper;
import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.service.${className}Service;
@Service("${classname}Service")
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements ${className}Service {
}
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
import request from '@/router/axios'
export function fetchList(query) {
return request({
url: '/${moduleName}/${pathName}/page',
method: 'get',
params: query
})
}
export function addObj(obj) {
return request({
url: '/${moduleName}/${pathName}/',
method: 'post',
data: obj
})
}
export function getObj(id) {
return request({
url: '/${moduleName}/${pathName}/' + id,
method: 'get'
})
}
export function delObj(id) {
return request({
url: '/${moduleName}/${pathName}/' + id,
method: 'delete'
})
}
export function putObj(obj) {
return request({
url: '/${moduleName}/${pathName}/',
method: 'put',
data: obj
})
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
export const tableOption = {
"border": true,
"index": true,
"stripe": true,
"menuAlign": "center",
"align": "center",
"editBtn": false,
"delBtn": false,
"dic": [],
"column": [
#foreach ($column in $columns)
{
label: '$column.comments',
prop: '$column.lowerAttrName'
},
#end
]
}
@@ -0,0 +1,189 @@
<!--
- Copyright (c) 2018-2025, lengleng All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- Neither the name of the pig4cloud.com developer nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
- Author: lengleng (wangiegie@gmail.com)
-->
<template>
<div class="app-container pull-auto">
<basic-container>
<avue-crud ref="crud"
:page="page"
:data="tableData"
:table-loading="tableLoading"
:option="tableOption"
@current-change="currentChange"
@refresh-change="refreshChange"
@size-change="sizeChange"
@row-update="handleUpdate"
@row-save="handleSave"
@row-del="rowDel">
<template slot="menuLeft">
<el-button type="primary"
@click="handleAdd"
size="small"
v-if="permissions.${moduleName}_${pathName}_add">新 增</el-button>
<br /><br />
</template>
<template slot-scope="scope"
slot="menu">
<el-button type="primary"
v-if="permissions.${moduleName}_${pathName}_edit"
icon="el-icon-check"
size="small"
plain
@click="handleEdit(scope.row,scope.index)">编辑</el-button>
<el-button type="danger"
v-if="permissions.${moduleName}_${pathName}_del"
icon="el-icon-delete"
size="small"
plain
@click="handleDel(scope.row,scope.index)">删除</el-button>
</template>
</avue-crud>
</basic-container>
</div>
</template>
<script>
import { fetchList, getObj, addObj, putObj, delObj } from '@/api/${pathName}'
import { tableOption } from '@/const/crud/${pathName}'
import { mapGetters } from 'vuex'
export default {
name: '${pathName}',
data() {
return {
tableData: [],
page: {
total: 0, // 总页数
currentPage: 1, // 当前页数
pageSize: 20 // 每页显示多少条
},
tableLoading: false,
tableOption: tableOption
}
},
created() {
this.getList()
},
mounted: function() { },
computed: {
...mapGetters(['permissions'])
},
methods: {
getList() {
this.tableLoading = true
fetchList({
page: this.page.currentPage,
limit: this.page.pageSize
}).then(response => {
this.tableData = response.data.records
this.page.total = response.data.total
this.tableLoading = false
})
},
currentChange(val) {
console.log(val)
this.getList()
},
currentChange(val) {
this.page.currentPage = val
this.getList()
},
sizeChange(val) {
this.page.pageSize = val
this.getList()
},
/**
* @title 打开新增窗口
* @detail 调用crud的handleadd方法即可
*
**/
handleAdd: function() {
this.$refs.crud.rowAdd()
},
handleEdit(row, index) {
this.$refs.crud.rowEdit(row, index)
},
handleDel(row, index) {
this.$refs.crud.rowDel(row, index)
},
rowDel: function(row, index) {
var _this = this
this.$confirm('是否确认删除ID为' + row.clientId, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(function() {
return delObj(row.clientId)
})
.then(data => {
_this.tableData.splice(index, 1)
_this.$message({
showClose: true,
message: '删除成功',
type: 'success'
})
})
.catch(function(err) { })
},
/**
* @title 数据更新
* @param row 为当前的数据
* @param index 为当前更新数据的行数
* @param done 为表单关闭函数
*
**/
handleUpdate: function(row, index, done) {
putObj(row).then(data => {
this.tableData.splice(index, 1, Object.assign({}, row))
this.$message({
showClose: true,
message: '修改成功',
type: 'success'
})
done()
})
},
/**
* @title 数据添加
* @param row 为当前的数据
* @param done 为表单关闭函数
*
**/
handleSave: function(row, done) {
addObj(row).then(data => {
this.tableData.push(Object.assign({}, row))
this.$message({
showClose: true,
message: '添加成功',
type: 'success'
})
done()
})
},
/**
* 刷新回调
*/
refreshChange() {
this.getList()
}
}
}
</script>
<style lang="scss" scoped>
</style>
@@ -0,0 +1,11 @@
-- 菜单SQL
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '1', 'views/${moduleName}/${pathName}/index', '', '0', 'client', 'icon-bangzhushouji', '8', '0', '2018-01-20 13:17:19', '8', '2018-07-29 13:38:19', '${comments}管理');
-- 菜单对应按钮SQL
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '8', null, '${moduleName}_${pathName}_add', '1', null, '1', '81', '0', '2018-05-15 21:35:18', '0', '2018-07-29 13:38:59', '${comments}新增');
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '8', null, '${moduleName}_${pathName}_edit', '1', null, '1', '81', '0', '2018-05-15 21:35:18', '1', '2018-07-29 13:38:59', '${comments}修改');
insert into `pigx`.`sys_menu` ( `parent_id`, `component`, `permission`, `type`, `path`, `icon`, `menu_id`, `del_flag`, `create_time`, `sort`, `update_time`, `name`)
values ( '8', null, '${moduleName}_${pathName}_del', '1', null, '1', '81', '0', '2018-05-15 21:35:18', '2', '2018-07-29 13:38:59', '${comments}删除');
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class RenrenApplicationTests {
@Test
public void contextLoads() {
}
}
@@ -20,6 +20,7 @@ package com.pig4cloud.pigx.daemon;
import com.pig4cloud.pigx.common.job.annotation.EnablePigxJob;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
/**
* @author lengleng
@@ -27,7 +28,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* 分布式任务调度模块
*/
@EnablePigxJob
@SpringBootApplication
@SpringCloudApplication
public class PigxDaemonApplication {
public static void main(String[] args) {
+1
View File
@@ -34,6 +34,7 @@
<packaging>pom</packaging>
<modules>
<module>pigx-codegen</module>
<module>pigx-daemon</module>
<module>pigx-monitor</module>
</modules>