优化BUG
This commit is contained in:
@@ -2,11 +2,17 @@ package com.tashow.cloud.product.controller.admin;
|
||||
|
||||
import com.tashow.cloud.common.pojo.CommonResult;
|
||||
import com.tashow.cloud.common.pojo.PageResult;
|
||||
import com.tashow.cloud.product.mapper.ProdMapper;
|
||||
import com.tashow.cloud.productapi.api.product.dto.ProdDO;
|
||||
import com.tashow.cloud.product.service.ProdService;
|
||||
import com.tashow.cloud.productapi.api.product.dto.SkuDO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdPageReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdRecycleBinVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdSaveReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdServiceVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.sku.SkuPageReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.sku.SkuRecycleBinVO;
|
||||
import com.tashow.cloud.productapi.enums.BaseEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -16,6 +22,9 @@ import jakarta.validation.Valid;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.tashow.cloud.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 商品")
|
||||
@@ -26,7 +35,8 @@ public class ProdController {
|
||||
|
||||
@Resource
|
||||
private ProdService prodService;
|
||||
|
||||
@Resource
|
||||
private ProdMapper prodMapper;
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建商品")
|
||||
@PermitAll
|
||||
@@ -62,23 +72,59 @@ public class ProdController {
|
||||
}
|
||||
|
||||
|
||||
/* @PutMapping("/update")
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新商品")
|
||||
@PreAuthorize("@ss.hasPermission('tashow-module-product:prod:update')")
|
||||
public CommonResult<Boolean> updateProd(@Valid @RequestBody ProdSaveReqVO updateReqVO) {
|
||||
@PermitAll
|
||||
public CommonResult<Boolean> updateProd(@RequestBody ProdSaveReqVO updateReqVO) {
|
||||
prodService.updateProd(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除商品")
|
||||
@PermitAll
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('tashow-module-product:prod:delete')")
|
||||
public CommonResult<Boolean> deleteProd(@RequestParam("id") Long id) {
|
||||
prodService.deleteProd(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@DeleteMapping("/deleteSkuList")
|
||||
@Operation(summary = "批量删除商品")
|
||||
@Parameter(name = "ids", description = "商品id", required = true)
|
||||
@PermitAll
|
||||
public CommonResult<Boolean> deleteSkuList(@RequestParam("ids") List<Long> ids) {
|
||||
for(Long id:ids){
|
||||
ProdDO prod = new ProdDO();
|
||||
prod.setProdId(id);
|
||||
prod.setDeleted(BaseEnum.YES_ONE.getKey());
|
||||
prod.setDeleteTime(new Date());
|
||||
// 删除
|
||||
prodMapper.deleteById(prod);
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/updateSkuShelfList")
|
||||
@Operation(summary = "批量上下架")
|
||||
@Parameter(name = "status", description = "默认是1,正常状态(出售中), 0:下架(仓库中) 2:待审核", required = true)
|
||||
@PermitAll
|
||||
public CommonResult<Boolean> updateSkuShelfList(@RequestParam("ids") List<Long> ids,@RequestParam("status") Integer status) {
|
||||
for(Long id:ids){
|
||||
ProdDO prod = new ProdDO();
|
||||
prod.setProdId(id);
|
||||
prod.setStatus(status);
|
||||
prodMapper.updateBatch(prod);
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得商品")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@@ -91,8 +137,16 @@ public class ProdController {
|
||||
@PermitAll
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品分页")
|
||||
public CommonResult<PageResult<ProdDO>> getProdPage(@Valid ProdPageReqVO pageReqVO) {
|
||||
public CommonResult<PageResult<ProdDO>> getProdPage(ProdPageReqVO pageReqVO) {
|
||||
PageResult<ProdDO> pageResult = prodService.getProdPage(pageReqVO);
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
@GetMapping("/getProdRecycleBinPageList")
|
||||
@Operation(summary = "获得商品回收站分页列表")
|
||||
public CommonResult<PageResult<SkuRecycleBinVO>> getProdRecycleBinPageList(ProdRecycleBinVO prodRecycleBinVO) {
|
||||
PageResult<SkuRecycleBinVO> pageResult = prodService.getProdRecycleBinPageList(prodRecycleBinVO);
|
||||
return success(pageResult);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import static com.tashow.cloud.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 单品SKU")
|
||||
@RestController
|
||||
@RequestMapping("/tz/sku")
|
||||
@RequestMapping("/product/sku")
|
||||
@Validated
|
||||
public class SkuController {
|
||||
|
||||
@@ -84,6 +84,16 @@ public class SkuController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/disableProp")
|
||||
@Operation(summary = "禁用规格值")
|
||||
@PermitAll
|
||||
public CommonResult<Boolean> disableProp(@RequestParam("id") Long id) {
|
||||
skuService.disableProp(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除单品SKU")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@@ -98,13 +108,14 @@ public class SkuController {
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@PermitAll
|
||||
public CommonResult<Boolean> deleteSkuList(@RequestParam("id") List<Long> ids) {
|
||||
for(Long id:ids){
|
||||
/*for(Long id:ids){
|
||||
SkuDO sku = new SkuDO();
|
||||
sku.setSkuId(id);
|
||||
sku.setDeleteTime(new Date());
|
||||
// 删除
|
||||
skuMapper.deleteById(sku);
|
||||
}
|
||||
}*/
|
||||
skuService.deleteSkus(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -115,10 +126,7 @@ public class SkuController {
|
||||
@Parameter(name = "isShelf", description = "是否上下架(0下架 1上架)", required = true)
|
||||
@PermitAll
|
||||
public CommonResult<Boolean> updateSkuShelf(@RequestParam("id") Long id,@RequestParam("isShelf") Integer isShelf) {
|
||||
SkuDO sku = new SkuDO();
|
||||
sku.setSkuId(id);
|
||||
sku.setIsShelf(isShelf);
|
||||
skuMapper.updateBatch(sku);
|
||||
skuService.updatSkuIsShelf(id,isShelf);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -134,6 +142,7 @@ public class SkuController {
|
||||
sku.setIsShelf(isShelf);
|
||||
skuMapper.updateBatch(sku);
|
||||
}
|
||||
skuService.updatSkuIsShelfs(ids,isShelf);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -155,6 +164,15 @@ public class SkuController {
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
@GetMapping("/getSkuPageList")
|
||||
@Operation(summary = "获得SKU分页列表")
|
||||
public CommonResult<PageResult<SkuDO>> getSkuPageList(@Valid SkuPageReqVO pageReqVO) {
|
||||
PageResult<SkuDO> pageResult = skuService.getSkuPageList(pageReqVO);
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
|
||||
/* @PermitAll
|
||||
@GetMapping("/getSkuRecycleBinPageList")
|
||||
@Operation(summary = "获得SKU回收站分页列表")
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.tashow.cloud.mybatis.mybatis.core.mapper.BaseMapperX;
|
||||
import com.tashow.cloud.productapi.api.product.dto.*;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdPageReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdServiceVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.sku.SkuRecycleBinVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -21,7 +22,11 @@ import org.apache.ibatis.annotations.Param;
|
||||
@Mapper
|
||||
public interface ProdMapper extends BaseMapperX<ProdDO> {
|
||||
|
||||
IPage<ProdDO> getProdPageList(Page<?> page, ProdPageReqVO reqVO);
|
||||
IPage<ProdDO> getProdPageList(Page<?> page,@Param("createTime") String[] createTime
|
||||
, @Param("prodName") String prodName
|
||||
, @Param("shopId") Long shopId
|
||||
, @Param("status") Integer status
|
||||
, @Param("categoryId") Long categoryId);
|
||||
|
||||
ProdServiceVO selectProdService(@Param("prodId") Long prodId
|
||||
, @Param("regionSwitch") Integer regionSwitch
|
||||
@@ -41,4 +46,8 @@ public interface ProdMapper extends BaseMapperX<ProdDO> {
|
||||
, @Param("additionalFeeSwitch") Integer additionalFeeSwitch
|
||||
, @Param("weightSwitch") Integer weightSwitch
|
||||
);
|
||||
|
||||
IPage<SkuRecycleBinVO> getProdRecycleBinPageList(Page<?> page,@Param("createTime") String[] createTime
|
||||
, @Param("prodName") String prodName);
|
||||
|
||||
}
|
||||
@@ -24,4 +24,9 @@ public interface ProdPropValueMapper extends BaseMapperX<ProdPropValueDO> {
|
||||
*/
|
||||
void insertPropValues(@Param("propId") Long propId, @Param("prodPropValues") List<ProdPropValueDO> prodPropValues);
|
||||
|
||||
List<ProdPropValueDO> selectSalesValuesByProdId(@Param("prodId") Long prodId);
|
||||
|
||||
List<ProdPropValueDO> selectSalesValuesByState(@Param("prodId") Long prodId);
|
||||
|
||||
void batchMarkDeleted(@Param("ids") List<Long> ids);
|
||||
}
|
||||
@@ -20,6 +20,11 @@ public interface SkuMapper extends BaseMapperX<SkuDO> {
|
||||
|
||||
IPage<SkuRecycleBinVO> getSkuRecycleBinPageList(Page<?> page, @Param("prodId") Long prodId, @Param("properties")String properties);
|
||||
|
||||
List<SkuDO> getSkuListByName( @Param("propertiesName")String propertiesName);
|
||||
IPage<SkuDO> getSkuPageList(Page<?> page, @Param("prodId") Long prodId,@Param("skuId") Long skuId, @Param("properties")String properties);
|
||||
|
||||
|
||||
List<SkuDO> getSkuListByName( @Param("propertiesName")String propertiesName);
|
||||
List<String> selectPropertiesByProdIdAndNotDeleted( @Param("prodId")Long prodId);
|
||||
|
||||
List<String> selectPropertiesByProdIdShelf( @Param("prodId")Long prodId);
|
||||
}
|
||||
@@ -4,8 +4,10 @@ import java.util.*;
|
||||
|
||||
import com.tashow.cloud.productapi.api.product.dto.ProdDO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdPageReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdRecycleBinVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdSaveReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdServiceVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.sku.SkuRecycleBinVO;
|
||||
import jakarta.validation.*;
|
||||
import com.tashow.cloud.common.pojo.PageResult;
|
||||
import com.tashow.cloud.common.pojo.PageParam;
|
||||
@@ -82,4 +84,5 @@ public interface ProdService {
|
||||
*/
|
||||
PageResult<ProdDO> getProdPage(ProdPageReqVO pageReqVO);
|
||||
|
||||
PageResult<SkuRecycleBinVO> getProdRecycleBinPageList(ProdRecycleBinVO prodRecycleBinVO);
|
||||
}
|
||||
@@ -63,6 +63,13 @@ public interface SkuService {
|
||||
*/
|
||||
void deleteProp(Long id);
|
||||
|
||||
/**
|
||||
* 禁用规格值
|
||||
*
|
||||
* @param id 删除规格值
|
||||
*/
|
||||
void disableProp(Long id);
|
||||
|
||||
|
||||
|
||||
SkuPropInfoVO getSKuPropList(Long prodId);
|
||||
@@ -74,6 +81,29 @@ public interface SkuService {
|
||||
*/
|
||||
void deleteSku(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除删SKU
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
void deleteSkus(List<Long> ids);
|
||||
|
||||
|
||||
/**
|
||||
* 删除单品SKU
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void updatSkuIsShelf(Long id,Integer isShelf);
|
||||
|
||||
/**
|
||||
* 批量删除删SKU
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
void updatSkuIsShelfs(List<Long> ids,Integer isShelf);
|
||||
|
||||
|
||||
/**
|
||||
* 获得单品SKU
|
||||
*
|
||||
@@ -86,6 +116,8 @@ public interface SkuService {
|
||||
|
||||
PageResult<SkuRecycleBinVO> getSkuRecycleBinPageList(SkuPageReqVO pageReqVO);
|
||||
|
||||
|
||||
PageResult<SkuDO> getSkuPageList(SkuPageReqVO pageReqVO);
|
||||
/**
|
||||
* 获得单品SKU分页
|
||||
*
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ProdPropServiceImpl extends ServiceImpl<ProdPropMapper, ProdPropDO>
|
||||
return;
|
||||
}
|
||||
for (ProdPropValueDO prodPropValueDO : createReqVO.getProdPropValues()){
|
||||
prodPropValueDO.setPropId(prodProp.getPropId());
|
||||
prodPropValueDO.setPropId(prodProp.getId());
|
||||
prodPropValueMapper.insert(prodPropValueDO);
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class ProdPropServiceImpl extends ServiceImpl<ProdPropMapper, ProdPropDO>
|
||||
}
|
||||
for (ProdPropValueDO prodPropValueDO : createReqVO.getProdPropValues()){
|
||||
if(Objects.equals(BaseEnum.YES_ONE.getKey(),prodPropValueDO.getIsExist())){
|
||||
prodPropValueDO.setPropId(prodProp.getPropId());
|
||||
prodPropValueDO.setPropId(prodProp.getId());
|
||||
prodPropValueMapper.insert(prodPropValueDO);
|
||||
}else {
|
||||
prodPropValueMapper.updateById(prodPropValueDO);
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tashow.cloud.common.util.date.DateUtils;
|
||||
import com.tashow.cloud.mybatis.mybatis.core.util.MyBatisUtils;
|
||||
import com.tashow.cloud.productapi.api.product.dto.*;
|
||||
import com.tashow.cloud.product.mapper.*;
|
||||
@@ -11,8 +12,11 @@ import com.tashow.cloud.product.service.ProdPropService;
|
||||
import com.tashow.cloud.product.service.ProdService;
|
||||
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdPageReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdRecycleBinVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdSaveReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.prod.ProdServiceVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.sku.SkuPageReqVO;
|
||||
import com.tashow.cloud.productapi.api.product.vo.sku.SkuRecycleBinVO;
|
||||
import com.tashow.cloud.productapi.enums.BaseEnum;
|
||||
import lombok.val;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -271,8 +275,12 @@ public class ProdServiceImpl implements ProdService {
|
||||
public void deleteProd(Long id) {
|
||||
// 校验存在
|
||||
validateProdExists(id);
|
||||
ProdDO prod = new ProdDO();
|
||||
prod.setProdId(id);
|
||||
prod.setDeleted(BaseEnum.YES_ONE.getKey());
|
||||
prod.setDeleteTime(new Date());
|
||||
// 删除
|
||||
prodMapper.deleteById(id);
|
||||
prodMapper.deleteById(prod);
|
||||
}
|
||||
|
||||
private void validateProdExists(Long id) {
|
||||
@@ -288,7 +296,17 @@ public class ProdServiceImpl implements ProdService {
|
||||
|
||||
@Override
|
||||
public PageResult<ProdDO> getProdPage(ProdPageReqVO pageReqVO) {
|
||||
IPage<ProdDO> prodPageList = prodMapper.getProdPageList(MyBatisUtils.buildPage(pageReqVO), pageReqVO);
|
||||
IPage<ProdDO> prodPageList = prodMapper.getProdPageList(MyBatisUtils.buildPage(pageReqVO),
|
||||
pageReqVO.getCreateTime(), pageReqVO.getProdName(), pageReqVO.getShopId(), pageReqVO.getStatus(), pageReqVO.getCategoryId());
|
||||
return new PageResult<>(prodPageList.getRecords(),prodPageList.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SkuRecycleBinVO> getProdRecycleBinPageList(ProdRecycleBinVO prodRecycleBinVO){
|
||||
IPage<SkuRecycleBinVO> prodPageList = prodMapper.getProdRecycleBinPageList(MyBatisUtils.buildPage(prodRecycleBinVO), prodRecycleBinVO.getDeleteTime(), prodRecycleBinVO.getProdName());
|
||||
for(SkuRecycleBinVO prodPage : prodPageList.getRecords()){
|
||||
prodPage.setRemainingDays(DateUtils.getRemainingDays(prodPage.getDeleteTime()));
|
||||
}
|
||||
return new PageResult<>(prodPageList.getRecords(),prodPageList.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ public class SkuServiceImpl implements SkuService {
|
||||
private ProdPropValueService prodPropValueService;
|
||||
@Resource
|
||||
private ProdExtendService prodExtendService;
|
||||
@Resource
|
||||
private ProdPropValueMapper prodPropValueMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Long createSku(SkuSaveReqVO createReqVO) {
|
||||
@@ -413,11 +416,39 @@ public class SkuServiceImpl implements SkuService {
|
||||
ProdPropValueDO prodPropValueDO =prodPropValueService.getById(id);
|
||||
prodPropValueService.deleteProdPropValue(id);
|
||||
List<SkuDO> skuDOList = skuMapper.getSkuListByName(prodPropValueDO.getPropValue());
|
||||
List<SkuDO> skuDOList1 = new ArrayList<>();
|
||||
for(SkuDO skuDO : skuDOList){
|
||||
if(skuDO.getProperties()!=null){
|
||||
String[] split = skuDO.getProperties().split(",");
|
||||
for (String s : split){
|
||||
if(s.equals(prodPropValueDO.getPropValue())){
|
||||
skuDOList1.add(skuDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
skuMapper.deleteByIds(skuDOList1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableProp(Long id) {
|
||||
ProdPropValueDO prodPropValueDO =prodPropValueService.getById(id);
|
||||
prodPropValueDO.setState(BaseEnum.YES_ONE.getKey());
|
||||
prodPropValueService.updateById(prodPropValueDO);
|
||||
List<SkuDO> skuDOList = skuMapper.getSkuListByName(prodPropValueDO.getPropValue());
|
||||
List<SkuDO> skuDOList1 = new ArrayList<>();
|
||||
for(SkuDO skuDO : skuDOList){
|
||||
if(skuDO.getProperties()!=null){
|
||||
String[] split = skuDO.getProperties().split(",");
|
||||
for (String s : split){
|
||||
if(s.equals(prodPropValueDO.getPropValue())){
|
||||
skuDO.setIsShelf(BaseEnum.NO_ZERO.getKey());
|
||||
skuDOList1.add(skuDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
skuMapper.updateBatch(skuDOList1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -425,14 +456,14 @@ public class SkuServiceImpl implements SkuService {
|
||||
LambdaQueryWrapper<ProdPropDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ProdPropDO::getProdId,prodId);
|
||||
wrapper.eq(ProdPropDO::getState, BaseEnum.YES_ONE.getKey())
|
||||
.orderByDesc(ProdPropDO::getSort);
|
||||
.orderByAsc(ProdPropDO::getSort);
|
||||
|
||||
List<ProdPropDO> list = prodPropService.list(wrapper);
|
||||
list.forEach(prop -> {
|
||||
List<ProdPropValueDO> values = prodPropValueService.list(
|
||||
new LambdaQueryWrapper<ProdPropValueDO>()
|
||||
.eq(ProdPropValueDO::getPropId, prop.getId())
|
||||
.orderByDesc(ProdPropValueDO::getSort)
|
||||
.orderByAsc(ProdPropValueDO::getSort)
|
||||
);
|
||||
/* LambdaQueryWrapper<ProdPropValueDO> wrapper1 = new LambdaQueryWrapper<>();
|
||||
wrapper1.eq(ProdPropValueDO::getPropId,prop.getPropId());
|
||||
@@ -454,16 +485,203 @@ public class SkuServiceImpl implements SkuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteSku(Long id) {
|
||||
// 校验存在
|
||||
validateSkuExists(id);
|
||||
SkuDO sku = new SkuDO();
|
||||
sku.setSkuId(id);
|
||||
sku.setDeleteTime(new Date());
|
||||
|
||||
SkuDO prodSku = skuMapper.selectById( id);
|
||||
// Step 1: 获取该商品下所有未删除的 SKU 的 properties
|
||||
List<String> activeProperties = skuMapper.selectPropertiesByProdIdAndNotDeleted(prodSku.getProdId());
|
||||
|
||||
// Step 2: 提取所有正在被使用的属性值(去重)
|
||||
Set<String> currentlyUsedValues = new HashSet<>();
|
||||
for (String props : activeProperties) {
|
||||
if (props != null && !props.trim().isEmpty()) {
|
||||
String[] values = props.split(",");
|
||||
for (String v : values) {
|
||||
currentlyUsedValues.add(v.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除
|
||||
skuMapper.deleteById(sku);
|
||||
// Step 3: 查询该商品下所有 rule=1 的属性值(销售属性)
|
||||
List<ProdPropValueDO> allPropValues = prodPropValueMapper.selectSalesValuesByProdId(prodSku.getProdId());
|
||||
// Step 4: 遍历每个属性值,检查是否还在被使用
|
||||
for (ProdPropValueDO pv : allPropValues) {
|
||||
String value = pv.getPropValue().trim();
|
||||
// 如果当前属性值不在“活跃使用”列表中,说明没有未删除的 SKU 使用它
|
||||
if (!currentlyUsedValues.contains(value)) {
|
||||
// 可以安全删除该属性值
|
||||
// 可以安全禁用该属性值
|
||||
ProdPropValueDO prodPropValueDO = new ProdPropValueDO();
|
||||
prodPropValueDO.setId(pv.getId());
|
||||
prodPropValueDO.setIsExpire(BaseEnum.YES_ONE.getKey());
|
||||
prodPropValueDO.setDeleteTime(new Date());
|
||||
prodPropValueMapper.updateById(prodPropValueDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteSkus(List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 1: 查询这些 SKU 的基本信息(主要是 prod_id)
|
||||
List<SkuDO> skuList = skuMapper.selectByIds(ids);
|
||||
if (skuList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Long prodId = skuList.get(0).getProdId();
|
||||
// 校验是否属于同一个商品(可选)
|
||||
boolean allSameProd = skuList.stream().allMatch(s -> s.getProdId().equals(prodId));
|
||||
if (!allSameProd) {
|
||||
throw new IllegalArgumentException("批量删除的 SKU 必须属于同一个商品");
|
||||
}
|
||||
|
||||
|
||||
// Step 3: 获取该商品下【当前仍然未删除】的 SKU 的 properties
|
||||
List<String> activeProperties = skuMapper.selectPropertiesByProdIdAndNotDeleted(prodId);
|
||||
|
||||
for(Long id:ids){
|
||||
SkuDO sku = new SkuDO();
|
||||
sku.setSkuId(id);
|
||||
sku.setDeleteTime(new Date());
|
||||
// 删除
|
||||
skuMapper.deleteById(sku);
|
||||
}
|
||||
// Step 4: 提取所有仍在使用的属性值(去重 + trim)
|
||||
Set<String> currentlyUsedValues = new HashSet<>();
|
||||
for (String props : activeProperties) {
|
||||
if (props != null && !props.trim().isEmpty()) {
|
||||
String[] values = props.split(",");
|
||||
for (String v : values) {
|
||||
currentlyUsedValues.add(v.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5: 查询该商品下所有 rule=1 的销售属性值(未删除的)
|
||||
List<ProdPropValueDO> allPropValues = prodPropValueMapper.selectSalesValuesByProdId(prodId);
|
||||
|
||||
// Step 6: 收集需要删除的属性值 ID
|
||||
List<Long> valueIdsToDelete = new ArrayList<>();
|
||||
for (ProdPropValueDO pv : allPropValues) {
|
||||
String value = pv.getPropValue().trim();
|
||||
if (!currentlyUsedValues.contains(value)) {
|
||||
valueIdsToDelete.add(pv.getId());
|
||||
}
|
||||
}
|
||||
// Step 7: 批量删除无用的属性值
|
||||
if (!valueIdsToDelete.isEmpty()) {
|
||||
prodPropValueMapper.batchMarkDeleted(valueIdsToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatSkuIsShelf(Long id, Integer isShelf) {
|
||||
// 校验存在
|
||||
validateSkuExists(id);
|
||||
|
||||
SkuDO prodSku = skuMapper.selectById( id);
|
||||
// Step 1: 获取该商品下所有未禁用的 SKU 的 properties
|
||||
List<String> activeProperties = skuMapper.selectPropertiesByProdIdShelf(prodSku.getProdId());
|
||||
SkuDO sku = new SkuDO();
|
||||
sku.setSkuId(id);
|
||||
sku.setIsShelf(isShelf);
|
||||
skuMapper.updateById(sku);
|
||||
// Step 2: 提取所有正在被使用的属性值(去重)
|
||||
Set<String> currentlyUsedValues = new HashSet<>();
|
||||
for (String props : activeProperties) {
|
||||
if (props != null && !props.trim().isEmpty()) {
|
||||
String[] values = props.split(",");
|
||||
for (String v : values) {
|
||||
currentlyUsedValues.add(v.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Step 3: 查询该商品下所有 rule=1 的属性值(销售属性)
|
||||
List<ProdPropValueDO> allPropValues = prodPropValueMapper.selectSalesValuesByState(prodSku.getProdId());
|
||||
// Step 4: 遍历每个属性值,检查是否还在被使用
|
||||
for (ProdPropValueDO pv : allPropValues) {
|
||||
String value = pv.getPropValue().trim();
|
||||
// 如果当前属性值不在“活跃使用”列表中,说明没有未删除的 SKU 使用它
|
||||
if (!currentlyUsedValues.contains(value)) {
|
||||
// 可以安全禁用该属性值
|
||||
ProdPropValueDO prodPropValueDO = new ProdPropValueDO();
|
||||
prodPropValueDO.setId(pv.getId());
|
||||
prodPropValueDO.setState(BaseEnum.NO_ZERO.getKey());
|
||||
prodPropValueMapper.updateById(prodPropValueDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatSkuIsShelfs(List<Long> ids, Integer isShelf) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 1: 查询这些 SKU 的基本信息(主要是 prod_id)
|
||||
List<SkuDO> skuList = skuMapper.selectByIds(ids);
|
||||
if (skuList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Long prodId = skuList.get(0).getProdId();
|
||||
// 校验是否属于同一个商品(可选)
|
||||
boolean allSameProd = skuList.stream().allMatch(s -> s.getProdId().equals(prodId));
|
||||
if (!allSameProd) {
|
||||
throw new IllegalArgumentException("批量删除的 SKU 必须属于同一个商品");
|
||||
}
|
||||
|
||||
|
||||
// Step 3: 获取该商品下【当前仍然未禁用】的 SKU 的 properties
|
||||
List<String> activeProperties = skuMapper.selectPropertiesByProdIdShelf(prodId);
|
||||
|
||||
for(Long id:ids){
|
||||
SkuDO sku = new SkuDO();
|
||||
sku.setSkuId(id);
|
||||
sku.setIsShelf(isShelf);
|
||||
skuMapper.updateBatch(sku);
|
||||
}
|
||||
// Step 4: 提取所有仍在使用的属性值(去重 + trim)
|
||||
Set<String> currentlyUsedValues = new HashSet<>();
|
||||
for (String props : activeProperties) {
|
||||
if (props != null && !props.trim().isEmpty()) {
|
||||
String[] values = props.split(",");
|
||||
for (String v : values) {
|
||||
currentlyUsedValues.add(v.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5: 查询该商品下所有 rule=1 的销售属性值(未删除的)
|
||||
List<ProdPropValueDO> allPropValues = prodPropValueMapper.selectSalesValuesByState(prodId);
|
||||
|
||||
// Step 6: 收集需要删除的属性值 ID
|
||||
List<Long> valueIdsToDelete = new ArrayList<>();
|
||||
for (ProdPropValueDO pv : allPropValues) {
|
||||
String value = pv.getPropValue().trim();
|
||||
if (!currentlyUsedValues.contains(value)) {
|
||||
valueIdsToDelete.add(pv.getId());
|
||||
}
|
||||
}
|
||||
// Step 7: 批量删除无用的属性值
|
||||
if (!valueIdsToDelete.isEmpty()) {
|
||||
prodPropValueMapper.batchMarkDeleted(valueIdsToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void validateSkuExists(Long id) {
|
||||
if (skuMapper.selectById(id) == null) {
|
||||
throw exception(ErrorCodeConstants.SKU_NOT_EXISTS);
|
||||
@@ -484,6 +702,14 @@ public class SkuServiceImpl implements SkuService {
|
||||
return new PageResult<>(prodPageList.getRecords(),prodPageList.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SkuDO> getSkuPageList(SkuPageReqVO pageReqVO){
|
||||
IPage<SkuDO> prodPageList = skuMapper.getSkuPageList(MyBatisUtils.buildPage(pageReqVO), pageReqVO.getProdId(), pageReqVO.getSkuId(),pageReqVO.getProperties());
|
||||
|
||||
return new PageResult<>(prodPageList.getRecords(),prodPageList.getTotal());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PageResult<SkuDO> getSkuPage(SkuPageReqVO pageReqVO) {
|
||||
|
||||
@@ -233,8 +233,25 @@
|
||||
|
||||
|
||||
|
||||
<select id="getProdPageList" resultType="com.tashow.cloud.productapi.api.product.dto.ProdDO" >
|
||||
select * from tz_prod
|
||||
<select id="getProdPageList" resultType="com.tashow.cloud.productapi.api.product.dto.ProdDO">
|
||||
SELECT * FROM tz_prod
|
||||
where deleted = 0
|
||||
<if test="createTime != null and createTime.length == 2">
|
||||
AND create_time BETWEEN #{createTime[0]} AND #{createTime[1]}
|
||||
</if>
|
||||
<if test="prodName != null">
|
||||
AND prod_name = #{prodName}
|
||||
</if>
|
||||
<if test="shopId != null">
|
||||
AND shop_id = #{shopId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
AND category_id = #{categoryId}
|
||||
</if>
|
||||
ORDER by create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
@@ -502,4 +519,15 @@
|
||||
ORDER BY p.prod_id
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getProdRecycleBinPageList" resultType="com.tashow.cloud.productapi.api.product.vo.sku.SkuRecycleBinVO" >
|
||||
select * from tz_prod where deleted = 1
|
||||
<if test="properties != null and properties != ''">
|
||||
and properties like concat('%', #{prodName}, '%')
|
||||
</if>
|
||||
<if test="deleteTime != null and deleteTime.length == 2">
|
||||
AND delete_time BETWEEN #{deleteTime[0]} AND #{deleteTime[1]}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -14,4 +14,47 @@
|
||||
(#{propId},#{prodPropValue.propValue})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
||||
|
||||
<!-- ProdPropValueMapper.xml -->
|
||||
<select id="selectSalesValuesByProdId" resultType="com.tashow.cloud.productapi.api.product.dto.ProdPropValueDO">
|
||||
SELECT
|
||||
pp.id AS propId,
|
||||
pp.prop_name,
|
||||
ppv.id AS valueId,
|
||||
ppv.prop_value
|
||||
FROM tz_prod_prop pp
|
||||
JOIN tz_prod_prop_value ppv ON pp.id = ppv.prop_id
|
||||
WHERE pp.prod_id = #{prodId}
|
||||
AND pp.rule = 1
|
||||
AND ppv.is_expire = 0
|
||||
</select>
|
||||
|
||||
<select id="selectSalesValuesByState" resultType="com.tashow.cloud.productapi.api.product.dto.ProdPropValueDO">
|
||||
SELECT
|
||||
pp.id AS propId,
|
||||
pp.prop_name,
|
||||
ppv.id AS valueId,
|
||||
ppv.prop_value
|
||||
FROM tz_prod_prop pp
|
||||
JOIN tz_prod_prop_value ppv ON pp.id = ppv.prop_id
|
||||
WHERE pp.prod_id = #{prodId}
|
||||
AND pp.rule = 1
|
||||
AND ppv.state = 1
|
||||
AND ppv.is_expire = 0
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
<update id="batchMarkDeleted">
|
||||
UPDATE tz_prod_prop_value
|
||||
SET is_expire = 1, delete_time = NOW()
|
||||
WHERE id IN
|
||||
<foreach item="id" collection="ids" open="(" separator="," close=")">
|
||||
#{ids}
|
||||
</foreach>
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -17,6 +17,20 @@
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getSkuPageList" resultType="com.tashow.cloud.productapi.api.product.dto.SkuDO">
|
||||
Select * from tz_sku where deleted = 0
|
||||
<if test="prodId != null and prodId != ''">
|
||||
and prod_id = #{prodId}
|
||||
</if>
|
||||
<if test="skuId != null and skuId != ''">
|
||||
and sku_id = #{skuId}
|
||||
</if>
|
||||
<if test="properties != null and properties != ''">
|
||||
and properties like concat('%', #{propertiesName}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getSkuListByName" resultType="com.tashow.cloud.productapi.api.product.dto.SkuDO" >
|
||||
select sku_id, properties, delete_time,deleted from tz_sku
|
||||
<if test="properties != null and properties != ''">
|
||||
@@ -24,4 +38,22 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- SkuMapper.xml -->
|
||||
<select id="selectPropertiesByProdIdAndNotDeleted" resultType="string">
|
||||
SELECT properties
|
||||
FROM tz_sku
|
||||
WHERE prod_id = #{prodId}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- SkuMapper.xml -->
|
||||
<select id="selectPropertiesByProdIdShelf" resultType="string">
|
||||
SELECT properties
|
||||
FROM tz_sku
|
||||
WHERE prod_id = #{prodId}
|
||||
AND deleted = 0
|
||||
and is_shelf =0
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user