Authored by peuei

update 支持多门店多卖家配置

... ... @@ -49,5 +49,11 @@ public interface StoragePriceMapper {
List<StoragePrice> selectMinPriceByStorageIdList(@Param("list") List<Integer> storageIdList);
List<StoragePrice> selectByProductIdsAndSellerUid(@Param("list") List<Integer> productIdList, @Param("sellerUid") Integer defaultSellerUid, @Param("status") Integer defaultSkupStatus);
List<StoragePrice> selectByProductIdsAndSellerUid(@Param("productList") List<Integer> productIdList, @Param("sellerList") List<Integer> sellerUid, @Param("status") Integer defaultSkupStatus);
List<Integer> selectProductIdsBySkupInfoPlus(@Param("storagePrice") StoragePrice storagePrice, @Param("list") List<Integer> sellerUid);
int selectStoragePriceCountBySellerUid(@Param("storagePrice") StoragePrice storagePrice, @Param("list") List<Integer> sellerUid);
List<StoragePrice> selectStoragePriceListBySellerUid(@Param("storagePrice") StoragePrice storagePrice, @Param("start") int startIndex, @Param("rows") int rows, @Param("list") List<Integer> sellerUid);
}
\ No newline at end of file
... ...
... ... @@ -181,12 +181,81 @@
select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
update_time, create_time
from storage_price
where seller_uid = #{sellerUid,jdbcType=INTEGER}
and status = #{status,jdbcType=INTEGER}
where status = #{status,jdbcType=INTEGER}
and product_id in
<foreach item="productItem" index="index" collection="productList" open="(" separator="," close=")">
#{productItem}
</foreach>
and seller_uid in
<foreach item="sellerItem" index="index" collection="sellerList" open="(" separator="," close=")">
#{sellerItem}
</foreach>
</select>
<select id="selectProductIdsBySkupInfoPlus" resultType="java.lang.Integer">
select DISTINCT product_id from storage_price where 1 = 1
<if test="storagePrice.storageId != null and storagePrice.storageId > 0">
and storage_id = #{storagePrice.storageId}
</if>
<if test="storagePrice.skup != null and storagePrice.skup > 0">
and skup = #{storagePrice.skup}
</if>
and seller_uid in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
order by create_time desc limit 300
</select>
<select id="selectStoragePriceCountBySellerUid" resultType="java.lang.Integer">
select count(*) from storage_price sp, storage s where sp.storage_id = s.id
<if test="storagePrice.status != null and storagePrice.status > -1">
and sp.status = #{storagePrice.status}
</if>
<if test="storagePrice.storageId != null and storagePrice.storageId > 0">
and sp.storage_id = #{storagePrice.storageId}
</if>
<if test="storagePrice.productId != null and storagePrice.productId > 0">
and sp.product_id = #{storagePrice.productId}
</if>
<if test="storagePrice.skup != null and storagePrice.skup > 0">
and sp.skup = #{storagePrice.skup}
</if>
<if test="storagePrice.sizeId != null and storagePrice.sizeId > 0">
and s.size_id = #{storagePrice.sizeId}
</if>
and sp.seller_uid in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectStoragePriceListBySellerUid" resultMap="BaseResultMap">
select sp.id, sp.skup, sp.product_id, s.goods_id, sp.storage_id, sp.depot_num, sp.seller_uid, sp.price, sp.status,
sp.update_time, sp.create_time
from storage_price sp, storage s where sp.storage_id = s.id
<if test="storagePrice.status != null and storagePrice.status > -1">
and sp.status = #{storagePrice.status}
</if>
<if test="storagePrice.storageId != null and storagePrice.storageId > 0">
and sp.storage_id = #{storagePrice.storageId}
</if>
<if test="storagePrice.productId != null and storagePrice.productId > 0">
and sp.product_id = #{storagePrice.productId}
</if>
<if test="storagePrice.skup != null and storagePrice.skup > 0">
and sp.skup = #{storagePrice.skup}
</if>
<if test="storagePrice.sizeId != null and storagePrice.sizeId > 0">
and s.size_id = #{storagePrice.sizeId}
</if>
and sp.seller_uid in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
order by sp.id desc limit #{start},#{rows}
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.product;
import com.yoho.ufo.dal.StoragePriceMapper;
import com.yoho.ufo.dal.model.StoragePrice;
import com.yoho.ufo.service.InfoPrintService;
import com.yoho.ufo.service.impl.SellerStoreMapUtil;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.request.product.InfoPrintRequestBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -12,9 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
/***
* @author peuei
... ... @@ -31,6 +33,12 @@ public class InfoPrintController {
@Resource
private InfoPrintService infoPrintService;
@Autowired
private SellerStoreMapUtil sellerStoreMapUtil;
@Autowired
private StoragePriceMapper storagePriceMapper;
/**
* 获得服务系统时间
*
... ... @@ -43,6 +51,22 @@ public class InfoPrintController {
}
/**
* 获取卖家ID 和 门店ID
*
* @return
*/
@RequestMapping(value = "/getSellerUidAndStoreId")
@ResponseBody
public ApiResponse getSellerUidAndStoreId(@RequestParam(name = "skup", required = true) String skup) {
StoragePrice storagePrice = storagePriceMapper.selectBySkup(Integer.valueOf(skup));
Integer storeId = sellerStoreMapUtil.getStoreIdBySellerUid(storagePrice.getSellerUid());
Map<String, Integer> map = new HashMap<>();
map.put("storeId", storeId);
map.put("sellerUid", storagePrice.getSellerUid());
return new ApiResponse(map);
}
/**
* 打印吊牌 将需要打印的数据放至 shops 服务中
*
* @param bo
... ...
package com.yoho.ufo.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.*;
/***
* @author peuei
* @date 2019/1/15 11:53
* @description 解析 sellerUid 和 storeId 的映射
* 形式如: storeId,sellerUid|storeId,sellerUid|storeId,sellerUid
*/
@Service
public class SellerStoreMapUtil {
private static Map<Integer, Integer> map = null;
@Value("${offline.store.seller}")
String defaultSellerUidData;
private Map<Integer, Integer> generateData() {
if (map != null && !map.isEmpty())
return map;
String[] result = StringUtils.split(defaultSellerUidData, "|");
if (result == null)
return null;
Map<Integer, Integer> convert = new HashMap<>();
Arrays.stream(result).forEach(ele -> {
String[] e = StringUtils.split(ele, ",");
convert.put(Integer.valueOf(e[0]), Integer.valueOf(e[1]));
});
map = convert;
return convert;
}
public Integer getSellerUidByStoreId(Integer storeId) {
Map<Integer, Integer> result = generateData();
if (result == null)
return null;
return result.get(storeId);
}
public Integer getStoreIdBySellerUid(Integer sellerUid) {
Map<Integer, Integer> result = generateData();
if (result == null)
return null;
for (Integer key : result.keySet()) {
if (sellerUid.equals(result.get(key)))
return key;
}
return null;
}
public List<Integer> getAllSellerUid() {
Map<Integer, Integer> result = generateData();
if (result == null)
return null;
List<Integer> list = new ArrayList<>();
for (Integer key : result.keySet()) {
list.add(result.get(key));
}
return list;
}
public Map<Integer, Integer> getMap() {
return generateData();
}
}
... ...
... ... @@ -32,7 +32,7 @@ public class StoragePriceService {
return null;
}
StoragePrice storagePrice = productConvertService.convertProduct2Skup(product);
StoragePrice storagePrice = productConvertService.convertProduct2Skup(product);
List<Integer> productIds = storagePriceMapper.selectProductIdsBySkupInfo(storagePrice);
... ... @@ -40,4 +40,22 @@ public class StoragePriceService {
return CollectionUtils.isEmpty(productIds) ? Lists.newArrayList() : productIds;
}
/**
* @param product
* @param sellerUid
* @return
*/
public List<Integer> selectProductIdByPlus(Product product, List<Integer> sellerUid) {
/**
* 如果不需要查询 sku-p 表则返回null
*/
if (sellerUid.isEmpty() &&
(null == product ||
(null == product.getStorageId() && null == product.getSkup() && null == product.getSellerUid())))
return null;
StoragePrice storagePrice = productConvertService.convertProduct2Skup(product);
List<Integer> productIds = storagePriceMapper.selectProductIdsBySkupInfoPlus(storagePrice, sellerUid);
return CollectionUtils.isEmpty(productIds) ? Lists.newArrayList() : productIds;
}
}
... ...
... ... @@ -51,7 +51,8 @@ public class StorageService {
@Autowired
private GoodsMapper goodsMapper;
private static final Integer DEFAULT_SELLER_UID = 500031170;
@Autowired
private SellerStoreMapUtil sellerStoreMapUtil;
private static final Integer DEFAULT_SKUP_STATUS = 1;
... ... @@ -89,6 +90,37 @@ public class StorageService {
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
/**
* @param bo
* @return
*/
public PageResponseBO<ProductResponceBo> storageListPlus(ProductRequestBo bo, List<Integer> sellerUid) {
Product product = OrikaUtils.map(bo, Product.class);
/**
* 获取 productId
*/
List<Integer> integerList = storagePriceService.selectProductIdByPlus(product, sellerUid);
if (null != integerList && integerList.isEmpty()) {
// 返回空列表 代表查询了storage_price 但查询的接口是空 再联合查询肯定也是空
return new PageResponseBO<>();
}
product.setProductIdList(integerList);
int count = productMapper.selectProductStorageCount(product);
if (count == 0) {
LOGGER.warn("StorageService storageListPlus count is 0.param = {}, sellerUid = {}", bo, sellerUid);
return new PageResponseBO<>();
}
List<Product> productList = productMapper.selectProductStorageList(product, bo.getStartIndex(), bo.getRows());
List<ProductResponceBo> responseBos = new ArrayList<>();
ProductResponceBo productResponseBo;
for (Product productItem : productList) {
productResponseBo = productConvertService.convertProductDo2Bo(productItem);
responseBos.add(productResponseBo);
}
productAssistService.fillBrandName(responseBos).fillSkupInfo(responseBos);
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
public PageResponseBO<ProductResponceBo> storagePriceList(ProductRequestBo bo) {
LOGGER.info("StorageService storagePriceList param = {}", bo);
... ... @@ -119,6 +151,23 @@ public class StorageService {
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
public PageResponseBO<ProductResponceBo> storagePriceListPlus(ProductRequestBo bo, List<Integer> sellerUid) {
StoragePrice storagePrice = productConvertService.convertBo2Skup(bo);
int count = storagePriceMapper.selectStoragePriceCountBySellerUid(storagePrice, sellerUid);
if (count == 0)
return new PageResponseBO<>();
List<StoragePrice> storagePriceList = storagePriceMapper.selectStoragePriceListBySellerUid(storagePrice, bo.getStartIndex(), bo.getRows(), sellerUid);
LOGGER.info("storagePriceListPlus method execute storagePriceList is {}", storagePriceList);
List<ProductResponceBo> responseBos = new ArrayList<>();
ProductResponceBo productResponseBo;
for (StoragePrice storagePriceItem : storagePriceList) {
productResponseBo = productConvertService.convertSkupDo2Bo(storagePriceItem);
responseBos.add(productResponseBo);
}
productAssistService.fillProductDetail(responseBos).fillGoodsColor(responseBos).fillSizeName(responseBos);
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
/**
* 门店商品 菜单栏专用查询
*
... ... @@ -127,8 +176,11 @@ public class StorageService {
*/
public PageResponseBO<ProductResponceBo> storageListLineShops(ProductRequestBo request) {
LOGGER.info("StorageService storageListLineShops param = {}", request);
request.setSellerUid(DEFAULT_SELLER_UID);
PageResponseBO<ProductResponceBo> productPageRsp = storageList(request);
/**
* seller_uid 取配置的uid 即seller_uid过滤是无效,由后台配置决定
*/
request.setSellerUid(null);
PageResponseBO<ProductResponceBo> productPageRsp = storageListPlus(request, sellerStoreMapUtil.getAllSellerUid());
/**
* 设置图片
*/
... ... @@ -138,7 +190,7 @@ public class StorageService {
return productPageRsp;
List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
List<StoragePrice> storagePricesList = storagePriceMapper.selectByProductIdsAndSellerUid(productIdList, DEFAULT_SELLER_UID, DEFAULT_SKUP_STATUS);
List<StoragePrice> storagePricesList = storagePriceMapper.selectByProductIdsAndSellerUid(productIdList, sellerStoreMapUtil.getAllSellerUid(), DEFAULT_SKUP_STATUS);
productList.forEach(respBo -> {
Goods goods = goodsMap.get(respBo.getId());
if (goods != null) {
... ... @@ -166,9 +218,12 @@ public class StorageService {
*/
public PageResponseBO<ProductResponceBo> storagePriceListLineShops(ProductRequestBo bo) {
LOGGER.info("StorageService storagePriceListLineShops param = {}", bo);
bo.setSellerUid(DEFAULT_SELLER_UID);
/**
* seller_uid 取配置的uid 即seller_uid过滤是无效,由后台配置决定
*/
bo.setSellerUid(null);
bo.setStatus(DEFAULT_SKUP_STATUS);
PageResponseBO<ProductResponceBo> result = storagePriceList(bo);
PageResponseBO<ProductResponceBo> result = storagePriceListPlus(bo, sellerStoreMapUtil.getAllSellerUid());
/**
* 排序 : 尺码小 价格低 创建时间前 的排序越靠前
*/
... ...
... ... @@ -43,4 +43,9 @@ ufo.live.notify.url = http://testapi.yohops.com/ufoLive/ufo_avthumb_notify
ufo.nfc.syncBlockChain.url=http://192.168.102.49:3030/api/addItem
shops.gateway.url=http://192.168.102.47:8080/portal-gateway
\ No newline at end of file
shops.gateway.url=http://192.168.102.47:8080/portal-gateway
ip.port.search.server=http://192.168.102.216:8080
offline.store.seller=70,500031170|1,500031974
... ...
... ... @@ -42,4 +42,10 @@ ufo.live.notify.url = ${ufo.live.notify.url}
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
shops.gateway.url=${shops.gateway.url}
\ No newline at end of file
shops.gateway.url=${shops.gateway.url}
ip.port.search.server=${ip.port.search.server}
offline.store.seller=${offline.store.seller}
... ...
... ... @@ -150,18 +150,30 @@
}
});
var param = {
type: "shopProduct",
header: "数据|码|EPC",
storeId: null,
DEFAULT_SELLER_UID: null,
codeList: []
};
// 执行打印吊牌标签
function editRow(skup) {
var param = {
type: "shopProduct",
header: "数据|码|EPC",
storeId: 1,
DEFAULT_SELLER_UID: 500031170,
codeList: []
};
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
async: false,
url: contextPath + "/infoPrint/getSellerUidAndStoreId?skup=" + skup,
success: function (result) {
param.storeId = result.data.storeId
param.DEFAULT_SELLER_UID = result.data.sellerUid
}
});
// 吊牌标签 : https://o.yohobuy.com/ufo?p=1,70555&skup=70555&productId=10006215&skn=10006215
var codeTemplate = "https://o.yohobuy.com/ufo?p={storeId_Uid}&skup={skup}&productId={skn}&skn={skn}";
var content = codeTemplate.replace('{storeId_Uid}', [param.storeId, ",", param.DEFAULT_SELLER_UID].join(""));
var codeTemplate = "https://o.yohobuy.com/ufo?p={storeId_Uid}&skup={skup}&skn={skn}";
var content = codeTemplate.replace('{storeId_Uid}', [param.DEFAULT_SELLER_UID, ",", param.storeId].join(""));
content = content.replace('{skup}', skup);
content = content.replace(new RegExp('{skn}', 'g'), productId);
$.ajax({
... ...