master:系统调优;
parent
0e1f61ebfd
commit
c684529d91
|
|
@ -154,47 +154,19 @@ public class GtController extends BaseController {
|
|||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* step5
|
||||
*/
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
@GetMapping("/prod/cache/{userId}")
|
||||
public R<Integer> getProdCache(@PathVariable Integer userId) {
|
||||
// 从redis中获取数据
|
||||
List<GtProdSkuVO> cacheList = ObjectUtils.defaultIfNull(redisCache
|
||||
.getCacheObject(CacheConstants.MIGRATION_GT_SALE_BASIC_KEY + userId), new ArrayList<>());
|
||||
if (CollectionUtils.isEmpty(cacheList)) {
|
||||
return R.fail();
|
||||
}
|
||||
Map<String, List<GtProdSkuVO>> artNoGroup = cacheList.stream()
|
||||
.sorted(Comparator.comparing(GtProdSkuVO::getArticle_number)
|
||||
.thenComparing(GtProdSkuVO::getColor))
|
||||
.collect(Collectors
|
||||
.groupingBy(GtProdSkuVO::getArticle_number, LinkedHashMap::new, Collectors.toList()));
|
||||
// 货号 颜色 map
|
||||
Map<String, Set<String>> artNoColorMap = new LinkedHashMap<>();
|
||||
artNoGroup.forEach((artNo, colorList) -> {
|
||||
artNoColorMap.put(artNo, colorList.stream().map(GtProdSkuVO::getColor).collect(Collectors.toSet()));
|
||||
});
|
||||
@DeleteMapping("/clear/cache/{user_id}/{product_id}")
|
||||
public R<Integer> clearCache(@PathVariable(value = "user_id") Integer userId, @PathVariable("product_id") Integer productId) {
|
||||
|
||||
artNoColorMap.forEach((k, v) -> {
|
||||
System.err.println(k + ":" + v);
|
||||
});
|
||||
|
||||
// cacheList 按照货号分组,获取所有价格,价格去重
|
||||
Map<String, Set<BigDecimal>> artNoPriceMap = cacheList.stream().collect(Collectors.groupingBy(
|
||||
GtProdSkuVO::getArticle_number, Collectors.mapping(GtProdSkuVO::getPrice, Collectors.toSet())));
|
||||
AtomicInteger count = new AtomicInteger();
|
||||
artNoPriceMap.forEach((k, v) -> {
|
||||
if (v.size() > 1) {
|
||||
count.addAndGet(1);
|
||||
System.err.println(k + ":" + v);
|
||||
}
|
||||
});
|
||||
System.err.println(count);
|
||||
|
||||
// Map<String, List<Integer>> artNoPriceMap =
|
||||
|
||||
|
||||
// TODO 如何对比??
|
||||
// 清除GT在售商品缓存
|
||||
redisCache.deleteObject(CacheConstants.MIGRATION_GT_SALE_BASIC_KEY + userId);
|
||||
// 清除GT下架商品缓存
|
||||
redisCache.deleteObject(CacheConstants.MIGRATION_GT_OFF_SALE_BASIC_KEY + userId);
|
||||
// 清除GT在售商品属性缓存
|
||||
redisCache.deleteObject(CacheConstants.MIGRATION_GT_SALE_ATTR_KEY + userId + "_" + productId);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.ruoyi.common.core.controller.BaseController;
|
|||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.web.controller.xkt.migartion.vo.ty.TyCusDiscImportVO;
|
||||
import com.ruoyi.web.controller.xkt.migartion.vo.ty.TyCusImportVO;
|
||||
|
|
@ -15,10 +16,7 @@ import lombok.RequiredArgsConstructor;
|
|||
import org.apache.commons.collections4.CollectionUtils;
|
||||
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.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -54,6 +52,8 @@ public class TyController extends BaseController {
|
|||
tyProdVOList = tyProdVOList.stream()
|
||||
// 只导入价格不能为空的存货
|
||||
.filter(x -> ObjectUtils.isNotEmpty(x.getPrice()))
|
||||
// 过滤掉货号为空的存货
|
||||
.filter(x -> StringUtils.isNotBlank(x.getTySnPrefix()))
|
||||
.map(x -> {
|
||||
String prodArtNum = x.getProdArtNum().trim();
|
||||
String colorName = x.getColorName().trim();
|
||||
|
|
@ -70,7 +70,7 @@ public class TyController extends BaseController {
|
|||
System.err.println(k + ":" + v);
|
||||
});
|
||||
// 存到redis中
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_PROD_KEY + userId, tyProdVOList, 5, TimeUnit.DAYS);
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_PROD_KEY + userId, tyProdVOList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ public class TyController extends BaseController {
|
|||
List<TyCusImportVO> tyCusVOList = util.importExcel(file.getInputStream());
|
||||
tyCusVOList.forEach(x -> x.setCusName(x.getCusName().trim()));
|
||||
// 存到redis中
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_CUS_KEY + userId, tyCusVOList, 5, TimeUnit.DAYS);
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_CUS_KEY + userId, tyCusVOList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
|
@ -93,19 +93,44 @@ public class TyController extends BaseController {
|
|||
* step3
|
||||
*/
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
@PostMapping("/cus/disc/cache/{cusName}/{userId}")
|
||||
public R<Integer> createCusDiscCache(@PathVariable(value = "userId") Integer userId, @PathVariable(value = "cusName") String cusName,
|
||||
MultipartFile file) throws IOException {
|
||||
@PostMapping("/cus/disc/cache")
|
||||
public R<Integer> createCusDiscCache(@RequestParam(value = "userId") Long userId, @RequestParam(value = "cusName") String cusName,
|
||||
@RequestParam(value = "selfCheck") Boolean selfCheck, MultipartFile file) throws IOException {
|
||||
// 判断客户是否存在
|
||||
List<TyCusImportVO> tyCusVOList = redisCache.getCacheObject(CacheConstants.MIGRATION_TY_CUS_KEY + userId);
|
||||
Map<String, TyCusImportVO> tyCusMap = tyCusVOList.stream().collect(Collectors.toMap(TyCusImportVO::getCusName, x -> x));
|
||||
if (!tyCusMap.containsKey(cusName)) {
|
||||
throw new ServiceException(cusName + " : 客户不存在", HttpStatus.ERROR);
|
||||
}
|
||||
// 从redis中获取已存在的客户优惠数据
|
||||
List<TyCusDiscImportVO> cacheList = redisCache.getCacheObject(CacheConstants.MIGRATION_TY_CUS_DISCOUNT_KEY + userId);
|
||||
cacheList = Optional.ofNullable(cacheList).orElse(new ArrayList<>());
|
||||
// 判断当前客户是否已导入过,若是则直接报错
|
||||
Map<String, List<TyCusDiscImportVO>> cusDiscMap = cacheList.stream().collect(Collectors.groupingBy(TyCusDiscImportVO::getCusName));
|
||||
if (cusDiscMap.containsKey(cusName)) {
|
||||
throw new ServiceException("客户已导入过优惠数据", HttpStatus.ERROR);
|
||||
throw new ServiceException(cusName + " : 客户已导入过优惠数据", HttpStatus.ERROR);
|
||||
}
|
||||
ExcelUtil<TyCusDiscImportVO> util = new ExcelUtil<>(TyCusDiscImportVO.class);
|
||||
List<TyCusDiscImportVO> tyProdVOList = util.importExcel(file.getInputStream());
|
||||
// 是否要自校验,校验识图是否准确
|
||||
if (selfCheck) {
|
||||
Map<String, Map<String, Integer>> artNoColorDiscountMap = tyProdVOList.stream()
|
||||
// 只设置有优惠的存货及颜色
|
||||
.filter(x -> ObjectUtils.isNotEmpty(x.getBasicPrice()))
|
||||
.collect(Collectors.groupingBy(TyCusDiscImportVO::getProdArtNum, Collectors.toMap(TyCusDiscImportVO::getColorName, x ->
|
||||
ObjectUtils.defaultIfNull(x.getBasicPrice(), 0) - ObjectUtils.defaultIfNull(x.getCustomerPrice(), 0), (v1, v2) -> v2)));
|
||||
// 校验同一客户在同一货号不同颜色存在优惠是否相同,不同则需要提示
|
||||
List<String> discErrorList = new ArrayList<>();
|
||||
artNoColorDiscountMap.forEach((artNo, colorDiscMap) -> {
|
||||
// 判断colorDiscMap所有颜色的优惠是否相同
|
||||
if (colorDiscMap.values().stream().distinct().count() > 1) {
|
||||
discErrorList.add(cusName + ":" + artNo + "," + "不同颜色优惠力度不同!");
|
||||
}
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(discErrorList)) {
|
||||
throw new ServiceException(discErrorList.toString(), HttpStatus.ERROR);
|
||||
}
|
||||
}
|
||||
// 因为是采用的截图转excel方式,所以每个张图会冗余部分数据长度,导入是需要判断是否已存在
|
||||
Map<String, TyCusDiscImportVO> importCusDiscMap = new ConcurrentHashMap<>();
|
||||
List<TyCusDiscImportVO> importList = new ArrayList<>();
|
||||
|
|
@ -118,8 +143,8 @@ public class TyController extends BaseController {
|
|||
System.err.println(x.getProdArtNum() + ":" + x.getColorName());
|
||||
} else {
|
||||
final int discount = x.getBasicPrice() - x.getCustomerPrice();
|
||||
if (discount < 0) {
|
||||
errorList.add(cusName + ":" + x.getProdArtNum() + ":" + x.getColorName() + ":优惠金额不能小于0");
|
||||
if (discount <= 0) {
|
||||
errorList.add(cusName + ":" + x.getProdArtNum() + ":" + x.getColorName() + ":优惠金额不能小于等于0");
|
||||
}
|
||||
String prodArtNum = x.getProdArtNum().trim();
|
||||
String colorName = x.getColorName().trim();
|
||||
|
|
@ -138,7 +163,7 @@ public class TyController extends BaseController {
|
|||
// 加到总的客户优惠上
|
||||
CollectionUtils.addAll(cacheList, importList);
|
||||
// 存到redis中
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_CUS_DISCOUNT_KEY + userId, cacheList, 5, TimeUnit.DAYS);
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_CUS_DISCOUNT_KEY + userId, cacheList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +192,7 @@ public class TyController extends BaseController {
|
|||
cacheList.add(x.setProdArtNum(prodArtNum).setColorName(colorName));
|
||||
}
|
||||
});
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_PROD_STOCK_KEY + userId, cacheList, 5, TimeUnit.DAYS);
|
||||
redisCache.setCacheObject(CacheConstants.MIGRATION_TY_PROD_STOCK_KEY + userId, cacheList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
store_product_statistics sps
|
||||
WHERE
|
||||
sps.del_flag = 0
|
||||
AND sps.img_search_count > 0
|
||||
AND sps.voucher_date BETWEEN #{beginDate} AND #{endDate}
|
||||
GROUP BY
|
||||
sps.store_prod_id
|
||||
|
|
|
|||
Loading…
Reference in New Issue