新增接口,分类新增,优化添加分类的复杂性

This commit is contained in:
liyj 2025-11-29 10:38:19 +08:00
parent 1d328b38f7
commit d9bb03770a
4 changed files with 68 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package com.suisung.mall.shop.base.controller.admin;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
@ -10,10 +11,7 @@ import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import static com.suisung.mall.common.utils.ContextUtil.getCurrentUser;
@ -168,5 +166,15 @@ public class ShopBaseProductCategoryController {
return CommonResult.success(shopBaseProductCategoryService.tree(queryWrapper));
}
/**
* 新增优化
* @return
*/
@ApiOperation(value = "商品分类表-新增优化", notes = "商品分类表-新增优化")
@RequestMapping(value = "/simpleAdd", method = {RequestMethod.POST})
public CommonResult simpleAdd(@RequestBody JSONArray jsonArray) {
return CommonResult.success(shopBaseProductCategoryService.simpleAdd(jsonArray));
}
}

View File

@ -1,7 +1,9 @@
package com.suisung.mall.shop.base.service;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.domain.UserDto;
import com.suisung.mall.common.modules.admin.ElTree;
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
@ -151,4 +153,6 @@ public interface ShopBaseProductCategoryService extends IBaseService<ShopBasePro
void clearCategoryCache(String storeId);
CommonResult simpleAdd(JSONArray jsonArray);
}

View File

@ -7,8 +7,11 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.api.StateCode;
import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.constant.RedisConstant;
@ -47,6 +50,7 @@ import com.suisung.mall.shop.product.service.ShopProductItemService;
import com.suisung.mall.shop.sixun.service.SxSyncCategoryService;
import com.suisung.mall.shop.store.service.ShopStoreActivityItemService;
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
import com.suisung.mall.shop.user.service.ShopUserCartService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -54,7 +58,9 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.*;
@ -86,6 +92,7 @@ public class ShopBaseProductCategoryServiceImpl extends BaseServiceImpl<ShopBase
private ShopBaseProductAssistService productAssistService;
@Autowired
private ShopBaseProductAssistItemService productAssistItemService;
@Lazy
@Autowired
private ShopBaseProductBrandService productBrandService;
@Lazy
@ -126,6 +133,10 @@ public class ShopBaseProductCategoryServiceImpl extends BaseServiceImpl<ShopBase
@Autowired
private ShopStoreBaseService shopStoreBaseService;
@Lazy
@Resource
private SyncThirdDataService syncThirdDataService;
@Override
public List<ElTree> tree(QueryWrapper<ShopBaseProductCategory> queryWrapper) {
List<ShopBaseProductCategory> list = find(queryWrapper);
@ -1279,4 +1290,35 @@ public class ShopBaseProductCategoryServiceImpl extends BaseServiceImpl<ShopBase
redisService.del(cache_key);
}
@Override
@Transactional
public CommonResult simpleAdd(JSONArray jsonArray) {
UserDto userDto= ContextUtil.getCurrentUser();
if(null==userDto){
throw new ApiException("权限不足");
}
if(userDto.getRole_id()==2||userDto.getRole_id()==9){
String storeId=userDto.getStore_id();
QueryWrapper<ShopBaseProductBrand> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("store_id",Integer.valueOf(storeId));
queryWrapper.eq("brand_name","其它品牌");
List<ShopBaseProductBrand> shopBaseProductBrands=productBrandService.list(queryWrapper);
if(CollectionUtil.isEmpty(shopBaseProductBrands)){
ShopBaseProductBrand shopBaseProductBrand=new ShopBaseProductBrand();
shopBaseProductBrand.setBrand_name("其它品牌");
shopBaseProductBrand.setBrand_desc("其它品牌");
productBrandService.saveOrUpdateBrand(shopBaseProductBrand);
}
List<ShopBaseProductCategory> shopBaseProductCategories = JSONUtil.toList(jsonArray, ShopBaseProductCategory.class);
syncThirdDataService.baseSaveOrUpdateShopBaseProductCategoryBatch(shopBaseProductCategories,jsonArray,storeId);
String redisKey = RedisConstant.Product_Cate_Key + ":" + storeId;
redisService.del(redisKey);
}else{
throw new ApiException("权限不足");
}
return null;
}
}

View File

@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suisung.mall.common.api.ResultCode;
import com.suisung.mall.common.api.StateCode;
import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.domain.UserDto;
import com.suisung.mall.common.enums.DicEnum;
import com.suisung.mall.common.exception.ApiException;
import com.suisung.mall.common.feignService.AccountService;
@ -35,6 +36,7 @@ import com.suisung.mall.common.modules.store.ShopStoreBase;
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
import com.suisung.mall.common.pojo.req.SyncThirdMemberReq;
import com.suisung.mall.common.pojo.res.ThirdApiRes;
import com.suisung.mall.common.utils.ContextUtil;
import com.suisung.mall.common.utils.DateTimeUtils;
import com.suisung.mall.common.utils.I18nUtil;
import com.suisung.mall.common.utils.StringUtils;
@ -51,6 +53,7 @@ import com.suisung.mall.shop.sixun.dto.SxGoosModel;
import com.suisung.mall.shop.store.service.ShopStoreActivityBaseService;
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
import org.apache.commons.lang3.math.NumberUtils;
import org.hibernate.validator.internal.util.stereotypes.Lazy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -71,6 +74,7 @@ public abstract class SyncBaseThirdSxAbstract{
private final Logger logger = LoggerFactory.getLogger(SyncBaseThirdSxAbstract.class);
@Autowired
private ShopBaseProductBrandService productBrandService;
@Lazy
@Autowired
private ShopBaseProductCategoryService productCategoryService;
@Autowired
@ -130,6 +134,11 @@ public abstract class SyncBaseThirdSxAbstract{
public int baseSaveOrUpdateShopBaseProductCategoryBatch(List<ShopBaseProductCategory> list ,JSONArray categoryListJSON,
String storeId){
int count = 0;
UserDto userDto=ContextUtil.getCurrentUser();
Integer dataSource=1;
if(userDto==null){
dataSource=2;
}
List<ShopBaseProductType> productTypeList = new ArrayList<>();
Map<String,String> productTypeListMap=new HashMap<>();
for (int i = 0; i < list.size(); i++) {
@ -138,7 +147,7 @@ public abstract class SyncBaseThirdSxAbstract{
continue;
}
list.get(i).setStore_id(storeId); // app 记录传进来
list.get(i).setData_source(2); // 思迅数据来源
list.get(i).setData_source(dataSource); // 思迅数据来源
list.get(i).setCategory_is_enable(1);
JSONObject o = (JSONObject) categoryListJSON.get(i);