From 2038d76b1e323fe3cabf9258f6e44b055e369ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Tue, 25 Apr 2023 04:33:38 +0800 Subject: [PATCH] =?UTF-8?q?bugfix=20=E4=BF=AE=E5=A4=8D=E8=8B=A5=E5=B9=B2?= =?UTF-8?q?=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86Bug=EF=BC=9B=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E4=B8=8D?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=B8=8B=E6=9E=B6=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epp/PageTable/enums/AddType.java | 1 + .../epp/PageTable/enums/EditType.java | 1 + .../epp/PageTable/utils/FieldRuleBuilder.java | 34 +++++++++++++--- .../epp/shop/controller/GoodController.java | 39 +++++++++++++------ .../com/cxyxiaomo/epp/shop/dao/GoodDao.java | 2 + .../epp/shop/service/GoodService.java | 7 ++++ .../resources/mybatis/mapper/GoodMapper.xml | 12 ++++++ frontend/src/components/manage-list.vue | 15 ++++--- 8 files changed, 90 insertions(+), 21 deletions(-) diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/AddType.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/AddType.java index 4ab0af7..b488d09 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/AddType.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/AddType.java @@ -3,6 +3,7 @@ package com.cxyxiaomo.epp.PageTable.enums; public enum AddType { CAN_NOT_ADD("plainText"), INPUT("input"), + INPUT_NUMBER("input-number"), TEXTAREA("textarea"), SELECT("select"), IMAGE("image"); diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/EditType.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/EditType.java index 9f608e7..76f714d 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/EditType.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/enums/EditType.java @@ -3,6 +3,7 @@ package com.cxyxiaomo.epp.PageTable.enums; public enum EditType { CAN_NOT_EDIT("plainText"), INPUT("input"), + INPUT_NUMBER("input-number"), TEXTAREA("textarea"), SELECT("select"), IMAGE("image"); diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldRuleBuilder.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldRuleBuilder.java index f9480a1..9afe956 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldRuleBuilder.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldRuleBuilder.java @@ -43,11 +43,12 @@ public class FieldRuleBuilder { return this; } - public FieldRuleBuilder number() { - rules.put("type", "number"); - rules.put("message", fieldDisplayName + "必须为数字"); - return this; - } + // public FieldRuleBuilder number() { + // // rules.put("type", "number"); // 字符串类型的数字匹配不上 + // rules.put("regexp", "^\\d+?$"); + // rules.put("message", fieldDisplayName + "必须为数字"); + // return this; + // } public FieldRuleBuilder min(Integer min) { rules.put("min", min); @@ -61,6 +62,7 @@ public class FieldRuleBuilder { return this; } + // 字符串类型长度范围 public FieldRuleBuilder minMax(Integer min, Integer max) { rules.put("min", min); rules.put("max", max); @@ -68,6 +70,28 @@ public class FieldRuleBuilder { return this; } + // 数字类型数值范围 + // public FieldRuleBuilder range(Integer min, Integer max) { + // // rules.put("min", min); + // // rules.put("max", max); + // rules.put("message", fieldDisplayName + "应大于 " + min + " 且小于 " + max); + // return this; + // } + + // // 数字类型数字个数 + // public FieldRuleBuilder price(Integer minLen, Integer maxLen) { + // rules.put("regexp", "^\\d{" + minLen + "," + maxLen + "}(\\.\\d{1,2})?$"); + // rules.put("message", fieldDisplayName + "应大于等于 " + Math.pow(10, minLen - 1) + " ,小于等于 " + (Math.pow(10, maxLen) - 1) + " 且小数位数不超过 2 位"); + // return this; + // } + + // public FieldRuleBuilder regexp(String regexp) { + // // rules.put("type", "regexp"); + // rules.put("pattern", regexp); + // rules.put("message", fieldDisplayName + "输入不符合要求,请检查"); + // return this; + // } + public FieldRuleBuilder length(Integer len) { rules.put("min", len); rules.put("max", len); diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java index 42345fb..caa5aa9 100644 --- a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java +++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java @@ -56,7 +56,7 @@ public class GoodController { searchText = null; } } - List list = goodService.list(cateId, searchText); + List list = goodService.listOnSale(cateId, searchText); return Res.success(list); } @@ -100,7 +100,8 @@ public class GoodController { // 分类列表 List cateList = goodService.getCateList(); - String cateListForMock = JSONArray.from(cateList.stream().map(i -> i.getId()).collect(Collectors.toList())).toString(); + String cateListForMock = JSONArray.from(cateList.stream() + .map(i -> i.getId().toString()).collect(Collectors.toList())).toString(); // id列 字段名(区分大小写;以VO中的变量名为准) // 新增、修改弹窗时,使用该列作为主键列进行操作 @@ -133,7 +134,7 @@ public class GoodController { "商品分类", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER, FieldRuleListBuilder.create() .add(FieldRuleBuilder.create("商品分类").required()), - "DPD @pick(" + cateListForMock + "])" + "DPD @pick(" + cateListForMock + ")" ) .add("brand", "brand", "商品品牌", "", FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT, @@ -153,7 +154,7 @@ public class GoodController { .add(FieldRuleBuilder.create("商品简介").minMax(6, 30)), "DPD @cword(15, 30)" ) - .add("isOnSale", "isOnSale", "状态", true, + .add("isOnSale", "isOnSaleDisplay", "状态", true, FieldType.TEXT, SearchType.SELECT, AddType.SELECT, EditType.SELECT, FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME, "状态", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER, @@ -177,20 +178,24 @@ public class GoodController { "DPD @cword(1, 2)" ) .add("counterPrice", "counterPrice", "专柜价格", "", - FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT, + FieldType.TEXT, SearchType.INPUT, AddType.INPUT_NUMBER, EditType.INPUT_NUMBER, "专柜价/原价/划线价", "专柜价格 / 原价 / 划线价", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER, FieldRuleListBuilder.create() - .add(FieldRuleBuilder.create("专柜价格").required()), - "DTD /^\\d+?(\\.?\\d+?)?$/" + .add(FieldRuleBuilder.create("专柜价格").required()) + // .add(FieldRuleBuilder.create("专柜价格").regexp("^(\\d+(\\.\\d{1,2})?)$")) + , + "DTD /^[1-9]\\d{0,4}(\\.?\\d{1,2})?$/" ) .add("retailPrice", "retailPrice", "零售价格", "", - FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT, + FieldType.TEXT, SearchType.INPUT, AddType.INPUT_NUMBER, EditType.INPUT_NUMBER, "零售价/售价/未划线价", "零售价 / 售价 / 未划线价", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER, FieldRuleListBuilder.create() - .add(FieldRuleBuilder.create("零售价格").required()), - "DTD /^\\d+?(\\.?\\d+?)?$/" + .add(FieldRuleBuilder.create("零售价格").required()) + // .add(FieldRuleBuilder.create("零售价格").regexp("^(\\d+(\\.\\d{1,2})?)$")) + , + "DTD /^[1-9]\\d{0,2}(\\.?\\d{1,2})?$/" ) .add("detail", "detail", "商品详细介绍", "暂无商品详细介绍", FieldType.LONG_TEXT, SearchType.INPUT, AddType.TEXTAREA, EditType.TEXTAREA, @@ -212,7 +217,7 @@ public class GoodController { // build JSONArray fieldMapper = FieldMapperBuilder.create() .add("categoryId", "categoryName", cateMap) - .add("isOnSale", "isOnSale", stateMap) + .add("isOnSale", "isOnSaleDisplay", stateMap) .build(); // 拼装返回结果 @@ -237,6 +242,18 @@ public class GoodController { @ResponseBody public Res editGood(@ModelAttribute GoodVO goodVO) { Good good = GoodVO.convertTo(goodVO); + Double retailPrice = good.getRetailPrice(); + if (Objects.nonNull(retailPrice)) { + if (retailPrice < 0 || retailPrice > 99999999.99) { + return Res.error("零售价格输入不符,须在 0 - 99999999.99 之间"); + } + } + Double counterPrice = good.getCounterPrice(); + if (Objects.nonNull(counterPrice)) { + if (counterPrice < 0 || counterPrice > 99999999.99) { + return Res.error("专柜价格输入不符,须在 0 - 99999999.99 之间"); + } + } // 先查询商品是否存在 Good existGood = goodService.getGoodById(good.getId()); diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodDao.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodDao.java index 2386525..5a70621 100644 --- a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodDao.java +++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodDao.java @@ -14,6 +14,8 @@ public interface GoodDao { List list(@Param("cateId") Integer cateId, @Param("searchText") String searchText); + List listOnSale(@Param("cateId") Integer cateId, @Param("searchText") String searchText); + Good getById(Long id); Good selectById(Long id); diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java index 1c2e471..8fade97 100644 --- a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java +++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java @@ -27,6 +27,13 @@ public class GoodService { return goodVOS; } + // 只列出上架状态的商品 + public List listOnSale(Integer cateId, String searchText) { + List list = goodDao.listOnSale(cateId, searchText); + List goodVOS = GoodVO.convertFrom(list); + return goodVOS; + } + public GoodVO getById(Long id) { Good good = goodDao.getById(id); GoodVO goodVO = GoodVO.convertFrom(good); diff --git a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodMapper.xml b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodMapper.xml index 5a90e76..cccdfbb 100644 --- a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodMapper.xml +++ b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodMapper.xml @@ -37,6 +37,18 @@ order by `sort_order` asc +