src/main/java/com/taoke/autopay/controller/WebApiController.java
@@ -11,10 +11,12 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.UrlUtils; import javax.annotation.Resource; import java.io.PrintWriter; import java.util.Date; import java.util.List; @Controller @RequestMapping("webapi") @@ -25,11 +27,15 @@ private KeyOrderService keyOrderService; @ResponseBody @RequestMapping(value = "submitKey") public void push(String key, PrintWriter out) { public String submitKey(String key) { if(StringUtil.isNullOrEmpty(key)){ out.print(JsonUtil.loadFalseResult(0,"请上传key")); return; return JsonUtil.loadFalseResult(0,"请上传key"); } List<String> urllist = UrlUtils.parseUrlsFromText(key); if(urllist.isEmpty()||!urllist.get(0).contains("ur.alipay.com")){ return JsonUtil.loadFalseResult("支付宝口令不正确"); } try { KeyOrder order = keyOrderService.addKeyOrder(key); @@ -42,18 +48,11 @@ orderUpdate.setDistributeTime(new Date()); keyOrderService.update(orderUpdate); } out.print(JsonUtil.loadTrueResult("")); return JsonUtil.loadTrueResult(""); } catch (KeyOrderException e) { e.printStackTrace(); out.print(JsonUtil.loadFalseResult(e.getMessage())); return JsonUtil.loadFalseResult(e.getMessage()); } } @ResponseBody @RequestMapping(value = "test") public String test(String key) { return "123123"; } } src/main/java/com/taoke/autopay/controller/client/OrderController.java
@@ -18,6 +18,7 @@ import com.taoke.autopay.utils.JsonUtil; import com.taoke.autopay.utils.StringUtil; import com.taoke.autopay.utils.TimeUtil; import com.taoke.autopay.utils.order.DYOrderApi; import com.taoke.autopay.vo.AcceptData; import com.taoke.autopay.vo.KeyOrderVO; import com.taoke.autopay.vo.OrderFilter; @@ -91,7 +92,7 @@ query.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_NOT_PROCESS}); break; case OrderFilter.STATE_PROCESSED: query.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_PAY}); query.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_PAY, KeyOrder.STATE_REJECT_PAY}); break; case OrderFilter.STATE_PROCESS_ERROR: query.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_NOT_PAY}); @@ -145,10 +146,20 @@ return JsonUtil.loadTrueResult(data); } /** * @author hxh * @description 设置订单号 * @date 23:08 2024/6/24 * @param: acceptData * @param: id 订单ID * @param: orderNo 订单号 * @param: orderStatus 订单状态:订单已取消/已支付 * @return java.lang.String **/ @ResponseBody @RequestMapping("setOrderNo") public String setOrderNo(AcceptData acceptData, String id,String orderNo){ loggerPay.info("setOrderNo: {}-{}",id,orderNo); public String setOrderNo(AcceptData acceptData, String id, String orderNo, String orderStatus) { loggerPay.info("setOrderNo: {}-{}-{}", id, orderNo, orderStatus); if(StringUtil.isNullOrEmpty(id)){ return JsonUtil.loadFalseResult("请上传id"); } @@ -170,17 +181,23 @@ } try { DYOrderDto dto = new DYOrderDto(); // DYOrderApi.getOrderDetail(orderNo); dto.setOrder_status(1); DYOrderDto dto = DYOrderApi.getOrderDetail(orderNo); // dto.setOrder_status(1); if(dto.getOrder_status() !=DYOrderDto.ORDER_STATUS_NOT_PAY){ // 订单不处于尚未付款状态 KeyOrder orderUpdate=new KeyOrder(); orderUpdate.setId(id); orderUpdate.setOrderState(dto.getOrder_status()); orderUpdate.setOrderType(1); orderUpdate.setOrderNo(orderNo); if(order.getState() == KeyOrder.STATE_NOT_PROCESS){ orderUpdate.setState(KeyOrder.STATE_NOT_PAY); orderUpdate.setStateDesc("订单不处于待付款状态"); if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) { orderUpdate.setState(KeyOrder.STATE_PAY); orderUpdate.setStateDesc(dto.getOrder_status_desc()); } else { orderUpdate.setState(KeyOrder.STATE_PAY); orderUpdate.setStateDesc(dto.getOrder_status_desc()); } } keyOrderService.update(orderUpdate); if(dto.getOrder_status() ==DYOrderDto.ORDER_STATUS_CANCELED){ @@ -198,6 +215,16 @@ keyOrderService.update(orderUpdate); order = keyOrderService.selectById(id); return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order))); } catch (KeyOrderException e) { KeyOrder orderUpdate = new KeyOrder(); orderUpdate.setId(id); orderUpdate.setOrderType(1); orderUpdate.setOrderState(0); orderUpdate.setOrderNo(orderNo); orderUpdate.setState(KeyOrder.STATE_REJECT_PAY); orderUpdate.setStateDesc(e.getMessage()); keyOrderService.update(orderUpdate); return JsonUtil.loadFalseResult(e.getMessage()); } catch (Exception e) { e.printStackTrace(); return JsonUtil.loadFalseResult(e.getMessage()); @@ -219,6 +246,7 @@ return JsonUtil.loadFalseResult("没有匹配到订单号"); } if(order.getState()==KeyOrder.STATE_NOT_PROCESS) { if(!paySuccess){ // 支付失败 KeyOrder orderUpdate=new KeyOrder(); @@ -233,14 +261,53 @@ orderUpdate.setStateDesc("支付成功"); keyOrderService.update(orderUpdate); } } return JsonUtil.loadTrueResult(""); } @ResponseBody @RequestMapping("rejectPay") public String rejectPay(AcceptData acceptData, Long uid, String id) { loggerPay.info("rejectPay: {}-{}", uid, id); if (StringUtil.isNullOrEmpty(id)) { return JsonUtil.loadFalseResult("请上传id"); } KeyOrder order = keyOrderService.selectById(id); if (order == null) { return JsonUtil.loadFalseResult("口令不存在"); } if (order.getState() != KeyOrder.STATE_NOT_PROCESS) { return JsonUtil.loadFalseResult("只能驳回未执行状态的口令"); } KeyOrder orderUpdate = new KeyOrder(); orderUpdate.setId(id); orderUpdate.setState(KeyOrder.STATE_REJECT_PAY); orderUpdate.setStateDesc("人工驳回"); keyOrderService.update(orderUpdate); return JsonUtil.loadTrueResult(""); } @ResponseBody @RequestMapping("deleteAll") public String deleteAll(AcceptData acceptData){ public String deleteAll(AcceptData acceptData,Long uid) { ClientInfo user= clientInfoService.selectByPrimaryKey(uid); if(user==null){ return JsonUtil.loadFalseResult("用户不存在"); } if(user.getRule() != ClientInfo.RULE_ADMIN){ return JsonUtil.loadFalseResult("只有管理员才能删除"); } // 删除24小时之前的数据 // keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24*60*60*1000L)); keyOrderService.deleteAll(new Date(System.currentTimeMillis())); // 刪除所有數據 return JsonUtil.loadTrueResult(""); } src/main/java/com/taoke/autopay/controller/client/UserController.java
@@ -5,6 +5,7 @@ import com.taoke.autopay.service.ClientInfoService; import com.taoke.autopay.utils.JsonUtil; import com.taoke.autopay.vo.AcceptData; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -37,4 +38,17 @@ } } @ResponseBody @RequestMapping("logout") public String logout(AcceptData acceptData,Long uid){ try { clientInfoService.logout(uid); return JsonUtil.loadTrueResult(new JSONObject()); } catch (Exception e) { e.printStackTrace(); return JsonUtil.loadFalseResult(1,e.getMessage()); } } } src/main/java/com/taoke/autopay/dao/ClientInfoMapper.java
@@ -18,6 +18,8 @@ long count(@Param("query") DaoQuery query); int clearActiveTime(@Param("id") Long uid); public static class DaoQuery{ public Long id; public String name; src/main/java/com/taoke/autopay/dao/KeyOrderMapper.java
@@ -21,10 +21,12 @@ long count(@Param("query") DaoQuery query); List<OrderDistributeCountInfo> listDistributeUids(); List<OrderDistributeCountInfo> listDistributeUids(@Param("minActiveTime") Date minActiveTime); List<KeyOrder> listNotDistributed(@Param("start") int start,@Param("count") int count); int deleteAll(@Param("maxCreateTime") Date maxCreateTime); public static class DaoQuery{ public String id; public String key; src/main/java/com/taoke/autopay/dto/DYOrderDto.java
@@ -12,7 +12,7 @@ // 订单未支付 public final static int ORDER_STATUS_NOT_PAY = 1; // 订单取消 public final static int ORDER_STATUS_CANCELED= 2; public final static int ORDER_STATUS_CANCELED= 4; /** src/main/java/com/taoke/autopay/entity/KeyOrder.java
@@ -20,6 +20,8 @@ public final static int STATE_NOT_PAY = 1; // 已支付 public final static int STATE_PAY = 2; // 已支付 public final static int STATE_REJECT_PAY = 3; @Id src/main/java/com/taoke/autopay/factory/OrderFactory.java
@@ -26,13 +26,16 @@ vo.setKey(order.getKey()); switch (order.getState()){ case KeyOrder.STATE_NOT_PROCESS: vo.setState(OrderFilter.STATE_NOT_PROCESS); vo.setState(KeyOrderVO.STATE_NOT_PROCESS); break; case KeyOrder.STATE_NOT_PAY: vo.setState(OrderFilter.STATE_PROCESS_ERROR); vo.setState(KeyOrderVO.STATE_PROCESS_ERROR); break; case KeyOrder.STATE_PAY: vo.setState(OrderFilter.STATE_PROCESSED); vo.setState(KeyOrderVO.STATE_PROCESSED); break; case KeyOrder.STATE_REJECT_PAY: vo.setState(KeyOrderVO.STATE_PROCESSED); break; } return vo; src/main/java/com/taoke/autopay/service/ClientInfoService.java
@@ -24,6 +24,17 @@ **/ public ClientInfo login(String account, String pwd) throws LoginException; /** * @author hxh * @description 退出登录 * @date 16:49 2024/6/18 * @param: uid * @return com.taoke.autopay.entity.ClientInfo **/ public void logout(Long uid); /** * @author hxh * @description /根据主键查询 src/main/java/com/taoke/autopay/service/KeyOrderService.java
@@ -4,6 +4,7 @@ import com.taoke.autopay.entity.KeyOrder; import com.taoke.autopay.exception.KeyOrderException; import java.util.Date; import java.util.List; /** @@ -57,8 +58,31 @@ public long count(KeyOrderMapper.DaoQuery query); /** * @author hxh * @description 获取可用于分配的设备ID信息 * @date 16:41 2024/6/17 * @return java.lang.Long **/ public Long getCanDistributeUid(); /** * @author hxh * @description 查询还没分配设备ID的数据 * @date 16:40 2024/6/17 * @param: page * @param: pageSize * @return java.util.List<com.taoke.autopay.entity.KeyOrder> **/ public List<KeyOrder> listNotDistributed(int page,int pageSize); /** * @author hxh * @description 删除所有数据 * @date 16:40 2024/6/17 * @param: maxCreateTime * @return void **/ public void deleteAll(Date maxCreateTime); } src/main/java/com/taoke/autopay/service/impl/ClientInfoServiceImpl.java
@@ -39,6 +39,11 @@ } @Override public void logout(Long uid) { clientInfoMapper.clearActiveTime(uid); } @Override public ClientInfo selectByPrimaryKey(Long id) { return clientInfoMapper.selectByPrimaryKey(id); } src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java
@@ -10,9 +10,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.*; /** * @author hxh @@ -96,12 +94,43 @@ @Override public Long getCanDistributeUid() { List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(); // 最近1小时有活跃 List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L)); if(list==null||list.size()==0){ return null; } Comparator<OrderDistributeCountInfo> cm = (OrderDistributeCountInfo o1, OrderDistributeCountInfo o2)-> o1.getCount()-o2.getCount(); // count小于2直接视为0 for (OrderDistributeCountInfo info : list) { if (info.getCount() < 2) { info.setCount(0); } } 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(); } @@ -109,4 +138,9 @@ public List<KeyOrder> listNotDistributed(int page, int pageSize) { return keyOrderMapper.listNotDistributed((page-1)*pageSize,pageSize); } @Override public void deleteAll(Date maxCreateTime) { keyOrderMapper.deleteAll(maxCreateTime); } } src/main/java/com/taoke/autopay/task/KeyOrderDistributeTask.java
@@ -1,12 +1,18 @@ package com.taoke.autopay.task; import com.taoke.autopay.dao.KeyOrderMapper; import com.taoke.autopay.dto.DYOrderDto; import com.taoke.autopay.entity.KeyOrder; import com.taoke.autopay.exception.KeyOrderException; import com.taoke.autopay.service.KeyOrderService; import com.taoke.autopay.utils.StringUtil; import com.taoke.autopay.utils.order.DYOrderApi; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import javax.annotation.Resource; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -40,4 +46,61 @@ } } /** * @return void * @author hxh * @description 修正已经处理的订单 * @date 17:53 2024/6/20 **/ @Scheduled(cron = "0/5 * * * * ? ") private void repaireProcessedOrders() { // TODO 待完成 KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery(); // 修正1分钟到1小时的数据之前执行的数据 query.maxUpdateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 1L); query.minUpdateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 60L); query.sortList = Arrays.asList(new String[]{"update_time asc"}); query.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_NOT_PAY, KeyOrder.STATE_PAY}); query.orderState = DYOrderDto.ORDER_STATUS_NOT_PAY; query.start = 0; query.count = 20; List<KeyOrder> list = keyOrderService.list(query); if (list != null && list.size() > 0) { for (KeyOrder order : list) { // 如果没有拿到订单就不做处理 if (StringUtil.isNullOrEmpty(order.getOrderNo())) { continue; } // 查询结果 DYOrderDto dto = null; try { dto = DYOrderApi.getOrderDetail(order.getOrderNo()); if (dto.getOrder_status() != DYOrderDto.ORDER_STATUS_NOT_PAY) { // 订单不处于尚未付款状态 KeyOrder orderUpdate = new KeyOrder(); orderUpdate.setId(order.getId()); orderUpdate.setOrderState(dto.getOrder_status()); orderUpdate.setState(KeyOrder.STATE_PAY); orderUpdate.setStateDesc(dto.getOrder_status_desc()); keyOrderService.update(orderUpdate); } else { KeyOrder update = new KeyOrder(); update.setId(order.getId()); update.setState(KeyOrder.STATE_NOT_PROCESS); update.setStateDesc("重置未分配"); update.setOrderState(dto.getOrder_status()); keyOrderService.update(update); } } catch (KeyOrderException e) { e.printStackTrace(); KeyOrder orderUpdate = new KeyOrder(); orderUpdate.setId(order.getId()); orderUpdate.setState(KeyOrder.STATE_PAY); orderUpdate.setStateDesc(e.getMessage()); keyOrderService.update(orderUpdate); } } } } } src/main/java/com/taoke/autopay/utils/order/DYOrderApi.java
@@ -1,6 +1,7 @@ package com.taoke.autopay.utils.order; import com.taoke.autopay.dto.DYOrderDto; import com.taoke.autopay.exception.KeyOrderException; import com.taoke.autopay.utils.HttpUtil; import com.taoke.autopay.utils.JsonUtil; import net.sf.json.JSONObject; @@ -22,19 +23,20 @@ return result; } public static DYOrderDto getOrderDetail(String orderNo) throws Exception { public static DYOrderDto getOrderDetail(String orderNo) throws KeyOrderException { String result = requestByOrderNo1(orderNo); JSONObject root = JSONObject.fromObject(result); if (root.optInt("code") != 1000) { logger.error(String.format("抖音订单查询出错:%s - %s",orderNo, result)); throw new Exception(root.optString("message")); throw new KeyOrderException(root.optString("message")); } JSONObject data = root.optJSONObject("data"); return JsonUtil.getSimpleGson().fromJson(data.toString(),DYOrderDto.class); } public static void main(String[] args) throws Exception { DYOrderDto dto = (DYOrderApi.getOrderDetail("6930867557709059751")); DYOrderDto dto = (DYOrderApi.getOrderDetail("6931134387948820382")); System.out.println("123123"); } } src/main/java/com/taoke/autopay/vo/KeyOrderVO.java
@@ -3,6 +3,10 @@ import java.util.Date; public class KeyOrderVO { public final static int STATE_NOT_PROCESS = 0; public final static int STATE_PROCESSED = 1; public final static int STATE_PROCESS_ERROR = 2; private String id; private String key; private int state; src/main/java/com/taoke/autopay/vo/OrderFilter.java
@@ -17,9 +17,9 @@ public static final int TIME_TYPE_MONTH=3; public static final int STATE_NOT_PROCESS=0; public static final int STATE_PROCESSED=1; public static final int STATE_PROCESS_ERROR=2; public static final int STATE_NOT_PROCESS=1; public static final int STATE_PROCESSED=2; public static final int STATE_PROCESS_ERROR=3; src/main/resources/application-dev.yml
@@ -1,5 +1,5 @@ server: port: 8080 port: 9010 tomcat: uri-encoding: UTF-8 spring: src/main/resources/application-pro.yml
@@ -1,5 +1,5 @@ server: port: 9010 port: 9011 tomcat: uri-encoding: UTF-8 spring: @@ -11,9 +11,15 @@ charset: UTF-8 enabled: true datasource: url: jdbc:mysql://172.16.16.17:3306/taoke_autopay?serverTimezone=GMT%2B8 username: root password: Yeshi2016@ # 测试 # url: jdbc:mysql://172.16.16.17:3306/taoke_autopay?serverTimezone=GMT%2B8 # username: root # password: Yeshi2016@ # XCP url: jdbc:mysql://127.0.0.1:3306/taoke_autopay?serverTimezone=GMT%2B8 username: taoke_autopay password: xcp123123 driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource druid: src/main/resources/logback.xml
@@ -13,7 +13,7 @@ <property name="log.maxHistory" value="30"/> <!--日志存储的根路径 ${catalina.base}指向每个Tomcat目录私有信息的位置, 就是conf、logs、temp、webapps和work的父目录--> <property name="log.filePath" value="/tmp/logs"/> <property name="log.filePath" value="/var/logs/taoke"/> <!--日志展示的格式--> <property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n"/> src/main/resources/mapper/ClientInfoMapper.xml
@@ -72,4 +72,14 @@ <if test="rule != null">rule=#{rule,jdbcType=INTEGER},</if> </set> where id = #{id,jdbcType=BIGINT} </update> <update id="clearActiveTime" parameterType="java.lang.Long">update table_user <set> active_time = NULL </set> where id = #{id,jdbcType=BIGINT} </update> </mapper> src/main/resources/mapper/KeyOrderMapper.xml
@@ -111,8 +111,12 @@ </set> where id = #{id,jdbcType=VARCHAR} </update> <select id="listDistributeUids" resultMap="DistributeResultMap"> SELECT u.`id` as uid, IF( a.count IS NULL,0,a.count) AS `count` FROM `table_user` u LEFT JOIN (SELECT o.`distribute_client_uid` AS uid,COUNT(*) AS `count` FROM `table_order` o WHERE o.`state` = 0 GROUP BY o.`distribute_client_uid`) a ON a.uid = u.`id` WHERE rule=0 <select id="listDistributeUids" resultMap="DistributeResultMap" parameterType="java.util.Date"> SELECT u.`id` as uid, IF( a.count IS NULL,0,a.count) AS `count` FROM `table_user` u LEFT JOIN (SELECT o.`distribute_client_uid` AS uid,COUNT(*) AS `count` FROM `table_order` o WHERE o.`state` = 0 GROUP BY o.`distribute_client_uid`) a ON a.uid = u.`id` WHERE rule=0 <if test="minActiveTime!=null"> and active_time >=#{minActiveTime} </if> </select> @@ -121,4 +125,9 @@ </select> <delete id="deleteAll" parameterType="java.util.Date"> delete from table_order where #{maxCreateTime} >= create_time </delete> </mapper> src/test/java/com/taoke/autopay/AutopayApplicationTests.java
@@ -5,6 +5,7 @@ import com.taoke.autopay.entity.ClientInfo; import com.taoke.autopay.entity.OrderDistributeCountInfo; import com.taoke.autopay.exception.KeyOrderException; import com.taoke.autopay.service.ClientInfoService; import com.taoke.autopay.service.KeyOrderService; import com.taoke.autopay.utils.StringUtil; import org.junit.jupiter.api.Test; @@ -14,11 +15,14 @@ import java.util.Date; import java.util.List; //@SpringBootTest @SpringBootTest class AutopayApplicationTests { @Resource private ClientInfoMapper mapper; @Resource private ClientInfoService clientInfoService; @Resource private KeyOrderService keyOrderService; @@ -27,16 +31,32 @@ private KeyOrderMapper keyOrderMapper; @Test void addClientInfo(){ for(int i=4;i<50;i++) { ClientInfo info=new ClientInfo(); info.setRule(0); info.setAccount("c"+i); info.setPwd("e10adc3949ba59abbe56e057f20f883e"); info.setCreateTime(new Date()); info.setName("客户端"+i); mapper.insertSelective(info); } } @Test void test2() throws KeyOrderException { keyOrderService.addKeyOrder("【\uD83D\uDC4D z h`i付宝\uD83D\uDC4D】亲,复制 T:/TQEx7jy96Gr o:/b CA5742 2020/12/07打开支付宝就可以帮我\uD83C\uDFEE付款啦\uD83D\uDCAAhttps://ur.alipay.com/_72G9ZwXA6jz28jdJUNhUx7"); } @Test void test3() throws Exception { void test4(){ clientInfoService.logout(3L); } Long uid = keyOrderService.getCanDistributeUid(); System.out.println(uid); @Test void test3() throws Exception { keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 1000*60*60*24L *5)); } @Test src/test/java/com/taoke/autopay/MapperTest.java
@@ -4,6 +4,9 @@ import org.junit.jupiter.api.Test; import org.yeshi.utils.generater.mybatis.MyBatisMapperUtil; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author hxh * @title: MapperTest @@ -15,7 +18,19 @@ @Test public void test() { // MyBatisMapperUtil.createMapper(ClientInfo.class); MyBatisMapperUtil.createMapper(KeyOrder.class); // MyBatisMapperUtil.createMapper(KeyOrder.class); String orderNoStr = "抖音电商商家 即时到账--抖音电商-订单编号6931067415405008690"; Pattern pattern = Pattern.compile("\\d+"); // 匹配连续的数字 Matcher matcher = pattern.matcher(orderNoStr); while (matcher.find()) { String number = matcher.group(); // 获取匹配到的数字字符串 if(number.length()>10){ orderNoStr = number; break; } } System.out.println(orderNoStr); }