Authored by Lixiaodi

Merge branch 'dev_极速发货' of http://git.yoho.cn/ufo/yohoufo-fore into dev_极速发货

# Conflicts:
#	product/src/main/java/com/yohoufo/product/controller/ProductController.java
#	product/src/main/java/com/yohoufo/product/service/ProductService.java
#	product/src/main/java/com/yohoufo/product/service/impl/ProductServiceImpl.java
... ... @@ -21,4 +21,7 @@ public interface ProductMapper {
List<Product> selectByProductCode(@Param("productCode") String productCode);
String selectIntroByProductId(Integer id);
List<Product> selectByCodes(List<String> codes);
}
\ No newline at end of file
... ...
... ... @@ -16,7 +16,9 @@ public interface SizeMapper {
int updateByPrimaryKey(Size record);
List<Size> selectByIds(List<Integer> ids);
List<Size> selectByNames(List<String> names);
/**
* 根据品类查询所有的尺码
* @param sortId
... ...
... ... @@ -28,4 +28,6 @@ public interface StorageMapper {
List<Storage> selectByIds(@Param("idList") Collection<Integer> idList);
List<Storage> selectByProductId(@Param("productId") Integer productId);
List<Storage> selectByProductIds(@Param("productIds") List<Integer> productIds);
}
\ No newline at end of file
... ...
... ... @@ -95,4 +95,11 @@
from product_intro
where product_id = #{productId} limit 1
</select>
<select id="selectByCodes" resultMap="BaseResultMap">
select id, product_name, product_code, series_id from product where product_code in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -45,6 +45,14 @@
</foreach>
order by order_by
</select>
<select id="selectByNames" resultMap="BaseResultMap">
select id, size_name, order_by
from `size` where size_name in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectAllSizeBySortIdList" resultMap="BaseResultMap">
select s.id, s.size_name,ss.order_by
... ...
... ... @@ -89,6 +89,17 @@
</foreach>
</select>
<select id="selectByProductIds" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time, suggest_low_price, suggest_high_price
from storage
where product_id in
<foreach item="id" collection="productIds" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="selectByProductId" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, suggest_low_price, suggest_high_price
from storage where product_id=#{productId,jdbcType=INTEGER} AND status = 1
... ...
... ... @@ -18,6 +18,8 @@ import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohobuy.ufo.model.response.StorageInfoResp;
import com.yohobuy.ufo.model.response.StorageCheckResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
... ... @@ -52,7 +54,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@RestController
public class ProductController {
... ... @@ -950,4 +951,13 @@ public class ProductController {
return ufoServiceCaller.call("ufo.resource.product", ApiResponse.class, StringUtils.join(poolIds, ","), clientType);
}
@ApiOperation(name = "ufo.product.storage", desc = "根据货号尺码颜色查询storage")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.storage")
public ApiResponse getStorageByCodeAndColorName(@RequestBody List<ProductRequestBo> reqList) {
LOG.info("Enter getStorageByCodeAndColorName with req={}", reqList);
List<StorageCheckResp> resp = productService.getStorageByCodeAndColorName(reqList);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product data").build();
}
}
\ No newline at end of file
... ...
... ... @@ -9,7 +9,9 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.ufo.model.ProductInfo;
import com.yohobuy.ufo.model.request.StoragePriceBo;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohobuy.ufo.model.response.StorageCheckResp;
import com.yohobuy.ufo.model.response.StorageInfoResp;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.model.SkupInfo;
... ... @@ -135,4 +137,11 @@ public interface ProductService {
List<StorageInfoResp> queryLeastOnSalePrice(String productCode);
void tabsGoods(ProductDetailResp resp);
/**
* 根据货号尺码查询storage
* @param reqList
* @return
*/
List<StorageCheckResp> getStorageByCodeAndColorName(List<ProductRequestBo> reqList);
}
... ...
... ... @@ -16,8 +16,11 @@ import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.response.StorageCheckResp;
import com.yohobuy.ufo.model.response.store.StoreInfoBo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.utils.OrikaUtils;
import com.yohoufo.dal.product.*;
import com.yohoufo.dal.product.model.*;
import org.apache.commons.collections.MapUtils;
... ... @@ -33,7 +36,7 @@ import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.servlet.ModelAndView;
import com.yohobuy.ufo.model.enums.StorageCheckEnum;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
... ... @@ -68,6 +71,7 @@ import com.yohoufo.product.response.SkupDetailForScreenResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductSearchService;
import com.yohoufo.product.service.ProductService;
import com.yohoufo.dal.product.model.Size;
@Service
... ... @@ -206,7 +210,7 @@ public class ProductServiceImpl implements ProductService {
BigDecimal quickDeliveryLeastPrice = quickDeliveryLeastPriceList.stream().min((p1, p2) -> (p1.compareTo(p2))).get();
productInfo.setQuickDeliveryPrice(quickDeliveryLeastPrice);
}
goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy));
List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsSizes);
if(!CollectionUtils.isEmpty(otherAddSizeList)) {
... ... @@ -2078,7 +2082,7 @@ public class ProductServiceImpl implements ProductService {
/**
* 根据编码查询货号 名称 和图片 商品颜色
* @param productId
* @param productIds
* @return
*/
public Map<Integer, ProductInfo> queryProductInfoMap(List<Integer> productIds) {
... ... @@ -2138,4 +2142,115 @@ public class ProductServiceImpl implements ProductService {
return false;
}
@Override
public List<StorageCheckResp> getStorageByCodeAndColorName(List<ProductRequestBo> 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)) {
throw new ServiceException(400, "参数错误");
}
// 1. 获取参数中的productCode, sizeName,
reqList.stream().forEach(item -> {
reqProductCode.add(item.getProductCode());
reqSizeName.add(item.getSizeName());
result.add(OrikaUtils.map(item, StorageCheckResp.class));
});
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;
}
// 不存在的尺码
if (reqSizeName.contains(item.getSizeName())) {
LOGGER.info("尺码名称不存在 = {}", item);
setStorageCheckRespStatusInfo(item, StorageCheckEnum.SIZE_NOT_FOUND.getType());
continue;
}
for(Storage storage : storages) {
// 货号和尺码匹配
if (item.getProductCode() == productIdAndCode.get(storage.getProductId()) && item.getSizeName() == sizeIdAndName.get(storage.getSizeId())) {
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_MATCH.getType());
continue loop;
}
}
// 货号和尺码不匹配
setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_NOT_MATCH.getType());
}
return result;
}
/**
* 设置检测结果状态信息
* @param item
* @param status
* @return
*/
private StorageCheckResp setStorageCheckRespStatusInfo(StorageCheckResp item, Integer status) {
item.setStatus(status);
item.setStatusStr(StorageCheckEnum.getTypeName(status));
return item;
}
}
... ...