@Transactional(rollbackFor = Exception.class) @Override public void reset() { int vipSellCount = configService.getInt("vip.sell.count"); Map<Integer, Integer> map = new HashMap<>(); List<VipAccount> list = vipAccountMapper.listAll(); for (VipAccount vipAccount : list) { vipAccount.setCount(vipSellCount); vipAccountMapper.updateByPrimaryKey(vipAccount); Integer count = map.get(vipAccount.getType()); if (null == count) { map.put(vipAccount.getType(), 1); } else { map.put(vipAccount.getType(), ++count); } } // 更新商品数量 for (Integer vipType : map.keySet()) { Goods goods = new Goods(); goods.setType(1); goods.setVipType(vipType); goods = goodsMapper.selectByTypeAndVipType(goods); goods.setCount(vipSellCount * map.get(vipType)); goodsMapper.updateByPrimaryKey(goods); } }
@Transactional(rollbackFor = Exception.class) @Override public int save(VipAccount vipAccount) { // 更新商品数量 Goods goods = new Goods(); goods.setType(1); goods.setVipType(vipAccount.getType()); goods = goodsMapper.selectByTypeAndVipType(goods); if (goods != null) { goods.setCount(goods.getCount() + vipAccount.getCount()); goodsMapper.updateByPrimaryKey(goods); } return vipAccountMapper.insert(vipAccount); }