| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.JedisPool; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | private JedisPool jedisPool; |
| | | |
| | | |
| | | /** |
| | | * 礼金创建成功 |
| | |
| | | * @param money |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void createLijinSuccess(Long accountId, Long auctionId, BigDecimal money, Date createTime) { |
| | | public void createLijinSuccess(Long accountId, String auctionId, BigDecimal money, Date createTime) { |
| | | String day = TimeUtil.getGernalTime(createTime.getTime(), "yyyyMMdd"); |
| | | String goodsKey = String.format("lijingoodsnum-%s-%s", day, accountId); |
| | | String accountMoneyKey = String.format("lijinaccountmoney-%s-%s", day, accountId); |
| | |
| | | //获取账号当日的商品数量 |
| | | long goodsNum = redisTemplate.opsForSet().size(goodsKey); |
| | | //获取账号当日的资金消耗 |
| | | Long todayMoney = Long.parseLong(redisTemplate.opsForValue().get(accountMoneyKey) + ""); |
| | | |
| | | Long todayMoney = null; |
| | | Jedis jedis = jedisPool.getResource(); |
| | | try { |
| | | todayMoney = Long.parseLong(jedis.get(accountMoneyKey) + ""); |
| | | } catch (NumberFormatException e) { |
| | | jedis.set(accountMoneyKey, money.multiply(new BigDecimal(100)).intValue() + ""); |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | |
| | | //同步到数据库 |
| | | LiJinProviderTaoKeAccount account = liJinProviderAccountMapper.selectByPrimaryKeyForUpdate(accountId); |
| | | if (account != null) { |
| | | LiJinProviderTaoKeAccount update = new LiJinProviderTaoKeAccount(); |
| | | update.setId(account.getId()); |
| | | update.setTodayConsumeMoney(new BigDecimal(todayMoney).divide(new BigDecimal(100), 2, RoundingMode.FLOOR)); |
| | | update.setTodayConsumeNumber((int) goodsNum); |
| | | update.setUpdateTime(new Date()); |
| | |
| | | * @param accountId |
| | | */ |
| | | public void initTodayData(Long accountId) { |
| | | createLijinSuccess(accountId, 1L, new BigDecimal(0), new Date()); |
| | | createLijinSuccess(accountId, 1L+"", new BigDecimal(0), new Date()); |
| | | } |
| | | |
| | | |
| | |
| | | public void deleteInfoInRedis(Date date) { |
| | | String day = TimeUtil.getGernalTime(date.getTime(), "yyyyMMdd"); |
| | | String goodsKey = String.format("lijingoodsnum-%s-*", day); |
| | | String accountMoneyKey = String.format("lijinaccountmoney-%s-%s", day); |
| | | String accountMoneyKey = String.format("lijinaccountmoney-%s-*", day); |
| | | redisTemplate.delete(goodsKey); |
| | | redisTemplate.delete(accountMoneyKey); |
| | | } |