Pārlūkot izejas kodu

feat:定位功能修改优化

Ritchie 1 gadu atpakaļ
vecāks
revīzija
72335eff61

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
src/main/java/com/szwl/aspect/MyWebMvcConfigurer.java


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

@@ -288,7 +288,6 @@ public class IndexController {
 //            return "位置不匹配,请联系售后或营销经理处理";
 //        }
 
-        System.out.println(checkResult + "******");
 
         return this.initNew(clientId, managerId, gtClientId, equipmentType);
     }

+ 6 - 1
src/main/java/com/szwl/controller/ScheduledService.java

@@ -44,13 +44,18 @@ public class ScheduledService {
     public void equipmentLocCheck() throws IOException {
         if (isDo()) {
             List<TLocationCheck> locationChecks = locationCheckMapper.selectNotNullIp();
+//            String locErrorEq = null;
+            StringBuilder locErrorEq = new StringBuilder();
             for (TLocationCheck locationChc : locationChecks) {
                 String clientId = locationChc.getClientId();
                 String ip = locationChc.getIp();
                 String addr = WhoIsUtil.getLocByIp(ip);
                 // 这里不需要更新ip,只需要校验有ip的设备位置对不对
-                locationCheckService.locCheckMsg(locationChc, clientId, addr);
+//                locationCheckService.locCheckMsg(locationChc, clientId, addr);
+                String check = locationCheckService.schLocCheck(locationChc, clientId, addr);
+                locErrorEq.append(check);
             }
+            locationCheckService.schSendMsg(locErrorEq.toString());
         }
     }
 

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

@@ -0,0 +1,46 @@
+package com.szwl.controller;
+
+import com.szwl.mapper.TLocationCheckMapper;
+import com.szwl.model.entity.TLocationCheck;
+import com.szwl.service.TLocationCheckService;
+import com.szwl.util.WhoIsUtil;
+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 javax.annotation.Resource;
+import java.io.IOException;
+import java.util.List;
+
+@Slf4j
+@Api(value = "/tTest", tags = {"测试"})
+@RestController
+@RequestMapping("/tTest")
+public class TestController {
+
+    @Resource
+    TLocationCheckMapper locationCheckMapper;
+    @Resource
+    TLocationCheckService locationCheckService;
+    @ApiOperation(value = "测试定时任务")
+    @PostMapping("/testSch")
+    public void test() throws IOException {
+        List<TLocationCheck> locationChecks = locationCheckMapper.selectNotNullIp();
+//            String locErrorEq = null;
+        StringBuilder locErrorEq = new StringBuilder();
+        for (TLocationCheck locationChc : locationChecks) {
+            String clientId = locationChc.getClientId();
+            String ip = locationChc.getIp();
+            String addr = WhoIsUtil.getLocByIp(ip);
+            // 这里不需要更新ip,只需要校验有ip的设备位置对不对
+//                locationCheckService.locCheckMsg(locationChc, clientId, addr);
+            String check = locationCheckService.schLocCheck(locationChc, clientId, addr);
+            locErrorEq.append(check);
+        }
+        locationCheckService.schSendMsg(locErrorEq.toString());
+    }
+
+}

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

@@ -8,7 +8,7 @@ import java.io.IOException;
 
 /**
  * <p>
- *  服务类
+ * 服务类
  * </p>
  *
  * @author wuhs
@@ -16,5 +16,9 @@ import java.io.IOException;
  */
 public interface TLocationCheckService extends IService<TLocationCheck> {
 
-    String locCheckMsg(TLocationCheck locationCheck,String clientId, String addr) throws IOException;
+    String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException;
+
+    String schLocCheck(TLocationCheck locationCheck, String clientId, String addr);
+
+    void schSendMsg(String locErrorEq) throws IOException;
 }

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

@@ -78,5 +78,45 @@ public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper,
         return "success";
     }
 
+    @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)) {
+            if (country.equals("中国")) {
+                return "国内必须精确到省市";
+            } else {
+                containsUserInput = addr.contains(country);
+            }
+        } else {
+            if (country.equals("中国")) {
+                containsUserInput = addr.contains(location);
+            } else {
+                containsUserInput = addr.contains(country) || addr.contains(location);
+            }
+        }
+
+        if (!containsUserInput) { // 不包含,返回设备编号
+            return "{" + clientId + "}";
+        }
+
+        return "";
+    }
+
+    @Override
+    public void schSendMsg(String locErrorEq) throws IOException {
+        String phone = "18620242721";
+        String messages = "【申泽部门】设备编号:" + locErrorEq + ",所在ip与设定位置不符,请及时查看。";
+        YunPianSms.sendSms(appid, messages, phone);
+    }
+
 
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 240
src/test/java/com/szwl/RegexpTemp.java