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
Showing
9 changed files
with
172 additions
and
5 deletions
@@ -21,4 +21,7 @@ public interface ProductMapper { | @@ -21,4 +21,7 @@ public interface ProductMapper { | ||
21 | List<Product> selectByProductCode(@Param("productCode") String productCode); | 21 | List<Product> selectByProductCode(@Param("productCode") String productCode); |
22 | 22 | ||
23 | String selectIntroByProductId(Integer id); | 23 | String selectIntroByProductId(Integer id); |
24 | + | ||
25 | + List<Product> selectByCodes(List<String> codes); | ||
26 | + | ||
24 | } | 27 | } |
@@ -16,7 +16,9 @@ public interface SizeMapper { | @@ -16,7 +16,9 @@ public interface SizeMapper { | ||
16 | int updateByPrimaryKey(Size record); | 16 | int updateByPrimaryKey(Size record); |
17 | 17 | ||
18 | List<Size> selectByIds(List<Integer> ids); | 18 | List<Size> selectByIds(List<Integer> ids); |
19 | - | 19 | + |
20 | + List<Size> selectByNames(List<String> names); | ||
21 | + | ||
20 | /** | 22 | /** |
21 | * 根据品类查询所有的尺码 | 23 | * 根据品类查询所有的尺码 |
22 | * @param sortId | 24 | * @param sortId |
@@ -28,4 +28,6 @@ public interface StorageMapper { | @@ -28,4 +28,6 @@ public interface StorageMapper { | ||
28 | List<Storage> selectByIds(@Param("idList") Collection<Integer> idList); | 28 | List<Storage> selectByIds(@Param("idList") Collection<Integer> idList); |
29 | 29 | ||
30 | List<Storage> selectByProductId(@Param("productId") Integer productId); | 30 | List<Storage> selectByProductId(@Param("productId") Integer productId); |
31 | + | ||
32 | + List<Storage> selectByProductIds(@Param("productIds") List<Integer> productIds); | ||
31 | } | 33 | } |
@@ -95,4 +95,11 @@ | @@ -95,4 +95,11 @@ | ||
95 | from product_intro | 95 | from product_intro |
96 | where product_id = #{productId} limit 1 | 96 | where product_id = #{productId} limit 1 |
97 | </select> | 97 | </select> |
98 | + <select id="selectByCodes" resultMap="BaseResultMap"> | ||
99 | + select id, product_name, product_code, series_id from product where product_code in | ||
100 | + <foreach item="item" index="index" collection="list" | ||
101 | + open="(" separator="," close=")"> | ||
102 | + #{item} | ||
103 | + </foreach> | ||
104 | + </select> | ||
98 | </mapper> | 105 | </mapper> |
@@ -45,6 +45,14 @@ | @@ -45,6 +45,14 @@ | ||
45 | </foreach> | 45 | </foreach> |
46 | order by order_by | 46 | order by order_by |
47 | </select> | 47 | </select> |
48 | + <select id="selectByNames" resultMap="BaseResultMap"> | ||
49 | + select id, size_name, order_by | ||
50 | + from `size` where size_name in | ||
51 | + <foreach item="item" index="index" collection="list" | ||
52 | + open="(" separator="," close=")"> | ||
53 | + #{item} | ||
54 | + </foreach> | ||
55 | + </select> | ||
48 | 56 | ||
49 | <select id="selectAllSizeBySortIdList" resultMap="BaseResultMap"> | 57 | <select id="selectAllSizeBySortIdList" resultMap="BaseResultMap"> |
50 | select s.id, s.size_name,ss.order_by | 58 | select s.id, s.size_name,ss.order_by |
@@ -89,6 +89,17 @@ | @@ -89,6 +89,17 @@ | ||
89 | </foreach> | 89 | </foreach> |
90 | </select> | 90 | </select> |
91 | 91 | ||
92 | + <select id="selectByProductIds" resultMap="BaseResultMap"> | ||
93 | + select id, product_id, goods_id, size_id, storage_num, update_time, create_time, suggest_low_price, suggest_high_price | ||
94 | + from storage | ||
95 | + where product_id in | ||
96 | + <foreach item="id" collection="productIds" open="(" separator="," close=")"> | ||
97 | + #{id} | ||
98 | + </foreach> | ||
99 | + </select> | ||
100 | + | ||
101 | + | ||
102 | + | ||
92 | <select id="selectByProductId" resultMap="BaseResultMap"> | 103 | <select id="selectByProductId" resultMap="BaseResultMap"> |
93 | select id, product_id, goods_id, size_id, storage_num, suggest_low_price, suggest_high_price | 104 | select id, product_id, goods_id, size_id, storage_num, suggest_low_price, suggest_high_price |
94 | from storage where product_id=#{productId,jdbcType=INTEGER} AND status = 1 | 105 | from storage where product_id=#{productId,jdbcType=INTEGER} AND status = 1 |
@@ -18,6 +18,8 @@ import com.yohobuy.ufo.model.request.product.ProductRequestBo; | @@ -18,6 +18,8 @@ import com.yohobuy.ufo.model.request.product.ProductRequestBo; | ||
18 | import com.yohobuy.ufo.model.response.ProductDetailResp; | 18 | import com.yohobuy.ufo.model.response.ProductDetailResp; |
19 | import com.yohobuy.ufo.model.response.StorageDataResp; | 19 | import com.yohobuy.ufo.model.response.StorageDataResp; |
20 | import com.yohobuy.ufo.model.response.StorageInfoResp; | 20 | import com.yohobuy.ufo.model.response.StorageInfoResp; |
21 | +import com.yohobuy.ufo.model.response.StorageCheckResp; | ||
22 | + | ||
21 | import com.yohoufo.common.ApiResponse; | 23 | import com.yohoufo.common.ApiResponse; |
22 | import com.yohoufo.common.annotation.IgnoreSession; | 24 | import com.yohoufo.common.annotation.IgnoreSession; |
23 | import com.yohoufo.common.annotation.IgnoreSignature; | 25 | import com.yohoufo.common.annotation.IgnoreSignature; |
@@ -52,7 +54,6 @@ import java.util.concurrent.ExecutorService; | @@ -52,7 +54,6 @@ import java.util.concurrent.ExecutorService; | ||
52 | import java.util.concurrent.Executors; | 54 | import java.util.concurrent.Executors; |
53 | import java.util.stream.Collectors; | 55 | import java.util.stream.Collectors; |
54 | 56 | ||
55 | - | ||
56 | @RestController | 57 | @RestController |
57 | public class ProductController { | 58 | public class ProductController { |
58 | 59 | ||
@@ -950,4 +951,13 @@ public class ProductController { | @@ -950,4 +951,13 @@ public class ProductController { | ||
950 | return ufoServiceCaller.call("ufo.resource.product", ApiResponse.class, StringUtils.join(poolIds, ","), clientType); | 951 | return ufoServiceCaller.call("ufo.resource.product", ApiResponse.class, StringUtils.join(poolIds, ","), clientType); |
951 | } | 952 | } |
952 | 953 | ||
954 | + @ApiOperation(name = "ufo.product.storage", desc = "根据货号尺码颜色查询storage") | ||
955 | + @IgnoreSignature | ||
956 | + @IgnoreSession | ||
957 | + @RequestMapping(params = "method=ufo.product.storage") | ||
958 | + public ApiResponse getStorageByCodeAndColorName(@RequestBody List<ProductRequestBo> reqList) { | ||
959 | + LOG.info("Enter getStorageByCodeAndColorName with req={}", reqList); | ||
960 | + List<StorageCheckResp> resp = productService.getStorageByCodeAndColorName(reqList); | ||
961 | + return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product data").build(); | ||
962 | + } | ||
953 | } | 963 | } |
@@ -9,7 +9,9 @@ import com.alibaba.fastjson.JSONObject; | @@ -9,7 +9,9 @@ import com.alibaba.fastjson.JSONObject; | ||
9 | import com.yoho.core.dal.datasource.annotation.Database; | 9 | import com.yoho.core.dal.datasource.annotation.Database; |
10 | import com.yohobuy.ufo.model.ProductInfo; | 10 | import com.yohobuy.ufo.model.ProductInfo; |
11 | import com.yohobuy.ufo.model.request.StoragePriceBo; | 11 | import com.yohobuy.ufo.model.request.StoragePriceBo; |
12 | +import com.yohobuy.ufo.model.request.product.ProductRequestBo; | ||
12 | import com.yohobuy.ufo.model.response.ProductDetailResp; | 13 | import com.yohobuy.ufo.model.response.ProductDetailResp; |
14 | +import com.yohobuy.ufo.model.response.StorageCheckResp; | ||
13 | import com.yohobuy.ufo.model.response.StorageInfoResp; | 15 | import com.yohobuy.ufo.model.response.StorageInfoResp; |
14 | import com.yohoufo.dal.product.model.StoragePrice; | 16 | import com.yohoufo.dal.product.model.StoragePrice; |
15 | import com.yohoufo.product.model.SkupInfo; | 17 | import com.yohoufo.product.model.SkupInfo; |
@@ -135,4 +137,11 @@ public interface ProductService { | @@ -135,4 +137,11 @@ public interface ProductService { | ||
135 | 137 | ||
136 | List<StorageInfoResp> queryLeastOnSalePrice(String productCode); | 138 | List<StorageInfoResp> queryLeastOnSalePrice(String productCode); |
137 | void tabsGoods(ProductDetailResp resp); | 139 | void tabsGoods(ProductDetailResp resp); |
140 | + | ||
141 | + /** | ||
142 | + * 根据货号尺码查询storage | ||
143 | + * @param reqList | ||
144 | + * @return | ||
145 | + */ | ||
146 | + List<StorageCheckResp> getStorageByCodeAndColorName(List<ProductRequestBo> reqList); | ||
138 | } | 147 | } |
@@ -16,8 +16,11 @@ import java.util.function.BinaryOperator; | @@ -16,8 +16,11 @@ import java.util.function.BinaryOperator; | ||
16 | import java.util.function.Function; | 16 | import java.util.function.Function; |
17 | import java.util.stream.Collectors; | 17 | import java.util.stream.Collectors; |
18 | 18 | ||
19 | +import com.yohobuy.ufo.model.request.product.ProductRequestBo; | ||
20 | +import com.yohobuy.ufo.model.response.StorageCheckResp; | ||
19 | import com.yohobuy.ufo.model.response.store.StoreInfoBo; | 21 | import com.yohobuy.ufo.model.response.store.StoreInfoBo; |
20 | import com.yohoufo.common.ApiResponse; | 22 | import com.yohoufo.common.ApiResponse; |
23 | +import com.yohoufo.common.utils.OrikaUtils; | ||
21 | import com.yohoufo.dal.product.*; | 24 | import com.yohoufo.dal.product.*; |
22 | import com.yohoufo.dal.product.model.*; | 25 | import com.yohoufo.dal.product.model.*; |
23 | import org.apache.commons.collections.MapUtils; | 26 | import org.apache.commons.collections.MapUtils; |
@@ -33,7 +36,7 @@ import org.springframework.stereotype.Service; | @@ -33,7 +36,7 @@ import org.springframework.stereotype.Service; | ||
33 | import org.springframework.ui.ModelMap; | 36 | import org.springframework.ui.ModelMap; |
34 | import org.springframework.util.CollectionUtils; | 37 | import org.springframework.util.CollectionUtils; |
35 | import org.springframework.web.servlet.ModelAndView; | 38 | import org.springframework.web.servlet.ModelAndView; |
36 | - | 39 | +import com.yohobuy.ufo.model.enums.StorageCheckEnum; |
37 | import com.alibaba.fastjson.JSONArray; | 40 | import com.alibaba.fastjson.JSONArray; |
38 | import com.alibaba.fastjson.JSONObject; | 41 | import com.alibaba.fastjson.JSONObject; |
39 | import com.google.common.collect.Lists; | 42 | import com.google.common.collect.Lists; |
@@ -68,6 +71,7 @@ import com.yohoufo.product.response.SkupDetailForScreenResp; | @@ -68,6 +71,7 @@ import com.yohoufo.product.response.SkupDetailForScreenResp; | ||
68 | import com.yohoufo.product.response.StorageLeastPriceResp; | 71 | import com.yohoufo.product.response.StorageLeastPriceResp; |
69 | import com.yohoufo.product.service.ProductSearchService; | 72 | import com.yohoufo.product.service.ProductSearchService; |
70 | import com.yohoufo.product.service.ProductService; | 73 | import com.yohoufo.product.service.ProductService; |
74 | +import com.yohoufo.dal.product.model.Size; | ||
71 | 75 | ||
72 | 76 | ||
73 | @Service | 77 | @Service |
@@ -206,7 +210,7 @@ public class ProductServiceImpl implements ProductService { | @@ -206,7 +210,7 @@ public class ProductServiceImpl implements ProductService { | ||
206 | BigDecimal quickDeliveryLeastPrice = quickDeliveryLeastPriceList.stream().min((p1, p2) -> (p1.compareTo(p2))).get(); | 210 | BigDecimal quickDeliveryLeastPrice = quickDeliveryLeastPriceList.stream().min((p1, p2) -> (p1.compareTo(p2))).get(); |
207 | productInfo.setQuickDeliveryPrice(quickDeliveryLeastPrice); | 211 | productInfo.setQuickDeliveryPrice(quickDeliveryLeastPrice); |
208 | } | 212 | } |
209 | - | 213 | + |
210 | goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy)); | 214 | goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy)); |
211 | List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsSizes); | 215 | List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsSizes); |
212 | if(!CollectionUtils.isEmpty(otherAddSizeList)) { | 216 | if(!CollectionUtils.isEmpty(otherAddSizeList)) { |
@@ -2078,7 +2082,7 @@ public class ProductServiceImpl implements ProductService { | @@ -2078,7 +2082,7 @@ public class ProductServiceImpl implements ProductService { | ||
2078 | 2082 | ||
2079 | /** | 2083 | /** |
2080 | * 根据编码查询货号 名称 和图片 商品颜色 | 2084 | * 根据编码查询货号 名称 和图片 商品颜色 |
2081 | - * @param productId | 2085 | + * @param productIds |
2082 | * @return | 2086 | * @return |
2083 | */ | 2087 | */ |
2084 | public Map<Integer, ProductInfo> queryProductInfoMap(List<Integer> productIds) { | 2088 | public Map<Integer, ProductInfo> queryProductInfoMap(List<Integer> productIds) { |
@@ -2138,4 +2142,115 @@ public class ProductServiceImpl implements ProductService { | @@ -2138,4 +2142,115 @@ public class ProductServiceImpl implements ProductService { | ||
2138 | return false; | 2142 | return false; |
2139 | } | 2143 | } |
2140 | 2144 | ||
2145 | + @Override | ||
2146 | + public List<StorageCheckResp> getStorageByCodeAndColorName(List<ProductRequestBo> reqList) { | ||
2147 | + List<StorageCheckResp> result = new ArrayList<>(); | ||
2148 | + | ||
2149 | + // 请求参数中的货号 | ||
2150 | + List<String> reqProductCode = new ArrayList<>(); | ||
2151 | + | ||
2152 | + // 系统中有的货号 | ||
2153 | + List<String> resultProductCode = new ArrayList<>(); | ||
2154 | + | ||
2155 | + // 系统中货号对应的productIds | ||
2156 | + List<Integer> productIds = new ArrayList<>(); | ||
2157 | + HashMap<Integer, String> productIdAndCode = new HashMap<>(); | ||
2158 | + | ||
2159 | + // 请求参数中的尺码名称 | ||
2160 | + List<String> reqSizeName = new ArrayList<>(); | ||
2161 | + | ||
2162 | + // 系统中的尺码名称 | ||
2163 | + List<String> resultSizeName = new ArrayList<>(); | ||
2164 | + HashMap<Integer, String> sizeIdAndName = new HashMap<>(); | ||
2165 | + | ||
2166 | + List<Integer> resultSizeIds = new ArrayList<>(); | ||
2167 | + | ||
2168 | + if (CollectionUtils.isEmpty(reqList)) { | ||
2169 | + throw new ServiceException(400, "参数错误"); | ||
2170 | + } | ||
2171 | + | ||
2172 | + // 1. 获取参数中的productCode, sizeName, | ||
2173 | + reqList.stream().forEach(item -> { | ||
2174 | + reqProductCode.add(item.getProductCode()); | ||
2175 | + reqSizeName.add(item.getSizeName()); | ||
2176 | + result.add(OrikaUtils.map(item, StorageCheckResp.class)); | ||
2177 | + }); | ||
2178 | + | ||
2179 | + LOGGER.info("int reqProductCode lengh= {}", resultProductCode.size()); | ||
2180 | + // 2. 查询 productCode 对应的product_id, 根据product_id 查询storage | ||
2181 | + List<Product> products = productMapper.selectByCodes(reqProductCode); | ||
2182 | + | ||
2183 | + // 货号都不存在 | ||
2184 | + if (CollectionUtils.isEmpty(products)) { | ||
2185 | + for(StorageCheckResp item : result) { | ||
2186 | + setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_NOT_FOUND.getType()); | ||
2187 | + } | ||
2188 | + return result; | ||
2189 | + } | ||
2190 | + | ||
2191 | + products.stream().forEach(item -> { | ||
2192 | + productIds.add(item.getId()); | ||
2193 | + resultProductCode.add(item.getProductCode()); | ||
2194 | + productIdAndCode.put(item.getId(), item.getProductCode()); | ||
2195 | + }); | ||
2196 | + LOGGER.info("int resultProductCode lengh= {}", resultProductCode.size()); | ||
2197 | + | ||
2198 | + // 3.查询系统中的库存 | ||
2199 | + List<Storage> storages = storageMapper.selectByProductIds(productIds); | ||
2200 | + | ||
2201 | + // 4. 查询 sizeName 对应的size_id | ||
2202 | + List<Size> sizes = sizeMapper.selectByNames(reqSizeName); | ||
2203 | + sizes.stream().forEach(item->{ | ||
2204 | + resultSizeName.add(item.getSizeName()); | ||
2205 | + resultSizeIds.add(item.getId()); | ||
2206 | + sizeIdAndName.put(item.getId(), item.getSizeName()); | ||
2207 | + }); | ||
2208 | + | ||
2209 | + // 5. 标记检测情况 | ||
2210 | + // 5.1 不存在的货号 | ||
2211 | + reqProductCode.removeAll(resultProductCode); | ||
2212 | + // 5.2 不存在的尺码名称 | ||
2213 | + reqSizeName.removeAll(resultSizeName); | ||
2214 | + | ||
2215 | + loop: for(StorageCheckResp item : result) { | ||
2216 | + // 不存在的货号 | ||
2217 | + if (reqProductCode.contains(item.getProductCode())) { | ||
2218 | + setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_NOT_FOUND.getType()); | ||
2219 | + LOGGER.info("货号不存在 = {}", item); | ||
2220 | + continue; | ||
2221 | + } | ||
2222 | + | ||
2223 | + // 不存在的尺码 | ||
2224 | + if (reqSizeName.contains(item.getSizeName())) { | ||
2225 | + LOGGER.info("尺码名称不存在 = {}", item); | ||
2226 | + setStorageCheckRespStatusInfo(item, StorageCheckEnum.SIZE_NOT_FOUND.getType()); | ||
2227 | + continue; | ||
2228 | + } | ||
2229 | + | ||
2230 | + for(Storage storage : storages) { | ||
2231 | + // 货号和尺码匹配 | ||
2232 | + if (item.getProductCode() == productIdAndCode.get(storage.getProductId()) && item.getSizeName() == sizeIdAndName.get(storage.getSizeId())) { | ||
2233 | + setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_MATCH.getType()); | ||
2234 | + continue loop; | ||
2235 | + } | ||
2236 | + } | ||
2237 | + | ||
2238 | + // 货号和尺码不匹配 | ||
2239 | + setStorageCheckRespStatusInfo(item, StorageCheckEnum.PRODUCT_SIZE_NOT_MATCH.getType()); | ||
2240 | + } | ||
2241 | + | ||
2242 | + return result; | ||
2243 | + } | ||
2244 | + | ||
2245 | + /** | ||
2246 | + * 设置检测结果状态信息 | ||
2247 | + * @param item | ||
2248 | + * @param status | ||
2249 | + * @return | ||
2250 | + */ | ||
2251 | + private StorageCheckResp setStorageCheckRespStatusInfo(StorageCheckResp item, Integer status) { | ||
2252 | + item.setStatus(status); | ||
2253 | + item.setStatusStr(StorageCheckEnum.getTypeName(status)); | ||
2254 | + return item; | ||
2255 | + } | ||
2141 | } | 2256 | } |
-
Please register or login to post a comment