Преглед изворни кода

:art: 定位信息不用再录入备选location

Ritchie пре 1 година
родитељ
комит
51415aeb2d

+ 0 - 61
src/main/java/com/szwl/controller/IndexController.java

@@ -244,9 +244,6 @@ public class IndexController {
     @RequestMapping(value = "/initNew2.htm", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
     @ResponseBody
     public String initNew2(String clientId, String managerId, String gtClientId, String equipmentType, String ip, String longitude, String latitude) throws IOException {
-//        if (StringUtils.isEmpty(ip) || StringUtils.isEmpty(clientId)) {
-//            return "ip、clientId不能为空";
-//        }
         if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(longitude) || StringUtils.isEmpty(latitude)) {
             return "设备编号、经纬度不能为空";
         }
@@ -285,66 +282,8 @@ public class IndexController {
             if (checkResult.equals("fail")) {
                 return "位置不匹配,请联系营销经理/售后处理";
             }
-
         }
         return this.initNew(clientId, managerId, gtClientId, equipmentType);
-
-//        ObjectMapper objectMapper = new ObjectMapper();
-//        JsonNode jsonNode = objectMapper.readTree(s);
-//        String pro = jsonNode.get("pro").asText();
-//        String proCode = jsonNode.get("proCode").asText();
-//        String city = jsonNode.get("city").asText();
-//        String cityCode = jsonNode.get("cityCode").asText();
-//        String region = jsonNode.get("region").asText();
-//        String regionCode = jsonNode.get("regionCode").asText();
-//        String regionNames = jsonNode.get("regionNames").asText();
-//        String addr = jsonNode.get("addr").asText();
-//        String err = jsonNode.get("err").asText();
-
-
-//        locationCheck.setPro(pro);
-//        locationCheck.setProCode(proCode);
-//        locationCheck.setCity(city);
-//        locationCheck.setCityCode(cityCode);
-//        locationCheck.setRegion(region);
-//        locationCheck.setRegionCode(regionCode);
-//        locationCheck.setRegionNames(regionNames);
-
-//        locationCheck.setErr(err);
-
-//        String location = locationCheck.getLocation();
-//        String country = locationCheck.getCountry();
-
-//        boolean containsUserInput = false;
-//        if (StringUtils.isEmpty(location)) {
-//            // 只需要判断 pro,city,region,addr中是否包含 country
-//            if (StringUtils.isNotEmpty(pro) && pro.contains(country)) {
-//                containsUserInput = true;
-//            } else if (StringUtils.isNotEmpty(city) && city.contains(country)) {
-//                containsUserInput = true;
-//            } else if (StringUtils.isNotEmpty(region) && region.contains(country)) {
-//                containsUserInput = true;
-//            } else if (StringUtils.isNotEmpty(addr) && addr.contains(country)) {
-//                containsUserInput = true;
-//            }
-//        }
-        // 判断 pro,city,region,addr中是否包含 country 或 location
-
-
-//        boolean containsUserInput = true;
-//        if (StringUtils.isEmpty(location)) {
-//            containsUserInput = addr.contains(country);
-//        } else {
-//            containsUserInput = addr.contains(country) || addr.contains(location);
-//        }
-//
-//        String phone = "18620242721";
-//        String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
-//        if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
-//            YunPianSms.sendSms(appid, messages, phone);
-//            return "位置不匹配,请联系售后或营销经理处理";
-//        }
-
     }
 
 

+ 4 - 4
src/main/java/com/szwl/controller/TLocationCheckController.java

@@ -127,7 +127,7 @@ public class TLocationCheckController {
         String modName = locationCheck.getModName();
         String modPhone = locationCheck.getModPhone();
         String clientId = locationCheck.getClientId();
-        String location = locationCheck.getLocation();
+//        String location = locationCheck.getLocation();
         String country = locationCheck.getCountry();
         String message = locationCheck.getMessage();
 
@@ -146,7 +146,7 @@ public class TLocationCheckController {
 //        tLocationCheck.setModAdminId(modAdminId);
         tLocationCheck.setModPhone(modPhone);
         tLocationCheck.setModUsername(modUsername);
-        tLocationCheck.setLocation(location);
+//        tLocationCheck.setLocation(location);
         tLocationCheck.setClientId(clientId);
         tLocationCheck.setCountry(country);
         tLocationCheck.setMessage(message);
@@ -170,7 +170,7 @@ public class TLocationCheckController {
         String username = locationCheck.getUsername();
         String clientId = locationCheck.getClientId();
         String country = locationCheck.getCountry(); // 国家
-        String location = locationCheck.getLocation(); // 地区
+//        String location = locationCheck.getLocation(); // 地区
 
         if (Objects.isNull(clientId)) {
             return R.fail("设备唯一码不能为空");
@@ -197,7 +197,7 @@ public class TLocationCheckController {
         tLocationCheck.setUsername(username);
         tLocationCheck.setClientId(clientId);
         tLocationCheck.setCountry(country);
-        tLocationCheck.setLocation(location);
+//        tLocationCheck.setLocation(location);
 
         locationCheckService.save(tLocationCheck);
 

+ 2 - 4
src/main/java/com/szwl/controller/TParametersController.java

@@ -54,8 +54,7 @@ public class TParametersController {
 
     /**
      * 获取设备参数
-     *
-     * @param
+     * @param parameters
      * @return
      */
     @PostMapping("/getParameters")
@@ -86,8 +85,7 @@ public class TParametersController {
 
     /**
      * 推送设备共同以及/设备参数
-     *
-     * @param
+     * @param commonParamVo
      * @return
      */
     @PostMapping("/updateParameters")

+ 0 - 15
src/main/java/com/szwl/controller/TestController.java

@@ -1,15 +0,0 @@
-package com.szwl.controller;
-
-import io.swagger.annotations.Api;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-
-@Slf4j
-@Api(value = "/tTest", tags = {"测试"})
-@RestController
-@RequestMapping("/tTest")
-public class TestController {
-
-}

+ 20 - 30
src/main/java/com/szwl/service/impl/TLocationCheckServiceImpl.java

@@ -9,6 +9,7 @@ import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
+import java.util.StringTokenizer;
 
 /**
  * <p>
@@ -21,24 +22,15 @@ import java.io.IOException;
 @Service
 public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper, TLocationCheck> implements TLocationCheckService {
 
-
     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);
-        }
+        boolean containsUserInput = isAddressInCountryList(addr, country);
 
         if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
             return "fail";
@@ -49,22 +41,13 @@ public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper,
     @Override
     public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
 
-        String location = locationCheck.getLocation();
         String country = locationCheck.getCountry();
 
         if (StringUtils.isEmpty(country)) {
             return "国家不能为空";
         }
 
-        // 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
-        boolean containsUserInput = true;
-        // location 为空 / 不为空
-        // country 是中国 / 不是中国
-        if (StringUtils.isEmpty(location)) {
-            containsUserInput = addr.contains(country);
-        } else {
-            containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
-        }
+        boolean containsUserInput = isAddressInCountryList(addr, country);
 
         String phone = "18620242721";
 //        String phone1 = "13631231970"; // 基哥
@@ -79,23 +62,30 @@ public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper,
         return "success";
     }
 
+    public static boolean isAddressInCountryList(String addr, String country) {
+        // 使用StringTokenizer分割国家字符串
+        StringTokenizer tokenizer = new StringTokenizer(country, "、");
+
+        // 循环遍历国家列表
+        while (tokenizer.hasMoreTokens()) {
+            String singleCountry = tokenizer.nextToken();
+            // 如果地址包含当前国家,则返回true
+            if (addr.contains(singleCountry)) {
+                return true;
+            }
+        }
+        // 如果没有找到匹配的国家,则返回false
+        return false;
+    }
+
     @Override
     public String schLocCheck(TLocationCheck locationCheck, String clientId, String addr) {
-        String location = locationCheck.getLocation();
         String country = locationCheck.getCountry();
 
         if (StringUtils.isEmpty(country)) {
             return "国家不能为空";
         }
-
-        boolean containsUserInput = true;
-        // location 地区为空 / 不为空
-        // country 国家是中国 / 不是中国
-        if (StringUtils.isEmpty(location)) {
-            containsUserInput = addr.contains(country);
-        } else {
-            containsUserInput = addr.contains(country) || addr.contains(location) || location.contains(addr);
-        }
+        boolean containsUserInput = isAddressInCountryList(addr, country);
 
         if (!containsUserInput) { // 不包含,返回设备编号
             return "{" + clientId + "}";

+ 51 - 0
src/test/java/com/szwl/controller/TestController.java

@@ -0,0 +1,51 @@
+package com.szwl.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+import java.util.StringTokenizer;
+import org.junit.Test;
+
+@Slf4j
+@Api(value = "/tTest", tags = {"测试"})
+@RestController
+@RequestMapping("/tTest")
+public class TestController {
+
+    @Test
+    @ApiOperation(value = "测试")
+    @PostMapping("/testService")
+    public void testService(){
+        String country = "美国";
+
+        String addr = "日本冲绳札幌市二丁目";
+
+        boolean containsUserInput = isAddressInCountryList(addr, country);
+        if (!containsUserInput) {
+            System.out.println("不包含");
+        }
+        System.out.println("通过,包含");
+    }
+
+
+    public static boolean isAddressInCountryList(String addr, String country) {
+        // 使用StringTokenizer分割国家字符串
+        StringTokenizer tokenizer = new StringTokenizer(country, "、");
+
+        // 循环遍历国家列表
+        while (tokenizer.hasMoreTokens()) {
+            String singleCountry = tokenizer.nextToken();
+            // 如果地址包含当前国家,则返回true
+            if (addr.contains(singleCountry)) {
+                return true;
+            }
+        }
+        // 如果没有找到匹配的国家,则返回false
+        return false;
+    }
+}