From 7afa32638bd4c1eec05a19a6586af3f4b1ce8ccb Mon Sep 17 00:00:00 2001
From: wuxw7 <wuxw7@asiainfo.com>
Date: 星期六, 16 六月 2018 01:25:43 +0800
Subject: [PATCH] 日志服务实现

---
 java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java |   47 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/java110-common/src/main/java/com/java110/common/util/SequenceUtil.java b/java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java
similarity index 84%
rename from java110-common/src/main/java/com/java110/common/util/SequenceUtil.java
rename to java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java
index 3227f90..b0a591d 100644
--- a/java110-common/src/main/java/com/java110/common/util/SequenceUtil.java
+++ b/java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java
@@ -1,4 +1,4 @@
-package com.java110.common.util;
+package com.java110.core.factory;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.common.cache.MappingCache;
@@ -7,6 +7,9 @@
 import com.java110.common.exception.GenerateCodeException;
 import com.java110.common.exception.ResponseErrorException;
 import com.java110.common.factory.ApplicationContextFactory;
+import com.java110.common.util.Assert;
+import com.java110.common.util.DateUtil;
+import com.java110.feign.code.ICodeApi;
 import org.springframework.web.client.RestTemplate;
 
 import java.rmi.NoSuchObjectException;
@@ -23,7 +26,7 @@
  * 鐢熸垚搴忓垪宸ュ叿绫�
  * Created by wuxw on 2017/2/27.
  */
-public class SequenceUtil {
+public class GenerateCodeFactory {
 
     private static final long ONE_STEP = 1000000;
     private static final Lock LOCK = new ReentrantLock();
@@ -83,6 +86,15 @@
     }
 
     /**
+     * 鑾峰彇鍐呴儴骞冲彴 浜ゆ槗娴佹按
+     * @return
+     * @throws NoSuchObjectException
+     */
+    public static String getInnerTransactionId() throws Exception{
+        return codeApi().generateCode(prefixMap.get("transactionId"));
+    }
+
+    /**
      * 鑾峰彇浜ゆ槗娴佹按ID
      *
      * @return
@@ -115,6 +127,9 @@
             String responseMessage = restTemplate().postForObject(MappingCache.getValue(MappingConstant.KEY_CODE_PATH),
                     createCodeRequestJson(getTransactionId(),prefix,prefix).toJSONString(), String.class);
 
+            if(ResponseConstant.RESULT_CODE_ERROR.equals(responseMessage)){
+                throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "鐢熸垚oId缂栫爜澶辫触");
+            }
             Assert.jsonObjectHaveKey(responseMessage, "code", "缂栫爜鐢熸垚绯荤粺 杩斿洖鎶ユ枃閿欒" + responseMessage);
 
             JSONObject resJson = JSONObject.parseObject(responseMessage);
@@ -149,12 +164,12 @@
         return getCode(prefixMap.get("attrId"));
     }
 
+    /**
+     * 鐢熸垚dataFlowId
+     * @return
+     * @throws GenerateCodeException
+     */
     public static String getDataFlowId()  throws GenerateCodeException{
-        /*if(!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))){
-            return prefixMap.get("dataFlowId") + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H) + nextId("%08d");
-        }
-
-        return getCode(prefixMap.get("dataFlowId"));*/
 
         return UUID.randomUUID().toString().replace("-","").toLowerCase();
 
@@ -185,6 +200,24 @@
        return (RestTemplate) bean;
     }
 
+    /**
+     * 鑾峰彇codeApi
+     * @return
+     * @throws NoSuchObjectException
+     */
+    private static ICodeApi codeApi() throws NoSuchObjectException{
+
+        Object bean = ApplicationContextFactory.getBean("codeApi");
+
+        if(bean == null){
+            throw new NoSuchObjectException("codeApi锛岃鏍稿疄");
+        }
+
+        return (ICodeApi) bean;
+    }
+
+
+
 
     /**
      * ID鐢熸垚璇锋眰鎶ユ枃

--
Gitblit v1.8.0