Bläddra i källkod

feat: 定位相关功能调整,国内ip可绕过,售后可录入,增加修改原因

Ritchie 1 år sedan
förälder
incheckning
fdc022d91a

+ 28 - 21
src/main/java/com/szwl/controller/IndexController.java

@@ -219,7 +219,7 @@ public class IndexController {
     @ApiOperation(value = "设备初始化申请2")
     @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) throws IOException {
+    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不能为空";
         }
@@ -232,8 +232,25 @@ public class IndexController {
             return "生产部未录入改设备的位置信息";
         }
 
-        // 根据ip校验位置信息
-        String addr = WhoIsUtil.getLocByIp(ip);
+        // 判断ip是否属于国内,if 国内,放行
+        double lon = Double.parseDouble(longitude);
+        double lat = Double.parseDouble(latitude);
+
+        // 经度范围在73至135之间,纬度范围在3至53之间,即国内区域
+        if (!(lon >= 73) || !(lon <= 135) || !(lat >= 3) || !(lat <= 53)) {
+            // 根据ip校验位置信息
+            String addr = WhoIsUtil.getLocByIp(ip);
+            locationCheck.setIp(ip);
+            locationCheck.setAddr(addr);
+            locationCheckService.saveOrUpdate(locationCheck);
+
+            String checkResult = locationCheckService.locCheckMsg(locationCheck, clientId, addr);
+            if (checkResult.equals("fail")) {
+                return "位置不匹配,请联系营销经理/售后处理";
+            }
+
+        }
+        return this.initNew(clientId, managerId, gtClientId, equipmentType);
 
 //        ObjectMapper objectMapper = new ObjectMapper();
 //        JsonNode jsonNode = objectMapper.readTree(s);
@@ -247,7 +264,7 @@ public class IndexController {
 //        String addr = jsonNode.get("addr").asText();
 //        String err = jsonNode.get("err").asText();
 
-        locationCheck.setIp(ip);
+
 //        locationCheck.setPro(pro);
 //        locationCheck.setProCode(proCode);
 //        locationCheck.setCity(city);
@@ -255,15 +272,8 @@ public class IndexController {
 //        locationCheck.setRegion(region);
 //        locationCheck.setRegionCode(regionCode);
 //        locationCheck.setRegionNames(regionNames);
-        locationCheck.setAddr(addr);
-//        locationCheck.setErr(err);
-
-        locationCheckService.saveOrUpdate(locationCheck);
 
-        String checkResult = locationCheckService.locCheckMsg(locationCheck, clientId, addr);
-        if (checkResult.equals("fail")) {
-            return "位置不匹配,请联系售后或营销经理处理";
-        }
+//        locationCheck.setErr(err);
 
 //        String location = locationCheck.getLocation();
 //        String country = locationCheck.getCountry();
@@ -298,8 +308,6 @@ public class IndexController {
 //            return "位置不匹配,请联系售后或营销经理处理";
 //        }
 
-
-        return this.initNew(clientId, managerId, gtClientId, equipmentType);
     }
 
 
@@ -399,7 +407,7 @@ public class IndexController {
 
     }
 
-//    @ApiOperation(value = "同意设备申请")
+    //    @ApiOperation(value = "同意设备申请")
 //    @RequestMapping(value = "/agree", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
 //    @ResponseBody
     private void agree(Long id) {
@@ -1144,7 +1152,7 @@ public class IndexController {
             ServletInputStream input = request.getInputStream();
             Auth auth = Auth.create(ConfigConsts.QINIU_CLOUD_ACCESS_KEY, ConfigConsts.QINIU_CLOUD_SECRET_KEY);
             String upToken = auth.uploadToken(ConfigConsts.QINIU_CLOUD_BUCKET, key);
-            Response responseMap = uploadManager.put(input, key, upToken,null, null);
+            Response responseMap = uploadManager.put(input, key, upToken, null, null);
             //解析上传成功的结果
             DefaultPutRet putRet = new Gson().fromJson(responseMap.bodyString(), DefaultPutRet.class);
             System.out.println(putRet.key);
@@ -2187,16 +2195,15 @@ public class IndexController {
     /**
      * 设备语言 开机时上传
      *
-     * @param clientId  个推
-
+     * @param clientId 个推
      * @return
      */
     @RequestMapping(value = "/upLoadLanguage", method = RequestMethod.GET, produces = "text/html;charset=utf-8")
     @ResponseBody
-    public String upLoadLanguage(String clientId, String language){
-        if(!StringUtils.isEmpty(language)){
+    public String upLoadLanguage(String clientId, String language) {
+        if (!StringUtils.isEmpty(language)) {
             LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
-            query.eq(TEquipment::getClientId,clientId);
+            query.eq(TEquipment::getClientId, clientId);
             TEquipment equipment = equipmentService.getOne(query);
             if (equipment == null) {
                 return "fail";

+ 14 - 49
src/main/java/com/szwl/controller/TLocationCheckController.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.szwl.constant.ResponseCodesEnum;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.entity.TAdmin;
@@ -22,9 +23,7 @@ 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;
+import java.util.*;
 
 /**
  * <p>
@@ -100,29 +99,23 @@ public class TLocationCheckController {
         // 售后部同事修改的信息:姓名,电话,username,clientId,国家
         String modUsername = locationCheck.getModUsername();
         if (!("shouhoumi".equals(modUsername)) && !("admin".equals(modUsername))) {
-            return R.fail("该账号无权操作");
+            return R.fail("该账号无权修改");
         }
         String modName = locationCheck.getModName();
         String modPhone = locationCheck.getModPhone();
         String clientId = locationCheck.getClientId();
         String location = locationCheck.getLocation();
         String country = locationCheck.getCountry();
+        String message = locationCheck.getMessage();
 
         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, modUsername);
-//        TAdmin modAdmin = adminService.getOne(lqw);
-//        if (Objects.isNull(modAdmin)) {
-//            return R.fail("modAdmin账号不存在");
+//        if (country.equals("中国")) {
+//            if (StringUtils.isEmpty(location)) {
+//                return R.fail("国内省市不能为空");
+//            }
 //        }
 
         LambdaQueryWrapper<TLocationCheck> wrapper = Wrappers.lambdaQuery();
@@ -130,24 +123,16 @@ public class TLocationCheckController {
         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("姓名有误");
-//        }
 
         tLocationCheck.setModifyTime(new Date());
         tLocationCheck.setModName(modName);
 //        tLocationCheck.setModAdminId(modAdminId);
         tLocationCheck.setModPhone(modPhone);
-//        tLocationCheck.setModUsername(modUsername);
+        tLocationCheck.setModUsername(modUsername);
         tLocationCheck.setLocation(location);
         tLocationCheck.setClientId(clientId);
         tLocationCheck.setCountry(country);
+        tLocationCheck.setMessage(message);
 
         locationCheckService.updateById(tLocationCheck);
 
@@ -179,37 +164,17 @@ public class TLocationCheckController {
         if (checks.size() > 0) {
             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账号不存在");
-//        }
-//        Long adminId = admin.getId();
-//        String phone1 = admin.getPhone();
-//        if (!Objects.equals(phone1, phone)) {
-//            return R.fail("手机号码有误");
-//        }
-        // 孙超,黄堪通
-//        String sunPhone = "15546789003";
-//        String huangPhone = "18320396362";
-//        if (!Objects.equals(sunPhone, phone) || !Objects.equals(huangPhone, phone)) {
-//            return R.fail("手机号有误");
-//        }
-//        String name1 = admin.getName();
-        String adminStr = "admin";
-        String sun = "sunchao";
-        String huang = "huangkantong";
-        if (!Objects.equals(sun, username) || !Objects.equals(huang, username) || !Objects.equals(adminStr, username)) {
+
+        Set<String> allowedUsers = new HashSet<>(Arrays.asList("admin", "sunchao", "huangkantong", "shouhou121", "shouhou369", "shouhou397", "shouhoumi"));
+        if (!allowedUsers.contains(username)) {
             return R.fail("该账号无权操作");
         }
 
+
         TLocationCheck tLocationCheck = new TLocationCheck();
-//        String uuid = IdUtil.randomUUID();
         String uuid = IdUtil.simpleUUID();
         tLocationCheck.setId(uuid);
         tLocationCheck.setCreateTime(new Date());
-//        tLocationCheck.setAdminId(adminId);
         tLocationCheck.setPhone(phone);
         tLocationCheck.setUsername(username);
         tLocationCheck.setClientId(clientId);

+ 7 - 7
src/main/java/com/szwl/controller/TParametersController.java

@@ -5,6 +5,7 @@ import cn.com.crbank.ommo.bean.ResultMessage;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage;
+import com.szwl.constant.ResponseCodesEnum;
 import com.szwl.model.bean.CommonParamVo;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
@@ -111,7 +112,7 @@ public class TParametersController {
     public ResponseModel<?> enableMaterial(@RequestBody TParameters parameters) {
         Long equipmentId = parameters.getEquipmentId();
         if (equipmentId == null) {
-            return R.fail("设备id不能为空");
+            return R.fail(ResponseCodesEnum.A0001,"设备id不能为空");
         }
 //        TParameters tParameters = tParametersService.getById(equipmentId);
 //        if (Objects.isNull(tParameters)) {
@@ -125,18 +126,17 @@ public class TParametersController {
             equipmentDescService.saveOrUpdate(tEquipmentDesc);
         } else {
             String isMaterialUse = equipmentDesc.getIsMaterialUse();
-            if (isMaterialUse.equals("1")) {
-                return R.ok("已开启ENABLED");
-            } else {
-                equipmentDesc.setIsMaterialUse("1");
-                equipmentDescService.saveOrUpdate(equipmentDesc);
+            if (StringUtils.isNotEmpty(isMaterialUse) && "1".equals(isMaterialUse)) {
+                return R.ok(ResponseCodesEnum.ALL_OK,"已开启ENABLED");
             }
+            equipmentDesc.setIsMaterialUse("1");
+            equipmentDescService.saveOrUpdate(equipmentDesc);
         }
 
         TEquipment equipment = tEquipmentService.getById(equipmentId);
         tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", "M502" + ":" + "1").toString());
 
-        return R.ok("开启物料监控功能成功SUCCESS");
+        return R.ok(ResponseCodesEnum.ALL_OK,"开启物料监控功能成功SUCCESS");
     }
 
 }

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

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

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

@@ -31,15 +31,16 @@
         <result column="mod_phone" property="modPhone" />
         <result column="mod_username" property="modUsername" />
         <result column="mod_name" property="modName" />
+        <result column="message" property="message" />
     </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, mod_admin_id, mod_phone, mod_username, mod_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, message
     </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, mod_admin_id, mod_phone, mod_username, mod_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, message
         from t_location_check
         where ip is not null
     </select>

+ 4 - 1
src/main/java/com/szwl/model/entity/TLocationCheck.java

@@ -15,7 +15,7 @@ import lombok.EqualsAndHashCode;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-11
+ * @since 2023-12-25
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -103,5 +103,8 @@ public class TLocationCheck implements Serializable {
     @ApiModelProperty(value = "售后部员工姓名")
     private String modName;
 
+    @ApiModelProperty(value = "修改原因")
+    private String message;
+
 
 }

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

@@ -8,11 +8,11 @@ import java.io.IOException;
 
 /**
  * <p>
- * 服务类
+ *  服务类
  * </p>
  *
  * @author wuhs
- * @since 2023-12-11
+ * @since 2023-12-25
  */
 public interface TLocationCheckService extends IService<TLocationCheck> {
 

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

@@ -25,7 +25,7 @@ import java.util.Objects;
  * </p>
  *
  * @author wuhs
- * @since 2023-12-11
+ * @since 2023-12-25
  */
 @Service
 public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper, TLocationCheck> implements TLocationCheckService {
@@ -92,7 +92,7 @@ public class TLocationCheckServiceImpl extends ServiceImpl<TLocationCheckMapper,
         // country 是中国 / 不是中国
         if (StringUtils.isEmpty(location)) {
             if (country.equals("中国")) {
-                return "国内必须精确到省";
+                return "国内必须精确到省";
             } else {
                 containsUserInput = addr.contains(country);
             }

+ 41 - 0
src/test/java/com/szwl/model/utils/usaEquipment/ContainsTest.java

@@ -0,0 +1,41 @@
+package com.szwl.model.utils.usaEquipment;
+
+import org.apache.commons.lang.StringUtils;
+
+public class ContainsTest {
+    public static void main(String[] args) {
+        String addr = "浙江省杭州市 联通";
+        String country = "中国";
+        String location = "浙江省杭州";
+
+        ContainsTest containsTest = new ContainsTest();
+        String s = containsTest.cTest(addr, country, location);
+        System.out.println(s);
+
+    }
+
+    public String cTest(String addr, String country, String 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);
+            }
+        }
+
+        if (!containsUserInput) { // 不包含,返回设备编号
+            return "{" + 111 + "}";
+        }
+
+        return "nih";
+    }
+}