master:系统迁移优化;

pull/1121/head
liujiang 2025-09-22 15:45:53 +08:00
parent b40ef4f06b
commit 4d9ce0c646
7 changed files with 85 additions and 52 deletions

View File

@ -0,0 +1,37 @@
package com.ruoyi.web.controller.xkt.shipMaster;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Compare
*
* @author ruoyi
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/rest/v1/compare")
public class CompareBizController extends BaseController {
final IShipMasterService shipMasterService;
final RedisCache redisCache;
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PutMapping("/double/ship")
public R<Integer> createAttrCache() {
return R.ok();
}
}

View File

@ -1,20 +1,24 @@
package com.ruoyi.web.controller.xkt.shipMaster;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.constant.HttpStatus;
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.DoubleRunAttrRQVO;
import com.ruoyi.web.controller.xkt.shipMaster.vo.DoubleRunRQVO;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.controller.xkt.shipMaster.vo.DoubleRunAttrVO;
import com.ruoyi.web.controller.xkt.shipMaster.vo.DoubleRunVO;
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@ -32,39 +36,31 @@ public class DoubleRunController extends BaseController {
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PostMapping("/cache")
public R<Integer> createCache(@Validated @RequestBody DoubleRunRQVO importVO) {
List<DoubleRunRQVO.DRIArtNoVO> artNoList = importVO.getData().getData();
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();
// 先从redis中获取列表数据
List<DoubleRunRQVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.DOUBLE_RUN_KEY + userId), new ArrayList<>());
// Map<String, Map<String, List<DoubleRunImportVO.DRIArtNoSkuVO>>> artNoMap = new LinkedHashMap<>();
List<DoubleRunVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.DOUBLE_RUN_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());
// artNoMap.put(artNoInfo.getArticle_number(), artNoInfo.getSkus().stream().collect(Collectors
// .groupingBy(DoubleRunImportVO.DRIArtNoSkuVO::getColor)));
});
// CollectionUtils.addAll(cacheList, artNoList);
// 存到redis中
redisCache.setCacheObject(CacheConstants.DOUBLE_RUN_KEY + userId, cacheList);
// Map<String, List<String>> artNoColorMap = new LinkedHashMap<>();
// artNoMap.forEach((artNo, colorSkuMap) -> {
// artNoColorMap.put(artNo, new ArrayList<>(colorSkuMap.keySet()));
// colorSkuMap.forEach((color, skuList) -> {
// skuList.sort(Comparator.comparing(DoubleRunImportVO.DRIArtNoSkuVO::getSize));
// System.err.println(artNo + ":" + color + ":" + skuList);
// });
// });
redisCache.setCacheObject(CacheConstants.DOUBLE_RUN_BASIC_KEY + userId, cacheList);
return R.ok();
}
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PostMapping("/attr/cache/{product_id}")
public R<Integer> createAttrCache(@PathVariable Integer product_id, @Validated @RequestBody DoubleRunAttrRQVO attrVO) {
@PostMapping("/attr/cache/{user_id}/{product_id}")
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);
if (MapUtils.isNotEmpty(existMap)) {
throw new ServiceException("该商品已设置过类目属性", HttpStatus.ERROR);
}
Map<String, String> attrMap = new HashMap<>();
attrVO.getData().forEach((itemId, attr) -> {
// 不处理 multi=1 的属性
@ -73,15 +69,11 @@ public class DoubleRunController extends BaseController {
}
// 有值
if (attr.getHas_value() == 1) {
attr.getAttr().stream().filter(x -> x.getChoosed() == 1).forEach(x -> attrMap.put(this.decodeUnicode(x.getProps_name()), this.decodeUnicode(x.getPropsvalue_name())));
attr.getAttr().stream().filter(x -> x.getChoosed() == 1).forEach(x -> attrMap
.put(this.decodeUnicode(x.getProps_name()), this.decodeUnicode(x.getPropsvalue_name())));
}
});
Map<Integer, Map<String, String>> productIdAttrMap = new HashMap<>();
productIdAttrMap.put(product_id, attrMap);
redisCache.setCacheMap(CacheConstants.DOUBLE_RUN_ATTR_KEY + user_id + "_" + product_id, attrMap);
return R.ok();
}
@ -90,20 +82,20 @@ public class DoubleRunController extends BaseController {
@GetMapping("/cache/{userId}")
public R<Integer> getCache(@PathVariable Integer userId) {
// 从redis中获取数据
List<DoubleRunRQVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.DOUBLE_RUN_KEY + userId), new ArrayList<>());
List<DoubleRunVO.DRIArtNoSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.DOUBLE_RUN_BASIC_KEY + userId), new ArrayList<>());
if (CollectionUtils.isEmpty(cacheList)) {
return R.fail();
}
Map<String, List<DoubleRunRQVO.DRIArtNoSkuVO>> artNoGroup = cacheList.stream()
.sorted(Comparator.comparing(DoubleRunRQVO.DRIArtNoSkuVO::getArticle_number)
.thenComparing(DoubleRunRQVO.DRIArtNoSkuVO::getColor))
Map<String, List<DoubleRunVO.DRIArtNoSkuVO>> artNoGroup = cacheList.stream()
.sorted(Comparator.comparing(DoubleRunVO.DRIArtNoSkuVO::getArticle_number)
.thenComparing(DoubleRunVO.DRIArtNoSkuVO::getColor))
.collect(Collectors
.groupingBy(DoubleRunRQVO.DRIArtNoSkuVO::getArticle_number, LinkedHashMap::new, Collectors.toList()));
.groupingBy(DoubleRunVO.DRIArtNoSkuVO::getArticle_number, LinkedHashMap::new, Collectors.toList()));
// 货号 颜色 map
Map<String, List<String>> artNoColorMap = new LinkedHashMap<>();
artNoGroup.forEach((artNo, colorList) -> {
artNoColorMap.put(artNo, colorList.stream().map(DoubleRunRQVO.DRIArtNoSkuVO::getColor).collect(Collectors.toList()));
artNoColorMap.put(artNo, colorList.stream().map(DoubleRunVO.DRIArtNoSkuVO::getColor).collect(Collectors.toList()));
});
artNoColorMap.forEach((k,v) -> {
@ -112,7 +104,6 @@ public class DoubleRunController extends BaseController {
// TODO 如何对比??
return R.ok();
}

View File

@ -4,7 +4,7 @@ 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.ShipMasterRQVO;
import com.ruoyi.web.controller.xkt.shipMaster.vo.ShipMasterVO;
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
@ -14,6 +14,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@ -31,15 +32,15 @@ public class ShipMasterController extends BaseController {
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
@PostMapping("/cache")
public R<Integer> createCache(@Validated @RequestBody ShipMasterRQVO importVO) {
public R<Integer> createCache(@Validated @RequestBody ShipMasterVO importVO) {
// 供应商ID
final Integer supplierId = importVO.getData().getRecords().get(0).getSupplierId();
// 先从redis中获取列表数据
List<ShipMasterRQVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
List<ShipMasterVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.SUPPLIER_KEY + supplierId), new ArrayList<>());
CollectionUtils.addAll(cacheList, importVO.getData().getRecords());
// 存到redis中
redisCache.setCacheObject(CacheConstants.SUPPLIER_KEY + supplierId, cacheList);
redisCache.setCacheObject(CacheConstants.SUPPLIER_KEY + supplierId, cacheList, 5, TimeUnit.DAYS);
return R.ok();
}
@ -47,23 +48,23 @@ public class ShipMasterController extends BaseController {
@GetMapping("/cache/{supplierId}")
public R<Integer> getCache(@PathVariable Integer supplierId) {
// 从redis中获取数据
List<ShipMasterRQVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
List<ShipMasterVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
.getCacheObject(CacheConstants.SUPPLIER_KEY + supplierId), new ArrayList<>());
if (CollectionUtils.isEmpty(cacheList)) {
return R.fail();
}
// 按照artNo分组
Map<String, List<ShipMasterRQVO.SMIVO>> artNoGroup = cacheList.stream()
.sorted(Comparator.comparing(ShipMasterRQVO.SMIVO::getArtNo)
.thenComparing(ShipMasterRQVO.SMIVO::getColor))
Map<String, List<ShipMasterVO.SMIVO>> artNoGroup = cacheList.stream()
.sorted(Comparator.comparing(ShipMasterVO.SMIVO::getArtNo)
.thenComparing(ShipMasterVO.SMIVO::getColor))
.collect(Collectors
.groupingBy(ShipMasterRQVO.SMIVO::getArtNo, LinkedHashMap::new, Collectors.toList()));
.groupingBy(ShipMasterVO.SMIVO::getArtNo, LinkedHashMap::new, Collectors.toList()));
// 货号 颜色 对应的条码前缀
Map<String, Map<String, String>> artSnPrefixMap = new LinkedHashMap<>();
// 货号 颜色 map
Map<String, List<String>> artNoColorMap = new LinkedHashMap<>();
artNoGroup.forEach((artNo, colorList) -> {
artNoColorMap.put(artNo, colorList.stream().map(ShipMasterRQVO.SMIVO::getColor).collect(Collectors.toList()));
artNoColorMap.put(artNo, colorList.stream().map(ShipMasterVO.SMIVO::getColor).collect(Collectors.toList()));
Map<String, String> snPrefixMap = new LinkedHashMap<>();
// 按照颜色设置条码前缀
colorList.forEach(color -> snPrefixMap

View File

@ -10,7 +10,7 @@ import java.util.Map;
* @date 2025-05-11 23:46
*/
@Data
public class DoubleRunAttrRQVO {
public class DoubleRunAttrVO {
private Map<String, DRAAttrVO> data;

View File

@ -11,7 +11,7 @@ import java.util.List;
* @date 2025-05-11 23:46
*/
@Data
public class DoubleRunRQVO {
public class DoubleRunVO {
private DRIDataVO data;

View File

@ -9,7 +9,7 @@ import java.util.List;
* @date 2025-05-11 23:46
*/
@Data
public class ShipMasterRQVO {
public class ShipMasterVO {
private SMIDataVO data;

View File

@ -319,6 +319,10 @@ public class CacheConstants {
/**
*
*/
public static final String DOUBLE_RUN_KEY = "double_run:";
public static final String DOUBLE_RUN_BASIC_KEY = "double_run_basic:";
/**
*
*/
public static final String DOUBLE_RUN_ATTR_KEY = "double_run_attr:";
}