Initial commit

This commit is contained in:
南宁网宿科技
2023-06-03 23:56:49 +08:00
commit 912944faea
821 changed files with 74279 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package com.gxwebsoft;
import com.gxwebsoft.common.core.utils.JSONUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.Resource;
import java.util.HashMap;
@SpringBootTest
public class RedisTest {
@Resource
private StringRedisTemplate stringRedisTemplate;
//
// @Test
// public void test(){
//// stringRedisTemplate.opsForValue().set("test:add:2",Long.toString(1L));
//// stringRedisTemplate.opsForValue().increment("test:add:2",10L);
//// stringRedisTemplate.opsForValue().decrement("test:add:2",2L);
//// stringRedisTemplate.opsForValue().append("test:add:2","ssss");
// HashMap<String, String> map = new HashMap<>();
// map.put("name","李四");
// map.put("phone","13800138001");
// HashMap<String, String> map2 = new HashMap<>();
// map2.put("name","赵六");
// map2.put("phone","13800138001");
// HashMap<String, String> map3 = new HashMap<>();
// map3.put("name","张三");
// map3.put("phone","13800138001");
// stringRedisTemplate.opsForSet().add("test:set:2", JSONUtil.toJSONString(map),JSONUtil.toJSONString(map2),JSONUtil.toJSONString(map3));
// }
}

View File

@@ -0,0 +1,263 @@
package com.gxwebsoft;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.qrcode.QrCodeException;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.gxwebsoft.apps.service.HualalaService;
import com.gxwebsoft.apps.service.TestDataService;
import com.gxwebsoft.common.system.mapper.RoleMapper;
import com.gxwebsoft.common.system.mapper.UserMapper;
import com.gxwebsoft.common.system.service.SettingService;
import com.gxwebsoft.common.system.service.UserService;
import com.gxwebsoft.shop.mapper.OrderGoodsMapper;
import com.gxwebsoft.shop.mapper.OrderMapper;
import com.gxwebsoft.shop.service.OrderService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Created by WebSoft on 2020-03-23 23:37
*/
@SpringBootTest
public class TestMain {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private OrderService orderService;
@Resource
private OrderGoodsMapper orderGoodsMapper;
@Resource
private OrderMapper orderMapper;
@Resource
private TestDataService testDataService;
@Resource
private HualalaService hualalaService;
@Resource
private SettingService settingService;
@Resource
private UserService userService;
@Resource
private UserMapper userMapper;
@Resource
private RoleMapper roleMapper;
/**
* 生成唯一的key用于jwt工具类
*/
// @Test
// public void testGenJwtKey() {
// System.out.println(JwtUtil.encodeKey(JwtUtil.randomKey()));
// }
/**
* 生成加密后的登录密码
* @return
*/
@Test
public void testEncodePassword() throws UnsupportedEncodingException {
// DateTime date = DateUtil.date();
// System.out.println("date = " + date);
// final String today = DateUtil.today();
// System.out.println("today = " + today);
// final DateTime dateTime = DateUtil.beginOfDay(date);
// System.out.println("dateTime = " + dateTime);
// System.out.println(new BCryptPasswordEncoder().encode("admin"));
String encodedReturnUrl = URLEncoder.encode("https://server.gxwebsoft.com/api/open/wx-work/saveAccessToken","UTF-8");
System.out.println("encodedReturnUrl = " + encodedReturnUrl);
}
// @Test
// public void test3() {
// String key = "test:user:10";
// HashMap<String, Object> map = new HashMap<>();
// map.put("name", "科技小王子");
// map.put("sex", "男");
// map.put("phone", "13737128880");
// map.put("money", "238585.215");
// stringRedisTemplate.opsForHash().putAll(key, map);
// }
// OrderParam param = new OrderParam();
// param.setPayStatus(30);
// param.setOrderNo("202303118310602");
// final List<Order> all = orderMapper.getAll(param);
// System.out.println("all = " + all);
// OrderParam param = new OrderParam();
// param.setOrderNo("2023031181184283");
// param.setPayStatus(20);
// boolean b = orderMapper.updatePayStatus(param);
// System.out.println("b = " + b);
// Order order = orderService.getByOutTradeNo("20230301761610059");
// OrderParam orderParam = new OrderParam();
// orderParam.setPayStatus(20);
// orderParam.setOrderNo("20230301761610059");
// orderMapper.updatePayStatus(orderParam);
// System.out.println("order = " + order);
// Order order = new Order();
// order.setOrderId(400);
// order.setComments("sdfsdfsdfs");
//
// boolean update = orderService.lambdaUpdate()
// .eq(Order::getOrderId, order.getOrderId())
// .update(order);
// System.out.println("update = " + update);
// OrderParam param = new OrderParam();
// param.setOrderNo("20230301761610059");
// Order order = orderService.getByOutTradeNo("20230301761610059");
// System.out.println("order = " + order);
// final int i = orderMapper.updateById(order);
// System.out.println("i = " + i);
// final Order one = param.getOne(orderMapper.getOne(param));
// one.setTotalPrice(new BigDecimal("2.22"));
// one.setPayStatus(20);
// orderMapper.updateById(one);
// System.out.println("one = " + one);
// Order order = orderService.getByOutTradeNo("20230301761610059");
// order.setPayStatus(20);
// order.setTotalPrice(new BigDecimal("1.11"));
// if (orderService.updateById(order)) {
// System.out.println("成功");
// }
// @Test
// public void test() {
// final TestData testData = new TestData();
// testData.setTitle("测试");
// testData.setContent("内容...");
// testData.setTenantId(10);
// testDataService.save(testData);
// final boolean b = testDataService.removeById(2496);
// }
// @Test
// public void query() {
// HashMap<String, Object> params = new HashMap<>();
// params.put("shopID", Long.valueOf("76230180"));
// JSONObject response = hualalaService.doPost("/doc/getPaySubject", params);
// System.out.println("response = " + response);
// }
// 推送订单到哗啦啦
// @Test
// public void pushOrder(){
// Order orderInfo = orderService.getByOutTradeNo("202303118345835");
// final List<OrderGoods> goodsInfo = orderGoodsMapper.selectByOrderId(orderInfo.getOrderId());
// System.out.println("orderInfo = " + orderInfo);
// System.out.println("goodsInfo = " + goodsInfo);
// // 菜品信息
// ArrayList<Object> orderItem = new ArrayList<>();
// JSONObject item = new JSONObject();
// item.put("foodID",603798638);
// item.put("foodName","肉汁煲霜打萝卜.");
// item.put("foodUnit","份");
// item.put("foodUnitID","1748099318");
// item.put("isSetFood",0);
// item.put("isBatching",0);
// item.put("foodCount",1);
// item.put("originPrice","100");
// item.put("takeoutPackagingFee","1");
// item.put("isDiscount",0);
// item.put("duePrice","1");
// orderItem.add(item);
// // 支付信息
// ArrayList<Object> payInfo = new ArrayList<>();
// JSONObject payItem = new JSONObject();
// payItem.put("paymentSubjectID",Long.valueOf("51010440"));
// payItem.put("paymentSubjectName","微信小程序实收");
// payItem.put("dueAmount","1");
// payItem.put("paymentStatus",20);
// payItem.put("payWay",70);
// payInfo.add(payItem);
//
// // 订单信息
// JSONObject order = new JSONObject();
// order.put("orderSubType",20);
// order.put("orderStatus",20);
// order.put("discountTotalAmount","1");
// order.put("dinners",1);
// // 期望送达时间
// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmm");
// order.put("orderTime",sdf1.format(orderInfo.getCreateTime()));
// order.put("orderItem",orderItem);
// order.put("takeoutAddress","外送地址:");
// order.put("deliveryAmount","0");
// order.put("serviceAmount","0");
// order.put("channelKey","399_weixin");
// order.put("isAlreadyPaid","1");
// order.put("orderMode",1);
// order.put("OrderRemark","");
// order.put("payment",payInfo);
//
// HashMap<String,Object> params = new HashMap<>();
// params.put("shopID",Long.valueOf("76230180"));
// params.put("isCheackOut",0);
// params.put("isThirdPay",2);
// params.put("bankCode","weChat");
// params.put("order",order);
// params.put("isSentMsg",1);
// params.put("msgType",120);
// params.put("thirdOrderID",orderInfo.getOrderNo());
//
//// JSONObject response = hualalaService.doPost("/order/submitordernew", params);
//// System.out.println("response = " + response);
// }
// @Test
// public void chat() {
//
// String endpoint = "https://api.openai.com/v1/engines/davinci-codex/completions";
// String apiKey = "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";
//
//
// // 构建请求
// HttpRequest request = HttpRequest.get("https://api.openai.com/v1/engines/davinci-codex/completions")
// .header("Authorization", "Bearer ".concat(apiKey));
//
// // 发送请求并获取响应
// HttpResponse response = request.execute();
//
// // 处理响应结果
// int statusCode = response.getStatus();
// String body = response.body();
// System.out.println("body = " + body);
// }
// @Test
// public void chatGPT() {
// String abc = "{\"finish_reason\":\"stop\",\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"您好!有什么我能为您效劳的吗?\"}}";
// final JSONObject jsonObject = JSONObject.parseObject(abc);
// final String message = jsonObject.getString("message");
// System.out.println("message = " + message);
// final JSONObject jsonObject1 = JSONObject.parseObject(message);
// final String content = jsonObject1.getString("content");
// System.out.println("content = " + content);
// }
// 自定义参数这部分是Hutool工具封装的
// @Test
// public void initQrConfig() {
// // 生成指定url对应的二维码到文件宽和高都是300像素
// QrCodeUtil.generate("https://hutool.cn/", 300, 300, FileUtil.file("/Users/gxwebsoft/Documents/uploads/qrcode.jpg"));
// }
}

View File

@@ -0,0 +1,13 @@
package com.gxwebsoft;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class WebSoftApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@@ -0,0 +1,189 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class AppsGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "科技小王子";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/com_gxwebsoft_oa?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "com_gxwebsoft_oa";
private static final String DB_PASSWORD = "EZfW2R4YiWfbLHLw";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "apps";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "apps_equipment",
// "apps_equipment_fault",
// "apps_equipment_alarm",
// "apps_equipment_record"
// "apps_equipment_order"
// "apps_cashier",
// "apps_hualala_card",
// "apps_hualala_card_benefits",
// "apps_hualala_food",
// "apps_hualala_shop",
// "apps_hualala_cart_food",
// "apps_hualala_food_category",
// "apps_test_data",
// "apps_link",
// "apps_bc_agent",
// "apps_bc_temporary",
// "apps_link",
// "apps_bc_plan",
// "apps_bc_food",
// "apps_bc_equipment",
// "apps_bc_cookbook"
"apps_bc_export"
// "apps_equipment_order_goods"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"apps_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,177 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class CmsGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "科技小王子";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/com_gxwebsoft_oa?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "com_gxwebsoft_oa";
private static final String DB_PASSWORD = "EZfW2R4YiWfbLHLw";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "cms";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "cms_article",
"cms_article_category",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
// "cms_docs",
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"cms_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,167 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class CodeGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "WebSoft";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://localhost:3306/websoft-api?useUnicode=true&useSSL=false&characterEncoding=utf8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "root";
private static final String DB_PASSWORD = "123456";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "test";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
"sys_user",
"sys_role"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"sys_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,179 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class OaGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "科技小王子";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/com_gxwebsoft_oa?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "com_gxwebsoft_oa";
private static final String DB_PASSWORD = "EZfW2R4YiWfbLHLw";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "oa";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "oa_project",
// "oa_link",
// "oa_assets",
// "oa_customer",
// "oa_task",
// "oa_task_record",
// "oa_task_user",
// "sys_tenant",
// "oa_app",
// "oa_setting",
// "oa_assets",
"oa_app_user",
// "oa_notice"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"oa_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,203 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class ShopGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "科技小王子";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/com_gxwebsoft_oa?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "com_gxwebsoft_oa";
private static final String DB_PASSWORD = "EZfW2R4YiWfbLHLw";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "shop";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "shop_order",
// "shop_goods",
// "shop_store",
// "shop_cart",
// "shop_express",
// "shop_category",
// "shop_goods_image",
// "shop_comment",
// "shop_goods_service"
// "shop_member"
// "shop_user_balance_log",
// "shop_user_address",
// "shop_user_coupon",
// "shop_user_follow",
// "shop_user_oauth",
// "shop_user_points_log",
// "shop_cart"
// "shop_info"
// "shop_coupon"
// "shop_clerk"
// "shop_merchant",
// "shop_merchant_clerk"
// "shop_merchant_withdraw"
// "shop_order_address"
// "shop_payment",
// "shop_payment_template",
// "shop_payment_trade"
// "shop_order_goods"
// "shop_user_oauth"
// "shop_order_renew"
// "shop_recharge_order",
// "shop_recharge_order_plan",
// "shop_recharge_plan",
// "shop_user_balance_log"
// "shop_user_referee",
"shop_order_refund",
"shop_order_refund_address"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"shop_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,175 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class SysGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "科技小王子";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/com_gxwebsoft_oa?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "com_gxwebsoft_oa";
private static final String DB_PASSWORD = "EZfW2R4YiWfbLHLw";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "common.system";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "sys_user",
// "sys_tenant",
// "sys_setting"
// "sys_access_key"
// "sys_company",
// "sys_industry"
// "sys_plug",
"sys_company"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"sys_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,170 @@
package com.gxwebsoft.generator;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 代码生成工具
*
* @author WebSoft
* @since 2021-09-05 00:31:14
*/
public class TowerGenerator {
// 输出位置
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
// 输出目录
private static final String OUTPUT_DIR = "/src/main/java";
// 作者名称
private static final String AUTHOR = "科技小王子";
// 是否在xml中添加二级缓存配置
private static final boolean ENABLE_CACHE = false;
// 数据库连接配置
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/com_gxwebsoft_oa?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_USERNAME = "com_gxwebsoft_oa";
private static final String DB_PASSWORD = "EZfW2R4YiWfbLHLw";
// 包名
private static final String PACKAGE_NAME = "com.gxwebsoft";
// 模块名
private static final String MODULE_NAME = "tower";
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
// "tower_equipment",
// "tower_warehouse",
// "tower_accessory"
// "tower_project",
"tower_model"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{
"sys_",
"tb_"
};
// 不需要作为查询参数的字段
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
"tenant_id",
"create_time",
"update_time"
};
// 查询参数使用String的类型
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
"Date",
"LocalDate",
"LocalTime",
"LocalDateTime"
};
// 查询参数使用EQ的类型
private static final String[] PARAM_EQ_TYPE = new String[]{
"Integer",
"Boolean",
"BigDecimal"
};
// 是否添加权限注解
private static final boolean AUTH_ANNOTATION = true;
// 是否添加日志注解
private static final boolean LOG_ANNOTATION = true;
// controller的mapping前缀
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
// 模板所在位置
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
gc.setAuthor(AUTHOR);
gc.setOpen(false);
gc.setFileOverride(true);
gc.setEnableCache(ENABLE_CACHE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(DB_URL);
// dsc.setSchemaName("public");
dsc.setDriverName(DB_DRIVER);
dsc.setUsername(DB_USERNAME);
dsc.setPassword(DB_PASSWORD);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(MODULE_NAME);
pc.setParent(PACKAGE_NAME);
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setInclude(TABLE_NAMES);
strategy.setTablePrefix(TABLE_PREFIX);
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setControllerMappingHyphenStyle(true);
strategy.setLogicDeleteFieldName("deleted");
mpg.setStrategy(strategy);
// 模板配置
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
templateConfig.setService(TEMPLATES_DIR + "/service.java");
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
// 自定义模板配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("packageName", PACKAGE_NAME);
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
map.put("paramEqType", PARAM_EQ_TYPE);
map.put("authAnnotation", AUTH_ANNOTATION);
map.put("logAnnotation", LOG_ANNOTATION);
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
this.setMap(map);
}
};
String templatePath = TEMPLATES_DIR + "/param.java.btl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
+ PACKAGE_NAME.replace(".", "/")
+ "/" + pc.getModuleName() + "/param/"
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.execute();
}
}

View File

@@ -0,0 +1,50 @@
package com.gxwebsoft.generator.engine;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.FileResourceLoader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
/**
* Beetl模板引擎实现文件输出
*
* @author WebSoft
* @since 2021-09-05 00:30:28
*/
public class BeetlTemplateEnginePlus extends AbstractTemplateEngine {
private GroupTemplate groupTemplate;
@Override
public AbstractTemplateEngine init(ConfigBuilder configBuilder) {
super.init(configBuilder);
try {
Configuration cfg = Configuration.defaultConfiguration();
groupTemplate = new GroupTemplate(new FileResourceLoader(), cfg);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return this;
}
@Override
public void writer(Map<String, Object> objectMap, String templatePath, String outputFile) throws Exception {
Template template = groupTemplate.getTemplate(templatePath);
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
template.binding(objectMap);
template.renderTo(fileOutputStream);
}
logger.debug("模板:" + templatePath + "; 文件:" + outputFile);
}
@Override
public String templateFilePath(String filePath) {
return filePath + ".btl";
}
}

View File

@@ -0,0 +1,283 @@
<%
var serviceIns = strutil.toLowerCase(strutil.subStringTo(table.serviceName, 0, 1)) + strutil.subString(table.serviceName, 1);
var authPre = package.ModuleName + ':' + table.entityPath;
var idFieldName, idPropertyName;
for(field in table.fields) {
if(field.keyFlag) {
idFieldName = field.name;
idPropertyName = field.propertyName;
}
}
%>
package ${package.Controller};
<% if(isNotEmpty(superControllerClassPackage)) { %>
import ${superControllerClassPackage};
<% } %>
import ${cfg.packageName!}.${package.ModuleName}.service.${entity}Service;
import ${cfg.packageName!}.${package.ModuleName}.entity.${entity};
import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param;
import ${cfg.packageName!}.common.core.web.ApiResult;
import ${cfg.packageName!}.common.core.web.PageResult;
import ${cfg.packageName!}.common.core.web.PageParam;
import ${cfg.packageName!}.common.core.web.BatchParam;
import ${cfg.packageName!}.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
<% if(!restControllerStyle) { %>
import org.springframework.stereotype.Controller;
<% } %>
import javax.annotation.Resource;
import java.util.List;
/**
* ${table.comment!}控制器
*
* @author ${author}
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
*/
<% if(swagger2) { %>
@Api(tags = "${table.comment!}管理")
<% } %>
<% if(restControllerStyle) { %>
@RestController
<% } else { %>
@Controller
<% } %>
@RequestMapping("${cfg.controllerMappingPrefix!}<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>")
<% if(kotlin) { %>
class ${table.controllerName}<% if(isNotEmpty(superControllerClass)) { %> : ${superControllerClass}()<% } %>
<% } else if(isNotEmpty(superControllerClass)) { %>
public class ${table.controllerName} extends ${superControllerClass} {
<% } else { %>
public class ${table.controllerName} {
<% } %>
@Resource
private ${table.serviceName} ${serviceIns};
<% if(!swagger2) { %>
/**
* 分页查询${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:list')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("分页查询${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@GetMapping("/page")
public ApiResult<PageResult<${entity}>> page(${entity}Param param) {
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(${serviceIns}.page(page, page.getWrapper()));
// 使用关联查询
//return success(${serviceIns}.pageRel(param));
}
<% if(!swagger2) { %>
/**
* 查询全部${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:list')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("查询全部${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@GetMapping()
public ApiResult<List<${entity}>> list(${entity}Param param) {
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(${serviceIns}.list(page.getOrderWrapper()));
// 使用关联查询
//return success(${serviceIns}.listRel(param));
}
<% if(!swagger2) { %>
/**
* 根据id查询${table.comment!}
*/
<% } %>
@PreAuthorize("hasAuthority('${authPre}:list')")
@OperationLog
@ApiOperation("根据id查询${table.comment!}")
@GetMapping("/{id}")
public ApiResult<${entity}> get(@PathVariable("id") Integer id) {
return success(${serviceIns}.getById(id));
// 使用关联查询
//return success(${serviceIns}.getByIdRel(id));
}
<% if(!swagger2) { %>
/**
* 添加${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:save')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("添加${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@PostMapping()
public ApiResult<?> save(@RequestBody ${entity} ${table.entityPath}) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
${table.entityPath}.setUserId(loginUser.getUserId());
}
if (${serviceIns}.save(${table.entityPath})) {
return success("添加成功");
}
return fail("添加失败");
}
<% if(!swagger2) { %>
/**
* 修改${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:update')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("修改${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@PutMapping()
public ApiResult<?> update(@RequestBody ${entity} ${table.entityPath}) {
if (${serviceIns}.updateById(${table.entityPath})) {
return success("修改成功");
}
return fail("修改失败");
}
<% if(!swagger2) { %>
/**
* 删除${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:remove')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("删除${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (${serviceIns}.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
<% if(!swagger2) { %>
/**
* 批量添加${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:save')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("批量添加${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<${entity}> list) {
if (${serviceIns}.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
<% if(!swagger2) { %>
/**
* 批量修改${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:update')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("批量修改${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<${entity}> batchParam) {
if (batchParam.update(${serviceIns}, "${idFieldName!}")) {
return success("修改成功");
}
return fail("修改失败");
}
<% if(!swagger2) { %>
/**
* 批量删除${table.comment!}
*/
<% } %>
<% if(cfg.authAnnotation) { %>
@PreAuthorize("hasAuthority('${authPre}:remove')")
<% } %>
<% if(cfg.logAnnotation) { %>
@OperationLog
<% } %>
<% if(swagger2) { %>
@ApiOperation("批量删除${table.comment!}")
<% } %>
<% if(!restControllerStyle) { %>
@ResponseBody
<% } %>
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (${serviceIns}.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -0,0 +1,158 @@
package ${package.Entity};
<% for(pkg in table.importPackages) { %>
import ${pkg};
<% } %>
<% if(swagger2) { %>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
<% } %>
<% if(entityLombokModel) { %>
import lombok.Data;
import lombok.EqualsAndHashCode;
<% if(chainModel) { %>
import lombok.experimental.Accessors;
<% } %>
<% } %>
/**
* ${table.comment!}
*
* @author ${author}
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
*/
<% if(entityLombokModel) { %>
@Data
<% if(isNotEmpty(superEntityClass)) { %>
@EqualsAndHashCode(callSuper = true)
<% } else { %>
@EqualsAndHashCode(callSuper = false)
<% } %>
<% if(chainModel) { %>
@Accessors(chain = true)
<% } %>
<% } %>
<% if(swagger2) { %>
@ApiModel(value = "${entity}对象", description = "${table.comment!''}")
<% } %>
<% if(table.convert) { %>
@TableName("${table.name}")
<% } %>
<% if(isNotEmpty(superEntityClass)) { %>
public class ${entity} extends ${superEntityClass}<% if(activeRecord) { %><${entity}><% } %>{
<% } else if(activeRecord) { %>
public class ${entity} extends Model<${entity}> {
<% } else { %>
public class ${entity} implements Serializable {
<% } %>
<% if(entitySerialVersionUID) { %>
private static final long serialVersionUID = 1L;
<% } %>
<% /** -----------BEGIN 字段循环遍历----------- **/ %>
<% for(field in table.fields) { %>
<%
var keyPropertyName;
if(field.keyFlag) {
keyPropertyName = field.propertyName;
}
%>
<% if(isNotEmpty(field.comment)) { %>
<% if(swagger2) { %>
@ApiModelProperty(value = "${field.comment}")
<% }else{ %>
/**
* ${field.comment}
*/
<% } %>
<% } %>
<% /* 主键 */ %>
<% if(field.keyFlag) { %>
<% if(field.keyIdentityFlag) { %>
@TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
<% } else if(isNotEmpty(idType)) { %>
@TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
<% } else if(field.convert) { %>
@TableId("${field.annotationColumnName}")
<% } %>
<% /* 普通字段 */ %>
<% } else if(isNotEmpty(field.fill)) { %>
<% if(field.convert){ %>
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
<% }else{ %>
@TableField(fill = FieldFill.${field.fill})
<% } %>
<% } else if(field.convert) { %>
@TableField("${field.annotationColumnName}")
<% } %>
<% /* 乐观锁注解 */ %>
<% if(versionFieldName!'' == field.name) { %>
@Version
<% } %>
<% /* 逻辑删除注解 */ %>
<% if(logicDeleteFieldName!'' == field.name) { %>
@TableLogic
<% } %>
private ${field.propertyType} ${field.propertyName};
<% } %>
<% /** -----------END 字段循环遍历----------- **/ %>
<% if(!entityLombokModel) { %>
<% for(field in table.fields) { %>
<%
var getprefix = '';
if(field.propertyType == 'boolean') {
getprefix = 'is';
} else {
getprefix = 'get';
}
%>
public ${field.propertyType} ${getprefix}${field.capitalName}() {
return ${field.propertyName};
}
<% if(chainModel) { %>
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<% } else { %>
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<% } %>
this.${field.propertyName} = ${field.propertyName};
<% if(chainModel){ %>
return this;
<% } %>
}
<% } %>
<% } %>
<% if(entityColumnConstant) { %>
<% for(field in table.fields) { %>
public static final String ${strutil.toUpperCase(field.name)} = "${field.name}";
<% } %>
<% } %>
<% if(activeRecord) { %>
@Override
protected Serializable pkVal() {
<% if(isNotEmpty(keyPropertyName)){ %>
return this.${keyPropertyName};
<% }else{ %>
return null;
<% } %>
}
<% } %>
<% if(!entityLombokModel){ %>
@Override
public String toString() {
return "${entity}{" +
<% for(field in table.fields){ %>
<% if(fieldLP.index==0){ %>
"${field.propertyName}=" + ${field.propertyName} +
<% }else{ %>
", ${field.propertyName}=" + ${field.propertyName} +
<% } %>
<% } %>
"}";
}
<% } %>
}

View File

@@ -0,0 +1,41 @@
package ${package.Mapper};
import ${superMapperClassPackage};
import com.baomidou.mybatisplus.core.metadata.IPage;
import ${package.Entity}.${entity};
import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* ${table.comment!}Mapper
*
* @author ${author}
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
*/
<% if(kotlin){ %>
interface ${table.mapperName} : ${superMapperClass}<${entity}>
<% }else{ %>
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<${entity}>
*/
List<${entity}> selectPageRel(@Param("page") IPage<${entity}> page,
@Param("param") ${entity}Param param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<${entity}> selectListRel(@Param("param") ${entity}Param param);
}
<% } %>

View File

@@ -0,0 +1,96 @@
<?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.Mapper}.${table.mapperName}">
<% if(enableCache) { %>
<!-- 开启二级缓存 -->
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
<% } %>
<% if(baseResultMap) { %>
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
<% /** 生成主键排在第一位 **/ %>
<% for(field in table.fields) { %>
<% if(field.keyFlag){ %>
<id column="${field.name}" property="${field.propertyName}" />
<% } %>
<% } %>
<% /** 生成公共字段 **/ %>
<% for(field in table.commonFields) { %>
<result column="${field.name}" property="${field.propertyName}" />
<% } %>
<% /** 生成普通字段 **/ %>
<% for(field in table.fields) { %>
<% if(!field.keyFlag) { %>
<result column="${field.name}" property="${field.propertyName}" />
<% } %>
<% } %>
</resultMap>
<% } %>
<% if(baseColumnList) { %>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
<% for(field in table.commonFields) { %>
${field.columnName},
<% } %>
${table.fieldNames}
</sql>
<% } %>
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM ${table.name} a
<where>
<% for(field in table.fields) { %>
<% if(field.keyFlag) { %>
<% /** 主键字段 **/ %>
<if test="param.${field.propertyName} != null">
AND a.${field.name} = #{param.${field.propertyName}}
</if>
<% } else if(field.name == logicDeleteFieldName) { %>
<% /** 逻辑删除字段 **/ %>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
</if>
<% } else if(field.name == 'create_time') { %>
<% /** 创建时间字段 **/ %>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<% } else if(array.contain(cfg.paramExcludeFields, field.name)) { %>
<% /** 排除的字段 **/ %>
<% } else if(array.contain(cfg.paramEqType, field.propertyType)) { %>
<% /** 使用EQ的字段 **/ %>
<if test="param.${field.propertyName} != null">
AND a.${field.name} = #{param.${field.propertyName}}
</if>
<% } else { %>
<% /** 其它类型使用LIKE **/ %>
<if test="param.${field.propertyName} != null">
AND a.${field.name} LIKE CONCAT('%', #{param.${field.propertyName}}, '%')
</if>
<% } %>
<% } %>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="${package.Entity}.${entity}">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="${package.Entity}.${entity}">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -0,0 +1,146 @@
package ${cfg.packageName!}.${package.ModuleName}.param;
import ${cfg.packageName!}.common.core.annotation.QueryField;
import ${cfg.packageName!}.common.core.annotation.QueryType;
import ${cfg.packageName!}.common.core.web.BaseParam;
import com.fasterxml.jackson.annotation.JsonInclude;
<% if(swagger2) { %>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
<% } %>
<% if(entityLombokModel) { %>
import lombok.Data;
import lombok.EqualsAndHashCode;
<% if(chainModel) { %>
import lombok.experimental.Accessors;
<% } %>
<% } %>
/**
* ${table.comment!}查询参数
*
* @author ${author}
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
*/
<% if(entityLombokModel) { %>
@Data
<% if(isNotEmpty(superEntityClass)) { %>
@EqualsAndHashCode(callSuper = true)
<% } else { %>
@EqualsAndHashCode(callSuper = false)
<% } %>
<% if(chainModel) { %>
@Accessors(chain = true)
<% } %>
<% } %>
@JsonInclude(JsonInclude.Include.NON_NULL)
<% if(swagger2) { %>
@ApiModel(value = "${entity}Param对象", description = "${table.comment!''}查询参数")
<% } %>
public class ${entity}Param extends BaseParam {
<% if(entitySerialVersionUID) { %>
private static final long serialVersionUID = 1L;
<% } %>
<% /** -----------BEGIN 字段循环遍历----------- **/ %>
<% for(field in table.fields) { %>
<%
var keyPropertyName;
if(field.keyFlag) {
keyPropertyName = field.propertyName;
}
// 排除的字段
if(array.contain(cfg.paramExcludeFields, field.name)) {
continue;
}
%>
<% if(isNotEmpty(field.comment)) { %>
<% if(swagger2) { %>
@ApiModelProperty(value = "${field.comment}")
<% }else{ %>
/**
* ${field.comment}
*/
<% } %>
<% } %>
<% /* 主键 */ %>
<% if(field.keyFlag) { %>
@QueryField(type = QueryType.EQ)
<% /* 使用EQ的字段 */ %>
<% } else if(array.contain(cfg.paramEqType, field.propertyType)) { %>
@QueryField(type = QueryType.EQ)
<% } %>
<% /* 使用String类型的字段 */ %>
<% if(array.contain(cfg.paramToStringType, field.propertyType)) { %>
private String ${field.propertyName};
<% } else { %>
<% /* 普通字段 */ %>
private ${field.propertyType} ${field.propertyName};
<% } %>
<% } %>
<% /** -----------END 字段循环遍历----------- **/ %>
<% if(!entityLombokModel) { %>
<% for(field in table.fields) { %>
<%
var getprefix = '';
if(field.propertyType == 'boolean') {
getprefix = 'is';
} else {
getprefix = 'get';
}
// 排除的字段
if(array.contain(cfg.paramExcludeFields, field.name)) {
continue;
}
%>
<% if(array.contain(cfg.paramToStringType, field.propertyType)) { %>
public String ${getprefix}${field.capitalName}() {
<% } else { %>
public ${field.propertyType} ${getprefix}${field.capitalName}() {
<% } %>
return ${field.propertyName};
}
<% if(chainModel) { %>
<% if(array.contain(cfg.paramToStringType, field.propertyType)) { %>
public ${entity} set${field.capitalName}(String ${field.propertyName}) {
<% } else { %>
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<% } %>
<% } else { %>
<% if(array.contain(cfg.paramToStringType, field.propertyType)) { %>
public void set${field.capitalName}(String ${field.propertyName}) {
<% } else { %>
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
<% } %>
<% } %>
this.${field.propertyName} = ${field.propertyName};
<% if(chainModel){ %>
return this;
<% } %>
}
<% } %>
<% } %>
<% if(!entityLombokModel) { %>
@Override
public String toString() {
return "${entity}{" +
<% for(field in table.fields) { %>
<%
// 排除的字段
if(array.contain(cfg.paramExcludeFields, field.name)) {
continue;
}
%>
<% if(fieldLP.index == 0) { %>
"${field.propertyName}=" + ${field.propertyName} +
<% } else { %>
", ${field.propertyName}=" + ${field.propertyName} +
<% } %>
<% } %>
"}";
}
<% } %>
}

View File

@@ -0,0 +1,55 @@
<%
var idPropertyName, idComment;
for(field in table.fields) {
if(field.keyFlag) {
idPropertyName = field.propertyName;
idComment = field.comment;
}
}
%>
package ${package.Service};
import ${superServiceClassPackage};
import ${cfg.packageName!}.common.core.web.PageResult;
import ${package.Entity}.${entity};
import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param;
import java.util.List;
/**
* ${table.comment!}Service
*
* @author ${author}
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
*/
<% if(kotlin){ %>
interface ${table.serviceName} : ${superServiceClass}<${entity}>
<% }else{ %>
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<${entity}>
*/
PageResult<${entity}> pageRel(${entity}Param param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<${entity}>
*/
List<${entity}> listRel(${entity}Param param);
/**
* 根据id查询
*
* @param ${idPropertyName!} ${idComment!}
* @return ${entity}
*/
${entity} getByIdRel(Integer ${idPropertyName!});
}
<% } %>

View File

@@ -0,0 +1,62 @@
<%
var idPropertyName, idCapitalName;
for(field in table.fields) {
if(field.keyFlag) {
idPropertyName = field.propertyName;
idCapitalName = field.capitalName;
}
}
%>
package ${package.ServiceImpl};
import ${superServiceImplClassPackage};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param;
import ${cfg.packageName!}.common.core.web.PageParam;
import ${cfg.packageName!}.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* ${table.comment!}Service实现
*
* @author ${author}
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
*/
@Service
<% if(kotlin){ %>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
}
<% }else{ %>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
@Override
public PageResult<${entity}> pageRel(${entity}Param param) {
PageParam<${entity}, ${entity}Param> page = new PageParam<>(param);
//page.setDefaultOrder("create_time desc");
List<${entity}> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<${entity}> listRel(${entity}Param param) {
List<${entity}> list = baseMapper.selectListRel(param);
// 排序
PageParam<${entity}, ${entity}Param> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public ${entity} getByIdRel(Integer ${idPropertyName!}) {
${entity}Param param = new ${entity}Param();
param.set${idCapitalName!}(${idPropertyName!});
return param.getOne(baseMapper.selectListRel(param));
}
}
<% } %>