diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java index 1df41d92ae..12720182f5 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java @@ -74,7 +74,15 @@ public abstract class BaseRequestLogAspect { transactionSerial, requestURI, method, objectsToString(args), requestHeaders); result = point.proceed(); resultInfoLog(transactionSerial, getExecPeriod(startTime), result); - } catch (RenException e) { + } catch (EpmetException e) { + result = handleRenException(e); + if (e.getCode() > 8000) { + resultWarnLog(transactionSerial, getExecPeriod(startTime), result, e.getInternalMsg(), ExceptionUtils.getErrorStackTrace(e)); + } else { + resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getInternalMsg(), ExceptionUtils.getErrorStackTrace(e)); + } + return result; + } catch (RenException e) { result = handleRenException(e); if (e.getCode() > 8000) { resultWarnLog(transactionSerial, getExecPeriod(startTime), result, e.getInternalMsg(), ExceptionUtils.getErrorStackTrace(e)); @@ -237,6 +245,31 @@ public abstract class BaseRequestLogAspect { return result; } + /** + * 处理EpmetException + * @param e + * @return + */ + private Result handleRenException(EpmetException e) { + if (e.getCode() > 8000) { + Result result; + if (StringUtils.isNotBlank(e.getMsg())) { + // 抛出异常的时候填写了自定义显示信息,把显示信息返回 + result = new Result().error(e.getCode(), e.getMsg()); + } else { + // 没有填写显示信息,则根据code找固定的显示信息 + result = new Result().error(e.getCode()); + } + result.setInternalMsg(e.getInternalMsg()); + return result; + } + // 转化成服务器开小差... + Result result=new Result().error(); + result.setInternalMsg(e.getInternalMsg()); + //result.setMsg(e.getMsg()); + return result; + } + /** * 将请求对象转换为String * @param args diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index a63db7b080..25d5d46ba2 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -7,6 +7,9 @@ package com.epmet.commons.tools.exception; */ public enum EpmetErrorCode { + /** + * 错误code及消息 + */ ERR10002( 10002,"数据库中已存在该记录"), /** * 账号或密码错误ACCOUNT_NOT_EXIST @@ -248,11 +251,13 @@ public enum EpmetErrorCode { ORG_ADD_FAILED(8919,"添加失败"), ORG_EDIT_FAILED(8920,"编辑失败"), ORG_DEL_FAILED(8921,"删除失败"), - //通用的 错误消息自己定义返回 - OPERATION_FAILED(9999,"网络开小差。。。"), - ; + //通用错误码 start + //通用的 错误消息自己定义返回 + EPMET_COMMON_OPERATION_FAIL(9999,"网络开小差..."), + //通用错误码 end + ; private int code; private String msg; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetException.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetException.java new file mode 100644 index 0000000000..6ce29315ba --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetException.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + *
+ * https://www.renren.io + *
+ * 版权所有,侵权必究!
+ */
+
+package com.epmet.commons.tools.exception;
+
+
+import com.epmet.commons.tools.constant.StrConstant;
+import com.epmet.commons.tools.utils.MessageUtils;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Epmet产品 自定义异常
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+public class EpmetException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+    /**
+     * desc:错误码
+     */
+    protected int code;
+    /**
+     * 显示给客户的消息
+     */
+    protected String msg;
+    /**
+     * 内部消息,用于服务之间传递错误信息,排错用
+     */
+    protected String internalMsg;
+
+    /**
+     * desc:指定错误码异常 外部异常内容为错误码对应的异常
+     * @param code
+     */
+    public EpmetException(int code) {
+        this(code, StrConstant.EPMETY_STR);
+    }
+
+    /**
+     * desc:指定内部错误消息的异常 外部异常内容为错误码对应的异常
+     * @param code
+     * @param internalMsg
+     */
+    public EpmetException(int code, String internalMsg) {
+        super(internalMsg);
+        this.code = code;
+        if (StringUtils.isBlank(internalMsg)) {
+            this.internalMsg = EpmetErrorCode.getMsg(code);
+            if (StringUtils.isBlank(this.internalMsg)) {
+                this.internalMsg = MessageUtils.getMessage(code, internalMsg);
+            }
+        } else {
+            this.internalMsg = internalMsg;
+        }
+    }
+
+    /**
+     * desc:指定错误码 内外部错误消息异常
+     * @param code
+     * @param internalMsg
+     * @param externalMsg
+     */
+    public EpmetException(int code, String internalMsg, String externalMsg) {
+        this(code, internalMsg);
+        this.msg = externalMsg;
+    }
+
+    /**
+     * desc:指定内部消息异常 外部错误码及消息为8000,服务器开小差
+     * @param internalMsg
+     */
+    public EpmetException(String internalMsg) {
+        super(internalMsg);
+        this.code = EpmetErrorCode.SERVER_ERROR.getCode();
+        this.internalMsg = internalMsg;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public String getInternalMsg() {
+        return internalMsg;
+    }
+}
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java
index 73ae4bf6b5..ee1d4da142 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/RenException.java
@@ -35,11 +35,12 @@ public class RenException extends RuntimeException {
      * 内部消息,用于服务之间传递错误信息,排错用
      */
     private String internalMsg;
-
+    @Deprecated  //已废弃 被EpmetException替代
     public RenException(int code) {
         this(code, "");
     }
 
+    @Deprecated  //已废弃 被EpmetException替代
     public RenException(int code, String internalMsg) {
         super(internalMsg);
         this.code = code;
@@ -53,11 +54,13 @@ public class RenException extends RuntimeException {
         }
     }
 
+    @Deprecated  //已废弃 被EpmetException替代
     public RenException(int code, String internalMsg, String msg, MessageMode mode) {
         this(code, internalMsg);
         this.msg = msg;
     }
 
+    @Deprecated  //已废弃 被EpmetException替代
     public RenException(String internalMsg) {
         super(internalMsg);
 //		this.code = ErrorCode.INTERNAL_SERVER_ERROR;
@@ -65,15 +68,12 @@ public class RenException extends RuntimeException {
         this.internalMsg = internalMsg;
     }
 
+    @Deprecated  //已废弃 被EpmetException替代
     public RenException(String internalMsg, String msg) {
         this(internalMsg);
         this.msg = msg;
     }
 
-
-
-
-
     public RenException(int code, String... params) {
         this.code = code;
         this.internalMsg = EpmetErrorCode.getMsg(code);
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/AssertUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/AssertUtils.java
index 2f5dcd311a..d060fc5e6a 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/AssertUtils.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/AssertUtils.java
@@ -11,6 +11,7 @@ package com.epmet.commons.tools.validator;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ArrayUtil;
+import com.epmet.commons.tools.exception.EpmetException;
 import com.epmet.commons.tools.exception.ErrorCode;
 import com.epmet.commons.tools.exception.RenException;
 import org.apache.commons.lang3.StringUtils;
@@ -32,7 +33,7 @@ public class AssertUtils {
 
     public static void isBlank(String str, Integer code, String... params) {
         if(code == null){
-            throw new RenException(ErrorCode.NOT_NULL, "code");
+            throw new EpmetException(ErrorCode.NOT_NULL, "code");
         }
 
         if (StringUtils.isBlank(str)) {
@@ -46,7 +47,7 @@ public class AssertUtils {
 
     public static void isNull(Object object, Integer code, String... params) {
         if(code == null){
-            throw new RenException(ErrorCode.NOT_NULL, "code");
+            throw new EpmetException(ErrorCode.NOT_NULL, "code");
         }
 
         if (object == null) {
@@ -60,7 +61,7 @@ public class AssertUtils {
 
     public static void isArrayEmpty(Object[] array, Integer code, String... params) {
         if(code == null){
-            throw new RenException(ErrorCode.NOT_NULL, "code");
+            throw new EpmetException(ErrorCode.NOT_NULL, "code");
         }
 
         if(ArrayUtil.isEmpty(array)){
@@ -74,7 +75,7 @@ public class AssertUtils {
 
     public static void isListEmpty(List> list, Integer code, String... params) {
         if(code == null){
-            throw new RenException(ErrorCode.NOT_NULL, "code");
+            throw new EpmetException(ErrorCode.NOT_NULL, "code");
         }
 
         if(CollUtil.isEmpty(list)){
@@ -88,7 +89,7 @@ public class AssertUtils {
 
     public static void isMapEmpty(Map map, Integer code, String... params) {
         if(code == null){
-            throw new RenException(ErrorCode.NOT_NULL, "code");
+            throw new EpmetException(ErrorCode.NOT_NULL, "code");
         }
 
         if(MapUtil.isEmpty(map)){
diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java
index d09b657ee0..fc0d7555e3 100644
--- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java
+++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java
@@ -18,7 +18,9 @@
 package com.epmet.dto;
 
 import com.epmet.commons.tools.validator.group.AddGroup;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import javax.validation.constraints.NotBlank;
 import java.io.Serializable;
@@ -49,7 +51,6 @@ public class IcPartyActivityDTO implements Serializable {
     /**
      * 组织ID
      */
-    @NotBlank(message = "agencyId不能为空",groups = AddGroup.class)
 	private String agencyId;
 
     /**
@@ -95,7 +96,8 @@ public class IcPartyActivityDTO implements Serializable {
     /**
      * 活动时间
      */
-    @NotBlank(message = "活动时间不能为空",groups = AddGroup.class)
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
 	private Date activityTime;
 
     /**
diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyActivityFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyActivityFormDTO.java
index 2053b99d0f..40ac5563ac 100644
--- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyActivityFormDTO.java
+++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyActivityFormDTO.java
@@ -2,6 +2,7 @@ package com.epmet.dto.form;
 
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -18,7 +19,9 @@ public class PartyActivityFormDTO implements Serializable {
     private String agencyId;
     private String unitId;
     private String title;
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
     private Date startTime;
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
     private Date endTime;
     private String serviceMatter;
     private Integer pageNo;
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
index 7578334f2c..d9019b6c5b 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
@@ -18,6 +18,7 @@
 package com.epmet.controller;
 
 import com.epmet.commons.tools.annotation.LoginUser;
+import com.epmet.commons.tools.aop.NoRepeatSubmit;
 import com.epmet.commons.tools.exception.RenException;
 import com.epmet.commons.tools.page.PageData;
 import com.epmet.commons.tools.security.dto.TokenDto;
@@ -145,6 +146,7 @@ public class IcCommunitySelfOrganizationController {
      * @author zxc
      * @date 2021/11/19 8:33 上午
      */
+    @NoRepeatSubmit
     @PostMapping("addcommunityselforganization")
     public Result addCommunitySelfOrganization(@LoginUser TokenDto tokenDto, @RequestBody AddCommunitySelfOrganizationFormDTO formDTO){
         ValidatorUtils.validateEntity(formDTO, AddCommunitySelfOrganizationFormDTO.AddCommunitySelfOrganizationForm.class);
@@ -159,6 +161,7 @@ public class IcCommunitySelfOrganizationController {
      * @author zxc
      * @date 2021/11/19 10:12 上午
      */
+    @NoRepeatSubmit
     @PostMapping("editcommunityselforganization")
     public Result editCommunitySelfOrganization(@LoginUser TokenDto tokenDto, @RequestBody EditCommunitySelfOrganizationFormDTO formDTO){
         ValidatorUtils.validateEntity(formDTO, EditCommunitySelfOrganizationFormDTO.EditCommunitySelfOrganizationForm.class);
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java
index 9da287e05d..413598926e 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java
@@ -18,6 +18,7 @@
 package com.epmet.controller;
 
 import com.epmet.commons.tools.annotation.LoginUser;
+import com.epmet.commons.tools.aop.NoRepeatSubmit;
 import com.epmet.commons.tools.page.PageData;
 import com.epmet.commons.tools.security.dto.TokenDto;
 import com.epmet.commons.tools.utils.ExcelUtils;
@@ -29,10 +30,12 @@ import com.epmet.dto.IcPartyActivityDTO;
 import com.epmet.dto.form.PartyActivityFormDTO;
 import com.epmet.excel.IcPartyActivityExcel;
 import com.epmet.service.IcPartyActivityService;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
@@ -64,6 +67,7 @@ public class IcPartyActivityController {
     }
 
     @PostMapping("save")
+    @NoRepeatSubmit
     public Result save(@LoginUser TokenDto tokenDto, @RequestBody IcPartyActivityDTO dto){
         //效验数据
         ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
@@ -80,17 +84,20 @@ public class IcPartyActivityController {
     @GetMapping("export")
     public void export(@RequestBody PartyActivityFormDTO formDTO, HttpServletResponse response) throws Exception {
         List