Commit 1c56ec2c authored by shiyu's avatar shiyu

版本3.5,拍卖保证金兼容上一版本

parent 10871d61
......@@ -45,4 +45,12 @@ public interface EarnestRecordDao {
* @return
*/
long sumForOccupy(EarnestRecordRequestDto dto);
/**
* 检查是否存在被保证金记录
* 兼容之前没有保证金的逻辑
* @param dto
* @return
*/
boolean isExisted(EarnestRecordRequestDto dto);
}
......@@ -68,4 +68,18 @@ public class EarnestRecordDaoImpl implements EarnestRecordDao {
JdbcHelper.ifPresent(dto.getState(), criteria :: andStateEqualTo);
return earnestRecordMapper.sumForOccupy(example);
}
@Override
public boolean isExisted(EarnestRecordRequestDto dto) {
EarnestRecordExample example = new EarnestRecordExample();
EarnestRecordExample.Criteria criteria = example.createCriteria();
JdbcHelper.ifPresent(dto.getUserId(), criteria :: andUserIdEqualTo);
JdbcHelper.ifPresent(dto.getItemId(), criteria :: andItemIdEqualTo);
JdbcHelper.ifPresent(dto.getType(), criteria :: andTypeEqualTo);
JdbcHelper.ifPresent(dto.getState(), criteria :: andStateEqualTo);
JdbcHelper.ifPresent(dto.getTypeList(), criteria :: andTypeIn);
JdbcHelper.ifPresent(dto.getFilterTypeList(), criteria :: andTypeNotIn);
return earnestRecordMapper.countByExample(example) > 0;
}
}
......@@ -15,6 +15,7 @@ import com.wwdz.ch.db.domain.openShop.UserAccount;
import com.wwdz.ch.db.dto.request.distribution.DistributionOrderRequestDto;
import com.wwdz.ch.db.dto.request.openShop.EarnestOrderRequestDto;
import com.wwdz.ch.db.dto.request.openShop.EarnestRecordRequestDto;
import com.wwdz.ch.wx.service.UserAccountService;
import com.wwdz.ch.wx.service.openShop.AuctionEarnestService;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
......@@ -50,6 +51,9 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
@Autowired
RedissonClient redissonClient;
@Autowired
UserAccountService userAccountService;
@Override
public Result payEarnest(EarnestOrderRequestDto dto) {
try {
......@@ -200,6 +204,19 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
if (!lock.tryLock(5, 5, TimeUnit.SECONDS)) {
return Result.failed("操作过快,稍后再试");
}
userAccountService.initAccount(dto.getUserId());
//检查该用户是否有被占用的保证金,兼容之前没有保证金的逻辑
EarnestRecordRequestDto checkDto = new EarnestRecordRequestDto();
checkDto.setUserId(dto.getUserId());
checkDto.setItemId(dto.getItemId());
checkDto.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
checkDto.setState(EarnestEnum.StateEnum.VALID.getCode());
if (!earnestRecordDao.isExisted(checkDto)) {
logger.info("该用户之前没有被占用过保证金,无需释放额度");
return Result.success();
}
long auctionPrice = dto.getAuctionPrice();
BigDecimal earnestAmount = new BigDecimal(String.valueOf(auctionPrice)).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应占用的保证金
......@@ -250,15 +267,25 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
@Override
public Result deductEarnest(EarnestRecordRequestDto dto) {
/*if (CommConsts.NOT_SEND_MSG_USERID.contains(dto.getUserId())) {
return Result.success();
}*/
String itemIdKey = CommConsts.EARNEST_ACCOUNT_LOCK + dto.getUserId();
RLock lock = redissonClient.getLock(itemIdKey);
try {
if (!lock.tryLock(5, 5, TimeUnit.SECONDS)) {
return Result.failed("操作过快,稍后再试");
}
userAccountService.initAccount(dto.getUserId());
//检查该用户是否有被占用的保证金,兼容之前没有保证金的逻辑
EarnestRecordRequestDto checkDto = new EarnestRecordRequestDto();
checkDto.setUserId(dto.getUserId());
checkDto.setItemId(dto.getItemId());
checkDto.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
checkDto.setState(EarnestEnum.StateEnum.VALID.getCode());
if (!earnestRecordDao.isExisted(checkDto)) {
logger.info("该用户之前没有被占用过保证金,无需扣除");
return Result.success();
}
long auctionPrice = dto.getAuctionPrice();
BigDecimal earnestAmount = new BigDecimal(String.valueOf(auctionPrice)).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应占用的保证金
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment