fix(智慧超市):库存导入导出适配,增加覆盖导入
This commit is contained in:
1 parent
f38cf9c02c
commit
c7a6a05598
2 files changed
+333
-26
No files matched your search
+19
@@ -36,6 +36,9 @@ public class SmErpSpuImportNewDto {
|
||||
@ExcelProperty("装数")
|
||||
private Integer packageNum; // 内装数量
|
||||
|
||||
@ExcelProperty("口味")
|
||||
private String taste; // 口味
|
||||
|
||||
@ExcelProperty("进价")
|
||||
private Double purchasePrice; // 进价
|
||||
|
||||
@@ -63,6 +66,22 @@ public class SmErpSpuImportNewDto {
|
||||
@ExcelProperty("商品状态")
|
||||
private String status; // 商品状态(0-正常,1-停售)
|
||||
|
||||
// 辅助条码字段
|
||||
@ExcelProperty("辅助条码1")
|
||||
private String auxiliaryBarcode1; // 辅助条码1
|
||||
|
||||
@ExcelProperty("辅助条码2")
|
||||
private String auxiliaryBarcode2; // 辅助条码2
|
||||
|
||||
@ExcelProperty("辅助条码3")
|
||||
private String auxiliaryBarcode3; // 辅助条码3
|
||||
|
||||
@ExcelProperty("辅助条码4")
|
||||
private String auxiliaryBarcode4; // 辅助条码4
|
||||
|
||||
@ExcelProperty("辅助条码5")
|
||||
private String auxiliaryBarcode5; // 辅助条码5
|
||||
|
||||
// 注释品牌字段,暂时不使用
|
||||
// @ExcelProperty("品牌")
|
||||
// private String brand; // 品牌
|
||||
|
||||
+314
-26
@@ -932,6 +932,245 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
int totalCount = smErpSpuImportNewDtos.size();
|
||||
int successCount = 0;
|
||||
|
||||
for (int i = 0; i < smErpSpuImportNewDtos.size(); i++) {
|
||||
int rowNumber = i + 1;
|
||||
SmErpSpuImportNewDto dto = smErpSpuImportNewDtos.get(i);
|
||||
List<String> errorReasons = new ArrayList<>();
|
||||
|
||||
try {
|
||||
// 1. 基础数据校验
|
||||
if (StringUtils.isBlank(dto.getProductCode())) {
|
||||
errorReasons.add("货号不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(dto.getProductName())) {
|
||||
errorReasons.add("商品名称不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(dto.getUnit())) {
|
||||
errorReasons.add("单位不能为空");
|
||||
}
|
||||
if (dto.getPackageNum() == null || dto.getPackageNum() <= 0) {
|
||||
errorReasons.add("装数必须大于0");
|
||||
}
|
||||
|
||||
if (!errorReasons.isEmpty()) {
|
||||
errorList.add(createErrorInfo(rowNumber, dto.getProductCode(), errorReasons));
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. 处理分类
|
||||
Long categoryId = null;
|
||||
if (StringUtils.isNotBlank(dto.getCategoryName())) {
|
||||
categoryId = resolveCategory(dto.getCategoryName(), errorReasons, rowNumber, dto.getProductCode(),
|
||||
SecurityUtils.getUser().getDeptId(), null);
|
||||
if (categoryId == null) {
|
||||
errorList.add(createErrorInfo(rowNumber, dto.getProductCode(), errorReasons));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 处理货商
|
||||
Long supplierId = null;
|
||||
if (StringUtils.isNotBlank(dto.getSupplierName())) {
|
||||
supplierId = resolveSupplierId(dto.getSupplierName(), errorReasons, rowNumber, dto.getProductCode());
|
||||
if (supplierId == null) {
|
||||
errorList.add(createErrorInfo(rowNumber, dto.getProductCode(), errorReasons));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 检查商品是否已存在
|
||||
LambdaQueryWrapper<SmErpSpuEntity> existingSpuWrapper = new LambdaQueryWrapper<>();
|
||||
existingSpuWrapper.eq(SmErpSpuEntity::getProductCode, dto.getProductCode());
|
||||
SmErpSpuEntity existingSpu = this.getOne(existingSpuWrapper);
|
||||
|
||||
SmErpSpuEntity spu;
|
||||
if (existingSpu != null) {
|
||||
// 商品已存在,记录警告但不更新(保护线上数据)
|
||||
errorReasons.add("商品已存在,跳过导入以避免覆盖线上数据。货号:" + dto.getProductCode() + ",商品名称:" + existingSpu.getProductName());
|
||||
errorList.add(createErrorInfo(rowNumber, dto.getProductCode(), errorReasons));
|
||||
continue;
|
||||
|
||||
// 如果需要更新模式,可以取消注释下面的代码
|
||||
/*
|
||||
spu = existingSpu;
|
||||
spu.setProductName(dto.getProductName());
|
||||
spu.setSpec(dto.getSpec());
|
||||
spu.setOrigin(dto.getOrigin());
|
||||
spu.setBarCode(dto.getBarCode());
|
||||
spu.setPurchasePrice(dto.getPurchasePrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPurchasePrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setRetailPrice(dto.getRetailPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getRetailPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setPromotionPrice(dto.getPromotionPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPromotionPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setCostPrice(dto.getCostPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getCostPrice()).multiply(BigDecimal.valueOf(100)).doubleValue() : 0.0);
|
||||
spu.setProductNature("电子称称重商品".equals(dto.getProductNature()) ? "2" : "1");
|
||||
spu.setStatus("停销".equals(dto.getStatus()) ? "1" : "0");
|
||||
if (categoryId != null) {
|
||||
spu.setCategoryId(categoryId);
|
||||
}
|
||||
if (supplierId != null) {
|
||||
spu.setSupplierId(supplierId);
|
||||
}
|
||||
this.updateById(spu);
|
||||
*/
|
||||
} else {
|
||||
// 创建新商品
|
||||
spu = new SmErpSpuEntity();
|
||||
spu.setProductCode(dto.getProductCode());
|
||||
spu.setProductName(dto.getProductName());
|
||||
spu.setSpec(dto.getSpec());
|
||||
spu.setOrigin(dto.getOrigin());
|
||||
spu.setBarCode(dto.getBarCode());
|
||||
spu.setPurchasePrice(dto.getPurchasePrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPurchasePrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setRetailPrice(dto.getRetailPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getRetailPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setPromotionPrice(dto.getPromotionPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPromotionPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setCostPrice(dto.getCostPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getCostPrice()).multiply(BigDecimal.valueOf(100)).doubleValue() : 0.0);
|
||||
spu.setProductNature("电子称称重商品".equals(dto.getProductNature()) ? "2" : "1");
|
||||
spu.setStatus("停销".equals(dto.getStatus()) ? "1" : "0");
|
||||
spu.setDeptId(SecurityUtils.getUser().getDeptId());
|
||||
if (categoryId != null) {
|
||||
spu.setCategoryId(categoryId);
|
||||
}
|
||||
if (supplierId != null) {
|
||||
spu.setSupplierId(supplierId);
|
||||
}
|
||||
this.save(spu);
|
||||
}
|
||||
|
||||
// 5. 处理包装单位
|
||||
SmErpUnitEntity unit = new SmErpUnitEntity();
|
||||
unit.setSpuId(spu.getId());
|
||||
unit.setUnit(dto.getUnit());
|
||||
unit.setPackageNum(dto.getPackageNum());
|
||||
unit.setIsBase(true); // 默认为基础单位
|
||||
unit.setBarCode(dto.getBarCode()); // 包装单位的条码来自主条码
|
||||
unit.setTaste(dto.getTaste()); // 设置口味
|
||||
unit.setPurchasePrice(dto.getPurchasePrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPurchasePrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
unit.setRetailPrice(dto.getRetailPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getRetailPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
unit.setPromotionPrice(dto.getPromotionPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPromotionPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
unit.setCostPrice(dto.getCostPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getCostPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
|
||||
// 检查单位是否已存在(根据单位名称和口味)
|
||||
LambdaQueryWrapper<SmErpUnitEntity> existingUnitWrapper = new LambdaQueryWrapper<>();
|
||||
existingUnitWrapper.eq(SmErpUnitEntity::getSpuId, spu.getId())
|
||||
.eq(SmErpUnitEntity::getUnit, dto.getUnit())
|
||||
.eq(SmErpUnitEntity::getTaste, dto.getTaste());
|
||||
SmErpUnitEntity existingUnit = smErpUnitService.getOne(existingUnitWrapper);
|
||||
|
||||
if (existingUnit != null) {
|
||||
// 包装单位已存在,记录警告但不更新(保护线上数据)
|
||||
errorReasons.add("包装单位已存在,跳过导入以避免覆盖线上数据。单位:" + dto.getUnit() + ",口味:" + dto.getTaste());
|
||||
errorList.add(createErrorInfo(rowNumber, dto.getProductCode(), errorReasons));
|
||||
continue;
|
||||
|
||||
// 如果需要更新模式,可以取消注释下面的代码
|
||||
/*
|
||||
existingUnit.setPackageNum(dto.getPackageNum());
|
||||
existingUnit.setBarCode(dto.getBarCode()); // 更新条码
|
||||
existingUnit.setPurchasePrice(unit.getPurchasePrice());
|
||||
existingUnit.setRetailPrice(unit.getRetailPrice());
|
||||
existingUnit.setPromotionPrice(unit.getPromotionPrice());
|
||||
existingUnit.setCostPrice(unit.getCostPrice());
|
||||
smErpUnitService.updateById(existingUnit);
|
||||
*/
|
||||
} else {
|
||||
smErpUnitService.save(unit);
|
||||
}
|
||||
|
||||
// 6. 处理辅助条码(多个辅助条码)
|
||||
List<String> auxiliaryBarcodes = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode1())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode1());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode2())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode2());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode3())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode3());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode4())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode4());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode5())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode5());
|
||||
}
|
||||
|
||||
// 为每个辅助条码创建记录
|
||||
for (String auxiliaryBarcode : auxiliaryBarcodes) {
|
||||
// 检查辅助条码是否已存在
|
||||
LambdaQueryWrapper<SmErpAuxiliaryCodeEntity> existingBarcodeWrapper = new LambdaQueryWrapper<>();
|
||||
existingBarcodeWrapper.eq(SmErpAuxiliaryCodeEntity::getSpuId, spu.getId())
|
||||
.eq(SmErpAuxiliaryCodeEntity::getBarCode, auxiliaryBarcode);
|
||||
SmErpAuxiliaryCodeEntity existingBarcode = smErpAuxiliaryCodeService.getOne(existingBarcodeWrapper);
|
||||
|
||||
if (existingBarcode != null) {
|
||||
// 辅助条码已存在,记录警告但不更新(保护线上数据)
|
||||
errorReasons.add("辅助条码已存在,跳过导入以避免覆盖线上数据。条码:" + auxiliaryBarcode);
|
||||
continue;
|
||||
} else {
|
||||
SmErpAuxiliaryCodeEntity auxiliaryCode = new SmErpAuxiliaryCodeEntity();
|
||||
auxiliaryCode.setSpuId(spu.getId());
|
||||
auxiliaryCode.setBarCode(auxiliaryBarcode);
|
||||
auxiliaryCode.setUnitId(existingUnit != null ? existingUnit.getId() : unit.getId());
|
||||
smErpAuxiliaryCodeService.save(auxiliaryCode);
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 处理库存设置
|
||||
SmErpStockEntity stock = new SmErpStockEntity();
|
||||
stock.setErpSpuId(spu.getId());
|
||||
stock.setInventoryUpperLimit(dto.getInventoryUpperLimit() != null ? dto.getInventoryUpperLimit() : 1000);
|
||||
stock.setInventoryLowerLimit(dto.getInventoryLowerLimit() != null ? dto.getInventoryLowerLimit() : 10);
|
||||
stock.setBaseStock(dto.getStock() != null ? dto.getStock() : 0.0);
|
||||
stock.setCurrentStock(dto.getStock() != null ? dto.getStock() : 0.0);
|
||||
|
||||
// 检查库存记录是否已存在
|
||||
LambdaQueryWrapper<SmErpStockEntity> existingStockWrapper = new LambdaQueryWrapper<>();
|
||||
existingStockWrapper.eq(SmErpStockEntity::getErpSpuId, spu.getId());
|
||||
SmErpStockEntity existingStock = smErpStockService.getOne(existingStockWrapper);
|
||||
|
||||
if (existingStock != null) {
|
||||
// 库存记录已存在,记录警告但不更新(保护线上数据)
|
||||
errorReasons.add("库存记录已存在,跳过导入以避免覆盖线上数据");
|
||||
continue;
|
||||
} else {
|
||||
smErpStockService.save(stock);
|
||||
}
|
||||
|
||||
successList.add(spu);
|
||||
successCount++;
|
||||
|
||||
} catch (Exception e) {
|
||||
errorReasons.add("处理失败: " + e.getMessage());
|
||||
errorList.add(createErrorInfo(rowNumber, dto.getProductCode(), errorReasons));
|
||||
}
|
||||
}
|
||||
|
||||
return buildImportResult(totalCount, successCount, errorList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R importErpSpuNewUpdate(List<SmErpSpuImportNewDto> smErpSpuImportNewDtos, BindingResult bindingResult) {
|
||||
if (CollectionUtils.isEmpty(smErpSpuImportNewDtos)) {
|
||||
return R.failed("导入数据不能为空");
|
||||
}
|
||||
|
||||
List<Map<String, Object>> errorList = new ArrayList<>();
|
||||
List<SmErpSpuEntity> successList = new ArrayList<>();
|
||||
int totalCount = smErpSpuImportNewDtos.size();
|
||||
int successCount = 0;
|
||||
|
||||
for (int i = 0; i < smErpSpuImportNewDtos.size(); i++) {
|
||||
int rowNumber = i + 1;
|
||||
SmErpSpuImportNewDto dto = smErpSpuImportNewDtos.get(i);
|
||||
@@ -999,8 +1238,8 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
BigDecimal.valueOf(dto.getPromotionPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setCostPrice(dto.getCostPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getCostPrice()).multiply(BigDecimal.valueOf(100)).doubleValue() : 0.0);
|
||||
spu.setProductNature(dto.getProductNature());
|
||||
spu.setStatus("0".equals(dto.getStatus()) ? "0" : "1");
|
||||
spu.setProductNature("电子称称重商品".equals(dto.getProductNature()) ? "2" : "1");
|
||||
spu.setStatus("停销".equals(dto.getStatus()) ? "1" : "0");
|
||||
if (categoryId != null) {
|
||||
spu.setCategoryId(categoryId);
|
||||
}
|
||||
@@ -1024,8 +1263,8 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
BigDecimal.valueOf(dto.getPromotionPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
spu.setCostPrice(dto.getCostPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getCostPrice()).multiply(BigDecimal.valueOf(100)).doubleValue() : 0.0);
|
||||
spu.setProductNature(dto.getProductNature());
|
||||
spu.setStatus("0".equals(dto.getStatus()) ? "0" : "1");
|
||||
spu.setProductNature("电子称称重商品".equals(dto.getProductNature()) ? "2" : "1");
|
||||
spu.setStatus("停销".equals(dto.getStatus()) ? "1" : "0");
|
||||
spu.setDeptId(SecurityUtils.getUser().getDeptId());
|
||||
if (categoryId != null) {
|
||||
spu.setCategoryId(categoryId);
|
||||
@@ -1042,6 +1281,8 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
unit.setUnit(dto.getUnit());
|
||||
unit.setPackageNum(dto.getPackageNum());
|
||||
unit.setIsBase(true); // 默认为基础单位
|
||||
unit.setBarCode(dto.getBarCode()); // 包装单位的条码来自主条码
|
||||
unit.setTaste(dto.getTaste()); // 设置口味
|
||||
unit.setPurchasePrice(dto.getPurchasePrice() != null ?
|
||||
BigDecimal.valueOf(dto.getPurchasePrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
unit.setRetailPrice(dto.getRetailPrice() != null ?
|
||||
@@ -1051,14 +1292,17 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
unit.setCostPrice(dto.getCostPrice() != null ?
|
||||
BigDecimal.valueOf(dto.getCostPrice()).multiply(BigDecimal.valueOf(100)).intValue() : 0);
|
||||
|
||||
// 检查单位是否已存在
|
||||
// 检查单位是否已存在(根据单位名称和口味)
|
||||
LambdaQueryWrapper<SmErpUnitEntity> existingUnitWrapper = new LambdaQueryWrapper<>();
|
||||
existingUnitWrapper.eq(SmErpUnitEntity::getSpuId, spu.getId())
|
||||
.eq(SmErpUnitEntity::getUnit, dto.getUnit());
|
||||
.eq(SmErpUnitEntity::getUnit, dto.getUnit())
|
||||
.eq(SmErpUnitEntity::getTaste, dto.getTaste());
|
||||
SmErpUnitEntity existingUnit = smErpUnitService.getOne(existingUnitWrapper);
|
||||
|
||||
if (existingUnit != null) {
|
||||
// 更新现有包装单位
|
||||
existingUnit.setPackageNum(dto.getPackageNum());
|
||||
existingUnit.setBarCode(dto.getBarCode()); // 更新条码
|
||||
existingUnit.setPurchasePrice(unit.getPurchasePrice());
|
||||
existingUnit.setRetailPrice(unit.getRetailPrice());
|
||||
existingUnit.setPromotionPrice(unit.getPromotionPrice());
|
||||
@@ -1068,23 +1312,41 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
smErpUnitService.save(unit);
|
||||
}
|
||||
|
||||
// 6. 处理辅助条码(如果有条码的话)
|
||||
if (StringUtils.isNotBlank(dto.getBarCode())) {
|
||||
SmErpAuxiliaryCodeEntity auxiliaryCode = new SmErpAuxiliaryCodeEntity();
|
||||
auxiliaryCode.setSpuId(spu.getId());
|
||||
auxiliaryCode.setBarCode(dto.getBarCode());
|
||||
auxiliaryCode.setUnitId(existingUnit != null ? existingUnit.getId() : unit.getId());
|
||||
// 6. 处理辅助条码(多个辅助条码)
|
||||
List<String> auxiliaryBarcodes = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode1())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode1());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode2())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode2());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode3())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode3());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode4())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode4());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getAuxiliaryBarcode5())) {
|
||||
auxiliaryBarcodes.add(dto.getAuxiliaryBarcode5());
|
||||
}
|
||||
|
||||
// 为每个辅助条码创建记录
|
||||
for (String auxiliaryBarcode : auxiliaryBarcodes) {
|
||||
// 检查辅助条码是否已存在
|
||||
LambdaQueryWrapper<SmErpAuxiliaryCodeEntity> existingBarcodeWrapper = new LambdaQueryWrapper<>();
|
||||
existingBarcodeWrapper.eq(SmErpAuxiliaryCodeEntity::getSpuId, spu.getId())
|
||||
.eq(SmErpAuxiliaryCodeEntity::getBarCode, dto.getBarCode());
|
||||
.eq(SmErpAuxiliaryCodeEntity::getBarCode, auxiliaryBarcode);
|
||||
SmErpAuxiliaryCodeEntity existingBarcode = smErpAuxiliaryCodeService.getOne(existingBarcodeWrapper);
|
||||
|
||||
if (existingBarcode != null) {
|
||||
// 更新现有辅助条码
|
||||
existingBarcode.setUnitId(existingUnit != null ? existingUnit.getId() : unit.getId());
|
||||
smErpAuxiliaryCodeService.updateById(existingBarcode);
|
||||
} else {
|
||||
SmErpAuxiliaryCodeEntity auxiliaryCode = new SmErpAuxiliaryCodeEntity();
|
||||
auxiliaryCode.setSpuId(spu.getId());
|
||||
auxiliaryCode.setBarCode(auxiliaryBarcode);
|
||||
auxiliaryCode.setUnitId(existingUnit != null ? existingUnit.getId() : unit.getId());
|
||||
smErpAuxiliaryCodeService.save(auxiliaryCode);
|
||||
}
|
||||
}
|
||||
@@ -1103,6 +1365,7 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
SmErpStockEntity existingStock = smErpStockService.getOne(existingStockWrapper);
|
||||
|
||||
if (existingStock != null) {
|
||||
// 更新现有库存记录
|
||||
existingStock.setInventoryUpperLimit(dto.getInventoryUpperLimit() != null ? dto.getInventoryUpperLimit() : 1000);
|
||||
existingStock.setInventoryLowerLimit(dto.getInventoryLowerLimit() != null ? dto.getInventoryLowerLimit() : 10);
|
||||
existingStock.setBaseStock(dto.getStock() != null ? dto.getStock() : 0.0);
|
||||
@@ -1202,22 +1465,23 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
dto.setStock(stock != null ? stock.getCurrentStock() : 0.0);
|
||||
dto.setCategoryName(categoryName);
|
||||
dto.setPackageNum(1);
|
||||
dto.setTaste(""); // 默认口味为空
|
||||
dto.setPurchasePrice(spu.getPurchasePrice()/100.00);
|
||||
dto.setRetailPrice(spu.getRetailPrice()/100.00);
|
||||
dto.setSupplierName(supplierName);
|
||||
dto.setPromotionPrice(spu.getPromotionPrice()/100.00);
|
||||
dto.setProductNature(spu.getProductNature());
|
||||
dto.setProductNature("2".equals(spu.getProductNature()) ? "电子称称重商品" : "普通商品");
|
||||
dto.setCostPrice(spu.getCostPrice()/100.00);
|
||||
dto.setInventoryUpperLimit(stock != null ? stock.getInventoryUpperLimit() : 1000);
|
||||
dto.setInventoryLowerLimit(stock != null ? stock.getInventoryLowerLimit() : 10);
|
||||
dto.setStatus("0".equals(spu.getStatus()) ? "0" : "1");
|
||||
dto.setStatus("1".equals(spu.getStatus()) ? "停销" : "正常");
|
||||
exportList.add(dto);
|
||||
} else {
|
||||
// 为每个包装单位创建一条记录
|
||||
for (SmErpUnitEntity unit : units) {
|
||||
SmErpSpuImportNewDto dto = new SmErpSpuImportNewDto();
|
||||
dto.setProductCode(spu.getProductCode());
|
||||
dto.setBarCode(spu.getBarCode());
|
||||
dto.setBarCode(unit.getBarCode()); // 使用包装单位的条码
|
||||
dto.setProductName(spu.getProductName());
|
||||
dto.setUnit(unit.getUnit());
|
||||
dto.setOrigin(spu.getOrigin());
|
||||
@@ -1225,15 +1489,39 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
dto.setStock(stock != null ? stock.getCurrentStock() : 0.0);
|
||||
dto.setCategoryName(categoryName);
|
||||
dto.setPackageNum(unit.getPackageNum());
|
||||
dto.setTaste(unit.getTaste()); // 设置口味
|
||||
dto.setPurchasePrice(unit.getPurchasePrice() != null ? unit.getPurchasePrice() / 100.0 : spu.getPurchasePrice());
|
||||
dto.setRetailPrice(unit.getRetailPrice() != null ? unit.getRetailPrice() / 100.0 : spu.getRetailPrice());
|
||||
dto.setSupplierName(supplierName);
|
||||
dto.setPromotionPrice(unit.getPromotionPrice() != null ? unit.getPromotionPrice() / 100.0 : spu.getPromotionPrice());
|
||||
dto.setProductNature(spu.getProductNature());
|
||||
dto.setProductNature("2".equals(spu.getProductNature()) ? "电子称称重商品" : "普通商品");
|
||||
dto.setCostPrice(unit.getCostPrice() != null ? unit.getCostPrice() / 100.0 : spu.getCostPrice());
|
||||
dto.setInventoryUpperLimit(stock != null ? stock.getInventoryUpperLimit() : 1000);
|
||||
dto.setInventoryLowerLimit(stock != null ? stock.getInventoryLowerLimit() : 10);
|
||||
dto.setStatus("0".equals(spu.getStatus()) ? "0" : "1");
|
||||
dto.setStatus("1".equals(spu.getStatus()) ? "停销" : "正常");
|
||||
|
||||
// 获取该包装单位关联的辅助条码
|
||||
List<SmErpAuxiliaryCodeEntity> unitAuxiliaryCodes = auxiliaryCodes.stream()
|
||||
.filter(code -> unit.getId().equals(code.getUnitId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 设置辅助条码(最多5个)
|
||||
if (unitAuxiliaryCodes.size() > 0) {
|
||||
dto.setAuxiliaryBarcode1(unitAuxiliaryCodes.size() > 0 ? unitAuxiliaryCodes.get(0).getBarCode() : null);
|
||||
}
|
||||
if (unitAuxiliaryCodes.size() > 1) {
|
||||
dto.setAuxiliaryBarcode2(unitAuxiliaryCodes.get(1).getBarCode());
|
||||
}
|
||||
if (unitAuxiliaryCodes.size() > 2) {
|
||||
dto.setAuxiliaryBarcode3(unitAuxiliaryCodes.get(2).getBarCode());
|
||||
}
|
||||
if (unitAuxiliaryCodes.size() > 3) {
|
||||
dto.setAuxiliaryBarcode4(unitAuxiliaryCodes.get(3).getBarCode());
|
||||
}
|
||||
if (unitAuxiliaryCodes.size() > 4) {
|
||||
dto.setAuxiliaryBarcode5(unitAuxiliaryCodes.get(4).getBarCode());
|
||||
}
|
||||
|
||||
exportList.add(dto);
|
||||
}
|
||||
}
|
||||
@@ -1264,12 +1552,12 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
LambdaQueryWrapper<SmErpSupplierEntity> smErpSupplierEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
smErpSupplierEntityLambdaQueryWrapper.eq(SmErpSupplierEntity::getSupplierName, supplierName);
|
||||
// 1. 查询现有供应商(名称唯一)
|
||||
SmErpSupplierEntity existSupplier = smErpSupplierMapper.selectListByScope(smErpSupplierEntityLambdaQueryWrapper
|
||||
List<SmErpSupplierEntity> existSuppliers = smErpSupplierMapper.selectListByScope(smErpSupplierEntityLambdaQueryWrapper
|
||||
,DataScope.of()
|
||||
).get(0);
|
||||
|
||||
if (existSupplier != null) {
|
||||
return existSupplier.getSupplierId();
|
||||
);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(existSuppliers)) {
|
||||
return existSuppliers.get(0).getSupplierId();
|
||||
} else {
|
||||
errorReasons.add("供应商不存在,请先导入'" + supplierName + "'该供应商");
|
||||
return null;
|
||||
@@ -1292,11 +1580,11 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
|
||||
} catch (DuplicateKeyException e) {
|
||||
// 处理并发创建冲突:重新查询
|
||||
SmErpSupplierEntity conflictSupplier = smErpSupplierMapper.selectListByScope(
|
||||
List<SmErpSupplierEntity> conflictSuppliers = smErpSupplierMapper.selectListByScope(
|
||||
new LambdaQueryWrapper<SmErpSupplierEntity>()
|
||||
.eq(SmErpSupplierEntity::getSupplierName, supplierName),DataScope.of()
|
||||
).get(0);
|
||||
return conflictSupplier != null ? conflictSupplier.getSupplierId() : null;
|
||||
);
|
||||
return CollectionUtils.isNotEmpty(conflictSuppliers) ? conflictSuppliers.get(0).getSupplierId() : null;
|
||||
|
||||
} catch (Exception e) {
|
||||
errorReasons.add("供应商处理异常: " + e.getMessage());
|
||||
|
||||
Reference in new issue
Block a user