[fix]修改商品 增加business层
This commit is contained in:
parent
83084e2f78
commit
ebc18ac990
@ -0,0 +1,62 @@
|
||||
package org.dromara.common.web.core;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.domain.BaseBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wangqx
|
||||
* @description TODO
|
||||
* @date 2022/6/16
|
||||
*/
|
||||
@Data
|
||||
public class BusinessImpl<S extends IService<T>, C extends BaseConverter<V,B,T>,V,B extends BaseBO,T> implements IBusiness<V, B> {
|
||||
@Autowired
|
||||
protected S service;
|
||||
@Autowired
|
||||
protected C converter;
|
||||
|
||||
public BusinessImpl() {
|
||||
}
|
||||
public BusinessImpl(S service, C converter) {
|
||||
this.service = service;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(B bo) {
|
||||
T t=converter.toPo(bo);
|
||||
return service.save(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Serializable id) {
|
||||
T t= service.getById(id);
|
||||
return converter.toVO(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<V> list(B b) {
|
||||
List<T> tList=service.list(b.toWrapper());
|
||||
|
||||
return converter.toVO(tList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<V> page(B b) {
|
||||
return converter.toVO(service.page(b.getPage(),b.toWrapper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Serializable id) {
|
||||
service.removeById(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package org.dromara.common.web.core;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wangqx
|
||||
* @description TODO
|
||||
* @date 2022/6/16
|
||||
*/
|
||||
public interface IBusiness<V,B>{
|
||||
/**
|
||||
* 保存
|
||||
* @param t
|
||||
* @return
|
||||
*/
|
||||
boolean save(B t);
|
||||
|
||||
V get(Serializable id);
|
||||
|
||||
List<V> list(B d);
|
||||
|
||||
IPage<V> page( B d);
|
||||
|
||||
boolean delete(Serializable id);
|
||||
}
|
@ -39,12 +39,6 @@ public class VlogBO extends BaseBO {
|
||||
private Integer cityCode;
|
||||
private String firstFrameImg;
|
||||
|
||||
@ApiModelProperty("当前页数")
|
||||
private Long current;
|
||||
|
||||
@ApiModelProperty("分页大小")
|
||||
private Long size;
|
||||
|
||||
@ApiModelProperty("排序字段,例如 commentCounts, likeCounts, reason")
|
||||
private String Column;
|
||||
|
||||
|
@ -90,13 +90,6 @@ public class VlogPullServiceImpl implements IVlogPullService {
|
||||
@Override
|
||||
public void pullFromTencentCloud(VlogBO vlogBO) {
|
||||
try {
|
||||
// 验证分页参数
|
||||
if (vlogBO.getCurrent() < 1) {
|
||||
vlogBO.setCurrent(1L);
|
||||
}
|
||||
if (vlogBO.getSize() < 1 || vlogBO.getSize() > 50) {
|
||||
vlogBO.setSize(10L);
|
||||
}
|
||||
|
||||
// 如果有模糊查询条件、时间区间条件,或者有排序条件,则只查询数据库
|
||||
if (StringUtils.isNotBlank(vlogBO.getMobile())
|
||||
@ -139,7 +132,7 @@ public class VlogPullServiceImpl implements IVlogPullService {
|
||||
|
||||
// 设置分页参数
|
||||
req.setOffset(offset);
|
||||
req.setLimit(vlogBO.getSize());
|
||||
req.setLimit(vlogBO.getSize().longValue());
|
||||
|
||||
// 设置排序
|
||||
SortBy sort = new SortBy();
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.wzj.soopin.goods.business;
|
||||
|
||||
import com.wzj.soopin.goods.domain.bo.ProductBo;
|
||||
import com.wzj.soopin.goods.domain.vo.ProductVO;
|
||||
import org.dromara.common.web.core.IBusiness;
|
||||
|
||||
public interface IProductBusiness extends IBusiness<ProductVO, ProductBo> {
|
||||
boolean audit(Long id, Integer authFlag, String reasons);
|
||||
boolean publish(Long id, Integer publishStatus);
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.wzj.soopin.goods.business;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.wzj.soopin.goods.convert.ProductConvert;
|
||||
import com.wzj.soopin.goods.convert.SkuConvert;
|
||||
import com.wzj.soopin.goods.domain.bo.ProductBo;
|
||||
import com.wzj.soopin.goods.domain.entity.Product;
|
||||
import com.wzj.soopin.goods.domain.entity.Sku;
|
||||
import com.wzj.soopin.goods.domain.vo.ProductVO;
|
||||
import com.wzj.soopin.goods.service.ProductService;
|
||||
import com.wzj.soopin.goods.service.SkuService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.web.core.BusinessImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ProductBusinessImpl extends BusinessImpl<ProductService, ProductConvert, ProductVO,ProductBo,Product> implements IProductBusiness {
|
||||
|
||||
private final ProductService productService;
|
||||
private final SkuService skuService;
|
||||
private final SkuConvert skuConvert;
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean save(ProductBo bo) {
|
||||
|
||||
Product product = converter.toPo(bo);
|
||||
product.setType(1);
|
||||
product.setSales("0");
|
||||
productService.saveOrUpdate(product);
|
||||
//清理掉旧的SKU
|
||||
skuService.remove(new LambdaQueryWrapper<Sku>().eq(Sku::getProductId, product.getId()));
|
||||
// 2. 保存SKU列表
|
||||
if (CollectionUtils.isNotEmpty(bo.getSkuList())) {
|
||||
List<Sku> skus = bo.getSkuList().stream()
|
||||
.map(skuBO -> skuConvert.toPo(skuBO))
|
||||
.collect(Collectors.toList());
|
||||
skuService.saveBatch(skus);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean audit(Long id, Integer authFlag, String reasons) {
|
||||
Product productToUpdate = productService.getById(id);
|
||||
if (productToUpdate == null) {
|
||||
throw new RuntimeException("商品不存在");
|
||||
}
|
||||
productToUpdate.setAuthFlag(authFlag);
|
||||
productToUpdate.setReasons(reasons);
|
||||
productService.updateById(productToUpdate);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publish(Long id, Integer publishStatus) {
|
||||
Product product = productService.getById(id);
|
||||
if (product == null) {
|
||||
throw new RuntimeException("商品不存在");
|
||||
}
|
||||
product.setPublishStatus(publishStatus);
|
||||
productService.updateById(product);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.wzj.soopin.goods.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.wzj.soopin.goods.business.IProductBusiness;
|
||||
import com.wzj.soopin.goods.convert.ProductConvert;
|
||||
import com.wzj.soopin.goods.domain.bo.BrandBo;
|
||||
import com.wzj.soopin.goods.domain.bo.ProductBo;
|
||||
@ -41,15 +42,15 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class ProductController extends BaseController {
|
||||
|
||||
private final ProductServiceImpl service;
|
||||
private final ProductConvert convert;
|
||||
private final ProductService productService;
|
||||
private final ProductService service;
|
||||
|
||||
private final IProductBusiness business;
|
||||
|
||||
@Tag(name ="查询商品信息列表")
|
||||
@PostMapping("list")
|
||||
public R<IPage<ProductVO>> list(@RequestBody ProductBo query, @RequestBody Page<Product> page) {
|
||||
return R.ok(productService.getList(query,page));
|
||||
return R.ok(service.getList(query,page));
|
||||
}
|
||||
|
||||
|
||||
@ -71,22 +72,23 @@ public class ProductController extends BaseController {
|
||||
@Tag(name ="新增商品信息")
|
||||
@Log(title = "商品信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/add")
|
||||
public R add(@RequestBody ProductDTO productDTO) {
|
||||
return R.ok(service.insert(productDTO));
|
||||
public R add(@RequestBody ProductBo bo) {
|
||||
return R.ok(business.save(bo));
|
||||
}
|
||||
|
||||
@Tag(name ="修改商品信息")
|
||||
@Log(title = "商品信息", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
public R edit(@RequestBody Product product) {
|
||||
return R.ok(service.updateById(product));
|
||||
public R edit(@RequestBody ProductBo bo) {
|
||||
|
||||
return R.ok(business.save(bo));
|
||||
}
|
||||
|
||||
@Tag(name = "删除商品信息")
|
||||
@Log(title = "商品信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{id}")
|
||||
public R remove(@PathVariable Long id) {
|
||||
return R.ok(service.removeProductWithSkus(id));
|
||||
return R.ok(business.removeById(id));
|
||||
}
|
||||
|
||||
|
||||
@ -96,7 +98,7 @@ public class ProductController extends BaseController {
|
||||
public R audit( @RequestParam Long id,
|
||||
@RequestParam Integer authFlag,
|
||||
@RequestParam(required = false) String reasons) {
|
||||
return R.ok(service.audit(id,authFlag,reasons));
|
||||
return R.ok(service.(id,authFlag,reasons));
|
||||
}
|
||||
|
||||
@Tag(name ="上下架商品")
|
||||
|
@ -1,17 +1,18 @@
|
||||
package com.wzj.soopin.goods.domain.bo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.wzj.soopin.goods.domain.entity.Product;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.domain.BaseBO;
|
||||
import org.dromara.common.excel.annotation.Excel;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "商品信息 查询 对象")
|
||||
public class ProductBo {
|
||||
public class ProductBo extends BaseBO<Product> {
|
||||
|
||||
@Schema(description = "BRAND_ID 精确匹配")
|
||||
private Long brandId;
|
||||
@ -46,7 +47,74 @@ public class ProductBo {
|
||||
@Schema(description = "店家手机号")
|
||||
private String contactPhone;
|
||||
|
||||
public Wrapper<Product> toWrapper() {
|
||||
@Schema(description = "NAME")
|
||||
@Excel(name = "NAME")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "主图")
|
||||
@Excel(name = "主图")
|
||||
private String pic;
|
||||
|
||||
@Schema(description = "画册图片,连产品图片限制为5张,以逗号分割")
|
||||
@Excel(name = "画册图片,连产品图片限制为5张,以逗号分割")
|
||||
private String albumPics;
|
||||
|
||||
|
||||
|
||||
@Schema(description = "排序")
|
||||
@Excel(name = "排序")
|
||||
private Integer sort;
|
||||
|
||||
|
||||
@Schema(description = "单位")
|
||||
@Excel(name = "单位")
|
||||
private String unit;
|
||||
|
||||
@Schema(description = "商品重量,默认为克")
|
||||
@Excel(name = "商品重量,默认为克")
|
||||
private BigDecimal weight;
|
||||
|
||||
@Schema(description = "商品销售属性,json格式")
|
||||
@Excel(name = "商品销售属性,json格式")
|
||||
private String productAttr;
|
||||
|
||||
@Schema(description = "产品详情网页内容")
|
||||
@Excel(name = "产品详情网页内容")
|
||||
private String detailHtml;
|
||||
|
||||
@Schema(description = "移动端网页详情")
|
||||
@Excel(name = "移动端网页详情")
|
||||
private String detailMobileHtml;
|
||||
|
||||
@Schema(description = "品牌名称")
|
||||
@Excel(name = "品牌名称")
|
||||
private String brandName;
|
||||
|
||||
@Schema(description = "商品分类名称")
|
||||
@Excel(name = "商品分类名称")
|
||||
private String productCategoryName;
|
||||
|
||||
@Schema(description = "商品类型 1.团购;->2.拼团;3->秒杀")
|
||||
@Excel(name = "商品类型 1.团购;->2.拼团;3->秒杀")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "店铺id")
|
||||
@Excel(name = "店铺id")
|
||||
private String tenantId;
|
||||
|
||||
|
||||
@Schema(description = "销量")
|
||||
@Excel(name = "销量")
|
||||
private String sales;
|
||||
|
||||
@Schema(description = "驳回原因")
|
||||
@Excel(name = "驳回原因")
|
||||
private String reasons;
|
||||
|
||||
@Schema(description = "SKU列表")
|
||||
@Excel(name = "SKU列表")
|
||||
private List<SkuBo> skuList;
|
||||
public LambdaQueryWrapper<Product> toWrapper() {
|
||||
return new LambdaQueryWrapper<Product>()
|
||||
.eq(brandId != null, Product::getBrandId, brandId)
|
||||
.eq(categoryId != null, Product::getCategoryId, categoryId)
|
||||
|
@ -30,6 +30,9 @@ public class SkuBo {
|
||||
@Schema(description = "商品名称")
|
||||
private String productName;
|
||||
|
||||
@Schema(description = "库存")
|
||||
private Integer stock;
|
||||
|
||||
public Wrapper<Sku> toWrapper() {
|
||||
return new LambdaQueryWrapper<Sku>()
|
||||
.eq(productId != null, Sku::getProductId, productId)
|
||||
|
@ -1,102 +0,0 @@
|
||||
package com.wzj.soopin.goods.domain.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.excel.annotation.Excel;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "商品信息DTO对象")
|
||||
@Data
|
||||
public class ProductDTO {
|
||||
|
||||
@Schema(description = "品牌")
|
||||
@Excel(name = "BRAND_ID")
|
||||
private Long brandId;
|
||||
|
||||
@Schema(description = "分类")
|
||||
@Excel(name = "CATEGORY_ID")
|
||||
private Long categoryId;
|
||||
|
||||
@Schema(description = "商品编码")
|
||||
@Excel(name = "商品编码")
|
||||
private String outProductId;
|
||||
|
||||
@Schema(description = "NAME")
|
||||
@Excel(name = "NAME")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "主图")
|
||||
@Excel(name = "主图")
|
||||
private String pic;
|
||||
|
||||
@Schema(description = "画册图片,连产品图片限制为5张,以逗号分割")
|
||||
@Excel(name = "画册图片,连产品图片限制为5张,以逗号分割")
|
||||
private String albumPics;
|
||||
|
||||
@Schema(description = "上架状态:0->下架;1->上架")
|
||||
@Excel(name = "上架状态:0->下架;1->上架")
|
||||
private Integer publishStatus;
|
||||
|
||||
@Schema(description = "排序")
|
||||
@Excel(name = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "价格")
|
||||
@Excel(name = "价格")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "单位")
|
||||
@Excel(name = "单位")
|
||||
private String unit;
|
||||
|
||||
@Schema(description = "商品重量,默认为克")
|
||||
@Excel(name = "商品重量,默认为克")
|
||||
private BigDecimal weight;
|
||||
|
||||
@Schema(description = "商品销售属性,json格式")
|
||||
@Excel(name = "商品销售属性,json格式")
|
||||
private String productAttr;
|
||||
|
||||
@Schema(description = "产品详情网页内容")
|
||||
@Excel(name = "产品详情网页内容")
|
||||
private String detailHtml;
|
||||
|
||||
@Schema(description = "移动端网页详情")
|
||||
@Excel(name = "移动端网页详情")
|
||||
private String detailMobileHtml;
|
||||
|
||||
@Schema(description = "品牌名称")
|
||||
@Excel(name = "品牌名称")
|
||||
private String brandName;
|
||||
|
||||
@Schema(description = "商品分类名称")
|
||||
@Excel(name = "商品分类名称")
|
||||
private String productCategoryName;
|
||||
|
||||
@Schema(description = "商品类型 1.团购;->2.拼团;3->秒杀")
|
||||
@Excel(name = "商品类型 1.团购;->2.拼团;3->秒杀")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "店铺id")
|
||||
@Excel(name = "店铺id")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "审核状态 1.待审核;->2.审核通过;3->审核驳回")
|
||||
@Excel(name = "审核状态 1.待审核;->2.审核通过;3->审核驳回")
|
||||
private Integer authFlag;
|
||||
|
||||
@Schema(description = "销量")
|
||||
@Excel(name = "销量")
|
||||
private String sales;
|
||||
|
||||
@Schema(description = "驳回原因")
|
||||
@Excel(name = "驳回原因")
|
||||
private String reasons;
|
||||
|
||||
@Schema(description = "SKU列表")
|
||||
@Excel(name = "SKU列表")
|
||||
private List<SkuDTO> skuList;
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.wzj.soopin.goods.domain.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Schema(description = "SKU信息DTO")
|
||||
public class SkuDTO {
|
||||
|
||||
|
||||
@Schema(description = "SKU编码")
|
||||
private String outSkuId;
|
||||
|
||||
@Schema(description = "价格")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "图片")
|
||||
private String pic;
|
||||
|
||||
@Schema(description = "规格属性(JSON格式)")
|
||||
private String spData;
|
||||
|
||||
@Schema(description = "库存")
|
||||
private Integer stock;
|
||||
|
||||
}
|
@ -27,4 +27,5 @@ public interface ProductService extends IService<Product> {
|
||||
*/
|
||||
IPage<ProductVO> getProductPageList(ProductBo query, Page<Product> page);
|
||||
|
||||
ProductVO selectById(Long id);
|
||||
}
|
||||
|
@ -1,32 +1,23 @@
|
||||
package com.wzj.soopin.goods.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.wzj.soopin.goods.domain.bo.ProductBo;
|
||||
import com.wzj.soopin.goods.domain.dto.ProductDTO;
|
||||
import com.wzj.soopin.goods.domain.dto.SkuDTO;
|
||||
import com.wzj.soopin.goods.domain.entity.Product;
|
||||
import com.wzj.soopin.goods.domain.entity.Sku;
|
||||
import com.wzj.soopin.goods.domain.vo.ProductVO;
|
||||
import com.wzj.soopin.goods.mapper.ProductMapper;
|
||||
import com.wzj.soopin.goods.mapper.SkuMapper;
|
||||
import com.wzj.soopin.goods.service.ProductService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.core.enums.TenantType;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.SysTenant;
|
||||
import org.dromara.system.domain.dto.TenantDTO;
|
||||
import org.dromara.system.domain.vo.SysUserTenantVO;
|
||||
import org.dromara.system.mapper.SysDeptMapper;
|
||||
import org.dromara.system.mapper.SysTenantMapper;
|
||||
@ -35,7 +26,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 商品信息Service业务层处理
|
||||
@ -88,26 +78,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
return productMapper.getlist(page,new ProductBo(), tenantIds);
|
||||
}
|
||||
|
||||
public Product audit(Long id, Integer authFlag, String reasons) {
|
||||
Product productToUpdate = productMapper.selectById(id);
|
||||
if (productToUpdate == null) {
|
||||
throw new RuntimeException("商品不存在");
|
||||
}
|
||||
productToUpdate.setAuthFlag(authFlag);
|
||||
productToUpdate.setReasons(reasons);
|
||||
productMapper.updateById(productToUpdate);
|
||||
return productToUpdate;
|
||||
}
|
||||
|
||||
public Product publish(Long id, Integer publishStatus) {
|
||||
Product product = productMapper.selectById(id);
|
||||
if (product == null) {
|
||||
throw new RuntimeException("商品不存在");
|
||||
}
|
||||
product.setPublishStatus(publishStatus);
|
||||
productMapper.updateById(product);
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品信息
|
||||
@ -115,78 +85,13 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
* @param id 商品信息主键
|
||||
* @return 商品信息
|
||||
*/
|
||||
@Override
|
||||
public ProductVO selectById(Long id) {
|
||||
return productMapper.selectProductWithSkus(id);
|
||||
|
||||
}
|
||||
|
||||
public R insert(ProductDTO productDTO) {
|
||||
try {
|
||||
// 1. 保存商品基本信息
|
||||
Product product = convertToProduct(productDTO);
|
||||
productMapper.insert(product);
|
||||
|
||||
// 2. 保存SKU列表
|
||||
if (CollectionUtils.isNotEmpty(productDTO.getSkuList())) {
|
||||
List<Sku> skus = productDTO.getSkuList().stream()
|
||||
.map(skuDTO -> convertToSku(skuDTO, product.getId()))
|
||||
.collect(Collectors.toList());
|
||||
skuMapper.batchInsert(skus);
|
||||
}
|
||||
|
||||
return R.ok("商品添加成功");
|
||||
} catch (Exception e) {
|
||||
log.error("添加商品失败", e);
|
||||
throw new ServiceException("添加商品失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
private Product convertToProduct(ProductDTO dto) {
|
||||
// 获取登录信息
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
|
||||
Product product = new Product();
|
||||
product.setBrandId(dto.getBrandId());
|
||||
product.setCategoryId(dto.getCategoryId());
|
||||
product.setOutProductId(dto.getOutProductId());
|
||||
product.setName(dto.getName());
|
||||
product.setPic(dto.getPic());
|
||||
product.setPrice(dto.getPrice());
|
||||
product.setAlbumPics(dto.getAlbumPics());
|
||||
product.setUnit(dto.getUnit());
|
||||
product.setWeight(dto.getWeight());
|
||||
product.setProductAttr(dto.getProductAttr());
|
||||
product.setDetailHtml(dto.getDetailHtml());
|
||||
product.setDetailMobileHtml(dto.getDetailMobileHtml());
|
||||
product.setAuthFlag(1);
|
||||
product.setPublishStatus(dto.getPublishStatus());
|
||||
product.setBrandName(dto.getBrandName());
|
||||
product.setProductCategoryName(dto.getProductCategoryName());
|
||||
product.setType(1);
|
||||
product.setSales("0");
|
||||
return product;
|
||||
}
|
||||
|
||||
private Sku convertToSku(SkuDTO dto, Long productId) {
|
||||
Sku sku = new Sku();
|
||||
sku.setProductId(productId);
|
||||
sku.setOutSkuId(dto.getOutSkuId());
|
||||
sku.setPrice(dto.getPrice());
|
||||
sku.setPic(dto.getPic());
|
||||
sku.setSpData(dto.getSpData());
|
||||
sku.setStock(dto.getStock());
|
||||
return sku;
|
||||
}
|
||||
|
||||
|
||||
public boolean removeProductWithSkus(Long id) {
|
||||
//删除关联的SKU数据
|
||||
LambdaQueryWrapper<Sku> skuQueryWrapper = new LambdaQueryWrapper<>();
|
||||
skuQueryWrapper.eq(Sku::getProductId, id);
|
||||
skuMapper.delete(skuQueryWrapper);
|
||||
|
||||
//删除商品主表数据
|
||||
return productMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 不带租户的获取商品信息
|
||||
|
Loading…
x
Reference in New Issue
Block a user