修复下单接口
This commit is contained in:
@@ -39,7 +39,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -107,11 +106,6 @@ public class ShopOrderController extends BaseController {
|
||||
}
|
||||
|
||||
try {
|
||||
// 记录请求信息用于调试
|
||||
logger.info("收到下单请求 - 用户ID:{},商品ID:{},数量:{},总价:{},租户ID:{}",
|
||||
loginUser.getUserId(), request.getActualFormId(), request.getActualTotalNum(),
|
||||
request.getTotalPrice(), request.getTenantId());
|
||||
|
||||
Map<String, String> wxOrderInfo = orderBusinessService.createOrder(request, loginUser);
|
||||
return success("下单成功", wxOrderInfo);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.gxwebsoft.generator;
|
||||
|
||||
/**
|
||||
* ShopGenerator - 商城模块代码生成器
|
||||
*
|
||||
* 注意:由于MyBatis-Plus Generator版本兼容性问题,
|
||||
* 当前版本的API可能不兼容,建议手动创建代码文件
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* CMS模块-代码生成工具
|
||||
@@ -20,9 +27,9 @@ public class ShopGenerator {
|
||||
// 输出目录
|
||||
private static final String OUTPUT_DIR = "/src/main/java";
|
||||
// Vue文件输出位置
|
||||
private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/mp-vue";
|
||||
private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/shop";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_LOCATION_UNIAPP = "/Users/gxwebsoft/VUE/template-10550";
|
||||
private static final String OUTPUT_LOCATION_UNIAPP = "/Users/gxwebsoft/APP/shop";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_DIR_VUE = "/src";
|
||||
// 作者名称
|
||||
@@ -30,7 +37,7 @@ public class ShopGenerator {
|
||||
// 是否在xml中添加二级缓存配置
|
||||
private static final boolean ENABLE_CACHE = false;
|
||||
// 数据库连接配置
|
||||
private static final String DB_URL = "jdbc:mysql://1Panel-mysql-Bqdt:3306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
||||
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/modules?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 = "modules";
|
||||
private static final String DB_PASSWORD = "8YdLnk7KsPAyDXGA";
|
||||
@@ -47,6 +54,7 @@ public class ShopGenerator {
|
||||
// "shop_goods_spec",
|
||||
// "shop_goods_sku",
|
||||
// "shop_goods_category",
|
||||
"shop_coupon",
|
||||
// "shop_goods_coupon",
|
||||
// "shop_goods_description",
|
||||
// "shop_goods_log",
|
||||
@@ -126,22 +134,163 @@ public class ShopGenerator {
|
||||
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("=== 商城模块 MyBatis-Plus 代码生成器 ===");
|
||||
System.out.println("输出目录: " + OUTPUT_LOCATION + OUTPUT_DIR);
|
||||
System.out.println("包名: " + PACKAGE_NAME + "." + MODULE_NAME);
|
||||
System.out.println("表名: " + String.join(", ", TABLE_NAMES));
|
||||
System.out.println("数据库: " + DB_URL);
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
try {
|
||||
// 注意:由于MyBatis-Plus Generator版本兼容性问题,
|
||||
// 当前版本的API可能不兼容,建议手动创建代码文件
|
||||
System.out.println("请参考项目中现有的商城模块代码结构");
|
||||
System.out.println("或者手动创建Entity、Mapper、Service、Controller类");
|
||||
// 全局配置
|
||||
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);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("代码生成失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 数据源配置
|
||||
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;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 以下是生成VUE项目代码
|
||||
* 生成文件的路径 /api/shop/goods/index.ts
|
||||
*/
|
||||
templatePath = TEMPLATES_DIR + "/index.ts.btl";
|
||||
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.ts";
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig() {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_UNIAPP + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成TS文件 (/api/shop/goods/model/index.ts)
|
||||
templatePath = TEMPLATES_DIR + "/model.ts.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||
}
|
||||
});
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_UNIAPP + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成Vue文件(/views/shop/goods/index.vue)
|
||||
templatePath = TEMPLATES_DIR + "/index.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/edit.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.edit.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/search.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.search.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + "search.vue";
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user