master:系统调优;

pull/1121/head
liujiang 2025-09-23 09:38:48 +08:00
parent 4d9ce0c646
commit a3affaa0b3
5 changed files with 179 additions and 19 deletions

View File

@ -1,15 +1,23 @@
package com.ruoyi.web.controller.xkt.shipMaster;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.web.controller.xkt.shipMaster.vo.DoubleRunVO;
import com.ruoyi.web.controller.xkt.shipMaster.vo.ShipMasterVO;
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.stream.Collectors;
/**
* Compare
*
@ -24,10 +32,140 @@ public class CompareBizController extends BaseController {
final RedisCache redisCache;
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PutMapping("/double/ship")
public R<Integer> createAttrCache() {
@PutMapping("/double/ship/{userId}/{supplierId}")
public R<Integer> compare(@PathVariable("userId") Integer userId, @PathVariable("supplierId") Integer supplierId) {
Map<String, List<String>> multiSaleSameGoMap = new HashMap<>();
Map<String, List<String>> multiOffSaleSameGoMap = new HashMap<>();
Map<String, List<String>> multiSameFMap = new HashMap<>();
List<DoubleRunVO.DRIArtNoSkuVO> doubleRunSaleBasicList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_SALE_BASIC_KEY + userId), new ArrayList<>());
List<String> doubleRunSaleArtNoList = doubleRunSaleBasicList.stream().map(DoubleRunVO.DRIArtNoSkuVO::getArticle_number)
.distinct().collect(Collectors.toList());
// 查看double_run 在售的商品 这边有多少相似的货号
doubleRunSaleArtNoList.forEach(article_number -> {
// 只保留数字,去除其他所有符号
String cleanArtNo = article_number.replaceAll("[^0-9]", "");
List<String> existList = multiSaleSameGoMap.containsKey(cleanArtNo) ? multiSaleSameGoMap.get(cleanArtNo) : new ArrayList<>();
existList.add(article_number);
multiSaleSameGoMap.put(cleanArtNo, existList);
});
// 查看double_run 下架的商品有多少相似的货号
List<DoubleRunVO.DRIArtNoSkuVO> doubleRunOffSaleBasicList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_OFF_SALE_BASIC_KEY + userId), new ArrayList<>());
List<String> doubleRunOffSaleArtNoList = doubleRunOffSaleBasicList.stream().map(DoubleRunVO.DRIArtNoSkuVO::getArticle_number)
.distinct().collect(Collectors.toList());
doubleRunOffSaleArtNoList.forEach(article_number -> {
// 只保留数字,去除其他所有符号
String cleanArtNo = article_number.replaceAll("[^0-9]", "");
List<String> existList = multiOffSaleSameGoMap.containsKey(cleanArtNo) ? multiOffSaleSameGoMap.get(cleanArtNo) : new ArrayList<>();
existList.add(article_number);
multiOffSaleSameGoMap.put(cleanArtNo, existList);
});
// 查看ShipMaster 这边有多少相似的货号
List<ShipMasterVO.SMIVO> shipMasterProdList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + supplierId), new ArrayList<>());
List<String> shipArtNoList = shipMasterProdList.stream().map(ShipMasterVO.SMIVO::getArtNo)
.distinct().collect(Collectors.toList());
shipArtNoList.forEach(artNo -> {
// 只保留数字,去除其他所有符号
String cleanArtNo = artNo.replaceAll("[^0-9]", "");
List<String> existList = multiSameFMap.containsKey(cleanArtNo) ? multiSameFMap.get(cleanArtNo) : new ArrayList<>();
existList.add(artNo);
multiSameFMap.put(cleanArtNo, existList);
});
multiSaleSameGoMap.forEach((key, value) -> {
if (value.size() > 1) {
System.err.println(key + ":" + value + ":" + value.size());
}
});
System.err.println("============");
multiSameFMap.forEach((key, value) -> {
if (value.size() > 1) {
System.err.println(key + ":" + value + ":" + value.size());
}
});
Set<String> commonKeys = new HashSet<>(multiSaleSameGoMap.keySet());
commonKeys.retainAll(multiSameFMap.keySet());
// 获取GO2独有的key
Set<String> onlyInGoMap = new HashSet<>(multiSaleSameGoMap.keySet());
onlyInGoMap.removeAll(commonKeys);
// 获取ShipMaster独有的key
Set<String> onlyInFMap = new HashSet<>(multiSameFMap.keySet());
onlyInFMap.removeAll(commonKeys);
// 打印各自独有的key
System.err.println("============ GO2独有的key ============");
onlyInGoMap.forEach(key -> {
System.err.println(key + ":" + multiSaleSameGoMap.get(key));
});
System.err.println("============ ShipMaster独有的key ============");
onlyInFMap.forEach(key -> {
System.err.println(key + ":" + multiSameFMap.get(key));
});
onlyInFMap.removeAll(multiOffSaleSameGoMap.keySet());
System.err.println("============ ShipMaster 去掉下架的 独有的key ============");
onlyInFMap.forEach(key -> {
System.err.println(key + ":" + multiSameFMap.get(key));
});
/* List<String> articleNumberList = doubleRunBasicList.stream().map(DoubleRunVO.DRIArtNoSkuVO::getArticle_number)
.distinct().collect(Collectors.toList());
List<ShipMasterVO.SMIVO> shipMasterProdList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + supplierId), new ArrayList<>());
List<String> artNoList = shipMasterProdList.stream().map(ShipMasterVO.SMIVO::getArtNo).distinct().collect(Collectors.toList());
*/
/*// double_run基础数据
List<DoubleRunVO.DRIArtNoSkuVO> doubleRunBasicList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_BASIC_KEY + userId), new ArrayList<>());
List<String> articleNumberList = doubleRunBasicList.stream().map(DoubleRunVO.DRIArtNoSkuVO::getArticle_number)
.map(this::cleanArticleNumber).map(x -> x.toLowerCase(Locale.ROOT)).distinct().collect(Collectors.toList());
// ship_master基础数据
List<ShipMasterVO.SMIVO> shipMasterProdList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + supplierId), new ArrayList<>());
List<String> artNoList = shipMasterProdList.stream().map(ShipMasterVO.SMIVO::getArtNo)
.map(x -> x.toLowerCase(Locale.ROOT)).distinct().collect(Collectors.toList());
Set<String> common = new HashSet<>(articleNumberList);
common.retainAll(artNoList);
// 找出只存在于第一个列表的货号
Set<String> onlyInList1 = new HashSet<>(articleNumberList);
onlyInList1.removeAll(artNoList);
// 找出只存在于第二个列表的货号
Set<String> onlyInList2 = new HashSet<>(artNoList);
onlyInList2.removeAll(articleNumberList);
common.forEach(artNo -> System.err.println("common:" + artNo));
onlyInList1.stream().sorted(Comparator.naturalOrder()).forEach(artNo -> System.err.println("onlyInList1:" + artNo));
onlyInList2.stream().sorted(Comparator.naturalOrder()).forEach(artNo -> System.err.println("onlyInList2:" + artNo));*/
return R.ok();

View File

@ -35,20 +35,38 @@ public class DoubleRunController extends BaseController {
final RedisCache redisCache;
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PostMapping("/cache")
public R<Integer> createCache(@Validated @RequestBody DoubleRunVO importVO) {
List<DoubleRunVO.DRIArtNoVO> artNoList = importVO.getData().getData();
final Integer userId = importVO.getData().getData().get(0).getUser_id();
@PostMapping("/sale/cache")
public R<Integer> createSaleCache(@Validated @RequestBody DoubleRunVO doubleRunVO) {
List<DoubleRunVO.DRIArtNoVO> artNoList = doubleRunVO.getData().getData();
final Integer userId = doubleRunVO.getData().getData().get(0).getUser_id();
// 先从redis中获取列表数据
List<DoubleRunVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.DOUBLE_RUN_BASIC_KEY + userId), new ArrayList<>());
.getCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_SALE_BASIC_KEY + userId), new ArrayList<>());
artNoList.forEach(artNoInfo -> {
artNoInfo.getSkus().forEach(x -> x.setColor(this.decodeUnicode(x.getColor()))
.setArticle_number(artNoInfo.getArticle_number()).setProduct_id(artNoInfo.getId()));
cacheList.addAll(artNoInfo.getSkus());
});
// 存到redis中
redisCache.setCacheObject(CacheConstants.DOUBLE_RUN_BASIC_KEY + userId, cacheList);
redisCache.setCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_SALE_BASIC_KEY + userId, cacheList);
return R.ok();
}
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PostMapping("/off-sale/cache")
public R<Integer> createOffSaleCache(@Validated @RequestBody DoubleRunVO doubleRunVO) {
List<DoubleRunVO.DRIArtNoVO> artNoList = doubleRunVO.getData().getData();
final Integer userId = doubleRunVO.getData().getData().get(0).getUser_id();
// 先从redis中获取列表数据
List<DoubleRunVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_OFF_SALE_BASIC_KEY + userId), new ArrayList<>());
artNoList.forEach(artNoInfo -> {
artNoInfo.getSkus().forEach(x -> x.setColor(this.decodeUnicode(x.getColor()))
.setArticle_number(artNoInfo.getArticle_number()).setProduct_id(artNoInfo.getId()));
cacheList.addAll(artNoInfo.getSkus());
});
// 存到redis中
redisCache.setCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_OFF_SALE_BASIC_KEY + userId, cacheList);
return R.ok();
}
@ -57,7 +75,7 @@ public class DoubleRunController extends BaseController {
public R<Integer> createAttrCache(@PathVariable(value = "user_id") Integer user_id, @PathVariable("product_id") Integer product_id,
@Validated @RequestBody DoubleRunAttrVO attrVO) {
// 判断缓存中是否有该product_id
Map<String, String> existMap = redisCache.getCacheMap(CacheConstants.DOUBLE_RUN_ATTR_KEY + user_id + "_" + product_id);
Map<String, String> existMap = redisCache.getCacheMap(CacheConstants.MIGRATION_DOUBLE_RUN_SALE_ATTR_KEY + user_id + "_" + product_id);
if (MapUtils.isNotEmpty(existMap)) {
throw new ServiceException("该商品已设置过类目属性", HttpStatus.ERROR);
}
@ -73,7 +91,7 @@ public class DoubleRunController extends BaseController {
.put(this.decodeUnicode(x.getProps_name()), this.decodeUnicode(x.getPropsvalue_name())));
}
});
redisCache.setCacheMap(CacheConstants.DOUBLE_RUN_ATTR_KEY + user_id + "_" + product_id, attrMap);
redisCache.setCacheMap(CacheConstants.MIGRATION_DOUBLE_RUN_SALE_ATTR_KEY + user_id + "_" + product_id, attrMap);
return R.ok();
}
@ -83,7 +101,7 @@ public class DoubleRunController extends BaseController {
public R<Integer> getCache(@PathVariable Integer userId) {
// 从redis中获取数据
List<DoubleRunVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.DOUBLE_RUN_BASIC_KEY + userId), new ArrayList<>());
.getCacheObject(CacheConstants.MIGRATION_DOUBLE_RUN_SALE_BASIC_KEY + userId), new ArrayList<>());
if (CollectionUtils.isEmpty(cacheList)) {
return R.fail();
}

View File

@ -37,10 +37,10 @@ public class ShipMasterController extends BaseController {
final Integer supplierId = importVO.getData().getRecords().get(0).getSupplierId();
// 先从redis中获取列表数据
List<ShipMasterVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.SUPPLIER_KEY + supplierId), new ArrayList<>());
.getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + supplierId), new ArrayList<>());
CollectionUtils.addAll(cacheList, importVO.getData().getRecords());
// 存到redis中
redisCache.setCacheObject(CacheConstants.SUPPLIER_KEY + supplierId, cacheList, 5, TimeUnit.DAYS);
redisCache.setCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + supplierId, cacheList, 5, TimeUnit.DAYS);
return R.ok();
}
@ -49,7 +49,7 @@ public class ShipMasterController extends BaseController {
public R<Integer> getCache(@PathVariable Integer supplierId) {
// 从redis中获取数据
List<ShipMasterVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.SUPPLIER_KEY + supplierId), new ArrayList<>());
.getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + supplierId), new ArrayList<>());
if (CollectionUtils.isEmpty(cacheList)) {
return R.fail();
}

View File

@ -315,14 +315,18 @@ public class CacheConstants {
/**
*
*/
public static final String SUPPLIER_KEY = "supplier:";
public static final String MIGRATION_SUPPLIER_PROD_KEY = "mig_supplier_prod:";
/**
*
* double_run
*/
public static final String DOUBLE_RUN_BASIC_KEY = "double_run_basic:";
public static final String MIGRATION_DOUBLE_RUN_SALE_BASIC_KEY = "mig_double_run_sale_basic:";
/**
* double_run
*/
public static final String MIGRATION_DOUBLE_RUN_OFF_SALE_BASIC_KEY = "mig_double_run_off_sale_basic:";
/**
*
*/
public static final String DOUBLE_RUN_ATTR_KEY = "double_run_attr:";
public static final String MIGRATION_DOUBLE_RUN_SALE_ATTR_KEY = "mig_double_run_sale_attr:";
}

View File

@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND n.notice_title LIKE concat('%', #{noticeTitle}, '%')
</if>
<if test="noticeType != null">
AND n.notice
AND n.notice_type
</if>
AND un.user_id = #{userId}
ORDER BY