diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/base/controller/admin/ShopBaseProductCategoryController.java b/mall-shop/src/main/java/com/suisung/mall/shop/base/controller/admin/ShopBaseProductCategoryController.java index 9dac3ce7..612fa1c4 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/base/controller/admin/ShopBaseProductCategoryController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/base/controller/admin/ShopBaseProductCategoryController.java @@ -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)); + } + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseProductCategoryService.java b/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseProductCategoryService.java index fbcc6997..33108508 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseProductCategoryService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/base/service/ShopBaseProductCategoryService.java @@ -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 tree(QueryWrapper queryWrapper) { List list = find(queryWrapper); @@ -1279,4 +1290,44 @@ public class ShopBaseProductCategoryServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("store_id",Integer.valueOf(storeId)); + queryWrapper.eq("brand_name","其它品牌"); + List shopBaseProductBrands=productBrandService.list(queryWrapper); + if(CollectionUtil.isEmpty(shopBaseProductBrands)){ + ShopBaseProductBrand shopBaseProductBrand=new ShopBaseProductBrand(); + shopBaseProductBrand.setBrand_name("其它品牌"); + shopBaseProductBrand.setBrand_desc("其它品牌"); + productBrandService.saveOrUpdateBrand(shopBaseProductBrand); + } + List shopBaseProductCategories = JSONUtil.toList(jsonArray, ShopBaseProductCategory.class); + //校验 + for (ShopBaseProductCategory shopBaseProductCategory : shopBaseProductCategories) { + if(StringUtils.isEmpty(shopBaseProductCategory.getCategory_name())){ + throw new ApiException("存在分类为空的值"); + } + if(StringUtils.isEmpty(shopBaseProductCategory.getCategory_image())){ + shopBaseProductCategory.setCategory_image("https://media-mall-prod-1259811287.cos.ap-guangzhou.myqcloud.com/media/media/plantform/20250906/b93a9751b35a49fca6cf979829230868.png"); + } + } + syncThirdDataService.baseSaveOrUpdateShopBaseProductCategoryBatch(shopBaseProductCategories,jsonArray,storeId); + String redisKey = RedisConstant.Product_Cate_Key + ":" + storeId; + redisService.del(redisKey); + }else{ + throw new ApiException("权限不足"); + } + + return null; + } + + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncBaseThirdSxAbstract.java b/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncBaseThirdSxAbstract.java index 70afc2aa..36814cc1 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncBaseThirdSxAbstract.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/sync/service/impl/SyncBaseThirdSxAbstract.java @@ -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 list ,JSONArray categoryListJSON, String storeId){ int count = 0; + UserDto userDto=ContextUtil.getCurrentUser(); + Integer dataSource=1; + if(userDto==null){ + dataSource=2; + } List productTypeList = new ArrayList<>(); Map productTypeListMap=new HashMap<>(); for (int i = 0; i < list.size(); i++) { @@ -138,9 +147,10 @@ public abstract class SyncBaseThirdSxAbstract{ continue; } list.get(i).setStore_id(storeId); // app 记录传进来 - list.get(i).setData_source(2); // 思迅数据来源 - list.get(i).setCategory_is_enable(1); - + list.get(i).setData_source(dataSource); // 思迅数据来源 + if(null== list.get(i).getCategory_is_enable()){ + list.get(i).setCategory_is_enable(1); + } JSONObject o = (JSONObject) categoryListJSON.get(i); ShopBaseProductType productType=new ShopBaseProductType(); productType.setType_is_draft(1);//发布 diff --git a/sql/shop/dev/20251129_ddl.sql b/sql/shop/dev/20251129_ddl.sql new file mode 100644 index 00000000..91ce46fe --- /dev/null +++ b/sql/shop/dev/20251129_ddl.sql @@ -0,0 +1 @@ +INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/shop-base-product-category/simpleAdd', 'index', 'master', '', '0', '/admin/shop/shop-base-product-category/simpleAdd','分类新增-简化版'); \ No newline at end of file