bugfix 修复若干商品管理Bug;小程序商品列表不展示下架商品
This commit is contained in:
parent
0bcef8d497
commit
2038d76b1e
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -56,7 +56,7 @@ public class GoodController {
|
||||
searchText = null;
|
||||
}
|
||||
}
|
||||
List<GoodVO> list = goodService.list(cateId, searchText);
|
||||
List<GoodVO> list = goodService.listOnSale(cateId, searchText);
|
||||
return Res.success(list);
|
||||
}
|
||||
|
||||
@ -100,7 +100,8 @@ public class GoodController {
|
||||
|
||||
// 分类列表
|
||||
List<GoodCategory> 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());
|
||||
|
@ -14,6 +14,8 @@ public interface GoodDao {
|
||||
|
||||
List<Good> list(@Param("cateId") Integer cateId, @Param("searchText") String searchText);
|
||||
|
||||
List<Good> listOnSale(@Param("cateId") Integer cateId, @Param("searchText") String searchText);
|
||||
|
||||
Good getById(Long id);
|
||||
|
||||
Good selectById(Long id);
|
||||
|
@ -27,6 +27,13 @@ public class GoodService {
|
||||
return goodVOS;
|
||||
}
|
||||
|
||||
// 只列出上架状态的商品
|
||||
public List<GoodVO> listOnSale(Integer cateId, String searchText) {
|
||||
List<Good> list = goodDao.listOnSale(cateId, searchText);
|
||||
List<GoodVO> goodVOS = GoodVO.convertFrom(list);
|
||||
return goodVOS;
|
||||
}
|
||||
|
||||
public GoodVO getById(Long id) {
|
||||
Good good = goodDao.getById(id);
|
||||
GoodVO goodVO = GoodVO.convertFrom(good);
|
||||
|
@ -37,6 +37,18 @@
|
||||
</if>
|
||||
order by `sort_order` asc
|
||||
</select>
|
||||
<select id="listOnSale" resultType="com.cxyxiaomo.epp.common.pojo.Good">
|
||||
SELECT *
|
||||
FROM goods
|
||||
WHERE is_on_sale = 1
|
||||
<if test="cateId != null">
|
||||
AND category_id = #{cateId}
|
||||
</if>
|
||||
<if test="searchText != null">
|
||||
AND goods_name LIKE concat('%',#{searchText,jdbcType=VARCHAR},'%')
|
||||
</if>
|
||||
order by `sort_order` asc
|
||||
</select>
|
||||
<select id="getById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.Good">
|
||||
SELECT *
|
||||
FROM goods
|
||||
|
@ -5,9 +5,9 @@
|
||||
<!-- 筛选 -->
|
||||
<div class="handle-box">
|
||||
<template v-for="field in searchFields">
|
||||
<el-input v-if="field.searchType == 'input'" v-model="query[field.field]"
|
||||
@keyup.enter.native="handleSearch" :placeholder="field.placeholder" :prefix-icon="Filter"
|
||||
class="handle-input mr10"></el-input>
|
||||
<el-input v-if="field.searchType == 'input' || field.searchType == 'input-number'"
|
||||
v-model="query[field.field]" @keyup.enter.native="handleSearch" :placeholder="field.placeholder"
|
||||
:prefix-icon="Filter" class="handle-input mr10"></el-input>
|
||||
<el-select v-else-if="field.searchType == 'select'" v-model="query[field.field]" :clearable="true"
|
||||
@change="handleSearch" :placeholder="field.placeholder" class="handle-select mr10">
|
||||
<template #prefix>
|
||||
@ -98,6 +98,9 @@
|
||||
<el-input v-if="(formId > 0 ? field.editType : field.addType) == 'input'"
|
||||
:placeholder="formId > 0 ? field.editPlaceholder : field.addPlaceholder" class="popup-item"
|
||||
v-model="form[field.field]"></el-input>
|
||||
<el-input v-else-if="(formId > 0 ? field.editType : field.addType) == 'input-number'" type="number"
|
||||
:placeholder="formId > 0 ? field.editPlaceholder : field.addPlaceholder" class="popup-item"
|
||||
v-model="form[field.field]"></el-input>
|
||||
<el-input v-else-if="(formId > 0 ? field.editType : field.addType) == 'textarea'"
|
||||
:placeholder="formId > 0 ? field.editPlaceholder : field.addPlaceholder" class="popup-item"
|
||||
v-model="form[field.field]" type="textarea" :rows="4"></el-input>
|
||||
@ -396,7 +399,8 @@ const handleEdit = (index: number, row: any) => {
|
||||
for (let f of dialogFields.value) {
|
||||
switch (f.editType) {
|
||||
case "select":
|
||||
// 下拉框的值要为 string 类型
|
||||
case "input-number":
|
||||
// 下拉框、数字输入框的值要为 string 类型
|
||||
form[f.field] = String(row[f.field]);
|
||||
break;
|
||||
default:
|
||||
@ -416,7 +420,8 @@ const handleNew = () => {
|
||||
for (let f of dialogFields.value) {
|
||||
switch (f.editType) {
|
||||
case "select":
|
||||
// 下拉框的值要为 string 类型
|
||||
case "input-number":
|
||||
// 下拉框、数字输入框的值要为 string 类型
|
||||
form[f.field] = String(f.default);
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user