瀏覽代碼

基础模块更新,系统提示语优化合并

linfutong 2 年之前
父節點
當前提交
6a3f636613

+ 2 - 2
zd-common/common-core/src/main/java/com/zd/common/core/aspect/InnerAuthAspect.java

@@ -24,14 +24,14 @@ public class InnerAuthAspect implements Ordered {
         String source = ServletUtils.getRequest().getHeader(SecurityConstants.FROM_SOURCE);
         // 内部请求验证
         if (!StringUtils.equals(SecurityConstants.INNER, source)) {
-            throw new InnerAuthException("没有内部访问权限,不允许访问");
+            throw new InnerAuthException("无权限访问");
         }
 
         String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
         String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME);
         // 用户信息验证
         if (innerAuth.isUser() && (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))) {
-            throw new InnerAuthException("没有设置用户信息,不允许访问 ");
+            throw new InnerAuthException("未知用户,不允许访问");
         }
         return point.proceed();
     }

+ 4 - 4
zd-common/common-core/src/main/java/com/zd/common/core/aspect/ResponseAdvice.java

@@ -2,6 +2,7 @@ package com.zd.common.core.aspect;
 
 import com.zd.model.domain.AjaxResult;
 import com.zd.model.domain.R;
+import com.zd.model.domain.WVPResult;
 import com.zd.model.domain.ResultData;
 import com.zd.model.page.TableDataInfo;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
@@ -12,6 +13,7 @@ import org.springframework.http.server.ServerHttpRequest;
 import org.springframework.http.server.ServerHttpResponse;
 import org.springframework.util.AntPathMatcher;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
+import org.springframework.web.context.request.async.DeferredResult;
 import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
 
 import java.util.Map;
@@ -40,10 +42,8 @@ public class ResponseAdvice implements ResponseBodyAdvice<Object> {
                                   Class<? extends HttpMessageConverter<?>> aClass,
                                   ServerHttpRequest serverHttpRequest,
                                   ServerHttpResponse serverHttpResponse) {
-
-
-        if(o instanceof TableDataInfo || o instanceof AjaxResult || o instanceof ResultData
-                || o instanceof R || o instanceof String){
+        if (o instanceof TableDataInfo || o instanceof AjaxResult || o instanceof ResultData
+                || o instanceof R || o instanceof String || o instanceof Map || o instanceof WVPResult) {
             return o;
         }
 

+ 9 - 6
zd-common/common-core/src/main/java/com/zd/common/core/exception/GlobalExceptionHandler.java

@@ -32,7 +32,7 @@ public class GlobalExceptionHandler {
     public AjaxResult handlePreAuthorizeException(PreAuthorizeException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
-        return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员");
+        return AjaxResult.error(HttpStatus.FORBIDDEN, "无操作权限,请联系管理员");
     }
 
     /**
@@ -63,7 +63,7 @@ public class GlobalExceptionHandler {
     public AjaxResult handleDuplicateKeyException(DuplicateKeyException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',发生主键重复异常.", requestURI, e);
-        return AjaxResult.error("存在重复数据,操作失败!");
+        return AjaxResult.error("数据重复,请修改后再操作!");
     }
 
     /**
@@ -73,7 +73,10 @@ public class GlobalExceptionHandler {
     public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',发生未知异常.", requestURI, e);
-        return AjaxResult.error(e.getMessage());
+        if (e.getCause() != null) {
+            return AjaxResult.error(e.getCause().toString());
+        }
+        return AjaxResult.error(e.toString());
     }
 
     /**
@@ -112,7 +115,7 @@ public class GlobalExceptionHandler {
     @ExceptionHandler(RedisSystemException.class)
     public Object handleRedisSystemException(RedisSystemException e) {
         log.error(e.getMessage(), e);
-        return AjaxResult.error("正在重新连接...请重试!");
+        return AjaxResult.error("正在重新连接,请再次尝试!");
     }
 
     /**
@@ -122,7 +125,7 @@ public class GlobalExceptionHandler {
     public Object MaxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException e) {
         log.error("MaxUploadSizeExceededException: "+ e);
         e.printStackTrace();
-        return AjaxResult.error("上传文件太大!");
+        return AjaxResult.error("上传文件过大,请压缩后再试!");
     }
 
     /**
@@ -146,6 +149,6 @@ public class GlobalExceptionHandler {
      */
     @ExceptionHandler(NoRollException.class)
     public AjaxResult handleNoRollException(NoRollException e) {
-        return AjaxResult.error(e.getMessage());
+        return AjaxResult.error(e.getCode()== null? HttpStatus.ERROR : e.getCode(),e.getMessage());
     }
 }

+ 41 - 2
zd-common/common-core/src/main/java/com/zd/common/core/exception/NoRollException.java

@@ -4,7 +4,46 @@ public class NoRollException extends RuntimeException{
 
     private static final long serialVersionUID = 1L;
 
-    public NoRollException(String msg) {
-        super(msg);
+    /**
+     * 错误码
+     */
+    private Integer code;
+
+    /**
+     * 错误提示
+     */
+    private String message;
+
+    /**
+     * 数量
+     */
+    private Integer count;
+
+    public NoRollException() {
+    }
+
+    public NoRollException(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public NoRollException(Integer code, Integer count, String message) {
+        this.code = code;
+        this.count = count;
+        this.message = message;
     }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    @Override
+    public String getMessage() {
+        return message;
+    }
+
+    public Integer getCount() {
+        return count;
+    }
+
 }

+ 197 - 0
zd-common/common-core/src/main/java/com/zd/common/core/utils/DESUtils.java

@@ -0,0 +1,197 @@
+package com.zd.common.core.utils;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Random;
+
+/**
+ * <p>DES可逆加密</p>
+ *
+ * @author: linft
+ * @date: 2021/3/7
+ * @since:
+ */
+public class DESUtils {
+
+    /**
+     * 随意定一个私钥(长度必须为24位)
+     */
+    private static final String SECRET_KEY = "ABCDEFGHIJKLMN0123456789";
+
+    private static final String INSTANCE_STR = "DESede";
+
+    /**
+     * 加密
+     *
+     * @param inStr 需要加密的内容
+     * @return 加密后的数据
+     */
+
+    public static String encrypt(String inStr) {
+        SecretKey deskey = new SecretKeySpec(SECRET_KEY.getBytes(), INSTANCE_STR);
+        Cipher cipher;
+        String outStr = null;
+        try {
+            cipher = Cipher.getInstance(INSTANCE_STR);
+            cipher.init(Cipher.ENCRYPT_MODE, deskey);
+            outStr = byte2hex(cipher.doFinal(inStr.getBytes()));
+        } catch (Exception e) {
+            System.err.println("3DES加密异常"+ e.getMessage());
+        }
+        return outStr;
+    }
+
+    /**
+     * 解密
+     *
+     * @param inStr  需要解密的内容
+     * @return 解密后的数据
+     */
+    public static String decrypt(String inStr) {
+        SecretKey deskey = new SecretKeySpec(SECRET_KEY.getBytes(), INSTANCE_STR);
+        Cipher cipher;
+        String outStr = null;
+        try {
+            cipher = Cipher.getInstance(INSTANCE_STR);
+            cipher.init(Cipher.DECRYPT_MODE, deskey);
+            outStr = new String(cipher.doFinal(hex2byte(inStr)));
+        } catch (Exception e) {
+            System.err.println("3DES解密异常"+e.getMessage());
+        }
+        return outStr;
+    }
+
+    /**
+     * 转化为16进制字符串方法
+     *
+     * @param digest 需要转换的字节组
+     * @return 转换后的字符串
+     */
+    private static String byte2hex(byte[] digest) {
+        StringBuffer hs = new StringBuffer();
+        String stmp = "";
+        for (int n = 0; n < digest.length; n++) {
+            stmp = Integer.toHexString(digest[n] & 0XFF);
+
+            if (stmp.length() == 1) {
+                hs.append("0" + stmp);
+            } else {
+                hs.append(stmp);
+            }
+        }
+        return hs.toString().toUpperCase();
+    }
+
+    /**
+     * 十六进转二进制
+     *
+     * @param hexStr 待转换16进制字符串
+     * @return 二进制字节组
+     */
+    public static byte[] hex2byte(String hexStr) {
+        if (hexStr == null)
+            return null;
+        hexStr = hexStr.trim();
+        int len = hexStr.length();
+        if (len == 0 || len % 2 == 1)
+            return null;
+        byte[] digest = new byte[len / 2];
+        try {
+            for (int i = 0; i < hexStr.length(); i += 2) {
+                digest[i / 2] = (byte) Integer.decode("0x" + hexStr.substring(i, i + 2)).intValue();
+            }
+            return digest;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public static void main(String[] args) {
+        String data = "05367892";
+        String key = DESUtils.encrypt(data);
+        System.out.println("加密内容="+key);
+        String res = DESUtils.decrypt(key);
+        System.out.println("解密内容="+res);
+        //随机生成八位字符串
+        getRandomNum();
+    }
+
+
+    public static String getRandomNum() {
+        String randomNum = getRandomPassword(8);
+        System.out.println(randomNum);
+        return randomNum;
+    }
+
+
+    /**
+     * 返回随机产生的8位数
+     */
+    public static String getRandomPassword(int len) {
+        String result = makeRandomPassword(len);
+        if (result.matches(".*[a-z]{1,}.*") && result.matches(".*[A-Z]{1,}.*") && result.matches(".*\\d{1,}.*") &&
+                result.matches(".*[~!@#$%^&*\\.?]{1,}.*")) {
+            return result;
+        }
+        result = makeRandomPassword(len);
+        return result;
+    }
+
+    /**
+     * 产生8位随机数
+     *
+     * @param len 长度
+     * @return
+     */
+    public static String makeRandomPassword(int len) {
+        char charr[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
+        StringBuilder sb = new StringBuilder();
+        Random r = new Random();
+        for (int x = 0; x < len; ++x) {
+            sb.append(charr[r.nextInt(charr.length)]);
+        }
+        return sb.toString();
+    }
+
+
+
+    /**
+     * 16进制转换10进制丢0,补全0
+     *
+     * @param cardNum 卡号
+     * @return
+     */
+    public static String completeMissing(String cardNum) {
+        String[] userchar = cardNum.split("");
+        String placeholder = "";
+        for(int i=0;i<userchar.length;i++){
+            if(i==0){
+                if(userchar[i].equals("0")){
+                    placeholder+="0";
+                }else{
+                    break;
+                }
+            }else{
+                if(userchar[i].equals("0")){
+                    placeholder+="0";
+                }else{
+                    break;
+                }
+            }
+        }
+        long num = Long.parseLong(cardNum,16);
+
+        //部分卡16进制没有上报补0,所以这里先统一认为是10位卡处理
+        if((placeholder+num).length()<10){
+            String numstr = "";
+            for(long i=(placeholder+num).length();i<10;i++){
+                numstr += "0";
+            }
+            return numstr+num;
+        }
+
+        return placeholder+num;
+    }
+
+}

+ 13 - 0
zd-common/common-core/src/main/java/com/zd/common/core/utils/SaveUtil.java

@@ -61,4 +61,17 @@ public class SaveUtil {
             o.setDeptId(sysUser.getDept().getDeptId());
         }
     }
+
+    public static void setCommonAttr(BaseEntity o, LoginUser loginUser) {
+        SysUser sysUser = loginUser.getSysUser();
+        //设置创建时间
+        o.setCreateTime(DateUtils.getNowDate());
+        //设置创建人
+        o.setCreateBy(sysUser.getNickName());
+        o.setUserId(sysUser.getUserId());
+        if (sysUser.getDept() != null) {
+            o.setDeptId(sysUser.getDept().getDeptId());
+            o.setDeptName(sysUser.getDept().getDeptName());
+        }
+    }
 }

+ 2 - 5
zd-gateway/src/main/java/com/zd/gateway/filter/AuthFilter.java

@@ -58,17 +58,14 @@ public class AuthFilter implements GlobalFilter, Ordered {
         }
         String userStr = sops.get(getTokenKey(token));
         if (StringUtils.isEmpty(userStr)) {
-            return unauthorizedResponse(exchange, "登录状态已过期");
+            return unauthorizedResponse(exchange, "登录已过期");
         }
         JSONObject cacheObj = JSONObject.parseObject(userStr);
         String userid = cacheObj.getString("userid");
         String username = cacheObj.getString("username");
         if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
-            return unauthorizedResponse(exchange, "令牌验证失败");
+            return unauthorizedResponse(exchange, "账号认证失败");
         }
-
-        // 设置过期时间
-        //redisService.expire(getTokenKey(token), EXPIRE_TIME);
         // 设置用户信息到请求
         addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
         addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);

+ 0 - 2
zd-gateway/src/main/java/com/zd/gateway/filter/ValidateCodeFilter.java

@@ -44,12 +44,10 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
     public GatewayFilter apply(Object config) {
         return (exchange, chain) -> {
             ServerHttpRequest request = exchange.getRequest();
-
             // 非登录/注册请求或验证码关闭,不处理
             if (!containsAnyIgnoreCase(request.getURI().getPath(), VALIDATE_URL) || Boolean.TRUE.equals(!captchaProperties.getEnabled())) {
                 return chain.filter(exchange);
             }
-
             try {
                 String rspStr = resolveBodyFromRequest(request);
                 JSONObject obj = JSON.parseObject(rspStr);

+ 1 - 1
zd-gateway/src/main/java/com/zd/gateway/handler/GatewayExceptionHandler.java

@@ -35,7 +35,7 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
             ResponseStatusException responseStatusException = (ResponseStatusException) ex;
             msg = responseStatusException.getMessage();
         } else {
-            msg = "内部服务器错误";
+            msg = "服务异常,请稍后重试";
         }
         log.error("[网关异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), ex.getMessage());
         return ServletUtils.webFluxResponseWriter(response, msg);

+ 1 - 1
zd-gateway/src/main/java/com/zd/gateway/handler/SentinelFallbackHandler.java

@@ -15,7 +15,7 @@ import reactor.core.publisher.Mono;
  */
 public class SentinelFallbackHandler implements WebExceptionHandler {
     private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange) {
-        return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "请求超过最大数,请稍后再试");
+        return ServletUtils.webFluxResponseWriter(exchange.getResponse(), "当前请求量过大,请稍后再试");
     }
 
     @Override

+ 2 - 2
zd-model/src/main/java/com/zd/model/constant/CacheDevice.java

@@ -10,7 +10,7 @@ public enum CacheDevice {
     /**
      * 老传感器缓存前缀
      */
-    SENSOR_KEY("sensor_fedc_01:", 5 * 60 * 60L),
+    SENSOR_KEY("sensor_fedc_01:", 5 * 60L),
 
     /**
      * 老传感器失效周期
@@ -25,7 +25,7 @@ public enum CacheDevice {
     /**
      * 继电器失效周期
      */
-    RELAY_LIFE("relay_life:", 10 * 60 * 60L),
+    RELAY_LIFE("relay_life:", 10 * 60L),
 
     /**
      * 火灾摄像头前缀

+ 5 - 4
zd-model/src/main/java/com/zd/model/constant/HttpStatus.java

@@ -27,6 +27,11 @@ public interface HttpStatus {
     int NO_CONTENT = 204;
 
     /**
+     * 操作执行成功,但有部分失败数据
+     */
+    int NOT_IMPLEMENTED = 205;
+
+    /**
      * 资源已被移除
      */
     int MOVED_PERM = 301;
@@ -81,8 +86,4 @@ public interface HttpStatus {
      */
     int ERROR = 500;
 
-    /**
-     * 接口未实现
-     */
-    int NOT_IMPLEMENTED = 501;
 }

+ 32 - 0
zd-model/src/main/java/com/zd/model/domain/WVPResult.java

@@ -0,0 +1,32 @@
+package com.zd.model.domain;
+
+public class WVPResult<T> {
+
+    private int code;
+    private String msg;
+    private T data;
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+}

+ 8 - 1
zd-model/src/main/java/com/zd/model/entity/SubQueryConfig.java

@@ -77,7 +77,10 @@ public class SubQueryConfig {
      */
     public static final SubQueryConfig subQueryConfigWran;
 
-
+    /**
+     * 硬件类型集合
+     */
+    public Long[] typeCollection;
 
     static {
 
@@ -202,6 +205,10 @@ public class SubQueryConfig {
         this.conversionDictSubName = conversionDictSubName;
     }
 
+    public Long[] getTypeCollection() {        return typeCollection;    }
+
+    public void setTypeCollection(Long[] typeCollection) {        this.typeCollection = typeCollection;    }
+
     public static enum mode{
         //无权限
         none,

+ 15 - 2
zd-model/src/main/java/com/zd/model/entity/SysUser.java

@@ -189,11 +189,16 @@ public class SysUser extends BaseEntity implements Serializable {
     private String nature;
 
     /**
-     * 卡号
+     * 卡号8位简写
      */
     private String cardNum;
 
     /**
+     * 卡号des加密
+     */
+    private String cardNumSimple;
+
+    /**
      * 微信ID
      */
     private String wechatId;
@@ -370,7 +375,7 @@ public class SysUser extends BaseEntity implements Serializable {
         this.deptId = deptId;
     }
 
-    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
+    @Size(min = 0, max = 50, message = "用户昵称长度不能超过50个字符")
     public String getNickName() {
         return nickName;
     }
@@ -711,4 +716,12 @@ public class SysUser extends BaseEntity implements Serializable {
     public void setDeptIds(List<Long> deptIds) {
         this.deptIds = deptIds;
     }
+
+    public String getCardNumSimple() {
+        return cardNumSimple;
+    }
+
+    public void setCardNumSimple(String cardNumSimple) {
+        this.cardNumSimple = cardNumSimple;
+    }
 }

+ 1 - 0
zd-model/src/main/java/com/zd/model/enums/SenseType.java

@@ -37,6 +37,7 @@ public enum SenseType implements BaseEnum<Integer>, HardwareType {
     COCl2(15, "光气", "光气", "icon_22", "ppm"),
     Cl2(16, "氯气", "氯气", "icon_22", "ppm"),
     HCHO(17, "甲醛", "甲醛", "icon_22", "ppm"),
+    INFRA_RED(18, "红外测温仪", "红外测温仪", "icon_16", "℃"),
     ;
     private Integer code;
     private String name;

+ 1 - 0
zd-model/src/main/java/com/zd/model/enums/WarnMessageTypeEnum.java

@@ -12,6 +12,7 @@ public enum WarnMessageTypeEnum implements BaseEnum<Integer> {
 
     voice(0, "语音" ),
     SMS(1, "短信" ),
+    PHONE(2, "电话" ),
     ;
 
     WarnMessageTypeEnum(Integer code, String name) {