| | |
| | | import com.mzl.flower.mapper.point.PointGoodsMapper; |
| | | import com.mzl.flower.mapper.point.PointGoodsRecordMapper; |
| | | import com.mzl.flower.service.BaseService; |
| | | import com.mzl.flower.service.payment.RedisLockService; |
| | | import com.mzl.flower.utils.UUIDGenerator; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private CustomerPointDetailMapper customerPointDetailMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private RedisLockService lockService; |
| | | |
| | | public Long addPointGoods(PointGoodsCreateDTO dto){ |
| | | PointGoods p = new PointGoods(); |
| | |
| | | } |
| | | } |
| | | |
| | | public synchronized void exchangeGoods(ExchangeGoodsDTO dto) { |
| | | public void exchangeGoods(ExchangeGoodsDTO dto) { |
| | | String key="EXCHANGE_GOODS:"+dto.getGoodsId()+":"+SecurityUtils.getUserId(); |
| | | boolean lock = lockService.getObjectLock(key, ""); |
| | | if(!lock){ |
| | | throw new ValidationException("系统操作频繁,请稍后重试"); |
| | | } |
| | | try { |
| | | PointGoods p = pointGoodsMapper.selectById(dto.getGoodsId()); |
| | | if(p == null){ |
| | | throw new ValidationException("商品未找到"); |
| | |
| | | //更新库存 |
| | | p.setStock(p.getStock()- dto.getNum()); |
| | | pointGoodsMapper.updateById(p); |
| | | }catch (Exception e){ |
| | | throw new ValidationException("兑换失败"); |
| | | }finally { |
| | | lockService.releaseObjectLock(key,""); |
| | | } |
| | | |
| | | } |
| | | |
| | | public Page<PointGoodsRecordDTO> myExchangeGoods(QueryExchangeGoodsDTO dto, Page page) { |