Authored by caoyan

Merge branch 'test6.9.12' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.12

Showing 25 changed files with 216 additions and 127 deletions
... ... @@ -12,4 +12,6 @@ public interface BrandMapper {
List<Brand> selectAll();
int updateByPrimaryKey(Brand record);
List<Integer> selectExcludeAppraise();
}
\ No newline at end of file
... ...
... ... @@ -8,10 +8,12 @@ import java.util.List;
public interface IdentifyRecordsMapper {
IdentifyRecord selectByTagAndNfcId(@Param("tagId") String tagId, @Param("nfcUid") String nfcUid);
int updateOwner(@Param("tagId") String tagId, @Param("nfcUid") String nfcUid, @Param("owner") Integer owner, @Param("newOrderCode")Long newOrderCode);
int updateAllowPop(@Param("tagId") String tagId, @Param("nfcUid") String nfcUid, @Param("allowPop") Integer allowPop);
IdentifyRecord selectByOrderCode(@Param("orderCode") Long orderCode);
IdentifyRecord selectByTagId(@Param("tagId") String tagId);
}
\ No newline at end of file
... ...
... ... @@ -48,4 +48,8 @@
edit_time, edit_pid, order_by
from brand
</select>
<select id="selectExcludeAppraise" resultMap="BaseResultMap">
select id
from brand where ex_raise = 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -47,4 +47,10 @@
select <include refid="Base_Column_List" />
from identify_records where order_code = #{orderCode} or last_order_code = #{orderCode} limit 1
</select>
<select id="selectByTagId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from identify_records where tag_id = #{tagId} limit 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -4,5 +4,4 @@ public interface ClientSpecialSemanticCode {
int needRealName = 440;
int WaitingPayLimit = 512;
int realNameMisMatch = 443;
int mobileMisMatch = 444;
}
... ...
... ... @@ -135,19 +135,6 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
//是否直接鉴定通过
boolean isDirectPass = false;
// 极速 不管是寄存还是发货 都需要通知卖家发货
if (fastDeliveryProxyService.isFastDeliveryGoods(orderInfo.getSkup())){
String wayBillCode = fastDeliveryProxyService.getVRWaybillCode(orderInfo.getOrderCode());
// 同时生成物流单号,通知第三方发货
fastDeliveryProxyService.order(orderInfo.getSkup(), wayBillCode);
// 卖家自动发货
executors.submit(()->{
expressInfoService.deliverToDepot(orderInfo.getSellerUid(), 0, orderInfo.getOrderCode(), wayBillCode, DepotType.NJ.getCode());
});
}
//门店订单支付后直接完成
if (BuyerOrderUtils.isOffline(orderInfo)) {
targetOrderStatus = OrderStatus.DONE;
... ... @@ -187,6 +174,19 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
}
}
orderInfo.setStatus(orderStatusCode);
// 极速 不管是寄存还是发货 都需要通知卖家发货
if (fastDeliveryProxyService.isFastDeliveryGoods(orderInfo.getSkup())){
String wayBillCode = fastDeliveryProxyService.getVRWaybillCode(orderInfo.getOrderCode());
// 同时生成物流单号,通知第三方发货
fastDeliveryProxyService.order(orderInfo.getSkup(), wayBillCode);
// 卖家自动发货
executors.submit(()->{
expressInfoService.deliverToDepot(orderInfo.getSellerUid(), 0, orderInfo.getOrderCode(), wayBillCode, DepotType.NJ.getCode());
});
}
return result;
}
... ...
... ... @@ -33,6 +33,7 @@ import com.yohoufo.order.service.impl.PaymentServiceImpl;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.setting.SellerWrapper;
import com.yohoufo.order.service.impl.TradeBillsService;
import com.yohoufo.order.utils.SellerHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -861,7 +862,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
private boolean isSuperWithoutLock(int uid){
SellerWrapper sellerWrapper = sellerService.getBaseSellerWrapper(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
return sellerBo.isNormalSuper() || sellerBo.isLargeSettlementSuper();
return SellerHelper.isSuper(sellerBo.getEntrySellerType());
}
private static class CalculateNode{
... ...
... ... @@ -377,14 +377,12 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
// 上架
List<ProductImportTranItemBo> responseList = Lists.newArrayList();
List<Integer> skupIds = Lists.newArrayList();
// 上架的代码(和之前同)
List<FastDeliveryBatchOnShelfResp> shelfResps = Lists.newArrayList();
for(FastDeliveryBatchOnShelfReq.ProductInfo productInfo : req.getProductInfos()){
StorageCheckResp storage = storageMap.get(getProductCodeSizeNameKey(productInfo.getProductCode(), productInfo.getSizeName()));
if (storage == null){
if (storage == null || storage.getStorageId() == null){
logger.warn("productCode {} and sizeName {}. storageId not exist.", productInfo.getProductCode(), productInfo.getSizeName());
throw new UfoServiceException(403, "货号和尺寸对应的storageId不存在");
}
... ... @@ -487,7 +485,7 @@ public class ErpFastDeliveryServiceImpl implements IErpFastDeliveryService {
private ProductImportTranItemBo buildShelfResp(FastDeliveryBatchOnShelfReq req, FastDeliveryBatchOnShelfReq.ProductInfo productInfo,
SellerOrderSubmitHandler.ForkJoinResult fjr) {
// 构造结果对象 最终结果插入到 商品服务的product_import_tran_item表中
// 构造结果对象 最终结果插入到 商品服务的 product_import_tran_item 表中
ProductImportTranItemBo productImportTranItemBo = new ProductImportTranItemBo();
productImportTranItemBo.setUid(req.getUid());
productImportTranItemBo.setProductCode(productInfo.getProductCode());
... ...
... ... @@ -71,18 +71,12 @@ public class ShoppingRiskWatchDog {
logger.warn("checkOverseaOrderUserInfo: need realName cert, uid is {}", uid);
throw new UfoServiceException(ClientSpecialSemanticCode.needRealName, "请完成实名认证后操作");
}
//(3) 校验和收件人的姓名,手机号是否一致
//(3) 校验收件人姓名是否和实名认证的姓名一致
String buyerName = zhimaCert.getCertName();
String receiverName = addressInfo.getConsignee();
if(!buyerName.equals(receiverName)){
logger.warn("checkOverseaOrderUserInfo: name not match, receiverName is {}, buyerMobile is {}", receiverName, buyerName);
throw new UfoServiceException(ClientSpecialSemanticCode.realNameMisMatch, "收件人姓名必须与实名认证信息一致");
}
String buyerMobile = userProxyService.getMobile(uid);
String receiverMobile = addressInfo.getMobile();
if(!buyerMobile.equals(receiverMobile)){
logger.warn("checkOverseaOrderUserInfo: mobile not match, receiverMobile is {}, buyerMobile is {}", receiverMobile, buyerMobile);
throw new UfoServiceException(ClientSpecialSemanticCode.mobileMisMatch, "收件人手机号必须与账号对应手机号一致");
throw new UfoServiceException(ClientSpecialSemanticCode.realNameMisMatch, "收件人姓名必须与实名认证的姓名一致");
}
}
... ...
... ... @@ -552,7 +552,7 @@ public class ShoppingServiceImpl implements IShoppingService {
//查询并校验用户地址
Pair<AddressInfo, AddressInfo> userAddressPair = getAndCheckAddressInfo(shoppingRequest);
//若购买的是香港仓商品,uid必须实名认证,且姓名和手机号必须与收货人一致
//若购买的是香港仓商品,uid必须实名认证,收货人姓名必须和实名认证姓名一致
shoppingRiskWatchDog.checkOverseasOrderUserInfo(uid, psog.getAttributes(), userAddressPair.getKey());
//算费
... ...
... ... @@ -47,7 +47,7 @@ public class FastDeliveryProxyService {
public boolean isOnToThird(){
return configReader.getBoolean("ufo.fast.delivery.toThired", true);
return configReader.getBoolean("ufo.fast.delivery.toThird", true);
}
/**
... ...
... ... @@ -1076,6 +1076,22 @@ public class InBoxFacade extends BaseNoticeFacade{
}
}
public void noticeFastDeliverySeller(Integer uid, BigDecimal theshold){
String logPrefix = "notice fast delivery seller";
try{
newNotice(uid)
.withLogPrefix(logPrefix)
.withInBox(InboxBusinessTypeEnum.FAST_DELIVERY_SELLER_PART_FUNC, theshold)
.withSms(InboxBusinessTypeEnum.SMS_FAST_DELIVERY_SELLER_PERMISSION, theshold)
.send();
}catch (Exception e){
}
}
public void noticeSuperSellerDegrade(Integer uid, SuperEnterStageLevel sesl, BigDecimal leftInWallet) {
String logPrefix = "notice super seller degrade";
try {
... ...
... ... @@ -472,8 +472,22 @@ public class SellerEnterApplyService {
EntryThreshold set = estMap.get(currentEST);
Supplier<SellerLevelFuncBo> slfSupplier = () ->SellerHelper.getSellerLevelFunc(currentEST, set, left);
//目标身份对应的等级
logger.info("in changeLevel4Super ready change StoredSeller targetFuncLevel func, uid {} currentEnterType {}",
uid, currentEnterType);
logger.info("in changeLevel4Super ready change StoredSeller targetFuncLevel func, uid {} currentEnterType {}, {}",
uid, currentEnterType, left);
// 扣保证金 极速卖家场景-触发阀值场景
if (sellerBo.isFastDeliverySuper()){
if (left.compareTo(set.getPrepaymentAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, set.getPrepaymentAmount());
}else if(left.compareTo(set.getGoodsOnOffShelveAmount())<0 && left.compareTo(set.getHiddenGoodsAmount())>=0){
inBoxFacade.noticeFastDeliverySeller(uid, set.getGoodsOnOffShelveAmount());
}else if(left.compareTo(set.getHiddenGoodsAmount())<0){
inBoxFacade.noticeFastDeliverySeller(uid, set.getHiddenGoodsAmount());
}
return 0;
}
int result = 0;
if (sellerBo.isNormalSuper()) {
... ... @@ -493,7 +507,10 @@ public class SellerEnterApplyService {
inBoxFacade.noticeSuperSellerDegrade(uid, targetSESL, bslfb.getWalletThreshold());
}
processLargeSettlementSuperWhenWalletChange(sellerWrapper, left, slfSupplier);
if (sellerBo.isLargeSettlementSuper() ){
processLargeSettlementSuperWhenWalletChange(sellerWrapper, left, slfSupplier);
}
return result;
}
... ...
... ... @@ -303,6 +303,7 @@ public class SellerService {
List<EntrySellerType> targetESTs = new ArrayList<>(2);
targetESTs.add(EntrySellerType.SUPER_ENTRY);
targetESTs.add(EntrySellerType.LARGE_SETTLEMENT);
targetESTs.add(EntrySellerType.FAST_DELIVERY_SUPER);
if (!targetESTs.contains(currentEST)){
logger.warn("processAfterWalletChange user was {} , uid {}", currentEST , uid);
return ;
... ...
package com.yohoufo.order.service.support;
import com.google.common.collect.Lists;
import com.yoho.core.config.ConfigReader;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.constants.DeliveryWayEnum;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
... ... @@ -15,6 +16,7 @@ import com.yohoufo.order.utils.MathUtils;
import com.yohoufo.order.utils.OrderDetailDescHelper;
import com.yohoufo.order.utils.SellerGoodsHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
... ... @@ -24,6 +26,10 @@ import java.util.Objects;
@Service
public class ShoppingSupport {
@Autowired
private ConfigReader configReader;
/**
* 支付方式
* @return
... ... @@ -273,10 +279,27 @@ public class ShoppingSupport {
public DepositResp getDepositResp(SkupType skupType){
DepositResp depositResp = null;
if(SellerGoodsHelper.canDeposit(skupType)){
//若订单类型支持寄存,且开关已打开,则页面展示寄存
if(SellerGoodsHelper.canDeposit(skupType) && isDepositSwitchOpen(skupType)){
SkupType target = SellerGoodsHelper.getTargetSkupType4DepositOrder(OrderAttributes.DEPOSITE.getCode(), skupType);
depositResp = DepositResp.builder().desc(OrderDetailDescHelper.getPaymentDepositDesc(target)).depositable(OrderConstant.Y_STR).build();
}
return depositResp;
}
private boolean isDepositSwitchOpen(SkupType skupType){
boolean depositSwitchStatus ;
switch (skupType){
case IN_STOCK://现货寄存
depositSwitchStatus = configReader.getBoolean("ufo.order.deposit.inStock.switch", false);break;
case QUICK_DELIVER://闪购寄存
depositSwitchStatus = configReader.getBoolean("ufo.order.deposit.quickDeliver.switch", false);break;
case FAST_DELIVERY://极速寄存
depositSwitchStatus = configReader.getBoolean("ufo.order.deposit.fastDeliver.switch", false);break;
default:
depositSwitchStatus = false;
}
return depositSwitchStatus;
}
}
... ...
... ... @@ -80,6 +80,7 @@ public final class SellerGoodsHelper {
switch (skupType){
case IN_STOCK:
case QUICK_DELIVER:
case FAST_DELIVERY:
result = true;
break;
default: result = false;
... ...
... ... @@ -189,4 +189,26 @@ public class ProductIdentifyController {
return new ApiResponse.ApiResponseBuilder().code(402).message("操作失败,请稍后重试").build();
}
}
@ApiOperation(name = "ufo.product.shareIdentifyInfo", desc="NFC分享")
@ApiParam(name="tagId",required = true,desc="NFC标签id",type=Integer.class)
@ApiResp(dataClazz=ProductIdentifyResp.class, desc="NFC分享")
@ApiRespCode(code=200,desc="查询成功")
@ApiRespCode(code=402,desc="查询失败")
@IgnoreSignature
@RequestMapping(params = "method=ufo.product.shareIdentifyInfo")
public ApiResponse shareIdentifyInfo(@RequestParam(value = "tagId", required = true) String tagId) throws GatewayException {
logger.info("enter shareIdentifyInfo with tagId={}", tagId);
try{
ProductIdentifyResp info = identifyService.queryShareIdentifyInfo(tagId);
info.setTagId(tagId);
return new ApiResponse.ApiResponseBuilder().code(200).data(info).build();
}catch (Exception e){
logger.warn("shareIdentifyInfo error! tagId={}", tagId);
if( e instanceof GatewayException){
throw e;
}
return new ApiResponse.ApiResponseBuilder().code(402).message("查询失败,请稍后重试").build();
}
}
}
\ No newline at end of file
... ...
... ... @@ -330,7 +330,7 @@ public class ProductSearchController {
}
@ApiOperation(name = "ufo.product.search.appraise.list", desc="首页商品推荐")
@RequestMapping(params = "method=ufo.product.appraise.list")
@RequestMapping(params = "method=ufo.product.search.appraise.list")
@IgnoreSession
@Cachable(expire = 180)
public ApiResponse searchAppraiseProductList(
... ... @@ -339,7 +339,7 @@ public class ProductSearchController {
@RequestParam(value = "page", required = false)Integer page,
@RequestParam(value = "app_version", required = false)String appVersion
) {
ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page).setExcludeLimit("true");
ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page).setExcludeLimit("Y");
searchHelpService.setQuery(query, req);
//设置是否包含有货商品
LOG.info("in method=ufo.product.search.appraise.list req={}", req.toString());
... ...
... ... @@ -84,6 +84,8 @@ public final class SearchConstants {
String SOON_SALE = "isSoonSale";
String NOT_ID = "not_id";
String NOT_BRAND = "not_brand";
String FILTER_YEAR_MONTH = "filter_year_month";
... ... @@ -95,7 +97,7 @@ public final class SearchConstants {
String RANK_TYPE = "rankType";
String TYPE = "product_type";
String EXCLUDE_LIMIT = "exclude_limit";
String EXCLUDE_LIMIT = "isFilterLimitSale";
}
... ...
... ... @@ -57,7 +57,8 @@ public class SearchParam {
.setContainYoho(req.getContainYoho())
.setRankType(req.getRankType())
.setNotId(req.getNot_id())
.setExcludeLimit(req.getExcludeLimit());
.setExcludeLimit(req.getExcludeLimit())
.setNotBrand(req.getNot_brand());
return this;
}
... ... @@ -70,7 +71,7 @@ public class SearchParam {
.setStartTime(req.getStartTime())
.setEndTime(req.getEndTime())
.setContainYoho(req.getContainYoho())
.setRankType(req.getRankType()).setId(req.getId()).setNotId(req.getNot_id()).setExcludeLimit(req.getExcludeLimit());;
.setRankType(req.getRankType()).setId(req.getId()).setNotId(req.getNot_id()).setExcludeLimit(req.getExcludeLimit()).setNotBrand(req.getNot_brand());
return this;
}
... ... @@ -237,6 +238,13 @@ public class SearchParam {
return this;
}
public SearchParam setNotBrand(String notBrand) {
if (StringUtils.isNotBlank(notBrand)) {
param.put(SearchConstants.IndexNameConstant.NOT_BRAND, notBrand);
}
return this;
}
/**
* 每次查询的条数
*
... ...
... ... @@ -27,6 +27,7 @@ public class ProductSearchReq {
private String rankType;
private String couponToken;
private String excludeLimit;
private String not_brand;
@Override
public String toString() {
... ... @@ -256,6 +257,15 @@ public class ProductSearchReq {
return this;
}
public ProductSearchReq setNotBrand(String notBrand) {
this.not_brand = notBrand;
return this;
}
public String getNot_brand() {
return not_brand;
}
public String getExcludeLimit() {
return excludeLimit;
}
... ...
... ... @@ -14,8 +14,10 @@ public interface ProductIdentifyService {
ProductIdentifyResp queryIdentifyInfo(String tagId, String nfcUid) throws GatewayException;
IdentifyShareInfoResp getShareIdentifyInfo( String tagId, String nfcUid) throws GatewayException;
ProductIdentifyResp queryNewIdentifyInfo(String tagId, String nfcUid, Integer uid) throws GatewayException;
ProductIdentifyResp queryShareIdentifyInfo(String tagId) throws GatewayException;
int applyToBeOwner(String tagId, String nfcUid, Integer uid) throws GatewayException;
... ...
... ... @@ -1086,4 +1086,23 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
transferRecords.setOrderCode(null == orderCode ? 0L : orderCode);
transferRecordsMapper.insert(transferRecords); //增加记录到transfer_records
}
@Override
public ProductIdentifyResp queryShareIdentifyInfo(String tagId) throws GatewayException {
try {
ProductIdentifyResp result = new ProductIdentifyResp();
IdentifyRecord record = identifyRecordsMapper.selectByTagId(tagId);
if (null != record) {
result = queryNewIdentifyInfo(record.getTagId(), record.getNfcUid(), record.getOwner());
} else {
logger.warn("queryShareIdentifyInfo is not exist, tagId={}", tagId);
}
return result;
} catch (Exception err) {
throw new GatewayException(402, "鉴定信息不存在");
}
}
}
... ...
... ... @@ -13,6 +13,7 @@ import java.util.stream.Collectors;
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.dal.product.BrandMapper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -72,6 +73,9 @@ public class ProductSearchServiceImpl implements ProductSearchService {
private ProductSortMapper productSortMapper;
@Autowired
private BrandMapper brandMapper;
@Autowired
ProductSalesService productSalesService;
@Autowired
... ... @@ -183,6 +187,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
@Override
public JSONObject searchAppraiseProductList(ProductSearchReq req) {
req.setNotBrand(StringUtils.join(brandMapper.selectExcludeAppraise(), ","));
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
String url = PRODUCT_SEARCH_QUERY_URL;
JSONObject data = search(searchParam.getParam(), url);
... ...
package com.yohoufo.product.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.UUID;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
... ... @@ -2026,9 +2017,9 @@ public class ProductServiceImpl implements ProductService {
Map<String, List<GoodsBO>> tabs = new HashMap<>();
tabs.put("goods_list", Arrays.asList(goodsBO));
tabs.put("pre_sale_goods_list", Arrays.asList(preSaleGoodsBO));
tabs.put("seconds_goods_list", Arrays.asList(goodsBO));
tabs.put("seconds_goods_list", Arrays.asList(secondsGoodsBO));
product_info.setGoodsListTabs(tabs);
product_info.setGoodsList(null);
allGoodsBO.setSizeList(allSizeList);
}
}
... ... @@ -2133,9 +2124,9 @@ public class ProductServiceImpl implements ProductService {
}
return sp2;
}
private boolean notAllNull(Object... obj) {
for (Object o : obj) {
if (o != null) {
private boolean notAllNull(Integer... numbers) {
for (Integer n : numbers) {
if (n != null && n > 0) {
return true;
}
}
... ... @@ -2144,28 +2135,17 @@ public class ProductServiceImpl implements ProductService {
@Override
public List<StorageCheckResp> getStorageByCodeAndColorName(List<ProductRequestBo> reqList) {
List<StorageCheckResp> result = new ArrayList<>();
LOGGER.info("method ProductServiceImpl.getStorageByCodeAndColorName in, params is {}", reqList);
// 返回结果
List<StorageCheckResp> result = new ArrayList<>();
// 请求参数中的货号
List<String> reqProductCode = new ArrayList<>();
// 系统中有的货号
List<String> resultProductCode = new ArrayList<>();
// 系统中货号对应的productIds
List<Integer> productIds = new ArrayList<>();
HashMap<Integer, String> productIdAndCode = new HashMap<>();
// 请求参数中的尺码名称
List<String> reqSizeName = new ArrayList<>();
// 系统中的尺码名称
List<String> resultSizeName = new ArrayList<>();
HashMap<Integer, String> sizeIdAndName = new HashMap<>();
List<Integer> resultSizeIds = new ArrayList<>();
if (CollectionUtils.isEmpty(reqList)) {
LOGGER.error("getStorageByCodeAndColorName 参数错误, reqList = {}", reqList);
throw new ServiceException(400, "参数错误");
}
... ... @@ -2173,72 +2153,49 @@ public class ProductServiceImpl implements ProductService {
reqList.stream().forEach(item -> {
reqProductCode.add(item.getProductCode());
reqSizeName.add(item.getSizeName());
result.add(OrikaUtils.map(item, StorageCheckResp.class));
// 默认货号不存在
StorageCheckResp resultItem = OrikaUtils.map(item, StorageCheckResp.class);
setStorageCheckRespStatusInfo(resultItem, StorageCheckEnum.PRODUCT_NOT_FOUND.getType());
result.add(resultItem);
});
LOGGER.info("int reqProductCode lengh= {}", resultProductCode.size());
// 2. 查询 productCode 对应的product_id, 根据product_id 查询storage
List<Product> products = productMapper.selectByCodes(reqProductCode);
// 货号都不存在
if (CollectionUtils.isEmpty(products)) {
for(StorageCheckResp item : result) {
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_NOT_FOUND.getType());
}
return result;
}
products.stream().forEach(item -> {
productIds.add(item.getId());
resultProductCode.add(item.getProductCode());
productIdAndCode.put(item.getId(), item.getProductCode());
});
LOGGER.info("int resultProductCode lengh= {}", resultProductCode.size());
// 3.查询系统中的库存
List<Storage> storages = storageMapper.selectByProductIds(productIds);
// 4. 查询 sizeName 对应的size_id
List<Size> sizes = sizeMapper.selectByNames(reqSizeName);
sizes.stream().forEach(item->{
resultSizeName.add(item.getSizeName());
resultSizeIds.add(item.getId());
sizeIdAndName.put(item.getId(), item.getSizeName());
});
// 5. 标记检测情况
// 5.1 不存在的货号
reqProductCode.removeAll(resultProductCode);
// 5.2 不存在的尺码名称
reqSizeName.removeAll(resultSizeName);
loop: for(StorageCheckResp item : result) {
// 不存在的货号
if (reqProductCode.contains(item.getProductCode())) {
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_NOT_FOUND.getType());
LOGGER.info("货号不存在 = {}", item);
continue;
// 2. 查询 productCode/product_id对应关系
List<Integer> productIds = new ArrayList<>();
Map<String, Integer> productCodeIdMap = productMapper.selectByCodes(reqProductCode).stream().map(item -> {productIds.add(item.getId()); return item;}).collect(Collectors.toMap(Product::getProductCode, Product::getId));
// 3. 查询 sizeId/sizeName对应关系
Set<String> sizeNamesSet = new HashSet<>();
Map<Integer, String> sizeIdNameMap = sizeMapper.selectByNames(reqSizeName).stream().map(item -> {
sizeNamesSet.add(item.getSizeName());
return item;}).collect(Collectors.toMap(Size::getId, Size::getSizeName));
// 4.查询所有productCode 的库存
Map<Integer, List<Storage>> storagesMap = storageMapper.selectByProductIds(productIds).stream().collect(Collectors.groupingBy(Storage::getProductId));
// 5.标记查询结果
result.stream().map(item -> {
// 获取productCode 库存信息
List<Storage> storages = storagesMap.get(productCodeIdMap.get(item.getProductCode()));
if (null == storages) {
return item;
}
// 不存在的尺码
if (reqSizeName.contains(item.getSizeName())) {
LOGGER.info("尺码名称不存在 = {}", item);
// 尺码不存在
if (!sizeNamesSet.contains(item.getSizeName())) {
setStorageCheckRespStatusInfo(item, StorageCheckEnum.SIZE_NOT_FOUND.getType());
continue;
return item;
}
for(Storage storage : storages) {
// 货号和尺码匹配
if (item.getProductCode().equals(productIdAndCode.get(storage.getProductId())) && item.getSizeName().equals(sizeIdAndName.get(storage.getSizeId()))) {
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_MATCH.getType());
item.setStorageId(storage.getId());
continue loop;
// sizeName 匹配
storages.stream().forEach(storage -> {
if (null != sizeIdNameMap.get(storage.getSizeId()) && sizeIdNameMap.get(storage.getSizeId()).equals(item.getSizeName())){
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_MATCH.getType());
item.setStorageId((storage.getId()));
}
}
});
return item;
// 货号和尺码不匹配
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_NOT_MATCH.getType());
}
}).collect(Collectors.toList());
return result;
}
... ...