新增反馈归属地
Some checks failed
CI Build and Test / build (push) Has been cancelled
Deploy to Server / build-and-deploy (push) Has been cancelled

This commit is contained in:
2025-10-21 09:44:05 +08:00
parent 526971de9d
commit 1e356a03bb

View File

@@ -8,8 +8,11 @@ import com.corewing.app.dto.FeedbackRequest;
import com.corewing.app.entity.AppFeedback; import com.corewing.app.entity.AppFeedback;
import com.corewing.app.service.AppFeedbackService; import com.corewing.app.service.AppFeedbackService;
import com.corewing.app.util.DingTalkUtil; import com.corewing.app.util.DingTalkUtil;
import com.corewing.app.util.Ip2RegionUtil;
import com.corewing.app.util.IpUtil;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@@ -23,17 +26,19 @@ public class AppFeedbackController {
private final AppFeedbackService feedbackService; private final AppFeedbackService feedbackService;
private final DingTalkUtil dingTalkUtil; private final DingTalkUtil dingTalkUtil;
private final Ip2RegionUtil ip2RegionUtil;
public AppFeedbackController(AppFeedbackService feedbackService, DingTalkUtil dingTalkUtil) { public AppFeedbackController(AppFeedbackService feedbackService, DingTalkUtil dingTalkUtil, Ip2RegionUtil ip2RegionUtil) {
this.feedbackService = feedbackService; this.feedbackService = feedbackService;
this.dingTalkUtil = dingTalkUtil; this.dingTalkUtil = dingTalkUtil;
this.ip2RegionUtil = ip2RegionUtil;
} }
/** /**
* 创建反馈(支持匿名提交) * 创建反馈(支持匿名提交)
*/ */
@PostMapping @PostMapping
public Result<String> create(@RequestBody FeedbackRequest request) { public Result<String> create(@RequestBody FeedbackRequest request, HttpServletRequest httpRequest) {
try { try {
// 尝试获取当前登录用户ID如果未登录则为null // 尝试获取当前登录用户ID如果未登录则为null
Long userId = null; Long userId = null;
@@ -52,8 +57,12 @@ public class AppFeedbackController {
boolean success = feedbackService.createFeedback(feedback); boolean success = feedbackService.createFeedback(feedback);
if (success) { if (success) {
// 获取提交IP和归属地
String submitIp = IpUtil.getClientIp(httpRequest);
String submitRegion = ip2RegionUtil.getRegion(submitIp);
// 推送到钉钉 // 推送到钉钉
sendFeedbackToDingTalk(feedback); sendFeedbackToDingTalk(feedback, submitIp, submitRegion);
return Result.success("反馈提交成功"); return Result.success("反馈提交成功");
} }
return Result.error("反馈提交失败"); return Result.error("反馈提交失败");
@@ -174,7 +183,7 @@ public class AppFeedbackController {
/** /**
* 发送反馈信息到钉钉 * 发送反馈信息到钉钉
*/ */
private void sendFeedbackToDingTalk(AppFeedback feedback) { private void sendFeedbackToDingTalk(AppFeedback feedback, String submitIp, String submitRegion) {
try { try {
String title = "📢 新的用户反馈"; String title = "📢 新的用户反馈";
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
@@ -204,6 +213,10 @@ public class AppFeedbackController {
text.append("**联系方式:** ").append(feedback.getContact()).append("\n\n"); text.append("**联系方式:** ").append(feedback.getContact()).append("\n\n");
} }
// IP 和归属地
text.append("**提交IP** ").append(submitIp).append("\n\n");
text.append("**IP归属地** ").append(submitRegion).append("\n\n");
// 提交时间 // 提交时间
text.append("**提交时间:** ").append( text.append("**提交时间:** ").append(
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))