master:库存盘点返回数据调整;
parent
8d0a2a17ee
commit
fc81530d1a
|
|
@ -0,0 +1,133 @@
|
|||
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.DoubleRunImportVO;
|
||||
import com.ruoyi.web.controller.xkt.shipMaster.vo.ShipMasterImportVO;
|
||||
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ShipMaster 相关
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/rest/v1/double-run")
|
||||
public class DoubleRunController extends BaseController {
|
||||
|
||||
final IShipMasterService shipMasterService;
|
||||
final RedisCache redisCache;
|
||||
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
@PostMapping("/cache")
|
||||
public R<Integer> createCache(@Validated @RequestBody DoubleRunImportVO importVO) {
|
||||
List<DoubleRunImportVO.DRIArtNoVO> artNoList = importVO.getData().getData();
|
||||
Map<String, Map<String, List<DoubleRunImportVO.DRIArtNoSkuVO>>> artNoMap = new LinkedHashMap<>();
|
||||
artNoList.forEach(artNoInfo -> {
|
||||
artNoInfo.getSkus().forEach(x -> x.setColor(this.decodeUnicode(x.getColor())));
|
||||
artNoMap.put(artNoInfo.getArticle_number(), artNoInfo.getSkus().stream().collect(Collectors
|
||||
.groupingBy(DoubleRunImportVO.DRIArtNoSkuVO::getColor)));
|
||||
});
|
||||
|
||||
|
||||
artNoMap.forEach((artNo, colorSkuMap) -> {
|
||||
colorSkuMap.forEach((color, skuList) -> {
|
||||
skuList.sort(Comparator.comparing(DoubleRunImportVO.DRIArtNoSkuVO::getSize));
|
||||
System.err.println(artNo + ":" + color + ":" + skuList);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/* // 供应商ID
|
||||
final Integer supplierId = importVO.getData().getRecords().get(0).getSupplierId();
|
||||
// 先从redis中获取列表数据
|
||||
List<ShipMasterImportVO.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);*/
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
@GetMapping("/cache/{supplierId}")
|
||||
public R<Integer> getCache(@PathVariable Integer supplierId) {
|
||||
/*// 从redis中获取数据
|
||||
List<ShipMasterImportVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
|
||||
.getCacheObject(CacheConstants.SUPPLIER_KEY + supplierId), new ArrayList<>());
|
||||
if (CollectionUtils.isEmpty(cacheList)) {
|
||||
return R.fail();
|
||||
}
|
||||
// 按照artNo分组
|
||||
Map<String, List<ShipMasterImportVO.SMIVO>> artNoGroup = cacheList.stream()
|
||||
.sorted(Comparator.comparing(ShipMasterImportVO.SMIVO::getArtNo)
|
||||
.thenComparing(ShipMasterImportVO.SMIVO::getColor))
|
||||
.collect(Collectors
|
||||
.groupingBy(ShipMasterImportVO.SMIVO::getArtNo, LinkedHashMap::new, Collectors.toList()));
|
||||
Map<String, Map<String, String>> artSnPrefixMap = new LinkedHashMap<>();
|
||||
artNoGroup.forEach((artNo, colorList) -> {
|
||||
Map<String, String> snPrefixMap = new LinkedHashMap<>();
|
||||
// 按照颜色设置条码前缀
|
||||
colorList.forEach(color -> snPrefixMap
|
||||
.put(color.getColor(), color.getSupplierId() + String.format("%05d", color.getSupplierSkuId())));
|
||||
artSnPrefixMap.put(artNo, snPrefixMap);
|
||||
});
|
||||
artSnPrefixMap.forEach((k,v) -> {
|
||||
System.err.println(k + ":" + v);
|
||||
});*/
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Unicode解码方法
|
||||
* @param unicodeStr 包含Unicode编码的字符串
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
private String decodeUnicode(String unicodeStr) {
|
||||
if (unicodeStr == null || unicodeStr.isEmpty()) {
|
||||
return unicodeStr;
|
||||
}
|
||||
StringBuilder result = new StringBuilder();
|
||||
int i = 0;
|
||||
while (i < unicodeStr.length()) {
|
||||
if (unicodeStr.charAt(i) == '\\' && i + 1 < unicodeStr.length() && unicodeStr.charAt(i + 1) == 'u') {
|
||||
// 处理Unicode编码
|
||||
if (i + 5 < unicodeStr.length()) {
|
||||
try {
|
||||
String hexCode = unicodeStr.substring(i + 2, i + 6);
|
||||
char ch = (char) Integer.parseInt(hexCode, 16);
|
||||
result.append(ch);
|
||||
i += 6;
|
||||
} catch (NumberFormatException e) {
|
||||
result.append(unicodeStr.charAt(i));
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
result.append(unicodeStr.charAt(i));
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
result.append(unicodeStr.charAt(i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
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.ShipMasterImportVO;
|
||||
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ShipMaster 相关
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/rest/v1/ship-master")
|
||||
public class ShipMasterController extends BaseController {
|
||||
|
||||
final IShipMasterService shipMasterService;
|
||||
final RedisCache redisCache;
|
||||
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
@PostMapping("/cache")
|
||||
public R<Integer> createCache(@Validated @RequestBody ShipMasterImportVO importVO) {
|
||||
// 供应商ID
|
||||
final Integer supplierId = importVO.getData().getRecords().get(0).getSupplierId();
|
||||
// 先从redis中获取列表数据
|
||||
List<ShipMasterImportVO.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);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasAnyRoles('admin,general_admin')")
|
||||
@GetMapping("/cache/{supplierId}")
|
||||
public R<Integer> getCache(@PathVariable Integer supplierId) {
|
||||
// 从redis中获取数据
|
||||
List<ShipMasterImportVO.SMIVO> cacheList = ObjectUtils.defaultIfNull(redisCache
|
||||
.getCacheObject(CacheConstants.SUPPLIER_KEY + supplierId), new ArrayList<>());
|
||||
if (CollectionUtils.isEmpty(cacheList)) {
|
||||
return R.fail();
|
||||
}
|
||||
// 按照artNo分组
|
||||
Map<String, List<ShipMasterImportVO.SMIVO>> artNoGroup = cacheList.stream()
|
||||
.sorted(Comparator.comparing(ShipMasterImportVO.SMIVO::getArtNo)
|
||||
.thenComparing(ShipMasterImportVO.SMIVO::getColor))
|
||||
.collect(Collectors
|
||||
.groupingBy(ShipMasterImportVO.SMIVO::getArtNo, LinkedHashMap::new, Collectors.toList()));
|
||||
Map<String, Map<String, String>> artSnPrefixMap = new LinkedHashMap<>();
|
||||
artNoGroup.forEach((artNo, colorList) -> {
|
||||
Map<String, String> snPrefixMap = new LinkedHashMap<>();
|
||||
// 按照颜色设置条码前缀
|
||||
colorList.forEach(color -> snPrefixMap
|
||||
.put(color.getColor(), color.getSupplierId() + String.format("%05d", color.getSupplierSkuId())));
|
||||
artSnPrefixMap.put(artNo, snPrefixMap);
|
||||
});
|
||||
artSnPrefixMap.forEach((k,v) -> {
|
||||
System.err.println(k + ":" + v);
|
||||
});
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.ruoyi.web.controller.xkt.shipMaster.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 23:46
|
||||
*/
|
||||
@Data
|
||||
public class DoubleRunImportVO {
|
||||
|
||||
private DRIDataVO data;
|
||||
|
||||
@Data
|
||||
public static class DRIDataVO {
|
||||
private List<DRIArtNoVO> data;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DRIArtNoVO {
|
||||
private String article_number;
|
||||
private List<DRIArtNoSkuVO> skus;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DRIArtNoSkuVO {
|
||||
private String color;
|
||||
private Integer size;
|
||||
private BigDecimal weight;
|
||||
private BigDecimal price;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.ruoyi.web.controller.xkt.shipMaster.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author liangyq
|
||||
* @date 2025-05-11 23:46
|
||||
*/
|
||||
@Data
|
||||
public class ShipMasterImportVO {
|
||||
|
||||
private SMIDataVO data;
|
||||
|
||||
@Data
|
||||
public static class SMIDataVO {
|
||||
private List<SMIVO> records;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SMIVO {
|
||||
private Integer supplierId;
|
||||
private Integer supplierSkuId;
|
||||
private String artNo;
|
||||
private String color;
|
||||
private String size;
|
||||
private String snPrefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ public class StoreProdStockTakeResVO {
|
|||
private Long storeProdId;
|
||||
@ApiModelProperty(value = "商品货号")
|
||||
private String prodArtNum;
|
||||
@ApiModelProperty(value = "商品主图")
|
||||
private String mainPicUrl;
|
||||
@ApiModelProperty(value = "颜色列表")
|
||||
private List<SPSTColorSizeVO> colorList;
|
||||
|
||||
|
|
@ -27,6 +29,10 @@ public class StoreProdStockTakeResVO {
|
|||
@ApiModel
|
||||
@Accessors(chain = true)
|
||||
public static class SPSTColorSizeVO {
|
||||
@ApiModelProperty(value = "档口商品库存ID")
|
||||
private Long storeProdStockId;
|
||||
@ApiModelProperty(value = "档口商品颜色ID")
|
||||
private Long storeProdColorId;
|
||||
@ApiModelProperty(value = "颜色ID")
|
||||
private Long storeColorId;
|
||||
@ApiModelProperty(value = "颜色名称")
|
||||
|
|
|
|||
|
|
@ -312,5 +312,9 @@ public class CacheConstants {
|
|||
* 档口商品访问次数缓存
|
||||
*/
|
||||
public static final String STORE_PROD_VIEW_COUNT_CACHE = "store_prod_view_count_cache";
|
||||
/**
|
||||
* 供应商缓存
|
||||
*/
|
||||
public static final String SUPPLIER_KEY = "supplier:";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ public class StoreProdStockTakeResDTO {
|
|||
private Long storeProdId;
|
||||
@ApiModelProperty(value = "商品货号")
|
||||
private String prodArtNum;
|
||||
@ApiModelProperty(value = "商品主图")
|
||||
private String mainPicUrl;
|
||||
@ApiModelProperty(value = "颜色列表")
|
||||
private List<SPSTColorSizeDTO> colorList;
|
||||
|
||||
|
|
@ -27,6 +29,10 @@ public class StoreProdStockTakeResDTO {
|
|||
@ApiModel
|
||||
@Accessors(chain = true)
|
||||
public static class SPSTColorSizeDTO {
|
||||
@ApiModelProperty(value = "档口商品库存ID")
|
||||
private Long storeProdStockId;
|
||||
@ApiModelProperty(value = "档口商品颜色ID")
|
||||
private Long storeProdColorId;
|
||||
@ApiModelProperty(value = "颜色ID")
|
||||
private Long storeColorId;
|
||||
@ApiModelProperty(value = "颜色名称")
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import com.ruoyi.common.constant.HttpStatus;
|
|||
import com.ruoyi.common.core.page.Page;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.xkt.domain.StoreColor;
|
||||
import com.ruoyi.xkt.domain.StoreProduct;
|
||||
import com.ruoyi.xkt.domain.StoreProductColor;
|
||||
import com.ruoyi.xkt.domain.StoreProductColorSize;
|
||||
import com.ruoyi.xkt.domain.StoreProductStock;
|
||||
import com.ruoyi.xkt.dto.storeProductFile.StoreProdMainPicDTO;
|
||||
|
|
@ -48,6 +48,7 @@ public class StoreProductStockServiceImpl implements IStoreProductStockService {
|
|||
final StoreProductMapper storeProdMapper;
|
||||
final StoreProductColorSizeMapper prodColorSizeMapper;
|
||||
final StoreColorMapper storeColorMapper;
|
||||
final StoreProductColorMapper prodColorMapper;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -126,33 +127,42 @@ public class StoreProductStockServiceImpl implements IStoreProductStockService {
|
|||
@Transactional(readOnly = true)
|
||||
public StoreProdStockTakeResDTO getByStoreIdAndStoreProdId(Long storeId, Long storeProdId) {
|
||||
StoreProduct storeProd = Optional.ofNullable(this.storeProdMapper.selectById(storeProdId)).orElseThrow(() -> new ServiceException("该商品不存在", HttpStatus.ERROR));
|
||||
// 获取商品主图
|
||||
List<StoreProdMainPicDTO> mainPicList = this.storeProdFileMapper
|
||||
.selectMainPicByStoreProdIdList(Collections.singletonList(storeProdId), FileType.MAIN_PIC.getValue(), ORDER_NUM_1);
|
||||
// 查询该商品所有颜色的库存
|
||||
List<StoreProductStock> stockList = this.storeProdStockMapper.selectList(new LambdaQueryWrapper<StoreProductStock>()
|
||||
.eq(StoreProductStock::getStoreId, storeId).eq(StoreProductStock::getStoreProdId, storeProdId)
|
||||
.eq(StoreProductStock::getDelFlag, Constants.UNDELETED));
|
||||
Map<Long, StoreProductStock> storeProdColorStockMap = stockList.stream().collect(Collectors.toMap(StoreProductStock::getStoreColorId, x -> x));
|
||||
// 商品颜色对应的库存map
|
||||
Map<Long, StoreProductStock> colorSizeStockMap = stockList.stream().collect(Collectors.toMap(StoreProductStock::getStoreColorId, x -> x));
|
||||
// 档口商品颜色map
|
||||
List<StoreColor> storeColorList = this.storeColorMapper.selectList(new LambdaQueryWrapper<StoreColor>()
|
||||
.eq(StoreColor::getDelFlag, Constants.UNDELETED).eq(StoreColor::getStoreId, storeId));
|
||||
Map<Long, StoreColor> storeColorMap = storeColorList.stream().collect(Collectors.toMap(StoreColor::getId, x -> x));
|
||||
// 档口商品颜色
|
||||
List<StoreProductColor> storeProdColorList = this.prodColorMapper.selectList(new LambdaQueryWrapper<StoreProductColor>()
|
||||
.eq(StoreProductColor::getDelFlag, Constants.UNDELETED).eq(StoreProductColor::getStoreId, storeId)
|
||||
.eq(StoreProductColor::getStoreProdId, storeProdId));
|
||||
Map<Long, StoreProductColor> storeProdColorMap = storeProdColorList.stream().collect(Collectors.toMap(StoreProductColor::getStoreColorId, x -> x));
|
||||
// 获取商品所有颜色的基础信息
|
||||
List<StoreProductColorSize> prodColorSizeList = this.prodColorSizeMapper.selectList(new LambdaQueryWrapper<StoreProductColorSize>()
|
||||
.eq(StoreProductColorSize::getDelFlag, Constants.UNDELETED).eq(StoreProductColorSize::getStoreProdId, storeProdId));
|
||||
Map<Long, List<StoreProductColorSize>> colorSizeMap = prodColorSizeList.stream().collect(Collectors.groupingBy(StoreProductColorSize::getStoreColorId));
|
||||
List<StoreProdStockTakeResDTO.SPSTColorSizeDTO> colorResList = new ArrayList<>();
|
||||
colorSizeMap.forEach((colorId, colorSizeList) -> {
|
||||
colorSizeMap.forEach((storeColorId, colorSizeList) -> {
|
||||
// 商品颜色数据
|
||||
StoreProdStockTakeResDTO.SPSTColorSizeDTO color = new StoreProdStockTakeResDTO.SPSTColorSizeDTO()
|
||||
.setStoreColorId(colorId).setColorName(storeColorMap.containsKey(colorId) ? storeColorMap.get(colorId).getColorName() : "")
|
||||
StoreProdStockTakeResDTO.SPSTColorSizeDTO color = new StoreProdStockTakeResDTO.SPSTColorSizeDTO().setStoreColorId(storeColorId)
|
||||
.setStoreProdStockId(storeProdColorStockMap.containsKey(storeColorId) ? storeProdColorStockMap.get(storeColorId).getId() : null)
|
||||
.setStoreProdColorId(storeProdColorMap.containsKey(storeColorId) ? storeProdColorMap.get(storeColorId).getId() : null)
|
||||
.setColorName(storeProdColorMap.containsKey(storeColorId) ? storeProdColorMap.get(storeColorId).getColorName() : "")
|
||||
// 商品对应颜色的库存
|
||||
.setSizeStockList(colorSizeList.stream().sorted(Comparator.comparing(StoreProductColorSize::getSize))
|
||||
.map(x -> new StoreProdStockTakeResDTO.SPSTSizeStockDTO().setStoreProdColorSizeId(x.getId()).setSize(x.getSize())
|
||||
.setStock(this.getSizeStock(x.getSize(), colorSizeStockMap.get(colorId))))
|
||||
.setStock(this.getSizeStock(x.getSize(), colorSizeStockMap.get(storeColorId))))
|
||||
.collect(Collectors.toList()));
|
||||
colorResList.add(color);
|
||||
});
|
||||
return new StoreProdStockTakeResDTO().setStoreProdId(storeProdId).setProdArtNum(storeProd.getProdArtNum()).setColorList(colorResList);
|
||||
return new StoreProdStockTakeResDTO().setStoreProdId(storeProdId).setProdArtNum(storeProd.getProdArtNum())
|
||||
.setMainPicUrl(CollectionUtils.isNotEmpty(mainPicList) ? mainPicList.get(0).getFileUrl() : "")
|
||||
.setColorList(colorResList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.ruoyi.xkt.service.shipMaster;
|
||||
|
||||
/**
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IShipMasterService {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.ruoyi.xkt.service.shipMaster.impl;
|
||||
|
||||
import com.ruoyi.xkt.service.shipMaster.IShipMasterService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 公告
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ShipMasterServiceImpl implements IShipMasterService {
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue