From a15ed1f2d1a3e7117ef91ec0e93decb0f35f7a65 Mon Sep 17 00:00:00 2001 From: xjs <1294405880@qq.com> Date: Thu, 17 Mar 2022 17:12:10 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=B1=9E=E6=80=A7=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=A0=A1=E9=AA=8C=E5=8F=82=E6=95=B0=202?= =?UTF-8?q?=E3=80=81=E8=A7=84=E6=A0=BC=E5=88=86=E7=BB=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/attribute/attr-add-or-update.vue | 6 +- .../attribute/attrgroup-add-or-update.vue | 13 ++- .../mall/product/attribute/base-attr.vue | 2 +- ruoyi-ui/src/views/mall/product/brand.vue | 2 +- ruoyi-ui/src/views/mall/product/category.vue | 9 +- .../CheckNumberConstraintValidator.java | 25 ++++-- .../AttrAttrgroupRelationController.java | 84 ------------------- .../product/controller/AttrController.java | 22 ++--- .../controller/AttrGroupController.java | 27 +++--- .../mall/product/entity/AttrGroupEntity.java | 72 +++++++++------- .../service/AttrAttrgroupRelationService.java | 4 - .../AttrAttrgroupRelationServiceImpl.java | 18 +--- .../java/com/xjs/mall/product/vo/AttrVo.java | 23 +++++ 13 files changed, 133 insertions(+), 174 deletions(-) delete mode 100644 xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrAttrgroupRelationController.java diff --git a/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue b/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue index 123b44ff..304b1170 100644 --- a/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue +++ b/ruoyi-ui/src/views/mall/product/attribute/attr-add-or-update.vue @@ -135,7 +135,8 @@ export default { attrGroups: [], dataRule: { attrName: [ - {required: true, message: "属性名不能为空", trigger: "blur"} + {required: true, message: "属性名不能为空", trigger: "blur"}, + { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' } ], searchType: [ {required: true, message: "是否需要检索不能为空", trigger: "blur"} @@ -144,7 +145,8 @@ export default { {required: true, message: "值类型不能为空", trigger: "blur"} ], icon: [ - {required: true, message: "属性图标不能为空", trigger: "blur"} + {required: true, message: "属性图标不能为空", trigger: "blur"}, + { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' } ], attrType: [ {required: true, message: "属性类型不能为空", trigger: "blur"} diff --git a/ruoyi-ui/src/views/mall/product/attribute/attrgroup-add-or-update.vue b/ruoyi-ui/src/views/mall/product/attribute/attrgroup-add-or-update.vue index de906e8f..90e2586c 100644 --- a/ruoyi-ui/src/views/mall/product/attribute/attrgroup-add-or-update.vue +++ b/ruoyi-ui/src/views/mall/product/attribute/attrgroup-add-or-update.vue @@ -14,7 +14,7 @@ label-width="90px" > - + @@ -81,13 +81,18 @@ export default { }, dataRule: { attrGroupName: [ - {required: true, message: "组名不能为空", trigger: "blur"} + {required: true, message: "组名不能为空", trigger: "blur"}, + { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' } ], sort: [{required: true, message: "排序不能为空", trigger: "blur"}], descript: [ - {required: true, message: "描述不能为空", trigger: "blur"} + {required: true, message: "描述不能为空", trigger: "blur"}, + { min: 1, max: 255, message: '长度在 1 到 255 个字符', trigger: 'blur' } + ], + icon: [ + {required: true, message: "组图标不能为空", trigger: "blur"}, + { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' } ], - icon: [{required: true, message: "组图标不能为空", trigger: "blur"}], catelogId: [ {required: true, message: "所属分类id不能为空", trigger: "blur"} ] diff --git a/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue b/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue index 098c7987..6cda1206 100644 --- a/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue +++ b/ruoyi-ui/src/views/mall/product/attribute/base-attr.vue @@ -8,7 +8,7 @@
- + diff --git a/ruoyi-ui/src/views/mall/product/brand.vue b/ruoyi-ui/src/views/mall/product/brand.vue index 2ca6dfe9..effe695e 100644 --- a/ruoyi-ui/src/views/mall/product/brand.vue +++ b/ruoyi-ui/src/views/mall/product/brand.vue @@ -2,7 +2,7 @@
- + diff --git a/ruoyi-ui/src/views/mall/product/category.vue b/ruoyi-ui/src/views/mall/product/category.vue index 8dd44f0d..5d1df017 100644 --- a/ruoyi-ui/src/views/mall/product/category.vue +++ b/ruoyi-ui/src/views/mall/product/category.vue @@ -16,6 +16,7 @@ prefix-icon="el-icon-search" @input="rest" placeholder="输入关键字进行过滤" + maxlength="10" v-model="filterText"> @@ -134,11 +135,11 @@ export default { dataRule: { name: [ - { required: true, message: "分类名称不能为空", trigger: "blur" }, - { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' } + {required: true, message: "分类名称不能为空", trigger: "blur"}, + {min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'} ], productUnit: [ - { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' } + {min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'} ], }, @@ -180,7 +181,7 @@ export default { for (let i = 0; i < checkedNodes.length; i++) { catIds.push(checkedNodes[i].catId); } - if (catIds.length===0) { + if (catIds.length === 0) { this.$modal.notifyWarning("请选择删除内容") return } diff --git a/xjs-business/xjs-business-common/src/main/java/com/xjs/validation/constraintValidator/CheckNumberConstraintValidator.java b/xjs-business/xjs-business-common/src/main/java/com/xjs/validation/constraintValidator/CheckNumberConstraintValidator.java index d42d5d04..e90ac75a 100644 --- a/xjs-business/xjs-business-common/src/main/java/com/xjs/validation/constraintValidator/CheckNumberConstraintValidator.java +++ b/xjs-business/xjs-business-common/src/main/java/com/xjs/validation/constraintValidator/CheckNumberConstraintValidator.java @@ -11,7 +11,7 @@ import java.util.Objects; * @author xiejs * @since 2022-02-18 */ -public class CheckNumberConstraintValidator implements ConstraintValidator { +public class CheckNumberConstraintValidator implements ConstraintValidator { private int[] num; @@ -27,14 +27,29 @@ public class CheckNumberConstraintValidator implements ConstraintValidator params){ - PageUtils page = attrAttrgroupRelationService.queryPage(params); - - return R.ok().put("page", page); - } - - - /** - * 信息 - */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id); - - return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation); - } - - /** - * 保存 - */ - @RequestMapping("/save") - public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){ - attrAttrgroupRelationService.save(attrAttrgroupRelation); - - return R.ok(); - } - - /** - * 修改 - */ - @RequestMapping("/update") - public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){ - attrAttrgroupRelationService.updateById(attrAttrgroupRelation); - - return R.ok(); - } - - /** - * 删除 - */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - attrAttrgroupRelationService.removeByIds(Arrays.asList(ids)); - - return R.ok(); - } - -} diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java index adb32317..5de49c9c 100644 --- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java +++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrController.java @@ -7,22 +7,24 @@ import com.xjs.mall.product.vo.AttrResponseVo; import com.xjs.mall.product.vo.AttrVo; import com.xjs.utils.PageUtils; import com.xjs.utils.R; +import com.xjs.validation.group.AddGroup; +import com.xjs.validation.group.UpdateGroup; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.Arrays; import java.util.Map; - /** * 商品属性 * * @author xiejs * @email 1294405880@qq.com - * @since 2022-03-15 10:16:53 + * @since 2022-03-15 10:16:53 */ @RestController @RequestMapping("product/attr") @@ -45,8 +47,8 @@ public class AttrController { */ @GetMapping("/info/{attrId}") @ApiOperation("信息") - public R info(@PathVariable("attrId") Long attrId){ - AttrResponseVo attr = attrService.getAttrInfo(attrId); + public R info(@PathVariable("attrId") Long attrId) { + AttrResponseVo attr = attrService.getAttrInfo(attrId); return R.ok().put("attr", attr); } @@ -57,8 +59,8 @@ public class AttrController { @PostMapping("/save") @ApiOperation("保存") @Log(title = "规格参数", businessType = BusinessType.INSERT) - public R save(@RequestBody AttrVo attr){ - attrService.saveAttr(attr); + public R save(@Validated(AddGroup.class) @RequestBody AttrVo attr) { + attrService.saveAttr(attr); return R.ok(); } @@ -69,8 +71,8 @@ public class AttrController { @PutMapping("/update") @ApiOperation("修改") @Log(title = "规格参数", businessType = BusinessType.UPDATE) - public R update(@RequestBody AttrVo attr){ - attrService.updateAttr(attr); + public R update(@Validated(UpdateGroup.class) @RequestBody AttrVo attr) { + attrService.updateAttr(attr); return R.ok(); } @@ -81,8 +83,8 @@ public class AttrController { @DeleteMapping("/delete") @ApiOperation("删除") @Log(title = "规格参数", businessType = BusinessType.DELETE) - public R delete(@RequestBody Long[] attrIds){ - attrService.removeByIds(Arrays.asList(attrIds)); + public R delete(@RequestBody Long[] attrIds) { + attrService.removeByIds(Arrays.asList(attrIds)); return R.ok(); } diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java index d128e9fe..87931b73 100644 --- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java +++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/controller/AttrGroupController.java @@ -7,9 +7,12 @@ import com.xjs.mall.product.service.AttrGroupService; import com.xjs.mall.product.service.CategoryService; import com.xjs.utils.PageUtils; import com.xjs.utils.R; +import com.xjs.validation.group.AddGroup; +import com.xjs.validation.group.UpdateGroup; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.Arrays; @@ -23,7 +26,7 @@ import java.util.stream.Collectors; * * @author xiejs * @email 1294405880@qq.com - * @since 2022-03-15 10:16:53 + * @since 2022-03-15 10:16:53 */ @RestController @RequestMapping("product/attrgroup") @@ -39,9 +42,9 @@ public class AttrGroupController { */ @GetMapping("/list/{catelogId}") @ApiOperation("列表") - public R list(@RequestParam Map params,Long catelogId){ + public R list(@RequestParam Map params, Long catelogId) { - PageUtils page =attrGroupService.queryPage(params,catelogId); + PageUtils page = attrGroupService.queryPage(params, catelogId); return R.ok().put("page", page); } @@ -52,10 +55,10 @@ public class AttrGroupController { */ @GetMapping("/info/{attrGroupId}") @ApiOperation("信息") - public R info(@PathVariable("attrGroupId") Long attrGroupId){ - AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId); + public R info(@PathVariable("attrGroupId") Long attrGroupId) { + AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId); - Long[] path=categoryService.finCatelogPath(attrGroup.getCatelogId()); + Long[] path = categoryService.finCatelogPath(attrGroup.getCatelogId()); List collect = Arrays.stream(path).map(String::valueOf).collect(Collectors.toList()); attrGroup.setCatelogPath(collect); @@ -69,8 +72,8 @@ public class AttrGroupController { @PostMapping("/save") @ApiOperation("保存") @Log(title = "属性分组", businessType = BusinessType.INSERT) - public R save(@RequestBody AttrGroupEntity attrGroup){ - attrGroupService.save(attrGroup); + public R save(@Validated(AddGroup.class) @RequestBody AttrGroupEntity attrGroup) { + attrGroupService.save(attrGroup); return R.ok(); } @@ -81,8 +84,8 @@ public class AttrGroupController { @PutMapping("/update") @ApiOperation("修改") @Log(title = "属性分组", businessType = BusinessType.UPDATE) - public R update(@RequestBody AttrGroupEntity attrGroup){ - attrGroupService.updateById(attrGroup); + public R update(@Validated(UpdateGroup.class) @RequestBody AttrGroupEntity attrGroup) { + attrGroupService.updateById(attrGroup); return R.ok(); } @@ -93,8 +96,8 @@ public class AttrGroupController { @DeleteMapping("/delete") @ApiOperation("删除") @Log(title = "属性分组", businessType = BusinessType.DELETE) - public R delete(@RequestBody Long[] attrGroupIds){ - attrGroupService.removeByIds(Arrays.asList(attrGroupIds)); + public R delete(@RequestBody Long[] attrGroupIds) { + attrGroupService.removeByIds(Arrays.asList(attrGroupIds)); return R.ok(); } diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java index decf51db..b68028e7 100644 --- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java +++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/entity/AttrGroupEntity.java @@ -3,8 +3,12 @@ package com.xjs.mall.product.entity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.xjs.validation.group.AddGroup; +import com.xjs.validation.group.UpdateGroup; import lombok.Data; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; import java.io.Serializable; import java.util.List; @@ -18,38 +22,44 @@ import java.util.List; @Data @TableName("pms_attr_group") public class AttrGroupEntity implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 分组id - */ - @TableId - private Long attrGroupId; - /** - * 组名 - */ - private String attrGroupName; - /** - * 排序 - */ - private Integer sort; - /** - * 描述 - */ - private String descript; - /** - * 组图标 - */ - private String icon; - /** - * 所属分类id - */ - private Long catelogId; + /** + * 分组id + */ + @TableId + private Long attrGroupId; + /** + * 组名 + */ + @NotBlank(message = "组名不能为空", groups = {UpdateGroup.class, AddGroup.class}) + @Size(max = 20, groups = {UpdateGroup.class, AddGroup.class}, message = "图标大小长度大于 20 字符") + private String attrGroupName; + /** + * 排序 + */ + private Integer sort; + /** + * 描述 + */ + @NotBlank(message = "描述不能为空", groups = {UpdateGroup.class, AddGroup.class}) + @Size(max = 255, groups = {UpdateGroup.class, AddGroup.class}, message = "图标大小长度大于 255 字符") + private String descript; + /** + * 组图标 + */ + @Size(max = 50, groups = {UpdateGroup.class, AddGroup.class}, message = "图标大小长度大于 50 字符") + private String icon; + /** + * 所属分类id + */ + @NotBlank(message = "所属分类id不能为空", groups = {UpdateGroup.class, AddGroup.class}) + private Long catelogId; - /** - * 分类id完整路径 - */ - @TableField(exist = false) - private List catelogPath; + /** + * 分类id完整路径 + */ + @TableField(exist = false) + private List catelogPath; } diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java index 3ff6991f..9e785f0d 100644 --- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java +++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/AttrAttrgroupRelationService.java @@ -1,11 +1,8 @@ package com.xjs.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.xjs.utils.PageUtils; import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity; -import java.util.Map; - /** * 属性&属性分组关联 * @@ -15,6 +12,5 @@ import java.util.Map; */ public interface AttrAttrgroupRelationService extends IService { - PageUtils queryPage(Map params); } diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java index 1fec8f0c..7a185ded 100644 --- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java +++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/service/impl/AttrAttrgroupRelationServiceImpl.java @@ -1,29 +1,15 @@ package com.xjs.mall.product.service.impl; -import org.springframework.stereotype.Service; -import java.util.Map; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.xjs.utils.PageUtils; -import com.xjs.utils.Query; - import com.xjs.mall.product.dao.AttrAttrgroupRelationDao; import com.xjs.mall.product.entity.AttrAttrgroupRelationEntity; import com.xjs.mall.product.service.AttrAttrgroupRelationService; +import org.springframework.stereotype.Service; @Service("attrAttrgroupRelationService") public class AttrAttrgroupRelationServiceImpl extends ServiceImpl implements AttrAttrgroupRelationService { - @Override - public PageUtils queryPage(Map params) { - IPage page = this.page( - new Query().getPage(params), - new QueryWrapper() - ); - return new PageUtils(page); - } -} \ No newline at end of file +} diff --git a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrVo.java b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrVo.java index 6e3696f3..aed0baa0 100644 --- a/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrVo.java +++ b/xjs-business/xjs-project-mall/mall-product/src/main/java/com/xjs/mall/product/vo/AttrVo.java @@ -1,9 +1,17 @@ package com.xjs.mall.product.vo; +import com.xjs.validation.annotation.CheckNumber; +import com.xjs.validation.group.AddGroup; +import com.xjs.validation.group.UpdateGroup; import lombok.Data; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + /** * 商品属性Vo + * * @author xiejs * @since 2022-03-17 */ @@ -13,39 +21,54 @@ public class AttrVo { /** * 属性名 */ + @NotBlank(message = "属性名不能为空", groups = {AddGroup.class, UpdateGroup.class}) + @Size(max = 30, groups = {AddGroup.class, UpdateGroup.class}, message = "属性名长度在 1 到 30 字符") private String attrName; /** * 是否需要检索[0-不需要,1-需要] */ + @NotNull(message = "是否需要检索不能为空", groups = {AddGroup.class, UpdateGroup.class}) + @CheckNumber(num = {0, 1}, groups = {AddGroup.class, UpdateGroup.class}) private Integer searchType; /** * 属性图标 */ + @NotBlank(message = "属性图标不能为空", groups = {AddGroup.class, UpdateGroup.class}) + @Size(max = 30, groups = {AddGroup.class, UpdateGroup.class}, message = "属性图标长度在 1 到 30 字符") private String icon; /** * 可选值列表[用逗号分隔] */ + @Size(max = 255, groups = {AddGroup.class, UpdateGroup.class}, message = "可选值列表长度在 1 到 255 字符") private String valueSelect; /** * 属性类型[0-销售属性,1-基本属性,2-既是销售属性又是基本属性] */ + @CheckNumber(num = {0, 1}, groups = {AddGroup.class, UpdateGroup.class}) + @NotNull(message = "属性类型不能为空", groups = {AddGroup.class, UpdateGroup.class}) private Integer attrType; /** * 值类型(多选单选) */ + @NotNull(message = "值类型不能为空", groups = {AddGroup.class, UpdateGroup.class}) private Integer valueType; /** * 启用状态[0 - 禁用,1 - 启用] */ + @CheckNumber(num = {0, 1}, groups = {AddGroup.class, UpdateGroup.class}) + @NotNull(message = "启用状态不能为空", groups = {AddGroup.class, UpdateGroup.class}) private Long enable; /** * 所属分类 */ + @NotNull(message = "所属分类id不能为空", groups = {AddGroup.class, UpdateGroup.class}) private Long catelogId; /** * 快速展示【是否展示在介绍上;0-否 1-是】,在sku中仍然可以调整 */ + @CheckNumber(num = {0, 1}, groups = {AddGroup.class, UpdateGroup.class}) + @NotNull(message = "快速展示不能为空", groups = {AddGroup.class, UpdateGroup.class}) private Integer showDesc;