@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); } }
@Override public List<VipAccount> listVip(User user) { // 初始化 int beginSellTime = configService.getInt("goods.begin.sell.time"); int effectiveTime = configService.getInt("goods.effective.time"); int endSellTime = configService.getInt("goods.end.sell.time"); Calendar calendar = Calendar.getInstance(); int curHour = calendar.get(Calendar.HOUR_OF_DAY); if (curHour >= beginSellTime) { // 获取大于等于今日开卖点买的订单 calendar.set(Calendar.HOUR_OF_DAY, beginSellTime); Date startTime = calendar.getTime(); Map<String, Object> paramMap = new HashMap<>(); paramMap.put("userid", user.getId()); paramMap.put("startTime", startTime); return vipAccountMapper.listByUserAndTime(paramMap); } else if (curHour < effectiveTime) { // 获取昨天开买点到今日结束点购买的订单 calendar.set(Calendar.HOUR_OF_DAY, endSellTime); Date endTime = calendar.getTime(); calendar.add(Calendar.DATE, -1); calendar.set(Calendar.HOUR_OF_DAY, beginSellTime); Date startTime = calendar.getTime(); Map<String, Object> paramMap = new HashMap<>(); paramMap.put("userid", user.getId()); paramMap.put("startTime", startTime); paramMap.put("endTime", endTime); return vipAccountMapper.listByUserAndTime(paramMap); } return null; }