修复代码生成器
This commit is contained in:
@@ -27,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/shop";
|
||||
private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/mp-vue";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_LOCATION_UNIAPP = "/Users/gxwebsoft/APP/shop";
|
||||
private static final String OUTPUT_LOCATION_UNIAPP = "/Users/gxwebsoft/VUE/template-10550";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_DIR_VUE = "/src";
|
||||
// 作者名称
|
||||
@@ -37,7 +37,7 @@ public class ShopGenerator {
|
||||
// 是否在xml中添加二级缓存配置
|
||||
private static final boolean ENABLE_CACHE = false;
|
||||
// 数据库连接配置
|
||||
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_URL = "jdbc:mysql://8.134.169.209:13306/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";
|
||||
@@ -55,7 +55,7 @@ public class ShopGenerator {
|
||||
// "shop_goods_sku",
|
||||
// "shop_goods_category",
|
||||
"shop_coupon",
|
||||
// "shop_goods_coupon",
|
||||
"shop_goods_coupon",
|
||||
// "shop_goods_description",
|
||||
// "shop_goods_log",
|
||||
// "shop_goods_relation",
|
||||
|
||||
@@ -23,8 +23,8 @@ import ${cfg.packageName!}.common.core.web.PageParam;
|
||||
import ${cfg.packageName!}.common.core.web.BatchParam;
|
||||
import ${cfg.packageName!}.common.core.annotation.OperationLog;
|
||||
import ${cfg.packageName!}.common.system.entity.User;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
<% if(!restControllerStyle) { %>
|
||||
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
* @since ${date(), 'yyyy-MM-dd HH:mm:ss'}
|
||||
*/
|
||||
<% if(swagger2) { %>
|
||||
@Api(tags = "${table.comment!}管理")
|
||||
@Tag(name = "${table.comment!}管理")
|
||||
<% } %>
|
||||
<% if(restControllerStyle) { %>
|
||||
@RestController
|
||||
@@ -68,7 +68,7 @@ public class ${table.controllerName} {
|
||||
@PreAuthorize("hasAuthority('${authPre}:list')")
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("分页查询${table.comment!}")
|
||||
@Operation(summary = "分页查询${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -88,7 +88,7 @@ public class ${table.controllerName} {
|
||||
@PreAuthorize("hasAuthority('${authPre}:list')")
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("查询全部${table.comment!}")
|
||||
@Operation(summary = "查询全部${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -105,7 +105,7 @@ public class ${table.controllerName} {
|
||||
*/
|
||||
<% } %>
|
||||
@PreAuthorize("hasAuthority('${authPre}:list')")
|
||||
@ApiOperation("根据id查询${table.comment!}")
|
||||
@Operation(summary = "根据id查询${table.comment!}")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<${entity}> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
@@ -124,7 +124,7 @@ public class ${table.controllerName} {
|
||||
@OperationLog
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("添加${table.comment!}")
|
||||
@Operation(summary = "添加${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -154,7 +154,7 @@ public class ${table.controllerName} {
|
||||
@OperationLog
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("修改${table.comment!}")
|
||||
@Operation(summary = "修改${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -179,7 +179,7 @@ public class ${table.controllerName} {
|
||||
@OperationLog
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("删除${table.comment!}")
|
||||
@Operation(summary = "删除${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -204,7 +204,7 @@ public class ${table.controllerName} {
|
||||
@OperationLog
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("批量添加${table.comment!}")
|
||||
@Operation(summary = "批量添加${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -229,7 +229,7 @@ public class ${table.controllerName} {
|
||||
@OperationLog
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("批量修改${table.comment!}")
|
||||
@Operation(summary = "批量修改${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
@@ -254,7 +254,7 @@ public class ${table.controllerName} {
|
||||
@OperationLog
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiOperation("批量删除${table.comment!}")
|
||||
@Operation(summary = "批量删除${table.comment!}")
|
||||
<% } %>
|
||||
<% if(!restControllerStyle) { %>
|
||||
@ResponseBody
|
||||
|
||||
@@ -4,8 +4,7 @@ package ${package.Entity};
|
||||
import ${pkg};
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
<% } %>
|
||||
<% if(entityLombokModel) { %>
|
||||
import lombok.Data;
|
||||
@@ -33,7 +32,7 @@ import lombok.experimental.Accessors;
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiModel(value = "${entity}对象", description = "${table.comment!''}")
|
||||
@Schema(name = "${entity}对象", description = "${table.comment!''}")
|
||||
<% } %>
|
||||
<% if(table.convert) { %>
|
||||
@TableName("${table.name}")
|
||||
@@ -59,7 +58,7 @@ public class ${entity} implements Serializable {
|
||||
|
||||
<% if(isNotEmpty(field.comment)) { %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
@Schema(description = "${field.comment}")
|
||||
<% }else{ %>
|
||||
/**
|
||||
* ${field.comment}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult, PageResult } from '@/api';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ${entity}, ${entity}Param } from './model';
|
||||
import { MODULES_API_URL } from '@/config/setting';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { PageParam } from '@/api';
|
||||
import type { PageParam } from '@/api/index';
|
||||
|
||||
/**
|
||||
* ${table.comment!}
|
||||
|
||||
@@ -6,8 +6,7 @@ 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;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
<% } %>
|
||||
<% if(entityLombokModel) { %>
|
||||
import lombok.Data;
|
||||
@@ -36,7 +35,7 @@ import lombok.experimental.Accessors;
|
||||
<% } %>
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
<% if(swagger2) { %>
|
||||
@ApiModel(value = "${entity}Param对象", description = "${table.comment!''}查询参数")
|
||||
@Schema(name = "${entity}Param对象", description = "${table.comment!''}查询参数")
|
||||
<% } %>
|
||||
public class ${entity}Param extends BaseParam {
|
||||
<% if(entitySerialVersionUID) { %>
|
||||
@@ -57,7 +56,7 @@ public class ${entity}Param extends BaseParam {
|
||||
|
||||
<% if(isNotEmpty(field.comment)) { %>
|
||||
<% if(swagger2) { %>
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
@Schema(description = "${field.comment}")
|
||||
<% }else{ %>
|
||||
/**
|
||||
* ${field.comment}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
package com.gxwebsoft.shop.service;
|
||||
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.dto.OrderCreateRequest;
|
||||
import com.gxwebsoft.shop.entity.ShopGoods;
|
||||
import com.gxwebsoft.shop.entity.ShopOrder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* 订单业务服务测试类
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OrderBusinessServiceTest {
|
||||
|
||||
@Mock
|
||||
private ShopOrderService shopOrderService;
|
||||
|
||||
@Mock
|
||||
private ShopGoodsService shopGoodsService;
|
||||
|
||||
@InjectMocks
|
||||
private OrderBusinessService orderBusinessService;
|
||||
|
||||
private User testUser;
|
||||
private ShopGoods testGoods;
|
||||
private OrderCreateRequest testRequest;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// 准备测试用户
|
||||
testUser = new User();
|
||||
testUser.setUserId(1);
|
||||
testUser.setOpenid("test_openid");
|
||||
testUser.setPhone("13800138000");
|
||||
|
||||
// 准备测试商品
|
||||
testGoods = new ShopGoods();
|
||||
testGoods.setGoodsId(10021);
|
||||
testGoods.setName("扎尔伯特五谷礼盒");
|
||||
testGoods.setPrice(new BigDecimal("99.00"));
|
||||
testGoods.setStock(100);
|
||||
testGoods.setStatus(0);
|
||||
testGoods.setIsShow(true);
|
||||
testGoods.setDeleted(0);
|
||||
|
||||
// 准备测试请求(模拟前端发送的数据格式)
|
||||
testRequest = new OrderCreateRequest();
|
||||
testRequest.setGoodsId(10021); // 使用goodsId字段
|
||||
testRequest.setQuantity(1); // 使用quantity字段
|
||||
testRequest.setTotalPrice(new BigDecimal("99.00"));
|
||||
testRequest.setTenantId(10832);
|
||||
testRequest.setPayType(1);
|
||||
testRequest.setComments("扎尔伯特五谷礼盒");
|
||||
testRequest.setDeliveryType(0);
|
||||
testRequest.setType(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateOrder_Success() {
|
||||
// 模拟商品查询
|
||||
when(shopGoodsService.getById(10021)).thenReturn(testGoods);
|
||||
|
||||
// 模拟订单保存
|
||||
when(shopOrderService.save(any(ShopOrder.class))).thenReturn(true);
|
||||
|
||||
// 模拟微信支付订单创建
|
||||
Map<String, String> wxOrderInfo = new HashMap<>();
|
||||
wxOrderInfo.put("prepay_id", "test_prepay_id");
|
||||
when(shopOrderService.createWxOrder(any(ShopOrder.class))).thenReturn((HashMap<String, String>) wxOrderInfo);
|
||||
|
||||
// 执行测试
|
||||
Map<String, String> result = orderBusinessService.createOrder(testRequest, testUser);
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals("test_prepay_id", result.get("prepay_id"));
|
||||
|
||||
// 验证方法调用
|
||||
verify(shopGoodsService).getById(10021);
|
||||
verify(shopOrderService).save(any(ShopOrder.class));
|
||||
verify(shopOrderService).createWxOrder(any(ShopOrder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateOrder_GoodsNotFound() {
|
||||
// 模拟商品不存在
|
||||
when(shopGoodsService.getById(10021)).thenReturn(null);
|
||||
|
||||
// 执行测试并验证异常
|
||||
Exception exception = assertThrows(Exception.class, () -> {
|
||||
orderBusinessService.createOrder(testRequest, testUser);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("商品不存在"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateOrder_InsufficientStock() {
|
||||
// 设置库存不足
|
||||
testGoods.setStock(0);
|
||||
testRequest.setQuantity(1);
|
||||
|
||||
when(shopGoodsService.getById(10021)).thenReturn(testGoods);
|
||||
|
||||
// 执行测试并验证异常
|
||||
Exception exception = assertThrows(Exception.class, () -> {
|
||||
orderBusinessService.createOrder(testRequest, testUser);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("商品库存不足"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateOrder_PriceValidation() {
|
||||
// 设置错误的价格
|
||||
testRequest.setTotalPrice(new BigDecimal("50.00")); // 商品价格是99.00,但请求价格是50.00
|
||||
|
||||
when(shopGoodsService.getById(10021)).thenReturn(testGoods);
|
||||
|
||||
// 执行测试并验证异常
|
||||
Exception exception = assertThrows(Exception.class, () -> {
|
||||
orderBusinessService.createOrder(testRequest, testUser);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("商品价格异常"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateOrder_CompatibilityFields() {
|
||||
// 测试兼容性字段
|
||||
OrderCreateRequest compatRequest = new OrderCreateRequest();
|
||||
compatRequest.setFormId(10021); // 使用formId字段
|
||||
compatRequest.setTotalNum(1); // 使用totalNum字段
|
||||
compatRequest.setTotalPrice(new BigDecimal("99.00"));
|
||||
compatRequest.setTenantId(10832);
|
||||
compatRequest.setPayType(1);
|
||||
compatRequest.setType(0);
|
||||
|
||||
when(shopGoodsService.getById(10021)).thenReturn(testGoods);
|
||||
when(shopOrderService.save(any(ShopOrder.class))).thenReturn(true);
|
||||
|
||||
Map<String, String> wxOrderInfo = new HashMap<>();
|
||||
wxOrderInfo.put("prepay_id", "test_prepay_id");
|
||||
when(shopOrderService.createWxOrder(any(ShopOrder.class))).thenReturn((HashMap<String, String>) wxOrderInfo);
|
||||
|
||||
// 执行测试
|
||||
Map<String, String> result = orderBusinessService.createOrder(compatRequest, testUser);
|
||||
|
||||
// 验证结果
|
||||
assertNotNull(result);
|
||||
assertEquals("test_prepay_id", result.get("prepay_id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetActualFormId() {
|
||||
// 测试goodsId字段
|
||||
OrderCreateRequest request1 = new OrderCreateRequest();
|
||||
request1.setGoodsId(123);
|
||||
assertEquals(123, request1.getActualFormId());
|
||||
|
||||
// 测试formId字段优先级
|
||||
OrderCreateRequest request2 = new OrderCreateRequest();
|
||||
request2.setFormId(456);
|
||||
request2.setGoodsId(123);
|
||||
assertEquals(456, request2.getActualFormId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetActualTotalNum() {
|
||||
// 测试quantity字段
|
||||
OrderCreateRequest request1 = new OrderCreateRequest();
|
||||
request1.setQuantity(5);
|
||||
assertEquals(5, request1.getActualTotalNum());
|
||||
|
||||
// 测试totalNum字段优先级
|
||||
OrderCreateRequest request2 = new OrderCreateRequest();
|
||||
request2.setTotalNum(10);
|
||||
request2.setQuantity(5);
|
||||
assertEquals(10, request2.getActualTotalNum());
|
||||
|
||||
// 测试默认值
|
||||
OrderCreateRequest request3 = new OrderCreateRequest();
|
||||
assertEquals(1, request3.getActualTotalNum());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user