12 changed files with 585 additions and 7 deletions
-
56lottery-system/lottery-common/src/main/java/com/lottery/utils/HttpUtils.java
-
68lottery-system/lottery-common/src/main/java/com/lottery/utils/ValidationUtils.java
-
21lottery-system/lottery-pojo/src/main/java/com/lottery/dto/FundingRecordDto.java
-
24lottery-system/lottery-pojo/src/main/java/com/lottery/dto/FundingUserDto.java
-
4lottery-system/lottery-pojo/src/main/java/com/lottery/entity/FundingData.java
-
4lottery-system/lottery-pojo/src/main/java/com/lottery/entity/FundingUser.java
-
25lottery-system/lottery-pojo/src/main/java/com/lottery/vo/FundingUserVo.java
-
48lottery-system/lottery-service/src/main/java/com/lottery/admin/controller/FundingController.java
-
31lottery-system/lottery-service/src/main/java/com/lottery/admin/mapper/IFundingMapper.java
-
16lottery-system/lottery-service/src/main/java/com/lottery/admin/service/IFundingService.java
-
175lottery-system/lottery-service/src/main/java/com/lottery/admin/service/Impl/FundingServiceImpl.java
-
116lottery-system/lottery-service/src/main/resources/mapper/admin/fundingMapper.xml
@ -0,0 +1,56 @@ |
|||||
|
package com.lottery.utils; |
||||
|
import java.net.URI; |
||||
|
import java.net.URLEncoder; |
||||
|
import java.net.http.HttpClient; |
||||
|
import java.net.http.HttpRequest; |
||||
|
import java.net.http.HttpResponse; |
||||
|
import java.nio.charset.StandardCharsets; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public class HttpUtils{ |
||||
|
|
||||
|
private static final HttpClient client = HttpClient.newHttpClient(); |
||||
|
|
||||
|
/** |
||||
|
* 发送 POST 请求(urlencoded 格式,仅设置 Content-Type) |
||||
|
* @param url 接口地址 |
||||
|
* @param params 请求参数(键值对,自动编码) |
||||
|
* @return 响应字符串 |
||||
|
*/ |
||||
|
public static String postUrlencoded(String url, Map<String, String> params) throws Exception { |
||||
|
// 1. 构建 urlencoded 请求体 |
||||
|
StringBuilder requestBody = new StringBuilder(); |
||||
|
for (Map.Entry<String, String> entry : params.entrySet()) { |
||||
|
if (requestBody.length() > 0) { |
||||
|
requestBody.append("&"); |
||||
|
} |
||||
|
requestBody.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)) |
||||
|
.append("=") |
||||
|
.append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)); |
||||
|
} |
||||
|
|
||||
|
// 2. 创建 HTTP 请求(仅设置 Content-Type) |
||||
|
HttpRequest request = HttpRequest.newBuilder() |
||||
|
.uri(URI.create(url)) |
||||
|
.header("Content-Type", "application/x-www-form-urlencoded") // 仅设置 Content-Type |
||||
|
.POST(HttpRequest.BodyPublishers.ofString(requestBody.toString())) |
||||
|
.build(); |
||||
|
|
||||
|
// 3. 发送请求并返回响应 |
||||
|
return sendRequest(request); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 发送请求并返回响应 |
||||
|
*/ |
||||
|
private static String sendRequest(HttpRequest request) throws Exception { |
||||
|
HttpResponse<String> response = client.send( |
||||
|
request, HttpResponse.BodyHandlers.ofString()); |
||||
|
|
||||
|
if (response.statusCode() >= 400) { |
||||
|
throw new RuntimeException("HTTP 错误,状态码: " + response.statusCode() + ", 响应: " + response.body()); |
||||
|
} |
||||
|
|
||||
|
return response.body(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
package com.lottery.utils; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName ValidationUtils |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-15 16:26 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
|
||||
|
public class ValidationUtils { |
||||
|
|
||||
|
/** |
||||
|
* 校验数值是否满足: |
||||
|
* 1. 可以小于 0(允许负数) |
||||
|
* 2. 必须是整数(不能是小数) |
||||
|
* |
||||
|
* @param value 待校验的数值(可以是 String 或 Number 类型) |
||||
|
* @return 是否校验通过 |
||||
|
*/ |
||||
|
public static boolean validateInteger(Object value) { |
||||
|
try { |
||||
|
// 如果是 String 类型,先尝试转为 Number |
||||
|
if (value instanceof String) { |
||||
|
// 去掉可能的空格 |
||||
|
String strValue = ((String) value).trim(); |
||||
|
|
||||
|
// 检查是否为空 |
||||
|
if (strValue.isEmpty()) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 尝试解析为 Long(支持更大的整数范围) |
||||
|
try { |
||||
|
Long.parseLong(strValue); |
||||
|
} catch (NumberFormatException e) { |
||||
|
return false; // 解析失败,说明不是整数 |
||||
|
} |
||||
|
} |
||||
|
// 如果是 Number 类型(Integer、Long 等) |
||||
|
else if (value instanceof Number) { |
||||
|
Number num = (Number) value; |
||||
|
|
||||
|
// 检查是否是整数(避免浮点数) |
||||
|
if (num instanceof Double || num instanceof Float) { |
||||
|
double doubleValue = num.doubleValue(); |
||||
|
if (doubleValue != Math.floor(doubleValue)) { |
||||
|
return false; // 有小数部分,不合法 |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 如果是 Integer 或 Long,直接合法 |
||||
|
return true; |
||||
|
} |
||||
|
// 其他类型(如非数值类型) |
||||
|
else { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 所有检查通过 |
||||
|
return true; |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
return false; // 任何异常都视为不合法 |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
package com.lottery.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName FundingRecordDto |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-15 14:27 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class FundingRecordDto { |
||||
|
|
||||
|
private String token; |
||||
|
|
||||
|
private Integer activityId; |
||||
|
|
||||
|
private String marketSign; |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package com.lottery.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName FundingUserDto |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-15 10:47 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class FundingUserDto { |
||||
|
public Integer activityId; |
||||
|
|
||||
|
private String marketSign; // 市场标识(usa/hk) |
||||
|
private String username; // 用户名 |
||||
|
private String jwcode; // 用户唯一码 |
||||
|
private Integer page=1; |
||||
|
private Integer pagesize=10; |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
package com.lottery.vo; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* @program: lottery-system |
||||
|
* @ClassName FundingUserDto |
||||
|
* @description: |
||||
|
* @author:jihaipeng |
||||
|
* @create: 2025−07-15 10:09 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
public class FundingUserVo { |
||||
|
@TableId(type = IdType.AUTO) // 主键自增策略 |
||||
|
private Integer id; |
||||
|
private String marketSign; // 市场标识(usa/hk) |
||||
|
private String username; // 用户名 |
||||
|
private String jwcode; // 用户唯一码 |
||||
|
private LocalDateTime joinTime; // 参与时间 |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue