Преглед изворни кода

日志服务 编码生成服务测试通过

wuxw7 пре 7 година
родитељ
комит
288d590fbc
29 измењених фајлова са 445 додато и 75 уклоњено
  1. 12 2
      CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java
  2. 14 0
      CodeService/doc/start_codeService.sh
  3. 9 0
      CodeService/pom.xml
  4. 1 8
      CodeService/src/main/java/com/java110/CodeServiceApplicationStart.java
  5. 4 6
      CodeService/src/main/java/com/java110/code/api/CodeApi.java
  6. 14 0
      LogService/doc/start_logService.sh
  7. 4 1
      LogService/src/main/java/com/java110/log/LogServiceApplicationStart.java
  8. 1 1
      LogService/src/main/java/com/java110/log/kafka/LogServiceKafka.java
  9. 14 0
      LogService/src/main/java/com/java110/log/smo/impl/LogServiceSMOImpl.java
  10. 92 0
      LogService/src/main/resources/application-dev.yml
  11. 92 0
      LogService/src/main/resources/application-prod.yml
  12. 101 0
      LogService/src/main/resources/application-test.yml
  13. 2 26
      LogService/src/main/resources/application.yml
  14. 15 0
      LogService/src/main/resources/banner.txt
  15. 3 1
      LogService/src/test/java/com/java110/log/AppTest.java
  16. 9 0
      java110-common/src/main/java/com/java110/common/util/DateUtil.java
  17. 7 6
      java110-config/db/LogService/create_table.db
  18. 7 7
      java110-config/src/main/resources/config/code/zookeeper.properties
  19. 4 4
      java110-config/src/main/resources/mapper/log/LogServiceDaoImplMapper.xml
  20. 1 1
      java110-core/src/main/java/com/java110/core/base/controller/BaseController.java
  21. 4 0
      java110-core/src/main/java/com/java110/core/context/AbstractDataFlowContext.java
  22. 8 2
      java110-core/src/main/java/com/java110/core/context/AbstractTransactionLog.java
  23. 1 1
      java110-core/src/main/java/com/java110/core/factory/DataFlowFactory.java
  24. 3 3
      java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java
  25. 5 1
      java110-feign/pom.xml
  26. 5 1
      java110-feign/src/main/java/com/java110/feign/code/CodeApiFallback.java
  27. 5 1
      java110-feign/src/main/java/com/java110/feign/code/ICodeApi.java
  28. 1 1
      java110-logAgent/src/main/java/com/java110/log/agent/LogAgent.java
  29. 7 2
      java110-logAgent/src/test/java/com/java110/AppTest.java

+ 12 - 2
CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java

@@ -8,6 +8,7 @@ import com.java110.common.cache.AppRouteCache;
 import com.java110.common.cache.MappingCache;
 import com.java110.common.constant.*;
 import com.java110.common.exception.*;
+import com.java110.common.factory.ApplicationContextFactory;
 import com.java110.common.kafka.KafkaFactory;
 import com.java110.common.log.LoggerEngine;
 import com.java110.common.util.*;
@@ -23,6 +24,7 @@ import com.java110.entity.center.DataFlowLinksCost;
 import com.java110.event.center.DataFlowEventPublishing;
 
 import com.java110.log.agent.LogAgent;
+import com.java110.service.init.ServiceInfoListener;
 import com.java110.service.smo.IQueryServiceSMO;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -508,7 +510,9 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
         dataFlow.setResData(responseJson);
 
         DataFlowFactory.addCostTime(dataFlow,dataFlow.getCurrentBusiness().getServiceCode(), "调用"+dataFlow.getCurrentBusiness().getServiceCode()+"耗时", startDate);
-        saveLogMessage(dataFlow.getCurrentBusiness().getTransferData(),dataFlow.getResData());
+        saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getCurrentBusiness().getTransferData()),
+                LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),dataFlow.getResData()),
+                DateUtil.getCurrentDate().getTime()-startDate.getTime());
 
 
         DataFlowFactory.addCostTime(dataFlow, "invokeBusinessSystem", "调用下游系统耗时", startDate);
@@ -776,6 +780,11 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
         if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){
             throw new InitConfigDataException(ResponseConstant.RESULT_CODE_ERROR,"请求报文中没有包含 dataFlowId 节点");
         }
+        //重新刷端口信息
+        ServiceInfoListener serviceInfoListener =  ApplicationContextFactory.getBean("serviceInfoListener",ServiceInfoListener.class);
+        if(serviceInfoListener != null){
+            dataFlow.setPort(serviceInfoListener.getServerPort()+"");
+        }
         //重新加载配置
         initConfigData(dataFlow);
     }
@@ -1164,7 +1173,8 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
         dataFlow.setResponseBusinessJson(DataTransactionFactory.createOrderResponseJson(dataFlow.getTransactionId(),
                  ResponseConstant.RESULT_CODE_SUCCESS, "成功"));
         DataFlowFactory.addCostTime(dataFlow, "doSynchronousBusinesses", "异步调用业务系统总耗时", startDate);
-        saveLogMessage(dataFlow,dataFlow.getRequestBusinessJson(),dataFlow.getResponseBusinessJson(),
+        saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getRequestBusinessJson().toJSONString()),
+                LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getResponseBusinessJson().toJSONString()),
                 DateUtil.getCurrentDate().getTime()-startDate.getTime());
     }
 

+ 14 - 0
CodeService/doc/start_codeService.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+#### debug model prod
+#nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar -Dspring.profiles.active=dev CodeService.jar $1 > code.log 2>&1 &
+
+#### normal prod model
+#nohup java -jar -Dspring.profiles.active=prod $1 CodeService.jar > code.log $1 2>&1 &
+
+#### normal test model
+#nohup java -jar -Dspring.profiles.active=test $1 CodeService.jar > code.log $1 2>&1 &
+
+#### normal dev model
+nohup java -jar -Dspring.profiles.active=dev $1 CodeService.jar > code.log $1 2>&1 &
+
+tail -100f code.log

+ 9 - 0
CodeService/pom.xml

@@ -29,6 +29,7 @@
     </dependencies>
 
     <build>
+        <finalName>CodeService</finalName>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -56,6 +57,14 @@
                     </execution>
                 </executions>
             </plugin>
+
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <mainClass>com.java110.code.CodeServiceApplicationStart</mainClass>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 </project>

+ 1 - 8
CodeService/src/main/java/com/java110/CodeServiceApplicationStart.java

@@ -1,4 +1,4 @@
-package com.java110;
+package com.java110.code;
 
 /**
  * Hello world!
@@ -8,7 +8,6 @@ import com.java110.common.constant.ResponseConstant;
 import com.java110.common.exception.StartException;
 import com.java110.common.factory.ApplicationContextFactory;
 import com.java110.common.util.Assert;
-import com.java110.common.util.DateUtil;
 import com.java110.common.util.StringUtil;
 import com.java110.config.properties.code.ZookeeperProperties;
 import com.java110.service.init.ServiceInfoListener;
@@ -17,17 +16,11 @@ import org.apache.zookeeper.*;
 import org.apache.zookeeper.data.Stat;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.client.RestTemplateBuilder;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.http.converter.StringHttpMessageConverter;
-import org.springframework.web.client.RestTemplate;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.nio.charset.Charset;
 import java.util.List;
 
 /**

+ 4 - 6
CodeService/src/main/java/com/java110/code/api/CodeApi.java

@@ -12,10 +12,7 @@ import com.java110.core.factory.DataFlowFactory;
 import com.java110.core.factory.DataTransactionFactory;
 import com.java110.feign.code.ICodeApi;
 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;
@@ -100,7 +97,8 @@ public class CodeApi extends BaseController implements ICodeApi {
      * @return
      */
     @Override
-    public String generateCode(String prefix) {
+    @RequestMapping(value = "/codeApi/generateCode",method = RequestMethod.POST)
+    public String generateCode(@RequestParam("prefix") String prefix) {
 
         try {
             JSONObject requestInfo = new JSONObject();
@@ -114,7 +112,7 @@ public class CodeApi extends BaseController implements ICodeApi {
             primaryKeyServiceSMOImpl.generateCode(dataFlow);
 
             if (!ResponseConstant.RESULT_CODE_SUCCESS.equals(dataFlow.getResJson().getString("code"))) {
-                throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "生成oId编码失败 "
+                throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "生成编码失败 "
                         + dataFlow.getResJson().getString("message"));
             }
 

+ 14 - 0
LogService/doc/start_logService.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+#### debug model prod
+#nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar -Dspring.profiles.active=dev LogService.jar $1 > log.log 2>&1 &
+
+#### normal prod model
+#nohup java -jar -Dspring.profiles.active=prod $1 LogService.jar > log.log $1 2>&1 &
+
+#### normal test model
+#nohup java -jar -Dspring.profiles.active=test $1 LogService.jar > log.log $1 2>&1 &
+
+#### normal dev model
+nohup java -jar -Dspring.profiles.active=dev $1 LogService.jar > log.log $1 2>&1 &
+
+tail -100f log.log

+ 4 - 1
LogService/src/main/java/com/java110/log/LogServiceApplicationStart.java

@@ -8,6 +8,7 @@ import com.java110.service.init.ServiceStartInit;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
 import org.springframework.context.ApplicationContext;
 
 /**
@@ -19,8 +20,10 @@ import org.springframework.context.ApplicationContext;
  * @date 2016年8月6日
  * @tag
  */
-@SpringBootApplication(scanBasePackages = {"com.java110.service","com.java110.log","com.java110.core","com.java110.cache"})
+@SpringBootApplication(scanBasePackages = {"com.java110.service","com.java110.log",
+"com.java110.feign.code","com.java110.core","com.java110.cache"})
 @EnableDiscoveryClient
+@EnableFeignClients(basePackages = {"com.java110.feign.code"})
 public class LogServiceApplicationStart {
 
 

+ 1 - 1
LogService/src/main/java/com/java110/log/kafka/LogServiceKafka.java

@@ -44,7 +44,7 @@ public class LogServiceKafka extends BaseController {
     @Autowired
     private ILogServiceSMO logServiceSMOImpl;
 
-    @KafkaListener(topics = {KafkaConstant.TOPIC_LOG_NAME})
+    @KafkaListener(topics = {"LOG"})
     public void listen(ConsumerRecord<?, ?> record) {
         logger.info("LogServiceKafka receive message: {}", record.value().toString());
         String logMessage = record.value().toString();

+ 14 - 0
LogService/src/main/java/com/java110/log/smo/impl/LogServiceSMOImpl.java

@@ -7,6 +7,7 @@ import com.java110.common.util.Assert;
 import com.java110.common.util.DateUtil;
 import com.java110.core.base.smo.BaseServiceSMO;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.feign.code.ICodeApi;
 import com.java110.log.dao.LogServiceDao;
 import com.java110.log.smo.ILogServiceSMO;
 import org.slf4j.Logger;
@@ -31,6 +32,9 @@ public class LogServiceSMOImpl extends BaseServiceSMO implements ILogServiceSMO
 
     private final static Logger logger = LoggerFactory.getLogger(LogServiceSMOImpl.class);
 
+    @Autowired
+    private ICodeApi codeApi;
+
     @Autowired
     private LogServiceDao logServiceDaoImpl;
 
@@ -62,6 +66,7 @@ public class LogServiceSMOImpl extends BaseServiceSMO implements ILogServiceSMO
 
         // 调用服务生成log_id
         String log_id = GenerateCodeFactory.getInnerTransactionId();
+        //String log_id = codeApi.generateCode("1000001");
 
         // 封装日志保存参数
         Map logMessageParams= new HashMap();
@@ -95,6 +100,8 @@ public class LogServiceSMOImpl extends BaseServiceSMO implements ILogServiceSMO
         logMessageParams.put("responseMessage",responseMessageObj.getString("body"));
 
         logMessageParams.put("timestamp", DateUtil.getDefaultDateFromString(logMessageObj.getString("timestamp")));
+
+        logMessageParams.put("month",DateUtil.getCurrentMonth());
     }
 
     /**
@@ -122,6 +129,13 @@ public class LogServiceSMOImpl extends BaseServiceSMO implements ILogServiceSMO
         Assert.hasKey(logMessageObj,"responseMessage","can not find responseMessage node ");
     }
 
+    public ICodeApi getCodeApi() {
+        return codeApi;
+    }
+
+    public void setCodeApi(ICodeApi codeApi) {
+        this.codeApi = codeApi;
+    }
 
     public LogServiceDao getLogServiceDaoImpl() {
         return logServiceDaoImpl;

+ 92 - 0
LogService/src/main/resources/application-dev.yml

@@ -0,0 +1,92 @@
+jedis:
+  pool:
+    config:
+      maxTotal: 100
+      maxIdle: 20
+      maxWaitMillis: 20000
+    host: 192.168.31.199
+    port: 6379
+
+eureka:
+  instance:
+    leaseRenewalIntervalInSeconds: 10
+    leaseExpirationDurationInSeconds: 30
+  client:
+    serviceUrl:
+      defaultZone: http://192.168.31.199:8761/eureka/
+      #defaultZone: http://localhost:8761/eureka/
+server:
+  port: 8004
+  tomcat:
+    uri-encoding: UTF-8
+
+spring:
+  http:
+    encoding:
+      charset: UTF-8
+      enabled: true
+      force: true
+  application:
+    name: log-service
+  redis:
+    database: 0
+    host: 192.168.31.199
+    port: 6379
+    pool:
+      max-active: 300
+      max-wait: 10000
+      max-idle: 100
+      min-idle: 0
+      timeout: 0
+  datasource:
+    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
+    minIdle: 5
+    validationQuery: SELECT 1 FROM DUAL
+    initialSize: 5
+    maxWait: 60000
+    filters: stat,wall,log4j
+    poolPreparedStatements: true
+    type: com.alibaba.druid.pool.DruidDataSource
+    url: jdbc:mysql://192.168.31.199:3306/TT?useUnicode=true&characterEncoding=utf-8
+    maxPoolPreparedStatementPerConnectionSize: 20
+    password: TT@12345678
+    testOnBorrow: false
+    testWhileIdle: true
+    minEvictableIdleTimeMillis: 300000
+    timeBetweenEvictionRunsMillis: 60000
+    testOnReturn: false
+    driverClassName: com.mysql.jdbc.Driver
+    maxActive: 20
+    username: TT
+
+#============== kafka ===================
+kafka:
+  consumer:
+    zookeeper:
+      connect: 192.168.31.199:2181
+    servers: 192.168.31.199:9092
+    enable:
+      auto:
+        commit: true
+    session:
+      timeout: 6000
+    auto:
+      commit:
+        interval: 100
+      offset:
+        reset: latest
+    topic: test
+    group:
+      id: logService
+    concurrency: 10
+
+  producer:
+    zookeeper:
+      connect: 192.168.31.199:2181
+    servers: 192.168.31.199:9092
+    retries: 0
+    batch:
+      size: 4096
+    linger: 1
+    buffer:
+      memory: 40960

+ 92 - 0
LogService/src/main/resources/application-prod.yml

@@ -0,0 +1,92 @@
+jedis:
+  pool:
+    config:
+      maxTotal: 100
+      maxIdle: 20
+      maxWaitMillis: 20000
+    host: 135.192.86.200
+    port: 6379
+
+eureka:
+  instance:
+    leaseRenewalIntervalInSeconds: 10
+    leaseExpirationDurationInSeconds: 30
+  client:
+    serviceUrl:
+      defaultZone: http://135.192.86.200:8761/eureka/
+      #defaultZone: http://localhost:8761/eureka/
+server:
+  port: 8004
+  tomcat:
+    uri-encoding: UTF-8
+
+spring:
+  http:
+    encoding:
+      charset: UTF-8
+      enabled: true
+      force: true
+  application:
+    name: log-service
+  redis:
+    database: 0
+    host: 135.192.86.200
+    port: 6379
+    pool:
+      max-active: 300
+      max-wait: 10000
+      max-idle: 100
+      min-idle: 0
+      timeout: 0
+  datasource:
+    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
+    minIdle: 5
+    validationQuery: SELECT 1 FROM DUAL
+    initialSize: 5
+    maxWait: 60000
+    filters: stat,wall,log4j
+    poolPreparedStatements: true
+    type: com.alibaba.druid.pool.DruidDataSource
+    url: jdbc:mysql://135.192.86.200:3306/TT?useUnicode=true&characterEncoding=utf-8
+    maxPoolPreparedStatementPerConnectionSize: 20
+    password: TT@12345678
+    testOnBorrow: false
+    testWhileIdle: true
+    minEvictableIdleTimeMillis: 300000
+    timeBetweenEvictionRunsMillis: 60000
+    testOnReturn: false
+    driverClassName: com.mysql.jdbc.Driver
+    maxActive: 20
+    username: TT
+
+#============== kafka ===================
+kafka:
+  consumer:
+    zookeeper:
+      connect: 135.192.86.200:2181
+    servers: 135.192.86.200:9092
+    enable:
+      auto:
+        commit: true
+    session:
+      timeout: 6000
+    auto:
+      commit:
+        interval: 100
+      offset:
+        reset: latest
+    topic: test
+    group:
+      id: logService
+    concurrency: 10
+
+  producer:
+    zookeeper:
+      connect: 135.192.86.200:2181
+    servers: 135.192.86.200:9092
+    retries: 0
+    batch:
+      size: 4096
+    linger: 1
+    buffer:
+      memory: 40960

+ 101 - 0
LogService/src/main/resources/application-test.yml

@@ -0,0 +1,101 @@
+jedis:
+  pool:
+    config:
+      maxTotal: 100
+      maxIdle: 20
+      maxWaitMillis: 20000
+    host: 135.192.86.200
+    port: 6379
+
+eureka:
+  instance:
+    leaseRenewalIntervalInSeconds: 10
+    leaseExpirationDurationInSeconds: 30
+  client:
+    serviceUrl:
+      defaultZone: http://135.192.86.200:8761/eureka/
+      #defaultZone: http://localhost:8761/eureka/
+server:
+  port: 8004
+  tomcat:
+    uri-encoding: UTF-8
+
+feign:
+  hystrix:
+    enabled: true
+  compression:
+    request:
+      enabled: true
+    response:
+      enabled: true
+
+spring:
+  http:
+    encoding:
+      charset: UTF-8
+      enabled: true
+      force: true
+  application:
+    name: log-service
+  redis:
+    database: 0
+    host: 135.192.86.200
+    port: 6379
+    pool:
+      max-active: 300
+      max-wait: 10000
+      max-idle: 100
+      min-idle: 0
+      timeout: 0
+  datasource:
+    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
+    minIdle: 5
+    validationQuery: SELECT 1 FROM DUAL
+    initialSize: 5
+    maxWait: 60000
+    filters: stat,wall,log4j
+    poolPreparedStatements: true
+    type: com.alibaba.druid.pool.DruidDataSource
+    url: jdbc:mysql://135.192.86.200:3306/TT?useUnicode=true&characterEncoding=utf-8
+    maxPoolPreparedStatementPerConnectionSize: 20
+    password: TT@12345678
+    testOnBorrow: false
+    testWhileIdle: true
+    minEvictableIdleTimeMillis: 300000
+    timeBetweenEvictionRunsMillis: 60000
+    testOnReturn: false
+    driverClassName: com.mysql.jdbc.Driver
+    maxActive: 20
+    username: TT
+
+#============== kafka ===================
+kafka:
+  consumer:
+    zookeeper:
+      connect: 135.192.86.200:2181
+    servers: 135.192.86.200:9092
+    enable:
+      auto:
+        commit: true
+    session:
+      timeout: 6000
+    auto:
+      commit:
+        interval: 100
+      offset:
+        reset: latest
+    topic: test
+    group:
+      id: logService
+    concurrency: 10
+
+  producer:
+    zookeeper:
+      connect: 135.192.86.200:2181
+    servers: 135.192.86.200:9092
+    retries: 0
+    batch:
+      size: 4096
+    linger: 1
+    buffer:
+      memory: 40960

+ 2 - 26
LogService/src/main/resources/application.yml

@@ -1,27 +1,3 @@
 spring:
-  activemq:
-    broker-url: tcp://localhost:61616
-    in-memory: true
-    enabled: false
-  jms:
-    pub-sub-domain: true
-
-jedis:
-  pool:
-    config:
-      maxTotal: 100
-      maxIdle: 20
-      maxWaitMillis: 20000
-    host: 127.0.0.1
-    port: 3306
-
-eureka:
-  client:
-    serviceUrl:
-      defaultZone: http://localhost:8761/eureka/
-server:
-  port: 8762
-spring:
-  application:
-    name: order-service
-
+  profiles:
+    active: test

+ 15 - 0
LogService/src/main/resources/banner.txt

@@ -0,0 +1,15 @@
+${AnsiColor.BRIGHT_RED}
+     __                       ____  ____ _______
+    |__|_____  ___  _______  /_   |/_   |\   _  \
+    |  |\__  \ \  \/ /\__  \  |   | |   |/  /_\  \
+    |  | / __ \_\   /  / __ \_|   | |   |\  \_/   \
+/\__|  |(____  / \_/  (____  /|___| |___| \_____  /
+\______|     \/            \/                   \/
+_________                   __                   _________                      .__
+\_   ___ \   ____    ____ _/  |_   ____ _______ /   _____/  ____ _______ ___  __|__|  ____   ____
+/    \  \/ _/ __ \  /    \\   __\_/ __ \\_  __ \\_____  \ _/ __ \\_  __ \\  \/ /|  |_/ ___\_/ __ \
+\     \____\  ___/ |   |  \|  |  \  ___/ |  | \//        \\  ___/ |  | \/ \   / |  |\  \___\  ___/
+ \______  / \___  >|___|  /|__|   \___  >|__|  /_______  / \___  >|__|     \_/  |__| \___  >\___  >
+        \/      \/      \/            \/               \/      \/                        \/     \/
+
+ java110 CenterService starting, more information scan https://github.com/java110/MicroCommunity

+ 3 - 1
LogService/src/test/java/com/java110/log/AppTest.java

@@ -1,5 +1,6 @@
 package com.java110.log;
 
+import com.java110.feign.code.ICodeApi;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -33,6 +34,7 @@ public class AppTest
      */
     public void testApp()
     {
-        assertTrue( true );
+
+        //System.out.println(ICodeApi.class.getName());
     }
 }

+ 9 - 0
java110-common/src/main/java/com/java110/common/util/DateUtil.java

@@ -64,6 +64,15 @@ public class DateUtil {
         return calendar.getTime();
     }
 
+    /**
+     * 获取当前月
+     * @return
+     */
+    public static int getCurrentMonth(){
+        Calendar calendar = Calendar.getInstance();
+        return calendar.get(Calendar.MONTH)+1;
+    }
+
     /**
      * 获取未来时间
      * @param second 秒

+ 7 - 6
java110-config/db/LogService/create_table.db

@@ -1,7 +1,7 @@
 -- 日志表
 
 create table l_transaction_log(
-    log_id varchar(30) not null keY unique COMMENT 'id',
+    log_id varchar(30) not null  COMMENT 'id',
     transaction_id VARCHAR(30) NOT NULL COMMENT '外部交易流水',
     contract_id varchar(64) not null comment '上下文ID',
     ip varchar(20) not null comment '日志产生主机IP',
@@ -15,9 +15,9 @@ create table l_transaction_log(
     timestamp TIMESTAMP NOT NULL comment '日志交互时间,时间戳',
     cost_time int not null default 0 comment '耗时',
     status_cd varchar(2) not null comment '交互状态 S 成功 F 失败',
-    month INT NOT NULL default month(CURRENT_DATE) comment '月份',
+    month INT NOT NULL comment '月份',
     create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    PRIMARY KEY (log_id)
+    unique KEY (log_id,month)
 )
 partition BY RANGE (month) (
     partition transaction_log_1 VALUES LESS THAN (2),
@@ -39,14 +39,15 @@ partition BY RANGE (month) (
 -- 日志原始内容表
 
 create table l_transaction_log_message(
-    log_id varchar(30) not null unique FOREIGN KEY REFERENCES l_transaction_log(log_id) COMMENT 'id',
+    log_id varchar(30) not null  COMMENT 'id',
     request_header LONGTEXT COMMENT '请求头信息',
     response_header LONGTEXT COMMENT '返回头信息',
     request_message LONGTEXT comment '请求报文',
     response_message LONGTEXT comment '返回报文',
     remark varchar(200) comment '备注',
-    month INT NOT NULL default month(CURRENT_DATE) comment '月份',
-    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+    month INT NOT NULL  comment '月份',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+     UNIQUE KEY (log_id,`month`)
 )
 partition BY RANGE (month) (
     partition transaction_log_message_1 VALUES LESS THAN (2),

+ 7 - 7
java110-config/src/main/resources/config/code/zookeeper.properties

@@ -1,11 +1,11 @@
-#java110.code.zookeeper.url=135.192.86.200
-#java110.code.zookeeper.port=2181
-#java110.code.zookeeper.timeOut=60000
-#java110.code.zookeeper.workDir=/java110_works
-
-
-java110.code.zookeeper.url=192.168.31.199
+java110.code.zookeeper.url=135.192.86.200
 java110.code.zookeeper.port=2181
 java110.code.zookeeper.timeOut=60000
 java110.code.zookeeper.workDir=/java110_works
 
+
+#java110.code.zookeeper.url=192.168.31.199
+#java110.code.zookeeper.port=2181
+#java110.code.zookeeper.timeOut=60000
+#java110.code.zookeeper.workDir=/java110_works
+

+ 4 - 4
java110-config/src/main/resources/mapper/log/LogServiceDaoImplMapper.xml

@@ -7,17 +7,17 @@
     <!--保存日志-->
     <insert id="saveTransactionLog" parameterType="java.util.HashMap" >
         insert into l_transaction_log
-        (log_id,transaction_id,contract_id,ip,port,src_ip,src_port,app_id,user_id,service_code,service_name,cost_time,timestamp,status_cd)
+        (log_id,transaction_id,contract_id,ip,port,src_ip,src_port,app_id,user_id,service_code,service_name,cost_time,timestamp,status_cd,month)
         values
-        (#{logId},#{transactionId},#{dataFlowId},#{ip},#{port},#{srcIp},#{srcPort},#{appId},#{userId},#{serviceCode},#{serviceName},#{costTime},#{timestamp},#{logStatus})
+        (#{logId},#{transactionId},#{dataFlowId},#{ip},#{port},#{srcIp},#{srcPort},#{appId},#{userId},#{serviceCode},#{serviceName},#{costTime},#{timestamp},#{logStatus},#{month})
     </insert>
 
     <!--保存日志(交互报文)-->
     <insert id="saveTransactionLogMessage" parameterType="java.util.HashMap" >
         insert into l_transaction_log_message
-        (log_id,request_header,response_header,request_message,response_message,remark)
+        (log_id,request_header,response_header,request_message,response_message,remark,month)
         values
-        (#{logId},#{requestHeader},#{responseHeader},#{requestMessage},#{responseMessage},#{remark})
+        (#{logId},#{requestHeader},#{responseHeader},#{requestMessage},#{responseMessage},#{remark},#{month})
     </insert>
 
 

+ 1 - 1
java110-core/src/main/java/com/java110/core/base/controller/BaseController.java

@@ -94,7 +94,7 @@ public class BaseController extends AppBase {
         headers.put("IP",getIpAddr(request));
 
         headers.put("hostName",request.getLocalName());
-        headers.put("port",request.getLocalPort());
+        headers.put("port",request.getLocalPort()+"");
 
     }
 

+ 4 - 0
java110-core/src/main/java/com/java110/core/context/AbstractDataFlowContext.java

@@ -317,6 +317,10 @@ public abstract class AbstractDataFlowContext extends AbstractTransactionLog imp
 
     }
 
+    public void setPort(String port) {
+        this.port = port;
+    }
+
     public String getbId(){
         return null;
     }

+ 8 - 2
java110-core/src/main/java/com/java110/core/context/AbstractTransactionLog.java

@@ -2,6 +2,7 @@ package com.java110.core.context;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.java110.common.factory.ApplicationContextFactory;
 import com.java110.common.log.LoggerEngine;
 import com.java110.common.util.DateUtil;
 import org.slf4j.Logger;
@@ -20,7 +21,7 @@ public abstract class AbstractTransactionLog  implements TransactionLog {
 
     private final static Logger logger = LoggerFactory.getLogger(AbstractTransactionLog.class);
 
-    private String port;
+    protected String port;
 
     private String logStatus;
 
@@ -74,6 +75,10 @@ public abstract class AbstractTransactionLog  implements TransactionLog {
 
     /**
      * 预构建
+     * 如果不是http方式请求构建的对象情况下 port 为 -1 请在创建完对象后
+     * 用这个
+     * ServiceInfoListener serviceInfoListener =  ApplicationContextFactory.getBean("serviceInfoListener",ServiceInfoListener.class);
+     * 对象刷一下 端口
      * @param reqInfo
      * @param headerAll
      */
@@ -81,8 +86,9 @@ public abstract class AbstractTransactionLog  implements TransactionLog {
 
         if(headerAll != null && headerAll.containsKey("port")){
             this.port = headerAll.get("port");
+        }else{
+            this.port = "-1";
         }
-
     }
 
     /**

+ 1 - 1
java110-core/src/main/java/com/java110/core/factory/DataFlowFactory.java

@@ -503,7 +503,7 @@ public class DataFlowFactory {
     private static JSONObject getTransactionBusinessBaseJson(DataFlow dataFlow,String businessType){
         JSONObject notifyMessage = JSONObject.parseObject("{\"orders\":{},\"business\":{}}");
         JSONObject orders = notifyMessage.getJSONObject("orders");
-        orders.put("transactionId", GenerateCodeFactory.getTransactionId());
+        orders.put("transactionId", UUID.randomUUID().toString().replace("-",""));
         orders.put("dataFlowId",dataFlow.getDataFlowId());
         orders.put("orderTypeCd",dataFlow.getOrderTypeCd());
         orders.put("requestTime",DateUtil.getyyyyMMddhhmmssDateString());

+ 3 - 3
java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java

@@ -50,7 +50,7 @@ public class GenerateCodeFactory {
         prefixMap.put("transactionId","1000001");
         prefixMap.put("pageTransactionId","1000002");
         prefixMap.put("dataFlowId","2000");
-        prefixMap.put("userId","3000");
+        prefixMap.put("userId","30");
     }
 
     private static String PLATFORM_CODE = "0001";
@@ -177,7 +177,7 @@ public class GenerateCodeFactory {
 
     public static String getUserId()  throws GenerateCodeException{
         if(!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))){
-            return prefixMap.get("userId") + nextId("%08d");
+            return prefixMap.get("userId") +DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H)+ nextId("%06d");
         }
         //调用服务
         return getCode(prefixMap.get("userId"));
@@ -207,7 +207,7 @@ public class GenerateCodeFactory {
      */
     private static ICodeApi codeApi() throws NoSuchObjectException{
 
-        Object bean = ApplicationContextFactory.getBean("codeApi");
+        Object bean = ApplicationContextFactory.getBean(ICodeApi.class.getName());
 
         if(bean == null){
             throw new NoSuchObjectException("codeApi,请核实");

+ 5 - 1
java110-feign/pom.xml

@@ -27,7 +27,11 @@
         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-feign</artifactId>
-            <scope>provided</scope>
+        </dependency>
+        <!-- 整合ribbon -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-ribbon</artifactId>
         </dependency>
     </dependencies>
 </project>

+ 5 - 1
java110-feign/src/main/java/com/java110/feign/code/CodeApiFallback.java

@@ -2,12 +2,15 @@ package com.java110.feign.code;
 
 import com.java110.common.constant.ResponseConstant;
 import com.java110.common.util.ProtocolUtil;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
 /**
  * 调用用户服务失败时,返回
  * Created by wuxw on 2017/4/5.
  */
+@Component
 public class CodeApiFallback implements ICodeApi{
 
 
@@ -17,7 +20,8 @@ public class CodeApiFallback implements ICodeApi{
      * @return
      */
     @Override
-    public String generateCode(String prefix) {
+    @RequestMapping("/codeApi/generateCode")
+    public String generateCode(@RequestParam("prefix") String prefix) {
         return ResponseConstant.RESULT_CODE_ERROR;
     }
 }

+ 5 - 1
java110-feign/src/main/java/com/java110/feign/code/ICodeApi.java

@@ -1,6 +1,9 @@
 package com.java110.feign.code;
 
 import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 
 /**
  * Created by wuxw on 2018/6/15.
@@ -13,5 +16,6 @@ public interface ICodeApi {
      * @param prefix 前缀
      * @return
      */
-    public String generateCode(String prefix);
+    @RequestMapping(value = "/codeApi/generateCode",method = RequestMethod.POST)
+    public String generateCode(@RequestParam("prefix") String prefix);
 }

+ 1 - 1
java110-logAgent/src/main/java/com/java110/log/agent/LogAgent.java

@@ -77,7 +77,7 @@ public class LogAgent extends LoggerEngine{
         if(Assert.isJsonObject(body)){
             JSONObject bodyObj = JSONObject.parseObject(body);
 
-            Object codeNode = JSONPath.eval(body,"$.orders.response.code");
+            Object codeNode = JSONPath.eval(bodyObj,"$.orders.response.code");
             //判断订单是否成功
             if(codeNode != null && ResponseConstant.RESULT_CODE_SUCCESS.equals(codeNode.toString())){
                 //判断业务是否受理成功个,如果有一个业务受理失败,则认为失败

+ 7 - 2
java110-logAgent/src/test/java/com/java110/AppTest.java

@@ -2,6 +2,8 @@ package com.java110;
 
 import static org.junit.Assert.assertTrue;
 
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.JSONPath;
 import com.java110.core.context.DataFlow;
 import com.java110.core.context.TransactionLog;
 import org.junit.Test;
@@ -25,9 +27,12 @@ public class AppTest
 
     @Test
     public void testDataFlow(){
-        TransactionLog transactionLog = new DataFlow(new Date(),"0000");
+        /*TransactionLog transactionLog = new DataFlow(new Date(),"0000");
         transactionLog.reBuilder("234","234324","F",0);
 
-        System.out.println(transactionLog.toString());
+        System.out.println(transactionLog.toString());*/
+
+        JSONObject order = JSONObject.parseObject("{\"orders\":{\"response1\":{\"code\":\"1999\"}}}");
+        System.out.println(JSONPath.eval(order,"$.orders.response.code"));
     }
 }