| | |
| | | import com.taoke.autopay.entity.WxUserOrderCount; |
| | | import com.taoke.autopay.exception.WxOrderCountException; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.service.UserSettingService; |
| | | import com.taoke.autopay.service.WxUserOrderCountService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | @Resource |
| | | private WxUserOrderCountMapper wxUserOrderCountMapper; |
| | | |
| | | @Resource |
| | | private UserSettingService userSettingService; |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void addOrderCount(Long uid, OrderCountTypeEnum orderType, String day, int count, Integer maxCount) throws WxOrderCountException { |
| | | // 统计用户总次数 |
| | | WxUserOrderCountMapper.DaoQuery daoQuery=new WxUserOrderCountMapper.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.orderType=orderType.getType(); |
| | | Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery); |
| | | if(totalCount==null){ |
| | | totalCount = 0L; |
| | | } |
| | | if(totalCount>Integer.MAX_VALUE){ |
| | | totalCount = (long)Integer.MAX_VALUE; |
| | | } |
| | | int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue()); |
| | | if(maxCount==null){ |
| | | maxCount =Integer.MAX_VALUE; |
| | | } |
| | | maxCount = Math.min(submitCount, maxCount); |
| | | WxUserOrderCount info = new WxUserOrderCount(); |
| | | info.setDay(day); |
| | | info.setOrderType(orderType.getType()); |
| | |
| | | |
| | | if (old != null) { |
| | | if (maxCount != null && maxCount < count + old.getOrderCount()) { |
| | | throw new WxOrderCountException("超过次数最大值"); |
| | | throw new WxOrderCountException(String.format("今日超过最大提交次数(%s次)", maxCount)); |
| | | } |
| | | WxUserOrderCount update = new WxUserOrderCount(); |
| | | update.setId(info.getId()); |
| | |
| | | update.setUpdateTime(new Date()); |
| | | wxUserOrderCountMapper.updateByPrimaryKeySelective(update); |
| | | } else { |
| | | if (maxCount != null && maxCount < count + 0) { |
| | | throw new WxOrderCountException(String.format("今日超过最大提交次数(%s次)", maxCount)); |
| | | } |
| | | info.setCreateTime(new Date()); |
| | | info.setOrderCount(count); |
| | | wxUserOrderCountMapper.insertSelective(info); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void isOrderCountLimit(Long uid, OrderCountTypeEnum orderType, String day, int count, Integer maxCount) throws WxOrderCountException{ |
| | | |
| | | WxUserOrderCountMapper.DaoQuery daoQuery=new WxUserOrderCountMapper.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.orderType=orderType.getType(); |
| | | Long totalCount = wxUserOrderCountMapper.sumOrderCount(daoQuery); |
| | | if(totalCount==null){ |
| | | totalCount = 0L; |
| | | } |
| | | if(totalCount>Integer.MAX_VALUE){ |
| | | totalCount = (long)Integer.MAX_VALUE; |
| | | } |
| | | int submitCount = userSettingService.getLimitCountByTotalCount((int)totalCount.longValue()); |
| | | if(maxCount==null){ |
| | | maxCount =Integer.MAX_VALUE; |
| | | } |
| | | maxCount = Math.min(submitCount, maxCount); |
| | | WxUserOrderCount info = new WxUserOrderCount(); |
| | | info.setDay(day); |
| | | info.setOrderType(orderType.getType()); |
| | | info.setUid(uid); |
| | | info.setId(OrderFactory.createId(info)); |
| | | // 判断是否存在 |
| | | WxUserOrderCount old = wxUserOrderCountMapper.selectByPrimaryKeyForUpdate(info.getId()); |
| | | |
| | | |
| | | if (old != null) { |
| | | if (maxCount != null && maxCount < count + old.getOrderCount()) { |
| | | throw new WxOrderCountException(String.format("今日超过最大提交次数(%s次)", maxCount)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public WxUserOrderCount get(Long uid, OrderCountTypeEnum orderType, String day) { |
| | | WxUserOrderCountMapper.DaoQuery daoQuery = new WxUserOrderCountMapper.DaoQuery(); |
| | | daoQuery.uid = uid; |