Browse Source

Merge branch 'develop-v3.0.0' of http://39.106.8.246:3003/FM-dev/fm-basics into develop-v3.0.0

lixing 3 years ago
parent
commit
66161d560b

+ 59 - 0
fm-common/src/main/java/com/persagy/fm/common/constant/enums/ObjTagEnum.java

@@ -0,0 +1,59 @@
+package com.persagy.fm.common.constant.enums;
+/***
+ * Description: 物理世界对象的tag
+ * @author : lijie
+ * @date :2021/4/2 9:54
+ * Update By lijie 2021/4/2 9:54
+ */
+public enum ObjTagEnum {
+    /**项目*/
+    PROJECT("Pj","项目"),
+    /**建筑*/
+    BUILD("Bd","建筑"),
+    /**楼层*/
+    FLOOR("Fl","楼层"),
+    /**空间*/
+    SPACE("Sp","空间"),
+    /**系统*/
+    SYSTEM("Sy","系统"),
+    /**竖井*/
+    SHAFT("shaft","竖井"),
+    /**设备*/
+    EQUIP("Eq","设备"),
+    /**设备对象*/
+    EQUIP_OBJECT("EqObj","设备对象"),
+    /**设备对象*/
+    SYSTEM_OBJECT("SyObj","系统对象"),
+    /**设备类*/
+    EQUIP_CLASS("equip_class","设备类"),
+    /**设备字典-专业*/
+    DICT_CLASS("Clazz","设备字典-专业"),
+    /**设备字典-系统*/
+    DICT_SYSTEM("System","设备字典-系统"),
+    /**设备字典-设备*/
+    DICT_EQUIP("Equip","设备字典-设备");
+
+    ObjTagEnum(String type, String describe) {
+        this.type = type;
+        this.describe = describe;
+    }
+
+    private String type;
+    private String describe;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getDescribe() {
+        return describe;
+    }
+
+    public void setDescribe(String describe) {
+        this.describe = describe;
+    }
+}

+ 45 - 0
fm-common/src/main/java/com/persagy/fm/common/constant/enums/ResultEnum.java

@@ -0,0 +1,45 @@
+package com.persagy.fm.common.constant.enums;
+/***
+ * Description: 结果枚举
+ * @author : lijie
+ * @date :2021/4/2 18:19
+ * Update By lijie 2021/4/2 18:19
+ */
+public enum ResultEnum {
+    /**Result*/
+    RESULT("Result","结果key"),
+    /**success-成功*/
+    SUCCESS("success","成功"),
+    /**failure-失败*/
+    FAILURE("failure","失败"),
+    /**ResultMsg-错误消息*/
+    RESULT_MSG("ResultMsg","错误消息"),
+    /**内容数组*/
+    CONTENT("Content","内容数组"),
+    /**总数*/
+    COUNT("Count","总数");
+
+    ResultEnum(String type, String describe) {
+        this.type = type;
+        this.describe = describe;
+    }
+
+    private String type;
+    private String describe;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getDescribe() {
+        return describe;
+    }
+
+    public void setDescribe(String describe) {
+        this.describe = describe;
+    }
+}

+ 30 - 0
fm-common/src/main/java/com/persagy/fm/common/model/vo/BaseVo.java

@@ -0,0 +1,30 @@
+package com.persagy.fm.common.model.vo;
+
+import com.fasterxml.jackson.annotation.JsonAlias;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotBlank;
+/***
+ * Description: VO基类
+ * @author : lijie
+ * @date :2021/4/10 14:02
+ * Update By lijie 2021/4/10 14:02
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class BaseVo {
+    /**用户id*/
+    @ApiModelProperty(value = "账号id",required = true)
+    @NotBlank(message = "缺少非空项:user_id")
+    @JsonProperty("user_id")
+    @JsonAlias({"user_id","userId","accountId","account_id"})
+    private String userId;
+
+}

+ 159 - 0
fm-common/src/main/java/com/persagy/fm/common/old/utils/StringUtil.java

@@ -0,0 +1,159 @@
+package com.persagy.fm.common.old.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+/***
+ * Description: 老的自定义字符串的工具类
+ * @author : lijie
+ * @date :2021/4/26 18:41
+ * Update By lijie 2021/4/26 18:41
+ */
+@SuppressWarnings("unchecked")
+public class StringUtil {
+	/***
+	 * Description: 判断数组中的字段是否为null
+	 * @param lackFields : 满足条件的字段数组
+     * @param jsonObject : 校验的对象
+     * @param params : 校验的key
+	 * @return : boolean
+	 * @author : lijie
+	 * @date :2021/4/26 18:41
+	 * Update By lijie 2021/4/26 18:41
+	 */
+	public static boolean isNull(JSONArray lackFields, JSONObject jsonObject, String... params){
+		lackFields = lackFields == null ? new JSONArray() : lackFields;
+		if(null == jsonObject){
+            return false;
+        }
+		Object value;
+		boolean flag = false;
+		for(String param : params){
+			value = jsonObject.get(param);
+			if(value instanceof JSONObject){
+				if(((JSONObject)value).isEmpty()){
+					flag = true;
+					if(!lackFields.contains(param)){
+                        lackFields.add(param);
+                    }
+				}
+			}else if(value instanceof JSONArray){
+				if(((JSONArray)value).isEmpty()){
+					flag = true;
+					if(!lackFields.contains(param)){
+                        lackFields.add(param);
+                    }
+				}
+			}else{
+				if(null == value || "".equals(JSON.toJSON(value))){
+					flag = true;
+					if(!lackFields.contains(param)){
+                        lackFields.add(param);
+                    }
+				}
+			}
+		}
+		return flag;
+	}
+	/***
+	 * Description: 判断对象里是否存在该key
+	 * @param lackFields : 存储结果key的数组
+     * @param jsonObject : 校验的对象
+     * @param params : 校验的key
+	 * @return : boolean
+	 * @author : lijie
+	 * @date :2021/4/26 18:46
+	 * Update By lijie 2021/4/26 18:46
+	 */
+	public static boolean isExist(JSONArray lackFields, JSONObject jsonObject, String... params){
+		lackFields = lackFields == null ? new JSONArray() : lackFields;
+		if(jsonObject == null){
+            return false;
+        }
+		Object value;
+		boolean flag = false;
+		for(String param : params){
+			value = jsonObject.get(param);
+			if(value instanceof JSONObject){
+				if(((JSONObject)value).isEmpty()){
+					if(!lackFields.contains(param)){
+                        lackFields.add(param);
+                    }
+				}else{
+					flag = true;
+				}
+			}else if(value instanceof JSONArray){
+				if(((JSONArray)value).isEmpty()){
+					if(!lackFields.contains(param)){
+                        lackFields.add(param);
+                    }
+				}else{
+					flag = true;
+				}
+			}else{
+				if(value == null || "".equals(JSON.toJSON(value))){
+					if(!lackFields.contains(param)){
+                        lackFields.add(param);
+                    }
+				}else{
+					flag = true;
+				}
+			}
+		}
+		return flag;
+	}
+	
+    /**
+     * 判断String是否为null或空
+     * @param params:校验的参数
+     * @return
+     */
+    public static boolean isNull(String... params){
+        for(String param : params){
+            if(param == null || "".equals(param)){
+                return true;
+            }
+        }
+        return false;
+    }
+    /**
+     * 判断String是否为null或空
+     * @param params
+     * @return
+     */
+    public static boolean isNotNull(String... params){
+        return !isNull(params);
+    }
+    /**
+     * 判断JSONObects是否包含parmas中的字段
+     * @param jsonObject
+     * @param params
+     * @return
+     */
+    public static boolean isNull(JSONObject jsonObject, String... params){
+        for(String param : params){
+            if(isNull(jsonObject.getString(param))){
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 判断JSONObect中时候包含parmas中字段的为空数组
+     * @param jsonObject
+     * @param params
+     * @return
+     */
+    public static boolean isEmptyList(JSONObject jsonObject, String... params){
+        JSONArray jsonArray;
+        for(String param : params){
+            jsonArray = jsonObject.getJSONArray(param);
+            if(jsonArray == null || jsonArray.isEmpty()){
+                return true;
+            }
+        }
+        return false;
+    }
+}

+ 273 - 0
fm-common/src/main/java/com/persagy/fm/common/old/utils/ToolsUtil.java

@@ -0,0 +1,273 @@
+/**
+ * @包名称 com.sagacloud.common
+ * @文件名 ToolsUtil.java
+ * @创建者 wanghailong
+ * @邮箱 wanghailong@persagy.com  
+ * @修改描述 
+ */
+
+package com.persagy.fm.common.old.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.persagy.fm.common.constant.enums.ResultEnum;
+import sun.misc.BASE64Encoder;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+import java.util.stream.Stream;
+
+
+/** 
+ * 功能描述: 常用工具方法
+ * @类型名称 ToolsUtil
+ * @创建者 wanghailong
+ * @邮箱 wanghailong@persagy.com  
+ * @修改描述 
+ */
+public class ToolsUtil {
+    //返回项-缺少必填项
+    public final static String return_error_json = "{\"Result\":\"failure\",\"ResultMsg\":\"缺少必填项\"}";
+    public static String errorJsonMsg(String msg) {
+        JSONObject jsonRes = new JSONObject();
+		jsonRes.put("Result", "failure");
+		jsonRes.put("ResultMsg", msg);
+		return jsonRes.toString();
+    }
+    public static String errorJsonMsg(JSONObject item){
+        JSONObject jsonRes = new JSONObject();
+        jsonRes.put("Result", "failure");
+        jsonRes.put("Item", item);
+        return jsonRes.toJSONString();
+    }
+    
+    public static String successJsonMsg(JSONArray array){
+        JSONObject jsonRes = new JSONObject();
+        jsonRes.put("Result", "success");
+        jsonRes.put("Content", array);
+        jsonRes.put("Count", array.size());
+        return jsonRes.toJSONString();
+    }
+    public static <T> String successJsonMsg(List<T> array){
+        JSONObject jsonRes = new JSONObject();
+        jsonRes.put("Result", "success");
+        jsonRes.put("Content", array);
+        jsonRes.put("Count", array.size());
+        return jsonRes.toJSONString();
+    }
+
+    public static String successJsonMsg(JSONObject item){
+        JSONObject jsonRes = new JSONObject();
+        jsonRes.put("Result", "success");
+        jsonRes.put("Item", item);
+        return jsonRes.toJSONString();
+    }
+
+    public static String successJsonMsg(String successMsg){
+        JSONObject jsonRes = new JSONObject();
+        jsonRes.put("Result", "success");
+        jsonRes.put("ResultMsg", successMsg);
+        return jsonRes.toJSONString();
+    }
+
+
+    public static String getUuid() {
+    	String uuid = UUID.randomUUID().toString().replace("-","");
+    	return uuid;
+    }
+
+    /**
+     * 生成前缀+uuid的字符串
+     * @param prefix  --前缀字符串
+     * @return recordId --prefix+uuid(去除-)
+     */
+	public static String getRecordId(String prefix) {
+		String recordId = "";
+		if (!StringUtil.isNull(prefix)) {
+			recordId = prefix;
+		}
+		recordId = recordId + UUID.randomUUID().toString().replace("-", "");
+		return recordId;
+	}
+    /**
+     * 倒序排序
+     * @param array
+     * @return
+     */
+    public static JSONArray sortDesc(JSONArray array){
+        JSONArray newArray = new JSONArray();
+        for(int i=array.size()-1; i>-1; i--){
+            newArray.add(array.get(i));
+        }
+        return newArray;
+    }
+
+    /**
+     * 根据条件过滤数组字段
+     * @param array
+     * @param filterCondition
+     * @return
+     */
+    public static JSONArray filterRemind(JSONArray array, JSONArray filterCondition){
+        JSONArray newArray = new JSONArray();
+        JSONObject item, newItem;
+        if(array != null){
+            for(int i=0; i<array.size(); i++){
+                item = array.getJSONObject(i);
+                newItem = new JSONObject();
+                for(int j=0; j<filterCondition.size(); j++){
+                    newItem.put(filterCondition.getString(j), item.get(filterCondition.getString(j)));
+                }
+                newArray.add(newItem);
+            }
+        }
+        return newArray;
+    }
+    /**
+     * 根据条件过滤数组字段
+     * @param filterCondition
+     * @return
+     */
+    public static JSONObject filterRemind(JSONObject jsonObject, JSONArray filterCondition){
+    	JSONObject newItem = new JSONObject();
+    	if(jsonObject != null){
+			for(int j=0; j<filterCondition.size(); j++){
+				newItem.put(filterCondition.getString(j), jsonObject.get(filterCondition.getString(j)));
+			}
+    	}
+    	return newItem;
+    }
+    /**
+     * 根据条件过滤数组字段
+     * @param array
+     * @param filterConditions
+     * @return
+     */
+    public static JSONArray filterRemind(JSONArray array, String... filterConditions){
+    	JSONArray newArray = new JSONArray();
+    	JSONObject item, newItem;
+    	if(array != null){
+    		for(int i=0; i<array.size(); i++){
+    			item = array.getJSONObject(i);
+    			newItem = new JSONObject();
+    			for(String filterCondition : filterConditions){
+    				newItem.put(filterCondition, item.get(filterCondition));
+    			}
+    			newArray.add(newItem);
+    		}
+    	}
+    	return newArray;
+    }
+    /**
+     * 根据条件过滤数组字段
+     * @param queryResult
+     * @param filterConditions
+     * @return
+     */
+    public static String filterRemind(String queryResult, String... filterConditions){
+    	if(queryResult.contains(ResultEnum.RESULT.getType()) && queryResult.contains(ResultEnum.CONTENT.getType())) {
+    		JSONObject resultJson = JSONObject.parseObject(queryResult);
+			JSONArray contents = resultJson.getJSONArray(ResultEnum.CONTENT.getType());
+			contents = filterRemind(contents, filterConditions);
+			resultJson.put(ResultEnum.CONTENT.getType(), contents);
+			queryResult = JSON.toJSONString(resultJson);
+    	}
+    	return queryResult;
+    }
+    /**
+     * 根据条件过滤数组字段
+     * @param queryResult
+     * @param filterCondition
+     * @return
+     */
+    public static String filterRemind(String queryResult, JSONArray filterCondition){
+    	if(queryResult.contains(ResultEnum.RESULT.getType()) && queryResult.contains(ResultEnum.CONTENT.getType())) {
+    		JSONObject resultJson = JSONObject.parseObject(queryResult);
+    		JSONArray contents = resultJson.getJSONArray(ResultEnum.CONTENT.getType());
+    		contents = filterRemind(contents, filterCondition);
+    		resultJson.put(ResultEnum.CONTENT.getType(), contents);
+    		queryResult = JSON.toJSONString(resultJson);
+    	}
+    	return queryResult;
+    }
+
+    /**
+     * MD5加密
+     * @param str
+     * @return
+     * @throws NoSuchAlgorithmException
+     * @throws UnsupportedEncodingException
+     */
+    public static String encodeByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
+        //确定计算方法
+        MessageDigest md5= MessageDigest.getInstance("MD5");
+        BASE64Encoder base64en = new BASE64Encoder();
+        //加密后的字符串
+        String newstr=base64en.encode(md5.digest(str.getBytes("utf-8")));
+        return newstr;
+    }
+    
+    /**
+     * 根据map的value排序 倒序
+     * @param map
+     * @param <K>
+     * @return
+     */
+    public static <K> JSONArray sortMapByValue(Map<K, Integer> map){
+        JSONArray array = new JSONArray();
+        Stream<Map.Entry<K, Integer>> stream = map.entrySet().stream();
+        stream.sorted(Comparator.comparing(e -> Integer.valueOf(e.getValue()) * -1)).forEach(e -> array.add(e.getKey()));
+        return array;
+    }
+    
+    
+    /**
+     * 
+     * Description: ZillionAgent返回结果是否成功
+     * @param resultStr:结果字符串
+     * @return boolean
+     * @author yuecaipu
+     * @since 2018年7月9日: 下午12:20:22
+     * Update By yuecaipu 2018年7月9日: 下午12:20:22
+     */
+    public static boolean isSuccessForResult(String resultStr) {
+		JSONObject resultJson = JSONObject.parseObject(resultStr);
+		return isSuccessForResult(resultJson);
+	}
+    /***
+     * Description: 结果是否成功
+     * @param resultJson : 结果对象
+     * @return : boolean
+     * @author : lijie
+     * @date :2021/4/26 18:50
+     * Update By lijie 2021/4/26 18:50
+     */
+    public static boolean isSuccessForResult(JSONObject resultJson) {
+		String result = resultJson.getString(ResultEnum.RESULT.getType());
+		if (ResultEnum.SUCCESS.getType().equals(result)) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Description: 获取一个key升序排序的map
+	 * @return Map<String,JSONArray>
+	 * @author yuecaipu
+	 * @since 2018年7月26日: 下午1:35:01
+	 * Update By yuecaipu 2018年7月26日: 下午1:35:01
+	 */
+	public static Map<String, JSONArray> getAscMap(){
+		 Map<String, JSONArray> map = new TreeMap<String, JSONArray>(
+                 (obj1, obj2) -> {
+                     // 升序排序
+                     Integer order1 = Integer.valueOf(obj1);
+                     Integer order2 = Integer.valueOf(obj2);
+                     return order1.compareTo(order2);
+                 });
+		 return map;
+	}
+ }

+ 38 - 0
fm-common/src/main/java/com/persagy/fm/common/utils/DmpUpsertResultUtil.java

@@ -0,0 +1,38 @@
+package com.persagy.fm.common.utils;
+
+import com.persagy.fm.common.response.FmDmpResponseUtil;
+import com.persagy.fm.common.response.FmResponseItem;
+import com.persagy.fm.common.response.FmResponseUpsertVO;
+
+/**
+ * @description:
+ * @author: lixing
+ * @company: Persagy Technology Co.,Ltd
+ * @since: 2021/3/10 11:27 上午
+ * @version: V1.0
+ **/
+public class DmpUpsertResultUtil {
+    /**
+     * @description: 处理数据中台创建或更新结果
+     * @param: dmpUpsertResult
+     * @param: id
+     * @param: dmpInterfaceName
+     * @return: com.persagy.fm.common.response.FmResponseItem<com.persagy.fm.person.model.dto.department.ResponseDepartmentItemVO>
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2021/3/10 11:26 上午
+     * @version: V1.0
+     */
+//    public static FmResponseItem<FmResponseUpsertVO> dealDmpUpsertResult(
+//            String dmpUpsertResult, Long id, String dmpInterfaceName) {
+//        // 处理数据中台返回结果
+//        if (FmDmpResponseUtil.isSuccess(dmpUpsertResult)) {
+//            FmResponseUpsertVO fmResponseUpsertVO = new FmResponseUpsertVO();
+//            fmResponseUpsertVO.setId(id);
+//            return FmResponseUtil.successItem(fmResponseUpsertVO);
+//        } else {
+//            throw DmpExceptionUtil.rpcException(dmpInterfaceName);
+//        }
+//    }
+}

+ 46 - 0
fm-mybatis/src/main/java/com/persagy/fm/mybatis/handler/DbJsonTypeHandler.java

@@ -0,0 +1,46 @@
+package com.persagy.fm.mybatis.handler;
+
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+import org.springframework.util.Assert;
+/***
+ * Description: 针对mysql中json类型与Model映射处理器.用于处理集合的泛型不是String类型的
+ * @author : lijie
+ * @date :2021/4/27 15:18
+ * Update By lijie 2021/4/27 15:18
+ */
+@Slf4j
+@MappedTypes({ Object.class })
+@MappedJdbcTypes(JdbcType.VARCHAR)
+public class DbJsonTypeHandler extends AbstractJsonTypeHandler<Object> {
+
+    private final Class<?> clazz;
+
+    public DbJsonTypeHandler(Class<?> type, Class<?> innerType) {
+        if (log.isTraceEnabled()) {
+            log.trace("JacksonTypeHandler(" + type + ")");
+        }
+        Assert.notNull(type, "Type argument cannot be null");
+
+        this.clazz = innerType;
+    }
+
+    @Override
+    protected Object parse(String json) {
+        if (JSONUtil.isJsonArray(json)) {
+            return JSONUtil.toList(JSONUtil.parseArray(json), this.clazz);
+        } else {
+            return JSONUtil.toBean(json, this.clazz);
+        }
+    }
+
+    @Override
+    protected String toJson(Object obj) {
+        return JSONUtil.toJsonStr(obj);
+    }
+
+}