Przeglądaj źródła

feat:定位功能优化调整

Ritchie 1 rok temu
rodzic
commit
61074d5f57

+ 60 - 31
src/main/java/com/szwl/controller/IndexController.java

@@ -213,19 +213,6 @@ public class IndexController {
         if(StringUtils.isEmpty(ip) || StringUtils.isEmpty(clientId)) {
             return "ip、clientId不能为空";
         }
-        // 根据ip校验位置信息
-        String s = WhoIsUtil.getLocByIp(ip);
-        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();
 
         // 根据 clientId 查设备的 location,country
         LambdaQueryWrapper<TLocationCheck> lqw = Wrappers.lambdaQuery();
@@ -235,31 +222,73 @@ public class IndexController {
             return "生产部未录入改设备的位置信息";
         }
 
+        // 根据ip校验位置信息
+        String addr = WhoIsUtil.getLocByIp(ip);
+
+//        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.setIp(ip);
-        locationCheck.setPro(pro);
-        locationCheck.setProCode(proCode);
-        locationCheck.setCity(city);
-        locationCheck.setCityCode(cityCode);
-        locationCheck.setRegion(region);
-        locationCheck.setRegionCode(regionCode);
-        locationCheck.setRegionNames(regionNames);
+//        locationCheck.setPro(pro);
+//        locationCheck.setProCode(proCode);
+//        locationCheck.setCity(city);
+//        locationCheck.setCityCode(cityCode);
+//        locationCheck.setRegion(region);
+//        locationCheck.setRegionCode(regionCode);
+//        locationCheck.setRegionNames(regionNames);
         locationCheck.setAddr(addr);
-        locationCheck.setErr(err);
+//        locationCheck.setErr(err);
 
         locationCheckService.saveOrUpdate(locationCheck);
 
-//        locationCheckService.locCheckMsg(locationCheck, clientId, ip, s);
-        String location = locationCheck.getLocation();
-        String country = locationCheck.getCountry();
-
-        // 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
-        boolean contains = addr.contains(country) || addr.contains(location);
-        String phone = "18620242721";
-        String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
-        if (!contains) { // 不包含,发短信通知,并拒绝审核
-            YunPianSms.sendSms(appid, messages, phone);
+        String checkResult = locationCheckService.locCheckMsg(locationCheck, clientId, addr);
+        if (checkResult.equals("fail")) {
             return "位置不匹配,请联系售后或营销经理处理";
         }
+        
+//        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 "位置不匹配,请联系售后或营销经理处理";
+//        }
+
+        System.out.println(checkResult + "******");
 
         return this.initNew(clientId, managerId, gtClientId, equipmentType);
     }

+ 2 - 2
src/main/java/com/szwl/controller/ScheduledService.java

@@ -47,9 +47,9 @@ public class ScheduledService {
             for (TLocationCheck locationChc : locationChecks) {
                 String clientId = locationChc.getClientId();
                 String ip = locationChc.getIp();
-                String s = WhoIsUtil.getLocByIp(ip);
+                String addr = WhoIsUtil.getLocByIp(ip);
                 // 这里不需要更新ip,只需要校验有ip的设备位置对不对
-                locationCheckService.locCheckMsg(locationChc, clientId, ip, s);
+                locationCheckService.locCheckMsg(locationChc, clientId, addr);
             }
         }
     }

+ 74 - 79
src/main/java/com/szwl/controller/TLocationCheckController.java

@@ -5,7 +5,6 @@ import cn.hutool.core.util.IdUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
@@ -19,9 +18,11 @@ import com.szwl.service.TAdminService;
 import com.szwl.service.TLocationCheckService;
 import com.szwl.util.WhoIsUtil;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.List;
 import java.util.Objects;
 
@@ -31,7 +32,7 @@ import java.util.Objects;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-06
+ * @since 2023-12-11
  */
 @RestController
 @RequestMapping("/tLocationCheck")
@@ -46,52 +47,26 @@ public class TLocationCheckController {
     }
 
 
-    @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);
-
-        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.setIp(ip);
-        locationCheck.setPro(pro);
-        locationCheck.setProCode(proCode);
-        locationCheck.setCity(city);
-        locationCheck.setCityCode(cityCode);
-        locationCheck.setRegion(region);
-        locationCheck.setRegionCode(regionCode);
-        locationCheck.setRegionNames(regionNames);
-        locationCheck.setAddr(addr);
-        locationCheck.setErr(err);
-
-        locationCheckService.saveOrUpdate(locationCheck);
-
-        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("生产部未录入改设备的位置信息");
+//        }
+//
+//        String s = WhoIsUtil.getLocByIp(ip);
+//
+//        String result = locationCheckService.locCheckMsg(locationCheck, clientId, ip, s);
+//
+//        return R.ok(result);
+//    }
 
     @ApiOperation(value = "修改录入的位置信息")
     @PostMapping("/updateLocInfo")
@@ -99,41 +74,60 @@ public class TLocationCheckController {
         if (Objects.isNull(locationCheck)) {
             return R.fail("参数不能为空");
         }
-//        String phone = locationCheck.getPhone();
-//        String username = locationCheck.getUsername();
-//        String clientId = locationCheck.getClientId();
-//        String name = locationCheck.getName();
-//        String location = locationCheck.getLocation();
-//        String country = locationCheck.getCountry();
-//
-//        if (Objects.isNull(clientId)) {
-//            return R.fail("设备唯一码不能为空");
-//        }
-//
+
+        // 售后部同事修改的信息:姓名,电话,username,clientId,国家
+        String modName = locationCheck.getModName();
+//        String modUsername = locationCheck.getModUsername();
+        String modPhone = locationCheck.getModPhone();
+        String clientId = locationCheck.getClientId();
+        String location = locationCheck.getLocation();
+        String country = locationCheck.getCountry();
+
+        if (Objects.isNull(clientId)) {
+            return R.fail("设备唯一码不能为空");
+        }
+
+        if (country.equals("中国")) {
+            if (StringUtils.isEmpty(location)) {
+                return R.fail("国内省市不能为空");
+            }
+        }
+
 //        LambdaQueryWrapper<TAdmin> lqw = Wrappers.lambdaQuery();
-//        lqw.eq(TAdmin::getUsername, username);
-//        TAdmin admin = adminService.getOne(lqw);
-//        if (Objects.isNull(admin)) {
-//            return R.fail("adminId账号不存在");
+//        lqw.eq(TAdmin::getUsername, modUsername);
+//        TAdmin modAdmin = adminService.getOne(lqw);
+//        if (Objects.isNull(modAdmin)) {
+//            return R.fail("modAdmin账号不存在");
 //        }
-//
-//        LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
-//        wrapper.eq(TLocationCheck::getClientId,clientId);
-//        List<TLocationCheck> checks = locationCheckService.list(wrapper);
-//        TLocationCheck tLocationCheck = checks.get(0);
-//
-//
-//
-//        Long adminId = admin.getId();
-////        String phone1 = admin.getPhone();
-////        if (!Objects.equals(phone1, phone)) {
-////            return R.fail("手机号码有误");
-////        }
-//        String name1 = admin.getName();
-//        if (!Objects.equals(name1, name)) {
+
+        LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(TLocationCheck::getClientId, clientId);
+        List<TLocationCheck> checks = locationCheckService.list(wrapper);
+        TLocationCheck tLocationCheck = checks.get(0);
+
+//        Long modAdminId = modAdmin.getId();
+//        String phone1 = modAdmin.getPhone();
+//        String name1 = modAdmin.getName();
+//        if (!Objects.equals(phone1, modPhone)) {
+//            return R.fail("手机号码有误");
+//        }
+//        if (!Objects.equals(name1, modName)) {
 //            return R.fail("姓名有误");
 //        }
-return R.ok();
+
+        tLocationCheck.setModifyTime(new Date());
+        tLocationCheck.setModName(modName);
+//        tLocationCheck.setModAdminId(modAdminId);
+        tLocationCheck.setModPhone(modPhone);
+//        tLocationCheck.setModUsername(modUsername);
+        tLocationCheck.setLocation(location);
+        tLocationCheck.setClientId(clientId);
+        tLocationCheck.setCountry(country);
+
+        locationCheckService.updateById(tLocationCheck);
+
+
+        return R.ok("修改成功");
     }
 
 
@@ -180,6 +174,7 @@ return R.ok();
 //        String uuid = IdUtil.randomUUID();
         String uuid = IdUtil.simpleUUID();
         tLocationCheck.setId(uuid);
+        tLocationCheck.setCreateTime(new Date());
         tLocationCheck.setAdminId(adminId);
         tLocationCheck.setPhone(phone);
         tLocationCheck.setUsername(username);

+ 1 - 1
src/main/java/com/szwl/mapper/TLocationCheckMapper.java

@@ -11,7 +11,7 @@ import java.util.List;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-06
+ * @since 2023-12-11
  */
 public interface TLocationCheckMapper extends BaseMapper<TLocationCheck> {
 

+ 6 - 2
src/main/java/com/szwl/mapper/xml/TLocationCheckMapper.xml

@@ -27,15 +27,19 @@
         <result column="region_names" property="regionNames" />
         <result column="err" property="err" />
         <result column="name" property="name" />
+        <result column="mod_admin_id" property="modAdminId" />
+        <result column="mod_phone" property="modPhone" />
+        <result column="mod_username" property="modUsername" />
+        <result column="mod_name" property="modName" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, create_time, modify_time, admin_id, phone, client_id, location, longitude, latitude, country, country_code, username, ip, pro, pro_code, city, city_code, region, region_code, addr, region_names, err, name
+        id, create_time, modify_time, admin_id, phone, client_id, location, longitude, latitude, country, country_code, username, ip, pro, pro_code, city, city_code, region, region_code, addr, region_names, err, name, mod_admin_id, mod_phone, mod_username, mod_name
     </sql>
 
     <select id="selectNotNullIp" resultMap="BaseResultMap">
-        select id, create_time, modify_time, admin_id, phone, client_id, location, longitude, latitude, country, country_code, username, ip, pro, pro_code, city, city_code, region, region_code, addr, region_names, err, name
+        select id, create_time, modify_time, admin_id, phone, client_id, location, longitude, latitude, country, country_code, username, ip, pro, pro_code, city, city_code, region, region_code, addr, region_names, err, name, mod_admin_id, mod_phone, mod_username, mod_name
         from t_location_check
         where ip is not null
     </select>

+ 14 - 2
src/main/java/com/szwl/model/entity/TLocationCheck.java

@@ -15,7 +15,7 @@ import lombok.EqualsAndHashCode;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-06
+ * @since 2023-12-11
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -49,7 +49,7 @@ public class TLocationCheck implements Serializable {
     @ApiModelProperty(value = "纬度")
     private String latitude;
 
-    @ApiModelProperty(value = "生产部员工录入的国家信息	")
+    @ApiModelProperty(value = "国家名称")
     private String country;
 
     @ApiModelProperty(value = "国家编码")
@@ -91,5 +91,17 @@ public class TLocationCheck implements Serializable {
     @ApiModelProperty(value = "生产部员工姓名")
     private String name;
 
+    @ApiModelProperty(value = "售后部员工的adminId")
+    private Long modAdminId;
+
+    @ApiModelProperty(value = "售后部员工电话")
+    private String modPhone;
+
+    @ApiModelProperty(value = "售后部员工的username")
+    private String modUsername;
+
+    @ApiModelProperty(value = "售后部员工姓名")
+    private String modName;
+
 
 }

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

@@ -12,9 +12,9 @@ import java.io.IOException;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-06
+ * @since 2023-12-11
  */
 public interface TLocationCheckService extends IService<TLocationCheck> {
 
-    String locCheckMsg(TLocationCheck locationCheck,String clientId, String ip, String s) throws IOException;
+    String locCheckMsg(TLocationCheck locationCheck,String clientId, String addr) throws IOException;
 }

+ 35 - 10
src/main/java/com/szwl/service/impl/TLocationCheckServiceImpl.java

@@ -12,6 +12,7 @@ import com.szwl.mapper.TLocationCheckMapper;
 import com.szwl.model.utils.YunPianSms;
 import com.szwl.service.TLocationCheckService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -24,33 +25,57 @@ import java.util.Objects;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-06
+ * @since 2023-12-11
  */
 @Service
 public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper, TLocationCheck> implements TLocationCheckService {
 
+//    TLocationCheckService locationCheckService;
+//
+//    public TLocationCheckServiceImpl(TLocationCheckService locationCheckService) {
+//        this.locationCheckService = locationCheckService;
+//    }
 
     private static final String appid = "07784f5fedb508046c841b391005b7de";
 
     @Override
-    public String locCheckMsg(TLocationCheck locationCheck,String clientId, String ip, String s) throws IOException {
+    public String locCheckMsg(TLocationCheck locationCheck, String clientId, String addr) throws IOException {
 
         String location = locationCheck.getLocation();
         String country = locationCheck.getCountry();
-        ObjectMapper objectMapper = new ObjectMapper();
-        JsonNode jsonNode = objectMapper.readTree(s);
-        String addr = jsonNode.get("addr").asText();
 
+        if (StringUtils.isEmpty(country)) {
+            return "国家不能为空";
+        }
+//        ObjectMapper objectMapper = new ObjectMapper();
+//        JsonNode jsonNode = objectMapper.readTree(s);
+//        String addr = jsonNode.get("addr").asText();
 
         // 如果 pro,city,addr 中都不包含 country 或者 location,就是异常,发短信通知
-        boolean contains = addr.contains(country) || addr.contains(location);
+        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);
+            }
+        }
+
         String phone = "18620242721";
         String messages = "【申泽部门】设备编号:" + clientId + ",所在ip与设定位置不符,请及时查看。";
-        String result = null;
-        if (!contains) { // 不包含,发短信通知
-            result = YunPianSms.sendSms(appid, messages, phone);
+        if (!containsUserInput) { // 不包含,发短信通知,并拒绝审核
+            YunPianSms.sendSms(appid, messages, phone);
+            return "fail";
         }
-        return result;
+        return "success";
     }
 
 

+ 3 - 1
src/main/java/com/szwl/util/WhoIsUtil.java

@@ -6,7 +6,9 @@ public class WhoIsUtil {
 
     public static String getLocByIp(String ip) {
         // 根据 ip 获取位置
-        String reqUrl = "http://whois.pconline.com.cn/ipJson.jsp?json=true&ip=" + ip;
+//        String reqUrl = "http://whois.pconline.com.cn/ipJson.jsp?json=true&ip=" + ip;
+        String reqUrl = "http://whois.pconline.com.cn/ip.jsp?ip=" + ip;
+
 //        HttpRequest.get(reqUrl)
         return HttpUtil.get(reqUrl);
     }

Plik diff jest za duży
+ 240 - 0
src/test/java/com/szwl/RegexpTemp.java