记得上下班打卡 | git大法好,push需谨慎

Commit ee537f0b authored by 姜秀龙's avatar 姜秀龙

收钱 goods add edit

parent 3a8884fc
...@@ -10,7 +10,6 @@ import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQ ...@@ -10,7 +10,6 @@ import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQ
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
...@@ -125,11 +124,8 @@ public class GoblinStoreMgtGoodsSqbAddParam implements Serializable { ...@@ -125,11 +124,8 @@ public class GoblinStoreMgtGoodsSqbAddParam implements Serializable {
public GoblinGoodsInfoVo initGoodsInfoVo(String storeId, GoblinSqbPerfGoodsVo sqbGoods, String currentUid, LocalDateTime nowTime) { public GoblinGoodsInfoVo initGoodsInfoVo(String storeId, GoblinSqbPerfGoodsVo sqbGoods, String currentUid, LocalDateTime nowTime) {
GoblinGoodsInfoVo vo = GoblinGoodsInfoVo.getNew(); GoblinGoodsInfoVo vo = GoblinGoodsInfoVo.getNew();
vo.setStoreId(storeId); vo.setStoreId(storeId);
if (StringUtils.isBlank(sqbGoods.getSpuId())) { // 主表使用系统ID,收钱吧ID仅通过`goblin_sqb_goods_ext`映射
vo.setSpuId(IDGenerator.nextMilliId2()); vo.setSpuId(IDGenerator.nextMilliId2());
} else {
vo.setSpuId(sqbGoods.getSpuId());
}
vo.setSpuNo(vo.getSpuId()); vo.setSpuNo(vo.getSpuId());
vo.setSpuType(33); vo.setSpuType(33);
vo.setName(sqbGoods.getTitle()); vo.setName(sqbGoods.getTitle());
...@@ -182,13 +178,18 @@ public class GoblinStoreMgtGoodsSqbAddParam implements Serializable { ...@@ -182,13 +178,18 @@ public class GoblinStoreMgtGoodsSqbAddParam implements Serializable {
public void initGoodsSkuInfoVo(GoblinGoodsInfoVo goodsInfoVo, List<GoblinGoodsSkuInfoVo> skuInfoVos, public void initGoodsSkuInfoVo(GoblinGoodsInfoVo goodsInfoVo, List<GoblinGoodsSkuInfoVo> skuInfoVos,
List<GoblinGoodsSpecVo> goodsSpecVos, GoblinSqbPerfGoodsVo sqbGoods) { List<GoblinGoodsSpecVo> goodsSpecVos, GoblinSqbPerfGoodsVo sqbGoods) {
List<MallProductsQueryData.Sku> addSkuParamSqb = sqbGoods.getSkuResults(); List<MallProductsQueryData.Sku> addSkuParamSqb = sqbGoods.getSkuResults();
if (CollectionUtil.isEmpty(addSkuParamSqb)) {
addSkuParamSqb = new ArrayList<>();
}
List<String> skuIdList = CollectionUtil.arrayListString(); List<String> skuIdList = CollectionUtil.arrayListString();
for (MallProductsQueryData.Sku sku : addSkuParamSqb) { for (MallProductsQueryData.Sku sku : addSkuParamSqb) {
GoblinGoodsSkuInfoVo skuInfoVo = GoblinGoodsSkuInfoVo.getNew(); GoblinGoodsSkuInfoVo skuInfoVo = GoblinGoodsSkuInfoVo.getNew();
String systemSkuId = IDGenerator.nextMilliId2();
skuInfoVo.setSpuId(goodsInfoVo.getSpuId()); skuInfoVo.setSpuId(goodsInfoVo.getSpuId());
skuInfoVo.setSkuId(sku.getSkuId()); // 主表使用系统SKU_ID,收钱吧SKU_ID仅通过`goblin_sqb_goods_ext`映射
skuInfoVo.setSkuNo(sku.getSkuId()); skuInfoVo.setSkuId(systemSkuId);
skuInfoVo.setSkuBarCode(sku.getSkuId()); skuInfoVo.setSkuNo(systemSkuId);
skuInfoVo.setSkuBarCode(systemSkuId);
skuInfoVo.setSkuType(33); skuInfoVo.setSkuType(33);
skuInfoVo.setName(sku.getSkuName()); skuInfoVo.setName(sku.getSkuName());
skuInfoVo.setSubtitle(""); skuInfoVo.setSubtitle("");
...@@ -223,7 +224,7 @@ public class GoblinStoreMgtGoodsSqbAddParam implements Serializable { ...@@ -223,7 +224,7 @@ public class GoblinStoreMgtGoodsSqbAddParam implements Serializable {
skuSpecList.add(goblinGoodsSpecDto); skuSpecList.add(goblinGoodsSpecDto);
skuInfoVo.setSkuSpecList(skuSpecList); skuInfoVo.setSkuSpecList(skuSpecList);
} }
skuIdList.add(skuInfoVo.getSkuId()); skuIdList.add(systemSkuId);
skuInfoVos.add(skuInfoVo); skuInfoVos.add(skuInfoVo);
} }
......
package com.liquidnet.service.goblin.controller.manage; package com.liquidnet.service.goblin.controller.manage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.commons.lang.util.CurrentUtil; import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ErrorMapping; import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbAddParam; import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbAddParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbAddSkuParam; import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbEditSkuParam; import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.dto.vo.*; import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSpecVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSqbPerfGoodsVo;
import com.liquidnet.service.goblin.entity.GoblinSqbGoodsExt;
import com.liquidnet.service.goblin.mapper.GoblinSqbGoodsExtMapper;
import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQueryData; import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQueryData;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService; import com.liquidnet.service.goblin.service.IGoblinShouQianBaService;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtSqbGoodsService; import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtSqbGoodsService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils;
import com.liquidnet.service.goblin.util.GoblinRedisUtils; import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil; import com.liquidnet.service.goblin.util.ObjectUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -25,13 +25,19 @@ import org.apache.commons.lang3.StringUtils; ...@@ -25,13 +25,19 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Map;
/** /**
* 收钱吧商品管理 * 收钱吧商品管理
...@@ -46,57 +52,188 @@ public class GoblinStoreMgtSqbGoodsController { ...@@ -46,57 +52,188 @@ public class GoblinStoreMgtSqbGoodsController {
@Autowired @Autowired
private IGoblinStoreMgtSqbGoodsService goblinstoreMgtSqbGoodsService; private IGoblinStoreMgtSqbGoodsService goblinstoreMgtSqbGoodsService;
@Autowired @Autowired
private IGoblinStoreMgtExtraService goblinStoreMgtExtraService;
@Autowired
private GoblinRedisUtils goblinRedisUtils; private GoblinRedisUtils goblinRedisUtils;
@Autowired @Autowired
private GoblinMongoUtils goblinMongoUtils; private GoblinSqbGoodsExtMapper goblinSqbGoodsExtMapper;
@Autowired
private IGoblinShouQianBaService goblinShouQianBaService;
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@ApiOperation(value = "SPU添加-收钱吧商品") @ApiOperation(value = "SPU添加-收钱吧商品(批量)")
@PostMapping("add") @PostMapping("add")
public ResponseDto<Object> add(@RequestParam("storeId") String storeId, public ResponseDto<Object> add(@RequestParam("storeId") String storeId,
@RequestBody @Validated List<GoblinSqbPerfGoodsVo> items) { @RequestBody @Validated List<GoblinSqbPerfGoodsVo> items) {
String currentUid = CurrentUtil.getCurrentUid(); String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) return ResponseDto.failure(ErrorMapping.get("149002")); if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (CollectionUtils.isEmpty(items)) {
return ResponseDto.success(buildAddResult(0, 0, 0));
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("收钱吧商品管理:添加:[items={}]", JsonUtils.toJson(items)); log.debug("收钱吧商品管理:批量添加:[items={}]", JsonUtils.toJson(items));
} }
int addSuccess = 0, alreadyExists = 0, addFail = 0;
for (GoblinSqbPerfGoodsVo sqbGoods : items) { for (GoblinSqbPerfGoodsVo sqbGoods : items) {
GoblinStoreMgtGoodsSqbAddParam mgtGoodsSqbAddParamNew = new GoblinStoreMgtGoodsSqbAddParam(); if (sqbGoods == null || StringUtils.isBlank(sqbGoods.getSpuId()) || StringUtils.isBlank(sqbGoods.getMallSn())) {
GoblinGoodsInfoVo goodsInfoVo = mgtGoodsSqbAddParamNew.initGoodsInfoVo(storeId, sqbGoods, currentUid, LocalDateTime.now()); addFail++;
continue;
ArrayList<GoblinGoodsSpecVo> goodsSpecVoList = ObjectUtil.getGoblinGoodsSpecVoArrayList(); }
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList(); if (existsSqbSpu(sqbGoods.getMallSn(), sqbGoods.getSpuId())) {
mgtGoodsSqbAddParamNew.initGoodsSkuInfoVo(goodsInfoVo, goodsSkuInfoVoList, goodsSpecVoList, sqbGoods); alreadyExists++;
continue;
goodsInfoVo.setTagVoList(new ArrayList<>()); }
goodsInfoVo.setExtagVoList(new ArrayList<>()); try {
goodsInfoVo.setArtagVoList(new ArrayList<>()); GoblinStoreMgtGoodsSqbAddParam initParam = new GoblinStoreMgtGoodsSqbAddParam();
goodsInfoVo.setServiceSupportVoList(new ArrayList<>()); GoblinGoodsInfoVo goodsInfoVo = initParam.initGoodsInfoVo(storeId, sqbGoods, currentUid, LocalDateTime.now());
goblinstoreMgtSqbGoodsService.sqbGoodsAdd(goodsInfoVo, goodsSkuInfoVoList);
ArrayList<GoblinGoodsSpecVo> goodsSpecVoList = ObjectUtil.getGoblinGoodsSpecVoArrayList();
List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList = ObjectUtil.getGoblinGoodsSkuInfoVoArrayList();
initParam.initGoodsSkuInfoVo(goodsInfoVo, goodsSkuInfoVoList, goodsSpecVoList, sqbGoods);
goodsInfoVo.setTagVoList(new ArrayList<>());
goodsInfoVo.setExtagVoList(new ArrayList<>());
goodsInfoVo.setArtagVoList(new ArrayList<>());
goodsInfoVo.setServiceSupportVoList(new ArrayList<>());
goblinstoreMgtSqbGoodsService.sqbGoodsAdd(goodsInfoVo, goodsSkuInfoVoList);
saveSqbExtRelations(goodsInfoVo, sqbGoods);
addSuccess++;
} catch (Exception e) {
addFail++;
log.error("收钱吧商品管理:批量添加失败, storeId={}, sqbSpuId={}", storeId, sqbGoods.getSpuId(), e);
}
} }
return ResponseDto.success(); return ResponseDto.success(buildAddResult(addSuccess, alreadyExists, addFail));
} }
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "商品编辑:SPU编辑-收钱吧商品", notes = "只修改商品信息,不包含价格库存相关信息") @ApiOperation(value = "商品编辑:SPU编辑-收钱吧商品(批量,传系统spuId)")
@PutMapping("edit_spu") @PutMapping("edit_spu")
public ResponseDto<Object> editSpu(@RequestParam("storeId") String storeId, public ResponseDto<Object> editSpu(@RequestParam("storeId") String storeId,
@RequestBody @Validated List<GoblinSqbPerfGoodsVo> items) { @RequestBody @Validated List<String> localSpuIds) {
String currentUid = CurrentUtil.getCurrentUid(); String currentUid = CurrentUtil.getCurrentUid();
if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) return ResponseDto.failure(ErrorMapping.get("149002")); if (!goblinRedisUtils.hasStoreId(currentUid, storeId)) {
return ResponseDto.failure(ErrorMapping.get("149002"));
}
if (CollectionUtils.isEmpty(localSpuIds)) {
return ResponseDto.success(buildEditResult(0, 0, 0, 0));
}
if (log.isDebugEnabled()) { int editSuccess = 0, notAdded = 0, sqbNotFound = 0, editFail = 0;
log.debug("收钱吧商品管理:商品编辑:SPU编辑:[GoblinStoreMgtGoodsSqbAddParam={}]", JsonUtils.toJson(items)); for (String localSpuId : localSpuIds) {
if (StringUtils.isBlank(localSpuId)) {
editFail++;
continue;
}
List<GoblinSqbGoodsExt> extList = goblinSqbGoodsExtMapper.selectList(new LambdaQueryWrapper<GoblinSqbGoodsExt>()
.eq(GoblinSqbGoodsExt::getSpuId, localSpuId)
.eq(GoblinSqbGoodsExt::getDelFlg, "0"));
if (CollectionUtils.isEmpty(extList)) {
notAdded++;
continue;
}
GoblinGoodsInfoVo localGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(localSpuId);
if (localGoodsInfoVo == null) {
notAdded++;
continue;
}
GoblinSqbGoodsExt ext = extList.get(0);
String mallSn = ext.getMallSn();
String sqbSpuId = ext.getSqbSpuId();
String signature = ext.getSignature();
GoblinSqbPerfGoodsVo sqbGoods = fetchSqbGoodsByMallAndSpu(mallSn, sqbSpuId, signature);
if (sqbGoods == null) {
sqbNotFound++;
continue;
}
try {
if (goblinstoreMgtSqbGoodsService.sqbGoodsEditSpu(currentUid, sqbGoods, localGoodsInfoVo)) {
editSuccess++;
} else {
editFail++;
}
} catch (Exception e) {
editFail++;
log.error("收钱吧商品管理:批量编辑失败, storeId={}, localSpuId={}, sqbSpuId={}",
storeId, localSpuId, sqbSpuId, e);
}
} }
return ResponseDto.success(buildEditResult(editSuccess, notAdded, sqbNotFound, editFail));
}
private boolean existsSqbSpu(String mallSn, String sqbSpuId) {
return goblinSqbGoodsExtMapper.selectCount(new LambdaQueryWrapper<GoblinSqbGoodsExt>()
.eq(GoblinSqbGoodsExt::getMallSn, mallSn)
.eq(GoblinSqbGoodsExt::getSqbSpuId, sqbSpuId)
.eq(GoblinSqbGoodsExt::getDelFlg, "0")) > 0;
}
private void saveSqbExtRelations(GoblinGoodsInfoVo goodsInfoVo, GoblinSqbPerfGoodsVo sqbGoods) {
LocalDateTime now = LocalDateTime.now();
List<String> localSkuIds = goodsInfoVo.getSkuIdList() == null ? Collections.emptyList() : goodsInfoVo.getSkuIdList();
List<MallProductsQueryData.Sku> sqbSkus = sqbGoods.getSkuResults() == null ? Collections.emptyList() : sqbGoods.getSkuResults();
int relationSize = Math.max(localSkuIds.size(), sqbSkus.size());
if (relationSize == 0) {
relationSize = 1;
}
for (int i = 0; i < relationSize; i++) {
GoblinSqbGoodsExt ext = new GoblinSqbGoodsExt();
ext.setSpuId(goodsInfoVo.getSpuId());
ext.setSkuId(i < localSkuIds.size() ? localSkuIds.get(i) : null);
ext.setMallSn(sqbGoods.getMallSn());
ext.setSignature(sqbGoods.getSignature());
ext.setSqbSpuId(sqbGoods.getSpuId());
ext.setSqbSkuId(i < sqbSkus.size() ? sqbSkus.get(i).getSkuId() : null);
ext.setDelFlg("0");
ext.setCreatedAt(now);
ext.setUpdatedAt(now);
goblinSqbGoodsExtMapper.insert(ext);
}
}
for (GoblinSqbPerfGoodsVo item : items) { private GoblinSqbPerfGoodsVo fetchSqbGoodsByMallAndSpu(String mallSn, String sqbSpuId, String signature) {
GoblinGoodsInfoVo mgtGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(item.getSpuId()); if (StringUtils.isBlank(mallSn) || StringUtils.isBlank(sqbSpuId) || StringUtils.isBlank(signature)) {
goblinstoreMgtSqbGoodsService.sqbGoodsEditSpu(currentUid, item, mgtGoodsInfoVo); return null;
}
List<MallProductsQueryData> products = goblinShouQianBaService.queryMallProducts(mallSn, signature);
if (CollectionUtils.isEmpty(products)) {
return null;
} }
for (MallProductsQueryData product : products) {
if (sqbSpuId.equals(product.getSpuId())) {
GoblinSqbPerfGoodsVo vo = new GoblinSqbPerfGoodsVo();
vo.setMallSn(mallSn);
vo.setSignature(signature);
vo.setSpuId(product.getSpuId());
vo.setConverImages(product.getConverImages());
vo.setProductIntroduction(product.getProductIntroduction());
vo.setTitle(product.getTitle());
vo.setSkuResults(product.getSkuResults());
return vo;
}
}
return null;
}
return ResponseDto.success(); private Map<String, Integer> buildAddResult(int addSuccess, int alreadyExists, int addFail) {
Map<String, Integer> result = new HashMap<>();
result.put("addSuccess", addSuccess);
result.put("alreadyExists", alreadyExists);
result.put("addFail", addFail);
return result;
} }
private Map<String, Integer> buildEditResult(int editSuccess, int notAdded, int sqbNotFound, int editFail) {
Map<String, Integer> result = new HashMap<>();
result.put("editSuccess", editSuccess);
result.put("notAdded", notAdded);
result.put("sqbNotFound", sqbNotFound);
result.put("editFail", editFail);
return result;
}
} }
package com.liquidnet.service.goblin.service.impl.manage; package com.liquidnet.service.goblin.service.impl.manage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liquidnet.commons.lang.util.CollectionUtil; import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SqlMapping; import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst; import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto; import com.liquidnet.service.goblin.dto.GoblinGoodsSpecDto;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbAddParam; import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbAddParam;
import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtGoodsSqbEditSkuParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo; import com.liquidnet.service.goblin.dto.manage.vo.GoblinMgtCategorySpecVo;
import com.liquidnet.service.goblin.dto.vo.*; import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinSqbGoodsExt;
import com.liquidnet.service.goblin.mapper.GoblinSqbGoodsExtMapper;
import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQueryData; import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQueryData;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtSqbGoodsService; import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtSqbGoodsService;
import com.liquidnet.service.goblin.util.GoblinMongoUtils; import com.liquidnet.service.goblin.util.GoblinMongoUtils;
...@@ -40,6 +41,8 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood ...@@ -40,6 +41,8 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood
GoblinRedisUtils goblinRedisUtils; GoblinRedisUtils goblinRedisUtils;
@Autowired @Autowired
GoblinMongoUtils goblinMongoUtils; GoblinMongoUtils goblinMongoUtils;
@Autowired
GoblinSqbGoodsExtMapper goblinSqbGoodsExtMapper;
public void sqbGoodsAdd(GoblinGoodsInfoVo goodsInfoVo, List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList) { public void sqbGoodsAdd(GoblinGoodsInfoVo goodsInfoVo, List<GoblinGoodsSkuInfoVo> goodsSkuInfoVoList) {
goblinMongoUtils.setGoodsInfoVo(goodsInfoVo); goblinMongoUtils.setGoodsInfoVo(goodsInfoVo);
...@@ -130,7 +133,7 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood ...@@ -130,7 +133,7 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood
toMqSqls.add(SqlMapping.get("goblin_goods_sku.insert_for_coupon")); toMqSqls.add(SqlMapping.get("goblin_goods_sku.insert_for_coupon"));
toMqSqls.add(SqlMapping.get("goblin_goods_image.insert_byreplace")); toMqSqls.add(SqlMapping.get("goblin_goods_image.insert_byreplace"));
LinkedList<Object[]> initGoodsImageObjs = CollectionUtil.linkedListObjectArr(); LinkedList<Object[]> initGoodsImageObjs = CollectionUtil.linkedListObjectArr();
if (CollectionUtils.isEmpty(goodsInfoVo.getImageList())) { if (!CollectionUtils.isEmpty(goodsInfoVo.getImageList())) {
goodsInfoVo.getImageList().forEach(imageUrl -> initGoodsImageObjs.add(new Object[] { spuId, imageUrl })); goodsInfoVo.getImageList().forEach(imageUrl -> initGoodsImageObjs.add(new Object[] { spuId, imageUrl }));
} }
toMqSqls.add(SqlMapping.get("goblin_goods_tag.insert_byreplace")); toMqSqls.add(SqlMapping.get("goblin_goods_tag.insert_byreplace"));
...@@ -185,7 +188,7 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood ...@@ -185,7 +188,7 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood
public boolean sqbGoodsEditSpu(String uid, GoblinSqbPerfGoodsVo mgtGoodsAddParam, public boolean sqbGoodsEditSpu(String uid, GoblinSqbPerfGoodsVo mgtGoodsAddParam,
GoblinGoodsInfoVo mgtGoodsInfoVo) { GoblinGoodsInfoVo mgtGoodsInfoVo) {
String spuId = mgtGoodsAddParam.getSpuId(); String spuId = mgtGoodsInfoVo.getSpuId();
GoblinStoreMgtGoodsSqbAddParam initParam = new GoblinStoreMgtGoodsSqbAddParam(); GoblinStoreMgtGoodsSqbAddParam initParam = new GoblinStoreMgtGoodsSqbAddParam();
GoblinGoodsInfoVo updateSpuInfoVo = initParam.initEditGoodsInfoVo(mgtGoodsAddParam, mgtGoodsInfoVo); GoblinGoodsInfoVo updateSpuInfoVo = initParam.initEditGoodsInfoVo(mgtGoodsAddParam, mgtGoodsInfoVo);
...@@ -257,47 +260,64 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood ...@@ -257,47 +260,64 @@ public class GoblinStoreMgtSqbGoodsServiceImpl implements IGoblinStoreMgtSqbGood
GoblinGoodsInfoVo goodsInfoVo) { GoblinGoodsInfoVo goodsInfoVo) {
LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime nowTime = LocalDateTime.now();
List<MallProductsQueryData.Sku> skuResults = mgtGoodsAddParam.getSkuResults(); List<MallProductsQueryData.Sku> skuResults = mgtGoodsAddParam.getSkuResults();
if (goodsInfoVo == null || CollectionUtils.isEmpty(goodsInfoVo.getSkuIdList())) { if (goodsInfoVo == null || CollectionUtils.isEmpty(goodsInfoVo.getSkuIdList()) || CollectionUtils.isEmpty(skuResults)) {
return false;
}
LambdaQueryWrapper<GoblinSqbGoodsExt> wrapper = new LambdaQueryWrapper<GoblinSqbGoodsExt>()
.eq(GoblinSqbGoodsExt::getSpuId, goodsInfoVo.getSpuId())
.eq(GoblinSqbGoodsExt::getDelFlg, "0");
if (StringUtils.isNotBlank(mgtGoodsAddParam.getMallSn())) {
wrapper.eq(GoblinSqbGoodsExt::getMallSn, mgtGoodsAddParam.getMallSn());
}
List<GoblinSqbGoodsExt> extList = goblinSqbGoodsExtMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(extList)) {
return false; return false;
} }
// 先拿到 spu 下所有 sku 详情,后续只更新命中的 skuId,其余仅参与价格区间重算 Map<String, String> sqbSkuToLocalSkuMap = extList.stream()
for (String spuSkuId : goodsInfoVo.getSkuIdList()) { .filter(ext -> StringUtils.isNotBlank(ext.getSqbSkuId()) && StringUtils.isNotBlank(ext.getSkuId()))
String skuId = spuSkuId; .collect(Collectors.toMap(GoblinSqbGoodsExt::getSqbSkuId, GoblinSqbGoodsExt::getSkuId, (a, b) -> a));
if (StringUtils.isBlank(spuSkuId)) {
boolean updated = false;
LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
for (MallProductsQueryData.Sku sqbSku : skuResults) {
if (sqbSku == null || StringUtils.isBlank(sqbSku.getSkuId())) {
continue;
}
String localSkuId = sqbSkuToLocalSkuMap.get(sqbSku.getSkuId());
if (StringUtils.isBlank(localSkuId)) {
continue; continue;
} }
GoblinGoodsSkuInfoVo skuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(spuSkuId);
if (skuInfoVo != null && "0".equals(skuInfoVo.getDelFlg())) {
for (MallProductsQueryData.Sku sku : skuResults) {
if (sku.getSkuId().equals(spuSkuId)) {
skuInfoVo.setName(sku.getSkuName());
skuInfoVo.setPrice(BigDecimal.valueOf(sku.getPrice()));
skuInfoVo.setUpdatedBy(uid);
skuInfoVo.setUpdatedAt(nowTime);
if (goblinMongoUtils.updateGoodsSkuInfoVo(skuInfoVo)) {
goblinRedisUtils.delGoodsSkuInfoVo(sku.getSkuId());
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_edit_for_coupon"));
LinkedList<Object[]> updateGoodsSkuObjs = CollectionUtil.linkedListObjectArr();
updateGoodsSkuObjs.add(new Object[] {
skuInfoVo.getPrice(), skuInfoVo.getPriceMember(), skuInfoVo.getStock(),
skuInfoVo.getSkuStock(),
skuInfoVo.getBuyLimit(), skuInfoVo.getUpdatedBy(), skuInfoVo.getUpdatedAt(), skuId
});
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(), GoblinGoodsSkuInfoVo skuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(localSkuId);
SqlMapping.gets(toMqSqls, updateGoodsSkuObjs)); if (skuInfoVo == null || !"0".equals(skuInfoVo.getDelFlg())) {
return true; continue;
} }
break; skuInfoVo.setName(sqbSku.getSkuName());
} if (sqbSku.getPrice() != null) {
} skuInfoVo.setPrice(BigDecimal.valueOf(sqbSku.getPrice()));
skuInfoVo.setPriceMember(BigDecimal.valueOf(sqbSku.getPrice()));
}
skuInfoVo.setUpdatedBy(uid);
skuInfoVo.setUpdatedAt(nowTime);
if (goblinMongoUtils.updateGoodsSkuInfoVo(skuInfoVo)) {
goblinRedisUtils.delGoodsSkuInfoVo(localSkuId);
updateGoodsSkuObjs.add(new Object[] {
skuInfoVo.getPrice(), skuInfoVo.getPriceMember(), skuInfoVo.getStock(),
skuInfoVo.getSkuStock(),
skuInfoVo.getBuyLimit(), skuInfoVo.getUpdatedBy(), skuInfoVo.getUpdatedAt(), localSkuId
});
updated = true;
} }
} }
if (updated) {
return false; LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_goods_sku.update_by_edit_for_coupon"));
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_GOODS.getKey(),
SqlMapping.gets(toMqSqls, updateGoodsSkuObjs));
}
return updated;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment