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

Commit 7fb073da authored by 姜秀龙's avatar 姜秀龙

sqb 下架问题

parent e07f5bc1
......@@ -7,6 +7,8 @@ import com.liquidnet.client.admin.zhengzai.goblin.service.ISqbPerformanceGoodsSe
import com.liquidnet.client.admin.zhengzai.goblin.utils.GoblinRedisUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinAdminSqbGoodsVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSqbPerfLinkedGoodsVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSqbPerfListRespVo;
import com.liquidnet.service.goblin.entity.GoblinGoods;
......@@ -42,21 +44,86 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
/** skuType=33 代表收钱吧商品 */
private static final int SQB_SKU_TYPE = 33;
/** 与前台 Goblin 一致:单品上架状态 3=上架 */
private static final String SHELVES_ON = "3";
/**
* 与实体/上下架接口约定一致:0-待上架|1-下架|2-违规|3-上架(见 {@link GoblinGoods#getShelvesStatus} 注释)
*/
private static final String SHELF_WAIT = "0";
private static final String SHELF_OFF = "1";
private static final String SHELF_VIOLATION = "2";
private static final String SHELF_ON = "3";
private static String trimFlg(String s) {
return s == null ? "" : s.trim();
}
/** 演出关联列表:是否可售 + 展示文案(与 C 端 {@code GoblinFrontServiceImpl#getPerformanceSelectGoods} 过滤条件对齐) */
private static final class PerfShelfEval {
final boolean linkable;
final String statusLabel;
PerfShelfEval(boolean linkable, String statusLabel) {
this.linkable = linkable;
this.statusLabel = statusLabel;
}
}
private static boolean isSqbSkuAndSpuOnShelf(GoblinGoodsSku sku, GoblinGoods spu) {
if (sku == null || spu == null) {
return false;
/**
* Redis 中 SPU、SKU 均有缓存时优先用缓存;否则用 MySQL 行。可售=未删+SPU 展示+非活动独占+SPU/SKU 均为上架(3)。
*/
private PerfShelfEval evalPerfShelfState(String skuId, String spuId, GoblinGoodsSku mysqlSku, GoblinGoods mysqlSpu) {
String sid = skuId == null ? "" : skuId.trim();
String pid = spuId == null ? "" : spuId.trim();
if (!StringUtils.hasText(sid) || !StringUtils.hasText(pid)) {
return new PerfShelfEval(false, "数据异常");
}
if (!"0".equals(sku.getDelFlg()) || !"0".equals(spu.getDelFlg())) {
return false;
GoblinGoodsSkuInfoVo skuVo = goblinRedisUtils.getGoodsSkuInfoVo(sid);
GoblinGoodsInfoVo spuVo = goblinRedisUtils.getGoodsInfoVo(pid);
if (skuVo != null && spuVo != null) {
return evalFromSnapshot(trimFlg(skuVo.getDelFlg()), trimFlg(spuVo.getDelFlg()),
trimFlg(skuVo.getShelvesStatus()), trimFlg(spuVo.getShelvesStatus()),
trimFlg(spuVo.getSpuAppear()), spuVo.getMarketId(), true);
}
return SHELVES_ON.equals(sku.getShelvesStatus()) && SHELVES_ON.equals(spu.getShelvesStatus());
if (mysqlSku == null || mysqlSpu == null) {
return new PerfShelfEval(false, "缺少商品数据");
}
return evalFromSnapshot(trimFlg(mysqlSku.getDelFlg()), trimFlg(mysqlSpu.getDelFlg()),
trimFlg(mysqlSku.getShelvesStatus()), trimFlg(mysqlSpu.getShelvesStatus()),
trimFlg(mysqlSpu.getSpuAppear()), null, false);
}
private static String shelfStatusLabel(boolean onShelf) {
return onShelf ? "上架" : "已下架";
/**
* @param hasMarketId true 表示来自 Redis,可检查 marketId;MySQL DO 无该字段时传 false
*/
private static PerfShelfEval evalFromSnapshot(String skuDel, String spuDel, String skuShelf, String spuShelf,
String spuAppear, String marketId, boolean hasMarketId) {
if (!"0".equals(skuDel) || !"0".equals(spuDel)) {
return new PerfShelfEval(false, "已删除");
}
if (!"0".equals(spuAppear)) {
return new PerfShelfEval(false, "SPU隐藏");
}
if (hasMarketId && StringUtils.hasText(marketId)) {
return new PerfShelfEval(false, "活动商品");
}
boolean on = SHELF_ON.equals(skuShelf) && SHELF_ON.equals(spuShelf);
if (on) {
return new PerfShelfEval(true, "上架");
}
return new PerfShelfEval(false, humanizeNotOnShelf(skuShelf, spuShelf));
}
/** 非「上架」时的文案:区分待上架(0)、下架(1)、违规(2),避免把同步初始态 0 误标成「已下架」 */
private static String humanizeNotOnShelf(String skuShelf, String spuShelf) {
if (SHELF_WAIT.equals(skuShelf) || SHELF_WAIT.equals(spuShelf)) {
return "待上架";
}
if (SHELF_OFF.equals(skuShelf) || SHELF_OFF.equals(spuShelf)) {
return "已下架";
}
if (SHELF_VIOLATION.equals(skuShelf) || SHELF_VIOLATION.equals(spuShelf)) {
return "违规";
}
return "未上架";
}
private static String sqbSpuSkuDisplay(String spuTitle, String skuTitle) {
......@@ -149,7 +216,7 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
if (existing == null) {
GoblinGoods spu = goblinGoodsMapper.selectOne(new LambdaQueryWrapper<GoblinGoods>()
.eq(GoblinGoods::getSpuId, sku.getSpuId()).last("LIMIT 1"));
if (!isSqbSkuAndSpuOnShelf(sku, spu)) {
if (!evalPerfShelfState(skuId, sku.getSpuId(), sku, spu).linkable) {
return ResponseDto.failure("商品未上架或已下架,不可关联。请先让商户上架后再操作。skuId=" + skuId);
}
}
......@@ -262,7 +329,7 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
LambdaQueryWrapper<GoblinGoods> goodsQuery = new LambdaQueryWrapper<>();
goodsQuery.in(GoblinGoods::getSpuId, spuIdList)
.select(GoblinGoods::getSpuId, GoblinGoods::getName, GoblinGoods::getCoverPic,
GoblinGoods::getShelvesStatus, GoblinGoods::getDelFlg);
GoblinGoods::getShelvesStatus, GoblinGoods::getDelFlg, GoblinGoods::getSpuAppear);
for (GoblinGoods g : goblinGoodsMapper.selectList(goodsQuery)) {
if (g.getSpuId() != null) {
spuNameById.put(g.getSpuId(), g.getName());
......@@ -281,7 +348,8 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
vo.setSettlementPrice(rel.getSettlementPrice());
vo.setStatus(rel.getStatus());
GoblinGoodsSku sku = skuMap.get(rel.getSkuId());
String relSkuId = rel.getSkuId() == null ? null : rel.getSkuId().trim();
GoblinGoodsSku sku = relSkuId == null ? null : skuMap.get(relSkuId);
if (sku != null) {
vo.setSkuName(sku.getName());
vo.setSpuName(spuNameById.getOrDefault(rel.getSpuId(), ""));
......@@ -289,12 +357,12 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
vo.setPrice(sku.getPrice());
vo.setStock(sku.getSkuStock());
GoblinGoods spu = spuById.get(rel.getSpuId());
boolean onShelf = isSqbSkuAndSpuOnShelf(sku, spu);
vo.setLinkable(onShelf);
vo.setShelfStatusLabel(shelfStatusLabel(onShelf));
PerfShelfEval ev = evalPerfShelfState(relSkuId, rel.getSpuId(), sku, spu);
vo.setLinkable(ev.linkable);
vo.setShelfStatusLabel(ev.statusLabel);
} else {
vo.setLinkable(false);
vo.setShelfStatusLabel("已下架");
vo.setShelfStatusLabel("无SKU记录");
}
goodsList.add(vo);
}
......@@ -347,7 +415,7 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
LambdaQueryWrapper<GoblinGoods> gq = new LambdaQueryWrapper<>();
gq.in(GoblinGoods::getSpuId, spuIdForTitle)
.select(GoblinGoods::getSpuId, GoblinGoods::getName, GoblinGoods::getCoverPic,
GoblinGoods::getShelvesStatus, GoblinGoods::getDelFlg);
GoblinGoods::getShelvesStatus, GoblinGoods::getDelFlg, GoblinGoods::getSpuAppear);
for (GoblinGoods g : goblinGoodsMapper.selectList(gq)) {
if (g.getSpuId() != null) {
spuTitleById.put(g.getSpuId(), g.getName());
......@@ -367,10 +435,10 @@ public class SqbPerformanceGoodsServiceImpl implements ISqbPerformanceGoodsServi
vo.setSpuTitle(spuTitle);
vo.setSkuTitle(skuTitle);
GoblinGoods spu = spuRowById.get(sku.getSpuId());
boolean onShelf = isSqbSkuAndSpuOnShelf(sku, spu);
vo.setLinkable(onShelf);
vo.setShelfStatusLabel(shelfStatusLabel(onShelf));
vo.setTitle(sqbSpuSkuDisplay(spuTitle, skuTitle) + (onShelf ? "" : "(已下架)"));
PerfShelfEval ev = evalPerfShelfState(sku.getSkuId(), sku.getSpuId(), sku, spu);
vo.setLinkable(ev.linkable);
vo.setShelfStatusLabel(ev.statusLabel);
vo.setTitle(sqbSpuSkuDisplay(spuTitle, skuTitle) + (ev.linkable ? "" : "(" + ev.statusLabel + ")"));
vo.setSkuPic(pickSkuOrSpuCover(sku.getSkuPic(), spuCoverById.get(sku.getSpuId())));
vo.setPrice(sku.getPrice());
vo.setSkuStock(sku.getSkuStock());
......
......@@ -224,6 +224,21 @@ public class GoblinRedisUtils {
return vo;
}
/**
* 与 goblin 服务一致:SPU 基础缓存(用于后台与 C 端上下架状态对齐)
*/
public GoblinGoodsInfoVo getGoodsInfoVo(String spuId) {
if (spuId == null || spuId.isEmpty()) {
return null;
}
String rk = GoblinRedisConst.BASIC_GOODS.concat(spuId);
GoblinGoodsInfoVo vo = (GoblinGoodsInfoVo) redisDataSourceUtil.getRedisGoblinUtil().get(rk);
if (null == vo) {
return null;
}
return vo;
}
//覆盖 站位宾哥要dto
public void setNftNumDetails(String num, String skuId, GalaxyNftPublishAndBuyReqDto dto) {
String redisKey = GoblinRedisConst.GOBLIN_NUM_DETAILS.concat(num).concat(skuId);
......
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