Authored by chenchao

use cas lock

fix shop check bug
... ... @@ -89,7 +89,7 @@ public interface StorageDepositMapper {
int updateDelStatusByCode(@Param("uid")Integer uid, @Param("depositCode")String depositCode, @Param("status")Integer status);
int updateStorageShelveStatusByCAS(@Param("uid")int uid,
int updateStorageLockFlagByCAS(@Param("uid")int uid,
@Param("depositCode")String depositCode,
@Param("status")int status,
@Param("expectStatus")int expectStatus
... ...
... ... @@ -414,11 +414,12 @@
</update>
<update id="updateStorageShelveStatusByCAS">
<update id="updateStorageLockFlagByCAS">
update storage_deposit
set order_status = #{status,jdbcType=INTEGER} ,update_time = unix_timestamp(now())
set lock_flag = #{status,jdbcType=INTEGER} ,update_time = unix_timestamp(now())
where owner_uid = #{uid,jdbcType=INTEGER}
and deposit_code = #{depositCode,jdbcType=VARCHAR}
AND order_status = #{expectStatus,jdbcType=INTEGER}
AND lock_flag = #{expectStatus,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -2,7 +2,6 @@ package com.yohoufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
import com.yohobuy.ufo.model.order.bo.DepositProductBo;
... ... @@ -309,7 +308,7 @@ public class DepositServiceImpl implements DepositService {
}
return successList;
}
/**
* 批量上架-查询
* TODO 应当锁定相关记录,加中间状态
... ... @@ -325,19 +324,17 @@ public class DepositServiceImpl implements DepositService {
uid, storageId, num);
return sdList;
}
/*
List<StorageDeposit> lockedList = new ArrayList<>(sdList.size());
for (StorageDeposit sd : sdList){
for (StorageDeposit sd : sdList) {
int rows= storageDepositMapper.updateStorageShelveStatusByCAS(uid, sd.getDepositCode(), 11, 0);
if(rows == 1){
int rows = storageDepositMapper.updateStorageLockFlagByCAS(uid, sd.getDepositCode(), 1, 0);
if (rows == 1) {
lockedList.add(sd);
}else{
} else {
LOGGER.warn("getStorageDeposit4Publish updateStorageShelveStatusByCAS fail ,{}", sd);
}
}
return lockedList;
*/
return sdList;
}
// 批量下架
... ...
... ... @@ -203,14 +203,15 @@ public class ShoppingServiceImpl implements IShoppingService {
throw new ServiceException(ServiceError.ORDER_SKUP_CANNOT_SELL);
}
SkupType skupType = SkupType.getSkupType(skupGood.getAttributes());
int sellerUid = skupGood.getUid();
switch (skupType){
case QUICK_DELIVER:{
//寄存商品 是否存在
StorageDeposit sd = storageDepositMapper.queryByOwnerSkup(uid, skup);
StorageDeposit sd = storageDepositMapper.queryByOwnerSkup(sellerUid, skup);
Integer depositStatus = null;
if (Objects.isNull(sd) || (depositStatus = sd.getOrderStatus()) == 0){
logger.warn("deposit not exist or sale out, uid {}, skup type {}, skup {} depositStatus {}",
uid, skupType, skup, depositStatus);
logger.warn("deposit not exist or sale out, uid {}, skup type {},sellerUid {} skup {} depositStatus {}",
uid, skupType,sellerUid, skup, depositStatus);
ServiceExceptions.throwServiceException(401, "商品已售出");
}
break;
... ...