From 27c6695551c7229786ef2cf7dae722886c9edf53 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 09 八月 2024 22:53:44 +0800 Subject: [PATCH] 代理新功能完善 --- src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java | 123 ++++++++++++++++++++++++---------------- 1 files changed, 74 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java index 09e1df1..6ceb5fa 100644 --- a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java +++ b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java @@ -10,10 +10,7 @@ import com.taoke.autopay.exception.KeyVerifyException; import com.taoke.autopay.exception.WxOrderCountException; import com.taoke.autopay.factory.OrderFactory; -import com.taoke.autopay.service.KeyOrderService; -import com.taoke.autopay.service.SystemConfigService; -import com.taoke.autopay.service.WxUserOrderCountService; -import com.taoke.autopay.service.WxUserSettingService; +import com.taoke.autopay.service.*; import com.taoke.autopay.service.agent.ChannelAgentService; import com.taoke.autopay.service.agent.ChannelAgentSharingRatioService; import com.taoke.autopay.utils.*; @@ -57,6 +54,9 @@ @Resource private ChannelAgentSharingRatioService channelAgentSharingRatioService; + @Resource + private ClientInfoService clientInfoService; + @Override public KeyOrder selectById(String id) { @@ -65,11 +65,12 @@ @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); @@ -104,6 +105,13 @@ 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); @@ -137,7 +145,8 @@ 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); @@ -193,6 +202,7 @@ Map<OrderChannelEnum, BigDecimal> shareMoneyMap = channelAgentSharingRatioService.getShareMoneyMap(query.agentId); List<ChannelOrderStatistic> channelOrderStatisticList = keyOrderMapper.statisticChannelOrders(query); BigDecimal totalMoney = new BigDecimal(0); + long totalOrderCount = 0; for (ChannelOrderStatistic s : channelOrderStatisticList) { for (OrderChannelEnum channel : OrderChannelEnum.values()) { @@ -204,67 +214,57 @@ break; } } + totalOrderCount += s.getCount(); } long userCount = keyOrderMapper.countUser(query); ChannelOrderStatistic statistic = new ChannelOrderStatistic(); - statistic.setCount(userCount); + statistic.setUserCount(userCount); statistic.setMoney(totalMoney); + statistic.setCount(totalOrderCount); return statistic; } @Override public List<ChannelOrderStatistic> statisticChannelOrders(Long agentId, Date startTime, Date endTime) { - KeyOrderMapper.DaoQuery daoQuery=new KeyOrderMapper.DaoQuery(); - daoQuery.oMinCreateTime=startTime; - daoQuery.oMaxCreateTime=endTime; + KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery(); + daoQuery.oMinCreateTime = startTime; + daoQuery.oMaxCreateTime = endTime; daoQuery.agentId = agentId; - daoQuery.state =KeyOrder.STATE_PAY; - daoQuery.hasPayTime=true; + daoQuery.state = KeyOrder.STATE_PAY; + daoQuery.hasPayTime = true; return keyOrderMapper.statisticChannelOrders(daoQuery); } @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) { return null; } + // 鎺掗櫎閲嶆柊鍒嗛厤鐨勮澶� + List<Long> excludeIds = clientInfoService.getRePayClientIds(); + for (int i = 0; i < list.size(); i++) { + if (excludeIds.contains(list.get(i).getUid())) { + list.remove(i); + 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 @@ -278,13 +278,31 @@ } @Override - public DYOrderDto verifyKey(String orderNoDesc, String orderStatus, String money) 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(), Constant.DB_DAY_FORMAT), 1, maxCount); + } catch (WxOrderCountException e) { + e.printStackTrace(); + throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, "浠婃棩鎻愪氦瓒呰繃" +maxCount + "娆�"); + } } + String orderNo = ""; // 鍖归厤杩炵画鐨勬暟瀛� @@ -311,11 +329,18 @@ 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("鎶栭煶璁㈠崟鑾峰彇澶辫触"); -- Gitblit v1.8.0