Commit 0f0618d7 by 潘诗林

Revert "feat:SPU供应商字段挪到SKU级别,支持多选,批量导入同步修改/出入库记录&出库记录新增字段"

1 parent ff22746f
package cn.com.glsx.dj.smartcarlife.dto; package cn.com.glsx.dj.smartcarlife.dto;
import cn.com.glsx.dj.smartcarlife.model.MerchantGoodsStockReduceRecord; import cn.com.glsx.dj.smartcarlife.model.MerchantGoodsStockReduceRecord;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
...@@ -10,7 +9,6 @@ import lombok.ToString; ...@@ -10,7 +9,6 @@ import lombok.ToString;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
import java.util.List; import java.util.List;
@AllArgsConstructor @AllArgsConstructor
...@@ -69,8 +67,4 @@ public class MerchantGoodsStockReduceRecordDTO extends MerchantGoodsStockReduceR ...@@ -69,8 +67,4 @@ public class MerchantGoodsStockReduceRecordDTO extends MerchantGoodsStockReduceR
private String specificationData; private String specificationData;
private String specificationTypeSequence; private String specificationTypeSequence;
@ApiModelProperty(notes = "支付时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date successDate;
} }
...@@ -180,19 +180,12 @@ public class UpgradeGoodsDTO extends UpgradeGoods { ...@@ -180,19 +180,12 @@ public class UpgradeGoodsDTO extends UpgradeGoods {
@ApiModelProperty(notes = "sku适用区域列表") @ApiModelProperty(notes = "sku适用区域列表")
private List<UpgradeGoodsAreaDTO> upgradeGoodsAreaList; private List<UpgradeGoodsAreaDTO> upgradeGoodsAreaList;
@ApiModelProperty(notes = "供应商ID(已废弃,改用providerIds多选)") @ApiModelProperty(notes = "供货商ID")
@Deprecated
private Integer providerId; private Integer providerId;
@ApiModelProperty(notes = "供应商ID列表(多选)") @ApiModelProperty(notes = "供货商名称")
private List<Integer> providerIds;
@ApiModelProperty(notes = "供应商名称 / 分割")
private String providerName; private String providerName;
@ApiModelProperty(notes = "供应商名称集合")
private List<String> providerNameList;
@ApiModelProperty(notes = "基础场景编码,前端传新场景值,后端转换为历史sceneType") @ApiModelProperty(notes = "基础场景编码,前端传新场景值,后端转换为历史sceneType")
private String baseSceneCode; private String baseSceneCode;
......
package cn.com.glsx.dj.smartcarlife.dto.goods;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import javax.persistence.Column;
import java.io.Serializable;
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@Data
public class UpgradeGoodsProviderRefDTO implements Serializable {
@ApiModelProperty(notes = "升级商品ID")
private Integer upgradeGoodsId;
@ApiModelProperty("供应商名称")
private String providerName;
}
package cn.com.glsx.dj.smartcarlife.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@Data
@Table(name = "dj_car_life_upgrade_goods_provider_ref")
public class UpgradeGoodsProviderRef implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ApiModelProperty(notes = "升级商品ID")
@Column(name = "upgrade_goods_id")
private Integer upgradeGoodsId;
@ApiModelProperty(notes = "供应商ID")
@Column(name = "provider_id")
private Integer providerId;
@Column(name = "created_by")
private String createdBy;
@Column(name = "created_date")
private Date createdDate;
@Column(name = "updated_by")
private String updatedBy;
@Column(name = "updated_date")
private Date updatedDate;
@Column(name = "deleted_flag")
private String deletedFlag;
}
package cn.com.glsx.dj.smartcarlife.mapper;
import cn.com.glsx.dj.smartcarlife.dto.goods.UpgradeGoodsProviderRefDTO;
import cn.com.glsx.dj.smartcarlife.model.UpgradeGoodsProviderRef;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List;
@Mapper
public interface UpgradeGoodsProviderRefMapper extends OreMapper<UpgradeGoodsProviderRef> {
List<UpgradeGoodsProviderRef> findByUpgradeGoodsId(@Param("upgradeGoodsId") Integer upgradeGoodsId);
List<UpgradeGoodsProviderRef> findByUpgradeGoodsIds(@Param("upgradeGoodsIds") List<Integer> upgradeGoodsIds);
/**
* 返回 upgrade_goods_id → provider_id 列表的映射(用于填充 DTO.providerIds)
*/
List<UpgradeGoodsProviderRef> listProviderIdsByUpgradeGoodsIds(@Param("upgradeGoodsIds") List<Integer> upgradeGoodsIds);
/**
* 返回 upgrade_goods_id → "供应商A/供应商B" 的映射(用于填充 DTO.providerName)
*/
List<UpgradeGoodsProviderRefDTO> listProviderNamesByUpgradeGoodsIds(@Param("upgradeGoodsIds") List<Integer> upgradeGoodsIds);
int deleteByUpgradeGoodsId(@Param("upgradeGoodsId") Integer upgradeGoodsId);
/**
* 单个商品获取供应商名称
* @param upgradeGoodsId
* @return
*/
UpgradeGoodsProviderRefDTO findProviderNameByUpgradeGoodsId(@Param("upgradeGoodsId") Integer upgradeGoodsId);
}
...@@ -15,7 +15,10 @@ import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsMapper; ...@@ -15,7 +15,10 @@ import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsMapper;
import cn.com.glsx.dj.smartcarlife.model.*; import cn.com.glsx.dj.smartcarlife.model.*;
import cn.com.glsx.dj.smartcarlife.service.common.GoodsOperationLogService; import cn.com.glsx.dj.smartcarlife.service.common.GoodsOperationLogService;
import cn.com.glsx.dj.smartcarlife.service.common.UpdateOperationLogService; import cn.com.glsx.dj.smartcarlife.service.common.UpdateOperationLogService;
import cn.com.glsx.dj.smartcarlife.service.goods.*; import cn.com.glsx.dj.smartcarlife.service.goods.GoodsProviderService;
import cn.com.glsx.dj.smartcarlife.service.goods.GoodsSpecificationPermutationService;
import cn.com.glsx.dj.smartcarlife.service.goods.MerchantGoodsInfoService;
import cn.com.glsx.dj.smartcarlife.service.goods.UpgradeGoodsCarTypeConfigService;
import cn.com.glsx.dj.smartcarlife.vo.GoodsExportVO; import cn.com.glsx.dj.smartcarlife.vo.GoodsExportVO;
import cn.com.glsx.framework.core.beans.BaseModel; import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
...@@ -103,9 +106,6 @@ public class BaseGoodsService { ...@@ -103,9 +106,6 @@ public class BaseGoodsService {
@Autowired @Autowired
private GoodsOperationLogService goodsOperationLogService; private GoodsOperationLogService goodsOperationLogService;
@Autowired
private UpgradeGoodsProviderRefService upgradeGoodsProviderRefService;
public List<BaseGoodsDTO> list(BaseGoodsDTO record) { public List<BaseGoodsDTO> list(BaseGoodsDTO record) {
RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL, "BaseGoodsDTO not be null"); RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL, "BaseGoodsDTO not be null");
try { try {
...@@ -251,40 +251,21 @@ public class BaseGoodsService { ...@@ -251,40 +251,21 @@ public class BaseGoodsService {
record.setSpecificationPermutationList(goodsSpecificationPermutationService.listByBaseGoodsId(baseGoodsId)); record.setSpecificationPermutationList(goodsSpecificationPermutationService.listByBaseGoodsId(baseGoodsId));
// 关联升级商品 // 关联升级商品
List<UpgradeGoodsDTO> upgradeGoodsDTOList = upgradeGoodsService.listByBaseGoodsId(baseGoodsId, null); List<UpgradeGoodsDTO> upgradeGoodsDTOList = upgradeGoodsService.listByBaseGoodsId(baseGoodsId, null);
//查询供应商 upgradeGoodsDTOList.forEach(i -> {
Map<Integer, List<Integer>> refsMap = new HashMap<>(); i.setUpgradeGoodsServiceItemsList(upgradeGoodsServiceItemsRelationService.getByUpgradeGoodsId(i.getId()));
if(CollectionUtils.isNotEmpty(upgradeGoodsDTOList)){ if (i.getId() != null) {
List<Integer> upgradeGoodsIds = upgradeGoodsDTOList.stream() MerchantGoodsInfoDTO condition = MerchantGoodsInfoDTO.builder().upgradeGoodsId(i.getId())
.map(UpgradeGoodsDTO::getId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
List<UpgradeGoodsProviderRef> providerRefs = upgradeGoodsProviderRefService.findByUpgradeGoodsIds(upgradeGoodsIds);
if(CollectionUtils.isNotEmpty(providerRefs)){
refsMap = providerRefs.stream()
.collect(Collectors.groupingBy(
UpgradeGoodsProviderRef::getUpgradeGoodsId,
Collectors.mapping(UpgradeGoodsProviderRef::getProviderId, Collectors.toList())
));
}
}
for (UpgradeGoodsDTO upgradeGoodsDTO : upgradeGoodsDTOList) {
Integer upgradeGoodsDTOId = upgradeGoodsDTO.getId();
upgradeGoodsDTO.setUpgradeGoodsServiceItemsList(upgradeGoodsServiceItemsRelationService.getByUpgradeGoodsId(upgradeGoodsDTOId));
if (upgradeGoodsDTOId != null) {
MerchantGoodsInfoDTO condition = MerchantGoodsInfoDTO.builder().upgradeGoodsId(upgradeGoodsDTOId)
.statusList(Arrays.asList( .statusList(Arrays.asList(
CarLifeEnum.MerchantGoodsStatus.WAIT_AUDIT.getValue(), CarLifeEnum.MerchantGoodsStatus.WAIT_AUDIT.getValue(),
CarLifeEnum.MerchantGoodsStatus.ON_SHELF.getValue(), CarLifeEnum.MerchantGoodsStatus.ON_SHELF.getValue(),
CarLifeEnum.MerchantGoodsStatus.DRAFT.getValue() CarLifeEnum.MerchantGoodsStatus.DRAFT.getValue()
)).deletedFlag(BaseModel.DeletedFlagEnum.N.name()).build(); )).deletedFlag(BaseModel.DeletedFlagEnum.N.name()).build();
List<MerchantGoodsInfo> merchantGoodsInfos = merchantGoodsInfoService.listByCondition(condition); List<MerchantGoodsInfo> merchantGoodsInfos = merchantGoodsInfoService.listByCondition(condition);
upgradeGoodsDTO.setMerchantGoodsInfos(merchantGoodsInfos); i.setMerchantGoodsInfos(merchantGoodsInfos);
upgradeGoodsDTO.setCarTypeConfigList(upgradeGoodsCarTypeConfigService.listByUpgradeGoodsId(upgradeGoodsDTOId)); i.setCarTypeConfigList(upgradeGoodsCarTypeConfigService.listByUpgradeGoodsId(i.getId()));
upgradeGoodsDTO.setProviderIds(refsMap.get(upgradeGoodsDTOId));
} }
} });
//设置sku是否已上架 //设置sku是否已上架
setMerchantGoodsExist(upgradeGoodsDTOList); setMerchantGoodsExist(upgradeGoodsDTOList);
record.setUpgradeGoodsList(upgradeGoodsDTOList); record.setUpgradeGoodsList(upgradeGoodsDTOList);
...@@ -352,7 +333,7 @@ public class BaseGoodsService { ...@@ -352,7 +333,7 @@ public class BaseGoodsService {
GoodsMixDTO record = new GoodsMixDTO(); GoodsMixDTO record = new GoodsMixDTO();
BeanUtils.copyProperties(baseGoodsInfo, record); BeanUtils.copyProperties(baseGoodsInfo, record);
//record.getGoodsInfo().setProviderName(baseGoodsInfo.getGoodsInfo().getProviderName()); record.getGoodsInfo().setProviderName(baseGoodsInfo.getGoodsInfo().getProviderName());
//关联规格类型 //关联规格类型
record.setGoodsSpecificationNameList(goodsSpecificationService.listByBaseGoodsId(request.getId())); record.setGoodsSpecificationNameList(goodsSpecificationService.listByBaseGoodsId(request.getId()));
......
...@@ -14,14 +14,17 @@ import cn.com.glsx.dj.smartcarlife.mapper.MerchantGoodsAreaMapper; ...@@ -14,14 +14,17 @@ import cn.com.glsx.dj.smartcarlife.mapper.MerchantGoodsAreaMapper;
import cn.com.glsx.dj.smartcarlife.mapper.MerchantPackageAreaMapper; import cn.com.glsx.dj.smartcarlife.mapper.MerchantPackageAreaMapper;
import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsAreaMapper; import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsAreaMapper;
import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsMapper; import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsMapper;
import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsProviderRefMapper;
import cn.com.glsx.dj.smartcarlife.model.*; import cn.com.glsx.dj.smartcarlife.model.*;
import cn.com.glsx.dj.smartcarlife.model.UpgradeGoodsArea; import cn.com.glsx.dj.smartcarlife.model.UpgradeGoodsArea;
import cn.com.glsx.dj.smartcarlife.dto.ProductNoticeEvent; import cn.com.glsx.dj.smartcarlife.dto.ProductNoticeEvent;
import cn.com.glsx.dj.smartcarlife.dto.ProductNoticeDTO; import cn.com.glsx.dj.smartcarlife.dto.ProductNoticeDTO;
import cn.com.glsx.dj.smartcarlife.service.common.GoodsOperationLogService; import cn.com.glsx.dj.smartcarlife.service.common.GoodsOperationLogService;
import cn.com.glsx.dj.smartcarlife.service.common.UpdateOperationLogService; import cn.com.glsx.dj.smartcarlife.service.common.UpdateOperationLogService;
import cn.com.glsx.dj.smartcarlife.service.goods.*; import cn.com.glsx.dj.smartcarlife.service.goods.GoodsProviderService;
import cn.com.glsx.dj.smartcarlife.service.goods.MerchantGoodsInfoService;
import cn.com.glsx.dj.smartcarlife.service.goods.MerchantGoodsRefService;
import cn.com.glsx.dj.smartcarlife.service.goods.MerchantPackageGoodsInfoService;
import cn.com.glsx.dj.smartcarlife.service.goods.UpgradeGoodsCarTypeConfigService;
import cn.com.glsx.dj.smartcarlife.strategy.GoodsReviewUpdateBaseGoodsStatus; import cn.com.glsx.dj.smartcarlife.strategy.GoodsReviewUpdateBaseGoodsStatus;
import cn.com.glsx.dj.smartcarlife.util.CommonUtil; import cn.com.glsx.dj.smartcarlife.util.CommonUtil;
import cn.com.glsx.dj.smartcarlife.vo.GoodsExportVO; import cn.com.glsx.dj.smartcarlife.vo.GoodsExportVO;
...@@ -115,26 +118,24 @@ public class UpgradeGoodsService { ...@@ -115,26 +118,24 @@ public class UpgradeGoodsService {
@Autowired @Autowired
private MerchantPackageGoodsInfoService merchantPackageGoodsInfoService; private MerchantPackageGoodsInfoService merchantPackageGoodsInfoService;
@Autowired
private UpgradeGoodsProviderRefService upgradeGoodsProviderRefService;
// ===================== 通知辅助方法 ===================== // ===================== 通知辅助方法 =====================
/** /**
* 查询供应商名称:SKU升级商品ID -> 关系表 -> GoodsProvider.providerName * 查询供应商名称:goodsCode -> GoodsInfo.providerId -> GoodsProvider.providerName
*/ */
private String buildSupplierName(Integer upgradeGoodsId) { private String buildSupplierName(String goodsCode) {
try { try {
if (upgradeGoodsId == null) { if (StringUtils.isBlank(goodsCode)) {
return null; return null;
} }
UpgradeGoodsProviderRefDTO ref = upgradeGoodsProviderRefService.findProviderNameByUpgradeGoodsId(upgradeGoodsId); GoodsInfo goodsInfo = goodsInfoService.getByGoodsCode(goodsCode);
if (Objects.isNull(ref)) { if (goodsInfo == null || goodsInfo.getProviderId() == null) {
return null; return null;
} }
return ref.getProviderName(); GoodsProvider provider = goodsProviderService.getById(goodsInfo.getProviderId());
return provider != null ? provider.getProviderName() : null;
} catch (Exception e) { } catch (Exception e) {
log.warn("查询供应商名称失败 upgradeGoodsId={}", upgradeGoodsId, e); log.warn("查询供应商名称失败 goodsCode={}", goodsCode, e);
return null; return null;
} }
} }
...@@ -154,7 +155,7 @@ public class UpgradeGoodsService { ...@@ -154,7 +155,7 @@ public class UpgradeGoodsService {
.productCode(event.getType()) .productCode(event.getType())
.productName(event.getUpgradeGoodsName()) .productName(event.getUpgradeGoodsName())
.skuInfo(event.getCommodityCode()) .skuInfo(event.getCommodityCode())
.supplierName(buildSupplierName(event.getUpgradeGoodsId())) .supplierName(buildSupplierName(event.getGoodsCode()))
.operatingCost(event.getOperatingCost()) .operatingCost(event.getOperatingCost())
.oldOperatingCost(event.getOldOperatingCost()) .oldOperatingCost(event.getOldOperatingCost())
.newOperatingCost(event.getNewOperatingCost()) .newOperatingCost(event.getNewOperatingCost())
...@@ -790,9 +791,7 @@ public class UpgradeGoodsService { ...@@ -790,9 +791,7 @@ public class UpgradeGoodsService {
// ---------- 插入适用区域 ---------- // ---------- 插入适用区域 ----------
List<UpgradeGoodsArea> areaList = saveAreaSimple(upgradeGoods.getId(), dto.getUpgradeGoodsAreaList(), createBy, true); List<UpgradeGoodsArea> areaList = saveAreaSimple(upgradeGoods.getId(), dto.getUpgradeGoodsAreaList(), createBy, true);
// ---------- 保存供应商关系 ----------
upgradeGoodsProviderRefService.saveProviderRefs(upgradeGoods.getId(), dto.getProviderIds(), createBy,true);
// ---------- 收集通知事件(仅 D+ 来源且上架时) ---------- // ---------- 收集通知事件(仅 D+ 来源且上架时) ----------
if (!scrmSyncUpdate && Objects.equals(upgradeGoods.getOnShelfStatus(), ProductStatusEnum.ON_SHELF.getCode())) { if (!scrmSyncUpdate && Objects.equals(upgradeGoods.getOnShelfStatus(), ProductStatusEnum.ON_SHELF.getCode())) {
events.add(buildListedEvent(upgradeGoods, areaList, createBy)); events.add(buildListedEvent(upgradeGoods, areaList, createBy));
...@@ -1016,8 +1015,6 @@ public class UpgradeGoodsService { ...@@ -1016,8 +1015,6 @@ public class UpgradeGoodsService {
/*}*/ /*}*/
// productTemplateId 不为空,说明之前已保存过关联关系,不重复处理 // productTemplateId 不为空,说明之前已保存过关联关系,不重复处理
upgradeGoodsMapper.updateByPrimaryKeySelective(item); upgradeGoodsMapper.updateByPrimaryKeySelective(item);
// ---------- 更新供应商关系 ----------
upgradeGoodsProviderRefService.saveProviderRefs(item.getId(), item.getProviderIds(), updateBy,false);
// 记录操作日志 // 记录操作日志
if (CollectionUtils.isNotEmpty(oldUpgradeGoodsList) && oldUpgradeGoodsList.stream().map(UpgradeGoodsDTO::getId).collect(Collectors.toList()).contains(item.getId())) { if (CollectionUtils.isNotEmpty(oldUpgradeGoodsList) && oldUpgradeGoodsList.stream().map(UpgradeGoodsDTO::getId).collect(Collectors.toList()).contains(item.getId())) {
UpgradeGoodsDTO upgradeGoodsDTO = UpgradeGoodsDTO upgradeGoodsDTO =
...@@ -1187,8 +1184,6 @@ public class UpgradeGoodsService { ...@@ -1187,8 +1184,6 @@ public class UpgradeGoodsService {
upgradeGoodsServiceItemsRelationService.deleteByUpgradeGoodsId(id,updateBy); upgradeGoodsServiceItemsRelationService.deleteByUpgradeGoodsId(id,updateBy);
//删除关联适用区域 //删除关联适用区域
upgradeGoodsAreaService.deleteByUpgradeGoodsId(id, updateBy); upgradeGoodsAreaService.deleteByUpgradeGoodsId(id, updateBy);
//删除供应商关系
upgradeGoodsProviderRefService.deleteByUpgradeGoodsId(id);
}catch (RpcServiceException rpcServiceException){ }catch (RpcServiceException rpcServiceException){
throw rpcServiceException; throw rpcServiceException;
}catch (Exception e) { }catch (Exception e) {
...@@ -1379,8 +1374,6 @@ public class UpgradeGoodsService { ...@@ -1379,8 +1374,6 @@ public class UpgradeGoodsService {
upgradeGoodsMapper.insertSelective(upgradeGoodsDTO); upgradeGoodsMapper.insertSelective(upgradeGoodsDTO);
// 保存适用区域 // 保存适用区域
saveAreaSimple(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getUpgradeGoodsAreaList(), oprBy, true); saveAreaSimple(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getUpgradeGoodsAreaList(), oprBy, true);
// 保存供应商关系
upgradeGoodsProviderRefService.saveProviderRefs(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getProviderIds(), oprBy,true);
if (CollectionUtils.isNotEmpty(upgradeGoodsDTO.getUpgradeGoodsServiceItemsList())){ if (CollectionUtils.isNotEmpty(upgradeGoodsDTO.getUpgradeGoodsServiceItemsList())){
upgradeGoodsDTO.getUpgradeGoodsServiceItemsList().forEach(i->{ upgradeGoodsDTO.getUpgradeGoodsServiceItemsList().forEach(i->{
i.setUpgradeGoodsId(upgradeGoodsDTO.getId()); i.setUpgradeGoodsId(upgradeGoodsDTO.getId());
...@@ -1463,8 +1456,6 @@ public class UpgradeGoodsService { ...@@ -1463,8 +1456,6 @@ public class UpgradeGoodsService {
upgradeGoodsCarTypeConfigService.updateBatch(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getCarTypeConfigList(), upgradeGoodsDTO.getUpdatedBy()); upgradeGoodsCarTypeConfigService.updateBatch(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getCarTypeConfigList(), upgradeGoodsDTO.getUpdatedBy());
// 保存适用区域(先删后插) // 保存适用区域(先删后插)
saveAreaSimple(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getUpgradeGoodsAreaList(), upgradeGoodsDTO.getUpdatedBy(), false); saveAreaSimple(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getUpgradeGoodsAreaList(), upgradeGoodsDTO.getUpdatedBy(), false);
// // 保存供应商关系
upgradeGoodsProviderRefService.saveProviderRefs(upgradeGoodsDTO.getId(), upgradeGoodsDTO.getProviderIds(), upgradeGoodsDTO.getUpdatedBy(),false);
} }
......
...@@ -28,7 +28,7 @@ public enum GoodsTrackedFieldEnum { ...@@ -28,7 +28,7 @@ public enum GoodsTrackedFieldEnum {
THIRD_LEVEL_GOODS_TYPE_NAME("thirdLevelGoodsTypeName", "商品分类名(三级)"), THIRD_LEVEL_GOODS_TYPE_NAME("thirdLevelGoodsTypeName", "商品分类名(三级)"),
BRAND_MERCHANT_CODE("brandMerchantCode", "品牌商编号"), BRAND_MERCHANT_CODE("brandMerchantCode", "品牌商编号"),
BRAND_MERCHANT_NAME("brandMerchantName", "品牌商名称"), BRAND_MERCHANT_NAME("brandMerchantName", "品牌商名称"),
//PROVIDER_NAME("providerName", "供应商"), PROVIDER_NAME("providerName", "供应商"),
// GOODS_CODE("goodsCode", "产品编号"), // GOODS_CODE("goodsCode", "产品编号"),
// SAP_CODE("sapCode", "SAP编号"), // SAP_CODE("sapCode", "SAP编号"),
// THUMB_URL("thumbUrl", "商品缩略图"), // THUMB_URL("thumbUrl", "商品缩略图"),
...@@ -65,7 +65,6 @@ public enum GoodsTrackedFieldEnum { ...@@ -65,7 +65,6 @@ public enum GoodsTrackedFieldEnum {
SUPPLY_SOURCE("supplySource", "供应来源(1-原厂、2-集采、3-店采)"), SUPPLY_SOURCE("supplySource", "供应来源(1-原厂、2-集采、3-店采)"),
REMARK("remark", "备注"), REMARK("remark", "备注"),
UPGRADE_GOODS_AREA_LIST("upgradeGoodsAreaList", "适用区域"), UPGRADE_GOODS_AREA_LIST("upgradeGoodsAreaList", "适用区域"),
PROVIDER_NAME("providerName", "供应商"),
; ;
private final String fieldName; private final String fieldName;
......
...@@ -119,8 +119,6 @@ public class MerchantGoodsInfoService { ...@@ -119,8 +119,6 @@ public class MerchantGoodsInfoService {
private CreateBusinessProductService createBusinessProductService; private CreateBusinessProductService createBusinessProductService;
@Autowired @Autowired
private MerchantGoodsInventoryTypeRefService merchantGoodsInventoryTypeRefService; private MerchantGoodsInventoryTypeRefService merchantGoodsInventoryTypeRefService;
@Autowired
private UpgradeGoodsProviderRefService upgradeGoodsProviderRefService;
public String createMerchantGoodsCode(){ public String createMerchantGoodsCode(){
return "MG" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmss") + RandomUtils.nextInt(10000, 100000); return "MG" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmss") + RandomUtils.nextInt(10000, 100000);
...@@ -1562,21 +1560,20 @@ public class MerchantGoodsInfoService { ...@@ -1562,21 +1560,20 @@ public class MerchantGoodsInfoService {
log.warn("calculateOperationCost no sku, request={}", request); log.warn("calculateOperationCost no sku, request={}", request);
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "当前产品未查询到可计算运营成本的SKU"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "当前产品未查询到可计算运营成本的SKU");
} }
//查询sku的供应商 Set<Integer> providerIds = skuList.stream().map(UpgradeGoodsDTO::getProviderId).filter(Objects::nonNull).collect(Collectors.toSet());
List<UpgradeGoodsProviderRef> providerRefs = upgradeGoodsProviderRefService.findByUpgradeGoodsIds(matchedUpgradeGoodsIds); if (CollectionUtils.isEmpty(providerIds)) {
if (CollectionUtils.isEmpty(providerRefs)) {
log.warn("calculateOperationCost no provider, commodityCode={}", request.getCommodityCode()); log.warn("calculateOperationCost no provider, commodityCode={}", request.getCommodityCode());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "当前产品未配置供货商,无法计算运营成本"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "当前产品未配置供货商,无法计算运营成本");
} }
log.info("calculateOperationCost providerIds={}, sku={}", log.info("calculateOperationCost providerIds={}, sku={}",
providerRefs.stream().map(UpgradeGoodsProviderRef::getProviderId).collect(Collectors.toList()), skuList.stream().collect(Collectors.toMap(UpgradeGoods::getId, UpgradeGoods::getOperationCost, (p1, p2) -> p2))); providerIds, skuList.stream().collect(Collectors.toMap(UpgradeGoods::getId, UpgradeGoods::getOperationCost, (p1, p2) -> p2)));
BigDecimal totalCost = skuList.stream() BigDecimal totalCost = skuList.stream()
.map(UpgradeGoodsDTO::getOperationCost) .map(UpgradeGoodsDTO::getOperationCost)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal avgCost = totalCost.divide(BigDecimal.valueOf(providerRefs.size()), 2, RoundingMode.HALF_UP); BigDecimal avgCost = totalCost.divide(BigDecimal.valueOf(providerIds.size()), 2, RoundingMode.HALF_UP);
response.setOperationCost(avgCost); response.setOperationCost(avgCost);
response.setProviderCount(providerRefs.size()); response.setProviderCount(providerIds.size());
response.setSkuCount(skuList.size()); response.setSkuCount(skuList.size());
return response; return response;
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
......
...@@ -82,9 +82,6 @@ public class ProductManagerService { ...@@ -82,9 +82,6 @@ public class ProductManagerService {
@Autowired @Autowired
private GoodsProviderService goodsProviderService; private GoodsProviderService goodsProviderService;
@Autowired
private UpgradeGoodsProviderRefService upgradeGoodsProviderRefService;
public void checkAddOrUpdateProduct(ProductManagerAddOrUpdateDTO record) { public void checkAddOrUpdateProduct(ProductManagerAddOrUpdateDTO record) {
Integer goodsType = record.getGoodsInfo().getGoodsType(); Integer goodsType = record.getGoodsInfo().getGoodsType();
List<Integer> extendedInsuranceTypeIdList = CommonUtil.convert2Integer(env.getProperty("smartcarlife.goodsType.extendedInsurance", "155").split(","));//延保类 List<Integer> extendedInsuranceTypeIdList = CommonUtil.convert2Integer(env.getProperty("smartcarlife.goodsType.extendedInsurance", "155").split(","));//延保类
...@@ -134,9 +131,7 @@ public class ProductManagerService { ...@@ -134,9 +131,7 @@ public class ProductManagerService {
//保存素材 //保存素材
GoodsInfoDTO goodsInfoDTO = record.getGoodsInfo(); GoodsInfoDTO goodsInfoDTO = record.getGoodsInfo();
goodsInfoDTO.setGoodsSource(GoodsSource.DJ.getValue()); goodsInfoDTO.setGoodsSource(GoodsSource.DJ.getValue());
//供应商已迁移至sku goodsInfoService.addGoods(goodsInfoDTO);
goodsInfoDTO.setProviderId(null);
goodsInfoService.addGoods(goodsInfoDTO);
//保存基础、升级商品信息 //保存基础、升级商品信息
record.getUpgradeGoods().setGoodsCode(goodsInfoDTO.getGoodsCode()); record.getUpgradeGoods().setGoodsCode(goodsInfoDTO.getGoodsCode());
record.getUpgradeGoods().setUpdatedBy(record.getUpgradeGoods().getCreatedBy()); record.getUpgradeGoods().setUpdatedBy(record.getUpgradeGoods().getCreatedBy());
...@@ -172,9 +167,8 @@ public class ProductManagerService { ...@@ -172,9 +167,8 @@ public class ProductManagerService {
//保存素材 //保存素材
GoodsInfoDTO goodsInfoDTO = record.getGoodsInfo(); GoodsInfoDTO goodsInfoDTO = record.getGoodsInfo();
// 捕获更新前的旧状态,以便记录包含 SPU 和 Material 信息的完整日志 // 捕获更新前的旧状态,以便记录包含 SPU 和 Material 信息的完整日志
BaseGoodsDTO oldBaseGoods = baseGoodsService.getByBaseGoodsId(record.getUpgradeGoods().getId()); BaseGoodsDTO oldBaseGoods = baseGoodsService.getByBaseGoodsId(record.getUpgradeGoods().getId());
goodsInfoDTO.setProviderId(null); goodsInfoService.updateGoods(goodsInfoDTO);
goodsInfoService.updateGoods(goodsInfoDTO);
//保存基础、升级商品信息 //保存基础、升级商品信息
record.getUpgradeGoods().setGoodsCode(goodsInfoDTO.getGoodsCode()); record.getUpgradeGoods().setGoodsCode(goodsInfoDTO.getGoodsCode());
record.getUpgradeGoods().setUpdatedBy(record.getUpgradeGoods().getCreatedBy()); record.getUpgradeGoods().setUpdatedBy(record.getUpgradeGoods().getCreatedBy());
...@@ -328,29 +322,27 @@ public class ProductManagerService { ...@@ -328,29 +322,27 @@ public class ProductManagerService {
* @param records * @param records
*/ */
private void fillProviderName(List<BaseGoodsDTO> records) { private void fillProviderName(List<BaseGoodsDTO> records) {
List<Integer> upgradeGoodsIds = records.stream() List<Integer> providerIds = records.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(BaseGoodsDTO::getUpgradeGoodsList) .map(BaseGoodsDTO::getGoodsInfo)
.filter(CollectionUtils::isNotEmpty)
.flatMap(List::stream)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(UpgradeGoodsDTO::getId) .map(GoodsInfoDTO::getProviderId)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
if(CollectionUtils.isEmpty(upgradeGoodsIds)){ if (CollUtil.isNotEmpty(providerIds)) {
return; List<GoodsProvider> providers = goodsProviderService.listByIds(providerIds);
} if (CollUtil.isNotEmpty(providers)) {
if (CollUtil.isNotEmpty(upgradeGoodsIds)) { Map<Integer, String> providerNameMap = new HashMap<>();
List<UpgradeGoodsProviderRefDTO> upgradeGoodsProviderRefDTOS = upgradeGoodsProviderRefService.listProviderNamesByUpgradeGoodsIds(upgradeGoodsIds); for (GoodsProvider provider : providers) {
if(CollectionUtils.isNotEmpty(upgradeGoodsProviderRefDTOS)){ if (provider != null && provider.getId() != null) {
Map<Integer, String> goodsProviderMap = upgradeGoodsProviderRefDTOS.stream() providerNameMap.put(provider.getId(), provider.getProviderName());
.collect(Collectors.toMap(UpgradeGoodsProviderRefDTO::getUpgradeGoodsId, UpgradeGoodsProviderRefDTO::getProviderName)); }
}
for (BaseGoodsDTO record : records) { for (BaseGoodsDTO record : records) {
if(CollectionUtils.isNotEmpty(record.getUpgradeGoodsList())){ if (record.getGoodsInfo() != null && record.getGoodsInfo().getProviderId() != null
record.getUpgradeGoodsList().forEach(dto ->{ && providerNameMap.containsKey(record.getGoodsInfo().getProviderId())) {
dto.setProviderName(goodsProviderMap.get(dto.getId())); record.getGoodsInfo().setProviderName(providerNameMap.get(record.getGoodsInfo().getProviderId()));
});
} }
} }
} }
...@@ -389,9 +381,15 @@ public class ProductManagerService { ...@@ -389,9 +381,15 @@ public class ProductManagerService {
Page<BaseGoodsDTO> baseGoodsDTOS = baseGoodsService.spuPage(pagination); Page<BaseGoodsDTO> baseGoodsDTOS = baseGoodsService.spuPage(pagination);
List<BaseGoodsDTO> records = baseGoodsDTOS.getResult(); List<BaseGoodsDTO> records = baseGoodsDTOS.getResult();
if (CollUtil.isNotEmpty(records)) { if (CollUtil.isNotEmpty(records)) {
//查询产品供应商信息
Map<Integer, String> providerNameMap = getIntegerStringMap(records);
//构建buildUpgradeGoodsList //构建buildUpgradeGoodsList
Map<String, List<UpgradeGoodsDTO>> upgradeGoodsDTOSMap = buildUpgradeGoodsList(pagination, records); Map<String, List<UpgradeGoodsDTO>> upgradeGoodsDTOSMap = buildUpgradeGoodsList(pagination, records);
for (BaseGoodsDTO record : records) { for (BaseGoodsDTO record : records) {
if (MapUtil.isNotEmpty(providerNameMap) && providerNameMap.containsKey(record.getGoodsInfo().getProviderId())) {
record.getGoodsInfo().setProviderName(providerNameMap.get(record.getGoodsInfo().getProviderId()));
}
if (MapUtil.isNotEmpty(upgradeGoodsDTOSMap) && upgradeGoodsDTOSMap.containsKey(record.getGoodsCode())) { if (MapUtil.isNotEmpty(upgradeGoodsDTOSMap) && upgradeGoodsDTOSMap.containsKey(record.getGoodsCode())) {
record.setUpgradeGoodsList(upgradeGoodsDTOSMap.get(record.getGoodsCode())); record.setUpgradeGoodsList(upgradeGoodsDTOSMap.get(record.getGoodsCode()));
} }
...@@ -473,7 +471,24 @@ public class ProductManagerService { ...@@ -473,7 +471,24 @@ public class ProductManagerService {
Map<Integer, List<UpgradeGoodsAreaDTO>> areaMap = Map<Integer, List<UpgradeGoodsAreaDTO>> areaMap =
areaList.stream().collect(Collectors.groupingBy(UpgradeGoodsArea::getUpgradeGoodsId)); areaList.stream().collect(Collectors.groupingBy(UpgradeGoodsArea::getUpgradeGoodsId));
// 批量查询供应商名称
List<Integer> providerIds = records.stream()
.map(GoodsSkuDTO::getProviderId)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
Map<Integer, String> providerNameMap = new java.util.HashMap<>();
if (CollUtil.isNotEmpty(providerIds)) {
List<GoodsProvider> providers = goodsProviderService.listByIds(providerIds);
if (CollUtil.isNotEmpty(providers)) {
providerNameMap = providers.stream().collect(Collectors.toMap(GoodsProvider::getId, GoodsProvider::getProviderName));
}
}
for (GoodsSkuDTO record : records) { for (GoodsSkuDTO record : records) {
if (record.getProviderId() != null && MapUtil.isNotEmpty(providerNameMap) && providerNameMap.containsKey(record.getProviderId())) {
record.setProviderName(providerNameMap.get(record.getProviderId()));
}
if (record.getUpgradeGoodsId() != null && MapUtil.isNotEmpty(carTypeMap) && carTypeMap.containsKey(record.getUpgradeGoodsId())) { if (record.getUpgradeGoodsId() != null && MapUtil.isNotEmpty(carTypeMap) && carTypeMap.containsKey(record.getUpgradeGoodsId())) {
record.setCarTypeConfigList(carTypeMap.get(record.getUpgradeGoodsId())); record.setCarTypeConfigList(carTypeMap.get(record.getUpgradeGoodsId()));
} }
...@@ -600,8 +615,7 @@ public class ProductManagerService { ...@@ -600,8 +615,7 @@ public class ProductManagerService {
goodsInfoDTO.setSupplierName("广联直营"); goodsInfoDTO.setSupplierName("广联直营");
goodsInfoDTO.setThumbUrl(env.getProperty("partner.goods.default.img")); goodsInfoDTO.setThumbUrl(env.getProperty("partner.goods.default.img"));
goodsInfoDTO.setGoodsSource(GoodsSource.DJ.getValue()); goodsInfoDTO.setGoodsSource(GoodsSource.DJ.getValue());
goodsInfoDTO.setProviderId(null);
goods.setShoppingMallFlag((byte)0); goods.setShoppingMallFlag((byte)0);
} }
goodsInfoDTO.setGoodsName(scrmRecord.getGoodsName()); goodsInfoDTO.setGoodsName(scrmRecord.getGoodsName());
......
package cn.com.glsx.dj.smartcarlife.service.goods;
import cn.com.glsx.dj.smartcarlife.dto.goods.UpgradeGoodsProviderRefDTO;
import cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsProviderRefMapper;
import cn.com.glsx.dj.smartcarlife.model.UpgradeGoodsProviderRef;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = RpcServiceException.class)
public class UpgradeGoodsProviderRefService {
@Autowired
private UpgradeGoodsProviderRefMapper upgradeGoodsProviderRefMapper;
public void deleteByUpgradeGoodsId(Integer upgradeGoodsId) {
if(Objects.isNull(upgradeGoodsId)){
return;
}
upgradeGoodsProviderRefMapper.deleteByUpgradeGoodsId(upgradeGoodsId);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public void saveProviderRefs(Integer upgradeGoodsId, List<Integer> providerIds, String operator,boolean isNew) {
RpcAssert.assertNotEmpty(providerIds, DefaultErrorEnum.DATA_NULL, "providerIds list not null");
RpcAssert.assertNotNull(upgradeGoodsId, DefaultErrorEnum.DATA_NULL, "upgradeGoodsId list not null");
if(!isNew){
List<UpgradeGoodsProviderRef> refs = upgradeGoodsProviderRefMapper.findByUpgradeGoodsId(upgradeGoodsId);
Set<Integer> existingSet = new HashSet<>();
if (CollectionUtils.isNotEmpty(refs)) {
existingSet = refs.stream().map(UpgradeGoodsProviderRef::getProviderId).collect(Collectors.toSet());
}
Set<Integer> newSet = new HashSet<>(providerIds);
if (existingSet.equals(newSet)) {
return;
}
upgradeGoodsProviderRefMapper.deleteByUpgradeGoodsId(upgradeGoodsId);
}
// 2. 批量插入新关联
List<UpgradeGoodsProviderRef> refs =new ArrayList<>();
Date now = new Date();
for (Integer providerId : providerIds) {
UpgradeGoodsProviderRef ref = UpgradeGoodsProviderRef.builder()
.upgradeGoodsId(upgradeGoodsId)
.providerId(providerId)
.createdBy(operator)
.createdDate(now)
.updatedBy(operator)
.updatedDate(now)
.deletedFlag("N")
.build();
refs.add(ref);
}
upgradeGoodsProviderRefMapper.insertList(refs);
}
/**
* 批量查询sku关联供应商
* @param upgradeGoodsIds
* @return
*/
public List<UpgradeGoodsProviderRef> findByUpgradeGoodsIds(List<Integer> upgradeGoodsIds) {
return upgradeGoodsProviderRefMapper.findByUpgradeGoodsIds(upgradeGoodsIds);
}
/**
* 批量查询sku关联供应商名称
* @param upgradeGoodsIds
* @return
*/
public List<UpgradeGoodsProviderRefDTO> listProviderNamesByUpgradeGoodsIds(List<Integer> upgradeGoodsIds){
if(CollectionUtils.isEmpty(upgradeGoodsIds)){
return new ArrayList<>();
}
return upgradeGoodsProviderRefMapper.listProviderNamesByUpgradeGoodsIds(upgradeGoodsIds);
}
/**
* 批量查询sku关联供应商名称
* @param upgradeGoodsId
* @return
*/
public UpgradeGoodsProviderRefDTO findProviderNameByUpgradeGoodsId(Integer upgradeGoodsId){
if(Objects.isNull(upgradeGoodsId)){
return new UpgradeGoodsProviderRefDTO();
}
return upgradeGoodsProviderRefMapper.findProviderNameByUpgradeGoodsId(upgradeGoodsId);
}
}
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
<result column="scrm_flag" property="scrmFlag"/> <result column="scrm_flag" property="scrmFlag"/>
<result column="scrm_service_code" property="scrmServiceCode"/> <result column="scrm_service_code" property="scrmServiceCode"/>
<result column="provider_id" property="providerId"/> <result column="provider_id" property="providerId"/>
<result column="provider_name" property="providerName" />
<result column="accessory_type" property="accessoryType"/> <result column="accessory_type" property="accessoryType"/>
</association> </association>
<collection property="upgradeGoodsList" javaType="java.util.List" ofType="cn.com.glsx.dj.smartcarlife.dto.UpgradeGoodsDTO"> <collection property="upgradeGoodsList" javaType="java.util.List" ofType="cn.com.glsx.dj.smartcarlife.dto.UpgradeGoodsDTO">
...@@ -163,6 +164,7 @@ ...@@ -163,6 +164,7 @@
<result column="brandMerchantCode" property="brandMerchantCode"/> <result column="brandMerchantCode" property="brandMerchantCode"/>
<result column="brandMerchantName" property="brandMerchantName"/> <result column="brandMerchantName" property="brandMerchantName"/>
<result column="accessoryType" property="accessoryType"/> <result column="accessoryType" property="accessoryType"/>
<result column="providerId" property="providerId"/>
</association> </association>
</resultMap> </resultMap>
...@@ -245,9 +247,11 @@ ...@@ -245,9 +247,11 @@
gi.scrm_flag, gi.scrm_flag,
gi.scrm_service_code, gi.scrm_service_code,
gi.accessory_type, gi.accessory_type,
gp.provider_name,
bg.specification_type bg.specification_type
from dj_car_life_base_goods bg from dj_car_life_base_goods bg
left join dj_car_life_goods_info gi on gi.goods_code = bg.goods_code and gi.deleted_flag = 'N' left join dj_car_life_goods_info gi on gi.goods_code = bg.goods_code and gi.deleted_flag = 'N'
left join dj_car_life_goods_provider gp on gp.id = gi.provider_id
where bg.id = #{id} where bg.id = #{id}
and bg.deleted_flag = 'N' and bg.deleted_flag = 'N'
</select> </select>
...@@ -708,7 +712,7 @@ ...@@ -708,7 +712,7 @@
a.warning_value as warningValue, a.warning_value as warningValue,
a.warning_value_max as warningValueMax, a.warning_value_max as warningValueMax,
GROUP_CONCAT(d.series_name SEPARATOR '/') as carTypeStr, GROUP_CONCAT(d.series_name SEPARATOR '/') as carTypeStr,
GROUP_CONCAT(distinct gp.provider_name SEPARATOR '/') as providerName, c.provider_id as providerId,
a.created_date as createdDate, a.created_date as createdDate,
a.updated_date as updatedDate, a.updated_date as updatedDate,
b.specification_type AS specificationType, b.specification_type AS specificationType,
...@@ -717,8 +721,6 @@ ...@@ -717,8 +721,6 @@
from dj_car_life_upgrade_goods a from dj_car_life_upgrade_goods a
left join dj_car_life_base_goods b on a.goods_code = b.goods_code and b.deleted_flag = 'N' left join dj_car_life_base_goods b on a.goods_code = b.goods_code and b.deleted_flag = 'N'
left join dj_car_life_goods_info c on c.goods_code = a.goods_code and c.deleted_flag = 'N' left join dj_car_life_goods_info c on c.goods_code = a.goods_code and c.deleted_flag = 'N'
left join dj_car_life_upgrade_goods_provider_ref ugpr on ugpr.upgrade_goods_id = a.id and ugpr.deleted_flag = 'N'
left join dj_car_life_goods_provider gp on gp.id = ugpr.provider_id and gp.deleted_flag = 'N'
left join dj_car_life_upgrade_goods_car_type_config d on d.deleted_flag = 'N' left join dj_car_life_upgrade_goods_car_type_config d on d.deleted_flag = 'N'
and d.upgrade_goods_id = a.id and d.upgrade_goods_id = a.id
and d.deleted_flag = 'N' and d.deleted_flag = 'N'
...@@ -810,6 +812,7 @@ ...@@ -810,6 +812,7 @@
b.brand_merchant_name as brandMerchantName, b.brand_merchant_name as brandMerchantName,
IF(a.specification_type = 2, CONCAT('X', a.upgrade_goods_num), '-') as spuSpecificationData, IF(a.specification_type = 2, CONCAT('X', a.upgrade_goods_num), '-') as spuSpecificationData,
b.accessory_type as accessoryType, b.accessory_type as accessoryType,
b.provider_id as providerId,
CASE CASE
WHEN price.min_price IS NULL OR price.max_price IS NULL THEN '0' WHEN price.min_price IS NULL OR price.max_price IS NULL THEN '0'
WHEN price.min_price = price.max_price THEN CAST(price.min_price AS CHAR) WHEN price.min_price = price.max_price THEN CAST(price.min_price AS CHAR)
......
...@@ -56,8 +56,7 @@ ...@@ -56,8 +56,7 @@
GROUP_CONCAT(distinct gp.provider_name SEPARATOR "/") as providerNames GROUP_CONCAT(distinct gp.provider_name SEPARATOR "/") as providerNames
from dj_car_life_upgrade_goods ug from dj_car_life_upgrade_goods ug
left join dj_car_life_goods_info gi on gi.goods_code=ug.goods_code left join dj_car_life_goods_info gi on gi.goods_code=ug.goods_code
left join dj_car_life_upgrade_goods_provider_ref ugpr on ugpr.upgrade_goods_id=ug.id and ugpr.deleted_flag='N' left join dj_car_life_goods_provider gp on gp.id=gi.provider_id and gp.deleted_flag='N'
left join dj_car_life_goods_provider gp on gp.id=ugpr.provider_id and gp.deleted_flag='N'
<where> <where>
ug.deleted_flag='N' and gi.deleted_flag='N' ug.deleted_flag='N' and gi.deleted_flag='N'
and ug.product_template_id in and ug.product_template_id in
......
...@@ -91,7 +91,6 @@ ...@@ -91,7 +91,6 @@
<result column="totalCount" property="totalCount"/> <result column="totalCount" property="totalCount"/>
<result column="suit_car_type" property="suitCarType"/> <result column="suit_car_type" property="suitCarType"/>
<result column="accessory_type" property="accessoryType"/> <result column="accessory_type" property="accessoryType"/>
<result column="provider_name" property="providerName"/>
<association javaType="cn.com.glsx.dj.smartcarlife.model.GoodsInfo" property="goodsInfo"> <association javaType="cn.com.glsx.dj.smartcarlife.model.GoodsInfo" property="goodsInfo">
<result column="merchant_id" jdbcType="INTEGER" property="merchantId" /> <result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
<result column="goods_name" jdbcType="VARCHAR" property="goodsName" /> <result column="goods_name" jdbcType="VARCHAR" property="goodsName" />
...@@ -650,12 +649,9 @@ ...@@ -650,12 +649,9 @@
'升级' as attribute, '升级' as attribute,
gi.converted_value, gi.converted_value,
gi.accessory_type, gi.accessory_type,
DATE_FORMAT(ug.created_date, '%Y-%m-%d %H:%i:%s') as createDateStr, DATE_FORMAT(ug.created_date, '%Y-%m-%d %H:%i:%s') as createDateStr
GROUP_CONCAT(gp.provider_name SEPARATOR '/') as provider_name
from dj_car_life_upgrade_goods ug from dj_car_life_upgrade_goods ug
left join dj_car_life_goods_info gi on gi.goods_code = ug.goods_code and gi.deleted_flag = 'N' left join dj_car_life_goods_info gi on gi.goods_code = ug.goods_code and gi.deleted_flag = 'N'
left join dj_car_life_upgrade_goods_provider_ref ugpr on ugpr.upgrade_goods_id = ug.id and ugpr.deleted_flag = 'N'
left join dj_car_life_goods_provider gp on gp.id = ugpr.provider_id and gp.deleted_flag = 'N'
where ug.base_goods_id = #{id} where ug.base_goods_id = #{id}
and ug.deleted_flag='N' and ug.deleted_flag='N'
<if test="skuKey != null and skuKey != ''"> <if test="skuKey != null and skuKey != ''">
...@@ -1052,13 +1048,10 @@ ...@@ -1052,13 +1048,10 @@
</select> </select>
<select id="listByGoodsCode" resultMap="skuDTOResultMap"> <select id="listByGoodsCode" resultMap="skuDTOResultMap">
SELECT a.*, SELECT a.*
GROUP_CONCAT(distinct gp.provider_name SEPARATOR '/') as provider_name
FROM dj_car_life_upgrade_goods a FROM dj_car_life_upgrade_goods a
LEFT JOIN dj_car_life_base_goods b ON a.goods_code = b.goods_code AND b.deleted_flag = 'N' LEFT JOIN dj_car_life_base_goods b ON a.goods_code = b.goods_code AND b.deleted_flag = 'N'
LEFT JOIN dj_car_life_goods_info c ON c.goods_code = a.goods_code AND c.deleted_flag = 'N' LEFT JOIN dj_car_life_goods_info c ON c.goods_code = a.goods_code AND c.deleted_flag = 'N'
left join dj_car_life_upgrade_goods_provider_ref ugpr on ugpr.upgrade_goods_id = a.id and ugpr.deleted_flag = 'N'
left join dj_car_life_goods_provider gp on gp.id = ugpr.provider_id and gp.deleted_flag = 'N'
WHERE a.deleted_flag = 'N' WHERE a.deleted_flag = 'N'
and b.deleted_flag = 'N' and b.deleted_flag = 'N'
and c.deleted_flag = 'N' and c.deleted_flag = 'N'
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.com.glsx.dj.smartcarlife.mapper.UpgradeGoodsProviderRefMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.smartcarlife.model.UpgradeGoodsProviderRef" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="upgrade_goods_id" property="upgradeGoodsId" jdbcType="INTEGER" />
<result column="provider_id" property="providerId" jdbcType="INTEGER" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP" />
<result column="deleted_flag" property="deletedFlag" jdbcType="CHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, upgrade_goods_id, provider_id, created_by, created_date, updated_by, updated_date, deleted_flag
</sql>
<select id="findByUpgradeGoodsId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from dj_car_life_upgrade_goods_provider_ref
where deleted_flag = 'N' and upgrade_goods_id = #{upgradeGoodsId}
</select>
<select id="findByUpgradeGoodsIds" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from dj_car_life_upgrade_goods_provider_ref
where deleted_flag = 'N'
and upgrade_goods_id in
<foreach item="item" collection="upgradeGoodsIds" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</select>
<select id="listProviderIdsByUpgradeGoodsIds" resultMap="BaseResultMap">
select upgrade_goods_id, provider_id
from dj_car_life_upgrade_goods_provider_ref
where deleted_flag = 'N'
and upgrade_goods_id in
<foreach item="item" collection="upgradeGoodsIds" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</select>
<select id="listProviderNamesByUpgradeGoodsIds" resultType="cn.com.glsx.dj.smartcarlife.dto.goods.UpgradeGoodsProviderRefDTO">
select
ugpr.upgrade_goods_id AS upgradeGoodsId,
GROUP_CONCAT(distinct gp.provider_name SEPARATOR '/') as providerName
from
dj_car_life_upgrade_goods_provider_ref ugpr
left join dj_car_life_goods_provider gp on gp.id = ugpr.provider_id and gp.deleted_flag = 'N'
where ugpr.deleted_flag = 'N'
and ugpr.upgrade_goods_id in
<foreach item="item" collection="upgradeGoodsIds" index="index" separator="," open="(" close=")">
#{item}
</foreach>
group by ugpr.upgrade_goods_id
</select>
<select id="findProviderNameByUpgradeGoodsId" resultType="cn.com.glsx.dj.smartcarlife.dto.goods.UpgradeGoodsProviderRefDTO">
select
ugpr.upgrade_goods_id AS upgradeGoodsId,
GROUP_CONCAT(distinct gp.provider_name SEPARATOR '/') as providerName
from
dj_car_life_upgrade_goods_provider_ref ugpr
left join dj_car_life_goods_provider gp on gp.id = ugpr.provider_id and gp.deleted_flag = 'N'
where ugpr.deleted_flag = 'N'
and ugpr.upgrade_goods_id = #{upgradeGoodsId}
</select>
<update id="deleteByUpgradeGoodsId">
update dj_car_life_upgrade_goods_provider_ref
set deleted_flag = 'D'
where upgrade_goods_id = #{upgradeGoodsId} and deleted_flag = 'N'
</update>
</mapper>
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(Top 3)

    1. 违反重要规则:Dubbo Remote 接口 API 被破坏性修改(危险实现)

    • 问题描述:在 rpc-dj-smartcarlife-api 模块下的 MerchantGoodsStockReduceRecordDTO 和 UpgradeGoodsDTO 中,直接删除了已有的字段(如 successDate、providerIds、providerNameList)。
    • 影响分析:根据审查核心规则,Dubbo 服务提供者 Remote 接口中的已有请求参数变更视为危险实现。直接删除 API 包中的 DTO 字段会导致强烈的向后兼容性问题。如果消费者(其他微服务或前端 BFF 层)未同步更新 JAR 包或仍在传递这些字段,将会导致反序列化异常或业务逻辑断裂,引发线上故障。
    • 优化建议:对于需要废弃的字段,应使用 @Deprecated 注解进行标记,并在注释中说明废弃原因及替代方案,保留字段声明而不是直接物理删除。 java // 建议保留并标记废弃,而不是直接删除 @ApiModelProperty(notes = "供应商ID列表(已废弃)") @Deprecated private List<Integer> providerIds;

    2. 核心业务逻辑错误:运营成本计算公式存在严重缺陷

    • 问题描述:在 MerchantGoodsInfoService.java 的 calculateOperationCost 方法中,计算平均成本时使用了去重后的供应商数量(providerIds.size())作为除数。 java Set<Integer> providerIds = skuList.stream().map(UpgradeGoodsDTO::getProviderId).filter(Objects::nonNull).collect(Collectors.toSet()); BigDecimal totalCost = skuList.stream().map(UpgradeGoodsDTO::getOperationCost)...reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal avgCost = totalCost.divide(BigDecimal.valueOf(providerIds.size()), 2, RoundingMode.HALF_UP);
    • 影响分析:totalCost 是所有 SKU 运营成本的总和。如果传入的多个 SKU 属于同一个供应商,由于 providerIds 是 Set 集合,去重后 providerIds.size() 将变为 1。这会导致 avgCost 直接等于所有 SKU 的总成本,而不是平均成本,造成严重的财务/价格数据计算错误。
    • 优化建议:应根据实际业务需求,除以参与计算的 SKU 数量,或者在保证各 SKU 供应商不重复的前提下进行计算。合理推测应除以 skuList.size()。 java // 建议修改为除以参与计算的 SKU 数量 BigDecimal avgCost = totalCost.divide(BigDecimal.valueOf(skuList.size()), 2, RoundingMode.HALF_UP);

    3. 代码健壮性隐患:存在潜在的 NullPointerException

    • 问题描述:在 ProductManagerService.java 的 spuPage 方法中,遍历 records 赋值时,未对 record.getGoodsInfo() 进行判空保护,直接调用了 getProviderId()。 java for (BaseGoodsDTO record : records) { if (MapUtil.isNotEmpty(providerNameMap) && providerNameMap.containsKey(record.getGoodsInfo().getProviderId())) { record.getGoodsInfo().setProviderName(providerNameMap.get(record.getGoodsInfo().getProviderId())); } // ... }
    • 影响分析:在同类的 fillProviderName 方法中,开发者使用了 .filter(Objects::nonNull).map(BaseGoodsDTO::getGoodsInfo),说明 getGoodsInfo() 是有可能为 null 的。此处直接链式调用极易引发 NullPointerException,导致分页查询接口整体崩溃。
    • 优化建议:增加对象级别的判空保护。 java for (BaseGoodsDTO record : records) { if (record.getGoodsInfo() != null && MapUtil.isNotEmpty(providerNameMap) && providerNameMap.containsKey(record.getGoodsInfo().getProviderId())) { record.getGoodsInfo().setProviderName(providerNameMap.get(record.getGoodsInfo().getProviderId())); } }

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分):扣分较多。虽然代码主要目的是回滚(Revert)之前的特性,但回滚过程中在 MerchantGoodsInfoService 引入了严重的数学计算逻辑错误;同时遗留了明显的 NPE 隐患,边界条件处理不够严谨。
    • 安全性与潜在风险(30/30分):未发现 SQL 注入、越权等典型的系统安全漏洞。SQL 变更主要为表连接调整,符合“禁止使用子查询”的规范要求。
    • 最佳实践与可维护性(10/20分):违反了微服务 API 接口强兼容的核心最佳实践。对外暴露的 DTO 字段被直接删除,未采用平滑过渡的废弃(@Deprecated)策略,给调用方带来极大风险。
    • 性能与资源利用(4/5分):去除了原有的多对多关系表(upgrade_goods_provider_ref),简化了 SQL 的 Join 逻辑,对数据库查询性能有微小的正面提升。但在 Java 内存中进行的多次流式(Stream)处理和映射操作仍有略微优化的空间。
    • 提交信息质量(4/5分):Commit Message 清晰地标明了这是一个 Revert 操作,并附带了原提交的信息,具备可追溯性。但若能简要补充“为何回滚(如:业务需求变更或发现重大缺陷)”会更加完美。

    总分:68分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!