diff --git a/src/main/java/com/corewing/app/controller/AppFeedbackController.java b/src/main/java/com/corewing/app/controller/AppFeedbackController.java index 61e90b7..25d1a83 100644 --- a/src/main/java/com/corewing/app/controller/AppFeedbackController.java +++ b/src/main/java/com/corewing/app/controller/AppFeedbackController.java @@ -8,8 +8,11 @@ import com.corewing.app.dto.FeedbackRequest; import com.corewing.app.entity.AppFeedback; import com.corewing.app.service.AppFeedbackService; 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 javax.servlet.http.HttpServletRequest; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; @@ -23,17 +26,19 @@ public class AppFeedbackController { private final AppFeedbackService feedbackService; 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.dingTalkUtil = dingTalkUtil; + this.ip2RegionUtil = ip2RegionUtil; } /** * 创建反馈(支持匿名提交) */ @PostMapping - public Result create(@RequestBody FeedbackRequest request) { + public Result create(@RequestBody FeedbackRequest request, HttpServletRequest httpRequest) { try { // 尝试获取当前登录用户ID(如果未登录则为null) Long userId = null; @@ -52,8 +57,12 @@ public class AppFeedbackController { boolean success = feedbackService.createFeedback(feedback); if (success) { + // 获取提交IP和归属地 + String submitIp = IpUtil.getClientIp(httpRequest); + String submitRegion = ip2RegionUtil.getRegion(submitIp); + // 推送到钉钉 - sendFeedbackToDingTalk(feedback); + sendFeedbackToDingTalk(feedback, submitIp, submitRegion); return Result.success("反馈提交成功"); } 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 { String title = "📢 新的用户反馈"; StringBuilder text = new StringBuilder(); @@ -204,6 +213,10 @@ public class AppFeedbackController { 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( LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))