root 2 роки тому
батько
коміт
f9a0f7dd3d

+ 4 - 7
api-common/src/main/java/api/common/util/JsonUtil.java

@@ -85,7 +85,7 @@ public class JsonUtil {
         }
     }
 
-
+    @SuppressWarnings("all")
     public static Map jsonToMap(String json) {
         try {
             return new ObjectMapper().readValue(json, HashMap.class);
@@ -105,7 +105,8 @@ public class JsonUtil {
     }
 
     //泛化用的,把带下划线的json转换为驼峰jsom
-    public static String stringToJson(String ss) throws JsonProcessingException {
+    @SuppressWarnings("unchecked")
+    public static String stringToJson(String ss) {
         Map maps = jsonToMap(ss);
         Map map = new HashMap();
         for (Object obj : maps.keySet()) {
@@ -115,14 +116,10 @@ public class JsonUtil {
         return beanToJson(map);
     }
 
-    private static Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])");
+    private static final Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])");
 
     /**
      * 根据传入的带下划线的字符串转化为驼峰格式
-     *
-     * @param str
-     * @return
-     * @author mrf
      */
 
     public static String underlineToHump(String str) {

+ 18 - 58
api-common/src/main/java/api/common/util/ObjectUtil.java

@@ -7,16 +7,13 @@ import api.common.pojo.po.model.VehiclePO;
 import api.common.pojo.vo.model.VehicleVO;
 import api.common.pojo.vo.system.DictVO;
 import com.fasterxml.jackson.databind.JsonNode;
+import lombok.SneakyThrows;
 import org.springframework.beans.BeanUtils;
 
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.*;
-import java.util.function.BiConsumer;
-import java.util.function.Function;
 
-@SuppressWarnings("all")
 public class ObjectUtil {
 
     /**
@@ -26,19 +23,19 @@ public class ObjectUtil {
         boolean isNullFlag = true;
         if (obj != null) {
             if (obj instanceof List) {
-                isNullFlag = isNull((List) obj);
+                isNullFlag = isNull((List<?>) obj);
             } else if (obj instanceof Set) {
-                isNullFlag = isNull((Set) obj);
+                isNullFlag = isNull((Set<?>) obj);
             } else if (obj instanceof Object[]) {
-                isNullFlag = isNull((Object[]) ((Object[]) obj));
+                isNullFlag = isNull(obj);
             } else if (obj instanceof Map) {
-                isNullFlag = isNull((Map) obj);
+                isNullFlag = isNull((Map<?, ?>) obj);
             } else if (obj instanceof String) {
                 isNullFlag = isNull((String) obj);
             } else if (obj instanceof Integer) {
-                isNullFlag = isNull((Integer) obj);
+                isNullFlag = false;
             } else if (obj instanceof Boolean) {
-                isNullFlag = isNull((Boolean) obj);
+                isNullFlag = false;
             } else if (obj instanceof StringBuffer) {
                 isNullFlag = isNull((StringBuffer) obj);
             } else if (obj instanceof JsonNode) {
@@ -91,7 +88,7 @@ public class ObjectUtil {
     }
 
     public static List<DictVO> DictListToTree(List<DictVO> list) {
-        List<DictVO> treeList = new ArrayList<DictVO>();
+        List<DictVO> treeList = new ArrayList<>();
         for (DictVO dictVO : list) {
             if ("0".equals(dictVO.getPid())) {
                 treeList.add(findChildren(dictVO, list));
@@ -262,60 +259,20 @@ public class ObjectUtil {
         return vehiclePO;
     }
 
-    /**
-     * list转tree结构,
-     *
-     * @param list        List<T>类型数据源
-     * @param rootId      tree的根节点id
-     * @param getId       <T>类型获取id的方法
-     * @param getPid      <T>类型获取父id的方法
-     * @param getChildren <T>类型获取子对象的方法
-     * @param setChildren <T>类型设置子对象的方法
-     * @param <T>         该对象满足父子关系的相关字段:id 和 父id
-     * @param <String>    id的数据类型为String
-     * @return 树形结构的List<T>,多根型
-     */
-    public static <T, String> List<T> listToTree(List<T> list, String rootId, Function<T, String> getId, Function<T, String> getPid, Function<T, List<T>> getChildren, BiConsumer<T, List<T>> setChildren) {
-        List<T> treeList = new ArrayList<T>();
-        for (T node : list) {
-            if (rootId.equals(getPid.apply(node))) {
-                treeList.add(findChildren(node, list, getId, getPid, getChildren, setChildren));
-            }
-        }
-        return treeList;
-    }
-
-    /**
-     * list转tree递归调用
-     */
-    private static <T, String> T findChildren(T parent, List<T> list, Function<T, String> getId, Function<T, String> getPid, Function<T, List<T>> getChildren, BiConsumer<T, List<T>> setChildren) {
-        for (T node : list)
-            if (getId.apply(parent).equals(getPid.apply(node))) {
-                if (getChildren.apply(parent) == null || getChildren.apply(parent).size() == 0) {
-                    setChildren.accept(parent, new ArrayList<T>());
-                }
-                getChildren.apply(parent).add(findChildren(node, list, getId, getPid, getChildren, setChildren));
-            }
-        return parent;
-    }
 
     /**
      * list转tree结构,<T>类型需要在属性上添加注解,标识树形结构:@WId 、@WParentId、 @WChildren;
-     *
-     * @param list
-     * @param <T>
-     * @return
      */
     public static <T> List<T> listToTree(List<T> list) {
         if (isNull(list)) {
-            return new LinkedList<T>();
+            return new LinkedList<>();
         }
         return listToTree(list, "0");
     }
-
+    @SuppressWarnings("unchecked")
     public static <T> List<T> listToTree(List<T> list, String root) {
         try {
-            List<T> treeList = new LinkedList<T>();
+            List<T> treeList = new LinkedList<>();
             Class<?> tClass = null;
             for (T t : list) {
                 tClass = t.getClass();
@@ -346,7 +303,7 @@ public class ObjectUtil {
             }
             //解析列表
             for (T node : list) {
-                if (root.equals((String) getParentId.invoke(node))) {
+                if (root.equals(getParentId.invoke(node))) {
                     treeList.add(findChildren(node, list, getId, getParentId, getChildren, setChildren));
                 }
             }
@@ -360,14 +317,17 @@ public class ObjectUtil {
     /**
      * list转tree递归调用
      */
-    private static <T> T findChildren(T parent, List<T> list, Method getId, Method getParentId, Method getChildren, Method setChildren) throws InvocationTargetException, IllegalAccessException {
+    @SneakyThrows
+    @SuppressWarnings("unchecked")
+    private static <T> T findChildren(T parent, List<T> list, Method getId, Method getParentId, Method getChildren, Method setChildren) {
         for (T node : list) {
             String id = (String) getId.invoke(parent);
             String parentId = (String) getParentId.invoke(node);
             if (id.equals(parentId)) {
-                List<T> children = (List<T>) getChildren.invoke(parent);
+                final Object invoke = getChildren.invoke(parent);
+                List<T> children = (List<T>) invoke;
                 if (ObjectUtil.isNull(children)) {
-                    children = new ArrayList<T>();
+                    children = new ArrayList<>();
                     setChildren.invoke(parent, children);
                 }
                 children.add(findChildren(node, list, getId, getParentId, getChildren, setChildren));

+ 1 - 2
api-common/src/main/java/api/common/util/ParamUtil.java

@@ -12,9 +12,8 @@ public class ParamUtil {
 
     /**
      * 将多级下拉二维数组中的数据,赋值到对应对象的属性中
-     * @param arr
-     * @param object
      */
+    @SuppressWarnings("unchecked")
     public static void arrConvertObj(String[][] arr,Object object) {
         try {
             if(arr == null || arr.length == 0){

+ 1 - 4
simulation-resource-server/src/main/java/com/css/simulation/resource/model/controller/SensorGpsController.java

@@ -84,13 +84,10 @@ public class SensorGpsController {
     @RequestMapping("/shareGps")
     @PreAuthorize("@AuthorityCheck.admin()")
     public ResponseBodyVO<GpsPO> shareGps(@RequestBody GpsPO gpsPO) {
-        if (ObjectUtil.isNull(gpsPO)) {
-            return new ResponseBodyVO(false, 500, "参数必传!", null);
-        }
         ResponseBodyVO<GpsPO> response = new ResponseBodyVO<GpsPO>(ResponseBodyVO.Response.SUCCESS);
         GpsPO po = gpsService.shareGps(gpsPO);
         if (ObjectUtil.isNull(po.getId())) {
-            return new ResponseBodyVO(false, 500, "传感器名称重复!", null);
+            return new ResponseBodyVO<>(false, 500, "传感器名称重复!", null);
         }
         response.setInfo(po);
         return response;

+ 7 - 11
simulation-resource-server/src/main/java/com/css/simulation/resource/model/controller/SensorLidarController.java

@@ -64,12 +64,12 @@ public class SensorLidarController {
     @ResponseBody
     public ResponseBodyVO<LidarPO> saveLidar(@RequestBody LidarPO lidarPO) {
         if (ObjectUtil.isNull(lidarPO)) {
-            return new ResponseBodyVO(false, 500, "参数必传!", null);
+            return new ResponseBodyVO<>(false, 500, "参数必传!", null);
         }
         ResponseBodyVO<LidarPO> response = new ResponseBodyVO<LidarPO>(ResponseBodyVO.Response.SUCCESS);
         LidarPO po = lidarService.saveLidar(lidarPO);
         if (ObjectUtil.isNull(po.getId())) {
-            return new ResponseBodyVO(false, 500, "传感器名称重复!", null);
+            return new ResponseBodyVO<>(false, 500, "传感器名称重复!", null);
         }
         response.setInfo(po);
         return response;
@@ -83,12 +83,12 @@ public class SensorLidarController {
     @PreAuthorize("@AuthorityCheck.admin()")
     public ResponseBodyVO<LidarPO> shareLidar(@RequestBody LidarPO lidarPO) {
         if (ObjectUtil.isNull(lidarPO)) {
-            return new ResponseBodyVO(false, 500, "参数必传!", null);
+            return new ResponseBodyVO<>(false, 500, "参数必传!", null);
         }
         ResponseBodyVO<LidarPO> response = new ResponseBodyVO<LidarPO>(ResponseBodyVO.Response.SUCCESS);
         LidarPO po = lidarService.shareLidar(lidarPO);
         if (ObjectUtil.isNull(po.getId())) {
-            return new ResponseBodyVO(false, 500, "传感器名称重复!", null);
+            return new ResponseBodyVO<>(false, 500, "传感器名称重复!", null);
         }
         response.setInfo(po);
         return response;
@@ -99,12 +99,8 @@ public class SensorLidarController {
      */
     @RequestMapping("/delLidarById")
     @ResponseBody
-    public ResponseBodyVO delLidarById(@RequestBody LidarPO lidarPO) {
-        int i = lidarService.delLidarById(lidarPO);
-        if (i > 0) {
-            return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
-        } else {
-            return new ResponseBodyVO(false, 500, "删除失败!", null);
-        }
+    public ResponseBodyVO<Void> delLidarById(@RequestBody LidarPO lidarPO) {
+        lidarService.delLidarById(lidarPO);
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
     }
 }

+ 8 - 8
simulation-resource-server/src/main/java/com/css/simulation/resource/model/service/GpsService.java

@@ -42,9 +42,9 @@ public class GpsService {
         gpsParam.setCreateUserId(AuthUtil.getCurrentUserId());
         gpsParam.setShare(null);
         List<GpsVO> gpsList = gpsMapper.getGpsList(gpsParam);
-        gpsList.forEach(gps-> {
-            if("1".equals(gps.getShare()) ){
-                gps.setSensorName(gps.getSensorName()+"(公有)");
+        gpsList.forEach(gps -> {
+            if ("1".equals(gps.getShare())) {
+                gps.setSensorName(gps.getSensorName() + "(公有)");
             }
         });
         return gpsList;
@@ -60,17 +60,17 @@ public class GpsService {
         gpsPO.setShare(DictConstants.NO);//私有
         //名称校验
         List<GpsVO> list = gpsMapper.checkGpsName(gpsPO);
-        if(ObjectUtil.isNotNull(list)){
+        if (ObjectUtil.isNotNull(list)) {
             gpsPO.setId(null);
             return gpsPO;
         }
         String id = gpsPO.getId();
-        if(ObjectUtil.isNull(id)){//新增
+        if (ObjectUtil.isNull(id)) {//新增
             gpsPO.setId(StringUtil.getRandomUUID());
             gpsPO.setSensorCode(StringUtil.getRandomCode());
             gpsMapper.insert(gpsPO);
             LogUtil.insert();
-        }else{//修改
+        } else {//修改
             gpsMapper.update(gpsPO);
             LogUtil.update();
         }
@@ -84,7 +84,7 @@ public class GpsService {
         gpsPO.setCreateUserId(null);
         //名称校验
         List<GpsVO> list = gpsMapper.checkGpsName(gpsPO);
-        if(ObjectUtil.isNotNull(list)){
+        if (ObjectUtil.isNotNull(list)) {
             String currentUserId = AuthUtil.getCurrentUserId();
             Timestamp currentTime = TimeUtil.getNowForMysql();
             gpsPO.setId(list.get(0).getId());
@@ -92,7 +92,7 @@ public class GpsService {
             gpsPO.setModifyTime(currentTime);
             gpsMapper.update(gpsPO);
             LogUtil.update();
-        }else {
+        } else {
             //常规字段赋值
             PoUtil.initAddPo(gpsPO);
             gpsPO.setId(StringUtil.getRandomUUID());

+ 4 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/system/service/DictService.java

@@ -56,7 +56,7 @@ public class DictService {
             listParameter.setValue(dictList);
             dictLists.add(listParameter);
             //map 字典
-            Map<String, String> map = new HashMap();
+            Map<String, String> map = new HashMap<>();
             for (DictVO dictVO : dictVOS) {
                 String code = dictVO.getDictCode();
                 String name = dictVO.getDictName();
@@ -114,6 +114,7 @@ public class DictService {
         return dictTrees;
     }
 
+    @SuppressWarnings("all")
     public Map<String, Map<String, String>> getDictMapsByTypes(DictParam param) {
         //解析参数进行查询
         String dictTypes = param.getDictTypes();
@@ -139,10 +140,10 @@ public class DictService {
     }
 
     public Map<String, Map<String, String>> getDictMapsByTypes(String param, String... arg) {
-        StringBuffer sb = new StringBuffer(param);
+        StringBuilder sb = new StringBuilder(param);
         if (arg != null) {
             for (String s : arg) {
-                if (s != null && s != "") {
+                if (s != null && !s.equals("")) {
                     sb.append(",").append(s);
                 }
             }

+ 6 - 0
simulation-resource-sms/pom.xml

@@ -86,12 +86,18 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.css</groupId>
+            <artifactId>api-common</artifactId>
+            <version>1.0</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot.version}</version>
                 <configuration>
                     <fork>true</fork>
                     <addResources>true</addResources>

+ 1 - 1
simulation-resource-sms/src/main/java/com/css/simulation/resource/sms/consumer/SmsConsumer.java

@@ -1,8 +1,8 @@
 package com.css.simulation.resource.sms.consumer;
 
 
+import api.common.util.JsonUtil;
 import com.css.simulation.resource.sms.pojo.dto.SmsDTO;
-import com.css.simulation.resource.sms.util.JsonUtil;
 import com.css.simulation.resource.sms.util.TencentSMSUtil;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;

+ 0 - 115
simulation-resource-sms/src/main/java/com/css/simulation/resource/sms/util/JsonUtil.java

@@ -1,115 +0,0 @@
-package com.css.simulation.resource.sms.util;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.TextNode;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-@SuppressWarnings("all")
-public class JsonUtil {
-
-    private static final ObjectMapper mapper = new ObjectMapper();
-
-
-    /**
-     * bean 转成 json
-     *
-     * @param bean bean 对象
-     * @param <T>  声明为泛型方法
-     * @return json 字符串
-     * @throws JsonProcessingException 异常
-     */
-    public static <T> String beanToJson(T bean) throws JsonProcessingException {
-        return new ObjectMapper().writeValueAsString(bean);
-    }
-
-    /**
-     * json 转成 bean
-     *
-     * @param json   json 字符串
-     * @param tClass 返回值类型
-     * @param <T>    声明为泛型方法
-     * @return bean 对象
-     * @throws JsonProcessingException 异常
-     */
-    public static <T> T jsonToBean(String json, Class<T> tClass) throws JsonProcessingException {
-        return new ObjectMapper().readValue(json, tClass);
-    }
-
-    /**
-     * bean 转成 json
-     *
-     * @param list 列表对象
-     * @param <T>  声明为泛型方法
-     * @return json 字符串
-     * @throws JsonProcessingException 异常
-     */
-    public static <T> String listToJson(T list) throws JsonProcessingException {
-        return new ObjectMapper().writeValueAsString(list);
-    }
-
-
-    public static Map jsonToMap(String json) {
-        try {
-            return new ObjectMapper().readValue(json, HashMap.class);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return new HashMap();
-    }
-
-    public static JsonNode readTree(String json) {
-        try {
-            return mapper.readTree(json);
-        } catch (JsonProcessingException e) {
-            e.printStackTrace();
-        }
-        return new TextNode("");
-    }
-
-//泛化用的,把带下划线的json转换为驼峰jsom
-    public static String  stringToJson(String ss) throws JsonProcessingException {
-        Map maps = jsonToMap(ss);
-        Map map = new HashMap();
-        for (Object obj : maps.keySet()) {
-            String value = underlineToHump(obj.toString());
-            map.put(value, maps.get(obj));
-        }
-       return beanToJson(map);
-    }
-
-    private static Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])");
-
-    /**
-     * 根据传入的带下划线的字符串转化为驼峰格式
-     *
-     * @param str
-     * @return
-     * @author mrf
-     */
-
-    public static String underlineToHump(String str) {
-        //正则匹配下划线及后一个字符,删除下划线并将匹配的字符转成大写
-        Matcher matcher = UNDERLINE_PATTERN.matcher(str);
-        StringBuffer sb = new StringBuffer(str);
-        if (matcher.find()) {
-            sb = new StringBuffer();
-            //将当前匹配的子串替换成指定字符串,并且将替换后的子串及之前到上次匹配的子串之后的字符串添加到StringBuffer对象中
-            //正则之前的字符和被替换的字符
-            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
-            //把之后的字符串也添加到StringBuffer对象中
-            matcher.appendTail(sb);
-        } else {
-            //去除除字母之外的前面带的下划线
-            return sb.toString().replaceAll("_", "");
-        }
-        return underlineToHump(sb.toString());
-    }
-
-}
-