From 9454b49eeabd56894550f1419f14e96f9d10c2ef Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期六, 02 二月 2019 13:15:51 +0800
Subject: [PATCH] 调整日志信息
---
CodeService/src/main/java/com/java110/code/api/CodeApi.java | 102 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 78 insertions(+), 24 deletions(-)
diff --git a/CodeService/src/main/java/com/java110/code/api/CodeApi.java b/CodeService/src/main/java/com/java110/code/api/CodeApi.java
index e17f3f4..1055cdf 100644
--- a/CodeService/src/main/java/com/java110/code/api/CodeApi.java
+++ b/CodeService/src/main/java/com/java110/code/api/CodeApi.java
@@ -1,79 +1,88 @@
package com.java110.code.api;
+import com.alibaba.fastjson.JSONObject;
import com.java110.code.smo.IPrimaryKeyServiceSMO;
import com.java110.common.constant.ResponseConstant;
+import com.java110.common.exception.ResponseErrorException;
import com.java110.common.util.Assert;
+import com.java110.common.util.DateUtil;
import com.java110.core.base.controller.BaseController;
import com.java110.core.context.CodeDataFlow;
import com.java110.core.factory.DataFlowFactory;
import com.java110.core.factory.DataTransactionFactory;
+import com.java110.feign.code.ICodeApi;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
/**
* ID 鐢熸垚
* Created by wuxw on 2018/6/3.
*/
@RestController
-public class CodeApi extends BaseController {
+public class CodeApi extends BaseController implements ICodeApi {
+
+ protected final static Logger logger = LoggerFactory.getLogger(CodeApi.class);
+
@Autowired
IPrimaryKeyServiceSMO primaryKeyServiceSMOImpl;
- @RequestMapping(path = "/codeApi/generate",method= RequestMethod.GET)
+ @RequestMapping(path = "/codeApi/generate", method = RequestMethod.GET)
public String generateGet(HttpServletRequest request) {
- return DataTransactionFactory.createCodeResponseJson(ResponseConstant.NO_TRANSACTION_ID,"-1",
- ResponseConstant.RESULT_CODE_ERROR,"涓嶆敮鎸丟et鏂规硶璇锋眰").toJSONString();
+ return DataTransactionFactory.createCodeResponseJson(ResponseConstant.NO_TRANSACTION_ID, "-1",
+ ResponseConstant.RESULT_CODE_ERROR, "涓嶆敮鎸丟et鏂规硶璇锋眰").toJSONString();
}
- @RequestMapping(path = "/codeApi/generate",method= RequestMethod.POST)
- public String generatePost(@RequestBody String orderInfo,HttpServletRequest request) {
+ @RequestMapping(path = "/codeApi/generate", method = RequestMethod.POST)
+ public String generatePost(@RequestBody String orderInfo, HttpServletRequest request) {
Map<String, String> headers = new HashMap<String, String>();
try {
getRequestInfo(request, headers);
//棰勬牎楠�
- preValiateOrderInfo(orderInfo,headers);
- CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(orderInfo,null);
+ preValiateOrderInfo(orderInfo, headers);
+ CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(orderInfo, null);
primaryKeyServiceSMOImpl.generateCode(dataFlow);
return dataFlow.getResJson().toJSONString();
- }catch (Exception e){
- logger.error("璇锋眰璁㈠崟寮傚父",e);
- return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString();
+ } catch (Exception e) {
+ logger.error("璇锋眰璁㈠崟寮傚父", e);
+ return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR, e.getMessage() + e).toJSONString();
}
}
/**
* 鑾峰彇璇锋眰淇℃伅
+ *
* @param request
* @param headers
* @throws RuntimeException
*/
- private void getRequestInfo(HttpServletRequest request,Map headers) throws Exception{
- try{
- super.initHeadParam(request,headers);
- super.initUrlParam(request,headers);
- }catch (Exception e){
- logger.error("鍔犺浇澶翠俊鎭け璐�",e);
+ private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
+ try {
+ super.initHeadParam(request, headers);
+ super.initUrlParam(request, headers);
+ } catch (Exception e) {
+ logger.error("鍔犺浇澶翠俊鎭け璐�", e);
throw e;
}
}
/**
* 杩欓噷棰勬牎楠岋紝璇锋眰鎶ユ枃涓笉鑳芥湁 dataFlowId
+ *
* @param orderInfo
*/
- private void preValiateOrderInfo(String orderInfo,Map<String, String> headers) {
+ private void preValiateOrderInfo(String orderInfo, Map<String, String> headers) {
- Assert.jsonObjectHaveKey(orderInfo,"prefix","娌℃湁鍖呭惈prefix");
+ Assert.jsonObjectHaveKey(orderInfo, "prefix", "娌℃湁鍖呭惈prefix");
- Assert.jsonObjectHaveKey(orderInfo,"transactionId","娌℃湁鍖呭惈transactionId");
+ Assert.jsonObjectHaveKey(orderInfo, "transactionId", "娌℃湁鍖呭惈transactionId");
}
@@ -85,4 +94,49 @@
public void setPrimaryKeyServiceSMOImpl(IPrimaryKeyServiceSMO primaryKeyServiceSMOImpl) {
this.primaryKeyServiceSMOImpl = primaryKeyServiceSMOImpl;
}
+
+ /**
+ * 鐢熸垚 缂栫爜
+ *
+ * @param prefix 鍓嶇紑
+ * @return
+ */
+ @Override
+ @RequestMapping(value = "/codeApi/generateCode",method = RequestMethod.POST)
+ public String generateCode(@RequestParam("prefix") String prefix) {
+
+ try {
+ JSONObject requestInfo = new JSONObject();
+
+ //灏佽绗﹀悎鏋勫缓CodeDataFlow瀵硅薄鐨凧SON瀵硅薄鍙傛暟
+ builderRequestInfo(prefix, requestInfo);
+
+ CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(requestInfo.toJSONString(), null);
+
+ //鐢熸垚缂栫爜
+ primaryKeyServiceSMOImpl.generateCode(dataFlow);
+
+ if (!ResponseConstant.RESULT_CODE_SUCCESS.equals(dataFlow.getResJson().getString("code"))) {
+ throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "鐢熸垚缂栫爜澶辫触 "
+ + dataFlow.getResJson().getString("message"));
+ }
+
+ return dataFlow.getResJson().getString("id");
+ } catch (Exception e) {
+ logger.error("璇锋眰璁㈠崟寮傚父", e);
+ return ResponseConstant.RESULT_CODE_ERROR;
+ }
+ }
+
+ /**
+ * 灏佽绗﹀悎鏋勫缓CodeDataFlow瀵硅薄鐨凧SON瀵硅薄鍙傛暟
+ *
+ * @param prefix 鍓嶇紑
+ * @param requestInfo 鏋勫缓鐨勮姹侸SON瀵硅薄
+ */
+ private void builderRequestInfo(String prefix, JSONObject requestInfo) {
+ requestInfo.put("transactionId", UUID.randomUUID().toString().replace("-", ""));
+ requestInfo.put("prefix", prefix);
+ requestInfo.put("requestTime", DateUtil.getNowDefault());
+ }
}
--
Gitblit v1.8.0