From 5d7af3839879f47a7b346f2a1925ba5cb0f4ee16 Mon Sep 17 00:00:00 2001 From: liujiang <569804566@qq.com> Date: Sun, 13 Apr 2025 15:54:11 +0800 Subject: [PATCH] =?UTF-8?q?master=EF=BC=9A=E7=B3=BB=E7=BB=9F=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=86=E7=B1=BB=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SysDictDataController.java | 2 +- .../system/SysDictTypeController.java | 2 +- .../system/SysProductCategoryController.java | 91 +++++++++ .../domain/entity/SysProductCategory.java | 63 ++++++ .../vo/productCategory/ProdCateListResVO.java | 42 ++++ .../vo/productCategory/ProdCateListVO.java | 23 +++ .../domain/vo/productCategory/ProdCateVO.java | 34 +++ .../dto/productCategory/ProdCateDTO.java | 31 +++ .../dto/productCategory/ProdCateListDTO.java | 23 +++ .../productCategory/ProdCateListResDTO.java | 42 ++++ .../mapper/SysProductCategoryMapper.java | 13 ++ .../service/ISysProductCategoryService.java | 55 +++++ .../service/impl/SysDictDataServiceImpl.java | 9 +- .../service/impl/SysDictTypeServiceImpl.java | 9 +- .../impl/SysProductCategoryServiceImpl.java | 193 ++++++++++++++++++ 15 files changed, 622 insertions(+), 10 deletions(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProductCategoryController.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysProductCategory.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListResVO.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListVO.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateVO.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateDTO.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListDTO.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListResDTO.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysProductCategoryMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysProductCategoryService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysProductCategoryServiceImpl.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java index 00c1c23e4..15b0086ad 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java @@ -43,7 +43,7 @@ import java.util.List; * @author ruoyi */ @RequiredArgsConstructor -@Api(tags = "字典数据明细") +@Api(tags = "系统基础数据 - 字典数据明细") @RestController @RequestMapping("/system/dict/data") public class SysDictDataController extends BaseController { diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java index 313532f0d..6c2367051 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java @@ -35,7 +35,7 @@ import java.util.Optional; * * @author ruoyi */ -@Api(tags = "字典类型") +@Api(tags = "系统基础数据 - 字典类型") @RequiredArgsConstructor @RestController @RequestMapping("/system/dict/type") diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProductCategoryController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProductCategoryController.java new file mode 100644 index 000000000..aea64cb44 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProductCategoryController.java @@ -0,0 +1,91 @@ +package com.ruoyi.web.controller.system; + +import cn.hutool.core.bean.BeanUtil; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.XktBaseController; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.vo.productCategory.ProdCateListVO; +import com.ruoyi.common.core.domain.vo.productCategory.ProdCateVO; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.dto.productCategory.ProdCateDTO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateListDTO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateListResDTO; +import com.ruoyi.system.service.ISysProductCategoryService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 商品分类 + * + * @author ruoyi + */ +@Api(tags = "系统基础数据 - 商品分类") +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/prod-cate") +public class SysProductCategoryController extends XktBaseController { + + final ISysProductCategoryService prodCateService; + + /** + * 新增商品分类 + */ + @PreAuthorize("@ss.hasPermi('system:category:add')") + @ApiOperation(value = "新增商品分类", httpMethod = "POST", response = R.class) + @Log(title = "新增商品分类", businessType = BusinessType.INSERT) + @PostMapping + public R create(@Validated @RequestBody ProdCateVO prodCateVO) { + return R.ok(prodCateService.create(BeanUtil.toBean(prodCateVO, ProdCateDTO.class))); + } + + /** + * 修改商品分类 + */ + @PreAuthorize("@ss.hasPermi('system:category:edit')") + @ApiOperation(value = "修改商品分类", httpMethod = "PUT", response = R.class) + @Log(title = "修改商品分类", businessType = BusinessType.UPDATE) + @PutMapping + public R update(@Validated @RequestBody ProdCateVO prodCateVO) { + return R.ok(prodCateService.update(BeanUtil.toBean(prodCateVO, ProdCateDTO.class))); + } + + /** + * 删除商品分类 + */ + @PreAuthorize("@ss.hasPermi('system:category:remove')") + @ApiOperation(value = "删除商品分类", httpMethod = "DELETE", response = R.class) + @Log(title = "删除商品分类", businessType = BusinessType.DELETE) + @DeleteMapping("/{prodCateId}") + public R delete(@PathVariable Long prodCateId) { + return R.ok(prodCateService.delete(prodCateId)); + } + + + /** + * 查询商品分类详细 + */ + @PreAuthorize("@ss.hasPermi('system:category:query')") + @ApiOperation(value = "查询商品分类详细", httpMethod = "GET", response = R.class) + @GetMapping(value = "/{prodCateId}") + public R getInfo(@PathVariable Long prodCateId) { + return R.ok(BeanUtil.toBean(prodCateService.selectById(prodCateId), ProdCateVO.class)); + } + + /** + * 获取商品分类列表 + */ + @PreAuthorize("@ss.hasPermi('system:category:list')") + @ApiOperation(value = "获取商品分类列表", httpMethod = "POST", response = R.class) + @PostMapping("/list") + public R> list(@RequestBody ProdCateListVO listVO) { + return R.ok(BeanUtil.copyToList(prodCateService.selectList(BeanUtil.toBean(listVO, ProdCateListDTO.class)), ProdCateListResDTO.class)); + } + + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysProductCategory.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysProductCategory.java new file mode 100644 index 000000000..93f43a1ec --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysProductCategory.java @@ -0,0 +1,63 @@ +package com.ruoyi.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.XktBaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 商品类目 sys_product_category + * + * @author ruoyi + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysProductCategory extends XktBaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 字典主键 + */ + @TableId(value = "id") + private Long id; + + /** + * 字典名称 + */ + @Excel(name = "字典名称") + private String name; + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 显示顺序 + */ + private Integer orderNum; + /** + * 状态(0正常 1停用) + */ + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private String status; + + /** + * 备注 + */ + private String remark; + + @Override + public String toString() { + return "SysProductCategory{" + + "id=" + id + + ", name='" + name + '\'' + + ", parentId=" + parentId + + ", orderNum=" + orderNum + + ", status='" + status + '\'' + + ", remark='" + remark + '\'' + + "} " + super.toString(); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListResVO.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListResVO.java new file mode 100644 index 000000000..454dbbef2 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListResVO.java @@ -0,0 +1,42 @@ +package com.ruoyi.common.core.domain.vo.productCategory; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.ruoyi.common.core.domain.entity.SysMenu; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @author liujiang + * @version v1.0 + * @date 2025/3/27 15:12 + */ +@ApiModel("系统商品分类列表") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ProdCateListResVO { + + @ApiModelProperty(value = "商品分类主键, 新增不传 编辑必传") + private Long prodCateId; + @ApiModelProperty(name = "分类名称") + private String name; + @ApiModelProperty(name = "分类名称") + private Long parentId; + @ApiModelProperty(name = "显示顺序") + private Integer orderNum; + @ApiModelProperty(name = "状态") + private String status; + @ApiModelProperty(name = "备注") + private String remark; + @ApiModelProperty(name = "创建时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + @ApiModelProperty(name = "子分类") + private List children; + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListVO.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListVO.java new file mode 100644 index 000000000..42bba4d56 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateListVO.java @@ -0,0 +1,23 @@ +package com.ruoyi.common.core.domain.vo.productCategory; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liujiang + * @version v1.0 + * @date 2025/3/27 15:12 + */ +@ApiModel("系统商品分类列表") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ProdCateListVO { + + @ApiModelProperty(name = "分类名称") + private String name; + @ApiModelProperty(name = "状态") + private String status; + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateVO.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateVO.java new file mode 100644 index 000000000..40f62b85f --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/vo/productCategory/ProdCateVO.java @@ -0,0 +1,34 @@ +package com.ruoyi.common.core.domain.vo.productCategory; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author liujiang + * @version v1.0 + * @date 2025/3/27 15:12 + */ +@ApiModel("系统商品分类") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ProdCateVO { + + @ApiModelProperty(value = "商品分类主键, 新增不传 编辑必传") + private Long prodCateId; + @ApiModelProperty(name = "分类名称") + private String name; + @ApiModelProperty(name = "分类名称") + private Long parentId; + @ApiModelProperty(name = "显示顺序") + private Integer orderNum; + @ApiModelProperty(name = "状态") + private String status; + @ApiModelProperty(name = "备注") + private String remark; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateDTO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateDTO.java new file mode 100644 index 000000000..e5599f520 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateDTO.java @@ -0,0 +1,31 @@ +package com.ruoyi.system.domain.dto.productCategory; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liujiang + * @version v1.0 + * @date 2025/3/27 15:12 + */ +@ApiModel("系统商品分类") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ProdCateDTO { + + @ApiModelProperty(value = "商品分类主键, 新增不传 编辑必传") + private Long prodCateId; + @ApiModelProperty(name = "分类名称") + private String name; + @ApiModelProperty(name = "分类名称") + private Long parentId; + @ApiModelProperty(name = "显示顺序") + private Integer orderNum; + @ApiModelProperty(name = "状态") + private String status; + @ApiModelProperty(name = "备注") + private String remark; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListDTO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListDTO.java new file mode 100644 index 000000000..b8e5b31bf --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListDTO.java @@ -0,0 +1,23 @@ +package com.ruoyi.system.domain.dto.productCategory; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liujiang + * @version v1.0 + * @date 2025/3/27 15:12 + */ +@ApiModel("系统商品分类列表") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ProdCateListDTO { + + @ApiModelProperty(name = "分类名称") + private String name; + @ApiModelProperty(name = "状态") + private String status; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListResDTO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListResDTO.java new file mode 100644 index 000000000..9f23bd944 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/productCategory/ProdCateListResDTO.java @@ -0,0 +1,42 @@ +package com.ruoyi.system.domain.dto.productCategory; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * @author liujiang + * @version v1.0 + * @date 2025/3/27 15:12 + */ +@ApiModel("系统商品分类列表") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ProdCateListResDTO { + + @ApiModelProperty(value = "商品分类主键") + @JsonProperty(value = "prodCateId") + private Long id; + @ApiModelProperty(name = "分类名称") + private String name; + @ApiModelProperty(name = "分类名称") + private Long parentId; + @ApiModelProperty(name = "显示顺序") + private Integer orderNum; + @ApiModelProperty(name = "状态") + private String status; + @ApiModelProperty(name = "备注") + private String remark; + @ApiModelProperty(name = "创建时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + @ApiModelProperty(name = "子分类") + private List children; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysProductCategoryMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysProductCategoryMapper.java new file mode 100644 index 000000000..b58766ad4 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysProductCategoryMapper.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.common.core.domain.entity.SysProductCategory; + +/** + * 商品分类 数据层 + * + * @author ruoyi + */ +public interface SysProductCategoryMapper extends BaseMapper { + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysProductCategoryService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysProductCategoryService.java new file mode 100644 index 000000000..e2357a367 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysProductCategoryService.java @@ -0,0 +1,55 @@ +package com.ruoyi.system.service; + +import com.ruoyi.common.core.domain.vo.productCategory.ProdCateVO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateDTO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateListDTO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateListResDTO; + +import java.util.List; + +/** + * 商品分类 + * + * @author ruoyi + */ +public interface ISysProductCategoryService { + + /** + * 新增商品分类 + * + * @param cateDTO 新增商品分类入参 + * @return Integer + */ + Integer create(ProdCateDTO cateDTO); + + /** + * 编辑商品分类 + * + * @param cateDTO 编辑商品分类入参 + * @return Integer + */ + Integer update(ProdCateDTO cateDTO); + + /** + * 删除商品分类 + * + * @param prodCateId 商品分类ID + * @return Integer + */ + Integer delete(Long prodCateId); + + /** + * 获取商品分类详情 + * @param prodCateId 商品分类ID + * @return ProdCateDTO + */ + ProdCateDTO selectById(Long prodCateId); + + /** + * 获取商品分类列表 + * @param listDTO 查询入参 + * @return List + */ + List selectList(ProdCateListDTO listDTO); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java index c5808dcac..c5f89fd1f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java @@ -18,11 +18,10 @@ import com.ruoyi.system.domain.dto.dictData.DictDataResDTO; import com.ruoyi.system.mapper.SysDictDataMapper; import com.ruoyi.system.service.ISysDictDataService; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -45,6 +44,9 @@ public class SysDictDataServiceImpl implements ISysDictDataService { @Override @Transactional public Integer create(DictDataDTO dataDTO) { + if (ObjectUtils.isNotEmpty(dataDTO.getDictDataId())) { + throw new ServiceException("新增字典数据dictDataId必须为空!", HttpStatus.ERROR); + } SysDictData dictData = BeanUtil.toBean(dataDTO, SysDictData.class); dictData.setCreateBy(getUsername()); return this.dictDataMapper.insert(dictData); @@ -54,8 +56,7 @@ public class SysDictDataServiceImpl implements ISysDictDataService { @Transactional public Integer update(DictDataDTO dataDTO) { SysDictData dict = Optional.ofNullable(this.dictDataMapper.selectOne(new LambdaQueryWrapper() - .eq(SysDictData::getId, dataDTO.getDictDataId()).eq(SysDictData::getDelFlag, Constants.UNDELETED) - .eq(SysDictData::getStatus, dataDTO.getStatus()))) + .eq(SysDictData::getId, dataDTO.getDictDataId()).eq(SysDictData::getDelFlag, Constants.UNDELETED))) .orElseThrow(() -> new ServiceException("字典数据不存在!", HttpStatus.ERROR)); dict.setUpdateBy(getUsername()); BeanUtil.copyProperties(dataDTO, dict); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index b5dd8bd8b..f1e20b1d8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -82,6 +82,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService { @Override @Transactional public Integer create(DictTypeDTO typeDTO) { + if (ObjectUtils.isNotEmpty(typeDTO.getDictId())) { + throw new ServiceException("新增字典类型dictId必须为空!", HttpStatus.ERROR); + } // 如果字典名称已存在,则报错 if (!this.checkDictTypeUnique(typeDTO)) { throw new ServiceException("新增字典'" + typeDTO.getDictName() + "'失败,字典类型已存在", HttpStatus.ERROR); @@ -107,8 +110,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService { throw new ServiceException("修改字典'" + typeDTO.getDictName() + "'失败,字典类型已存在", HttpStatus.ERROR); } SysDictType dict = Optional.ofNullable(this.dictTypeMapper.selectOne(new LambdaQueryWrapper() - .eq(SysDictType::getDictId, typeDTO.getDictId()).eq(SysDictType::getDelFlag, Constants.UNDELETED) - .eq(SysDictType::getStatus, typeDTO.getStatus()))) + .eq(SysDictType::getDictId, typeDTO.getDictId()).eq(SysDictType::getDelFlag, Constants.UNDELETED))) .orElseThrow(() -> new ServiceException("字典类型不存在!", HttpStatus.ERROR)); dict.setUpdateBy(getUsername()); BeanUtil.copyProperties(typeDTO, dict); @@ -180,8 +182,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService { @Transactional(readOnly = true) public DictTypeResDTO selectById(Long dictId) { SysDictType dict = Optional.ofNullable(this.dictTypeMapper.selectOne(new LambdaQueryWrapper() - .eq(SysDictType::getDictId, dictId).eq(SysDictType::getDelFlag, Constants.UNDELETED) - .eq(SysDictType::getStatus, STATUS_NORMAL))) + .eq(SysDictType::getDictId, dictId).eq(SysDictType::getDelFlag, Constants.UNDELETED))) .orElseThrow(() -> new ServiceException("字典类型不存在!", HttpStatus.ERROR)); return BeanUtil.toBean(dict, DictTypeResDTO.class); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysProductCategoryServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysProductCategoryServiceImpl.java new file mode 100644 index 000000000..26a532659 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysProductCategoryServiceImpl.java @@ -0,0 +1,193 @@ +package com.ruoyi.system.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.core.domain.entity.SysProductCategory; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.system.domain.dto.productCategory.ProdCateDTO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateListDTO; +import com.ruoyi.system.domain.dto.productCategory.ProdCateListResDTO; +import com.ruoyi.system.mapper.SysProductCategoryMapper; +import com.ruoyi.system.service.ISysProductCategoryService; +import lombok.RequiredArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import static com.ruoyi.common.utils.SecurityUtils.getUsername; + +/** + * 字典 业务层处理 + * + * @author ruoyi + */ +@Service +@RequiredArgsConstructor +public class SysProductCategoryServiceImpl implements ISysProductCategoryService { + + final SysProductCategoryMapper prodCateMapper; + + /** + * 新增商品分类 + * + * @param cateDTO 新增商品分类入参 + * @return Integer + */ + @Override + @Transactional + public Integer create(ProdCateDTO cateDTO) { + if (ObjectUtils.isNotEmpty(cateDTO.getProdCateId())) { + throw new ServiceException("新增商品分类 prodCateId必须为空!", HttpStatus.ERROR); + } + return this.prodCateMapper.insert(BeanUtil.toBean(cateDTO, SysProductCategory.class)); + } + + /** + * 编辑商品分类 + * + * @param cateDTO 编辑商品分类入参 + * @return Integer + */ + @Override + @Transactional + public Integer update(ProdCateDTO cateDTO) { + SysProductCategory prodCate = Optional.ofNullable(this.prodCateMapper.selectOne(new LambdaQueryWrapper() + .eq(SysProductCategory::getId, cateDTO.getProdCateId()).eq(SysProductCategory::getDelFlag, Constants.UNDELETED))) + .orElseThrow(() -> new ServiceException("商品分类不存在!", HttpStatus.ERROR)); + prodCate.setUpdateBy(getUsername()); + BeanUtil.copyProperties(cateDTO, prodCate); + return this.prodCateMapper.updateById(prodCate); + } + + /** + * 删除商品分类 + * + * @param prodCateId 商品分类ID + * @return Integer + */ + @Override + @Transactional + public Integer delete(Long prodCateId) { + SysProductCategory prodCate = Optional.ofNullable(this.prodCateMapper.selectOne(new LambdaQueryWrapper() + .eq(SysProductCategory::getId, prodCateId).eq(SysProductCategory::getDelFlag, Constants.UNDELETED))) + .orElseThrow(() -> new ServiceException("商品分类不存在!", HttpStatus.ERROR)); + prodCate.setDelFlag(Constants.DELETED); + return this.prodCateMapper.updateById(prodCate); + } + + /** + * 获取商品分类详情 + * + * @param prodCateId 商品分类ID + * @return ProdCateDTO + */ + @Override + @Transactional(readOnly = true) + public ProdCateDTO selectById(Long prodCateId) { + SysProductCategory prodCate = Optional.ofNullable(this.prodCateMapper.selectOne(new LambdaQueryWrapper() + .eq(SysProductCategory::getId, prodCateId).eq(SysProductCategory::getDelFlag, Constants.UNDELETED))) + .orElseThrow(() -> new ServiceException("商品分类不存在!", HttpStatus.ERROR)); + return BeanUtil.toBean(prodCate, ProdCateDTO.class); + } + + /** + * 获取商品分类列表 + * + * @param listDTO 查询入参 + * @return List + */ + @Override + @Transactional(readOnly = true) + public List selectList(ProdCateListDTO listDTO) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(SysProductCategory::getDelFlag, Constants.UNDELETED) + .orderByAsc(SysProductCategory::getOrderNum); + if (StringUtils.isNotBlank(listDTO.getName())) { + queryWrapper.like(SysProductCategory::getName, listDTO.getName()); + } + if (StringUtils.isNotBlank(listDTO.getStatus())) { + queryWrapper.eq(SysProductCategory::getStatus, listDTO.getStatus()); + } + List prodCateList = this.prodCateMapper.selectList(queryWrapper); + if (CollectionUtils.isEmpty(prodCateList)) { + return new ArrayList<>(); + } + List resList = BeanUtil.copyToList(prodCateList, ProdCateListResDTO.class); + return this.buildCateTree(resList); + } + + + /** + * 组装商品分类树 + * + * @param cateList 商品分类列表 + * @return List + */ + private List buildCateTree(List cateList) { + List returnList = new ArrayList<>(); + List tempList = cateList.stream().map(ProdCateListResDTO::getId).collect(Collectors.toList()); + for (Iterator iterator = cateList.iterator(); iterator.hasNext(); ) { + ProdCateListResDTO category = iterator.next(); + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(category.getParentId())) { + recursionFn(cateList, category); + returnList.add(category); + } + } + if (returnList.isEmpty()) { + returnList = cateList; + } + return returnList; + } + + + /** + * 递归列表 + * + * @param cateList 分类表 + * @param cate 子节点 + */ + private void recursionFn(List cateList, ProdCateListResDTO cate) { + // 得到子节点列表 + List childList = getChildList(cateList, cate); + cate.setChildren(childList); + for (ProdCateListResDTO tChild : childList) { + if (hasChild(cateList, tChild)) { + recursionFn(cateList, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List cateList, ProdCateListResDTO cate) { + List tlist = new ArrayList<>(); + Iterator it = cateList.iterator(); + while (it.hasNext()) { + ProdCateListResDTO n = it.next(); + if (n.getParentId().longValue() == cate.getId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, ProdCateListResDTO cate) { + return getChildList(list, cate).size() > 0; + } + +}