first commit

This commit is contained in:
dev
2026-02-22 12:12:02 +08:00
commit b236048a24
1467 changed files with 160403 additions and 0 deletions
@@ -0,0 +1,23 @@
package org.dromara.mall.product.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* 商品中心自动配置类
* 主要用于扫描商品中心模块的组件
*
* @author pengles
*/
@Slf4j
@Configuration
@ComponentScan(basePackages = "org.dromara.mall.product")
@ConditionalOnProperty(prefix = "ruoyi.mall.product", name = "enabled", havingValue = "true", matchIfMissing = true)
public class MallProductAutoConfiguration {
public MallProductAutoConfiguration() {
log.info("商品中心模块已启用");
}
}
@@ -0,0 +1,122 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallAttributeBo;
import org.dromara.mall.product.domain.vo.MallAttributeVo;
import org.dromara.mall.product.service.MallAttributeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 属性管理
*
* @author pengles
*/
@Tag(name = "管理端-属性管理", description = "属性管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product/attribute")
public class AdminMallAttributeController extends BaseController {
private final MallAttributeService mallAttributeService;
/**
* 查询属性列表
*/
@Operation(summary = "查询属性列表", description = "分页查询属性列表")
@SaCheckPermission("mall:product:attribute:list")
@GetMapping("/list")
public TableDataInfo<MallAttributeVo> list(@Parameter(description = "属性查询条件") MallAttributeBo bo,
@Parameter(description = "分页参数") PageQuery pageQuery) {
return mallAttributeService.queryPageList(bo, pageQuery);
}
/**
* 导出属性列表
*/
@Operation(summary = "导出属性列表", description = "导出属性到Excel")
@SaCheckPermission("mall:product:attribute:export")
@Log(title = "属性", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(@Parameter(description = "属性查询条件") MallAttributeBo bo,
@Parameter(description = "响应对象") HttpServletResponse response) {
List<MallAttributeVo> list = mallAttributeService.queryList(bo);
ExcelUtil.exportExcel(list, "属性", MallAttributeVo.class, response);
}
/**
* 获取属性详细信息
*/
@Operation(summary = "获取属性详情", description = "根据属性ID获取详细信息")
@SaCheckPermission("mall:product:attribute:query")
@GetMapping("/{id}")
public R<MallAttributeVo> getInfo(@Parameter(description = "属性ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallAttributeService.queryById(id));
}
/**
* 根据模板ID查询属性列表
*/
@Operation(summary = "根据模板ID查询属性列表", description = "根据属性模板ID查询属性列表")
@SaCheckPermission("mall:product:attribute:list")
@GetMapping("/template/{templateId}")
public R<List<MallAttributeVo>> listByTemplateId(@Parameter(description = "模板ID", required = true)
@NotNull(message = "模板ID不能为空")
@PathVariable Long templateId) {
return R.ok(mallAttributeService.queryListByTemplateId(templateId));
}
/**
* 新增属性
*/
@Operation(summary = "新增属性", description = "新增属性")
@SaCheckPermission("mall:product:attribute:add")
@Log(title = "属性", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "属性信息") @Validated @RequestBody MallAttributeBo bo) {
return toAjax(mallAttributeService.insertByBo(bo));
}
/**
* 修改属性
*/
@Operation(summary = "修改属性", description = "修改属性")
@SaCheckPermission("mall:product:attribute:edit")
@Log(title = "属性", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "属性信息") @Validated @RequestBody MallAttributeBo bo) {
return toAjax(mallAttributeService.updateByBo(bo));
}
/**
* 删除属性
*/
@Operation(summary = "删除属性", description = "批量删除属性")
@SaCheckPermission("mall:product:attribute:remove")
@Log(title = "属性", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "属性ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallAttributeService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}
@@ -0,0 +1,110 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallAttributeTemplateBo;
import org.dromara.mall.product.domain.vo.MallAttributeTemplateVo;
import org.dromara.mall.product.service.MallAttributeTemplateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 属性模板管理
*
* @author pengles
*/
@Tag(name = "管理端-属性模板管理", description = "属性模板管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product/attribute/template")
public class AdminMallAttributeTemplateController extends BaseController {
private final MallAttributeTemplateService mallAttributeTemplateService;
/**
* 查询属性模板列表
*/
@Operation(summary = "查询属性模板列表", description = "分页查询属性模板列表")
@SaCheckPermission("mall:product:attribute:template:list")
@GetMapping("/list")
public TableDataInfo<MallAttributeTemplateVo> list(@Parameter(description = "属性模板查询条件") MallAttributeTemplateBo bo,
@Parameter(description = "分页参数") PageQuery pageQuery) {
return mallAttributeTemplateService.queryPageList(bo, pageQuery);
}
/**
* 导出属性模板列表
*/
@Operation(summary = "导出属性模板列表", description = "导出属性模板到Excel")
@SaCheckPermission("mall:product:attribute:template:export")
@Log(title = "属性模板", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(@Parameter(description = "属性模板查询条件") MallAttributeTemplateBo bo,
@Parameter(description = "响应对象") HttpServletResponse response) {
List<MallAttributeTemplateVo> list = mallAttributeTemplateService.queryList(bo);
ExcelUtil.exportExcel(list, "属性模板", MallAttributeTemplateVo.class, response);
}
/**
* 获取属性模板详细信息
*/
@Operation(summary = "获取属性模板详情", description = "根据属性模板ID获取详细信息")
@SaCheckPermission("mall:product:attribute:template:query")
@GetMapping("/{id}")
public R<MallAttributeTemplateVo> getInfo(@Parameter(description = "属性模板ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallAttributeTemplateService.queryById(id));
}
/**
* 新增属性模板
*/
@Operation(summary = "新增属性模板", description = "新增属性模板")
@SaCheckPermission("mall:product:attribute:template:add")
@Log(title = "属性模板", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "属性模板信息") @Validated @RequestBody MallAttributeTemplateBo bo) {
return toAjax(mallAttributeTemplateService.insertByBo(bo));
}
/**
* 修改属性模板
*/
@Operation(summary = "修改属性模板", description = "修改属性模板")
@SaCheckPermission("mall:product:attribute:template:edit")
@Log(title = "属性模板", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "属性模板信息") @Validated @RequestBody MallAttributeTemplateBo bo) {
return toAjax(mallAttributeTemplateService.updateByBo(bo));
}
/**
* 删除属性模板
*/
@Operation(summary = "删除属性模板", description = "批量删除属性模板")
@SaCheckPermission("mall:product:attribute:template:remove")
@Log(title = "属性模板", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "属性模板ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallAttributeTemplateService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}
@@ -0,0 +1,122 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallAttributeValueBo;
import org.dromara.mall.product.domain.vo.MallAttributeValueVo;
import org.dromara.mall.product.service.MallAttributeValueService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 属性值管理
*
* @author pengles
*/
@Tag(name = "管理端-属性值管理", description = "属性值管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product/attribute/value")
public class AdminMallAttributeValueController extends BaseController {
private final MallAttributeValueService mallAttributeValueService;
/**
* 查询属性值列表
*/
@Operation(summary = "查询属性值列表", description = "分页查询属性值列表")
@SaCheckPermission("mall:product:attribute:value:list")
@GetMapping("/list")
public TableDataInfo<MallAttributeValueVo> list(@Parameter(description = "属性值查询条件") MallAttributeValueBo bo,
@Parameter(description = "分页参数") PageQuery pageQuery) {
return mallAttributeValueService.queryPageList(bo, pageQuery);
}
/**
* 导出属性值列表
*/
@Operation(summary = "导出属性值列表", description = "导出属性值到Excel")
@SaCheckPermission("mall:product:attribute:value:export")
@Log(title = "属性值", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(@Parameter(description = "属性值查询条件") MallAttributeValueBo bo,
@Parameter(description = "响应对象") HttpServletResponse response) {
List<MallAttributeValueVo> list = mallAttributeValueService.queryList(bo);
ExcelUtil.exportExcel(list, "属性值", MallAttributeValueVo.class, response);
}
/**
* 获取属性值详细信息
*/
@Operation(summary = "获取属性值详情", description = "根据属性值ID获取详细信息")
@SaCheckPermission("mall:product:attribute:value:query")
@GetMapping("/{id}")
public R<MallAttributeValueVo> getInfo(@Parameter(description = "属性值ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallAttributeValueService.queryById(id));
}
/**
* 根据属性ID查询属性值列表
*/
@Operation(summary = "根据属性ID查询属性值列表", description = "根据属性ID查询属性值列表")
@SaCheckPermission("mall:product:attribute:value:list")
@GetMapping("/attribute/{attributeId}")
public R<List<MallAttributeValueVo>> listByAttributeId(@Parameter(description = "属性ID", required = true)
@NotNull(message = "属性ID不能为空")
@PathVariable Long attributeId) {
return R.ok(mallAttributeValueService.queryListByAttributeId(attributeId));
}
/**
* 新增属性值
*/
@Operation(summary = "新增属性值", description = "新增属性值")
@SaCheckPermission("mall:product:attribute:value:add")
@Log(title = "属性值", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "属性值信息") @Validated @RequestBody MallAttributeValueBo bo) {
return toAjax(mallAttributeValueService.insertByBo(bo));
}
/**
* 修改属性值
*/
@Operation(summary = "修改属性值", description = "修改属性值")
@SaCheckPermission("mall:product:attribute:value:edit")
@Log(title = "属性值", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "属性值信息") @Validated @RequestBody MallAttributeValueBo bo) {
return toAjax(mallAttributeValueService.updateByBo(bo));
}
/**
* 删除属性值
*/
@Operation(summary = "删除属性值", description = "批量删除属性值")
@SaCheckPermission("mall:product:attribute:value:remove")
@Log(title = "属性值", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "属性值ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallAttributeValueService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}
@@ -0,0 +1,110 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallBrandBo;
import org.dromara.mall.product.domain.vo.MallBrandVo;
import org.dromara.mall.product.service.MallBrandService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 品牌管理
*
* @author pengles
*/
@Tag(name = "管理端-品牌管理", description = "品牌管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product/brand")
public class AdminMallBrandController extends BaseController {
private final MallBrandService mallBrandService;
/**
* 查询品牌列表
*/
@Operation(summary = "查询品牌列表", description = "分页查询品牌列表")
@SaCheckPermission("mall:product:brand:list")
@GetMapping("/list")
public TableDataInfo<MallBrandVo> list(@Parameter(description = "品牌查询条件") MallBrandBo bo,
@Parameter(description = "分页参数") PageQuery pageQuery) {
return mallBrandService.queryPageList(bo, pageQuery);
}
/**
* 导出品牌列表
*/
@Operation(summary = "导出品牌列表", description = "导出品牌到Excel")
@SaCheckPermission("mall:product:brand:export")
@Log(title = "品牌", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(@Parameter(description = "品牌查询条件") MallBrandBo bo,
@Parameter(description = "响应对象") HttpServletResponse response) {
List<MallBrandVo> list = mallBrandService.queryList(bo);
ExcelUtil.exportExcel(list, "品牌", MallBrandVo.class, response);
}
/**
* 获取品牌详细信息
*/
@Operation(summary = "获取品牌详情", description = "根据品牌ID获取详细信息")
@SaCheckPermission("mall:product:brand:query")
@GetMapping("/{id}")
public R<MallBrandVo> getInfo(@Parameter(description = "品牌ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallBrandService.queryById(id));
}
/**
* 新增品牌
*/
@Operation(summary = "新增品牌", description = "新增品牌")
@SaCheckPermission("mall:product:brand:add")
@Log(title = "品牌", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "品牌信息") @Validated @RequestBody MallBrandBo bo) {
return toAjax(mallBrandService.insertByBo(bo));
}
/**
* 修改品牌
*/
@Operation(summary = "修改品牌", description = "修改品牌")
@SaCheckPermission("mall:product:brand:edit")
@Log(title = "品牌", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "品牌信息") @Validated @RequestBody MallBrandBo bo) {
return toAjax(mallBrandService.updateByBo(bo));
}
/**
* 删除品牌
*/
@Operation(summary = "删除品牌", description = "删除品牌")
@SaCheckPermission("mall:product:brand:remove")
@Log(title = "品牌", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "品牌ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallBrandService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}
@@ -0,0 +1,121 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallCategoryBo;
import org.dromara.mall.product.domain.vo.MallCategoryVo;
import org.dromara.mall.product.service.MallCategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 商品分类管理
*
* @author pengles
*/
@Tag(name = "管理端-商品分类管理", description = "商品分类管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product/category")
public class AdminMallCategoryController extends BaseController {
private final MallCategoryService mallCategoryService;
/**
* 查询商品分类列表
*/
@Operation(summary = "查询商品分类列表", description = "分页查询商品分类列表")
@SaCheckPermission("mall:product:category:list")
@GetMapping("/list")
public TableDataInfo<MallCategoryVo> list(@Parameter(description = "分类查询条件") MallCategoryBo bo,
@Parameter(description = "分页参数") PageQuery pageQuery) {
return mallCategoryService.queryPageList(bo, pageQuery);
}
/**
* 查询商品分类树形列表
*/
@Operation(summary = "查询商品分类树形列表", description = "查询商品分类树形结构")
@SaCheckPermission("mall:product:category:list")
@GetMapping("/tree")
public R<List<MallCategoryVo>> tree() {
List<MallCategoryVo> list = mallCategoryService.queryTreeList();
return R.ok(list);
}
/**
* 导出商品分类列表
*/
@Operation(summary = "导出商品分类列表", description = "导出商品分类到Excel")
@SaCheckPermission("mall:product:category:export")
@Log(title = "商品分类", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(@Parameter(description = "分类查询条件") MallCategoryBo bo,
@Parameter(description = "响应对象") HttpServletResponse response) {
List<MallCategoryVo> list = mallCategoryService.queryList(bo);
ExcelUtil.exportExcel(list, "商品分类", MallCategoryVo.class, response);
}
/**
* 获取商品分类详细信息
*/
@Operation(summary = "获取商品分类详情", description = "根据分类ID获取详细信息")
@SaCheckPermission("mall:product:category:query")
@GetMapping("/{id}")
public R<MallCategoryVo> getInfo(@Parameter(description = "分类ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallCategoryService.queryById(id));
}
/**
* 新增商品分类
*/
@Operation(summary = "新增商品分类", description = "新增商品分类")
@SaCheckPermission("mall:product:category:add")
@Log(title = "商品分类", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "分类信息") @Validated @RequestBody MallCategoryBo bo) {
return toAjax(mallCategoryService.insertByBo(bo));
}
/**
* 修改商品分类
*/
@Operation(summary = "修改商品分类", description = "修改商品分类")
@SaCheckPermission("mall:product:category:edit")
@Log(title = "商品分类", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "分类信息") @Validated @RequestBody MallCategoryBo bo) {
return toAjax(mallCategoryService.updateByBo(bo));
}
/**
* 删除商品分类
*/
@Operation(summary = "删除商品分类", description = "删除商品分类")
@SaCheckPermission("mall:product:category:remove")
@Log(title = "商品分类", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "分类ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallCategoryService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}
@@ -0,0 +1,132 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallProductAttributeBo;
import org.dromara.mall.product.domain.vo.MallProductAttributeVo;
import org.dromara.mall.product.service.MallProductAttributeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* 商品属性关联管理
*
* @author pengles
*/
@Tag(name = "管理端-商品属性关联管理", description = "商品属性关联管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product/attribute/product")
public class AdminMallProductAttributeController extends BaseController {
private final MallProductAttributeService mallProductAttributeService;
/**
* 获取商品属性关联详细信息
*/
@Operation(summary = "获取商品属性关联详情", description = "根据商品属性关联ID获取详细信息")
@SaCheckPermission("mall:product:attribute:product:query")
@GetMapping("/{id}")
public R<MallProductAttributeVo> getInfo(@Parameter(description = "商品属性关联ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallProductAttributeService.queryById(id));
}
/**
* 根据商品ID查询商品属性关联列表
*/
@Operation(summary = "根据商品ID查询商品属性关联列表", description = "根据商品ID查询商品属性关联列表")
@SaCheckPermission("mall:product:attribute:product:list")
@GetMapping("/product/{productId}")
public R<List<MallProductAttributeVo>> listByProductId(@Parameter(description = "商品ID", required = true)
@NotNull(message = "商品ID不能为空")
@PathVariable Long productId) {
return R.ok(mallProductAttributeService.queryListByProductId(productId));
}
/**
* 新增商品属性关联
*/
@Operation(summary = "新增商品属性关联", description = "新增商品属性关联")
@SaCheckPermission("mall:product:attribute:product:add")
@Log(title = "商品属性关联", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "商品属性关联信息") @Validated @RequestBody MallProductAttributeBo bo) {
return toAjax(mallProductAttributeService.insertByBo(bo));
}
/**
* 批量新增商品属性关联
*/
@Operation(summary = "批量新增商品属性关联", description = "批量新增商品属性关联")
@SaCheckPermission("mall:product:attribute:product:add")
@Log(title = "商品属性关联", businessType = BusinessType.INSERT)
@PostMapping("/batch")
public R<Void> addBatch(@Parameter(description = "商品属性关联信息列表") @Validated @RequestBody List<MallProductAttributeBo> list) {
return toAjax(mallProductAttributeService.insertBatch(list));
}
/**
* 保存商品属性关联(先删除旧的,再插入新的)
*/
@Operation(summary = "保存商品属性关联", description = "保存商品属性关联,先删除旧的,再插入新的")
@SaCheckPermission("mall:product:attribute:product:edit")
@Log(title = "商品属性关联", businessType = BusinessType.UPDATE)
@PostMapping("/product/{productId}")
public R<Void> saveProductAttributes(@Parameter(description = "商品ID", required = true)
@NotNull(message = "商品ID不能为空")
@PathVariable Long productId,
@Parameter(description = "商品属性关联信息列表") @RequestBody List<MallProductAttributeBo> list) {
return toAjax(mallProductAttributeService.saveProductAttributes(productId, list));
}
/**
* 修改商品属性关联
*/
@Operation(summary = "修改商品属性关联", description = "修改商品属性关联")
@SaCheckPermission("mall:product:attribute:product:edit")
@Log(title = "商品属性关联", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "商品属性关联信息") @Validated @RequestBody MallProductAttributeBo bo) {
return toAjax(mallProductAttributeService.updateByBo(bo));
}
/**
* 删除商品属性关联
*/
@Operation(summary = "删除商品属性关联", description = "批量删除商品属性关联")
@SaCheckPermission("mall:product:attribute:product:remove")
@Log(title = "商品属性关联", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "商品属性关联ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallProductAttributeService.deleteWithValidByIds(Arrays.asList(ids), true));
}
/**
* 根据商品ID删除商品属性关联
*/
@Operation(summary = "根据商品ID删除商品属性关联", description = "根据商品ID删除商品属性关联")
@SaCheckPermission("mall:product:attribute:product:remove")
@Log(title = "商品属性关联", businessType = BusinessType.DELETE)
@DeleteMapping("/product/{productId}")
public R<Void> removeByProductId(@Parameter(description = "商品ID", required = true)
@NotNull(message = "商品ID不能为空")
@PathVariable Long productId) {
return toAjax(mallProductAttributeService.deleteByProductId(productId));
}
}
@@ -0,0 +1,94 @@
package org.dromara.mall.product.controller.admin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.product.domain.bo.MallProductBo;
import org.dromara.mall.product.domain.vo.MallProductVo;
import org.dromara.mall.product.service.MallProductService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
/**
* 商品管理Controller
*
* @author pengles
*/
@Tag(name = "管理端-商品管理", description = "商品管理接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/product")
public class AdminMallProductController extends BaseController {
private final MallProductService mallProductService;
/**
* 查询商品列表
*/
@Operation(summary = "查询商品列表", description = "分页查询商品列表")
@SaCheckPermission("mall:product:list")
@GetMapping("/list")
public TableDataInfo<MallProductVo> list(@Parameter(description = "商品查询条件") MallProductBo bo,
@Parameter(description = "分页参数") PageQuery pageQuery) {
return mallProductService.queryPageList(bo, pageQuery);
}
/**
* 获取商品详细信息
*/
@Operation(summary = "获取商品详细信息", description = "根据商品ID获取商品详细信息")
@SaCheckPermission("mall:product:query")
@GetMapping("/{id}")
public R<MallProductVo> getInfo(@Parameter(description = "商品ID", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long id) {
return R.ok(mallProductService.queryById(id));
}
/**
* 新增商品
*/
@Operation(summary = "新增商品", description = "新增商品")
@SaCheckPermission("mall:product:add")
@Log(title = "商品管理", businessType = BusinessType.INSERT)
@PostMapping
public R<Void> add(@Parameter(description = "商品信息") @Validated @RequestBody MallProductBo bo) {
return toAjax(mallProductService.insertByBo(bo));
}
/**
* 修改商品
*/
@Operation(summary = "修改商品", description = "修改商品")
@SaCheckPermission("mall:product:edit")
@Log(title = "商品管理", businessType = BusinessType.UPDATE)
@PutMapping
public R<Void> edit(@Parameter(description = "商品信息") @Validated @RequestBody MallProductBo bo) {
return toAjax(mallProductService.updateByBo(bo));
}
/**
* 删除商品
*/
@Operation(summary = "删除商品", description = "批量删除商品")
@SaCheckPermission("mall:product:remove")
@Log(title = "商品管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@Parameter(description = "商品ID数组", required = true)
@NotNull(message = "主键不能为空")
@PathVariable Long[] ids) {
return toAjax(mallProductService.deleteWithValidByIds(Arrays.asList(ids), true));
}
}
@@ -0,0 +1,40 @@
package org.dromara.mall.product.controller.app;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.mall.product.domain.bo.MallBrandBo;
import org.dromara.mall.product.domain.vo.MallBrandVo;
import org.dromara.mall.product.service.MallBrandService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 品牌(移动端)
*
* @author pengles
*/
@Tag(name = "移动端-品牌", description = "品牌查询接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/mall/product/brand")
public class AppMallBrandController {
private final MallBrandService mallBrandService;
/**
* 查询品牌列表(移动端)
*/
@Operation(summary = "查询品牌列表", description = "查询启用的品牌列表")
@GetMapping("/list")
public R<List<MallBrandVo>> list() {
MallBrandBo bo = new MallBrandBo();
bo.setStatus(0); // 只查询启用的品牌
List<MallBrandVo> list = mallBrandService.queryList(bo);
return R.ok(list);
}
}
@@ -0,0 +1,37 @@
package org.dromara.mall.product.controller.app;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.mall.product.domain.vo.MallCategoryVo;
import org.dromara.mall.product.service.MallCategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 商品分类(移动端)
*
* @author pengles
*/
@Tag(name = "移动端-商品分类", description = "商品分类查询接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/mall/product/category")
public class AppMallCategoryController {
private final MallCategoryService mallCategoryService;
/**
* 查询商品分类树形列表(移动端)
*/
@Operation(summary = "查询商品分类树形列表", description = "查询启用的商品分类树形结构")
@GetMapping("/tree")
public R<List<MallCategoryVo>> tree() {
List<MallCategoryVo> list = mallCategoryService.queryTreeList();
return R.ok(list);
}
}
@@ -0,0 +1,82 @@
package org.dromara.mall.product.controller.app;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallProductBo;
import org.dromara.mall.product.domain.vo.MallProductVo;
import org.dromara.mall.product.domain.vo.MallSkuVo;
import org.dromara.mall.product.service.MallProductService;
import org.dromara.mall.product.service.MallSkuService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 商品(移动端)
*
* @author pengles
*/
@Tag(name = "移动端-商品", description = "商品查询接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/mall/product")
public class AppMallProductController {
private final MallProductService mallProductService;
private final MallSkuService mallSkuService;
/**
* 查询商品列表(移动端)
*/
@Operation(summary = "查询商品列表", description = "查询上架的商品列表")
@GetMapping("/list")
public R<TableDataInfo<MallProductVo>> list(
@Parameter(description = "查询条件") MallProductBo bo,
@Parameter(description = "分页参数") @Validated PageQuery pageQuery) {
// 移动端只查询上架的商品
if (bo == null) {
bo = new MallProductBo();
}
bo.setStatus(0); // 0表示上架
TableDataInfo<MallProductVo> result = mallProductService.queryPageList(bo, pageQuery);
return R.ok(result);
}
/**
* 查询商品详情(移动端)
*/
@Operation(summary = "查询商品详情", description = "根据商品ID查询商品详情")
@GetMapping("/{id}")
public R<MallProductVo> getInfo(
@Parameter(description = "商品ID", required = true) @PathVariable Long id) {
MallProductVo product = mallProductService.queryById(id);
if (product == null) {
return R.fail("商品不存在");
}
// 只有上架的商品才能查看
if (product.getStatus() != null && product.getStatus() != 0) {
return R.fail("商品已下架");
}
return R.ok(product);
}
/**
* 查询商品SKU列表(移动端)
*/
@Operation(summary = "查询商品SKU列表", description = "根据商品ID查询SKU列表")
@GetMapping("/{productId}/skus")
public R<List<MallSkuVo>> getSkus(
@Parameter(description = "商品ID", required = true) @PathVariable Long productId) {
List<MallSkuVo> skus = mallSkuService.queryListByProductId(productId);
return R.ok(skus);
}
}
@@ -0,0 +1,92 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 属性对象 mall_attribute
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_attribute")
public class MallAttribute implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 属性ID
*/
@TableId
private Long id;
/**
* 模板ID(可选,绑定到模板)
*/
private Long templateId;
/**
* 属性名称
*/
private String name;
/**
* 属性类型(0文本 1数字 2日期 3枚举)
*/
private Integer type;
/**
* 是否必填(0否 1是)
*/
private Integer required;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,82 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 属性模板对象 mall_attribute_template
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_attribute_template")
public class MallAttributeTemplate implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 模板ID
*/
@TableId
private Long id;
/**
* 模板名称
*/
private String name;
/**
* 分类ID(可选,绑定到分类)
*/
private Long categoryId;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,77 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 属性值对象 mall_attribute_value
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_attribute_value")
public class MallAttributeValue implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 属性值ID
*/
@TableId
private Long id;
/**
* 属性ID
*/
private Long attributeId;
/**
* 属性值
*/
private String value;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,82 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 品牌对象 mall_brand
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_brand")
public class MallBrand implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 品牌ID
*/
@TableId
private Long id;
/**
* 品牌名称
*/
private String name;
/**
* 品牌Logo
*/
private String logo;
/**
* 品牌描述
*/
private String description;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,87 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 商品分类对象 mall_category
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_category")
public class MallCategory implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 分类ID
*/
@TableId
private Long id;
/**
* 分类名称
*/
private String name;
/**
* 父分类ID(0表示顶级)
*/
private Long parentId;
/**
* 分类级别(1一级 2二级 3三级)
*/
private Integer level;
/**
* 分类图标
*/
private String icon;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,107 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 商品对象 mall_product
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_product")
public class MallProduct {
/**
* 商品ID
*/
@TableId
private Long id;
/**
* 商品名称
*/
private String name;
/**
* 分类ID
*/
private Long categoryId;
/**
* 品牌ID
*/
private Long brandId;
/**
* 封面图片
*/
private String coverUrl;
/**
* 商品图片(JSON数组)
*/
private String images;
/**
* 商品描述
*/
private String description;
/**
* 商品详情
*/
private String detail;
/**
* 状态(0上架 1下架)
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 销量
*/
private Integer salesCount;
/**
* 浏览量
*/
private Integer viewCount;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,77 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 商品属性关联对象 mall_product_attribute
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_product_attribute")
public class MallProductAttribute implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId
private Long id;
/**
* 商品ID
*/
private Long productId;
/**
* 属性ID
*/
private Long attributeId;
/**
* 属性值ID(当属性类型为枚举时使用)
*/
private Long attributeValueId;
/**
* 属性值(当属性类型为文本/数字/日期时使用,或自定义值)
*/
private String value;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,97 @@
package org.dromara.mall.product.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* SKU对象 mall_sku
*
* @author pengles
*/
@Data
@EqualsAndHashCode
@TableName("mall_sku")
public class MallSku {
/**
* SKU ID
*/
@TableId
private Long id;
/**
* 商品ID
*/
private Long productId;
/**
* SKU编码
*/
private String skuCode;
/**
* SKU名称
*/
private String name;
/**
* 价格(分)
*/
private Integer price;
/**
* 原价(分)
*/
private Integer originalPrice;
/**
* 库存
*/
private Integer stock;
/**
* SKU图片
*/
private String image;
/**
* 规格属性(JSON)
*/
private String specs;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateBy;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
@@ -0,0 +1,64 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.mall.product.domain.MallAttribute;
/**
* 属性业务对象 mall_attribute
*
* @author pengles
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MallAttribute.class, reverseConvertGenerate = false)
public class MallAttributeBo extends BaseEntity {
/**
* 属性ID
*/
private Long id;
/**
* 模板ID(可选,绑定到模板)
*/
private Long templateId;
/**
* 属性名称
*/
@NotBlank(message = "属性名称不能为空")
private String name;
/**
* 属性类型(0文本 1数字 2日期 3枚举)
*/
@NotNull(message = "属性类型不能为空")
private Integer type;
/**
* 是否必填(0否 1是)
*/
private Integer required;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@NotNull(message = "状态不能为空")
private Integer status;
/**
* 备注
*/
private String remark;
}
@@ -0,0 +1,53 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.mall.product.domain.MallAttributeTemplate;
/**
* 属性模板业务对象 mall_attribute_template
*
* @author pengles
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MallAttributeTemplate.class, reverseConvertGenerate = false)
public class MallAttributeTemplateBo extends BaseEntity {
/**
* 模板ID
*/
private Long id;
/**
* 模板名称
*/
@NotBlank(message = "模板名称不能为空")
private String name;
/**
* 分类ID(可选,绑定到分类)
*/
private Long categoryId;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@NotNull(message = "状态不能为空")
private Integer status;
/**
* 备注
*/
private String remark;
}
@@ -0,0 +1,49 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.mall.product.domain.MallAttributeValue;
/**
* 属性值业务对象 mall_attribute_value
*
* @author pengles
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MallAttributeValue.class, reverseConvertGenerate = false)
public class MallAttributeValueBo extends BaseEntity {
/**
* 属性值ID
*/
private Long id;
/**
* 属性ID
*/
@NotNull(message = "属性ID不能为空")
private Long attributeId;
/**
* 属性值
*/
@NotBlank(message = "属性值不能为空")
private String value;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@NotNull(message = "状态不能为空")
private Integer status;
}
@@ -0,0 +1,53 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.mall.product.domain.MallBrand;
/**
* 品牌业务对象 mall_brand
*
* @author pengles
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MallBrand.class, reverseConvertGenerate = false)
public class MallBrandBo extends BaseEntity {
/**
* 品牌ID
*/
private Long id;
/**
* 品牌名称
*/
@NotBlank(message = "品牌名称不能为空")
private String name;
/**
* 品牌Logo
*/
private String logo;
/**
* 品牌描述
*/
private String description;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@NotNull(message = "状态不能为空")
private Integer status;
}
@@ -0,0 +1,58 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.mall.product.domain.MallCategory;
/**
* 商品分类业务对象 mall_category
*
* @author pengles
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MallCategory.class, reverseConvertGenerate = false)
public class MallCategoryBo extends BaseEntity {
/**
* 分类ID
*/
private Long id;
/**
* 分类名称
*/
@NotBlank(message = "分类名称不能为空")
private String name;
/**
* 父分类ID(0表示顶级)
*/
private Long parentId;
/**
* 分类级别(1一级 2二级 3三级)
*/
private Integer level;
/**
* 分类图标
*/
private String icon;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@NotNull(message = "状态不能为空")
private Integer status;
}
@@ -0,0 +1,47 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.mall.product.domain.MallProductAttribute;
/**
* 商品属性关联业务对象 mall_product_attribute
*
* @author pengles
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MallProductAttribute.class, reverseConvertGenerate = false)
public class MallProductAttributeBo extends BaseEntity {
/**
* ID
*/
private Long id;
/**
* 商品ID
*/
@NotNull(message = "商品ID不能为空")
private Long productId;
/**
* 属性ID
*/
@NotNull(message = "属性ID不能为空")
private Long attributeId;
/**
* 属性值ID(当属性类型为枚举时使用)
*/
private Long attributeValueId;
/**
* 属性值(当属性类型为文本/数字/日期时使用,或自定义值)
*/
private String value;
}
@@ -0,0 +1,82 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.mall.product.domain.MallProduct;
import java.io.Serial;
import java.io.Serializable;
/**
* 商品业务对象 mall_product
*
* @author pengles
*/
@Data
@AutoMapper(target = MallProduct.class, reverseConvertGenerate = false)
public class MallProductBo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 商品ID
*/
private Long id;
/**
* 商品名称
*/
private String name;
/**
* 分类ID
*/
private Long categoryId;
/**
* 品牌ID
*/
private Long brandId;
/**
* 封面图片
*/
private String coverUrl;
/**
* 商品图片(JSON数组)
*/
private String images;
/**
* 商品描述
*/
private String description;
/**
* 商品详情
*/
private String detail;
/**
* 状态(0上架 1下架)
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 销量
*/
private Integer salesCount;
/**
* 浏览量
*/
private Integer viewCount;
}
@@ -0,0 +1,72 @@
package org.dromara.mall.product.domain.bo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.mall.product.domain.MallSku;
import java.io.Serial;
import java.io.Serializable;
/**
* SKU业务对象 mall_sku
*
* @author pengles
*/
@Data
@AutoMapper(target = MallSku.class, reverseConvertGenerate = false)
public class MallSkuBo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* SKU ID
*/
private Long id;
/**
* 商品ID
*/
private Long productId;
/**
* SKU编码
*/
private String skuCode;
/**
* SKU名称
*/
private String name;
/**
* 价格(分)
*/
private Integer price;
/**
* 原价(分)
*/
private Integer originalPrice;
/**
* 库存
*/
private Integer stock;
/**
* SKU图片
*/
private String image;
/**
* 规格属性(JSON)
*/
private String specs;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
}
@@ -0,0 +1,74 @@
package org.dromara.mall.product.domain.vo;
import cn.idev.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import org.dromara.mall.product.domain.MallAttributeTemplate;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 属性模板视图对象 mall_attribute_template
*
* @author pengles
*/
@Data
@AutoMapper(target = MallAttributeTemplate.class)
public class MallAttributeTemplateVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 模板ID
*/
@ExcelProperty(value = "模板ID")
private Long id;
/**
* 模板名称
*/
@ExcelProperty(value = "模板名称")
private String name;
/**
* 分类ID(可选,绑定到分类)
*/
@ExcelProperty(value = "分类ID")
private Long categoryId;
/**
* 排序
*/
@ExcelProperty(value = "排序")
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=启用,1=禁用")
private Integer status;
/**
* 备注
*/
@ExcelProperty(value = "备注")
private String remark;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -0,0 +1,68 @@
package org.dromara.mall.product.domain.vo;
import cn.idev.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import org.dromara.mall.product.domain.MallAttributeValue;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 属性值视图对象 mall_attribute_value
*
* @author pengles
*/
@Data
@AutoMapper(target = MallAttributeValue.class)
public class MallAttributeValueVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 属性值ID
*/
@ExcelProperty(value = "属性值ID")
private Long id;
/**
* 属性ID
*/
@ExcelProperty(value = "属性ID")
private Long attributeId;
/**
* 属性值
*/
@ExcelProperty(value = "属性值")
private String value;
/**
* 排序
*/
@ExcelProperty(value = "排序")
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=启用,1=禁用")
private Integer status;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -0,0 +1,88 @@
package org.dromara.mall.product.domain.vo;
import cn.idev.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import org.dromara.mall.product.domain.MallAttribute;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 属性视图对象 mall_attribute
*
* @author pengles
*/
@Data
@AutoMapper(target = MallAttribute.class)
public class MallAttributeVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 属性ID
*/
@ExcelProperty(value = "属性ID")
private Long id;
/**
* 模板ID(可选,绑定到模板)
*/
@ExcelProperty(value = "模板ID")
private Long templateId;
/**
* 属性名称
*/
@ExcelProperty(value = "属性名称")
private String name;
/**
* 属性类型(0文本 1数字 2日期 3枚举)
*/
@ExcelProperty(value = "属性类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=文本,1=数字,2=日期,3=枚举")
private Integer type;
/**
* 是否必填(0否 1是)
*/
@ExcelProperty(value = "是否必填", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=否,1=是")
private Integer required;
/**
* 排序
*/
@ExcelProperty(value = "排序")
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=启用,1=禁用")
private Integer status;
/**
* 备注
*/
@ExcelProperty(value = "备注")
private String remark;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -0,0 +1,63 @@
package org.dromara.mall.product.domain.vo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.mall.product.domain.MallBrand;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 品牌视图对象 mall_brand
*
* @author pengles
*/
@Data
@AutoMapper(target = MallBrand.class)
public class MallBrandVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 品牌ID
*/
private Long id;
/**
* 品牌名称
*/
private String name;
/**
* 品牌Logo
*/
private String logo;
/**
* 品牌描述
*/
private String description;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -0,0 +1,74 @@
package org.dromara.mall.product.domain.vo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.mall.product.domain.MallCategory;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 商品分类视图对象 mall_category
*
* @author pengles
*/
@Data
@AutoMapper(target = MallCategory.class)
public class MallCategoryVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 分类ID
*/
private Long id;
/**
* 分类名称
*/
private String name;
/**
* 父分类ID(0表示顶级)
*/
private Long parentId;
/**
* 分类级别(1一级 2二级 3三级)
*/
private Integer level;
/**
* 分类图标
*/
private String icon;
/**
* 排序
*/
private Integer sort;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 子分类列表(用于树形结构)
*/
private List<MallCategoryVo> children;
}
@@ -0,0 +1,47 @@
package org.dromara.mall.product.domain.vo;
import lombok.Data;
import org.dromara.mall.product.domain.MallProductAttribute;
import io.github.linpeilie.annotations.AutoMapper;
import java.io.Serial;
import java.io.Serializable;
/**
* 商品属性关联视图对象 mall_product_attribute
*
* @author pengles
*/
@Data
@AutoMapper(target = MallProductAttribute.class)
public class MallProductAttributeVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID
*/
private Long id;
/**
* 商品ID
*/
private Long productId;
/**
* 属性ID
*/
private Long attributeId;
/**
* 属性值ID(当属性类型为枚举时使用)
*/
private Long attributeValueId;
/**
* 属性值(当属性类型为文本/数字/日期时使用,或自定义值)
*/
private String value;
}
@@ -0,0 +1,93 @@
package org.dromara.mall.product.domain.vo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.mall.product.domain.MallProduct;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 商品视图对象 mall_product
*
* @author pengles
*/
@Data
@AutoMapper(target = MallProduct.class)
public class MallProductVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 商品ID
*/
private Long id;
/**
* 商品名称
*/
private String name;
/**
* 分类ID
*/
private Long categoryId;
/**
* 品牌ID
*/
private Long brandId;
/**
* 封面图片
*/
private String coverUrl;
/**
* 商品图片(JSON数组)
*/
private String images;
/**
* 商品描述
*/
private String description;
/**
* 商品详情
*/
private String detail;
/**
* 状态(0上架 1下架)
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 销量
*/
private Integer salesCount;
/**
* 浏览量
*/
private Integer viewCount;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -0,0 +1,83 @@
package org.dromara.mall.product.domain.vo;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.mall.product.domain.MallSku;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* SKU视图对象 mall_sku
*
* @author pengles
*/
@Data
@AutoMapper(target = MallSku.class)
public class MallSkuVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* SKU ID
*/
private Long id;
/**
* 商品ID
*/
private Long productId;
/**
* SKU编码
*/
private String skuCode;
/**
* SKU名称
*/
private String name;
/**
* 价格(分)
*/
private Integer price;
/**
* 原价(分)
*/
private Integer originalPrice;
/**
* 库存
*/
private Integer stock;
/**
* SKU图片
*/
private String image;
/**
* 规格属性(JSON)
*/
private String specs;
/**
* 状态(0启用 1禁用)
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -0,0 +1,57 @@
package org.dromara.mall.product.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 属性类型枚举
*
* @author pengles
*/
@Getter
@AllArgsConstructor
public enum AttributeType {
/**
* 文本
*/
TEXT(0, "文本"),
/**
* 数字
*/
NUMBER(1, "数字"),
/**
* 日期
*/
DATE(2, "日期"),
/**
* 枚举
*/
ENUM(3, "枚举");
/**
* 类型值
*/
private final Integer value;
/**
* 类型名称
*/
private final String name;
/**
* 根据值获取枚举
*/
public static AttributeType getByValue(Integer value) {
for (AttributeType type : values()) {
if (type.getValue().equals(value)) {
return type;
}
}
return null;
}
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallAttribute;
import org.dromara.mall.product.domain.vo.MallAttributeVo;
/**
* 属性Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallAttributeMapper extends BaseMapperPlus<MallAttribute, MallAttributeVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallAttributeTemplate;
import org.dromara.mall.product.domain.vo.MallAttributeTemplateVo;
/**
* 属性模板Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallAttributeTemplateMapper extends BaseMapperPlus<MallAttributeTemplate, MallAttributeTemplateVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallAttributeValue;
import org.dromara.mall.product.domain.vo.MallAttributeValueVo;
/**
* 属性值Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallAttributeValueMapper extends BaseMapperPlus<MallAttributeValue, MallAttributeValueVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallBrand;
import org.dromara.mall.product.domain.vo.MallBrandVo;
/**
* 品牌Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallBrandMapper extends BaseMapperPlus<MallBrand, MallBrandVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallCategory;
import org.dromara.mall.product.domain.vo.MallCategoryVo;
/**
* 商品分类Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallCategoryMapper extends BaseMapperPlus<MallCategory, MallCategoryVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallProductAttribute;
import org.dromara.mall.product.domain.vo.MallProductAttributeVo;
/**
* 商品属性关联Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallProductAttributeMapper extends BaseMapperPlus<MallProductAttribute, MallProductAttributeVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallProduct;
import org.dromara.mall.product.domain.vo.MallProductVo;
/**
* 商品Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallProductMapper extends BaseMapperPlus<MallProduct, MallProductVo> {
}
@@ -0,0 +1,16 @@
package org.dromara.mall.product.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.mall.product.domain.MallSku;
import org.dromara.mall.product.domain.vo.MallSkuVo;
/**
* SKU Mapper接口
*
* @author pengles
*/
@Mapper
public interface MallSkuMapper extends BaseMapperPlus<MallSku, MallSkuVo> {
}
@@ -0,0 +1,53 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallAttributeBo;
import org.dromara.mall.product.domain.vo.MallAttributeVo;
import java.util.Collection;
import java.util.List;
/**
* 属性Service接口
*
* @author pengles
*/
public interface MallAttributeService {
/**
* 查询属性
*/
MallAttributeVo queryById(Long id);
/**
* 查询属性列表
*/
TableDataInfo<MallAttributeVo> queryPageList(MallAttributeBo bo, PageQuery pageQuery);
/**
* 查询属性列表
*/
List<MallAttributeVo> queryList(MallAttributeBo bo);
/**
* 根据模板ID查询属性列表
*/
List<MallAttributeVo> queryListByTemplateId(Long templateId);
/**
* 新增属性
*/
Boolean insertByBo(MallAttributeBo bo);
/**
* 修改属性
*/
Boolean updateByBo(MallAttributeBo bo);
/**
* 校验并批量删除属性信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,48 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallAttributeTemplateBo;
import org.dromara.mall.product.domain.vo.MallAttributeTemplateVo;
import java.util.Collection;
import java.util.List;
/**
* 属性模板Service接口
*
* @author pengles
*/
public interface MallAttributeTemplateService {
/**
* 查询属性模板
*/
MallAttributeTemplateVo queryById(Long id);
/**
* 查询属性模板列表
*/
TableDataInfo<MallAttributeTemplateVo> queryPageList(MallAttributeTemplateBo bo, PageQuery pageQuery);
/**
* 查询属性模板列表
*/
List<MallAttributeTemplateVo> queryList(MallAttributeTemplateBo bo);
/**
* 新增属性模板
*/
Boolean insertByBo(MallAttributeTemplateBo bo);
/**
* 修改属性模板
*/
Boolean updateByBo(MallAttributeTemplateBo bo);
/**
* 校验并批量删除属性模板信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,53 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallAttributeValueBo;
import org.dromara.mall.product.domain.vo.MallAttributeValueVo;
import java.util.Collection;
import java.util.List;
/**
* 属性值Service接口
*
* @author pengles
*/
public interface MallAttributeValueService {
/**
* 查询属性值
*/
MallAttributeValueVo queryById(Long id);
/**
* 查询属性值列表
*/
TableDataInfo<MallAttributeValueVo> queryPageList(MallAttributeValueBo bo, PageQuery pageQuery);
/**
* 查询属性值列表
*/
List<MallAttributeValueVo> queryList(MallAttributeValueBo bo);
/**
* 根据属性ID查询属性值列表
*/
List<MallAttributeValueVo> queryListByAttributeId(Long attributeId);
/**
* 新增属性值
*/
Boolean insertByBo(MallAttributeValueBo bo);
/**
* 修改属性值
*/
Boolean updateByBo(MallAttributeValueBo bo);
/**
* 校验并批量删除属性值信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,48 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallBrandBo;
import org.dromara.mall.product.domain.vo.MallBrandVo;
import java.util.Collection;
import java.util.List;
/**
* 品牌Service接口
*
* @author pengles
*/
public interface MallBrandService {
/**
* 查询品牌
*/
MallBrandVo queryById(Long id);
/**
* 查询品牌列表
*/
TableDataInfo<MallBrandVo> queryPageList(MallBrandBo bo, PageQuery pageQuery);
/**
* 查询品牌列表
*/
List<MallBrandVo> queryList(MallBrandBo bo);
/**
* 新增品牌
*/
Boolean insertByBo(MallBrandBo bo);
/**
* 修改品牌
*/
Boolean updateByBo(MallBrandBo bo);
/**
* 校验并批量删除品牌信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,53 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallCategoryBo;
import org.dromara.mall.product.domain.vo.MallCategoryVo;
import java.util.Collection;
import java.util.List;
/**
* 商品分类Service接口
*
* @author pengles
*/
public interface MallCategoryService {
/**
* 查询商品分类
*/
MallCategoryVo queryById(Long id);
/**
* 查询商品分类列表
*/
TableDataInfo<MallCategoryVo> queryPageList(MallCategoryBo bo, PageQuery pageQuery);
/**
* 查询商品分类列表
*/
List<MallCategoryVo> queryList(MallCategoryBo bo);
/**
* 查询商品分类树形列表
*/
List<MallCategoryVo> queryTreeList();
/**
* 新增商品分类
*/
Boolean insertByBo(MallCategoryBo bo);
/**
* 修改商品分类
*/
Boolean updateByBo(MallCategoryBo bo);
/**
* 校验并批量删除商品分类信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,56 @@
package org.dromara.mall.product.service;
import org.dromara.mall.product.domain.bo.MallProductAttributeBo;
import org.dromara.mall.product.domain.vo.MallProductAttributeVo;
import java.util.Collection;
import java.util.List;
/**
* 商品属性关联Service接口
*
* @author pengles
*/
public interface MallProductAttributeService {
/**
* 查询商品属性关联
*/
MallProductAttributeVo queryById(Long id);
/**
* 根据商品ID查询商品属性关联列表
*/
List<MallProductAttributeVo> queryListByProductId(Long productId);
/**
* 新增商品属性关联
*/
Boolean insertByBo(MallProductAttributeBo bo);
/**
* 批量新增商品属性关联
*/
Boolean insertBatch(List<MallProductAttributeBo> list);
/**
* 修改商品属性关联
*/
Boolean updateByBo(MallProductAttributeBo bo);
/**
* 批量删除商品属性关联信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 根据商品ID删除商品属性关联
*/
Boolean deleteByProductId(Long productId);
/**
* 保存商品属性关联(先删除旧的,再插入新的)
*/
Boolean saveProductAttributes(Long productId, List<MallProductAttributeBo> list);
}
@@ -0,0 +1,48 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallProductBo;
import org.dromara.mall.product.domain.vo.MallProductVo;
import java.util.Collection;
import java.util.List;
/**
* 商品Service接口
*
* @author pengles
*/
public interface MallProductService {
/**
* 查询商品
*/
MallProductVo queryById(Long id);
/**
* 查询商品列表
*/
TableDataInfo<MallProductVo> queryPageList(MallProductBo bo, PageQuery pageQuery);
/**
* 查询商品列表
*/
List<MallProductVo> queryList(MallProductBo bo);
/**
* 新增商品
*/
Boolean insertByBo(MallProductBo bo);
/**
* 修改商品
*/
Boolean updateByBo(MallProductBo bo);
/**
* 校验并批量删除商品信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,53 @@
package org.dromara.mall.product.service;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.bo.MallSkuBo;
import org.dromara.mall.product.domain.vo.MallSkuVo;
import java.util.Collection;
import java.util.List;
/**
* SKU Service接口
*
* @author pengles
*/
public interface MallSkuService {
/**
* 查询SKU
*/
MallSkuVo queryById(Long id);
/**
* 查询SKU列表
*/
TableDataInfo<MallSkuVo> queryPageList(MallSkuBo bo, PageQuery pageQuery);
/**
* 查询SKU列表
*/
List<MallSkuVo> queryList(MallSkuBo bo);
/**
* 根据商品ID查询SKU列表
*/
List<MallSkuVo> queryListByProductId(Long productId);
/**
* 新增SKU
*/
Boolean insertByBo(MallSkuBo bo);
/**
* 修改SKU
*/
Boolean updateByBo(MallSkuBo bo);
/**
* 校验并批量删除SKU信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}
@@ -0,0 +1,167 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallAttribute;
import org.dromara.mall.product.domain.bo.MallAttributeBo;
import org.dromara.mall.product.domain.vo.MallAttributeVo;
import org.dromara.mall.product.mapper.MallAttributeMapper;
import org.dromara.mall.product.service.MallAttributeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 属性Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallAttributeServiceImpl implements MallAttributeService {
private final MallAttributeMapper baseMapper;
/**
* 查询属性
*/
@Override
public MallAttributeVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询属性列表
*/
@Override
public TableDataInfo<MallAttributeVo> queryPageList(MallAttributeBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallAttribute> lqw = buildQueryWrapper(bo);
Page<MallAttributeVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询属性列表
*/
@Override
public List<MallAttributeVo> queryList(MallAttributeBo bo) {
LambdaQueryWrapper<MallAttribute> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
/**
* 根据模板ID查询属性列表
*/
@Override
public List<MallAttributeVo> queryListByTemplateId(Long templateId) {
LambdaQueryWrapper<MallAttribute> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallAttribute::getTemplateId, templateId);
lqw.eq(MallAttribute::getStatus, 0);
lqw.orderByAsc(MallAttribute::getSort);
lqw.orderByAsc(MallAttribute::getId);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<MallAttribute> buildQueryWrapper(MallAttributeBo bo) {
LambdaQueryWrapper<MallAttribute> lqw = new LambdaQueryWrapper<>();
lqw.like(StringUtils.isNotBlank(bo.getName()), MallAttribute::getName, bo.getName());
lqw.eq(bo.getTemplateId() != null, MallAttribute::getTemplateId, bo.getTemplateId());
lqw.eq(bo.getType() != null, MallAttribute::getType, bo.getType());
lqw.eq(bo.getStatus() != null, MallAttribute::getStatus, bo.getStatus());
lqw.orderByAsc(MallAttribute::getSort);
lqw.orderByAsc(MallAttribute::getId);
return lqw;
}
/**
* 新增属性
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallAttributeBo bo) {
MallAttribute add = MapstructUtils.convert(bo, MallAttribute.class);
validEntityBeforeSave(add);
// 设置默认值
if (add.getRequired() == null) {
add.setRequired(0);
}
if (add.getSort() == null) {
add.setSort(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改属性
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallAttributeBo bo) {
MallAttribute update = MapstructUtils.convert(bo, MallAttribute.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallAttribute entity) {
if (StringUtils.isBlank(entity.getName())) {
throw new ServiceException("属性名称不能为空");
}
if (entity.getType() == null) {
throw new ServiceException("属性类型不能为空");
}
if (entity.getType() < 0 || entity.getType() > 3) {
throw new ServiceException("属性类型不合法");
}
// 检查属性名称是否重复(在同一模板下)
LambdaQueryWrapper<MallAttribute> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallAttribute::getName, entity.getName());
if (entity.getTemplateId() != null) {
lqw.eq(MallAttribute::getTemplateId, entity.getTemplateId());
}
if (entity.getId() != null) {
lqw.ne(MallAttribute::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("属性名称已存在");
}
}
/**
* 批量删除属性
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
for (Long id : ids) {
MallAttribute attribute = baseMapper.selectById(id);
if (attribute == null) {
throw new ServiceException("属性不存在");
}
// 可以后续添加属性值表关联查询,检查是否有关联的属性值
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,141 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallAttributeTemplate;
import org.dromara.mall.product.domain.bo.MallAttributeTemplateBo;
import org.dromara.mall.product.domain.vo.MallAttributeTemplateVo;
import org.dromara.mall.product.mapper.MallAttributeTemplateMapper;
import org.dromara.mall.product.service.MallAttributeTemplateService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 属性模板Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallAttributeTemplateServiceImpl implements MallAttributeTemplateService {
private final MallAttributeTemplateMapper baseMapper;
/**
* 查询属性模板
*/
@Override
public MallAttributeTemplateVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询属性模板列表
*/
@Override
public TableDataInfo<MallAttributeTemplateVo> queryPageList(MallAttributeTemplateBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallAttributeTemplate> lqw = buildQueryWrapper(bo);
Page<MallAttributeTemplateVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询属性模板列表
*/
@Override
public List<MallAttributeTemplateVo> queryList(MallAttributeTemplateBo bo) {
LambdaQueryWrapper<MallAttributeTemplate> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<MallAttributeTemplate> buildQueryWrapper(MallAttributeTemplateBo bo) {
LambdaQueryWrapper<MallAttributeTemplate> lqw = new LambdaQueryWrapper<>();
lqw.like(StringUtils.isNotBlank(bo.getName()), MallAttributeTemplate::getName, bo.getName());
lqw.eq(bo.getCategoryId() != null, MallAttributeTemplate::getCategoryId, bo.getCategoryId());
lqw.eq(bo.getStatus() != null, MallAttributeTemplate::getStatus, bo.getStatus());
lqw.orderByAsc(MallAttributeTemplate::getSort);
lqw.orderByAsc(MallAttributeTemplate::getId);
return lqw;
}
/**
* 新增属性模板
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallAttributeTemplateBo bo) {
MallAttributeTemplate add = MapstructUtils.convert(bo, MallAttributeTemplate.class);
validEntityBeforeSave(add);
// 设置默认值
if (add.getSort() == null) {
add.setSort(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改属性模板
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallAttributeTemplateBo bo) {
MallAttributeTemplate update = MapstructUtils.convert(bo, MallAttributeTemplate.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallAttributeTemplate entity) {
if (StringUtils.isBlank(entity.getName())) {
throw new ServiceException("模板名称不能为空");
}
// 检查模板名称是否重复
LambdaQueryWrapper<MallAttributeTemplate> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallAttributeTemplate::getName, entity.getName());
if (entity.getId() != null) {
lqw.ne(MallAttributeTemplate::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("模板名称已存在");
}
}
/**
* 批量删除属性模板
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
for (Long id : ids) {
MallAttributeTemplate template = baseMapper.selectById(id);
if (template == null) {
throw new ServiceException("属性模板不存在");
}
// 可以后续添加属性表关联查询,检查是否有关联的属性
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,158 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallAttributeValue;
import org.dromara.mall.product.domain.bo.MallAttributeValueBo;
import org.dromara.mall.product.domain.vo.MallAttributeValueVo;
import org.dromara.mall.product.mapper.MallAttributeValueMapper;
import org.dromara.mall.product.service.MallAttributeValueService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 属性值Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallAttributeValueServiceImpl implements MallAttributeValueService {
private final MallAttributeValueMapper baseMapper;
/**
* 查询属性值
*/
@Override
public MallAttributeValueVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询属性值列表
*/
@Override
public TableDataInfo<MallAttributeValueVo> queryPageList(MallAttributeValueBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallAttributeValue> lqw = buildQueryWrapper(bo);
Page<MallAttributeValueVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询属性值列表
*/
@Override
public List<MallAttributeValueVo> queryList(MallAttributeValueBo bo) {
LambdaQueryWrapper<MallAttributeValue> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
/**
* 根据属性ID查询属性值列表
*/
@Override
public List<MallAttributeValueVo> queryListByAttributeId(Long attributeId) {
LambdaQueryWrapper<MallAttributeValue> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallAttributeValue::getAttributeId, attributeId);
lqw.eq(MallAttributeValue::getStatus, 0);
lqw.orderByAsc(MallAttributeValue::getSort);
lqw.orderByAsc(MallAttributeValue::getId);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<MallAttributeValue> buildQueryWrapper(MallAttributeValueBo bo) {
LambdaQueryWrapper<MallAttributeValue> lqw = new LambdaQueryWrapper<>();
lqw.eq(bo.getAttributeId() != null, MallAttributeValue::getAttributeId, bo.getAttributeId());
lqw.like(StringUtils.isNotBlank(bo.getValue()), MallAttributeValue::getValue, bo.getValue());
lqw.eq(bo.getStatus() != null, MallAttributeValue::getStatus, bo.getStatus());
lqw.orderByAsc(MallAttributeValue::getSort);
lqw.orderByAsc(MallAttributeValue::getId);
return lqw;
}
/**
* 新增属性值
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallAttributeValueBo bo) {
MallAttributeValue add = MapstructUtils.convert(bo, MallAttributeValue.class);
validEntityBeforeSave(add);
// 设置默认值
if (add.getSort() == null) {
add.setSort(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改属性值
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallAttributeValueBo bo) {
MallAttributeValue update = MapstructUtils.convert(bo, MallAttributeValue.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallAttributeValue entity) {
if (entity.getAttributeId() == null) {
throw new ServiceException("属性ID不能为空");
}
if (StringUtils.isBlank(entity.getValue())) {
throw new ServiceException("属性值不能为空");
}
// 检查属性值是否重复(在同一属性下)
LambdaQueryWrapper<MallAttributeValue> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallAttributeValue::getAttributeId, entity.getAttributeId());
lqw.eq(MallAttributeValue::getValue, entity.getValue());
if (entity.getId() != null) {
lqw.ne(MallAttributeValue::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("属性值已存在");
}
}
/**
* 批量删除属性值
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
for (Long id : ids) {
MallAttributeValue value = baseMapper.selectById(id);
if (value == null) {
throw new ServiceException("属性值不存在");
}
// 可以后续添加商品属性关联表查询,检查是否有关联的商品属性
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,141 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallBrand;
import org.dromara.mall.product.domain.bo.MallBrandBo;
import org.dromara.mall.product.domain.vo.MallBrandVo;
import org.dromara.mall.product.mapper.MallBrandMapper;
import org.dromara.mall.product.service.MallBrandService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 品牌Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallBrandServiceImpl implements MallBrandService {
private final MallBrandMapper baseMapper;
/**
* 查询品牌
*/
@Override
public MallBrandVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询品牌列表
*/
@Override
public TableDataInfo<MallBrandVo> queryPageList(MallBrandBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallBrand> lqw = buildQueryWrapper(bo);
Page<MallBrandVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询品牌列表
*/
@Override
public List<MallBrandVo> queryList(MallBrandBo bo) {
LambdaQueryWrapper<MallBrand> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<MallBrand> buildQueryWrapper(MallBrandBo bo) {
LambdaQueryWrapper<MallBrand> lqw = new LambdaQueryWrapper<>();
lqw.like(StringUtils.isNotBlank(bo.getName()), MallBrand::getName, bo.getName());
lqw.eq(bo.getStatus() != null, MallBrand::getStatus, bo.getStatus());
lqw.orderByAsc(MallBrand::getSort);
lqw.orderByAsc(MallBrand::getId);
return lqw;
}
/**
* 新增品牌
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallBrandBo bo) {
MallBrand add = MapstructUtils.convert(bo, MallBrand.class);
validEntityBeforeSave(add);
// 设置默认值
if (add.getSort() == null) {
add.setSort(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改品牌
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallBrandBo bo) {
MallBrand update = MapstructUtils.convert(bo, MallBrand.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallBrand entity) {
if (StringUtils.isBlank(entity.getName())) {
throw new ServiceException("品牌名称不能为空");
}
// 检查品牌名称是否重复
LambdaQueryWrapper<MallBrand> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallBrand::getName, entity.getName());
if (entity.getId() != null) {
lqw.ne(MallBrand::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("品牌名称已存在");
}
}
/**
* 批量删除品牌
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
// 检查是否有关联的商品(这里需要关联商品表查询,暂时跳过)
// 可以后续添加商品表关联查询
for (Long id : ids) {
MallBrand brand = baseMapper.selectById(id);
if (brand == null) {
throw new ServiceException("品牌不存在");
}
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,250 @@
package org.dromara.mall.product.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallCategory;
import org.dromara.mall.product.domain.bo.MallCategoryBo;
import org.dromara.mall.product.domain.vo.MallCategoryVo;
import org.dromara.mall.product.mapper.MallCategoryMapper;
import org.dromara.mall.product.service.MallCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* 商品分类Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallCategoryServiceImpl implements MallCategoryService {
private final MallCategoryMapper baseMapper;
/**
* 查询商品分类
*/
@Override
public MallCategoryVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询商品分类列表
*/
@Override
public TableDataInfo<MallCategoryVo> queryPageList(MallCategoryBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallCategory> lqw = buildQueryWrapper(bo);
Page<MallCategoryVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询商品分类列表
*/
@Override
public List<MallCategoryVo> queryList(MallCategoryBo bo) {
LambdaQueryWrapper<MallCategory> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
/**
* 查询商品分类树形列表
*/
@Override
public List<MallCategoryVo> queryTreeList() {
MallCategoryBo bo = new MallCategoryBo();
bo.setStatus(0); // 只查询启用的分类
List<MallCategoryVo> list = queryList(bo);
return buildTree(list);
}
private LambdaQueryWrapper<MallCategory> buildQueryWrapper(MallCategoryBo bo) {
LambdaQueryWrapper<MallCategory> lqw = new LambdaQueryWrapper<>();
lqw.like(StringUtils.isNotBlank(bo.getName()), MallCategory::getName, bo.getName());
lqw.eq(bo.getParentId() != null, MallCategory::getParentId, bo.getParentId());
lqw.eq(bo.getLevel() != null, MallCategory::getLevel, bo.getLevel());
lqw.eq(bo.getStatus() != null, MallCategory::getStatus, bo.getStatus());
lqw.orderByAsc(MallCategory::getSort);
lqw.orderByAsc(MallCategory::getId);
return lqw;
}
/**
* 构建树形结构
*/
private List<MallCategoryVo> buildTree(List<MallCategoryVo> list) {
if (CollUtil.isEmpty(list)) {
return new ArrayList<>();
}
// 按父ID分组
Map<Long, List<MallCategoryVo>> childrenMap = list.stream()
.filter(item -> item.getParentId() != null && item.getParentId() != 0)
.collect(Collectors.groupingBy(MallCategoryVo::getParentId));
// 设置子节点
list.forEach(item -> {
List<MallCategoryVo> children = childrenMap.get(item.getId());
item.setChildren(children != null ? children : new ArrayList<>());
});
// 返回顶级节点
return list.stream()
.filter(item -> item.getParentId() == null || item.getParentId() == 0)
.sorted(Comparator.comparing(MallCategoryVo::getSort, Comparator.nullsLast(Comparator.naturalOrder())))
.collect(Collectors.toList());
}
/**
* 新增商品分类
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallCategoryBo bo) {
MallCategory add = MapstructUtils.convert(bo, MallCategory.class);
validEntityBeforeSave(add);
// 设置父级ID和级别
if (add.getParentId() == null || add.getParentId() == 0) {
add.setParentId(0L);
add.setLevel(1);
} else {
// 查询父分类
MallCategory parent = baseMapper.selectById(add.getParentId());
if (parent == null) {
throw new ServiceException("父分类不存在");
}
if (parent.getStatus() != 0) {
throw new ServiceException("父分类已禁用,不能添加子分类");
}
if (parent.getLevel() >= 3) {
throw new ServiceException("分类级别不能超过3级");
}
add.setLevel(parent.getLevel() + 1);
}
// 设置默认值
if (add.getSort() == null) {
add.setSort(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改商品分类
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallCategoryBo bo) {
MallCategory update = MapstructUtils.convert(bo, MallCategory.class);
validEntityBeforeSave(update);
// 不能将父分类设置为自己的子分类
if (update.getParentId() != null && update.getParentId() != 0) {
if (update.getId().equals(update.getParentId())) {
throw new ServiceException("不能将分类设置为自己的父分类");
}
// 检查是否会形成循环
if (hasCircularReference(update.getId(), update.getParentId())) {
throw new ServiceException("不能将分类设置为自己的子分类的子分类");
}
// 查询父分类
MallCategory parent = baseMapper.selectById(update.getParentId());
if (parent == null) {
throw new ServiceException("父分类不存在");
}
if (parent.getLevel() >= 3) {
throw new ServiceException("分类级别不能超过3级");
}
update.setLevel(parent.getLevel() + 1);
} else {
update.setParentId(0L);
update.setLevel(1);
}
return baseMapper.updateById(update) > 0;
}
/**
* 检查是否存在循环引用
*/
private boolean hasCircularReference(Long id, Long parentId) {
Long currentParentId = parentId;
Set<Long> visited = new HashSet<>();
visited.add(id);
while (currentParentId != null && currentParentId != 0) {
if (visited.contains(currentParentId)) {
return true;
}
visited.add(currentParentId);
MallCategory parent = baseMapper.selectById(currentParentId);
if (parent == null) {
break;
}
currentParentId = parent.getParentId();
}
return false;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallCategory entity) {
if (StringUtils.isBlank(entity.getName())) {
throw new ServiceException("分类名称不能为空");
}
// 检查同级分类名称是否重复
LambdaQueryWrapper<MallCategory> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallCategory::getName, entity.getName());
lqw.eq(entity.getParentId() != null, MallCategory::getParentId, entity.getParentId());
if (entity.getId() != null) {
lqw.ne(MallCategory::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("同级分类名称不能重复");
}
}
/**
* 批量删除商品分类
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
// 检查是否存在子分类
for (Long id : ids) {
LambdaQueryWrapper<MallCategory> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallCategory::getParentId, id);
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("存在子分类,不能删除");
}
// 检查是否有关联的商品(这里需要关联商品表查询,暂时跳过)
// 可以后续添加商品表关联查询
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,163 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.mall.product.domain.MallProductAttribute;
import org.dromara.mall.product.domain.bo.MallProductAttributeBo;
import org.dromara.mall.product.domain.vo.MallProductAttributeVo;
import org.dromara.mall.product.mapper.MallProductAttributeMapper;
import org.dromara.mall.product.service.MallProductAttributeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 商品属性关联Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallProductAttributeServiceImpl implements MallProductAttributeService {
private final MallProductAttributeMapper baseMapper;
/**
* 查询商品属性关联
*/
@Override
public MallProductAttributeVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 根据商品ID查询商品属性关联列表
*/
@Override
public List<MallProductAttributeVo> queryListByProductId(Long productId) {
LambdaQueryWrapper<MallProductAttribute> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallProductAttribute::getProductId, productId);
lqw.orderByAsc(MallProductAttribute::getId);
return baseMapper.selectVoList(lqw);
}
/**
* 新增商品属性关联
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallProductAttributeBo bo) {
MallProductAttribute add = MapstructUtils.convert(bo, MallProductAttribute.class);
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 批量新增商品属性关联
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertBatch(List<MallProductAttributeBo> list) {
if (list == null || list.isEmpty()) {
return true;
}
List<MallProductAttribute> entities = MapstructUtils.convert(list, MallProductAttribute.class);
for (MallProductAttribute entity : entities) {
validEntityBeforeSave(entity);
}
// 批量插入
for (MallProductAttribute entity : entities) {
baseMapper.insert(entity);
}
return true;
}
/**
* 修改商品属性关联
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallProductAttributeBo bo) {
MallProductAttribute update = MapstructUtils.convert(bo, MallProductAttribute.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallProductAttribute entity) {
if (entity.getProductId() == null) {
throw new ServiceException("商品ID不能为空");
}
if (entity.getAttributeId() == null) {
throw new ServiceException("属性ID不能为空");
}
// 检查同一商品下是否已有相同的属性
LambdaQueryWrapper<MallProductAttribute> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallProductAttribute::getProductId, entity.getProductId());
lqw.eq(MallProductAttribute::getAttributeId, entity.getAttributeId());
if (entity.getId() != null) {
lqw.ne(MallProductAttribute::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("商品已存在该属性");
}
}
/**
* 批量删除商品属性关联
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
for (Long id : ids) {
MallProductAttribute attribute = baseMapper.selectById(id);
if (attribute == null) {
throw new ServiceException("商品属性关联不存在");
}
}
}
return baseMapper.deleteByIds(ids) > 0;
}
/**
* 根据商品ID删除商品属性关联
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteByProductId(Long productId) {
LambdaQueryWrapper<MallProductAttribute> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallProductAttribute::getProductId, productId);
return baseMapper.delete(lqw) >= 0;
}
/**
* 保存商品属性关联(先删除旧的,再插入新的)
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean saveProductAttributes(Long productId, List<MallProductAttributeBo> list) {
// 删除旧的关联
deleteByProductId(productId);
// 插入新的关联
if (list != null && !list.isEmpty()) {
for (MallProductAttributeBo bo : list) {
bo.setProductId(productId);
}
return insertBatch(list);
}
return true;
}
}
@@ -0,0 +1,137 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallProduct;
import org.dromara.mall.product.domain.bo.MallProductBo;
import org.dromara.mall.product.domain.vo.MallProductVo;
import org.dromara.mall.product.mapper.MallProductMapper;
import org.dromara.mall.product.service.MallProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* 商品Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallProductServiceImpl implements MallProductService {
private final MallProductMapper baseMapper;
/**
* 查询商品
*/
@Override
public MallProductVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询商品列表
*/
@Override
public TableDataInfo<MallProductVo> queryPageList(MallProductBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallProduct> lqw = buildQueryWrapper(bo);
Page<MallProductVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询商品列表
*/
@Override
public List<MallProductVo> queryList(MallProductBo bo) {
LambdaQueryWrapper<MallProduct> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<MallProduct> buildQueryWrapper(MallProductBo bo) {
LambdaQueryWrapper<MallProduct> lqw = new LambdaQueryWrapper<>();
lqw.like(StringUtils.isNotBlank(bo.getName()), MallProduct::getName, bo.getName());
lqw.eq(bo.getCategoryId() != null, MallProduct::getCategoryId, bo.getCategoryId());
lqw.eq(bo.getBrandId() != null, MallProduct::getBrandId, bo.getBrandId());
lqw.eq(bo.getStatus() != null, MallProduct::getStatus, bo.getStatus());
lqw.orderByDesc(MallProduct::getSort);
lqw.orderByDesc(MallProduct::getId);
return lqw;
}
/**
* 新增商品
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallProductBo bo) {
MallProduct add = MapstructUtils.convert(bo, MallProduct.class);
validEntityBeforeSave(add);
// 设置默认值
if (add.getSort() == null) {
add.setSort(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
if (add.getSalesCount() == null) {
add.setSalesCount(0);
}
if (add.getViewCount() == null) {
add.setViewCount(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改商品
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallProductBo bo) {
MallProduct update = MapstructUtils.convert(bo, MallProduct.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallProduct entity) {
if (StringUtils.isBlank(entity.getName())) {
throw new ServiceException("商品名称不能为空");
}
}
/**
* 批量删除商品
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
for (Long id : ids) {
MallProduct product = baseMapper.selectById(id);
if (product == null) {
throw new ServiceException("商品不存在");
}
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,158 @@
package org.dromara.mall.product.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.mall.product.domain.MallSku;
import org.dromara.mall.product.domain.bo.MallSkuBo;
import org.dromara.mall.product.domain.vo.MallSkuVo;
import org.dromara.mall.product.mapper.MallSkuMapper;
import org.dromara.mall.product.service.MallSkuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.List;
/**
* SKU Service业务层处理
*
* @author pengles
*/
@RequiredArgsConstructor
@Service
public class MallSkuServiceImpl implements MallSkuService {
private final MallSkuMapper baseMapper;
/**
* 查询SKU
*/
@Override
public MallSkuVo queryById(Long id) {
return baseMapper.selectVoById(id);
}
/**
* 查询SKU列表
*/
@Override
public TableDataInfo<MallSkuVo> queryPageList(MallSkuBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<MallSku> lqw = buildQueryWrapper(bo);
Page<MallSkuVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
/**
* 查询SKU列表
*/
@Override
public List<MallSkuVo> queryList(MallSkuBo bo) {
LambdaQueryWrapper<MallSku> lqw = buildQueryWrapper(bo);
return baseMapper.selectVoList(lqw);
}
/**
* 根据商品ID查询SKU列表
*/
@Override
public List<MallSkuVo> queryListByProductId(Long productId) {
LambdaQueryWrapper<MallSku> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallSku::getProductId, productId);
lqw.eq(MallSku::getStatus, 0); // 只查询启用的SKU
lqw.orderByAsc(MallSku::getId);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<MallSku> buildQueryWrapper(MallSkuBo bo) {
LambdaQueryWrapper<MallSku> lqw = new LambdaQueryWrapper<>();
lqw.eq(bo.getProductId() != null, MallSku::getProductId, bo.getProductId());
lqw.eq(StringUtils.isNotBlank(bo.getSkuCode()), MallSku::getSkuCode, bo.getSkuCode());
lqw.like(StringUtils.isNotBlank(bo.getName()), MallSku::getName, bo.getName());
lqw.eq(bo.getStatus() != null, MallSku::getStatus, bo.getStatus());
lqw.orderByAsc(MallSku::getId);
return lqw;
}
/**
* 新增SKU
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MallSkuBo bo) {
MallSku add = MapstructUtils.convert(bo, MallSku.class);
validEntityBeforeSave(add);
// 设置默认值
if (add.getStock() == null) {
add.setStock(0);
}
if (add.getStatus() == null) {
add.setStatus(0);
}
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setId(add.getId());
}
return flag;
}
/**
* 修改SKU
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateByBo(MallSkuBo bo) {
MallSku update = MapstructUtils.convert(bo, MallSku.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(MallSku entity) {
if (entity.getProductId() == null) {
throw new ServiceException("商品ID不能为空");
}
if (StringUtils.isBlank(entity.getSkuCode())) {
throw new ServiceException("SKU编码不能为空");
}
if (entity.getPrice() == null) {
throw new ServiceException("价格不能为空");
}
// 检查SKU编码是否重复
LambdaQueryWrapper<MallSku> lqw = new LambdaQueryWrapper<>();
lqw.eq(MallSku::getSkuCode, entity.getSkuCode());
if (entity.getId() != null) {
lqw.ne(MallSku::getId, entity.getId());
}
Long count = baseMapper.selectCount(lqw);
if (count > 0) {
throw new ServiceException("SKU编码已存在");
}
}
/**
* 批量删除SKU
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
for (Long id : ids) {
MallSku sku = baseMapper.selectById(id);
if (sku == null) {
throw new ServiceException("SKU不存在");
}
}
}
return baseMapper.deleteByIds(ids) > 0;
}
}
@@ -0,0 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.dromara.mall.product.config.MallProductAutoConfiguration