|
|
@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.dromara.product.domain.bo.ProductBaseBo;
|
|
|
import org.dromara.product.domain.bo.SiteProductBo;
|
|
|
import org.dromara.product.domain.vo.ProductBaseVo;
|
|
|
+import org.dromara.product.domain.vo.RecommendProductVo;
|
|
|
import org.dromara.product.domain.vo.SiteProductVo;
|
|
|
import org.dromara.product.domain.ProductBase;
|
|
|
import org.dromara.product.domain.ProductExtend;
|
|
|
@@ -220,7 +221,7 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
try {
|
|
|
// 1. 保存产品基础信息
|
|
|
ProductBase productBase = MapstructUtils.convert(bo, ProductBase.class);
|
|
|
- validEntityBeforeSave(productBase);
|
|
|
+ validEntityBeforeSave(productBase, true);
|
|
|
|
|
|
// 设置默认值
|
|
|
setDefaultValues(productBase);
|
|
|
@@ -272,7 +273,7 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
|
|
|
// 1. 更新产品基础信息
|
|
|
ProductBase productBase = MapstructUtils.convert(bo, ProductBase.class);
|
|
|
- validEntityBeforeSave(productBase);
|
|
|
+ validEntityBeforeSave(productBase, false);
|
|
|
|
|
|
boolean flag = baseMapper.updateById(productBase) > 0;
|
|
|
if (!flag) {
|
|
|
@@ -350,7 +351,7 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
extend.setVolumeUnit(bo.getVolumeUnit());
|
|
|
extend.setAfterSalesService(bo.getAfterSalesService());
|
|
|
extend.setReferenceLink(bo.getReferenceLink());
|
|
|
- extend.setIsCustomize(bo.getCustomizable()?"1":"0");
|
|
|
+ extend.setIsCustomize(Boolean.TRUE.equals(bo.getCustomizable()) ? "1" : "0");
|
|
|
extend.setCustomDescription(bo.getCustomDescription());
|
|
|
// 直接使用前端传递的服务保障ID列表(逗号分隔)
|
|
|
extend.setServiceGuarantee(bo.getServiceGuarantee());
|
|
|
@@ -400,28 +401,53 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
* 更新产品扩展信息
|
|
|
*/
|
|
|
private void updateProductExtend(ProductBaseBo bo, Long productId) {
|
|
|
- // 先删除旧的扩展信息
|
|
|
+ // 检查是否存在扩展信息
|
|
|
LambdaQueryWrapper<ProductExtend> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(ProductExtend::getProductId, productId);
|
|
|
- extendMapper.delete(wrapper);
|
|
|
+ ProductExtend existing = extendMapper.selectOne(wrapper);
|
|
|
|
|
|
- // 重新保存
|
|
|
- saveProductExtend(bo, productId);
|
|
|
+ if (existing != null) {
|
|
|
+ // 存在则更新(只更新非空字段)
|
|
|
+ if (bo.getInvoiceName() != null) existing.setInvoiceName(bo.getInvoiceName());
|
|
|
+ if (bo.getInvoiceSpec() != null) existing.setInvoiceSpecs(bo.getInvoiceSpec());
|
|
|
+ if (bo.getUpcBarcode() != null) existing.setBarCoding(bo.getUpcBarcode());
|
|
|
+ if (bo.getWeight() != null) existing.setProductWeight(bo.getWeight());
|
|
|
+ if (bo.getWeightUnit() != null) existing.setWeightUnit(bo.getWeightUnit());
|
|
|
+ if (bo.getVolume() != null) existing.setProductVolume(bo.getVolume());
|
|
|
+ if (bo.getVolumeUnit() != null) existing.setVolumeUnit(bo.getVolumeUnit());
|
|
|
+ if (bo.getAfterSalesService() != null) existing.setAfterSalesService(bo.getAfterSalesService());
|
|
|
+ if (bo.getReferenceLink() != null) existing.setReferenceLink(bo.getReferenceLink());
|
|
|
+ if (bo.getCustomizable() != null) existing.setIsCustomize(bo.getCustomizable() ? "1" : "0");
|
|
|
+ if (bo.getCustomDescription() != null) existing.setCustomDescription(bo.getCustomDescription());
|
|
|
+ if (bo.getServiceGuarantee() != null) existing.setServiceGuarantee(bo.getServiceGuarantee());
|
|
|
+ if (bo.getFreeInstallation() != null) existing.setIsInstallService(bo.getFreeInstallation());
|
|
|
+ if (bo.getSalesVolume() != null) existing.setSalesVolume(bo.getSalesVolume());
|
|
|
+ extendMapper.updateById(existing);
|
|
|
+ } else {
|
|
|
+ // 不存在则新增
|
|
|
+ saveProductExtend(bo, productId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新产品价格库存信息
|
|
|
*/
|
|
|
private void updateProductPriceInventory(ProductBaseBo bo, Long productId) {
|
|
|
+ // 如果没有传价格相关信息,不做任何操作
|
|
|
+ if (bo.getMidRangePrice() == null && bo.getStandardPrice() == null &&
|
|
|
+ bo.getCertificatePrice() == null && bo.getPurchasePrice() == null &&
|
|
|
+ bo.getEstimatedPurchasePrice() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
ProductPriceInventory existing = priceInventoryMapper.selectById(productId);
|
|
|
if (existing != null) {
|
|
|
- // 更新现有记录
|
|
|
- existing.setMarketPrice(bo.getMidRangePrice());
|
|
|
- existing.setMemberPrice(bo.getStandardPrice());
|
|
|
- existing.setMinSellingPrice(bo.getCertificatePrice());
|
|
|
- existing.setPurchasingPrice(bo.getPurchasePrice());
|
|
|
- existing.setMaxPurchasePrice(bo.getEstimatedPurchasePrice());
|
|
|
-
|
|
|
+ // 更新非空字段
|
|
|
+ if (bo.getMidRangePrice() != null) existing.setMarketPrice(bo.getMidRangePrice());
|
|
|
+ if (bo.getStandardPrice() != null) existing.setMemberPrice(bo.getStandardPrice());
|
|
|
+ if (bo.getCertificatePrice() != null) existing.setMinSellingPrice(bo.getCertificatePrice());
|
|
|
+ if (bo.getPurchasePrice() != null) existing.setPurchasingPrice(bo.getPurchasePrice());
|
|
|
+ if (bo.getEstimatedPurchasePrice() != null) existing.setMaxPurchasePrice(bo.getEstimatedPurchasePrice());
|
|
|
priceInventoryMapper.updateById(existing);
|
|
|
} else {
|
|
|
// 创建新记录
|
|
|
@@ -433,21 +459,34 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
* 更新产品属性关联信息
|
|
|
*/
|
|
|
private void updateProductClassification(ProductBaseBo bo, Long productId) {
|
|
|
- // 先删除旧的分类关联
|
|
|
+ // 如果没有传分类信息,不做任何操作
|
|
|
+ if (bo.getBottomCategoryId() == null && bo.getAttributesList() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
LambdaQueryWrapper<ProductClassification> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(ProductClassification::getProductId, productId);
|
|
|
- classificationMapper.delete(wrapper);
|
|
|
+ ProductClassification existing = classificationMapper.selectOne(wrapper);
|
|
|
|
|
|
- // 重新保存
|
|
|
- saveProductClassification(bo, productId);
|
|
|
+ if (existing != null) {
|
|
|
+ // 存在则更新非空字段
|
|
|
+ if (bo.getBottomCategoryId() != null) existing.setCategoryId(bo.getBottomCategoryId());
|
|
|
+ if (bo.getAttributesList() != null) existing.setAttributesList(bo.getAttributesList());
|
|
|
+ classificationMapper.updateById(existing);
|
|
|
+ } else if (bo.getBottomCategoryId() != null) {
|
|
|
+ // 不存在且有分类ID才新增
|
|
|
+ saveProductClassification(bo, productId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
+ * @param entity 实体
|
|
|
+ * @param isInsert 是否新增操作
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(ProductBase entity){
|
|
|
+ private void validEntityBeforeSave(ProductBase entity, boolean isInsert){
|
|
|
// 校验产品编号唯一性(新增时)
|
|
|
- if (entity.getId() == null && StringUtils.isNotBlank(entity.getProductNo())) {
|
|
|
+ if (isInsert && StringUtils.isNotBlank(entity.getProductNo())) {
|
|
|
LambdaQueryWrapper<ProductBase> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(ProductBase::getProductNo, entity.getProductNo());
|
|
|
Long count = baseMapper.selectCount(wrapper);
|
|
|
@@ -456,8 +495,8 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 校验产品编号唯一性(更新时)
|
|
|
- if (entity.getId() != null && StringUtils.isNotBlank(entity.getProductNo())) {
|
|
|
+ // 校验产品编号唯一性(更新时,如果传了productNo才校验)
|
|
|
+ if (!isInsert && StringUtils.isNotBlank(entity.getProductNo())) {
|
|
|
LambdaQueryWrapper<ProductBase> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(ProductBase::getProductNo, entity.getProductNo());
|
|
|
wrapper.ne(ProductBase::getId, entity.getId());
|
|
|
@@ -467,14 +506,14 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 校验必填字段
|
|
|
- if (StringUtils.isBlank(entity.getItemName())) {
|
|
|
- throw new RuntimeException("产品名称不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验分类信息
|
|
|
- if (entity.getTopCategoryId() == null || entity.getMediumCategoryId() == null || entity.getBottomCategoryId() == null) {
|
|
|
- throw new RuntimeException("产品分类信息不完整,请选择完整的三级分类");
|
|
|
+ // 新增时校验必填字段
|
|
|
+ if (isInsert) {
|
|
|
+ if (StringUtils.isBlank(entity.getItemName())) {
|
|
|
+ throw new RuntimeException("产品名称不能为空");
|
|
|
+ }
|
|
|
+ if (entity.getTopCategoryId() == null || entity.getMediumCategoryId() == null || entity.getBottomCategoryId() == null) {
|
|
|
+ throw new RuntimeException("产品分类信息不完整,请选择完整的三级分类");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 校验数值范围
|
|
|
@@ -636,14 +675,22 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
* 更新产品定制信息
|
|
|
*/
|
|
|
private void updateProductCustomization(ProductBaseBo bo, Long productId) {
|
|
|
- // 先删除旧的定制信息
|
|
|
- LambdaQueryWrapper<ProductCustomization> wrapper = Wrappers.lambdaQuery();
|
|
|
- wrapper.eq(ProductCustomization::getProductId, productId);
|
|
|
- customizationMapper.delete(wrapper);
|
|
|
+ // 如果没有传定制相关信息,不做任何操作
|
|
|
+ if (bo.getCustomizable() == null && bo.getCustomDetailsJson() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // 如果可定制,则保存新的定制信息
|
|
|
- if (bo.getCustomizable() != null && bo.getCustomizable()) {
|
|
|
- saveProductCustomization(bo, productId);
|
|
|
+ // 只有明确传了定制详情JSON才更新定制信息
|
|
|
+ if (bo.getCustomDetailsJson() != null) {
|
|
|
+ // 先删除旧的定制信息
|
|
|
+ LambdaQueryWrapper<ProductCustomization> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(ProductCustomization::getProductId, productId);
|
|
|
+ customizationMapper.delete(wrapper);
|
|
|
+
|
|
|
+ // 如果可定制,则保存新的定制信息
|
|
|
+ if (Boolean.TRUE.equals(bo.getCustomizable())) {
|
|
|
+ saveProductCustomization(bo, productId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -680,4 +727,17 @@ public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, Prod
|
|
|
);
|
|
|
return productBase;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询推荐商品列表(联表查询分类名称)
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 推荐商品分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<RecommendProductVo> queryRecommendProductPageList(ProductBaseBo bo, PageQuery pageQuery) {
|
|
|
+ Page<RecommendProductVo> page = baseMapper.selectRecommendProductPage(pageQuery.build(), bo);
|
|
|
+ return TableDataInfo.build(page);
|
|
|
+ }
|
|
|
}
|