Browse Source

1)修改备注。

tomatozq 5 years ago
parent
commit
121f135c95

+ 21 - 0
picc-admin-server/src/main/java/com/jpsoft/picc/modules/sys/controller/LogController.java

@@ -15,6 +15,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -30,6 +31,26 @@ public class LogController {
     @Autowired
     private SysLogService sysLogService;
 
+    @GetMapping("add")
+    @Transactional(rollbackFor = Exception.class)
+    public MessageResult<SysLog> add() throws Exception{
+        MessageResult<SysLog> messageResult = new MessageResult<>();
+
+        SysLog sysLog = new SysLog();
+        sysLog.setUserId("test");
+        messageResult.setData(sysLog);
+
+        int affectCount = sysLogService.insert(sysLog);
+
+        logger.warn("affectCount=" + affectCount);
+
+        if (affectCount>0){
+            throw new Exception("回滚测试");
+        }
+
+        return messageResult;
+    }
+
     @ApiOperation(value="列表")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "userId",value = "用户编号", paramType = "form"),

+ 27 - 0
picc-common/src/main/java/com/jpsoft/picc/advice/GlobalExceptionHandler.java

@@ -0,0 +1,27 @@
+package com.jpsoft.picc.advice;
+
+import com.jpsoft.picc.exception.ApiException;
+import com.jpsoft.picc.modules.common.dto.MessageResult;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@ControllerAdvice
+public class GlobalExceptionHandler {
+    /**
+     * 如果针对Exception.class 有可能把非ajax都返回json
+     * @param e
+     * @return
+     */
+    @ResponseBody
+    @ExceptionHandler(value = Exception.class)
+    public MessageResult<String> handle(Exception e) {
+        //这里返回的类型不需要与抛异常的方法一致
+        MessageResult<String> messageResult = new MessageResult<>();
+        messageResult.setResult(false);
+        messageResult.setMessage(e.getMessage());
+
+        return messageResult;
+//        return e.getMessage();
+    }
+}

+ 15 - 0
picc-common/src/main/java/com/jpsoft/picc/exception/ApiException.java

@@ -0,0 +1,15 @@
+package com.jpsoft.picc.exception;
+
+public class ApiException extends RuntimeException {
+    public ApiException(String message) {
+        super(message);
+    }
+
+    public ApiException(Throwable cause) {
+        super(cause);
+    }
+
+    public ApiException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

+ 2 - 2
picc-common/src/main/java/com/jpsoft/picc/modules/sys/entity/Menu.java

@@ -27,14 +27,14 @@ public class Menu {
 	private Integer msgNum;
 
 	/**
-	 *获取菜单编号
+	 *获取菜单消息提示数
 	 */
 	public Integer getMsgNum(){
 		return msgNum;
 	}
 
 	/**
-	 *设置菜单编号
+	 *设置菜单消息提示数
 	 */
 	public void setMsgNum(Integer msgNum){
 		this.msgNum = msgNum;

+ 1 - 1
weixin-middleware/src/main/java/com/jpsoft/weixin/controller/WeixinController.java

@@ -218,7 +218,7 @@ public class WeixinController {
             if(!processed) {
                 String responseText = "success";
 
-                if(event.equals("subscribe")){
+                if("subscribe".equals(event)){
                     ReplyMessage replyMessage = replyMessageService.findByEvent(wechatId,event);
 
                     if(replyMessage!=null) {