mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-01 23:26:38 +00:00
feat(novel-front): 增加评论用户地理位置显示功能
This commit is contained in:
@ -1,11 +1,21 @@
|
||||
package com.java2nb.novel.core.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
|
||||
@Slf4j
|
||||
public class IpUtil {
|
||||
|
||||
/**
|
||||
* 获取真实IP
|
||||
*
|
||||
* @param request 请求体
|
||||
* @return 真实IP
|
||||
*/
|
||||
@ -31,4 +41,27 @@ public class IpUtil {
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本机公网IP
|
||||
*/
|
||||
public static String getPublicIP() {
|
||||
try {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://httpbin.org/ip"))
|
||||
.GET()
|
||||
.timeout(Duration.ofSeconds(5))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
return new ObjectMapper().readTree(response.body()).get("origin").asText();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取本机公网IP异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ public class BookComment {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
private String commentContent;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
private String location;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
private Integer replyCount;
|
||||
|
||||
@ -56,6 +59,16 @@ public class BookComment {
|
||||
this.commentContent = commentContent == null ? null : commentContent.trim();
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public void setLocation(String location) {
|
||||
this.location = location == null ? null : location.trim();
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public Integer getReplyCount() {
|
||||
return replyCount;
|
||||
|
@ -19,6 +19,9 @@ public final class BookCommentDynamicSqlSupport {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<String> commentContent = bookComment.commentContent;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<String> location = bookComment.location;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<Integer> replyCount = bookComment.replyCount;
|
||||
|
||||
@ -39,6 +42,8 @@ public final class BookCommentDynamicSqlSupport {
|
||||
|
||||
public final SqlColumn<String> commentContent = column("comment_content", JDBCType.VARCHAR);
|
||||
|
||||
public final SqlColumn<String> location = column("location", JDBCType.VARCHAR);
|
||||
|
||||
public final SqlColumn<Integer> replyCount = column("reply_count", JDBCType.INTEGER);
|
||||
|
||||
public final SqlColumn<Byte> auditStatus = column("audit_status", JDBCType.TINYINT);
|
||||
|
@ -29,7 +29,7 @@ import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||
@Mapper
|
||||
public interface BookCommentMapper {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
BasicColumn[] selectList = BasicColumn.columnList(id, bookId, commentContent, replyCount, auditStatus, createTime, createUserId);
|
||||
BasicColumn[] selectList = BasicColumn.columnList(id, bookId, commentContent, location, replyCount, auditStatus, createTime, createUserId);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||
@ -58,6 +58,7 @@ public interface BookCommentMapper {
|
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
|
||||
@Result(column="book_id", property="bookId", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="comment_content", property="commentContent", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="location", property="location", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="reply_count", property="replyCount", jdbcType=JdbcType.INTEGER),
|
||||
@Result(column="audit_status", property="auditStatus", jdbcType=JdbcType.TINYINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@ -92,6 +93,7 @@ public interface BookCommentMapper {
|
||||
c.map(id).toProperty("id")
|
||||
.map(bookId).toProperty("bookId")
|
||||
.map(commentContent).toProperty("commentContent")
|
||||
.map(location).toProperty("location")
|
||||
.map(replyCount).toProperty("replyCount")
|
||||
.map(auditStatus).toProperty("auditStatus")
|
||||
.map(createTime).toProperty("createTime")
|
||||
@ -105,6 +107,7 @@ public interface BookCommentMapper {
|
||||
c.map(id).toProperty("id")
|
||||
.map(bookId).toProperty("bookId")
|
||||
.map(commentContent).toProperty("commentContent")
|
||||
.map(location).toProperty("location")
|
||||
.map(replyCount).toProperty("replyCount")
|
||||
.map(auditStatus).toProperty("auditStatus")
|
||||
.map(createTime).toProperty("createTime")
|
||||
@ -118,6 +121,7 @@ public interface BookCommentMapper {
|
||||
c.map(id).toPropertyWhenPresent("id", record::getId)
|
||||
.map(bookId).toPropertyWhenPresent("bookId", record::getBookId)
|
||||
.map(commentContent).toPropertyWhenPresent("commentContent", record::getCommentContent)
|
||||
.map(location).toPropertyWhenPresent("location", record::getLocation)
|
||||
.map(replyCount).toPropertyWhenPresent("replyCount", record::getReplyCount)
|
||||
.map(auditStatus).toPropertyWhenPresent("auditStatus", record::getAuditStatus)
|
||||
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
|
||||
@ -157,6 +161,7 @@ public interface BookCommentMapper {
|
||||
return dsl.set(id).equalTo(record::getId)
|
||||
.set(bookId).equalTo(record::getBookId)
|
||||
.set(commentContent).equalTo(record::getCommentContent)
|
||||
.set(location).equalTo(record::getLocation)
|
||||
.set(replyCount).equalTo(record::getReplyCount)
|
||||
.set(auditStatus).equalTo(record::getAuditStatus)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
@ -168,6 +173,7 @@ public interface BookCommentMapper {
|
||||
return dsl.set(id).equalToWhenPresent(record::getId)
|
||||
.set(bookId).equalToWhenPresent(record::getBookId)
|
||||
.set(commentContent).equalToWhenPresent(record::getCommentContent)
|
||||
.set(location).equalToWhenPresent(record::getLocation)
|
||||
.set(replyCount).equalToWhenPresent(record::getReplyCount)
|
||||
.set(auditStatus).equalToWhenPresent(record::getAuditStatus)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
@ -179,6 +185,7 @@ public interface BookCommentMapper {
|
||||
return update(c ->
|
||||
c.set(bookId).equalTo(record::getBookId)
|
||||
.set(commentContent).equalTo(record::getCommentContent)
|
||||
.set(location).equalTo(record::getLocation)
|
||||
.set(replyCount).equalTo(record::getReplyCount)
|
||||
.set(auditStatus).equalTo(record::getAuditStatus)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
@ -192,6 +199,7 @@ public interface BookCommentMapper {
|
||||
return update(c ->
|
||||
c.set(bookId).equalToWhenPresent(record::getBookId)
|
||||
.set(commentContent).equalToWhenPresent(record::getCommentContent)
|
||||
.set(location).equalToWhenPresent(record::getLocation)
|
||||
.set(replyCount).equalToWhenPresent(record::getReplyCount)
|
||||
.set(auditStatus).equalToWhenPresent(record::getAuditStatus)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
|
Reference in New Issue
Block a user