Merge branch 'master' of http://git.yoho.cn/ufo/yohoufo-fore
Showing
20 changed files
with
372 additions
and
84 deletions
@@ -58,13 +58,13 @@ public class GlobalDefaultExceptionHandler { | @@ -58,13 +58,13 @@ public class GlobalDefaultExceptionHandler { | ||
58 | } | 58 | } |
59 | 59 | ||
60 | //如果是业务异常,则返回http 200,并且构造json消息体中错误码&错误内容 | 60 | //如果是业务异常,则返回http 200,并且构造json消息体中错误码&错误内容 |
61 | - if (e instanceof GatewayException || e instanceof ServiceException) { | 61 | + if (e instanceof GatewayException || e instanceof ServiceException || e instanceof Exception) { |
62 | int code; | 62 | int code; |
63 | String desc; | 63 | String desc; |
64 | if (e instanceof GatewayException) { | 64 | if (e instanceof GatewayException) { |
65 | code = ((GatewayException) e).getErrorCode(); | 65 | code = ((GatewayException) e).getErrorCode(); |
66 | desc = ((GatewayException) e).getDesc(); | 66 | desc = ((GatewayException) e).getDesc(); |
67 | - } else { //服务异常,不能直接返回给客户端,必须映射一下 | 67 | + } else if(e instanceof ServiceException) { //服务异常,不能直接返回给客户端,必须映射一下 |
68 | ServiceException serviceException = (ServiceException) e; | 68 | ServiceException serviceException = (ServiceException) e; |
69 | ServiceError serviceError = serviceException.getServiceError(); | 69 | ServiceError serviceError = serviceException.getServiceError(); |
70 | code = serviceError.getMappingGatewayError().getLeft(); | 70 | code = serviceError.getMappingGatewayError().getLeft(); |
@@ -72,6 +72,9 @@ public class GlobalDefaultExceptionHandler { | @@ -72,6 +72,9 @@ public class GlobalDefaultExceptionHandler { | ||
72 | if (serviceException.getParams() != null) { | 72 | if (serviceException.getParams() != null) { |
73 | desc = MessageFormat.format(desc, serviceException.getParams()); | 73 | desc = MessageFormat.format(desc, serviceException.getParams()); |
74 | } | 74 | } |
75 | + }else { | ||
76 | + code = 500; | ||
77 | + desc = "服务暂时异常,请稍等"; | ||
75 | } | 78 | } |
76 | 79 | ||
77 | log.warn("service exception happened at:{}, code:{}, desc:{}, uri:{}, request: {}, params is: {}", serviceName, code, desc, request.getRequestURI(), serviceName, params); | 80 | log.warn("service exception happened at:{}, code:{}, desc:{}, uri:{}, request: {}, params is: {}", serviceName, code, desc, request.getRequestURI(), serviceName, params); |
@@ -51,7 +51,6 @@ public class SignatureVerifyInterceptor implements HandlerInterceptor, Applicati | @@ -51,7 +51,6 @@ public class SignatureVerifyInterceptor implements HandlerInterceptor, Applicati | ||
51 | public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception { | 51 | public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception { |
52 | //(1) 验签开关, 控制是否需要验签. 默认需要验证 | 52 | //(1) 验签开关, 控制是否需要验签. 默认需要验证 |
53 | boolean isSignatureVerifyEnable = configReader.getBoolean("gateway.security.isSignatureVerifyEnable", true); | 53 | boolean isSignatureVerifyEnable = configReader.getBoolean("gateway.security.isSignatureVerifyEnable", true); |
54 | - logger.info("isDebugEnable is {},request param debug is {}",isDebugEnable,httpServletRequest.getParameter("debug"));//TODO test | ||
55 | if(!isSignatureVerifyEnable){ | 54 | if(!isSignatureVerifyEnable){ |
56 | logger.debug("gateway.security.isSignatureVerifyEnable is false"); | 55 | logger.debug("gateway.security.isSignatureVerifyEnable is false"); |
57 | return true; | 56 | return true; |
@@ -4,6 +4,8 @@ import com.yohoufo.dal.product.model.StoragePrice; | @@ -4,6 +4,8 @@ import com.yohoufo.dal.product.model.StoragePrice; | ||
4 | 4 | ||
5 | import java.util.List; | 5 | import java.util.List; |
6 | 6 | ||
7 | +import org.apache.ibatis.annotations.Param; | ||
8 | + | ||
7 | public interface StoragePriceMapper { | 9 | public interface StoragePriceMapper { |
8 | int deleteByPrimaryKey(Integer id); | 10 | int deleteByPrimaryKey(Integer id); |
9 | 11 | ||
@@ -20,6 +22,10 @@ public interface StoragePriceMapper { | @@ -20,6 +22,10 @@ public interface StoragePriceMapper { | ||
20 | int saleSkup(Integer skup); | 22 | int saleSkup(Integer skup); |
21 | 23 | ||
22 | int cancelSaleSkup(Integer skup); | 24 | int cancelSaleSkup(Integer skup); |
25 | + | ||
26 | + int updateStatus(@Param("skup")Integer skup, @Param("status")Integer status, @Param("beforeStatus")Integer beforeStatus); | ||
27 | + | ||
28 | + int updateDepotNum(@Param("skup")Integer skup, @Param("depotNum")Integer depotNum); | ||
23 | 29 | ||
24 | StoragePrice selectLeastPrice(Integer storageId); | 30 | StoragePrice selectLeastPrice(Integer storageId); |
25 | 31 |
@@ -20,7 +20,17 @@ public class StoragePrice { | @@ -20,7 +20,17 @@ public class StoragePrice { | ||
20 | 20 | ||
21 | private BigDecimal price; | 21 | private BigDecimal price; |
22 | 22 | ||
23 | - /** 1:可售,2卖出,3鉴定失败,4卖家取消, 5客服取消. */ | 23 | + /** |
24 | + * <pre> | ||
25 | + * 卖家操作 | ||
26 | + * 0:初始(未支付保证金),*1:可售(已经支付保证金),2:卖家取消支付保证金,3:卖家超时未支付保证金,4:卖家支付保证金后取消售卖 | ||
27 | + * 买家操作 | ||
28 | + * 100:购买使得商品卖出(可能下单未支付,且未超时,或者已支付),101:取消卖出(买家手动),102:取消卖出(超时未支付),103:下单失败 | ||
29 | + * 平台操作 | ||
30 | + * 200:客服取消,201:鉴定失败 | ||
31 | + * </pre> | ||
32 | + * | ||
33 | + */ | ||
24 | private Integer status; | 34 | private Integer status; |
25 | 35 | ||
26 | private Integer updateTime; | 36 | private Integer updateTime; |
@@ -60,7 +60,7 @@ | @@ -60,7 +60,7 @@ | ||
60 | where skup = #{skup,jdbcType=INTEGER} | 60 | where skup = #{skup,jdbcType=INTEGER} |
61 | </select> | 61 | </select> |
62 | <update id="saleSkup" parameterType="java.lang.Integer"> | 62 | <update id="saleSkup" parameterType="java.lang.Integer"> |
63 | - update storage_price set status = 2, | 63 | + update storage_price set status = 100, |
64 | update_time = unix_timestamp() | 64 | update_time = unix_timestamp() |
65 | where skup = #{skup,jdbcType=INTEGER} and status = 1 | 65 | where skup = #{skup,jdbcType=INTEGER} and status = 1 |
66 | </update> | 66 | </update> |
@@ -81,5 +81,19 @@ | @@ -81,5 +81,19 @@ | ||
81 | #{item} | 81 | #{item} |
82 | </foreach> | 82 | </foreach> |
83 | </select> | 83 | </select> |
84 | + <update id="updateStatus"> | ||
85 | + update storage_price set status = #{status,jdbcType=INTEGER}, | ||
86 | + update_time = unix_timestamp() | ||
87 | + where skup = #{skup,jdbcType=INTEGER} | ||
88 | + <if test="beforeStatus != null "> | ||
89 | + and status = #{beforeStatus} | ||
90 | + </if> | ||
91 | + </update> | ||
92 | + <update id="updateDepotNum"> | ||
93 | + update storage_price set depot_num = #{depotNum,jdbcType=INTEGER}, | ||
94 | + update_time = unix_timestamp() | ||
95 | + where skup = #{skup,jdbcType=INTEGER} | ||
96 | + and status = 100 | ||
97 | + </update> | ||
84 | 98 | ||
85 | </mapper> | 99 | </mapper> |
1 | package com.yohoufo.order.model; | 1 | package com.yohoufo.order.model; |
2 | 2 | ||
3 | +import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
3 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; | 4 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; |
4 | import lombok.Data; | 5 | import lombok.Data; |
5 | 6 | ||
@@ -38,5 +39,5 @@ public class SellerOrderContext { | @@ -38,5 +39,5 @@ public class SellerOrderContext { | ||
38 | private AddressInfo backAddress; | 39 | private AddressInfo backAddress; |
39 | 40 | ||
40 | 41 | ||
41 | - | 42 | + private transient SellerOrderGoods sellerOrderGoods; |
42 | } | 43 | } |
@@ -51,6 +51,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -51,6 +51,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
51 | orderInfo.setStatus(SellerOrderStatus.HAS_PAYED.getCode()); | 51 | orderInfo.setStatus(SellerOrderStatus.HAS_PAYED.getCode()); |
52 | 52 | ||
53 | sellerOrderMapper.updateByOrderCode(sellerOrder); | 53 | sellerOrderMapper.updateByOrderCode(sellerOrder); |
54 | + // | ||
55 | + | ||
54 | } | 56 | } |
55 | 57 | ||
56 | 58 |
@@ -2,6 +2,7 @@ package com.yohoufo.order.service.handler; | @@ -2,6 +2,7 @@ package com.yohoufo.order.service.handler; | ||
2 | 2 | ||
3 | import com.yoho.core.dal.datasource.annotation.Database; | 3 | import com.yoho.core.dal.datasource.annotation.Database; |
4 | import com.yohoufo.common.exception.GatewayException; | 4 | import com.yohoufo.common.exception.GatewayException; |
5 | +import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
5 | import com.yohoufo.order.model.GoodsInfo; | 6 | import com.yohoufo.order.model.GoodsInfo; |
6 | import com.yohoufo.order.model.SellerOrderContext; | 7 | import com.yohoufo.order.model.SellerOrderContext; |
7 | import com.yohoufo.order.service.impl.SkupService; | 8 | import com.yohoufo.order.service.impl.SkupService; |
@@ -35,17 +36,19 @@ public class SellerOrderSubmitHandler { | @@ -35,17 +36,19 @@ public class SellerOrderSubmitHandler { | ||
35 | 36 | ||
36 | @Transactional(propagation = Propagation.REQUIRES_NEW) | 37 | @Transactional(propagation = Propagation.REQUIRES_NEW) |
37 | @Database(ForceMaster=true, DataSource="ufo_order") | 38 | @Database(ForceMaster=true, DataSource="ufo_order") |
38 | - public Long submit(SellerOrderContext context) throws GatewayException { | 39 | + public void submit(SellerOrderContext context) throws GatewayException { |
39 | int uid = context.getUid(); | 40 | int uid = context.getUid(); |
40 | int storageId = context.getStorageId(); | 41 | int storageId = context.getStorageId(); |
41 | log.info("in seller order submit uid {}, storageId {}", uid, storageId); | 42 | log.info("in seller order submit uid {}, storageId {}", uid, storageId); |
42 | GoodsInfo goodsInfo = context.getSoldProduct(); | 43 | GoodsInfo goodsInfo = context.getSoldProduct(); |
43 | // | 44 | // |
44 | - int skup = skupService.addSkup(goodsInfo); | 45 | + SellerOrderGoods sellerOrderGoods = skupService.addSkup(goodsInfo); |
46 | + int skup = sellerOrderGoods.getId(); | ||
45 | if (skup <= 0){ | 47 | if (skup <= 0){ |
46 | log.warn("in computePublishPrd storageId not exist in prd , uid {}, storageId {}", uid, storageId); | 48 | log.warn("in computePublishPrd storageId not exist in prd , uid {}, storageId {}", uid, storageId); |
47 | throw new GatewayException(501, "商品发布失败"); | 49 | throw new GatewayException(501, "商品发布失败"); |
48 | } | 50 | } |
51 | + context.setSellerOrderGoods(sellerOrderGoods); | ||
49 | context.getSoldProduct().setSkup(skup); | 52 | context.getSoldProduct().setSkup(skup); |
50 | //step 2: create order, set status(not pay) | 53 | //step 2: create order, set status(not pay) |
51 | //generate a new real code | 54 | //generate a new real code |
@@ -54,7 +57,6 @@ public class SellerOrderSubmitHandler { | @@ -54,7 +57,6 @@ public class SellerOrderSubmitHandler { | ||
54 | sellerAddressService.saveSendBackAddress(context); | 57 | sellerAddressService.saveSendBackAddress(context); |
55 | //record every fee items | 58 | //record every fee items |
56 | sellerFeeService.saveFee(context); | 59 | sellerFeeService.saveFee(context); |
57 | - return 0L; | ||
58 | } | 60 | } |
59 | 61 | ||
60 | 62 |
@@ -3,6 +3,8 @@ package com.yohoufo.order.service.impl; | @@ -3,6 +3,8 @@ package com.yohoufo.order.service.impl; | ||
3 | import com.yohoufo.order.service.impl.visitor.AutoCancelCase; | 3 | import com.yohoufo.order.service.impl.visitor.AutoCancelCase; |
4 | import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase; | 4 | import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase; |
5 | import com.yohoufo.order.service.impl.visitor.UserCancelCase; | 5 | import com.yohoufo.order.service.impl.visitor.UserCancelCase; |
6 | +import org.slf4j.Logger; | ||
7 | +import org.slf4j.LoggerFactory; | ||
6 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
7 | 9 | ||
8 | /** | 10 | /** |
@@ -11,9 +13,10 @@ import org.springframework.stereotype.Service; | @@ -11,9 +13,10 @@ import org.springframework.stereotype.Service; | ||
11 | @Service | 13 | @Service |
12 | public class SellerOrderCancelService { | 14 | public class SellerOrderCancelService { |
13 | 15 | ||
16 | + private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
14 | 17 | ||
15 | public void cancel(UserCancelCase cancelCase){ | 18 | public void cancel(UserCancelCase cancelCase){ |
16 | - | 19 | + logger.info("in cancel UserCancelCase {}", cancelCase); |
17 | //未支付时 | 20 | //未支付时 |
18 | 21 | ||
19 | //支付完成,没有买家下单 | 22 | //支付完成,没有买家下单 |
@@ -23,13 +26,13 @@ public class SellerOrderCancelService { | @@ -23,13 +26,13 @@ public class SellerOrderCancelService { | ||
23 | 26 | ||
24 | 27 | ||
25 | public void cancel(AutoCancelCase autoCancelCase){ | 28 | public void cancel(AutoCancelCase autoCancelCase){ |
26 | - | 29 | + logger.info("in cancel autoCancelCase {}", autoCancelCase); |
27 | } | 30 | } |
28 | 31 | ||
29 | 32 | ||
30 | 33 | ||
31 | public void cancel(OffShelveCancelCase offShelveCancelCase){ | 34 | public void cancel(OffShelveCancelCase offShelveCancelCase){ |
32 | - | 35 | + logger.info("in cancel offShelveCancelCase {}", offShelveCancelCase); |
33 | } | 36 | } |
34 | 37 | ||
35 | } | 38 | } |
@@ -5,10 +5,10 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; | @@ -5,10 +5,10 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; | ||
5 | import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq; | 5 | import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq; |
6 | import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq; | 6 | import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq; |
7 | import com.yohobuy.ufo.model.order.resp.PageResp; | 7 | import com.yohobuy.ufo.model.order.resp.PageResp; |
8 | -import com.yohoufo.common.caller.UfoServiceCaller; | ||
9 | import com.yohoufo.common.exception.GatewayException; | 8 | import com.yohoufo.common.exception.GatewayException; |
10 | import com.yohoufo.dal.order.SellerOrderMapper; | 9 | import com.yohoufo.dal.order.SellerOrderMapper; |
11 | import com.yohoufo.order.common.OrderCodeType; | 10 | import com.yohoufo.order.common.OrderCodeType; |
11 | +import com.yohoufo.order.common.SkupStatus; | ||
12 | import com.yohoufo.order.convert.AddressInfoConvertor; | 12 | import com.yohoufo.order.convert.AddressInfoConvertor; |
13 | import com.yohoufo.order.convert.SellerOrderConvertor; | 13 | import com.yohoufo.order.convert.SellerOrderConvertor; |
14 | import com.yohoufo.order.model.AddressInfo; | 14 | import com.yohoufo.order.model.AddressInfo; |
@@ -23,11 +23,11 @@ import com.yohoufo.order.service.IOrderDetailService; | @@ -23,11 +23,11 @@ import com.yohoufo.order.service.IOrderDetailService; | ||
23 | import com.yohoufo.order.service.IOrderListService; | 23 | import com.yohoufo.order.service.IOrderListService; |
24 | import com.yohoufo.order.service.handler.SellerOrderComputeHandler; | 24 | import com.yohoufo.order.service.handler.SellerOrderComputeHandler; |
25 | import com.yohoufo.order.service.handler.SellerOrderSubmitHandler; | 25 | import com.yohoufo.order.service.handler.SellerOrderSubmitHandler; |
26 | +import com.yohoufo.order.service.proxy.ProductProxyService; | ||
26 | import com.yohoufo.order.service.proxy.UserProxyService; | 27 | import com.yohoufo.order.service.proxy.UserProxyService; |
27 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | 28 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; |
28 | import com.yohoufo.product.model.GoodsSize; | 29 | import com.yohoufo.product.model.GoodsSize; |
29 | import com.yohoufo.product.response.StorageDataResp; | 30 | import com.yohoufo.product.response.StorageDataResp; |
30 | -import com.yohoufo.product.response.StorageLeastPriceResp; | ||
31 | import lombok.extern.slf4j.Slf4j; | 31 | import lombok.extern.slf4j.Slf4j; |
32 | import org.apache.commons.lang3.StringUtils; | 32 | import org.apache.commons.lang3.StringUtils; |
33 | import org.springframework.beans.factory.annotation.Autowired; | 33 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -46,8 +46,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -46,8 +46,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
46 | @Autowired | 46 | @Autowired |
47 | private SellerOrderMapper sellerOrderMapper; | 47 | private SellerOrderMapper sellerOrderMapper; |
48 | 48 | ||
49 | - @Autowired | ||
50 | - private UfoServiceCaller ufoServiceCaller; | 49 | + |
51 | 50 | ||
52 | @Autowired | 51 | @Autowired |
53 | private SellerOrderComputeHandler computeHandler; | 52 | private SellerOrderComputeHandler computeHandler; |
@@ -67,6 +66,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -67,6 +66,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
67 | @Autowired | 66 | @Autowired |
68 | private SellerOrderDetailService sellerOrderDetailService; | 67 | private SellerOrderDetailService sellerOrderDetailService; |
69 | 68 | ||
69 | + @Autowired | ||
70 | + private ProductProxyService productProxyService; | ||
71 | + | ||
70 | 72 | ||
71 | public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException { | 73 | public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException { |
72 | log.info("in computePublishPrd, req {}", req); | 74 | log.info("in computePublishPrd, req {}", req); |
@@ -77,11 +79,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -77,11 +79,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
77 | log.warn("in computePublishPrd storageId illegal , req {}", req); | 79 | log.warn("in computePublishPrd storageId illegal , req {}", req); |
78 | throw new GatewayException(400, "storageId 错误"); | 80 | throw new GatewayException(400, "storageId 错误"); |
79 | } | 81 | } |
80 | - StorageLeastPriceResp resp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId); | ||
81 | - BigDecimal leastPrice; | ||
82 | - if (Objects.isNull(resp) || Objects.isNull(leastPrice = resp.getLeastPrice()) || leastPrice.doubleValue() == 0D){ | ||
83 | - throw new GatewayException(501, "暂无商品"); | ||
84 | - } | 82 | + BigDecimal leastPrice = productProxyService.getLeastprice(storageId); |
83 | + | ||
84 | + | ||
85 | /*商品鉴定费 ¥10.00 | 85 | /*商品鉴定费 ¥10.00 |
86 | 商品包装费 ¥10.00 | 86 | 商品包装费 ¥10.00 |
87 | 平台服务费(5%,优惠期间0%) ¥0.00 | 87 | 平台服务费(5%,优惠期间0%) ¥0.00 |
@@ -129,11 +129,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -129,11 +129,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
129 | throw new GatewayException(400, "商品不存在"); | 129 | throw new GatewayException(400, "商品不存在"); |
130 | } | 130 | } |
131 | context.setSoldProduct(goodsInfo); | 131 | context.setSoldProduct(goodsInfo); |
132 | - StorageLeastPriceResp leastPriceResp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId); | ||
133 | - BigDecimal leastPrice; | ||
134 | - if (Objects.isNull(leastPriceResp) || Objects.isNull(leastPrice = leastPriceResp.getLeastPrice()) || leastPrice.doubleValue() == 0D){ | ||
135 | - throw new GatewayException(501, "无法比对商品最低价"); | ||
136 | - } | 132 | + BigDecimal leastPrice = productProxyService.getLeastprice(storageId); |
137 | if (goodsInfo.getPrice().subtract(leastPrice).doubleValue() < 0D){ | 133 | if (goodsInfo.getPrice().subtract(leastPrice).doubleValue() < 0D){ |
138 | log.warn("in computePublishPrd,leastPrice {}, req {}", leastPrice, req); | 134 | log.warn("in computePublishPrd,leastPrice {}, req {}", leastPrice, req); |
139 | throw new GatewayException(501, "设定的价格低于商品最低价"); | 135 | throw new GatewayException(501, "设定的价格低于商品最低价"); |
@@ -154,6 +150,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -154,6 +150,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
154 | //submit all as atomic operation, use transaction of DB | 150 | //submit all as atomic operation, use transaction of DB |
155 | //all include : 1. skup, 2. order , 3. 寄回地址 | 151 | //all include : 1. skup, 2. order , 3. 寄回地址 |
156 | orderSubmitHandler.submit(context); | 152 | orderSubmitHandler.submit(context); |
153 | + | ||
154 | + boolean syncPrdFlag = productProxyService.syncSkup(context.getSellerOrderGoods(), SkupStatus.CAN_NOT_SELL); | ||
155 | + log.info("publish finish, syncPrdFlag {}, req {}, orderCode {}", syncPrdFlag, req, orderCode); | ||
156 | + //TODO 发消息 | ||
157 | return orderCode; | 157 | return orderCode; |
158 | } | 158 | } |
159 | 159 | ||
@@ -164,7 +164,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | @@ -164,7 +164,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi | ||
164 | int storageId = context.getStorageId(); | 164 | int storageId = context.getStorageId(); |
165 | BigDecimal salePrice = context.getSalePrice(); | 165 | BigDecimal salePrice = context.getSalePrice(); |
166 | try { | 166 | try { |
167 | - StorageDataResp prdResp = ufoServiceCaller.call("ufo.product.storage.data", storageId); | 167 | + StorageDataResp prdResp = productProxyService.getStorageData(storageId); |
168 | GoodsInfo goodsInfo = new GoodsInfo(); | 168 | GoodsInfo goodsInfo = new GoodsInfo(); |
169 | goodsInfo.setUid(uid); | 169 | goodsInfo.setUid(uid); |
170 | goodsInfo.setProductId(prdResp.getProductId()); | 170 | goodsInfo.setProductId(prdResp.getProductId()); |
@@ -21,12 +21,12 @@ public class SkupService { | @@ -21,12 +21,12 @@ public class SkupService { | ||
21 | 21 | ||
22 | @Transactional(propagation = Propagation.REQUIRED) | 22 | @Transactional(propagation = Propagation.REQUIRED) |
23 | @Database(ForceMaster=true, DataSource="ufo_order") | 23 | @Database(ForceMaster=true, DataSource="ufo_order") |
24 | - public int addSkup(GoodsInfo goodsInfo){ | 24 | + public SellerOrderGoods addSkup(GoodsInfo goodsInfo){ |
25 | //validate data legal | 25 | //validate data legal |
26 | SellerOrderGoods sellerOrderGoods = resp2Do4AddNew(goodsInfo); | 26 | SellerOrderGoods sellerOrderGoods = resp2Do4AddNew(goodsInfo); |
27 | // | 27 | // |
28 | sellerOrderGoodsMapper.insertSelective(sellerOrderGoods); | 28 | sellerOrderGoodsMapper.insertSelective(sellerOrderGoods); |
29 | - return sellerOrderGoods.getId(); | 29 | + return sellerOrderGoods; |
30 | } | 30 | } |
31 | 31 | ||
32 | 32 |
@@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | ||
5 | /** | 5 | /** |
6 | * Created by chenchao on 2018/9/17. | 6 | * Created by chenchao on 2018/9/17. |
7 | */ | 7 | */ |
8 | -public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{ | 8 | +public abstract class AbsSellerOrderCancelCase<T extends SellerOrderCancelService> implements SellerOrderCancelCase<T>{ |
9 | 9 | ||
10 | private int uid; | 10 | private int uid; |
11 | 11 | ||
@@ -17,7 +17,7 @@ public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{ | @@ -17,7 +17,7 @@ public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{ | ||
17 | this.orderCode = orderCode; | 17 | this.orderCode = orderCode; |
18 | } | 18 | } |
19 | 19 | ||
20 | - public abstract void accept(SellerOrderCancelService visitor); | 20 | + public abstract void accept(T visitor); |
21 | 21 | ||
22 | 22 | ||
23 | public int getUid() { | 23 | public int getUid() { |
@@ -27,4 +27,12 @@ public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{ | @@ -27,4 +27,12 @@ public abstract class AbsSellerOrderCancelCase implements SellerOrderCancelCase{ | ||
27 | public long getOrderCode() { | 27 | public long getOrderCode() { |
28 | return orderCode; | 28 | return orderCode; |
29 | } | 29 | } |
30 | + | ||
31 | + @Override | ||
32 | + public String toString() { | ||
33 | + return "{" + | ||
34 | + "uid=" + uid + | ||
35 | + ", orderCode=" + orderCode + | ||
36 | + '}'; | ||
37 | + } | ||
30 | } | 38 | } |
@@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | ||
5 | /**未支付 超时取消 | 5 | /**未支付 超时取消 |
6 | * Created by chenchao on 2018/9/17. | 6 | * Created by chenchao on 2018/9/17. |
7 | */ | 7 | */ |
8 | -public class AutoCancelCase extends AbsSellerOrderCancelCase { | 8 | +public class AutoCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> { |
9 | 9 | ||
10 | 10 | ||
11 | 11 | ||
@@ -14,10 +14,16 @@ public class AutoCancelCase extends AbsSellerOrderCancelCase { | @@ -14,10 +14,16 @@ public class AutoCancelCase extends AbsSellerOrderCancelCase { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | @Override | 16 | @Override |
17 | - public void accept(SellerOrderCancelService visitor) { | 17 | + public void accept(T visitor) { |
18 | visitor.cancel(this); | 18 | visitor.cancel(this); |
19 | } | 19 | } |
20 | 20 | ||
21 | 21 | ||
22 | - | 22 | + @Override |
23 | + public String toString() { | ||
24 | + final StringBuilder sb = new StringBuilder("AutoCancelCase{"); | ||
25 | + sb.append(super.toString()); | ||
26 | + sb.append('}'); | ||
27 | + return sb.toString(); | ||
28 | + } | ||
23 | } | 29 | } |
@@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | ||
5 | /**skup下架取消 | 5 | /**skup下架取消 |
6 | * Created by chenchao on 2018/9/17. | 6 | * Created by chenchao on 2018/9/17. |
7 | */ | 7 | */ |
8 | -public class OffShelveCancelCase extends AbsSellerOrderCancelCase { | 8 | +public class OffShelveCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> { |
9 | 9 | ||
10 | 10 | ||
11 | public OffShelveCancelCase(int uid, long orderCode) { | 11 | public OffShelveCancelCase(int uid, long orderCode) { |
@@ -14,7 +14,15 @@ public class OffShelveCancelCase extends AbsSellerOrderCancelCase { | @@ -14,7 +14,15 @@ public class OffShelveCancelCase extends AbsSellerOrderCancelCase { | ||
14 | 14 | ||
15 | 15 | ||
16 | @Override | 16 | @Override |
17 | - public void accept(SellerOrderCancelService visitor) { | 17 | + public void accept(T visitor) { |
18 | visitor.cancel(this); | 18 | visitor.cancel(this); |
19 | } | 19 | } |
20 | + | ||
21 | + @Override | ||
22 | + public String toString() { | ||
23 | + final StringBuilder sb = new StringBuilder("OffShelveCancelCase{"); | ||
24 | + sb.append(super.toString()); | ||
25 | + sb.append('}'); | ||
26 | + return sb.toString(); | ||
27 | + } | ||
20 | } | 28 | } |
@@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | ||
5 | /** | 5 | /** |
6 | * Created by chenchao on 2018/9/17. | 6 | * Created by chenchao on 2018/9/17. |
7 | */ | 7 | */ |
8 | -public interface SellerOrderCancelCase { | 8 | +public interface SellerOrderCancelCase<T extends SellerOrderCancelService> { |
9 | 9 | ||
10 | - void accept(SellerOrderCancelService visitor); | 10 | + void accept(T visitor); |
11 | } | 11 | } |
@@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | @@ -5,7 +5,7 @@ import com.yohoufo.order.service.impl.SellerOrderCancelService; | ||
5 | /** | 5 | /** |
6 | * Created by chenchao on 2018/9/17. | 6 | * Created by chenchao on 2018/9/17. |
7 | */ | 7 | */ |
8 | -public class UserCancelCase extends AbsSellerOrderCancelCase { | 8 | +public class UserCancelCase<T extends SellerOrderCancelService> extends AbsSellerOrderCancelCase<T> { |
9 | 9 | ||
10 | 10 | ||
11 | 11 | ||
@@ -14,7 +14,16 @@ public class UserCancelCase extends AbsSellerOrderCancelCase { | @@ -14,7 +14,16 @@ public class UserCancelCase extends AbsSellerOrderCancelCase { | ||
14 | } | 14 | } |
15 | 15 | ||
16 | @Override | 16 | @Override |
17 | - public void accept(SellerOrderCancelService visitor) { | 17 | + public void accept(T visitor) { |
18 | visitor.cancel(this); | 18 | visitor.cancel(this); |
19 | } | 19 | } |
20 | + | ||
21 | + | ||
22 | + @Override | ||
23 | + public String toString() { | ||
24 | + final StringBuilder sb = new StringBuilder("UserCancelCase{"); | ||
25 | + sb.append(super.toString()); | ||
26 | + sb.append('}'); | ||
27 | + return sb.toString(); | ||
28 | + } | ||
20 | } | 29 | } |
1 | +package com.yohoufo.order.service.proxy; | ||
2 | + | ||
3 | +import com.yohoufo.common.ApiResponse; | ||
4 | +import com.yohoufo.common.caller.UfoServiceCaller; | ||
5 | +import com.yohoufo.common.exception.GatewayException; | ||
6 | +import com.yohoufo.dal.order.SellerOrderGoodsMapper; | ||
7 | +import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
8 | +import com.yohoufo.order.common.SkupStatus; | ||
9 | +import com.yohoufo.product.request.StoragePriceBo; | ||
10 | +import com.yohoufo.product.response.StorageDataResp; | ||
11 | +import com.yohoufo.product.response.StorageLeastPriceResp; | ||
12 | +import org.slf4j.Logger; | ||
13 | +import org.slf4j.LoggerFactory; | ||
14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
15 | +import org.springframework.stereotype.Service; | ||
16 | + | ||
17 | +import java.math.BigDecimal; | ||
18 | +import java.util.Objects; | ||
19 | + | ||
20 | +/** | ||
21 | + * Created by chenchao on 2018/9/21. | ||
22 | + */ | ||
23 | +@Service | ||
24 | +public class ProductProxyService { | ||
25 | + | ||
26 | + final Logger logger = LoggerFactory.getLogger(getClass()); | ||
27 | + | ||
28 | + @Autowired | ||
29 | + private UfoServiceCaller ufoServiceCaller; | ||
30 | + | ||
31 | + private final static String syncSkup = "method=ufo.product.createSkup"; | ||
32 | + | ||
33 | + @Autowired | ||
34 | + private SellerOrderGoodsMapper sogMapper; | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + public BigDecimal getLeastprice(int storageId) throws GatewayException { | ||
39 | + StorageLeastPriceResp resp = ufoServiceCaller.call("ufo.product.storage.leastprice", storageId); | ||
40 | + BigDecimal leastPrice; | ||
41 | + if (Objects.isNull(resp) || Objects.isNull(leastPrice = resp.getLeastPrice()) || leastPrice.doubleValue() == 0D){ | ||
42 | + throw new GatewayException(501, "无法比对商品最低价"); | ||
43 | + } | ||
44 | + return leastPrice; | ||
45 | + } | ||
46 | + | ||
47 | + | ||
48 | + public StorageDataResp getStorageData(int storageId){ | ||
49 | + StorageDataResp prdResp = ufoServiceCaller.call("ufo.product.storage.data", storageId); | ||
50 | + | ||
51 | + return prdResp; | ||
52 | + } | ||
53 | + | ||
54 | + public boolean syncSkup(SellerOrderGoods goods, SkupStatus skupStatus){ | ||
55 | + boolean result = false; | ||
56 | + | ||
57 | + switch (skupStatus){ | ||
58 | + //一开始未支付时调用 | ||
59 | + case CAN_NOT_SELL: | ||
60 | + result = doSyncSkup(goods, skupStatus); | ||
61 | + break; | ||
62 | + case SELF_CANCEL_PAY: | ||
63 | + | ||
64 | + break; | ||
65 | + case TIMEOUT_CANCEL: | ||
66 | + | ||
67 | + break; | ||
68 | + case SELLER_CANCEL_SELL: | ||
69 | + | ||
70 | + break; | ||
71 | + case YOHO_CANCEL_SELL: | ||
72 | + | ||
73 | + break; | ||
74 | + default: | ||
75 | + | ||
76 | + break; | ||
77 | + } | ||
78 | + | ||
79 | + return result; | ||
80 | + } | ||
81 | + | ||
82 | + | ||
83 | + | ||
84 | + | ||
85 | + public boolean doSyncSkup(SellerOrderGoods goods, SkupStatus skupStatus){ | ||
86 | + StoragePriceBo skupReq = new StoragePriceBo(); | ||
87 | + skupReq.setSkup(goods.getId()); | ||
88 | + skupReq.setStatus(skupStatus.getCode()); | ||
89 | + skupReq.setProductId(goods.getProductId()); | ||
90 | + skupReq.setGoodsId(goods.getColorId()); | ||
91 | + skupReq.setStorageId(goods.getStorageId()); | ||
92 | + skupReq.setPrice(goods.getGoodsPrice()); | ||
93 | + skupReq.setSellerUid(goods.getUid()); | ||
94 | + ApiResponse resp = ufoServiceCaller.call(syncSkup, skupReq); | ||
95 | + return (null == resp || null == resp.getData())? false : (boolean)resp.getData(); | ||
96 | + } | ||
97 | +} |
@@ -116,14 +116,12 @@ public class ProductController { | @@ -116,14 +116,12 @@ public class ProductController { | ||
116 | return productService.queryStorageInfo(storageId); | 116 | return productService.queryStorageInfo(storageId); |
117 | } | 117 | } |
118 | 118 | ||
119 | - // 增加库存 | 119 | + // 创建skup |
120 | @RequestMapping(params = "method=ufo.product.createSkup") | 120 | @RequestMapping(params = "method=ufo.product.createSkup") |
121 | public ApiResponse createSkup(@RequestBody StoragePriceBo skupBo) { | 121 | public ApiResponse createSkup(@RequestBody StoragePriceBo skupBo) { |
122 | LOG.info("in method=ufo.product.createSkup skupBo = {}", skupBo); | 122 | LOG.info("in method=ufo.product.createSkup skupBo = {}", skupBo); |
123 | try { | 123 | try { |
124 | productService.createSkup(skupBo); | 124 | productService.createSkup(skupBo); |
125 | - LOG.info("createSkup success and async clearProductCache skup = {}", skupBo.getSkup()); | ||
126 | - clearProductCache(skupBo.getSkup()); | ||
127 | return new ApiResponse(200, "创建成功!", Boolean.TRUE); | 125 | return new ApiResponse(200, "创建成功!", Boolean.TRUE); |
128 | } catch (Exception e) { | 126 | } catch (Exception e) { |
129 | LOG.error("创建SKUP失败!", e); | 127 | LOG.error("创建SKUP失败!", e); |
@@ -132,6 +130,40 @@ public class ProductController { | @@ -132,6 +130,40 @@ public class ProductController { | ||
132 | } | 130 | } |
133 | } | 131 | } |
134 | 132 | ||
133 | + // 卖家修改状态:*1:可售(支付保证金),2:取消支付保证金,3:超时未支付保证金,4:支付保证金后取消售卖 | ||
134 | + @RequestMapping(params = "method=ufo.product.sellerUpdateStatus") | ||
135 | + public ApiResponse sellerUpdateStatus(@RequestBody StoragePriceBo skupBo) { | ||
136 | + LOG.info("in method=ufo.product.sellerUpdateStatus skupBo = {}", skupBo); | ||
137 | + try { | ||
138 | + productService.sellerUpdateStatus(skupBo); | ||
139 | + if (skupBo.getStatus() == 1 || skupBo.getStatus() == 4) { | ||
140 | + LOG.info("sellerUpdateStatus success and async clearProductCache skup = {}", skupBo.getSkup()); | ||
141 | + clearProductCache(skupBo.getSkup()); | ||
142 | + } | ||
143 | + return new ApiResponse(200, "创建成功!", Boolean.TRUE); | ||
144 | + } catch (Exception e) { | ||
145 | + LOG.error("sellerUpdateStatus失败!", e); | ||
146 | + int code = (e instanceof ServiceException) ? ((ServiceException) e).getCode() : 500; | ||
147 | + return new ApiResponse(code, e.getMessage(), Boolean.FALSE); | ||
148 | + } | ||
149 | + } | ||
150 | + | ||
151 | + // 设置鉴定中心 | ||
152 | + @RequestMapping(params = "method=ufo.product.setDepotNum") | ||
153 | + public ApiResponse setDepotNum( | ||
154 | + @RequestParam(value = "skup", required = true) Integer skup, | ||
155 | + @RequestParam(value = "depotNum", required = true) Integer depotNum) { | ||
156 | + LOG.info("in method=ufo.product.cancelSaleSkup skup={}, depotNum={}", skup, depotNum); | ||
157 | + try { | ||
158 | + productService.setDepotNum(skup, depotNum); | ||
159 | + return new ApiResponse(200, "设置成功!", Boolean.TRUE); | ||
160 | + } catch (Exception e) { | ||
161 | + LOG.error("设置鉴定中心失败!", e); | ||
162 | + int code = (e instanceof ServiceException) ? ((ServiceException) e).getCode() : 500; | ||
163 | + return new ApiResponse(code, e.getMessage(), Boolean.FALSE); | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
135 | // 售卖 | 167 | // 售卖 |
136 | @RequestMapping(params = "method=ufo.product.saleSkup") | 168 | @RequestMapping(params = "method=ufo.product.saleSkup") |
137 | public ApiResponse saleSkup( | 169 | public ApiResponse saleSkup( |
@@ -149,21 +181,15 @@ public class ProductController { | @@ -149,21 +181,15 @@ public class ProductController { | ||
149 | return new ApiResponse(code, e.getMessage(), Boolean.FALSE); | 181 | return new ApiResponse(code, e.getMessage(), Boolean.FALSE); |
150 | } | 182 | } |
151 | } | 183 | } |
152 | - | ||
153 | - /** | ||
154 | - * | ||
155 | - * @param skup | ||
156 | - * @return | ||
157 | - */ | ||
158 | - @IgnoreSignature | ||
159 | - @IgnoreSession | 184 | + |
160 | // 取消售卖 | 185 | // 取消售卖 |
161 | @RequestMapping(params = "method=ufo.product.cancelSaleSkup") | 186 | @RequestMapping(params = "method=ufo.product.cancelSaleSkup") |
162 | public ApiResponse cancelSaleSkup( | 187 | public ApiResponse cancelSaleSkup( |
163 | - @RequestParam(value = "skup", required = true) Integer skup) { | ||
164 | - LOG.info("in method=ufo.product.cancelSaleSkup skup={}", skup); | 188 | + @RequestParam(value = "skup", required = true) Integer skup, |
189 | + @RequestParam(value = "status", required = true) Integer status) { | ||
190 | + LOG.info("in method=ufo.product.cancelSaleSkup skup={}, status={}", skup, status); | ||
165 | try { | 191 | try { |
166 | - productService.cancelSaleSkup(skup); | 192 | + productService.cancelSaleSkup(skup, status); |
167 | LOG.info("saleSkup success and async clearProductCache skup = {}", skup); | 193 | LOG.info("saleSkup success and async clearProductCache skup = {}", skup); |
168 | clearProductCache(skup); | 194 | clearProductCache(skup); |
169 | return new ApiResponse(200, "取消卖出成功!", Boolean.TRUE); | 195 | return new ApiResponse(200, "取消卖出成功!", Boolean.TRUE); |
@@ -16,7 +16,7 @@ public interface ProductService { | @@ -16,7 +16,7 @@ public interface ProductService { | ||
16 | 16 | ||
17 | void saleSkup(Integer productId, Integer skup); | 17 | void saleSkup(Integer productId, Integer skup); |
18 | 18 | ||
19 | - void cancelSaleSkup(Integer skup); | 19 | + void cancelSaleSkup(Integer skup, Integer status); |
20 | 20 | ||
21 | StoragePrice getStoragePriceBySkup(Integer skup); | 21 | StoragePrice getStoragePriceBySkup(Integer skup); |
22 | 22 | ||
@@ -24,5 +24,8 @@ public interface ProductService { | @@ -24,5 +24,8 @@ public interface ProductService { | ||
24 | 24 | ||
25 | ProductSortTemplateResp querySortTemplateData(String productIds); | 25 | ProductSortTemplateResp querySortTemplateData(String productIds); |
26 | 26 | ||
27 | + void sellerUpdateStatus(StoragePriceBo skupBo); | ||
28 | + | ||
29 | + void setDepotNum(Integer skup, Integer depotNum); | ||
27 | 30 | ||
28 | } | 31 | } |
1 | package com.yohoufo.product.service.impl; | 1 | package com.yohoufo.product.service.impl; |
2 | 2 | ||
3 | import java.math.BigDecimal; | 3 | import java.math.BigDecimal; |
4 | -import java.util.*; | 4 | +import java.util.ArrayList; |
5 | +import java.util.Comparator; | ||
6 | +import java.util.HashMap; | ||
7 | +import java.util.List; | ||
8 | +import java.util.Map; | ||
9 | +import java.util.Objects; | ||
5 | import java.util.function.BinaryOperator; | 10 | import java.util.function.BinaryOperator; |
6 | import java.util.function.Function; | 11 | import java.util.function.Function; |
7 | import java.util.stream.Collectors; | 12 | import java.util.stream.Collectors; |
8 | 13 | ||
9 | -import com.yoho.core.common.helpers.ImagesHelper; | ||
10 | -import com.yohoufo.common.utils.UfoStringUtils; | ||
11 | -import com.yohoufo.dal.product.*; | ||
12 | -import com.yohoufo.dal.product.model.*; | ||
13 | -import com.yohoufo.product.model.*; | ||
14 | -import com.yohoufo.product.response.*; | ||
15 | import org.apache.commons.lang3.StringUtils; | 14 | import org.apache.commons.lang3.StringUtils; |
16 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
17 | import org.slf4j.LoggerFactory; | 16 | import org.slf4j.LoggerFactory; |
18 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
19 | +import org.springframework.util.CollectionUtils; | ||
20 | 20 | ||
21 | +import com.yoho.core.common.helpers.ImagesHelper; | ||
21 | import com.yoho.error.exception.ServiceException; | 22 | import com.yoho.error.exception.ServiceException; |
23 | +import com.yohoufo.common.utils.DateUtil; | ||
24 | +import com.yohoufo.common.utils.UfoStringUtils; | ||
25 | +import com.yohoufo.dal.product.BrandMapper; | ||
26 | +import com.yohoufo.dal.product.BrandSeriesMapper; | ||
27 | +import com.yohoufo.dal.product.GoodsImagesMapper; | ||
28 | +import com.yohoufo.dal.product.GoodsMapper; | ||
29 | +import com.yohoufo.dal.product.ProductMapper; | ||
30 | +import com.yohoufo.dal.product.SizeMapper; | ||
31 | +import com.yohoufo.dal.product.StorageMapper; | ||
32 | +import com.yohoufo.dal.product.StoragePriceMapper; | ||
33 | +import com.yohoufo.dal.product.model.Brand; | ||
34 | +import com.yohoufo.dal.product.model.BrandSeries; | ||
35 | +import com.yohoufo.dal.product.model.Goods; | ||
36 | +import com.yohoufo.dal.product.model.GoodsImages; | ||
37 | +import com.yohoufo.dal.product.model.Product; | ||
38 | +import com.yohoufo.dal.product.model.Size; | ||
39 | +import com.yohoufo.dal.product.model.Storage; | ||
40 | +import com.yohoufo.dal.product.model.StoragePrice; | ||
41 | +import com.yohoufo.product.model.GoodsBO; | ||
42 | +import com.yohoufo.product.model.GoodsImageBO; | ||
43 | +import com.yohoufo.product.model.GoodsSize; | ||
44 | +import com.yohoufo.product.model.ProductInfo; | ||
45 | +import com.yohoufo.product.model.ProductSeriesTemplate; | ||
46 | +import com.yohoufo.product.model.ProductSortTemplate; | ||
22 | import com.yohoufo.product.request.StoragePriceBo; | 47 | import com.yohoufo.product.request.StoragePriceBo; |
48 | +import com.yohoufo.product.response.ProductDetailResp; | ||
49 | +import com.yohoufo.product.response.ProductSeriesTemplateResp; | ||
50 | +import com.yohoufo.product.response.ProductSortTemplateResp; | ||
51 | +import com.yohoufo.product.response.StorageDataResp; | ||
52 | +import com.yohoufo.product.response.StorageLeastPriceResp; | ||
23 | import com.yohoufo.product.service.ProductService; | 53 | import com.yohoufo.product.service.ProductService; |
24 | -import com.yohoufo.common.utils.DateUtil; | ||
25 | -import org.springframework.util.CollectionUtils; | ||
26 | 54 | ||
27 | 55 | ||
28 | @Service | 56 | @Service |
@@ -199,13 +227,57 @@ public class ProductServiceImpl implements ProductService{ | @@ -199,13 +227,57 @@ public class ProductServiceImpl implements ProductService{ | ||
199 | @Override | 227 | @Override |
200 | public void createSkup(StoragePriceBo skupBo) { | 228 | public void createSkup(StoragePriceBo skupBo) { |
201 | storagePriceMapper.insert(exchangeCreateSkupBo(skupBo)); | 229 | storagePriceMapper.insert(exchangeCreateSkupBo(skupBo)); |
202 | - addStorageNum(skupBo.getSkup(), skupBo.getStorageId(), 1); | 230 | + } |
231 | + | ||
232 | + @Override | ||
233 | + public void sellerUpdateStatus(StoragePriceBo skupBo) { | ||
234 | + // 卖家修改状态:*1:可售(支付保证金),2:取消支付保证金,3:超时未支付保证金,4:支付保证金后取消售卖 | ||
235 | + if (skupBo == null) { | ||
236 | + throw new ServiceException(400, "skupBo为空!"); | ||
237 | + } | ||
238 | + | ||
239 | + Integer skup = skupBo.getSkup(); | ||
240 | + if (skup == null || skup < 1) { | ||
241 | + throw new ServiceException(400, "skup错误:" + skup); | ||
242 | + } | ||
243 | + | ||
244 | + int status; | ||
245 | + if (skupBo.getStatus() == null || (status = skupBo.getStatus()) < 1 || status > 4) { | ||
246 | + throw new ServiceException(400, "商品(status)错误:" + skupBo.getStatus()); | ||
247 | + } | ||
248 | + | ||
249 | + StoragePrice sp = storagePriceMapper.selectBySkup(skup); | ||
250 | + if (sp == null) { | ||
251 | + throw new ServiceException(400, "商品(skup)不存在:" + skup); | ||
252 | + } | ||
253 | + | ||
254 | + int expectedStatus = (status == 4) ? 1 : 0; | ||
255 | + if (sp.getStatus() == null || sp.getStatus() != expectedStatus) { | ||
256 | + throw new ServiceException(400, "商品(skup)状态已变更:" + sp.getStatus()); | ||
257 | + } | ||
258 | + | ||
259 | + // 使其可售 | ||
260 | + if (status == 1) { | ||
261 | + if (storagePriceMapper.updateStatus(skup, 1, 0) == 0) { | ||
262 | + throw new ServiceException(400, "商品(skup)状态已变更"); | ||
263 | + } | ||
264 | + addStorageNum(skup, sp.getStorageId(), 1); | ||
265 | + } else if (status == 2 || status == 3) { | ||
266 | + if (storagePriceMapper.updateStatus(skup, status, 0) == 0) { | ||
267 | + throw new ServiceException(400, "商品(skup)状态已变更"); | ||
268 | + } | ||
269 | + } else { | ||
270 | + if (storagePriceMapper.updateStatus(skup, status, 1) == 0) { | ||
271 | + throw new ServiceException(400, "商品(skup)状态已变更"); | ||
272 | + } | ||
273 | + addStorageNum(skup, sp.getStorageId(), -1); | ||
274 | + } | ||
203 | } | 275 | } |
204 | 276 | ||
205 | @Override | 277 | @Override |
206 | public void saleSkup(Integer productId, Integer skup) { | 278 | public void saleSkup(Integer productId, Integer skup) { |
207 | checkParamValid(productId, skup); | 279 | checkParamValid(productId, skup); |
208 | - checkProductCanSale(productId); | 280 | + checkProductStatus(productId); |
209 | StoragePrice sp = checkSkupCanSale(skup); | 281 | StoragePrice sp = checkSkupCanSale(skup); |
210 | if (!doSaleSkup(skup)) { | 282 | if (!doSaleSkup(skup)) { |
211 | throw new ServiceException(400, "商品(skup)已卖出:" + skup); | 283 | throw new ServiceException(400, "商品(skup)已卖出:" + skup); |
@@ -214,32 +286,53 @@ public class ProductServiceImpl implements ProductService{ | @@ -214,32 +286,53 @@ public class ProductServiceImpl implements ProductService{ | ||
214 | } | 286 | } |
215 | 287 | ||
216 | @Override | 288 | @Override |
217 | - public void cancelSaleSkup(Integer skup) { | ||
218 | - StoragePrice sp = checkSkupCanCancel(skup); | ||
219 | - if (!doCancelSaleSkup(skup)) { | 289 | + public void cancelSaleSkup(Integer skup, Integer status) { |
290 | + StoragePrice sp = checkSkupCanCancel(skup, status); | ||
291 | + if (!doCancelSaleSkup(skup, status)) { | ||
220 | throw new ServiceException(400, "商品(skup)取消售卖失败:" + skup); | 292 | throw new ServiceException(400, "商品(skup)取消售卖失败:" + skup); |
221 | } | 293 | } |
222 | addStorageNum(skup, sp.getStorageId(), 1); | 294 | addStorageNum(skup, sp.getStorageId(), 1); |
223 | } | 295 | } |
224 | 296 | ||
225 | - private StoragePrice checkSkupCanCancel(Integer skup) { | 297 | + @Override |
298 | + public void setDepotNum(Integer skup, Integer depotNum) { | ||
299 | + LOGGER.info("setDepotNum skup = {}", skup); | ||
300 | + StoragePrice sp = storagePriceMapper.selectBySkup(skup); | ||
301 | + if (sp == null) { | ||
302 | + throw new ServiceException(400, "商品(skup)不存在:" + skup); | ||
303 | + } | ||
304 | + if (sp.getStatus() == null || sp.getStatus() != 100) { | ||
305 | + throw new ServiceException(400, "商品(skup)没有卖出:" + skup); | ||
306 | + } | ||
307 | + if (depotNum == null || depotNum < 1 || depotNum > 2) { | ||
308 | + throw new ServiceException(400, "鉴定中心id错误:" + depotNum); | ||
309 | + } | ||
310 | + if (storagePriceMapper.updateDepotNum(skup, depotNum) != 1) { | ||
311 | + throw new ServiceException(400, "商品(skup)没有卖出:" + skup); | ||
312 | + } | ||
313 | + } | ||
314 | + | ||
315 | + private StoragePrice checkSkupCanCancel(Integer skup, Integer status) { | ||
226 | LOGGER.info("checkSkupCanCancel skup = {}", skup); | 316 | LOGGER.info("checkSkupCanCancel skup = {}", skup); |
317 | + if (status == null || status < 101 || status > 103) { | ||
318 | + throw new ServiceException(400, "status状态错误:" + skup); | ||
319 | + } | ||
227 | StoragePrice sp = storagePriceMapper.selectBySkup(skup); | 320 | StoragePrice sp = storagePriceMapper.selectBySkup(skup); |
228 | if (sp == null) { | 321 | if (sp == null) { |
229 | throw new ServiceException(400, "商品(skup)不存在:" + skup); | 322 | throw new ServiceException(400, "商品(skup)不存在:" + skup); |
230 | } | 323 | } |
231 | - if (sp.getStatus() == null || sp.getStatus() != 2) { | 324 | + if (sp.getStatus() == null || sp.getStatus() != 100) { |
232 | throw new ServiceException(400, "商品(skup)没有卖出:" + skup); | 325 | throw new ServiceException(400, "商品(skup)没有卖出:" + skup); |
233 | } | 326 | } |
234 | return sp; | 327 | return sp; |
235 | } | 328 | } |
236 | 329 | ||
237 | - private boolean doCancelSaleSkup(Integer skup) { | ||
238 | - return storagePriceMapper.cancelSaleSkup(skup) == 1; | 330 | + private boolean doCancelSaleSkup(Integer skup, Integer status) { |
331 | + return storagePriceMapper.updateStatus(skup, status, 100) == 1; | ||
239 | } | 332 | } |
240 | 333 | ||
241 | private boolean doSaleSkup(Integer skup) { | 334 | private boolean doSaleSkup(Integer skup) { |
242 | - return storagePriceMapper.saleSkup(skup) == 1; | 335 | + return storagePriceMapper.updateStatus(skup, 100, 1) == 1; |
243 | } | 336 | } |
244 | 337 | ||
245 | private void addStorageNum(Integer skup, Integer storageId, Integer num) { | 338 | private void addStorageNum(Integer skup, Integer storageId, Integer num) { |
@@ -272,7 +365,7 @@ public class ProductServiceImpl implements ProductService{ | @@ -272,7 +365,7 @@ public class ProductServiceImpl implements ProductService{ | ||
272 | return sp; | 365 | return sp; |
273 | } | 366 | } |
274 | 367 | ||
275 | - private void checkProductCanSale(Integer productId) { | 368 | + private void checkProductStatus(Integer productId) { |
276 | LOGGER.info("checkProductCanSale productId = {}", productId); | 369 | LOGGER.info("checkProductCanSale productId = {}", productId); |
277 | Product p = productMapper.selectByPrimaryKey(productId); | 370 | Product p = productMapper.selectByPrimaryKey(productId); |
278 | if (p == null) { | 371 | if (p == null) { |
@@ -282,7 +375,7 @@ public class ProductServiceImpl implements ProductService{ | @@ -282,7 +375,7 @@ public class ProductServiceImpl implements ProductService{ | ||
282 | throw new ServiceException(400, "商品已删除:" + productId); | 375 | throw new ServiceException(400, "商品已删除:" + productId); |
283 | } | 376 | } |
284 | if (p.getShelveStatus() == null || p.getShelveStatus() != 1) { | 377 | if (p.getShelveStatus() == null || p.getShelveStatus() != 1) { |
285 | - throw new ServiceException(400, "商品不可售:" + productId); | 378 | + throw new ServiceException(400, "商品已下架:" + productId); |
286 | } | 379 | } |
287 | } | 380 | } |
288 | 381 | ||
@@ -310,6 +403,8 @@ public class ProductServiceImpl implements ProductService{ | @@ -310,6 +403,8 @@ public class ProductServiceImpl implements ProductService{ | ||
310 | throw new ServiceException(400, "productId错误:" + productId); | 403 | throw new ServiceException(400, "productId错误:" + productId); |
311 | } | 404 | } |
312 | 405 | ||
406 | + checkProductStatus(skupBo.getProductId()); | ||
407 | + | ||
313 | Integer goodsId = skupBo.getGoodsId(); | 408 | Integer goodsId = skupBo.getGoodsId(); |
314 | if (goodsId == null || goodsId < 1) { | 409 | if (goodsId == null || goodsId < 1) { |
315 | throw new ServiceException(400, "goodsId错误:" + goodsId); | 410 | throw new ServiceException(400, "goodsId错误:" + goodsId); |
@@ -320,11 +415,6 @@ public class ProductServiceImpl implements ProductService{ | @@ -320,11 +415,6 @@ public class ProductServiceImpl implements ProductService{ | ||
320 | throw new ServiceException(400, "storageId错误:" + storageId); | 415 | throw new ServiceException(400, "storageId错误:" + storageId); |
321 | } | 416 | } |
322 | 417 | ||
323 | - Integer depotNum = skupBo.getDepotNum(); | ||
324 | - if (depotNum == null || depotNum < 1) { | ||
325 | - throw new ServiceException(400, "depotNum错误:" + depotNum); | ||
326 | - } | ||
327 | - | ||
328 | Integer sellerUid = skupBo.getSellerUid(); | 418 | Integer sellerUid = skupBo.getSellerUid(); |
329 | if (sellerUid == null || sellerUid < 1) { | 419 | if (sellerUid == null || sellerUid < 1) { |
330 | throw new ServiceException(400, "sellerUid错误:" + sellerUid); | 420 | throw new ServiceException(400, "sellerUid错误:" + sellerUid); |
@@ -332,7 +422,7 @@ public class ProductServiceImpl implements ProductService{ | @@ -332,7 +422,7 @@ public class ProductServiceImpl implements ProductService{ | ||
332 | 422 | ||
333 | BigDecimal price = skupBo.getPrice(); | 423 | BigDecimal price = skupBo.getPrice(); |
334 | if (price == null || price.compareTo(BigDecimal.ZERO) <= 0) { | 424 | if (price == null || price.compareTo(BigDecimal.ZERO) <= 0) { |
335 | - throw new ServiceException(400, "sellerUid错误:" + price); | 425 | + throw new ServiceException(400, "价格不合法:" + price); |
336 | } | 426 | } |
337 | LOGGER.info("skupBo 校验通过:skup = {}", skupBo.getSkup()); | 427 | LOGGER.info("skupBo 校验通过:skup = {}", skupBo.getSkup()); |
338 | 428 | ||
@@ -342,11 +432,11 @@ public class ProductServiceImpl implements ProductService{ | @@ -342,11 +432,11 @@ public class ProductServiceImpl implements ProductService{ | ||
342 | sp.setStorageId(storageId); | 432 | sp.setStorageId(storageId); |
343 | sp.setPrice(price); | 433 | sp.setPrice(price); |
344 | sp.setSellerUid(sellerUid); | 434 | sp.setSellerUid(sellerUid); |
345 | - sp.setDepotNum(depotNum); | 435 | + sp.setDepotNum(0); // 未设置 |
346 | sp.setSkup(skup); | 436 | sp.setSkup(skup); |
347 | sp.setCreateTime((int) (System.currentTimeMillis() / 1000)); | 437 | sp.setCreateTime((int) (System.currentTimeMillis() / 1000)); |
348 | sp.setUpdateTime(0); | 438 | sp.setUpdateTime(0); |
349 | - sp.setStatus(1); | 439 | + sp.setStatus(0); |
350 | 440 | ||
351 | LOGGER.info("StoragePrice 解析结果为: {}", sp); | 441 | LOGGER.info("StoragePrice 解析结果为: {}", sp); |
352 | return sp; | 442 | return sp; |
@@ -444,6 +534,7 @@ public class ProductServiceImpl implements ProductService{ | @@ -444,6 +534,7 @@ public class ProductServiceImpl implements ProductService{ | ||
444 | return goodsBOs; | 534 | return goodsBOs; |
445 | } | 535 | } |
446 | 536 | ||
537 | + @SuppressWarnings("unused") | ||
447 | private String buildImageFullUrl(String url) { | 538 | private String buildImageFullUrl(String url) { |
448 | if (!StringUtils.startsWith(url, "http")){ | 539 | if (!StringUtils.startsWith(url, "http")){ |
449 | return ImagesHelper.template2(url, ImagesHelper.SYS_BUCKET.get(ImagesHelper.SYS_GOODS_NAME)).replaceAll("extent\\/\\{width}x\\{height}\\/",""); | 540 | return ImagesHelper.template2(url, ImagesHelper.SYS_BUCKET.get(ImagesHelper.SYS_GOODS_NAME)).replaceAll("extent\\/\\{width}x\\{height}\\/",""); |
-
Please register or login to post a comment