fix(智慧超市):库存商品分页修复查重,允许超卖,后续入库
This commit is contained in:
1 parent
9a5b4d3a30
commit
3be7f7d356
6 files changed
+533
-31
No files matched your search
+1
-5
@@ -1,10 +1,6 @@
|
||||
package com.bsd.pjcloud.supermarket.dto.erpspu;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.bsd.pjcloud.common.core.util.MoneyDeserializer;
|
||||
import com.bsd.pjcloud.common.core.util.MoneySerializer;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -72,4 +68,4 @@ public class SmErpSpuImportDto {
|
||||
@ExcelProperty("停销")
|
||||
private Boolean discontinued; // 停销
|
||||
|
||||
}
|
||||
}
|
||||
+82
-19
@@ -22,6 +22,14 @@ public class SmErpSpuStockExcel implements Serializable {
|
||||
@ExcelProperty("货号")
|
||||
private String productCode;
|
||||
|
||||
|
||||
/**
|
||||
* 自编码/条码
|
||||
*/
|
||||
@Schema(description="自编码/条码")
|
||||
@ExcelProperty("自编码/条码")
|
||||
private String barCode;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
@@ -30,14 +38,6 @@ public class SmErpSpuStockExcel implements Serializable {
|
||||
private String productName;
|
||||
|
||||
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
@Schema(description="库存")
|
||||
@ExcelProperty("库存")
|
||||
private Double stock;
|
||||
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
@@ -45,13 +45,14 @@ public class SmErpSpuStockExcel implements Serializable {
|
||||
@ExcelProperty("单位")
|
||||
private String unit;
|
||||
|
||||
|
||||
/**
|
||||
* 条码
|
||||
* 产地
|
||||
*/
|
||||
@Schema(description="条码")
|
||||
@ExcelProperty("条码")
|
||||
private String barCode;
|
||||
@Schema(description="产地")
|
||||
@ExcelProperty("产地")
|
||||
private String origin;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 规格
|
||||
@@ -62,19 +63,81 @@ public class SmErpSpuStockExcel implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 内装数量
|
||||
* 库存
|
||||
*/
|
||||
@Schema(description="内装")
|
||||
@ExcelProperty("内装")
|
||||
private Integer packageNum;
|
||||
@Schema(description="库存")
|
||||
@ExcelProperty("库存")
|
||||
private Double stock;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 商品分类编号
|
||||
*/
|
||||
@Schema(description="分类")
|
||||
@ExcelProperty("分类")
|
||||
private String categoryName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 内装数量
|
||||
*/
|
||||
@Schema(description="装数")
|
||||
@ExcelProperty("装数")
|
||||
private Integer packageNum;
|
||||
|
||||
|
||||
|
||||
@Schema(description="进价")
|
||||
@ExcelProperty("进价")
|
||||
private Double purchasePrice;
|
||||
/**
|
||||
* 零售价/单位分
|
||||
*/
|
||||
@Schema(description="零售价/单位分")
|
||||
@ExcelProperty("零售价/元")
|
||||
@Schema(description="零售价")
|
||||
@ExcelProperty("零售价")
|
||||
private Double retailPrice;
|
||||
|
||||
|
||||
@Schema(description="货商")
|
||||
@ExcelProperty("货商")
|
||||
private String supplierName;
|
||||
|
||||
|
||||
/**
|
||||
* 促销价(分为单位)
|
||||
*/
|
||||
@Schema(description="促销价")
|
||||
@ExcelProperty("促销价")
|
||||
private Double promotionPrice;
|
||||
|
||||
|
||||
/**
|
||||
* 商品性质(字典)
|
||||
*/
|
||||
@Schema(description="商品性质")
|
||||
@ExcelProperty("商品性质")
|
||||
private String productNature;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 成本单价,单位: 分
|
||||
*/
|
||||
@Schema(description="成本单价")
|
||||
@ExcelProperty("成本单价")
|
||||
private Double costPrice;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 条码
|
||||
*/
|
||||
@Schema(description="辅助条码")
|
||||
@ExcelProperty("辅助条码")
|
||||
private String fzCode;
|
||||
|
||||
|
||||
}
|
||||
+37
@@ -18,6 +18,7 @@ import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockByCodeReqDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuImportDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuPageDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuImportNewDto;
|
||||
import com.bsd.pjcloud.supermarket.entity.SmErpAuxiliaryCodeEntity;
|
||||
import com.bsd.pjcloud.supermarket.entity.SmErpSpuEntity;
|
||||
import com.bsd.pjcloud.supermarket.entity.SmErpStockEntity;
|
||||
@@ -189,6 +190,20 @@ public class SmErpSpuController {
|
||||
return smErpSpuService.exportSupermarketSpuStockExcel(supermarketSpu, ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新的导出方法(用于测试)
|
||||
* 导出符合新格式的商品数据,包含包装单位、辅助条码等信息
|
||||
* @param supermarketSpu 查询条件
|
||||
* @param ids 导出指定ID
|
||||
* @return excel 文件流
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/exportNew")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_supermarketSpu_export')" )
|
||||
@Operation(summary = "新的商品导出", description = "导出包含包装单位、辅助条码等详细信息的商品数据")
|
||||
public List<SmErpSpuImportNewDto> exportNew(SmErpSpuEntity supermarketSpu, Long[] ids) {
|
||||
return smErpSpuService.exportSupermarketSpuNewExcel(supermarketSpu, ids);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "简要查询" , description = "根据商品名称或者或者查询商品简要信息" )
|
||||
@@ -238,6 +253,28 @@ public class SmErpSpuController {
|
||||
return smErpSpuService.importErpSpu(collect, bindingResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新的导入方法(用于测试)
|
||||
* 参考图片数据结构:商品编码、商品名称、规格、包装单位编码、换算率、是否主单位、辅助条码、条码类型
|
||||
*
|
||||
* @param dtos 导入数据列表
|
||||
* @param bindingResult 错误信息列表
|
||||
* @return R
|
||||
*/
|
||||
@PostMapping("/importNew")
|
||||
@PreAuthorize("@pms.hasPermission('supermarket_supermarketSpu_import')" )
|
||||
@Idempotent(expireTime = 10, info = "请勿重复导入,10秒后再重新尝试")
|
||||
@Operation(summary = "新的商品导入", description = "支持包装单位、辅助条码等详细信息的导入")
|
||||
public R importErpSpuNew(@RequestExcel List<SmErpSpuImportNewDto> dtos, BindingResult bindingResult) {
|
||||
List<SmErpSpuImportNewDto> collect = dtos.stream()
|
||||
.filter(dto -> StringUtils.isNotBlank(dto.getProductCode()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(collect)) {
|
||||
return R.failed("导入数据不能为空");
|
||||
}
|
||||
return smErpSpuService.importErpSpuNew(collect, bindingResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件查询spu单表 列表信息
|
||||
* @param supermarketSpuQueryDTO 商品spu
|
||||
|
||||
+17
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockByCodeReqDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.cgplan.ErpCgPlanDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuImportDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuImportNewDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuPageDto;
|
||||
import com.bsd.pjcloud.supermarket.entity.SmErpSpuEntity;
|
||||
import com.bsd.pjcloud.supermarket.vo.ad.SmErpSpuDetailsVo;
|
||||
@@ -112,6 +113,14 @@ public interface SmErpSpuService extends IService<SmErpSpuEntity> {
|
||||
*/
|
||||
R importErpSpu(List<SmErpSpuImportDto> smErpSupplierImportDtos, BindingResult bindingResult);
|
||||
|
||||
/**
|
||||
* 新的导入方法(用于测试)
|
||||
* @param smErpSpuImportNewDtos
|
||||
* @param bindingResult
|
||||
* @return
|
||||
*/
|
||||
R importErpSpuNew(List<SmErpSpuImportNewDto> smErpSpuImportNewDtos, BindingResult bindingResult);
|
||||
|
||||
|
||||
/**
|
||||
* 导出
|
||||
@@ -121,6 +130,14 @@ public interface SmErpSpuService extends IService<SmErpSpuEntity> {
|
||||
*/
|
||||
List<SmErpSpuStockExcel> exportSupermarketSpuStockExcel(SmErpSpuEntity supermarketSpu, Long[] ids);
|
||||
|
||||
/**
|
||||
* 新的导出方法(用于测试)
|
||||
* @param supermarketSpu
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
List<SmErpSpuImportNewDto> exportSupermarketSpuNewExcel(SmErpSpuEntity supermarketSpu, Long[] ids);
|
||||
|
||||
|
||||
// R calculateCostPrice();
|
||||
|
||||
|
||||
+323
-5
@@ -19,6 +19,7 @@ import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockByCodeReqDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.cgplan.ErpCgPlanDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuImportDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuImportNewDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.erpspu.SmErpSpuPageDto;
|
||||
import com.bsd.pjcloud.supermarket.dto.inventoryrecords.UpdateStockDTO;
|
||||
import com.bsd.pjcloud.supermarket.entity.*;
|
||||
@@ -387,11 +388,11 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
lambdaUpdateWrapper.eq(SmErpStockEntity::getErpSpuId, spuId);
|
||||
SmErpStockEntity smErpStockEntity = smErpStockMapper.selectOne(lambdaUpdateWrapper);
|
||||
|
||||
|
||||
//todo 要求先允许超卖,过后在入库回来
|
||||
// 检查库存是否足够
|
||||
if (incrCount < 0 && Math.abs(incrCount) > smErpStockEntity.getCurrentStock()) {
|
||||
return R.failed(spu.getProductName() + "库存不足,无法完成操作");
|
||||
}
|
||||
// if (incrCount < 0 && Math.abs(incrCount) > smErpStockEntity.getCurrentStock()) {
|
||||
// return R.failed(spu.getProductName() + "库存不足,无法完成操作");
|
||||
// }
|
||||
|
||||
UpdateStockDTO updateStockDTO = new UpdateStockDTO(spuId, incrCount);
|
||||
updateStockDTOS.add(updateStockDTO);
|
||||
@@ -742,7 +743,7 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
dto.getClassification(),
|
||||
errorReasons,
|
||||
rowNumber,
|
||||
productCode,deptId,merchantId
|
||||
productCode,deptId,null
|
||||
);
|
||||
if (categoryId == null) {
|
||||
errorList.add(createErrorInfo(rowNumber, productCode, errorReasons));
|
||||
@@ -919,11 +920,328 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
return buildImportResult(smErpSpuImportDtos.size(), productCodeToSpuMap.size(), errorList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R importErpSpuNew(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);
|
||||
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) {
|
||||
// 更新现有商品
|
||||
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(dto.getProductNature());
|
||||
spu.setStatus("0".equals(dto.getStatus()) ? "0" : "1");
|
||||
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(dto.getProductNature());
|
||||
spu.setStatus("0".equals(dto.getStatus()) ? "0" : "1");
|
||||
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.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());
|
||||
SmErpUnitEntity existingUnit = smErpUnitService.getOne(existingUnitWrapper);
|
||||
|
||||
if (existingUnit != null) {
|
||||
existingUnit.setPackageNum(dto.getPackageNum());
|
||||
existingUnit.setPurchasePrice(unit.getPurchasePrice());
|
||||
existingUnit.setRetailPrice(unit.getRetailPrice());
|
||||
existingUnit.setPromotionPrice(unit.getPromotionPrice());
|
||||
existingUnit.setCostPrice(unit.getCostPrice());
|
||||
smErpUnitService.updateById(existingUnit);
|
||||
} else {
|
||||
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());
|
||||
|
||||
// 检查辅助条码是否已存在
|
||||
LambdaQueryWrapper<SmErpAuxiliaryCodeEntity> existingBarcodeWrapper = new LambdaQueryWrapper<>();
|
||||
existingBarcodeWrapper.eq(SmErpAuxiliaryCodeEntity::getSpuId, spu.getId())
|
||||
.eq(SmErpAuxiliaryCodeEntity::getBarCode, dto.getBarCode());
|
||||
SmErpAuxiliaryCodeEntity existingBarcode = smErpAuxiliaryCodeService.getOne(existingBarcodeWrapper);
|
||||
|
||||
if (existingBarcode != null) {
|
||||
existingBarcode.setUnitId(existingUnit != null ? existingUnit.getId() : unit.getId());
|
||||
smErpAuxiliaryCodeService.updateById(existingBarcode);
|
||||
} else {
|
||||
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) {
|
||||
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);
|
||||
existingStock.setCurrentStock(dto.getStock() != null ? dto.getStock() : 0.0);
|
||||
smErpStockService.updateById(existingStock);
|
||||
} 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
|
||||
public List<SmErpSpuStockExcel> exportSupermarketSpuStockExcel(SmErpSpuEntity supermarketSpu, Long[] ids) {
|
||||
return baseMapper.exportSupermarketSpuStockExcel(supermarketSpu, ids,DataScope.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SmErpSpuImportNewDto> exportSupermarketSpuNewExcel(SmErpSpuEntity supermarketSpu, Long[] ids) {
|
||||
List<SmErpSpuEntity> spuList;
|
||||
|
||||
if (ids != null && ids.length > 0) {
|
||||
// 导出指定ID的商品
|
||||
spuList = this.listByIds(Arrays.asList(ids));
|
||||
} else {
|
||||
// 根据条件查询商品
|
||||
LambdaQueryWrapper<SmErpSpuEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(supermarketSpu.getProductCode())) {
|
||||
wrapper.like(SmErpSpuEntity::getProductCode, supermarketSpu.getProductCode());
|
||||
}
|
||||
if (StringUtils.isNotBlank(supermarketSpu.getProductName())) {
|
||||
wrapper.like(SmErpSpuEntity::getProductName, supermarketSpu.getProductName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(supermarketSpu.getBarCode())) {
|
||||
wrapper.like(SmErpSpuEntity::getBarCode, supermarketSpu.getBarCode());
|
||||
}
|
||||
spuList = this.list(wrapper);
|
||||
}
|
||||
|
||||
List<SmErpSpuImportNewDto> exportList = new ArrayList<>();
|
||||
|
||||
for (SmErpSpuEntity spu : spuList) {
|
||||
// 获取包装单位信息
|
||||
List<SmErpUnitEntity> units = smErpUnitService.list(
|
||||
new LambdaQueryWrapper<SmErpUnitEntity>()
|
||||
.eq(SmErpUnitEntity::getSpuId, spu.getId())
|
||||
);
|
||||
|
||||
// 获取辅助条码信息
|
||||
List<SmErpAuxiliaryCodeEntity> auxiliaryCodes = smErpAuxiliaryCodeService.list(
|
||||
new LambdaQueryWrapper<SmErpAuxiliaryCodeEntity>()
|
||||
.eq(SmErpAuxiliaryCodeEntity::getSpuId, spu.getId())
|
||||
);
|
||||
|
||||
// 获取库存信息
|
||||
SmErpStockEntity stock = smErpStockService.getOne(
|
||||
new LambdaQueryWrapper<SmErpStockEntity>()
|
||||
.eq(SmErpStockEntity::getErpSpuId, spu.getId())
|
||||
);
|
||||
|
||||
// 获取分类信息
|
||||
String categoryName = null;
|
||||
if (spu.getCategoryId() != null) {
|
||||
SmErpCategoryEntity category = smErpCategoryMapper.selectById(spu.getCategoryId());
|
||||
if (category != null) {
|
||||
categoryName = category.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取货商信息
|
||||
String supplierName = null;
|
||||
if (spu.getSupplierId() != null) {
|
||||
SmErpSupplierEntity supplier = smErpSupplierMapper.selectById(spu.getSupplierId());
|
||||
if (supplier != null) {
|
||||
supplierName = supplier.getSupplierName();
|
||||
}
|
||||
}
|
||||
|
||||
if (units.isEmpty()) {
|
||||
// 如果没有包装单位,创建一个默认的
|
||||
SmErpSpuImportNewDto dto = new SmErpSpuImportNewDto();
|
||||
dto.setProductCode(spu.getProductCode());
|
||||
dto.setBarCode(spu.getBarCode());
|
||||
dto.setProductName(spu.getProductName());
|
||||
dto.setUnit("个");
|
||||
dto.setOrigin(spu.getOrigin());
|
||||
dto.setSpec(spu.getSpec());
|
||||
dto.setStock(stock != null ? stock.getCurrentStock() : 0.0);
|
||||
dto.setCategoryName(categoryName);
|
||||
dto.setPackageNum(1);
|
||||
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.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");
|
||||
exportList.add(dto);
|
||||
} else {
|
||||
// 为每个包装单位创建一条记录
|
||||
for (SmErpUnitEntity unit : units) {
|
||||
SmErpSpuImportNewDto dto = new SmErpSpuImportNewDto();
|
||||
dto.setProductCode(spu.getProductCode());
|
||||
dto.setBarCode(spu.getBarCode());
|
||||
dto.setProductName(spu.getProductName());
|
||||
dto.setUnit(unit.getUnit());
|
||||
dto.setOrigin(spu.getOrigin());
|
||||
dto.setSpec(spu.getSpec());
|
||||
dto.setStock(stock != null ? stock.getCurrentStock() : 0.0);
|
||||
dto.setCategoryName(categoryName);
|
||||
dto.setPackageNum(unit.getPackageNum());
|
||||
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.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");
|
||||
exportList.add(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return exportList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析供应商ID(存在则返回,不存在则创建)
|
||||
*
|
||||
|
||||
+73
-2
@@ -105,7 +105,7 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectPageXmlByScope" resultMap="supermarketSpuMap">
|
||||
<!-- <select id="selectPageXmlByScope" resultMap="supermarketSpuMap">
|
||||
SELECT
|
||||
spu.id,
|
||||
spu.product_code,
|
||||
@@ -132,7 +132,7 @@
|
||||
LEFT JOIN sm_erp_supplier supplier
|
||||
ON spu.supplier_id = supplier.supplier_id
|
||||
<where>
|
||||
spu.del_flag = '0' and unit.del_flag = '0'
|
||||
spu.del_flag = '0' and unit.del_flag = '0' and unit.is_base=1
|
||||
<if test="supermarketSpuPageDto.productCode != null">
|
||||
AND spu.product_code = #{supermarketSpuPageDto.productCode}
|
||||
</if>
|
||||
@@ -156,5 +156,76 @@
|
||||
</if>
|
||||
</where>
|
||||
order by spu.create_time desc,spu.id desc
|
||||
</select>-->
|
||||
<select id="selectPageXmlByScope" resultMap="supermarketSpuMap">
|
||||
WITH SpuUnitRank AS (
|
||||
SELECT
|
||||
spu.id,
|
||||
spu.product_code,
|
||||
spu.product_name,
|
||||
spu.category_id,
|
||||
spu.pic_url,
|
||||
spu.product_nature,
|
||||
spu.create_time,
|
||||
spu.sales_count,
|
||||
spu.dept_id,
|
||||
spu.create_by,
|
||||
spu.unit,
|
||||
spu.spec,
|
||||
unit.retail_price,
|
||||
unit.cost_price,
|
||||
st.current_stock as stock,
|
||||
supplier.supplier_id,
|
||||
unit.bar_code,
|
||||
CASE WHEN #{supermarketSpuPageDto.barCode} IS NOT NULL
|
||||
THEN CASE WHEN unit.bar_code = #{supermarketSpuPageDto.barCode} THEN 0 ELSE 1 END
|
||||
ELSE 0
|
||||
END AS search_priority,
|
||||
ROW_NUMBER() OVER(
|
||||
PARTITION BY spu.id
|
||||
ORDER BY
|
||||
CASE WHEN #{supermarketSpuPageDto.barCode} IS NOT NULL
|
||||
THEN CASE WHEN unit.bar_code = #{supermarketSpuPageDto.barCode} THEN 0 ELSE 1 END
|
||||
ELSE 0
|
||||
END,
|
||||
unit.id ASC
|
||||
) AS unit_rank
|
||||
FROM sm_erp_spu spu
|
||||
JOIN sm_erp_unit unit ON spu.id = unit.spu_id
|
||||
LEFT JOIN sm_erp_stock st ON spu.id = st.erp_spu_id
|
||||
LEFT JOIN sm_erp_supplier supplier ON spu.supplier_id = supplier.supplier_id
|
||||
<where>
|
||||
spu.del_flag = '0' AND unit.del_flag = '0'
|
||||
<if test="supermarketSpuPageDto.productCode != null">
|
||||
AND spu.product_code = #{supermarketSpuPageDto.productCode}
|
||||
</if>
|
||||
<if test="supermarketSpuPageDto.productName != null">
|
||||
AND spu.product_name LIKE CONCAT('%', #{supermarketSpuPageDto.productName}, '%')
|
||||
</if>
|
||||
<if test="supermarketSpuPageDto.categoryId != null">
|
||||
AND spu.category_id = #{supermarketSpuPageDto.categoryId}
|
||||
</if>
|
||||
<if test="supermarketSpuPageDto.productNature != null">
|
||||
AND spu.product_nature = #{supermarketSpuPageDto.productNature}
|
||||
</if>
|
||||
<if test="supermarketSpuPageDto.status != null">
|
||||
AND spu.status = #{supermarketSpuPageDto.status}
|
||||
</if>
|
||||
<if test="supermarketSpuPageDto.supplierId != null">
|
||||
AND spu.supplier_id = #{supermarketSpuPageDto.supplierId}
|
||||
</if>
|
||||
</where>
|
||||
)
|
||||
SELECT *
|
||||
FROM SpuUnitRank
|
||||
WHERE unit_rank = 1
|
||||
<if test="supermarketSpuPageDto.barCode != null">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM SpuUnitRank sub
|
||||
WHERE sub.id = SpuUnitRank.id
|
||||
AND sub.bar_code = #{supermarketSpuPageDto.barCode}
|
||||
)
|
||||
</if>
|
||||
ORDER BY create_time DESC, id DESC
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user