|
@@ -10,7 +10,10 @@ import org.springframework.validation.BindException;
|
|
|
import org.springframework.validation.FieldError;
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -21,6 +24,10 @@ import java.util.Map;
|
|
|
*/
|
|
|
public class CdssLogUtil {
|
|
|
|
|
|
+ private final static String CDSS_REQ = "cdss_req";
|
|
|
+ private final static String CDSS_RESP = "cdss_resp";
|
|
|
+ private final static String CDSS_LOG_SP = "→";
|
|
|
+
|
|
|
/**
|
|
|
* 入参设置
|
|
|
*
|
|
@@ -66,6 +73,8 @@ public class CdssLogUtil {
|
|
|
long execTime = System.currentTimeMillis() - start;
|
|
|
tranLog.setGmtResp(DateUtil.now());
|
|
|
tranLog.setExecTime(String.valueOf(execTime));
|
|
|
+ //业务处理
|
|
|
+ bizDeal(tranLog);
|
|
|
return tranLog;
|
|
|
}
|
|
|
|
|
@@ -96,6 +105,8 @@ public class CdssLogUtil {
|
|
|
long execTime = System.currentTimeMillis() - start;
|
|
|
tranLog.setGmtResp(DateUtil.now());
|
|
|
tranLog.setExecTime(String.valueOf(execTime));
|
|
|
+ //业务处理
|
|
|
+ bizDeal(tranLog);
|
|
|
return tranLog;
|
|
|
}
|
|
|
|
|
@@ -148,4 +159,71 @@ public class CdssLogUtil {
|
|
|
resp.msg = e.getMessage();
|
|
|
return resp;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日志处理
|
|
|
+ *
|
|
|
+ * @param tranLog
|
|
|
+ */
|
|
|
+ private static void bizDeal(TranLog tranLog) {
|
|
|
+ HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
|
|
+ //入参处理
|
|
|
+ String params = tranLog.getParams();
|
|
|
+ String req = response.getHeader(CDSS_REQ);
|
|
|
+ if (StringUtil.isNotBlank(req)) {
|
|
|
+ if (StringUtil.isNotBlank(params)) {
|
|
|
+ params += CDSS_LOG_SP + req;
|
|
|
+ } else {
|
|
|
+ params = req;
|
|
|
+ }
|
|
|
+ response.setHeader(CDSS_REQ, "");
|
|
|
+ }
|
|
|
+ tranLog.setParams(params);
|
|
|
+ //出参处理
|
|
|
+ String result = tranLog.getResult();
|
|
|
+ String resp = response.getHeader(CDSS_RESP);
|
|
|
+ if (StringUtil.isNotBlank(resp)) {
|
|
|
+ if (StringUtil.isNotBlank(result)) {
|
|
|
+ result += CDSS_LOG_SP + resp;
|
|
|
+ } else {
|
|
|
+ result = resp;
|
|
|
+ }
|
|
|
+ response.setHeader(CDSS_RESP, "");
|
|
|
+ }
|
|
|
+ tranLog.setResult(result);
|
|
|
+ //todo 个性化处理
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加入参
|
|
|
+ *
|
|
|
+ * @param o
|
|
|
+ */
|
|
|
+ public static void addBizReq(Object o) {
|
|
|
+ handleRespHeaderMap(CDSS_REQ, o);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加出参
|
|
|
+ *
|
|
|
+ * @param o
|
|
|
+ */
|
|
|
+ public static void addBizResp(Object o) {
|
|
|
+ handleRespHeaderMap(CDSS_RESP, o);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void handleRespHeaderMap(String key, Object o) {
|
|
|
+ HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
|
|
+ String value = response.getHeader(key);
|
|
|
+ if (StringUtil.isNotBlank(value)) {
|
|
|
+ value += CDSS_LOG_SP + FastJsonUtils.getBeanToJson(o);
|
|
|
+ } else {
|
|
|
+ value = FastJsonUtils.getBeanToJson(o);
|
|
|
+ }
|
|
|
+ // 设置Header
|
|
|
+ response.setHeader(key, value);
|
|
|
+ }
|
|
|
}
|