Authored by mali

防并发操作

... ... @@ -51,7 +51,7 @@ public interface StorageDepositMapper {
StorageDeposit selectByDepositCode(@Param("uid") int uid, @Param("depositCode")String depositCode, @Param("statusList")List<Integer> statusList);
List<StorageDeposit> getDepositOffs(@Param("uid") Integer uid, @Param("storageId") Integer storageId, @Param("count") Integer count);
int updateStorageStatus(@Param("depositCode")String depositCode, @Param("status")int status);
int updateStorageStatus(@Param("depositCode")String depositCode, @Param("status")int status, @Param("orderStatus")int orderStatus);
int getUserDepositCount(@Param("uid") Integer uid);
}
\ No newline at end of file
... ...
... ... @@ -347,6 +347,6 @@
<update id="updateStorageStatus">
update storage_deposit
set status = #{status,jdbcType=INTEGER} ,update_time = unix_timestamp(now())
where deposit_code = #{depositCode,jdbcType=VARCHAR} AND del_status = 0
where deposit_code = #{depositCode,jdbcType=VARCHAR} AND del_status = 0 AND order_status = #{orderStatus,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.cache.ControllerCacheAop;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.deposit.DepositOrderService;
... ... @@ -13,10 +18,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.lang.reflect.Method;
/**
* Created by li.ma on 2019/7/9.
*/
... ... @@ -27,6 +35,9 @@ public class DepositOrderController {
@Autowired
private DepositOrderService depositOrderService;
@Autowired
private ControllerCacheAop cacheAop;
/**
* 根据库存货号,计算召回的费用
* @param uid
... ... @@ -83,6 +94,7 @@ public class DepositOrderController {
*/
@RequestMapping(params = "method=ufo.deposit.orderInfo")
@ResponseBody
@Cachable(expire = 60)
public ApiResponse depositOrderInfo(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "deposit_code", required = true)String depositCode) throws GatewayException {
DepositOrderComputeReq req = DepositOrderComputeReq.builder().uid(uid).depositCode(depositCode).build();
... ... @@ -92,4 +104,20 @@ public class DepositOrderController {
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("查询成功").build();
}
@RequestMapping("/depositOrder/clearDepositOrderCache")
@IgnoreSignature
@IgnoreSession
public ApiResponse clearDepositOrderCache(@RequestBody DepositOrderComputeReq bo) {
Integer uid = bo.getUid();
String depositCode = bo.getDepositCode();
LOG.info("in clearDepositOrderCache bo={}", bo);
try {
Method depositOrderInfo = DepositOrderController.class.getMethod("depositOrderInfo", new Class[]{Integer.class, String.class});
cacheAop.clearCache(depositOrderInfo, new Object[]{uid, depositCode});
} catch (Exception e) {
LOG.error("删除寄存订单缓存失败!", e);
}
return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE);
}
}
... ...
... ... @@ -41,7 +41,7 @@ public interface DepositService {
// 剩余存储天数
int getRemainDay(Integer uid, String depositCode);
int changeStorageStatus(String depositCode, int status);
int changeStorageStatus(String depositCode, int status, int orderStatus);
/**
* Do 转 Vo
... ...
... ... @@ -156,6 +156,8 @@ public class DepositOrderService {
setBuyerPrice(storageDeposit.getOrderCode(), priceInfo); // 设置入手价
queryWaybillCode(depositDetailBo);// 查询召回(到期)后寄回的运单号
return DepositOrderComputeResp.builder().userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).depositDetailBo(depositDetailBo).build();
}
... ... @@ -216,4 +218,8 @@ public class DepositOrderService {
}
return storageDeposit;
}
private void queryWaybillCode(DepositDetailBo depositDetailBo) {
}
}
... ...
... ... @@ -20,6 +20,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class DepositOrderPaymentService extends AbstractOrderPaymentService {
private final Logger logger = LoggerFactory.getLogger(getClass());
... ... @@ -129,7 +131,16 @@ public class DepositOrderPaymentService extends AbstractOrderPaymentService {
public void processAfterPay(OrderInfo orderInfo) {
DepositOrder depositOrder = depositOrderService.selectByOrderCode(orderInfo.getOrderCode());
depositService.changeStorageStatus(depositOrder.getDepositCode(), StorageDepositStatusEnum.WAITING_QUERY.getCode());
if (Objects.isNull(depositOrder)) {
logger.error("depositOrderService.selectByOrderCode is null, orderCode is {}", orderInfo.getOrderCode());
return;
}
// 更新为拣货状态的时候,必须是下架状态
int result = depositService.changeStorageStatus(depositOrder.getDepositCode(), StorageDepositStatusEnum.WAITING_QUERY.getCode(), OrderStatus.WAITING_PAY.getCode());
if (result != 1) {
logger.error("depositService.changeStorageStatus find wrong, depositCode is {}, result is {}", depositOrder.getDepositCode(), result);
return;
}
}
private OrderInfo buildOrderInfo(DepositOrder order) {
... ...
... ... @@ -278,8 +278,8 @@ public class DepositServiceImpl implements DepositService {
return getRemainDay(sd.getDepositEndTime());
}
public int changeStorageStatus(String depositCode, int status) {
return storageDepositMapper.updateStorageStatus(depositCode, status);
public int changeStorageStatus(String depositCode, int status, int orderStatus) {
return storageDepositMapper.updateStorageStatus(depositCode, status, orderStatus);
}
/**
... ...