Przeglądaj źródła

feat: ip2region

shc 1 rok temu
rodzic
commit
495c1c1c8f

+ 7 - 0
hnqz-common/hnqz-common-core/pom.xml

@@ -16,6 +16,13 @@
 
 
 	<dependencies>
+		<dependency>
+			<groupId>com.bribric</groupId>
+			<artifactId>beetroot</artifactId>
+			<version>0.0.6</version>
+			<scope>system</scope>
+			<systemPath>${pom.basedir}/src/main/resources/lib/beetroot-0.0.6.jar</systemPath>
+		</dependency>
 		<!--hutool-->
 		<dependency>
 			<groupId>cn.hutool</groupId>

+ 57 - 0
hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/util/HttpUtils.java

@@ -0,0 +1,57 @@
+package com.qunzhixinxi.hnqz.common.core.util;
+
+import cn.hutool.core.util.CharUtil;
+import cn.hutool.core.util.StrUtil;
+import lombok.experimental.UtilityClass;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * http 工具类 获取请求中的参数
+ *
+ * @author show
+ * @date 14:23 2019/5/29
+ */
+@UtilityClass
+public class HttpUtils {
+
+
+    /**
+     * 获取请求IP地址
+     *
+     * @param request
+     * @return
+     */
+    public static String getIpAddr(HttpServletRequest request) {
+        if (request == null) {
+            return "unknown";
+        }
+        String ip = request.getHeader("x-forwarded-for");
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("Proxy-Client-IP");
+        }
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("X-Forwarded-For");
+        }
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("WL-Proxy-Client-IP");
+        }
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("X-Real-IP");
+        }
+
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getRemoteAddr();
+        }
+        //"***.***.***.***".length() = 15
+        if (StrUtil.isNotBlank(ip) && ip.length() > 15) {
+            if (ip.indexOf(CharUtil.COMMA) > 0) {
+                ip = ip.substring(0, ip.indexOf(","));
+            }
+        }
+        // 处理获取多个ip地址情况 nginx多层代理会出现多个ip 第一个为真实ip地址
+        return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
+    }
+
+
+}

BIN
hnqz-common/hnqz-common-core/src/main/resources/lib/beetroot-0.0.6.jar


+ 29 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/config/CommonConfiguration.java

@@ -0,0 +1,29 @@
+package com.qunzhixinxi.hnqz.admin.config;
+
+import com.bribric.beetroot.net.Ip2Region;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 会员中心公共配置
+ *
+ * @author jimmy
+ * @version 1.0.0
+ * @date 2022-12-21 22:02
+ */
+@Slf4j
+@Configuration
+public class CommonConfiguration {
+
+	/**
+	 * 获取IP属地查询器
+	 *
+	 * @return 查询器
+	 */
+	@Bean
+	public Ip2Region ip2Region() {
+
+		return new Ip2Region();
+	}
+}

+ 12 - 2
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/ApiController.java

@@ -14,6 +14,7 @@ import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.IdcardUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
@@ -23,6 +24,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.bribric.beetroot.common.exception.BeetrootException;
+import com.bribric.beetroot.net.Ip2Region;
 import com.google.zxing.WriterException;
 import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
@@ -134,6 +137,7 @@ import com.qunzhixinxi.hnqz.common.core.constant.enums.CommonFlag;
 import com.qunzhixinxi.hnqz.common.core.constant.enums.LoginTypeEnum;
 import com.qunzhixinxi.hnqz.common.core.constant.enums.UpmsState;
 import com.qunzhixinxi.hnqz.common.core.exception.BizException;
+import com.qunzhixinxi.hnqz.common.core.util.HttpUtils;
 import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
 import com.qunzhixinxi.hnqz.common.security.annotation.Inner;
@@ -158,6 +162,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.imageio.ImageIO;
 import javax.imageio.stream.ImageOutputStream;
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
@@ -199,6 +204,7 @@ import java.util.stream.Stream;
 @RequiredArgsConstructor
 @RequestMapping("/api")
 public class ApiController {
+	private final Ip2Region ip2Region;
 	private final WmTaskContentService wmTaskContentService;
 	private final WmTaskContentConfigService wmTaskContentConfigService;
 	private final WmWkArticleService wmWkArticleService;
@@ -1268,7 +1274,11 @@ public class ApiController {
 	 */
 	@SysLog("新增任务内容表")
 	@PostMapping("/saveTaskContent")
-	public R<?> saveTaskContent(@RequestBody WmTaskContent wmTaskContent) {
+	public R<?> saveTaskContent(@RequestBody WmTaskContent wmTaskContent, HttpServletRequest request) throws BeetrootException {
+
+		String ipAddr = HttpUtils.getIpAddr(request);
+		String region = ip2Region.toRegion(ipAddr);
+		log.info("提交任务远端IP和地址: [{}]:[{}]", ipAddr, region);
 		log.info("saveTaskContent入参:{}", wmTaskContent);
 		Set<String> errorHash = new HashSet<>();
 		List<String> ducImgUrl = new ArrayList<>();
@@ -1315,7 +1325,7 @@ public class ApiController {
 
 		R<?> r = null;
 		try {
-			r = wmTaskContentService.saveTaskContent(wmTaskContent);
+			r = wmTaskContentService.saveTaskContent(wmTaskContent, ipAddr, region);
 		} catch (Exception e) {
 			log.error("", e);
 			return R.failed(e.getMessage());

+ 239 - 228
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmTask.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -20,232 +21,242 @@ import java.util.List;
 @TableName(value = "wm_task", autoResultMap = true)
 @EqualsAndHashCode(callSuper = true)
 public class WmTask extends Model<WmTask> {
-	private static final long serialVersionUID = 1L;
-
-
-	@TableId
-	private String id;
-
-	/**
-	 * 任务编号
-	 */
-	private String taskNumber;
-
-	/**
-	 * 任务类型ID
-	 */
-	private String taskTypeId;
-
-	/**
-	 * 任务类型名称
-	 */
-	@TableField(exist = false)
-	private String taskTypeName;
-
-	Integer score;
-
-	String scorePackageDrugId;
-
-	String scorePackageLevel1Id;
-
-	String scorePackageId;
-
-	/**
-	 * 积分包名称
-	 */
-	@TableField(exist = false)
-	private String scorePackageName;
-
-	String taskRuleId;
-
-	/**
-	 * 调研时间
-	 */
-	private LocalDateTime lookintoDate;
-	/**
-	 * 省
-	 */
-	private String province;
-	/**
-	 * 市
-	 */
-	private String city;
-	/**
-	 * 区
-	 */
-	private String area;
-	/**
-	 * 地址
-	 */
-	private String address;
-	/**
-	 * 调研类型ID
-	 */
-	private String lookintoTypeId;
-	/**
-	 * 任务内容ID
-	 */
-	private String taskContentId;
-	/**
-	 * 任务状态
-	 */
-	private String taskStatus;
-
-	/**
-	 * 提交审核状态
-	 */
-	private String submitStatus;
-
-	/**
-	 * 任务用户ID
-	 */
-	private String taskUserId;
-
-	/**
-	 * 用户类型ID
-	 */
-	private String taskUserType;
-
-	/**
-	 * 服务药企
-	 */
-	private String drugEntId;
-
-	/**
-	 * 分享图片地址
-	 */
-	private String shareImgUrl;
-
-	/**
-	 * 组织机构ID
-	 */
-	private String deptId;
-	/**
-	 * 是否删除
-	 */
-	private String delFlag;
-	/**
-	 * 是否禁用
-	 */
-	private String enableFlag;
-	/**
-	 * 所属租户
-	 */
-	private Integer tenantId;
-	/**
-	 * 创建时间
-	 */
-	private LocalDateTime createTime;
-	/**
-	 * 创建人
-	 */
-	private Integer createUser;
-	/**
-	 * 更新时间
-	 */
-	private LocalDateTime updateTime;
-	/**
-	 * 更新人
-	 */
-	private String updateUser;
-
-	private String platAuditStatus;
-
-	@TableField(typeHandler = JacksonTypeHandler.class)
-	private List<String> extIds;
-
-	private String taskInfoImg;
-
-	/**
-	 * 对比结果
-	 */
-	private String compareResult;
-	/**
-	 * 审批意见
-	 */
-	private String approvalOpinion;
-	/**
-	 * 审批说明
-	 */
-	private String approvalInfo;
-
-	private String realFlag;
-
-	private Integer reportOneId;
-	private String reportOneApprovalStatus;
-	private String reportOneApprovalOpinion;
-	private String reportOneApprovalInfo;
-
-	private Integer reportSecondId;
-	private String reportSecondApprovalStatus;
-	private String reportSecondApprovalOpinion;
-	private String reportSecondApprovalInfo;
-
-	private Integer reportDrugId;
-	private String reportDrugApprovalStatus;
-	private String reportDrugApprovalOpinion;
-	private String reportDrugApprovalInfo;
-
-	/**
-	 * 接单对象list
-	 */
-	@TableField(exist = false)
-	private WmTaskContent wmTaskContent;
-
-	@TableField(exist = false)
-	private String type;
-
-	/**
-	 * cso审批说明
-	 */
-	private String taskStatusInfo;
-
-
-	private String taskFrom;
-
-	/**
-	 * 复审次数记录
-	 */
-	private Integer reviewTaskCount;
-
-	/**
-	 * 企业复审次数记录
-	 */
-	private Integer deptReviewTaskCount;
-
-	/**
-	 * 任务用户用户名
-	 */
-	@TableField(exist = false)
-	private String taskUsername;
-
-	/**
-	 * 关联的用户手机号
-	 */
-	@TableField(exist = false)
-	private String username;
-
-	/**
-	 * 结算状态
-	 */
-	@TableField(exist = false)
-	private Integer settleStatus;
-
-	/**
-	 * 提交时间
-	 */
-	@TableField(exist = false)
-	private LocalDateTime subTime;
-
-	/**
-	 * 提交到零工时间
-	 */
-	@TableField(exist = false)
-	private LocalDateTime subToGigTime;
-
-	/**
-	 * 结算时间
-	 */
-	@TableField(exist = false)
-	private LocalDateTime notifyDate;
+    private static final long serialVersionUID = 1L;
+
+
+    @TableId
+    private String id;
+
+    /**
+     * 任务编号
+     */
+    private String taskNumber;
+
+    /**
+     * 任务类型ID
+     */
+    private String taskTypeId;
+
+    /**
+     * 任务类型名称
+     */
+    @TableField(exist = false)
+    private String taskTypeName;
+
+    Integer score;
+
+    String scorePackageDrugId;
+
+    String scorePackageLevel1Id;
+
+    String scorePackageId;
+
+    /**
+     * 积分包名称
+     */
+    @TableField(exist = false)
+    private String scorePackageName;
+
+    String taskRuleId;
+
+    /**
+     * 调研时间
+     */
+    private LocalDateTime lookintoDate;
+    /**
+     * 省
+     */
+    private String province;
+    /**
+     * 市
+     */
+    private String city;
+    /**
+     * 区
+     */
+    private String area;
+    /**
+     * 地址
+     */
+    private String address;
+    /**
+     * 调研类型ID
+     */
+    private String lookintoTypeId;
+    /**
+     * 任务内容ID
+     */
+    private String taskContentId;
+    /**
+     * 任务状态
+     */
+    private String taskStatus;
+
+    /**
+     * 提交审核状态
+     */
+    private String submitStatus;
+
+    /**
+     * 任务用户ID
+     */
+    private String taskUserId;
+
+    /**
+     * 用户类型ID
+     */
+    private String taskUserType;
+
+    /**
+     * 服务药企
+     */
+    private String drugEntId;
+
+    /**
+     * 分享图片地址
+     */
+    private String shareImgUrl;
+
+    /**
+     * 组织机构ID
+     */
+    private String deptId;
+    /**
+     * 是否删除
+     */
+    private String delFlag;
+    /**
+     * 是否禁用
+     */
+    private String enableFlag;
+    /**
+     * 所属租户
+     */
+    private Integer tenantId;
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+    /**
+     * 创建人
+     */
+    private Integer createUser;
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+    /**
+     * 更新人
+     */
+    private String updateUser;
+
+    private String platAuditStatus;
+
+    @TableField(typeHandler = JacksonTypeHandler.class)
+    private List<String> extIds;
+
+    private String taskInfoImg;
+
+    /**
+     * 对比结果
+     */
+    private String compareResult;
+    /**
+     * 审批意见
+     */
+    private String approvalOpinion;
+    /**
+     * 审批说明
+     */
+    private String approvalInfo;
+
+    private String realFlag;
+
+    private Integer reportOneId;
+    private String reportOneApprovalStatus;
+    private String reportOneApprovalOpinion;
+    private String reportOneApprovalInfo;
+
+    private Integer reportSecondId;
+    private String reportSecondApprovalStatus;
+    private String reportSecondApprovalOpinion;
+    private String reportSecondApprovalInfo;
+
+    private Integer reportDrugId;
+    private String reportDrugApprovalStatus;
+    private String reportDrugApprovalOpinion;
+    private String reportDrugApprovalInfo;
+
+    /**
+     * 接单对象list
+     */
+    @TableField(exist = false)
+    private WmTaskContent wmTaskContent;
+
+    @TableField(exist = false)
+    private String type;
+
+    /**
+     * cso审批说明
+     */
+    private String taskStatusInfo;
+
+
+    private String taskFrom;
+
+    /**
+     * 复审次数记录
+     */
+    private Integer reviewTaskCount;
+
+    /**
+     * 企业复审次数记录
+     */
+    private Integer deptReviewTaskCount;
+
+    /**
+     * 任务用户用户名
+     */
+    @TableField(exist = false)
+    private String taskUsername;
+
+    /**
+     * 关联的用户手机号
+     */
+    @TableField(exist = false)
+    private String username;
+
+    /**
+     * 结算状态
+     */
+    @TableField(exist = false)
+    private Integer settleStatus;
+
+    /**
+     * 提交时间
+     */
+    @TableField(exist = false)
+    private LocalDateTime subTime;
+
+    /**
+     * 提交到零工时间
+     */
+    @TableField(exist = false)
+    private LocalDateTime subToGigTime;
+
+    /**
+     * 结算时间
+     */
+    @TableField(exist = false)
+    private LocalDateTime notifyDate;
+
+    /**
+     * 请求ip
+     */
+    private String remoteIp;
+
+    /**
+     * ip归属地
+     */
+    private String ip2region;
 }

+ 1 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmTaskContentService.java

@@ -22,7 +22,7 @@ public interface WmTaskContentService extends IService<WmTaskContent> {
 	 * @param wmTaskContent 任务内容
 	 * @return 保存结果
 	 */
-	R<?> saveTaskContent(WmTaskContent wmTaskContent);
+	R<?> saveTaskContent(WmTaskContent wmTaskContent, String ip, String region);
 
 	/**
 	 * 获取任务类型校验规则

+ 3 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmTaskContentServiceImpl.java

@@ -531,7 +531,7 @@ public class WmTaskContentServiceImpl extends ServiceImpl<WmTaskContentMapper, W
 	 */
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public R<?> saveTaskContent(WmTaskContent wmTaskContent) {
+	public R<?> saveTaskContent(WmTaskContent wmTaskContent, String ip, String region) {
 
 		// 获取积分包
 		WmScorePackage tWmScorePackage = this.checkPackage(wmTaskContent.getTemp32());
@@ -576,6 +576,8 @@ public class WmTaskContentServiceImpl extends ServiceImpl<WmTaskContentMapper, W
 		if (this.save(wmTaskContent)) {
 			if (null != sysU) {
 				WmTask wmTask = new WmTask();
+				wmTask.setRemoteIp(ip);
+				wmTask.setIp2region(region);
 				wmTask.setTaskFrom("1");
 				LocalDateTime localDateTime = LocalDateTime.now();
 				wmTask.setUpdateTime(localDateTime);