Commit aad521a7f83124db409c2f6f02423540079e3e46

Authored by cfl
1 parent cc7ccf9570
Exists in dev

民族和职业返回字段类型修改

Showing 4 changed files with 49 additions and 153 deletions

talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/GlobalExceptionHandler.java View file @ aad521a
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 @ aad521a
  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/LymsXljcArchive.java View file @ aad521a
... ... @@ -77,7 +77,7 @@
77 77 * 民族
78 78 */
79 79 @TableField(value = "nation")
80   - private String nation;
  80 + private Integer nation;
81 81  
82 82 /**
83 83 * 职业类别
talkonlineweb/src/main/java/com/lyms/talkonlineweb/service/impl/LymsXljcRecordServiceImpl.java View file @ aad521a
... ... @@ -211,7 +211,7 @@
211 211 patient.setBirth(archive.getBirth());
212 212 patient.setSex(archive.getSex());
213 213 patient.setCcnt(0);
214   - patient.setNation(archive.getNation());
  214 + patient.setNation(String.valueOf(archive.getNation()));
215 215 patient.setJobType(archive.getJobType());
216 216 patient.setResideAddres(archive.getResideAddres());
217 217 patient.setCreatedby(currentUser.getUid());