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

Commit daf529a8 authored by 张国柄's avatar 张国柄

+api:条码识别商品详情:pos机使用;

parent 2d813d6c
......@@ -28,6 +28,9 @@ public class GoblinFrontGoodDetailVo implements Serializable {
@ApiModelProperty(value = "商品可参与券类型")
ArrayList<String> getSpuType;
@ApiModelProperty(value = "条码识别到的SKUID列表", notes = "仅当条码识别时有效")
private List<String> hitSkuIdList;
private static final long serialVersionUID = 1L;
private static final GoblinFrontGoodDetailVo obj = new GoblinFrontGoodDetailVo();
......
......@@ -20,7 +20,7 @@ public interface IGoblinStoreZhengzaiService {
/**
* 正在下单 商铺参与活动的商品列表
* @param marketId
* @param keyword 搜索内容,支持`SPU名称`、`SKU名称`、`SKU编码`
* @param keyword 搜索关键字,支持搜索`SPU名称`
* @return
*/
ResponseDto<List<GoblinZhengzaiGoodVo>> getSpuList(String marketId, String keyword);
......
package com.liquidnet.service.goblin.controller;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinFrontHotWord;
import com.liquidnet.service.goblin.service.impl.GoblinFrontServiceImpl;
import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -22,10 +28,13 @@ import java.util.List;
* @Description:前端接口
* @date 2021/12/27 下午6:25
*/
@Slf4j
@Api(tags = "前端接口管理")
@RestController
@RequestMapping("/front")
public class GoblinFrontController {
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinFrontServiceImpl goblinFrontService;
......@@ -75,6 +84,33 @@ public class GoblinFrontController {
return ResponseDto.success(vo);
}
@GetMapping("getGoodsDetail2")
@ApiOperation(value = "获得商品详情2", notes = "条码识别SKU时使用")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "skuCode", value = "SKU条码"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id"),
})
public ResponseDto<GoblinFrontGoodDetailVo> getGoodsDetail2(@RequestParam(name = "skuCode") String skuNo, @RequestParam("marketId") String marketId) {
String currentUid = CurrentUtil.getCurrentUid();
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVoByUid(currentUid);
if (storeInfoVo == null) {
return ResponseDto.failure("店铺不存在");
}
GoblinFrontGoodDetailVo vo;
try {
vo = goblinFrontService.getGoodsDetail2(skuNo, storeInfoVo.getStoreId(), marketId);
if (vo == null) {
return ResponseDto.failure("商品不存在");
}
} catch (LiquidnetServiceException e) {
return ResponseDto.failure(e.getMessage());
} catch (Exception e) {
log.error("Ex.扫条码识别商品:发生异常[skuNo={},marketId={}]", skuNo, marketId, e);
return ResponseDto.failure("识别失败");
}
return ResponseDto.success(vo);
}
@GetMapping("getMoudleIndex")
@ApiOperation("获取组件排序")
public ResponseDto getMoudleIndex() throws ParseException {
......
......@@ -38,7 +38,7 @@ public class GoblinStoreZhengzaiController {
@ApiOperation("正在下单-参与活动的spu")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "kw", value = "搜索内容【1~64位】,支持`SPU名称`、`SKU名称`、`SKU编码`", example = ""),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "kw", value = "搜索关键字【1~64位】支持搜索`SPU名称`", example = ""),
})
public ResponseDto<List<GoblinZhengzaiGoodVo>> getStoreList(@RequestParam("marketId") @Valid String marketId,
@RequestParam(value = "kw", required = false) @Size(min = 1, max = 64, message = "搜索内容长度超出范围1~64位") String keyword) {
......@@ -50,8 +50,7 @@ public class GoblinStoreZhengzaiController {
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "marketId", value = "活动id", example = "1"),
@ApiImplicitParam(type = "form", required = true, dataType = "Integet", name = "page", value = "页数", example = "1"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "kw", value = "搜索内容【1~64位】,支持`SPU名称`、`SKU名称`、`SKU编码`", example = ""),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "kw", value = "搜索关键字【1~64位】支持搜索`SPU名称`", example = ""),
})
public ResponseDto<GoblinZhengzaiGoodPageVo> getStoreList2(@RequestParam("marketId") @Valid String marketId,
@RequestParam("page") @Valid Integer page,
......
......@@ -2,6 +2,7 @@ package com.liquidnet.service.goblin.service.impl;
import com.alibaba.fastjson.JSON;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto;
......@@ -32,6 +33,7 @@ import org.springframework.data.mongodb.core.query.Collation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.ParseException;
......@@ -39,6 +41,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service
@Slf4j
......@@ -345,6 +348,90 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
return goblinFrontGoodDetailVo;
}
/**
* 根据条码获得商品详情
*/
public GoblinFrontGoodDetailVo getGoodsDetail2(String skuNo, String storeId, String marketId) {
Criteria skuCriteria = Criteria.where("delFlg").is("0").and("storeId").is(storeId).and("skuNo").is(skuNo);
Query skuQuery = Query.query(skuCriteria);
skuQuery.fields().include("spuId").include("skuId");
List<GoblinGoodsSkuInfoVo> skuQueryResultList = mongoTemplate.find(skuQuery, GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
if (CollectionUtils.isEmpty(skuQueryResultList)) {
return null;
}
List<String> skuQueryResultSpuIdList = skuQueryResultList.stream().map(GoblinGoodsSkuInfoVo::getSpuId).collect(Collectors.toList());
Criteria criteria = Criteria.where("delFlg").is("0").and("storeId").is(storeId).and("spuId").in(skuQueryResultSpuIdList)
.and("marketId").is(GoblinStatusConst.MarketPreStatus.MARKET_PRE_ZHENGZAI.getValue().concat(marketId));
Query query = Query.query(criteria);
List<GoblinGoodsInfoVo> goblinGoodsInfoVos = mongoTemplate.find(query, GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
if (CollectionUtils.isEmpty(goblinGoodsInfoVos)) {
return null;
} else if (goblinGoodsInfoVos.size() > 1) {
throw new LiquidnetServiceException("-1", "条码识别到多个商品,请更正处理");
}
String spuId = goblinGoodsInfoVos.get(0).getSpuId();
Integer buyCount = 0;
GoblinFrontGoodDetailVo goblinFrontGoodDetailVo = GoblinFrontGoodDetailVo.getNew();
GoblinGoodsInfoVo goblinGoodsInfoVo = goblinRedisUtils.getGoodsInfoVo(spuId);
GoblinGoodsInfoDetailVo goblinGoodsInfoDetailVo = GoblinGoodsInfoDetailVo.getNew();
//skuIdList
if (null != goblinGoodsInfoVo) {
BeanUtils.copyProperties(goblinGoodsInfoVo, goblinGoodsInfoDetailVo);
goblinFrontGoodDetailVo.setGoblinGoodsInfoVo(goblinGoodsInfoDetailVo);
// int limit= getStockCount(goblinGoodsInfoVo.getStoreId());
List<String> skuIdList = goblinGoodsInfoVo.getSkuIdList();
ArrayList<GoblinGoodsSkuInfoDetailVo> list = ObjectUtil.goblinGoodsSkuInfoDetailVos();
for (String sku : skuIdList) {
String userId = CurrentUtil.getCurrentUid();
if (StringUtils.isNotBlank(userId)) {
buyCount = goblinRedisUtils.getSkuCountByUid(userId, sku);
}
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo = goblinRedisUtils.getGoodsSkuInfoVo(sku);
if (null != goblinGoodsSkuInfoVo && goblinGoodsSkuInfoVo.getDelFlg().equals("0") && goblinGoodsSkuInfoVo.getShelvesStatus().equals("3")) {
//获取 sku 库存数量
String pre = GoblinStatusConst.MarketPreStatus.getPre(spuId);
int stock = goblinRedisUtils.getSkuStock(pre, goblinGoodsSkuInfoVo.getSkuId());
log.debug("skuId:{},库存数量{}", goblinGoodsSkuInfoVo.getSkuId(), stock);
GoblinGoodsSkuInfoDetailVo goblinGoodsSkuInfoDetailVo = GoblinGoodsSkuInfoDetailVo.getNew();
BeanUtils.copyProperties(goblinGoodsSkuInfoVo, goblinGoodsSkuInfoDetailVo);
if (0 != goblinGoodsSkuInfoDetailVo.getBuyLimit()) {
if (null == buyCount) {
buyCount = 0;
}
goblinGoodsSkuInfoDetailVo.setCanBuy(goblinGoodsSkuInfoDetailVo.getBuyLimit() - buyCount);
} else {
goblinGoodsSkuInfoDetailVo.setCanBuy(-9999);
}
if (stock <= 0) {
goblinGoodsSkuInfoDetailVo.setStockLess(true);
} else {
goblinGoodsSkuInfoDetailVo.setStockLess(false);
}
goblinGoodsSkuInfoDetailVo.setRestStock(stock);
list.add(goblinGoodsSkuInfoDetailVo);
}
}
//goblinGoodsInfoVo
GoblinStoreInfoVo goblinStoreInfoVo = this.getStore(goblinGoodsInfoVo.getStoreId());
if (null != goblinStoreInfoVo) {
goblinFrontGoodDetailVo.setStoreName(goblinStoreInfoVo.getStoreName());
}
goblinFrontGoodDetailVo.setGoblinGoodsSkuInfoVolist(list);
} else {
return null;
}
ArrayList<String> list = goblinCouponService.getSpuType(spuId, goblinGoodsInfoDetailVo.getStoreId());
goblinFrontGoodDetailVo.setGetSpuType(list);
// 设置条码命中的SKUID列表
List<String> hitSkuIdList = skuQueryResultList.stream().filter(r -> r.getSpuId().equals(spuId)).map(GoblinGoodsSkuInfoVo::getSkuId).collect(Collectors.toList());
goblinFrontGoodDetailVo.setHitSkuIdList(hitSkuIdList);
return goblinFrontGoodDetailVo;
}
/**
* 获取组件排序
*/
......
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