Commit cc7ccf95700f3a392adb4604747f644e993c5810
1 parent
9350c4ed44
Exists in
dev
心理检测通知记录保存bug修改
Showing 4 changed files with 162 additions and 51 deletions
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/GlobalExceptionHandler.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/ValidatedExceptionHandler.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsXljcTracePushRecord.java
- talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/XljcTracePushTask.java
talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/GlobalExceptionHandler.java
View file @
cc7ccf9
1 | +package com.lyms.talkonlineweb.aop; | |
2 | + | |
3 | +import com.lyms.talkonlineweb.constants.ErrorCodeConstants; | |
4 | +import com.lyms.talkonlineweb.result.BaseResponse; | |
5 | +import lombok.extern.log4j.Log4j2; | |
6 | +import org.springframework.aop.AopInvocationException; | |
7 | +import org.springframework.dao.DataAccessResourceFailureException; | |
8 | +import org.springframework.validation.BindException; | |
9 | +import org.springframework.web.bind.MissingServletRequestParameterException; | |
10 | +import org.springframework.web.bind.annotation.ControllerAdvice; | |
11 | + | |
12 | +import org.springframework.http.HttpStatus; | |
13 | +import org.springframework.validation.BindingResult; | |
14 | +import org.springframework.validation.FieldError; | |
15 | +import org.springframework.validation.ObjectError; | |
16 | +import org.springframework.web.bind.MethodArgumentNotValidException; | |
17 | +import org.springframework.web.bind.annotation.ExceptionHandler; | |
18 | +import org.springframework.web.bind.annotation.ResponseBody; | |
19 | +import org.springframework.web.bind.annotation.ResponseStatus; | |
20 | + | |
21 | +import javax.servlet.http.HttpServletRequest; | |
22 | +import javax.servlet.http.HttpServletResponse; | |
23 | +import java.util.HashMap; | |
24 | +import java.util.List; | |
25 | +import java.util.Map; | |
26 | + | |
27 | +@Log4j2 | |
28 | +@ControllerAdvice | |
29 | +public class GlobalExceptionHandler { | |
30 | + | |
31 | + private String globalMsg = "服务器内部错误,请联系管理员"; | |
32 | + | |
33 | + | |
34 | + /** | |
35 | + * 处理@Validated参数校验失败异常 | |
36 | + * @param exception 异常类 | |
37 | + * @return 响应 | |
38 | + */ | |
39 | + @ResponseBody | |
40 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | |
41 | + @ExceptionHandler(MethodArgumentNotValidException.class) | |
42 | + public BaseResponse exceptionHandler(MethodArgumentNotValidException exception){ | |
43 | + BindingResult result = exception.getBindingResult(); | |
44 | + StringBuilder stringBuilder = new StringBuilder(); | |
45 | + if (result.hasErrors()) { | |
46 | + List<ObjectError> errors = result.getAllErrors(); | |
47 | + if (errors != null) { | |
48 | + errors.forEach(p -> { | |
49 | + FieldError fieldError = (FieldError) p; | |
50 | + log.warn("Bad Request Parameters: dto entity [{}],field [{}],message [{}]",fieldError.getObjectName(), fieldError.getField(), fieldError.getDefaultMessage()); | |
51 | + stringBuilder.append(fieldError.getDefaultMessage()+";"); | |
52 | + }); | |
53 | + } | |
54 | + } | |
55 | + BaseResponse baseResponse=new BaseResponse(); | |
56 | + baseResponse.setErrorcode(1); | |
57 | + baseResponse.setErrormsg(stringBuilder.toString()); | |
58 | + return baseResponse; | |
59 | + } | |
60 | + | |
61 | + @ExceptionHandler(org.springframework.dao.DataAccessResourceFailureException.class) | |
62 | + @ResponseBody | |
63 | + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | |
64 | + public BaseResponse handException(DataAccessResourceFailureException e) { | |
65 | + log.error(e); | |
66 | + BaseResponse error = new BaseResponse(); | |
67 | + error.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); | |
68 | + error.setErrormsg(globalMsg); | |
69 | + return error; | |
70 | + } | |
71 | + | |
72 | + @ExceptionHandler(org.springframework.aop.AopInvocationException.class) | |
73 | + @ResponseBody | |
74 | + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | |
75 | + public BaseResponse handException(AopInvocationException e) { | |
76 | + log.error(e); | |
77 | + BaseResponse error = new BaseResponse(); | |
78 | + error.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); | |
79 | + error.setErrormsg(globalMsg); | |
80 | + return error; | |
81 | + } | |
82 | + | |
83 | + | |
84 | + @ExceptionHandler(BindException.class) | |
85 | + @ResponseStatus(HttpStatus.OK) | |
86 | + @ResponseBody | |
87 | + public Map validationError(BindException e, HttpServletResponse httpServletResponse) { | |
88 | + setHttpResponseHeader(httpServletResponse); | |
89 | + | |
90 | + return createValidationResponse(e.getBindingResult()); | |
91 | + | |
92 | + } | |
93 | + | |
94 | + | |
95 | + /** | |
96 | + * 处理spring mvc 缺少请求参数的异常提示 | |
97 | + * | |
98 | + * @param httpServletResponse | |
99 | + * @param missRequestParameter | |
100 | + */ | |
101 | + @ResponseStatus(HttpStatus.OK) | |
102 | + @ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) | |
103 | + @ResponseBody | |
104 | + public Map handlMissingServletRequestParameter(HttpServletResponse httpServletResponse, | |
105 | + MissingServletRequestParameterException missRequestParameter, | |
106 | + HttpServletRequest httpServletRequest) { | |
107 | + setHttpResponseHeader(httpServletResponse); | |
108 | + Map<String, Object> resultMap = new HashMap<>(); | |
109 | + resultMap.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR); | |
110 | + resultMap.put("errormsg", missRequestParameter.getMessage()); | |
111 | + log.error("ExceptionHandlerController handlMissingServletRequestParameter." + httpServletRequest.getRequestURI() + "?" + httpServletRequest.getQueryString(),missRequestParameter); | |
112 | + return resultMap; | |
113 | + } | |
114 | + | |
115 | + | |
116 | + @ResponseStatus(HttpStatus.OK) | |
117 | + @ExceptionHandler(Exception.class) | |
118 | + @ResponseBody | |
119 | + public Map<String, Object> buildException(HttpServletResponse httpServletResponse, Exception e, HttpServletRequest httpServletRequest) { | |
120 | + setHttpResponseHeader(httpServletResponse); | |
121 | + Map<String, Object> resultMap = new HashMap<>(); | |
122 | + resultMap.put("errorcode", ErrorCodeConstants.SYSTEM_ERROR); | |
123 | + resultMap.put("errormsg", "服务器异常."); | |
124 | + resultMap.put("message", e.getMessage()); | |
125 | + resultMap.put("exception", e.getClass()); | |
126 | + if(!e.getClass().getSimpleName().equals("ClientAbortException") ){ | |
127 | + log.error("ExceptionHandlerController Exception. queryStr: " +httpServletRequest.getRequestURI() + "?"+httpServletRequest.getQueryString(),e); | |
128 | + } | |
129 | + | |
130 | + return resultMap; | |
131 | + } | |
132 | + | |
133 | + private Map<String, Object> createValidationResponse(BindingResult bindingResult) { | |
134 | + Map<String, Object> map = new HashMap<String, Object>(); | |
135 | + List<org.springframework.validation.FieldError> fieldErrors = bindingResult.getFieldErrors(); | |
136 | + for (org.springframework.validation.FieldError fieldError : fieldErrors) { | |
137 | + map.put("errorcode", ErrorCodeConstants.PARAMETER_ERROR); | |
138 | + map.put("errormsg","参数错误"); | |
139 | + break; | |
140 | + } | |
141 | + return map; | |
142 | + } | |
143 | + | |
144 | + private void setHttpResponseHeader(HttpServletResponse httpServletResponse) { | |
145 | + httpServletResponse.setCharacterEncoding("UTF-8"); | |
146 | + httpServletResponse.setHeader("Cache-Control", "no-cache"); | |
147 | + | |
148 | + httpServletResponse.setContentType("application/json;charset=UTF-8"); | |
149 | + } | |
150 | + | |
151 | +} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/ValidatedExceptionHandler.java
View file @
cc7ccf9
1 | -package com.lyms.talkonlineweb.aop; | |
2 | - | |
3 | -import com.lyms.talkonlineweb.result.BaseResponse; | |
4 | -import lombok.extern.log4j.Log4j2; | |
5 | -import org.springframework.web.bind.annotation.ControllerAdvice; | |
6 | - | |
7 | -import org.springframework.http.HttpStatus; | |
8 | -import org.springframework.validation.BindingResult; | |
9 | -import org.springframework.validation.FieldError; | |
10 | -import org.springframework.validation.ObjectError; | |
11 | -import org.springframework.web.bind.MethodArgumentNotValidException; | |
12 | -import org.springframework.web.bind.annotation.ExceptionHandler; | |
13 | -import org.springframework.web.bind.annotation.ResponseBody; | |
14 | -import org.springframework.web.bind.annotation.ResponseStatus; | |
15 | -import java.util.List; | |
16 | - | |
17 | -@Log4j2 | |
18 | -@ControllerAdvice | |
19 | -public class ValidatedExceptionHandler { | |
20 | - /** | |
21 | - * 处理@Validated参数校验失败异常 | |
22 | - * @param exception 异常类 | |
23 | - * @return 响应 | |
24 | - */ | |
25 | - @ResponseBody | |
26 | - @ResponseStatus(HttpStatus.BAD_REQUEST) | |
27 | - @ExceptionHandler(MethodArgumentNotValidException.class) | |
28 | - public BaseResponse exceptionHandler(MethodArgumentNotValidException exception){ | |
29 | - BindingResult result = exception.getBindingResult(); | |
30 | - StringBuilder stringBuilder = new StringBuilder(); | |
31 | - if (result.hasErrors()) { | |
32 | - List<ObjectError> errors = result.getAllErrors(); | |
33 | - if (errors != null) { | |
34 | - errors.forEach(p -> { | |
35 | - FieldError fieldError = (FieldError) p; | |
36 | - log.warn("Bad Request Parameters: dto entity [{}],field [{}],message [{}]",fieldError.getObjectName(), fieldError.getField(), fieldError.getDefaultMessage()); | |
37 | - stringBuilder.append(fieldError.getDefaultMessage()+";"); | |
38 | - }); | |
39 | - } | |
40 | - } | |
41 | - BaseResponse baseResponse=new BaseResponse(); | |
42 | - baseResponse.setErrorcode(1); | |
43 | - baseResponse.setErrormsg(stringBuilder.toString()); | |
44 | - return baseResponse; | |
45 | - } | |
46 | - | |
47 | -} |
talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsXljcTracePushRecord.java
View file @
cc7ccf9
talkonlineweb/src/main/java/com/lyms/talkonlineweb/task/XljcTracePushTask.java
View file @
cc7ccf9
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | import com.lyms.talkonlineweb.util.WeiXinUtil; |
11 | 11 | import lombok.extern.log4j.Log4j2; |
12 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
13 | +import org.springframework.beans.factory.annotation.Value; | |
13 | 14 | import org.springframework.scheduling.annotation.Scheduled; |
14 | 15 | import org.springframework.stereotype.Component; |
15 | 16 | |
16 | 17 | |
... | ... | @@ -24,12 +25,18 @@ |
24 | 25 | @Component |
25 | 26 | @Log4j2 |
26 | 27 | public class XljcTracePushTask { |
28 | + @Value("${getAccessToken.on_off}") | |
29 | + public boolean on_off;//配置yml 微信公众号获取access_token(测试环境部署不要开启。会与线上环境冲突) | |
27 | 30 | |
28 | 31 | @Autowired |
29 | 32 | LymsXljcTracePushRecordService lymsXljcTracePushRecordService; |
30 | 33 | |
31 | - @Scheduled(cron = "0 0 16 * * ?") | |
32 | - public void pushArtcleData(){ | |
34 | + @Scheduled(cron = "0 0 9 * * ?") | |
35 | + public void xljcTraceNoticePush(){ | |
36 | + | |
37 | + if(!on_off){ | |
38 | + return; | |
39 | + } | |
33 | 40 | log.info("推送心理检测预约通知开始"); |
34 | 41 | |
35 | 42 | List<LymsXljcTracePushRecord> tracePushRecords = lymsXljcTracePushRecordService.queryNeedPushRecords(); |
... | ... | @@ -53,7 +60,7 @@ |
53 | 60 | record.setMsg("该患者未关注公众号"); |
54 | 61 | } else { |
55 | 62 | Map<String, Object> map = new HashMap<>(); |
56 | - map.put("first", new DataEntity("您预约了" + DateUtil.getDateTime(record.getNextExamineDate(), "yyyy年MM月dd日") + "复查,请及时复诊", "#173177")); | |
63 | + map.put("first", new DataEntity("您预约了复查,请及时复诊", "#173177")); | |
57 | 64 | map.put("keyword1", new DataEntity(record.getPname(), "#173177")); |
58 | 65 | map.put("keyword2", new DataEntity(record.getHname(), "#173177")); |
59 | 66 | map.put("keyword3", new DataEntity(record.getDpName(), "#173177")); |