Преглед на файлове

feat: 根据ip校验clientId设备位置判断地区位置调整

Ritchie преди 1 година
родител
ревизия
1ad8b6eca7

+ 28 - 20
src/main/java/com/szwl/controller/TLocationCheckController.java

@@ -68,26 +68,34 @@ public class TLocationCheckController {
         return R.fail("地区信息未录入");
     }
 
-//    @ApiOperation(value = "根据ip校验clientId设备位置")
-//    @PostMapping("/ipCheck")
-//    public ResponseModel<?> ipCheck(@RequestParam String clientId, @RequestParam String ip) throws IOException {
-//        if (StringUtils.isBlank(clientId) || StringUtils.isBlank(ip)) {
-//            return R.fail("参数不能为空");
-//        }
-//        // 根据 clientId 查设备的 location,country
-//        LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
-//        lqw.eq(TLocationCheck::getClientId, clientId);
-//        TLocationCheck locationCheck = locationCheckService.getOne(lqw);
-//        if (Objects.isNull(locationCheck)) {
-//            return R.fail("生产部未录入改设备的位置信息");
-//        }
-//
-//        String s = WhoIsUtil.getLocByIp(ip);
-//
-//        String result = locationCheckService.locCheckMsg(locationCheck, clientId, ip, s);
-//
-//        return R.ok(result);
-//    }
+    @ApiOperation(value = "根据ip校验clientId设备位置")
+    @PostMapping("/ipCheck")
+    public ResponseModel<?> ipCheck(@RequestParam String clientId, @RequestParam String ip) throws IOException {
+        if (StringUtils.isBlank(clientId) || StringUtils.isBlank(ip)) {
+            return R.fail("参数不能为空");
+        }
+        // 根据 clientId 查设备的 location,country
+        LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
+        lqw.eq(TLocationCheck::getClientId, clientId);
+        TLocationCheck locationCheck = locationCheckService.getOne(lqw);
+        if (Objects.isNull(locationCheck)) {
+            return R.fail("生产部未录入改设备的位置信息");
+        }
+
+        locationCheck.setIp(ip);
+        locationCheck.setModifyTime(new Date());
+
+        String addr = WhoIsUtil.getLocByIp(ip);
+
+//        String result = locationCheckService.locCheckMsg(locationCheck, clientId, addr);
+        String result = locationCheckService.locCheckNoMsg(locationCheck, clientId, addr);
+
+        if ("fail".equals(result)) {
+            locationCheck.setErr("不匹配");
+        }
+        locationCheckService.updateById(locationCheck);
+        return R.ok(result);
+    }
 
     @ApiOperation(value = "修改录入的位置信息")
     @PostMapping("/updateLocInfo")

+ 2 - 0
src/main/java/com/szwl/service/TLocationCheckService.java

@@ -16,6 +16,8 @@ import java.io.IOException;
  */
 public interface TLocationCheckService extends IService<TLocationCheck> {
 
+    String locCheckNoMsg(TLocationCheck locationCheck, String clientId, String addr);
+
     String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException;
 
     String schLocCheck(TLocationCheck locationCheck, String clientId, String addr);

+ 22 - 0
src/main/java/com/szwl/service/impl/TLocationCheckServiceImpl.java

@@ -39,6 +39,28 @@ public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper,
     private static final String appid = "07784f5fedb508046c841b391005b7de";
 
     @Override
+    public String locCheckNoMsg(TLocationCheck locationCheck, String clientId, String addr) {
+        String location = locationCheck.getLocation();
+        String country = locationCheck.getCountry();
+        if (StringUtils.isEmpty(country)) {
+            return "国家不能为空";
+        }
+        // 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
+        boolean containsUserInput = true;
+        // location 为空 / 不为空
+        if (StringUtils.isEmpty(location)) {
+            containsUserInput = addr.contains(country);
+        } else {
+            containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
+        }
+
+        if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
+            return "fail";
+        }
+        return "success";
+    }
+
+    @Override
     public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
 
         String location = locationCheck.getLocation();