|
|
|
|
@ -15,6 +15,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.yami.shop.bean.model.Product;
|
|
|
|
|
import com.yami.shop.bean.model.ShopDetail;
|
|
|
|
|
import com.yami.shop.bean.model.Sku;
|
|
|
|
|
import com.yami.shop.bean.param.ProductParam;
|
|
|
|
|
import com.yami.shop.common.exception.YamiShopBindException;
|
|
|
|
|
@ -22,19 +23,19 @@ import com.yami.shop.common.response.ServerResponseEntity;
|
|
|
|
|
import com.yami.shop.common.util.Json;
|
|
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
|
|
import com.yami.shop.security.admin.util.SecurityUtils;
|
|
|
|
|
import com.yami.shop.service.BasketService;
|
|
|
|
|
import com.yami.shop.service.ProdTagReferenceService;
|
|
|
|
|
import com.yami.shop.service.ProductService;
|
|
|
|
|
import com.yami.shop.service.SkuService;
|
|
|
|
|
import com.yami.shop.service.*;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import jodd.util.StringUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -58,6 +59,8 @@ public class ProductController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BasketService basketService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ShopDetailService shopDetailService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取商品信息
|
|
|
|
|
@ -65,13 +68,34 @@ public class ProductController {
|
|
|
|
|
@GetMapping("/page")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('prod:prod:page')")
|
|
|
|
|
public ServerResponseEntity<IPage<Product>> page(ProductParam product, PageParam<Product> page) {
|
|
|
|
|
List<ShopDetail> shopList = null;
|
|
|
|
|
List<Long> shopIdList = null;
|
|
|
|
|
|
|
|
|
|
if (!StringUtil.isEmpty(product.getShopName())) {
|
|
|
|
|
shopList = shopDetailService.list(new LambdaQueryWrapper<ShopDetail>().like(ShopDetail::getShopName, product.getShopName()));
|
|
|
|
|
// 将 shopList 转换为包含 shopId 的列表
|
|
|
|
|
if (shopList != null && !shopList.isEmpty()) {
|
|
|
|
|
shopIdList = shopList.stream()
|
|
|
|
|
.map(ShopDetail::getShopId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
IPage<Product> products = productService.page(page,
|
|
|
|
|
new LambdaQueryWrapper<Product>()
|
|
|
|
|
.like(StrUtil.isNotBlank(product.getProdName()), Product::getProdName, product.getProdName())
|
|
|
|
|
.eq(Product::getShopId, SecurityUtils.getSysUser().getShopId())
|
|
|
|
|
.eq(!SecurityUtils.getSysUser().checkAdmin(), Product::getShopId, SecurityUtils.getSysUser().getShopId())
|
|
|
|
|
.eq(product.getStatus() != null, Product::getStatus, product.getStatus())
|
|
|
|
|
.eq(product.getProductType() != null, Product::getProductType, product.getProductType())
|
|
|
|
|
.in(shopIdList != null && !shopIdList.isEmpty(),Product::getShopId,shopIdList)
|
|
|
|
|
.orderByDesc(Product::getPutawayTime));
|
|
|
|
|
List<Product> records = products.getRecords();
|
|
|
|
|
records.forEach(prod->{
|
|
|
|
|
ShopDetail shop = shopDetailService.getById(prod.getShopId());
|
|
|
|
|
if (shop != null) {
|
|
|
|
|
prod.setShopName(shop.getShopName());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
products.setRecords(records);
|
|
|
|
|
return ServerResponseEntity.success(products);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -91,6 +115,10 @@ public class ProductController {
|
|
|
|
|
//获取分组标签
|
|
|
|
|
List<Long> listTagId = prodTagReferenceService.listTagIdByProdId(prodId);
|
|
|
|
|
prod.setTagList(listTagId);
|
|
|
|
|
|
|
|
|
|
ShopDetail shopDetail = shopDetailService.getById(prod.getShopId());
|
|
|
|
|
prod.setShopName(shopDetail.getShopName());
|
|
|
|
|
|
|
|
|
|
return ServerResponseEntity.success(prod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -210,6 +238,22 @@ public class ProductController {
|
|
|
|
|
}
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 更新商品状态
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/prodZone")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('prod:prod:updateZone')")
|
|
|
|
|
public ServerResponseEntity<Void> setZone(@RequestBody Product product) {
|
|
|
|
|
|
|
|
|
|
productService.updateById(product);
|
|
|
|
|
productService.removeProductCacheByProdId(product.getProdId());
|
|
|
|
|
List<String> userIds = basketService.listUserIdByProdId(product.getProdId());
|
|
|
|
|
for (String userId : userIds) {
|
|
|
|
|
basketService.removeShopCartItemsCacheByUserId(userId);
|
|
|
|
|
}
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkParam(ProductParam productParam) {
|
|
|
|
|
if (CollectionUtil.isEmpty(productParam.getTagList())) {
|
|
|
|
|
|