| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public KeyOrder addKeyOrder(SubmitKeyInfo keyInfo, Long uid, String day) throws KeyOrderException, WxOrderCountException { |
| | | public KeyOrder addKeyOrder(SubmitKeyInfo keyInfo, Long uid, String day, Integer orderType, DYOrderDto orderDto) throws KeyOrderException, WxOrderCountException { |
| | | // 判断提交次数是否过量 |
| | | if (uid != null) { |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(uid); |
| | | wxUserOrderCountService.addOrderCount(uid, OrderCountTypeEnum.SUBMIT_TOKEN_COUNT, day, 1, settings.getTotalOrderCountPerDay()); |
| | | OrderCountTypeEnum countType = OrderCountTypeEnum.SUBMIT_TOKEN_COUNT; |
| | | wxUserOrderCountService.addOrderCount(uid, countType, day, 1, settings.getTotalOrderCountPerDay()); |
| | | } |
| | | String id = OrderFactory.createId(keyInfo.getKey()); |
| | | KeyOrder order = keyOrderMapper.selectById(id); |
| | |
| | | order.setState(KeyOrder.STATE_NOT_PROCESS); |
| | | order.setStateDesc("尚未处理"); |
| | | order.setCreateTime(new Date()); |
| | | if(orderType!=Constant.ORDER_TYPE_UNKNOWN){ |
| | | order.setOrderType(orderType); |
| | | } |
| | | if (orderDto != null) { |
| | | order.setOrderNo(orderDto.getOrder_id()); |
| | | } |
| | | |
| | | keyOrderMapper.insertSelective(order); |
| | | |
| | | |
| | |
| | | return; |
| | | } |
| | | if (old.getUid() != null) { |
| | | wxUserOrderCountService.addOrderCount(old.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, day, 1, null); |
| | | Integer orderType = old.getOrderType(); |
| | | wxUserOrderCountService.addOrderCount(old.getUid(), (orderType==null||orderType==Constant.ORDER_TYPE_DY)? OrderCountTypeEnum.DY_ORDER_PAY:OrderCountTypeEnum.KS_ORDER_PAY, day, 1, null); |
| | | } |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | |
| | | |
| | | |
| | | @Override |
| | | public Long getCanDistributeUid() { |
| | | public Long getCanDistributeUid(int maxQueueSize) { |
| | | // 最近1小时有活跃,且不算12以上未执行的数据 |
| | | List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L), new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 12L)); |
| | | if (list == null || list.size() == 0) { |
| | |
| | | i--; |
| | | } |
| | | } |
| | | |
| | | List<OrderDistributeCountInfo> filterList = new ArrayList<>(); |
| | | // count小于2直接视为0 |
| | | for (OrderDistributeCountInfo info : list) { |
| | | if (info.getCount() < 2) { |
| | | info.setCount(0); |
| | | if (info.getCount() >= maxQueueSize) { |
| | | continue; |
| | | } |
| | | filterList.add(info); |
| | | } |
| | | if (filterList.size() <= 0) { |
| | | return null; |
| | | } |
| | | |
| | | Comparator<OrderDistributeCountInfo> cm = new Comparator<OrderDistributeCountInfo>() { |
| | | @Override |
| | | public int compare(OrderDistributeCountInfo o1, OrderDistributeCountInfo o2) { |
| | | return o1.getCount() - o2.getCount(); |
| | | } |
| | | }; |
| | | list.sort(cm); |
| | | if (list.get(0).getCount() == 0) { |
| | | // 处理大多数设备都没有分配的情况 |
| | | // 将为0的数据随机分配 |
| | | List<OrderDistributeCountInfo> tempList = new ArrayList<>(); |
| | | for (OrderDistributeCountInfo info : list) { |
| | | if (info.getCount() == 0) { |
| | | tempList.add(info); |
| | | } |
| | | } |
| | | int index = new Random().nextInt(tempList.size()); |
| | | if (index < 0) { |
| | | index = 0; |
| | | } |
| | | if (index >= tempList.size()) { |
| | | index = tempList.size() - 1; |
| | | } |
| | | return tempList.get(index).getUid(); |
| | | } |
| | | return list.get(0).getUid(); |
| | | return ClientDistributeUtil.computeDistributeClient(filterList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DYOrderDto verifyKey(String orderNoDesc, String orderStatus, String money, Long uid) throws KeyVerifyException { |
| | | int orderType = Constant.ORDER_TYPE_UNKNOWN; |
| | | if (orderNoDesc.contains("抖音")||orderNoDesc.contains("上海格物致品")) { |
| | | orderType = Constant.ORDER_TYPE_DY; |
| | | } else if (orderNoDesc.contains("快手")) { |
| | | orderType = Constant.ORDER_TYPE_KS; |
| | | } |
| | | |
| | | public DYOrderDto verifyKey(String orderNoDesc, String orderStatus, String money, Long uid, String keyId) throws KeyVerifyException { |
| | | int orderType = AlipayOrderUtil.getOrderType(orderNoDesc); |
| | | if (uid != null) { |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(uid); |
| | | |
| | | OrderCountTypeEnum orderCountType=OrderCountTypeEnum.SUBMIT_TOKEN_COUNT; |
| | | int maxCount = settings.getTotalOrderCountPerDay(); |
| | | switch (orderType){ |
| | | case Constant.ORDER_TYPE_DY: |
| | | orderCountType = OrderCountTypeEnum.DY_ORDER_PAY; |
| | | maxCount = settings.getDyOrderCountPerDay(); |
| | | break; |
| | | case Constant.ORDER_TYPE_KS: |
| | | orderCountType = OrderCountTypeEnum.KS_ORDER_PAY; |
| | | maxCount = settings.getKsOrderCountPerDay(); |
| | | break; |
| | | } |
| | | |
| | | try { |
| | | wxUserOrderCountService.isOrderCountLimit(uid, orderCountType, TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyy-MM-dd"), 1, settings.getTotalOrderCountPerDay()); |
| | | wxUserOrderCountService.isOrderCountLimit(uid, orderCountType, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT), 1, maxCount); |
| | | } catch (WxOrderCountException e) { |
| | | e.printStackTrace(); |
| | | throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, "今日提交超过" +maxCount + "次"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | String orderNo = ""; |
| | |
| | | try { |
| | | if (orderType == Constant.ORDER_TYPE_DY && !StringUtil.isNullOrEmpty(orderNo)) { |
| | | dyOrderDto = DYOrderApi.getOrderDetail(orderNo); |
| | | if (dyOrderDto != null) { |
| | | if (dyOrderDto != null && false) { |
| | | // 验证金额 |
| | | if (dyOrderDto.getPay_amount().intValue() != new BigDecimal(money).multiply(new BigDecimal(100)).setScale(0).intValue()) { |
| | | throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH, String.format("支付金额与订单金额不一致:%s-%d", money, dyOrderDto.getPay_amount())); |
| | | } |
| | | // 验证订单号是否已经存在 |
| | | KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery(); |
| | | query.orderNo = orderNo; |
| | | query.orderType = orderType; |
| | | if (count(query) > 1) { |
| | | throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_NO_REPEAT, "订单号重复提交"); |
| | | } |
| | | } |
| | | } else { |
| | | throw new KeyOrderException("抖音订单获取失败"); |