From 961c82a1c7a4df147f2c9e173163d10e73de20aa Mon Sep 17 00:00:00 2001 From: xhxu Date: Wed, 22 Feb 2023 14:56:52 +0800 Subject: [PATCH] //goodsc --- .../V2023022000001__add_tt_goods_category.sql | 11 ++++ .../mapper/TtMallGoodsCategoryMapper.java | 7 ++ .../impl/TtGoodsCategoryServiceImpl.java | 3 + .../impl/TtMallGoodsCategoryServiceImpl.java | 65 +++++++++++++++++-- .../mapper/TtMallGoodsCategoryMapper.xml | 21 ++++++ 5 files changed, 103 insertions(+), 4 deletions(-) diff --git a/mallinkAdmin/src/main/resources/db/migration/V2023022000001__add_tt_goods_category.sql b/mallinkAdmin/src/main/resources/db/migration/V2023022000001__add_tt_goods_category.sql index 737cc2e1d..a1920be7d 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V2023022000001__add_tt_goods_category.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V2023022000001__add_tt_goods_category.sql @@ -2,3 +2,14 @@ ALTER TABLE `mallink`.`tt_goods_category` MODIFY COLUMN `service_fee` int(11) DEFAULT NULL COMMENT ''抖音软件服务费率(万分之)'' AFTER `is_leaf`, ADD COLUMN `software_fee` int(11) COMMENT ''软件服务费率(万分位)'' AFTER `service_fee`; +DROP TABLE IF EXISTS `tt_mall_goods_category`; +CREATE TABLE `tt_mall_goods_category` ( + `goods_category_id` int(11) NOT NULL, + `tenant_id` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', + `parent_tenant_id` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父租户ID', + `software_fee` int(11) DEFAULT NULL COMMENT '软件服务费率(万分位)', + `create_date` datetime(0) DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_date` datetime(0) DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', + `is_del` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否删除1是0否', + UNIQUE INDEX `goods_category_id`(`goods_category_id`, `tenant_id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/mapper/TtMallGoodsCategoryMapper.java b/mallinkService/src/main/java/com/iformall/mapper/TtMallGoodsCategoryMapper.java index 7c8083271..263f3c4c7 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/TtMallGoodsCategoryMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/TtMallGoodsCategoryMapper.java @@ -12,6 +12,12 @@ public interface TtMallGoodsCategoryMapper extends CommonMapper findAllTreeList(TtMallGoodsCategoryVo recordVo); + TtMallGoodsCategory selectByTenantAndCategoryId(TtMallGoodsCategory mallGoodsCategory); + + int updateByTenantAndCategoryId(TtMallGoodsCategory old); + + int insertList(List childList); + List findList(TtMallGoodsCategory record); @@ -22,4 +28,5 @@ public interface TtMallGoodsCategoryMapper extends CommonMapper ids = new ArrayList<>(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java index c99642e4b..3067769ce 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java @@ -17,8 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -29,6 +31,9 @@ public class TtMallGoodsCategoryServiceImpl implements TtMallGoodsCategoryServic @Autowired TtMallGoodsCategoryMapper ttMallGoodsCategoryMapper; + @Autowired + TtGoodsCategoryMapper ttGoodsCategoryMapper; + @Autowired @Qualifier("objectCommonRedisTemplate") RedisTemplate categoryRedisTemplate; @@ -74,13 +79,65 @@ public class TtMallGoodsCategoryServiceImpl implements TtMallGoodsCategoryServic return childList; } + @Transactional(rollbackFor = {Exception.class}) @Override public void updateFee(TtMallGoodsCategoryVo record) { - TtMallGoodsCategory mgcUpd = new TtMallGoodsCategory(); - mgcUpd.setGoodsCategoryId(record.getCategoryId()); - mgcUpd.updateTenantInfo(record); -// ttMallGoodsCategoryMapper.selectByTenantAnd(); + updateFeeByIds(record,record.getCategoryId(),record.getMallSoftwareFee(),new Date()); + } + /** + * 循环修改费率 + */ + private void updateFeeByIds(TenantEntity tenantEntity,Integer categoryId,Integer softwareFee,Date now){ + if(categoryId == null){ + return; + } + TtMallGoodsCategory mallGoodsCategory = new TtMallGoodsCategory(); + mallGoodsCategory.setGoodsCategoryId(categoryId); + mallGoodsCategory.updateTenantInfo(tenantEntity); + TtMallGoodsCategory old = ttMallGoodsCategoryMapper.selectByTenantAndCategoryId(mallGoodsCategory); + + TtGoodsCategory gcq = new TtGoodsCategory(); + gcq.setParentId(categoryId); + List childIds = ttGoodsCategoryMapper.findIdAll(gcq); + if(old != null){ + if(!softwareFee.equals(old.getSoftwareFee())){ + old.setSoftwareFee(softwareFee); + old.setUpdateDate(now); + ttMallGoodsCategoryMapper.updateByTenantAndCategoryId(old); + } + if(childIds != null && !childIds.isEmpty()){ + old.setGoodsCategoryId(null); + old.setCategoryIds(childIds); + ttMallGoodsCategoryMapper.updateByTenantAndCategoryId(old); + } + }else{ + old = new TtMallGoodsCategory(); + old.setGoodsCategoryId(categoryId); + old.updateTenantInfo(tenantEntity); + old.setSoftwareFee(softwareFee); + old.setCreateDate(now); + old.setUpdateDate(now); + ttMallGoodsCategoryMapper.insert(old); + if(childIds != null && !childIds.isEmpty()){ + List childList = new ArrayList<>(); + for (Integer childId:childIds) { + TtMallGoodsCategory child = new TtMallGoodsCategory(); + old.setGoodsCategoryId(childId); + old.updateTenantInfo(tenantEntity); + old.setSoftwareFee(softwareFee); + old.setCreateDate(now); + old.setUpdateDate(now); + childList.add(child); + } + ttMallGoodsCategoryMapper.insertList(childList); + } + } + if(childIds != null && !childIds.isEmpty()){ + for (Integer childId:childIds) { + updateFeeByIds(tenantEntity,childId,softwareFee,now); + } + } } } diff --git a/mallinkService/src/main/resources/mapper/TtMallGoodsCategoryMapper.xml b/mallinkService/src/main/resources/mapper/TtMallGoodsCategoryMapper.xml index 3e18a4620..41df734b8 100644 --- a/mallinkService/src/main/resources/mapper/TtMallGoodsCategoryMapper.xml +++ b/mallinkService/src/main/resources/mapper/TtMallGoodsCategoryMapper.xml @@ -44,6 +44,25 @@ + + + + update tt_mall_goods_category set `software_fee` = #{softwareFee}, update_date = #{updateDate} + where `tenant_id` = #{tenantId} + + and `goods_category_id` = #{goodsCategoryId} + + + and goods_category_id in + + #{idItem} + + + +