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

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

收钱吧商品列表、电店铺接口对接完成

parent de7edea0
package com.liquidnet.service.goblin.dto.vo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.liquidnet.service.goblin.param.shouqianba.response.data.MallProductsQueryData;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
public class GoblinSqbPerfGoodsVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("商城编号")
private String mallSn;
@ApiModelProperty("商城名称")
private String mallName;
@ApiModelProperty(value = "商品spuId")
private String spuId;
private String spuName;
private String skuId;
private String skuName;
/** 商品原价(分/元,与原有 price 字段保持向后兼容) */
private Long price;
private String coverPic;
private Integer sort;
/** 换购价格(为 null 时按售价) */
private BigDecimal settlementPrice;
/** 商品库存(管理后台展示用) */
private Integer stock;
/** 商品状态(管理后台展示用) */
private Integer status;
@ApiModelProperty(value = "商品图片")
private List<String> converImages;
@ApiModelProperty(value = "商品描述")
private String productIntroduction;
@ApiModelProperty(value = "商品标题")
private String title;
@ApiModelProperty(value = "商品规格")
private List<MallProductsQueryData.Sku> skuResults;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel(value = "商品规格")
public static class Sku {
@ApiModelProperty(value = "库存类型")
private Integer stockType;
@ApiModelProperty(value = "商品skuId")
private String skuId;
@ApiModelProperty(value = "库存值")
private BigDecimal quantity;
@ApiModelProperty(value = "规格标题")
private String skuTitle;
@ApiModelProperty(value = "规格名称")
private String skuName;
@ApiModelProperty(value = "价格")
private Long price;
}
}
......@@ -17,32 +17,4 @@ public class MallProductsQueryRequest {
@ApiModelProperty(value = "商城标识", required = true)
private CommonRequest.Mall mallID;
@ApiModelProperty(value = "商品筛选条件")
private Filter filter;
@ApiModelProperty(value = "分页游标")
private Cursor cursor;
@Data
@ApiModel("商品筛选条件")
public static class Filter {
@ApiModelProperty(value = "商品ID (spuId)")
private String spuId;
@ApiModelProperty(value = "商品名称 (模糊查询)")
private String title;
}
@Data
@ApiModel("分页游标")
public static class Cursor {
@ApiModelProperty(value = "游标字段")
private String cursorField;
@ApiModelProperty(value = "查询数量")
private Integer count;
@ApiModelProperty(value = "结束游标")
private String endCursor;
}
}
......@@ -12,12 +12,11 @@ import java.util.List;
public interface IGoblinSqbGoodsService {
/**
* 获取所有商城及商品列表
* 自动拉取所有商城,循环获取每个商城的商品列表,聚合返回
* 根据搜索条件拉取商城商品列表
*
* @return 商城商品列表
* @return 过滤后的商品列表
*/
ResponseDto<List<GoblinSqbPerfGoodsVo>> getAllMallProducts();
ResponseDto<List<GoblinSqbPerfGoodsVo>> getProductList();
/**
* 批量新增商品到 goblin 系统(不存在则新增)
......
......@@ -202,20 +202,20 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
List<GoblinSqbPerfGoodsVo> goodsList = new ArrayList<>();
for (GoblinSqbPerformanceGoods rel : relations) {
GoblinSqbPerfGoodsVo vo = new GoblinSqbPerfGoodsVo();
vo.setSkuId(rel.getSkuId());
vo.setSpuId(rel.getSpuId());
vo.setSort(rel.getSort());
vo.setSettlementPrice(rel.getSettlementPrice());
vo.setStatus(rel.getStatus());
GoblinGoodsSku sku = skuMap.get(rel.getSkuId());
if (sku != null) {
vo.setSkuName(sku.getName());
vo.setSpuName(sku.getName());
vo.setCoverPic(sku.getSkuPic());
vo.setPrice(sku.getPrice() != null ? sku.getPrice().longValue() : null);
vo.setStock(sku.getSkuStock());
}
// vo.setSkuId(rel.getSkuId());
// vo.setSpuId(rel.getSpuId());
// vo.setSort(rel.getSort());
// vo.setSettlementPrice(rel.getSettlementPrice());
// vo.setStatus(rel.getStatus());
//
// GoblinGoodsSku sku = skuMap.get(rel.getSkuId());
// if (sku != null) {
// vo.setSkuName(sku.getName());
// vo.setSpuName(sku.getName());
// vo.setCoverPic(sku.getSkuPic());
// vo.setPrice(sku.getPrice() != null ? sku.getPrice().longValue() : null);
// vo.setStock(sku.getSkuStock());
// }
goodsList.add(vo);
}
resp.setGoodsList(goodsList);
......@@ -246,13 +246,13 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
List<GoblinSqbPerfGoodsVo> result = new ArrayList<>();
for (GoblinGoodsSku sku : skuList) {
GoblinSqbPerfGoodsVo vo = new GoblinSqbPerfGoodsVo();
vo.setSkuId(sku.getSkuId());
vo.setSpuId(sku.getSpuId());
vo.setSkuName(sku.getName());
vo.setSpuName(sku.getName()); // 前端显示需要,统一赋值为 sku 名称
vo.setCoverPic(sku.getSkuPic()); // 同步阶段已将图片存入了 skuPic
vo.setPrice(sku.getPrice() != null ? sku.getPrice().longValue() : null);
vo.setStock(sku.getSkuStock());
// vo.setSkuId(sku.getSkuId());
// vo.setSpuId(sku.getSpuId());
// vo.setSkuName(sku.getName());
// vo.setSpuName(sku.getName()); // 前端显示需要,统一赋值为 sku 名称
// vo.setCoverPic(sku.getSkuPic()); // 同步阶段已将图片存入了 skuPic
// vo.setPrice(sku.getPrice() != null ? sku.getPrice().longValue() : null);
// vo.setStock(sku.getSkuStock());
result.add(vo);
}
return ResponseDto.success(result);
......
......@@ -37,7 +37,7 @@ public class GoblinSqbGoodsController {
@GetMapping("/list")
@ApiOperation("查询收钱吧所有商城及商品列表")
public ResponseDto<List<GoblinSqbPerfGoodsVo>> list() {
return goblinSqbGoodsService.getAllMallProducts();
return goblinSqbGoodsService.getProductList();
}
/**
......
......@@ -5,6 +5,7 @@ import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSqbPerfGoodsVo;
import com.liquidnet.service.goblin.config.properties.ShouqianbaProperties;
import com.liquidnet.service.goblin.entity.GoblinGoods;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import com.liquidnet.service.goblin.entity.GoblinSqbGoodsExt;
......@@ -32,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.apache.commons.lang3.StringUtils;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSpecVo;
import com.liquidnet.service.goblin.service.manage.IGoblinstoreMgtGoodsService;
......@@ -52,11 +53,8 @@ import java.util.stream.Collectors;
@Service
public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
// TODO: 后期移入配置文件
private static final String SQB_APPID = "test_appid";
private static final String SQB_MERCHANT_ID = "todo_merchant_id";
private static final String SQB_MERCHANT_USER_ID = "todo_merchant_user_id";
private static final String SQB_ROLE = "super_admin";
@Autowired
private ShouqianbaProperties shouqianbaProperties;
@Autowired
private GoblinGoodsMapper goblinGoodsMapper;
......@@ -88,11 +86,11 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
@Autowired
private IGoblinstoreMgtGoodsService goblinstoreMgtGoodsService;
private MallProductsQueryData querySqbProduct(String mallSn, String mallSignature, String sqbProductId) {
if (StringUtils.isEmpty(mallSn)) return null;
if (StringUtils.isEmpty(mallSn))
return null;
MallProductsQueryRequest request = new MallProductsQueryRequest();
request.setAppid(SQB_APPID);
request.setAppid(shouqianbaProperties.getAppId());
request.setSeller(buildSeller());
CommonRequest.Mall mallId = new CommonRequest.Mall();
mallId.setMallSn(mallSn);
......@@ -101,76 +99,110 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
List<MallProductsQueryData> dataList = goblinShouQianBaService.queryMallProducts(request);
if (!CollectionUtils.isEmpty(dataList)) {
for (MallProductsQueryData data : dataList) {
if (sqbProductId.equals(data.getSpuId())) return data;
if (sqbProductId.equals(data.getSpuId()))
return data;
}
}
return null;
}
@Override
public ResponseDto<List<GoblinSqbPerfGoodsVo>> getAllMallProducts() {
public ResponseDto<List<GoblinSqbPerfGoodsVo>> getProductList() {
try {
MallListQueryRequest mallRequest = new MallListQueryRequest();
mallRequest.setAppid(SQB_APPID);
MallListQueryRequest.Filter filter = new MallListQueryRequest.Filter();
filter.setSeller(buildSeller());
mallRequest.setFilter(filter);
List<MallListQueryData> mallList = goblinShouQianBaService.queryMallList(mallRequest);
List<GoblinSqbPerfGoodsVo> result = new ArrayList<>();
List<MallListQueryData> mallList = fetchAllMalls();
if (CollectionUtils.isEmpty(mallList)) {
return ResponseDto.success(new ArrayList<>());
}
List<GoblinSqbPerfGoodsVo> result = new ArrayList<>();
for (MallListQueryData mall : mallList) {
MallProductsQueryRequest productRequest = new MallProductsQueryRequest();
productRequest.setAppid(SQB_APPID);
productRequest.setSeller(buildSeller());
CommonRequest.Mall mallId = new CommonRequest.Mall();
mallId.setMallSn(mall.getMallSn());
mallId.setSignature(mall.getSignature());
productRequest.setMallID(mallId);
List<MallProductsQueryData> products = goblinShouQianBaService.queryMallProducts(productRequest);
List<MallProductsQueryData> products = fetchAllProducts(mall);
if (!CollectionUtils.isEmpty(products)) {
for (MallProductsQueryData product : products) {
List<MallProductsQueryData.Sku> skus = product.getSkuResults();
if (CollectionUtils.isEmpty(skus)) {
result.add(buildPerfGoodsVo(product, null));
} else {
for (MallProductsQueryData.Sku sku : skus) {
result.add(buildPerfGoodsVo(product, sku));
}
}
GoblinSqbPerfGoodsVo goblinSqbPerfGoodsVo = getGoblinSqbPerfGoodsVo(mall, product);
result.add(goblinSqbPerfGoodsVo);
}
}
}
return ResponseDto.success(result);
} catch (Exception e) {
log.error("[收钱吧] getAllMallProducts 异常", e);
return ResponseDto.failure("查询收钱吧商品列表失败");
log.error("search mall products error", e);
return ResponseDto.failure("查询收钱吧商品失败: " + e.getMessage());
}
}
private GoblinSqbPerfGoodsVo buildPerfGoodsVo(MallProductsQueryData product, MallProductsQueryData.Sku sku) {
GoblinSqbPerfGoodsVo vo = new GoblinSqbPerfGoodsVo();
vo.setSpuId(product.getSpuId());
vo.setSpuName(product.getTitle());
vo.setCoverPic(!CollectionUtils.isEmpty(product.getConverImages()) ? product.getConverImages().get(0) : "");
if (sku != null) {
vo.setSkuId(sku.getSkuId());
vo.setSkuName(sku.getSkuName() != null ? sku.getSkuName() : sku.getSkuTitle());
vo.setPrice(sku.getPrice());
} else {
vo.setSkuName(product.getTitle());
vo.setPrice(0L);
private static GoblinSqbPerfGoodsVo getGoblinSqbPerfGoodsVo(MallListQueryData mall, MallProductsQueryData product) {
GoblinSqbPerfGoodsVo goblinSqbPerfGoodsVo = new GoblinSqbPerfGoodsVo();
goblinSqbPerfGoodsVo.setMallSn(mall.getMallSn());
goblinSqbPerfGoodsVo.setMallName(mall.getMallName());
goblinSqbPerfGoodsVo.setSpuId(product.getSpuId());
goblinSqbPerfGoodsVo.setTitle(product.getTitle());
goblinSqbPerfGoodsVo.setProductIntroduction(product.getProductIntroduction());
goblinSqbPerfGoodsVo.setConverImages(product.getConverImages());
goblinSqbPerfGoodsVo.setSkuResults(product.getSkuResults());
return goblinSqbPerfGoodsVo;
}
/**
* 循环获取所有商城列表(支持游标分页)
*/
private List<MallListQueryData> fetchAllMalls() {
List<MallListQueryData> allMalls = new ArrayList<>();
int count = 100;
String lastMallSn = null;
while (true) {
MallListQueryRequest mallRequest = new MallListQueryRequest();
mallRequest.setAppid(shouqianbaProperties.getAppId());
MallListQueryRequest.Filter filter = new MallListQueryRequest.Filter();
filter.setSeller(buildSeller());
mallRequest.setFilter(filter);
MallListQueryRequest.Cursor cursor = new MallListQueryRequest.Cursor();
cursor.setCursorField("id");
cursor.setCount(count); // 最大支持1000
cursor.setEndCursor(lastMallSn);
mallRequest.setCursor(cursor);
MallListQueryRequest.Sort sort = new MallListQueryRequest.Sort();
sort.setSortField("id");
sort.setSort("DESC");
mallRequest.setSort(sort);
List<MallListQueryData> batch = goblinShouQianBaService.queryMallList(mallRequest);
if (CollectionUtils.isEmpty(batch)) {
break;
}
allMalls.addAll(batch);
lastMallSn = batch.get(batch.size() - 1).getMallSn();
// 如果拉取数量小于 count,说明是最后一页
if (batch.size() != count) {
break;
}
}
return vo;
return allMalls;
}
/**
* 循环获取某个商城下的所有商品列表(支持搜索和游标分页)
*/
private List<MallProductsQueryData> fetchAllProducts(MallListQueryData mall) {
MallProductsQueryRequest productRequest = new MallProductsQueryRequest();
productRequest.setAppid(shouqianbaProperties.getAppId());
productRequest.setSeller(buildSeller());
CommonRequest.Mall mallId = new CommonRequest.Mall();
mallId.setMallSn(mall.getMallSn());
mallId.setSignature(mall.getSignature());
productRequest.setMallID(mallId);
return goblinShouQianBaService.queryMallProducts(productRequest);
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResponseDto<String> addGoods(String storeId, List<GoblinSqbGoodsSyncParam> items) {
if (CollectionUtils.isEmpty(items)) return ResponseDto.failure("新增商品列表不能为空");
if (CollectionUtils.isEmpty(items))
return ResponseDto.failure("新增商品列表不能为空");
int newCount = 0, existCount = 0, failCount = 0;
String currentUid = "system";
......@@ -197,7 +229,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
// 1. 组装 AddParam
GoblinStoreMgtGoodsAddParam addParam = buildMgtGoodsAddParam(storeId, productsData);
// 2. 初始化 VOs
LocalDateTime now = LocalDateTime.now();
GoblinGoodsInfoVo goodsInfoVo = addParam.initGoodsInfoVo();
......@@ -224,11 +256,13 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuResults();
if (CollectionUtils.isEmpty(sqbSkus)) {
String skuId = goodsSkuInfoVoList.get(0).getSkuId();
goblinSqbGoodsExtMapper.insert(buildExt(goodsInfoVo.getSpuId(), skuId, mallSn, sqbProductId, sqbProductSn, null, now));
goblinSqbGoodsExtMapper.insert(
buildExt(goodsInfoVo.getSpuId(), skuId, mallSn, sqbProductId, sqbProductSn, null, now));
} else {
for (int i = 0; i < sqbSkus.size(); i++) {
String skuId = goodsSkuInfoVoList.get(i).getSkuId();
goblinSqbGoodsExtMapper.insert(buildExt(goodsInfoVo.getSpuId(), skuId, mallSn, sqbProductId, sqbProductSn, sqbSkus.get(i).getSkuId(), now));
goblinSqbGoodsExtMapper.insert(buildExt(goodsInfoVo.getSpuId(), skuId, mallSn, sqbProductId,
sqbProductSn, sqbSkus.get(i).getSkuId(), now));
}
}
newCount++;
......@@ -243,12 +277,14 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
@Override
@Transactional(rollbackFor = Exception.class)
public ResponseDto<String> updateGoods(String storeId, List<GoblinSqbGoodsSyncParam> items) {
if (CollectionUtils.isEmpty(items)) return ResponseDto.failure("更新商品列表不能为空");
if (CollectionUtils.isEmpty(items))
return ResponseDto.failure("更新商品列表不能为空");
int updateCount = 0, notFoundCount = 0, failCount = 0;
String currentUid = "system";
for (GoblinSqbGoodsSyncParam item : items) {
String sqbProductId = item.getSqbProductId(), mallSn = item.getMallSn(), mallSignature = item.getMallSignature();
String sqbProductId = item.getSqbProductId(), mallSn = item.getMallSn(),
mallSignature = item.getMallSignature();
try {
LambdaQueryWrapper<GoblinSqbGoodsExt> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(GoblinSqbGoodsExt::getSqbProductId, sqbProductId);
......@@ -285,11 +321,13 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuResults();
if (CollectionUtils.isEmpty(sqbSkus)) {
String skuId = sqbToSysSkuMap.get("PLACEHOLDER");
if (skuId != null) processSkuUpdate(currentUid, storeId, skuId, productsData, null);
if (skuId != null)
processSkuUpdate(currentUid, storeId, skuId, productsData, null);
} else {
for (MallProductsQueryData.Sku sqbSku : sqbSkus) {
String skuId = sqbToSysSkuMap.get(sqbSku.getSkuId());
if (skuId != null) processSkuUpdate(currentUid, storeId, skuId, productsData, sqbSku);
if (skuId != null)
processSkuUpdate(currentUid, storeId, skuId, productsData, sqbSku);
}
}
updateCount++;
......@@ -301,12 +339,15 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
return ResponseDto.success(String.format("更新完成:更新 %d, 未找到 %d, 失败 %d", updateCount, notFoundCount, failCount));
}
private void processSkuUpdate(String currentUid, String storeId, String skuId, MallProductsQueryData productsData, MallProductsQueryData.Sku sqbSku) {
private void processSkuUpdate(String currentUid, String storeId, String skuId, MallProductsQueryData productsData,
MallProductsQueryData.Sku sqbSku) {
GoblinGoodsSkuInfoVo mgtGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (null == mgtGoodsSkuInfoVo) return;
if (null == mgtGoodsSkuInfoVo)
return;
GoblinGoodsInfoVo mgtGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(mgtGoodsSkuInfoVo.getSpuId());
if (null == mgtGoodsInfoVo) return;
if (null == mgtGoodsInfoVo)
return;
GoblinStoreMgtGoodsEditSkuParam editSkuParam = new GoblinStoreMgtGoodsEditSkuParam();
editSkuParam.setStoreId(storeId);
......@@ -316,7 +357,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
if (!CollectionUtils.isEmpty(productsData.getConverImages())) {
editSkuParam.setSkuPic(productsData.getConverImages().get(0));
}
if (sqbSku != null) {
BigDecimal price = BigDecimal.valueOf(sqbSku.getPrice()).divide(BigDecimal.valueOf(100));
editSkuParam.setPrice(price);
......@@ -361,7 +402,8 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
editSkuParam.setSkuStock(mgtGoodsSkuInfoVo.getSkuStock());
}
goblinstoreMgtGoodsService.goodsEditSku(currentUid, editSkuParam, mgtGoodsSkuInfoVo, mgtGoodsInfoVo, null, null);
goblinstoreMgtGoodsService.goodsEditSku(currentUid, editSkuParam, mgtGoodsSkuInfoVo, mgtGoodsInfoVo, null,
null);
}
private GoblinStoreMgtGoodsAddParam buildMgtGoodsAddParam(String storeId, MallProductsQueryData productsData) {
......@@ -388,7 +430,8 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
return param;
}
private GoblinStoreMgtGoodsAddSkuParam buildMgtSkuParam(String defaultName, MallProductsQueryData.Sku sqbSku, List<String> images) {
private GoblinStoreMgtGoodsAddSkuParam buildMgtSkuParam(String defaultName, MallProductsQueryData.Sku sqbSku,
List<String> images) {
GoblinStoreMgtGoodsAddSkuParam sku = new GoblinStoreMgtGoodsAddSkuParam();
sku.setSkuPic(!CollectionUtils.isEmpty(images) ? images.get(0) : "");
sku.setSkuSpecList(new ArrayList<>());
......@@ -413,8 +456,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
// 1. 获取演出级全局配置
GoblinSqbPerformanceConfig config = goblinSqbPerformanceConfigMapper.selectOne(
new LambdaQueryWrapper<GoblinSqbPerformanceConfig>()
.eq(GoblinSqbPerformanceConfig::getPerformancesId, performancesId)
);
.eq(GoblinSqbPerformanceConfig::getPerformancesId, performancesId));
// 2. 如果开启了自动下架,检查演出状态
if (config != null && Integer.valueOf(1).equals(config.getAutoOffline())) {
......@@ -426,30 +468,46 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
}
List<GoblinSqbPerfGoodsVo> cached = goblinSqbRedisUtils.getPerfGoods(performancesId);
if (cached != null) return ResponseDto.success(cached);
if (cached != null)
return ResponseDto.success(cached);
try {
LambdaQueryWrapper<GoblinSqbPerformanceGoods> query = new LambdaQueryWrapper<>();
query.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId).eq(GoblinSqbPerformanceGoods::getStatus, 1).orderByAsc(GoblinSqbPerformanceGoods::getSort);
query.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId)
.eq(GoblinSqbPerformanceGoods::getStatus, 1).orderByAsc(GoblinSqbPerformanceGoods::getSort);
List<GoblinSqbPerformanceGoods> relations = goblinSqbPerformanceGoodsMapper.selectList(query);
if (CollectionUtils.isEmpty(relations)) {
List<GoblinSqbPerfGoodsVo> empty = new ArrayList<>();
goblinSqbRedisUtils.setPerfGoods(performancesId, empty);
return ResponseDto.success(empty);
}
List<String> skuIds = relations.stream().map(GoblinSqbPerformanceGoods::getSkuId).collect(Collectors.toList());
List<String> spuIds = relations.stream().map(GoblinSqbPerformanceGoods::getSpuId).distinct().collect(Collectors.toList());
List<GoblinGoodsSku> skuList = goblinGoodsSkuMapper.selectList(new LambdaQueryWrapper<GoblinGoodsSku>().in(GoblinGoodsSku::getSkuId, skuIds));
Map<String, GoblinGoodsSku> skuMap = skuList.stream().collect(Collectors.toMap(GoblinGoodsSku::getSkuId, Function.identity(), (a, b) -> a));
List<GoblinGoods> spuList = goblinGoodsMapper.selectList(new LambdaQueryWrapper<GoblinGoods>().in(GoblinGoods::getSpuId, spuIds));
Map<String, GoblinGoods> spuMap = spuList.stream().collect(Collectors.toMap(GoblinGoods::getSpuId, Function.identity(), (a, b) -> a));
List<String> skuIds = relations.stream().map(GoblinSqbPerformanceGoods::getSkuId)
.collect(Collectors.toList());
List<String> spuIds = relations.stream().map(GoblinSqbPerformanceGoods::getSpuId).distinct()
.collect(Collectors.toList());
List<GoblinGoodsSku> skuList = goblinGoodsSkuMapper
.selectList(new LambdaQueryWrapper<GoblinGoodsSku>().in(GoblinGoodsSku::getSkuId, skuIds));
Map<String, GoblinGoodsSku> skuMap = skuList.stream()
.collect(Collectors.toMap(GoblinGoodsSku::getSkuId, Function.identity(), (a, b) -> a));
List<GoblinGoods> spuList = goblinGoodsMapper
.selectList(new LambdaQueryWrapper<GoblinGoods>().in(GoblinGoods::getSpuId, spuIds));
Map<String, GoblinGoods> spuMap = spuList.stream()
.collect(Collectors.toMap(GoblinGoods::getSpuId, Function.identity(), (a, b) -> a));
List<GoblinSqbPerfGoodsVo> result = new ArrayList<>();
for (GoblinSqbPerformanceGoods rel : relations) {
GoblinSqbPerfGoodsVo vo = new GoblinSqbPerfGoodsVo();
vo.setSkuId(rel.getSkuId()); vo.setSpuId(rel.getSpuId()); vo.setSort(rel.getSort());
GoblinGoodsSku sku = skuMap.get(rel.getSkuId());
if (sku != null) { vo.setSkuName(sku.getName()); vo.setPrice(sku.getPrice() != null ? sku.getPrice().longValue() : null); }
GoblinGoods spu = spuMap.get(rel.getSpuId());
if (spu != null) { vo.setSpuName(spu.getName()); vo.setCoverPic(spu.getCoverPic()); }
// vo.setSkuId(rel.getSkuId());
// vo.setSpuId(rel.getSpuId());
// vo.setSort(rel.getSort());
// GoblinGoodsSku sku = skuMap.get(rel.getSkuId());
// if (sku != null) {
// vo.setSkuName(sku.getName());
// vo.setPrice(sku.getPrice() != null ? sku.getPrice().longValue() : null);
// }
// GoblinGoods spu = spuMap.get(rel.getSpuId());
// if (spu != null) {
// vo.setSpuName(spu.getName());
// vo.setCoverPic(spu.getCoverPic());
// }
result.add(vo);
}
goblinSqbRedisUtils.setPerfGoods(performancesId, result);
......@@ -464,10 +522,12 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
try {
// 借鉴 GoblinMongoUtils 中的逻辑,通过关联的官方营销活动状态判断演出状态
// status: 2 表示活动结束, 7 表示停用
List<GoblinSelfMarketingVo> marketingList = goblinMongoUtils.getSelfMarketingByPerformanceId(performancesId);
List<GoblinSelfMarketingVo> marketingList = goblinMongoUtils
.getSelfMarketingByPerformanceId(performancesId);
if (!CollectionUtils.isEmpty(marketingList)) {
GoblinSelfMarketingVo marketing = marketingList.get(0);
if (Integer.valueOf(2).equals(marketing.getStatus()) || Integer.valueOf(7).equals(marketing.getStatus())) {
if (Integer.valueOf(2).equals(marketing.getStatus())
|| Integer.valueOf(7).equals(marketing.getStatus())) {
return true;
}
}
......@@ -479,17 +539,23 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
private CommonRequest.Seller buildSeller() {
CommonRequest.Seller seller = new CommonRequest.Seller();
seller.setMerchantId(SQB_MERCHANT_ID);
seller.setMerchantUserId(SQB_MERCHANT_USER_ID);
seller.setRole(SQB_ROLE);
seller.setMerchantId(shouqianbaProperties.getMerchantId());
seller.setMerchantUserId(shouqianbaProperties.getMerchantUserId());
seller.setRole(shouqianbaProperties.getRole());
return seller;
}
private GoblinSqbGoodsExt buildExt(String spuId, String skuId, String mallSn, String sqbProductId, String sqbProductSn, String sqbSkuId, LocalDateTime now) {
private GoblinSqbGoodsExt buildExt(String spuId, String skuId, String mallSn, String sqbProductId,
String sqbProductSn, String sqbSkuId, LocalDateTime now) {
GoblinSqbGoodsExt ext = new GoblinSqbGoodsExt();
ext.setSpuId(spuId); ext.setSkuId(skuId); ext.setMallSn(mallSn);
ext.setSqbProductId(sqbProductId); ext.setSqbProductSn(sqbProductSn); ext.setSqbSkuId(sqbSkuId);
ext.setCreatedAt(now); ext.setUpdatedAt(now);
ext.setSpuId(spuId);
ext.setSkuId(skuId);
ext.setMallSn(mallSn);
ext.setSqbProductId(sqbProductId);
ext.setSqbProductSn(sqbProductSn);
ext.setSqbSkuId(sqbSkuId);
ext.setCreatedAt(now);
ext.setUpdatedAt(now);
return ext;
}
}
......@@ -15,6 +15,7 @@ import com.liquidnet.service.goblin.service.IGoblinShouQianBaService;
import com.liquidnet.service.goblin.service.IGoblinSqbOrderService;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.GoblinSqbRedisUtils;
import com.liquidnet.service.goblin.config.properties.ShouqianbaProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -51,12 +52,8 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// ========== 常量(后期可移至配置文件) ==========
// TODO: 将以下常量移至 application.yml 配置
private static final String SQB_APPID = "test_appid";
private static final String SQB_MERCHANT_ID = "todo_merchant_id";
private static final String SQB_MERCHANT_USER_ID = "todo_merchant_user_id";
private static final String SQB_ROLE = "super_admin";
@Autowired
private ShouqianbaProperties shouqianbaProperties;
// ================================ 创建订单 ================================
......@@ -100,7 +97,7 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
// Step 4.1: createSettlement → 得 checkoutItemsId
// TODO: 从商品数据中获取价格、图片、标题等信息填充 CheckoutItem
SettlementCreateRequest settlementReq = new SettlementCreateRequest();
settlementReq.setAppid(SQB_APPID);
settlementReq.setAppid(shouqianbaProperties.getAppId());
settlementReq.setSeller(seller);
CommonRequest.Buyer buyer = new CommonRequest.Buyer();
buyer.setBuyerId(userId);
......@@ -117,7 +114,7 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
// Step 4.2: createOrder → 得 sqbOrderSn + sqbOrderSignature + sqbAcquiringSn
OrderCreateRequest orderReq = new OrderCreateRequest();
orderReq.setAppid(SQB_APPID);
orderReq.setAppid(shouqianbaProperties.getAppId());
orderReq.setSeller(seller);
orderReq.setCheckoutItemsId(checkoutItemsId);
orderReq.setBuyer(buyer);
......@@ -372,7 +369,7 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
// 调用收钱吧查询券码
CouponQueryRequest req = new CouponQueryRequest();
req.setAppid(SQB_APPID);
req.setAppid(shouqianbaProperties.getAppId());
req.setSeller(buildSeller());
CouponQueryRequest.OrderInfo orderInfo = new CouponQueryRequest.OrderInfo();
orderInfo.setSn(orderVo.getSqbOrderSn());
......@@ -422,7 +419,7 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
try {
// 调用收钱吧退款
CouponRefundRequest refundReq = new CouponRefundRequest();
refundReq.setAppid(SQB_APPID);
refundReq.setAppid(shouqianbaProperties.getAppId());
refundReq.setSeller(buildSeller());
refundReq.setRequestSource("EXTERN");
refundReq.setRequestId(IDGenerator.nextSnowId());
......@@ -480,14 +477,14 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
if (!userId.equals(orderVo.getUserId())) return ResponseDto.failure("无权限访问该订单");
CouponStatusSyncRequest req = new CouponStatusSyncRequest();
req.setAppid(SQB_APPID);
req.setAppid(shouqianbaProperties.getAppId());
req.setRedeemSource("EXTERN");
// TODO: 填充 voucherNos(券号列表)、redeemMerchantId、redeemExternalOrderSn、clientSn、status
// 需要从 orderVo 中获取 couponSn 和其他必要字段
if (orderVo.getCouponSn() != null) {
req.setVoucherNos(java.util.Collections.singletonList(orderVo.getCouponSn()));
}
req.setRedeemMerchantId(SQB_MERCHANT_ID);
req.setRedeemMerchantId(shouqianbaProperties.getMerchantId());
req.setRedeemExternalOrderSn(IDGenerator.nextSnowId());
req.setClientSn("terminal_001"); // TODO: 配置终端号
req.setStatus((byte) 1); // 1-已核销
......@@ -729,16 +726,16 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
private CommonRequest.Seller buildSeller() {
CommonRequest.Seller seller = new CommonRequest.Seller();
seller.setMerchantId(SQB_MERCHANT_ID);
seller.setMerchantUserId(SQB_MERCHANT_USER_ID);
seller.setRole(SQB_ROLE);
seller.setMerchantId(shouqianbaProperties.getMerchantId());
seller.setMerchantUserId(shouqianbaProperties.getMerchantUserId());
seller.setRole(shouqianbaProperties.getRole());
return seller;
}
private CashierQueryRequest buildCashierQueryRequest(CommonRequest.Seller seller,
String acquiringSn, String acquiringSignature) {
CashierQueryRequest req = new CashierQueryRequest();
req.setAppid(SQB_APPID);
req.setAppid(shouqianbaProperties.getAppId());
req.setSeller(seller);
req.setPaymentMode(4); // 4-微信小程序支付
......@@ -760,7 +757,7 @@ public class GoblinSqbOrderServiceImpl implements IGoblinSqbOrderService {
String seq,
CashierQueryData cashierData) {
CreateWechatPrepayOrderRequest req = new CreateWechatPrepayOrderRequest();
req.setAppid(SQB_APPID);
req.setAppid(shouqianbaProperties.getAppId());
req.setSeller(seller);
req.setAcquiringSn(acquiringSn);
req.setSignature(acquiringSignature);
......
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