ソースを参照

20180418测试

wuxw7 8 年 前
コミット
ea3bded6c8

+ 14 - 0
CenterService/src/main/java/com/java110/center/dao/ICenterServiceDAO.java

@@ -1,6 +1,7 @@
 package com.java110.center.dao;
 
 import com.java110.common.exception.DAOException;
+import com.java110.entity.mapping.Mapping;
 
 import java.util.List;
 import java.util.Map;
@@ -83,4 +84,17 @@ public interface ICenterServiceDAO {
      * @throws DAOException
      */
     public List<Map> getCommonOrderCompledBusinessByBId(String bId) throws DAOException;
+
+    /**
+     * 查询所有组件
+     * @return
+     */
+    public List<Map> getAppRouteAndServiceInfoAll();
+
+    /**
+     * 查询映射表
+     * @return
+     */
+    public List<Mapping> getMappingInfoAll();
+
 }

+ 18 - 0
CenterService/src/main/java/com/java110/center/dao/impl/CenterServiceDAOImpl.java

@@ -6,6 +6,7 @@ import com.java110.common.constant.ResponseConstant;
 import com.java110.common.exception.DAOException;
 import com.java110.common.log.LoggerEngine;
 import com.java110.core.base.dao.BaseServiceDao;
+import com.java110.entity.mapping.Mapping;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -171,4 +172,21 @@ public class CenterServiceDAOImpl extends BaseServiceDao implements ICenterServi
         LoggerEngine.debug("----【CenterServiceDAOImpl.getCommonOrderCompledBusinessByBId】数据入参 : " + bId);
         return sqlSessionTemplate.selectList("centerServiceDAOImpl.getCommonOrderCompledBusinessByBId",bId);
     }
+
+    @Override
+    public List<Map> getAppRouteAndServiceInfoAll() {
+        return sqlSessionTemplate.selectList("centerServiceDAOImpl.getAppInfoAll");
+    }
+
+
+    /**
+     * 查询映射表
+     * @return
+     */
+    @Override
+    public List<Mapping> getMappingInfoAll() {
+        return sqlSessionTemplate.selectList("centerServiceDAOImpl.getMappingInfoAll");
+    }
+
+
 }

+ 48 - 0
CenterService/src/main/java/com/java110/center/rest/CacheApi.java

@@ -0,0 +1,48 @@
+package com.java110.center.rest;
+
+import com.java110.center.smo.ICenterServiceCacheSMO;
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.util.ResponseTemplateUtil;
+import com.java110.core.base.controller.BaseController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 主要提供给内部刷缓存用
+ * Created by wuxw on 2018/4/18.
+ */
+@RestController
+public class CacheApi extends BaseController{
+    @Autowired
+    ICenterServiceCacheSMO centerServiceCacheSMOImpl;
+
+    @RequestMapping(path = "/cacheApi/flush",method= RequestMethod.GET)
+    public String flushGet(HttpServletRequest request) {
+        return ResponseTemplateUtil.createOrderResponseJson(ResponseConstant.NO_TRANSACTION_ID,
+                ResponseConstant.NO_NEED_SIGN,ResponseConstant.RESULT_CODE_ERROR,"不支持Get方法请求").toJSONString();
+    }
+
+    @RequestMapping(path = "/cacheApi/flush",method= RequestMethod.POST)
+    public String flushPost(HttpServletRequest request) {
+        try {
+            centerServiceCacheSMOImpl.flush();
+        }catch (Exception e){
+            return ResponseTemplateUtil.createOrderResponseJson(ResponseConstant.NO_TRANSACTION_ID,
+                    ResponseConstant.NO_NEED_SIGN,ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString();
+        }
+        return ResponseTemplateUtil.createOrderResponseJson(ResponseConstant.NO_TRANSACTION_ID,
+                ResponseConstant.NO_NEED_SIGN,ResponseConstant.RESULT_CODE_SUCCESS,"成功").toJSONString();
+    }
+
+    public ICenterServiceCacheSMO getCenterServiceCacheSMOImpl() {
+        return centerServiceCacheSMOImpl;
+    }
+
+    public void setCenterServiceCacheSMOImpl(ICenterServiceCacheSMO centerServiceCacheSMOImpl) {
+        this.centerServiceCacheSMOImpl = centerServiceCacheSMOImpl;
+    }
+}

+ 12 - 0
CenterService/src/main/java/com/java110/center/smo/ICenterServiceCacheSMO.java

@@ -0,0 +1,12 @@
+package com.java110.center.smo;
+
+/**
+ * Created by wuxw on 2018/4/18.
+ */
+public interface ICenterServiceCacheSMO {
+
+    /**
+     * 刷新 缓存
+     */
+    public void flush();
+}

+ 98 - 0
CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceCacheSMOImpl.java

@@ -0,0 +1,98 @@
+package com.java110.center.smo.impl;
+
+import com.java110.center.dao.ICenterServiceDAO;
+import com.java110.center.smo.ICenterServiceCacheSMO;
+import com.java110.common.cache.AppRouteCache;
+import com.java110.common.cache.MappingCache;
+import com.java110.entity.center.AppRoute;
+import com.java110.entity.mapping.Mapping;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 刷新缓存
+ * Created by wuxw on 2018/4/18.
+ */
+@Service("centerServiceCacheSMOImpl")
+public class CenterServiceCacheSMOImpl implements ICenterServiceCacheSMO {
+
+    @Autowired
+    ICenterServiceDAO centerServiceDAOImpl;
+
+    @Override
+    public void flush() {
+
+        //1.0 封装 AppRoute
+        flushAppRoute();
+
+        //2.0 分装 Mapping
+        flushMapping();
+    }
+
+    /**
+     * 刷新 Mapping 数据
+     */
+    private void flushMapping() {
+
+        List<Mapping> mappings = centerServiceDAOImpl.getMappingInfoAll();
+
+        for(Mapping mapping : mappings){
+            MappingCache.setVaule(mapping);
+        }
+
+        Map<String,List<Mapping>> mappingMap = new HashMap<String,List<Mapping>>();
+        List<Mapping> mappingsNew = null;
+        for(Mapping mapping : mappings){
+            if(mappingMap.containsKey(mapping.getDomain())){
+                mappingsNew = mappingMap.get(mapping.getDomain());
+                mappingsNew.add(mapping);
+            }else{
+                mappingsNew = new ArrayList<Mapping>();
+                mappingsNew.add(mapping);
+                mappingMap.put(mapping.getDomain(),mappingsNew);
+            }
+        }
+
+        for (String domain : mappingMap.keySet()) {
+            MappingCache.setValue(mappingMap.get(domain));
+        }
+    }
+
+    /**
+     * 刷新AppRoute数据
+     */
+    private void flushAppRoute(){
+
+        List<Map> appInfos = centerServiceDAOImpl.getAppRouteAndServiceInfoAll();
+        Map<String,List<AppRoute>> appRoustsMap = new HashMap<String,List<AppRoute>>();
+        List<AppRoute> appRoutes = null;
+        for(Map appInfo : appInfos){
+            if(appRoustsMap.containsKey(appInfo.get("app_id").toString())){
+                appRoutes = appRoustsMap.get(appInfo.get("app_id").toString());
+                appRoutes.add(AppRoute.newInstance().builder(appInfo));
+            }else{
+                appRoutes = new ArrayList<AppRoute>();
+                appRoutes.add(AppRoute.newInstance().builder(appInfo));
+                appRoustsMap.put(appInfo.get("app_id").toString(),appRoutes);
+            }
+        }
+
+        for (String appId : appRoustsMap.keySet()) {
+            AppRouteCache.setAppRoute(appRoustsMap.get(appId));
+        }
+
+    }
+
+    public ICenterServiceDAO getCenterServiceDAOImpl() {
+        return centerServiceDAOImpl;
+    }
+
+    public void setCenterServiceDAOImpl(ICenterServiceDAO centerServiceDAOImpl) {
+        this.centerServiceDAOImpl = centerServiceDAOImpl;
+    }
+}

+ 16 - 13
CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java

@@ -22,8 +22,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
-import javax.print.DocFlavor;
-import java.util.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 中心服务处理类
@@ -123,14 +124,16 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
     private void initConfigData(DataFlow dataFlow) {
         Date startDate = DateUtil.getCurrentDate();
         //查询配置信息,并将配置信息封装到 dataFlow 对象中
-        AppRoute appRoute = AppRouteCache.getAppRoute(dataFlow.getAppId());
+        List<AppRoute> appRoutes = AppRouteCache.getAppRoute(dataFlow.getAppId());
 
-        if (appRoute == null) {
+        if (appRoutes == null) {
             //添加耗时
             DataFlowFactory.addCostTime(dataFlow, "initConfigData", "加载配置耗时", startDate);
             throw new InitConfigDataException(ResponseConstant.RESULT_CODE_INNER_ERROR,"当前没有获取到AppId对应的信息");
         }
-        dataFlow.setAppRoute(appRoute);
+        for(AppRoute appRoute: appRoutes) {
+            dataFlow.addAppRoutes(appRoute);
+        }
         //
         if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){
             dataFlow.setDataFlowId(SequenceUtil.getDataFlowId());
@@ -149,7 +152,7 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
     private void judgeAuthority(DataFlow dataFlow) throws NoAuthorityException {
         Date startDate = DateUtil.getCurrentDate();
 
-        if (StringUtil.isNullOrNone(dataFlow.getAppId()) || dataFlow.getAppRoute() == null) {
+        if (StringUtil.isNullOrNone(dataFlow.getAppId()) || dataFlow.getAppRoutes().size() == 0 ) {
             //添加耗时
             DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate);
             throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "appId 为空或不正确");
@@ -195,7 +198,7 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
         }
 
         //检验白名单
-        List<String> whileListIp = dataFlow.getAppRoute().getWhileListIp();
+        List<String> whileListIp = dataFlow.getAppRoutes().get(0).getWhileListIp();
         if (whileListIp != null && !whileListIp.contains(dataFlow.getIp())) {
             //添加耗时
             DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate);
@@ -203,7 +206,7 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
         }
 
         //检查黑名单
-        List<String> backListIp = dataFlow.getAppRoute().getBackListIp();
+        List<String> backListIp = dataFlow.getAppRoutes().get(0).getBackListIp();
         if (backListIp != null && backListIp.contains(dataFlow.getIp())) {
             //添加耗时
             DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate);
@@ -337,12 +340,12 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
     private void invalidCompletedBusinessSystem(DataFlow dataFlow) throws Exception{
         // 根据 c_business 表中的字段business_type_cd 找到对应的消息队列名称
         List<Map> completedBusinesses = centerServiceDaoImpl.getCommonOrderCompledBusinessByBId(dataFlow.getBusinesses().get(0).getbId());
-        for(AppServiceStatus serviceStatus :dataFlow.getAppRoute().getAppServices()){
+        for(AppRoute appRoute :dataFlow.getAppRoutes()){
             for(Map completedBusiness : completedBusinesses){
-                if(completedBusiness.get("business_type_cd").equals(serviceStatus.getAppService().getBusinessTypeCd())){
-                    KafkaFactory.sendKafkaMessage(serviceStatus.getAppService().getMessageQueueName(),"",
-                            DataFlowFactory.getCompletedBusinessErrorJson(dataFlow,completedBusiness,serviceStatus.getAppService()));
-                    saveLogMessage(DataFlowFactory.getCompletedBusinessErrorJson(dataFlow,completedBusiness,serviceStatus.getAppService()),null);
+                if(completedBusiness.get("business_type_cd").equals(appRoute.getAppService().getBusinessTypeCd())){
+                    KafkaFactory.sendKafkaMessage(appRoute.getAppService().getMessageQueueName(),"",
+                            DataFlowFactory.getCompletedBusinessErrorJson(dataFlow,completedBusiness,appRoute.getAppService()));
+                    saveLogMessage(DataFlowFactory.getCompletedBusinessErrorJson(dataFlow,completedBusiness,appRoute.getAppService()),null);
                 }
             }
         }

+ 33 - 3
java110-bean/src/main/java/com/java110/entity/center/AppRoute.java

@@ -3,6 +3,7 @@ package com.java110.entity.center;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  *
@@ -31,7 +32,8 @@ public class AppRoute implements Serializable{
     private List<String> backListIp = new ArrayList<String>();
 
     //服务
-    private List<AppServiceStatus> appServices = new ArrayList<AppServiceStatus>();
+    //private List<AppServiceStatus> appServices = new ArrayList<AppServiceStatus>();
+    private AppService appService;
 
     private String remark;
 
@@ -95,12 +97,20 @@ public class AppRoute implements Serializable{
         this.backListIp.add(backIp);
     }
 
-    public List<AppServiceStatus> getAppServices() {
+    /*public List<AppServiceStatus> getAppServices() {
         return appServices;
     }
 
     public void addAppServices(AppServiceStatus appServiceStatus) {
         this.appServices.add(appServiceStatus);
+    }*/
+
+    public AppService getAppService() {
+        return appService;
+    }
+
+    public void setAppService(AppService appService) {
+        this.appService = appService;
     }
 
     public String getRemark() {
@@ -123,12 +133,32 @@ public class AppRoute implements Serializable{
      * 构建数据
      * @return
      */
-    public AppRoute builder(){
+    public AppRoute builder(Map appInfo){
+        String []listIps = null;
+        this.setAppId(appInfo.get("app_id").toString());
+        this.setLimitTimes(appInfo.get("invoke_limit_times") == null ? -1 : Integer.parseInt(appInfo.get("invoke_limit_times").toString()));
+        this.setName(appInfo.get("name").toString());
+        this.setOrderTypeCd(appInfo.get("order_type_cd").toString());
+        this.setSecurityCode(appInfo.get("security_code").toString());
+        if(appInfo.get("while_list_ip") != null && !"".equals(appInfo.get("while_list_ip"))){
+            listIps = appInfo.get("while_list_ip").toString().split(";");
+            for(String whileIp : listIps )
+                this.addWhileListIp(whileIp);
+        }
+        if(appInfo.get("black_list_ip") != null && !"".equals(appInfo.get("black_list_ip"))){
+            listIps = appInfo.get("black_list_ip").toString().split(";");
+            for(String backIp : listIps )
+                this.addBackListIp(backIp);
+        }
+        this.setAppService(AppService.newInstance().builder(appInfo));
         return this;
     }
 
 
 
+    public static AppRoute newInstance(){
+        return new AppRoute();
+    }
 
 
 }

+ 20 - 0
java110-bean/src/main/java/com/java110/entity/center/AppService.java

@@ -1,6 +1,7 @@
 package com.java110.entity.center;
 
 import java.io.Serializable;
+import java.util.Map;
 
 /**
  * 提供服务
@@ -131,5 +132,24 @@ public class AppService implements Serializable{
         this.messageQueueName = messageQueueName;
     }
 
+    public AppService builder(Map serviceInfo){
+        this.setBusinessTypeCd(serviceInfo.get("business_type_cd").toString());
+        this.setInvokeModel(serviceInfo.get("invoke_model").toString());
+        this.setMessageQueueName(serviceInfo.get("messageQueueName") == null ? null :serviceInfo.get("messageQueueName").toString());
+        this.setMethod(serviceInfo.get("method")==null ? null:serviceInfo.get("method").toString());
+        this.setName(serviceInfo.get("name").toString());
+        this.setRetryCount(Integer.parseInt(serviceInfo.get("retry_count").toString()));
+        this.setSeq(Integer.parseInt(serviceInfo.get("seq").toString()));
+        this.setServiceCode(serviceInfo.get("service_code").toString());
+        this.setTimeOut(Integer.parseInt(serviceInfo.get("timeout").toString()));
+        this.setUrl(serviceInfo.get("url") == null ? null : serviceInfo.get("url").toString());
+        this.setServiceId(Integer.parseInt(serviceInfo.get("service_id").toString()));
+        return this;
+    }
+
+    public static AppService newInstance(){
+        return new AppService();
+    }
+
 
 }

+ 12 - 2
java110-bean/src/main/java/com/java110/entity/center/DataFlow.java

@@ -67,7 +67,9 @@ public class DataFlow {
 
     private Map<String,String> headers = new HashMap<String,String>();
 
-    private AppRoute appRoute;
+    /*private AppRoute appRoute;*/
+
+    private List<AppRoute> appRoutes = new ArrayList<AppRoute>();
     //请求业务系统报文
     private JSONObject requestBusinessJson;
 
@@ -258,12 +260,20 @@ public class DataFlow {
         return headers;
     }
 
-    public AppRoute getAppRoute() {
+    /*public AppRoute getAppRoute() {
         return appRoute;
     }
 
     public void setAppRoute(AppRoute appRoute) {
         this.appRoute = appRoute;
+    }*/
+
+    public List<AppRoute> getAppRoutes() {
+        return appRoutes;
+    }
+
+    public void addAppRoutes(AppRoute appRoute) {
+        this.appRoutes.add(appRoute);
     }
 
     public String getIp() {

+ 10 - 11
java110-common/src/main/java/com/java110/common/cache/AppRouteCache.java

@@ -3,6 +3,8 @@ package com.java110.common.cache;
 import com.java110.common.util.SerializeUtil;
 import com.java110.entity.center.AppRoute;
 
+import java.util.List;
+
 /**
  * 路由配置
  * Created by wuxw on 2018/4/14.
@@ -14,26 +16,23 @@ public class AppRouteCache extends BaseCache {
      * @param appId
      * @return
      */
-    public static AppRoute getAppRoute(String appId){
-        AppRoute appRoute = null;
+    public static List<AppRoute> getAppRoute(String appId){
+        List<AppRoute> appRoutes = null;
 
-            Object object = SerializeUtil.unserialize(getJedis().get(appId.getBytes()));
-            if(object == null)
-            {
+            appRoutes = SerializeUtil.unserializeList(getJedis().get(appId.getBytes()),AppRoute.class);
+            if(appRoutes == null || appRoutes.size() ==0) {
                 return null;
             }
-            appRoute = (AppRoute) object;
-
 
-        return appRoute;
+        return appRoutes;
     }
 
 
     /**
      * 保存路由信息
-     * @param appRoute
+     * @param appRoutes
      */
-    public static void setAppRoute(AppRoute appRoute){
-        getJedis().set(appRoute.getAppId().getBytes(),SerializeUtil.serialize(appRoute));
+    public static void setAppRoute(List<AppRoute> appRoutes){
+        getJedis().set(appRoutes.get(0).getAppId().getBytes(),SerializeUtil.serializeList(appRoutes));
     }
 }

+ 1 - 1
java110-common/src/main/java/com/java110/common/cache/MappingCache.java

@@ -60,7 +60,7 @@ public class MappingCache extends BaseCache {
      * @param mappings
      */
     public static void setValue(List<Mapping> mappings){
-        getJedis().set((mappings.get(0).getDomain()+mappings.get(0).getKey()).getBytes(),SerializeUtil.serializeList(mappings));
+        getJedis().set((mappings.get(0).getDomain()).getBytes(),SerializeUtil.serializeList(mappings));
     }
 
 

+ 7 - 6
java110-common/src/main/java/com/java110/common/factory/DataFlowFactory.java

@@ -23,6 +23,7 @@ public class DataFlowFactory {
         return new DataFlow(DateUtil.getCurrentDate(), ResponseConstant.RESULT_CODE_SUCCESS);
     }
 
+
     /**
      * 添加耗时
      * @param dataFlow 数据流
@@ -64,15 +65,15 @@ public class DataFlowFactory {
      * @return
      */
     public static AppService getService(DataFlow dataFlow, String serviceCode){
-        if (dataFlow.getAppRoute() == null){
+        if (dataFlow.getAppRoutes().size() == 0){
             throw new RuntimeException("当前没有获取到AppId对应的信息");
         }
 
-        List<AppServiceStatus> serviceStatuses = dataFlow.getAppRoute().getAppServices();
-        for(AppServiceStatus serviceStatus : serviceStatuses) {
-            if (StatusConstant.STATUS_CD_VALID.equals(serviceStatus.getStatusCd())
-                    &&serviceStatus.getAppService().getServiceCode().equals(serviceCode)){
-                return serviceStatus.getAppService();
+        List<AppRoute> appRoutes = dataFlow.getAppRoutes();
+        for(AppRoute appRoute : appRoutes) {
+            if (StatusConstant.STATUS_CD_VALID.equals(appRoute.getStatusCd())
+                    &&appRoute.getAppService().getServiceCode().equals(serviceCode)){
+                return appRoute.getAppService();
             }
         }
         return null;

+ 137 - 116
java110-config/db/CenterService/create_table.db

@@ -1,161 +1,182 @@
---c_orders
-
-create table c_orders(
-    o_id varchar(18) not null COMMENT '订单ID',
-    app_id varchar(10) not null comment '应用ID',
-    ext_transaction_id varchar(30) not null comment '外部交易流水',
-    user_id varchar(12) not null comment '用户ID',
-    request_time varchar(16) not null comment '外部系统请求时间',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    order_type_cd varchar(4) not null comment '订单类型,参考c_order_type表',
-    finish_time timestamp comment '订单完成时间',
-    remark varchar(200) comment '备注',
-    status_cd varchar(2) not null comment '数据状态,详细参考c_status表'
+-- c_orders
+
+CREATE TABLE c_orders(
+    o_id VARCHAR(18) NOT NULL COMMENT '订单ID',
+    app_id VARCHAR(10) NOT NULL COMMENT '应用ID',
+    ext_transaction_id VARCHAR(30) NOT NULL COMMENT '外部交易流水',
+    user_id VARCHAR(12) NOT NULL COMMENT '用户ID',
+    request_time VARCHAR(16) NOT NULL COMMENT '外部系统请求时间',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    order_type_cd VARCHAR(4) NOT NULL COMMENT '订单类型,参考c_order_type表',
+    finish_time DATE COMMENT '订单完成时间',
+    remark VARCHAR(200) COMMENT '备注',
+    status_cd VARCHAR(2) NOT NULL COMMENT '数据状态,详细参考c_status表'
 );
 
---c_orders_attrs
+-- c_orders_attrs
 
-create table c_orders_attrs(
-    o_id varchar(18) not null COMMENT '订单ID',
-    attr_id varchar(18) not null comment '属性id',
-    spec_cd varchar(12) not null comment '规格id,参考spec表',
-    value varchar(50) not null comment '属性值'
+CREATE TABLE c_orders_attrs(
+    o_id VARCHAR(18) NOT NULL COMMENT '订单ID',
+    attr_id VARCHAR(18) NOT NULL COMMENT '属性id',
+    spec_cd VARCHAR(12) NOT NULL COMMENT '规格id,参考spec表',
+    VALUE VARCHAR(50) NOT NULL COMMENT '属性值'
 );
 
 -- c_business
 
-create table c_business(
-    b_id varchar(18) not null comment '业务Id',
-    o_id varchar(18) not null COMMENT '订单ID',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    business_type_cd varchar(4) not null comment '业务项类型,参考c_business_type表',
-    finish_time timestamp comment '完成时间',
-    remark varchar(200) comment '备注',
-    status_cd varchar(2) not null comment '数据状态,详细参考c_status表'
+CREATE TABLE c_business(
+    b_id VARCHAR(18) NOT NULL COMMENT '业务Id',
+    o_id VARCHAR(18) NOT NULL COMMENT '订单ID',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    business_type_cd VARCHAR(4) NOT NULL COMMENT '业务项类型,参考c_business_type表',
+    finish_time DATE COMMENT '完成时间',
+    remark VARCHAR(200) COMMENT '备注',
+    status_cd VARCHAR(2) NOT NULL COMMENT '数据状态,详细参考c_status表'
 );
 
 --c_orders_attrs
 
-create table c_business_attrs(
-    b_id varchar(18) not null COMMENT '订单ID',
-    attr_id varchar(18) not null comment '属性id',
-    spec_cd varchar(12) not null comment '规格id,参考spec表',
-    value varchar(50) not null comment '属性值'
+CREATE TABLE c_business_attrs(
+    b_id VARCHAR(18) NOT NULL COMMENT '订单ID',
+    attr_id VARCHAR(18) NOT NULL COMMENT '属性id',
+    spec_cd VARCHAR(12) NOT NULL COMMENT '规格id,参考spec表',
+    VALUE VARCHAR(50) NOT NULL COMMENT '属性值'
 );
 
---c_status
+-- c_status
 
-create table c_status(
-    id int not null auto_increment comment 'id',
-    status_cd varchar(4) not null comment '状态',
-    name varchar(50) not null comment '名称',
-    description varchar(200) comment '描述',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+CREATE TABLE c_status(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    status_cd VARCHAR(4) NOT NULL COMMENT '状态',
+    `name` VARCHAR(50) NOT NULL COMMENT '名称',
+    description VARCHAR(200) COMMENT '描述',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
 );
 
-insert into c_status(status_cd,name,description) values('1','无效的,不在用的','无效的,不在用的');
-insert into c_status(status_cd,name,description) values('0','有效的,在用的','有效的,在用的');
-insert into c_status(status_cd,name,description) values('S','保存成功','保存成功');
-insert into c_status(status_cd,name,description) values('D','作废订单','作废订单');
-insert into c_status(status_cd,name,description) values('E','错误订单','错误订单');
-insert into c_status(status_cd,name,description) values('NE','通知错误订单','通知错误订单');
-insert into c_status(status_cd,name,description) values('C','错误订单','错误订单');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('1','无效的,不在用的','无效的,不在用的');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('0','有效的,在用的','有效的,在用的');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('S','保存成功','保存成功');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('D','作废订单','作废订单');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('E','错误订单','错误订单');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('NE','通知错误订单','通知错误订单');
+INSERT INTO c_status(status_cd,NAME,description) VALUES('C','错误订单','错误订单');
 
 --c_order_type
 
-create table c_order_type(
-    id int not null auto_increment comment 'id',
-    order_type_cd varchar(4) not null comment '订单类型',
-    name varchar(50) not null comment '名称',
-    description varchar(200) comment '描述',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+CREATE TABLE c_order_type(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    order_type_cd VARCHAR(4) NOT NULL COMMENT '订单类型',
+    `name` VARCHAR(50) NOT NULL COMMENT '名称',
+    description VARCHAR(200) COMMENT '描述',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
 );
 
---c_business_type
 
-create table c_order_type(
-    id int not null auto_increment comment 'id',
-    order_type_cd varchar(4) not null comment '业务项类型',
-    name varchar(50) not null comment '名称',
-    description varchar(200) comment '描述',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+-- c_business_type
+
+CREATE TABLE c_business_type(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    business_type_cd VARCHAR(4) NOT NULL COMMENT '业务项类型',
+    `name` VARCHAR(50) NOT NULL COMMENT '名称',
+    description VARCHAR(200) COMMENT '描述',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
 );
 
---c_business_type
+-- spec
 
-create table spec(
-    id int not null auto_increment comment 'id',
-    spec_cd varchar(4) not null comment '业务项类型规格编码,从x00020001开始每次加一就可以(约定,x=10表示c_orders_attrs 中属性,x=11表示c_business_attrs 中的属性)',
-    name varchar(50) not null comment '名称',
-    description varchar(200) comment '描述',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
+CREATE TABLE spec(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    spec_cd VARCHAR(4) NOT NULL COMMENT '业务项类型规格编码,从x00020001开始每次加一就可以(约定,x=10表示c_orders_attrs 中属性,x=11表示c_business_attrs 中的属性)',
+    `name` VARCHAR(50) NOT NULL COMMENT '名称',
+    description VARCHAR(200) COMMENT '描述',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
 );
 
 -- c_route
 
-create table c_route(
-    id int not null auto_increment comment 'id',
-    app_id varchar(10) not null comment '应用ID',
-    service_id int not null comment '下游接口配置ID',
-    order_type_cd varchar(4) not null comment '订单类型,参考c_order_type表',
-    invoke_limit_times int comment '接口调用一分钟调用次数',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    status_cd varchar(2) not null comment '数据状态,详细参考c_status表,0在用,1失效,2 表示下线(当组件调用服务超过限制时自动下线)'
+CREATE TABLE c_route(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    app_id VARCHAR(10) NOT NULL COMMENT '应用ID',
+    service_id INT NOT NULL COMMENT '下游接口配置ID',
+    order_type_cd VARCHAR(4) NOT NULL COMMENT '订单类型,参考c_order_type表',
+    invoke_limit_times INT COMMENT '接口调用一分钟调用次数',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    status_cd VARCHAR(2) NOT NULL COMMENT '数据状态,详细参考c_status表,0在用,1失效,2 表示下线(当组件调用服务超过限制时自动下线)'
 );
 
+
+
 -- c_service
 
-create table c_service(
-    service_id int not null auto_increment comment 'id',
-    service_code varchar(50) not null comment '自定义,命名方式查询类query.+目标系统+.+业务名称 保存类 save.+目标系统+.+业务名称 修改类 modify.+目标系统+.+业务名称 删除类 remove.+目标系统+.+业务名称 例如:query.user.userinfo save.user.adduserinfo',
-    invoke_model varchar(1) not null comment '1-同步方式 2-异步方式',
-    business_type_cd varchar(4) not null comment '业务项类型,参考c_business_type表',
-    name varchar(50) not null comment '服务名称',
-    seq int not null comment '顺序 只有同步方式下根据seq从小到大调用接口',
-    messageQueueName varchar(50) comment '消息队里名称 只有异步时有用',
-    url varchar(200) comment '目标地址',
-    method varchar(50) comment '方法 空 为http post LOCAL_SERVICE 为调用本地服务 其他为webservice方式调用',
-    timeout int not null DEFAULT 60 comment '超时时间',
-    retry_count int not null DEFAULT 3 comment '重试次数',
-    provide_app_id varchar(10) not null comment '应用ID',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    status_cd varchar(2) not null comment '数据状态,详细参考c_status表,0在用,1失效'
+CREATE TABLE c_service(
+    service_id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    service_code VARCHAR(50) NOT NULL COMMENT '自定义,命名方式查询类query.+目标系统+.+业务名称 保存类 save.+目标系统+.+业务名称 修改类 modify.+目标系统+.+业务名称 删除类 remove.+目标系统+.+业务名称 例如:query.user.userinfo save.user.adduserinfo',
+    invoke_model VARCHAR(1) NOT NULL COMMENT '1-同步方式 2-异步方式',
+    business_type_cd VARCHAR(4) NOT NULL COMMENT '业务项类型,参考c_business_type表',
+    `name` VARCHAR(50) NOT NULL COMMENT '服务名称',
+    seq INT NOT NULL COMMENT '顺序 只有同步方式下根据seq从小到大调用接口',
+    messageQueueName VARCHAR(50) COMMENT '消息队里名称 只有异步时有用',
+    url VARCHAR(200) COMMENT '目标地址',
+    method VARCHAR(50) COMMENT '方法 空 为http post LOCAL_SERVICE 为调用本地服务 其他为webservice方式调用',
+    timeout INT NOT NULL DEFAULT 60 COMMENT '超时时间',
+    retry_count INT NOT NULL DEFAULT 3 COMMENT '重试次数',
+    provide_app_id VARCHAR(10) NOT NULL COMMENT '应用ID',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    status_cd VARCHAR(2) NOT NULL default '0' COMMENT '数据状态,详细参考c_status表,0在用,1失效'
 );
 
+
+
 -- c_mapping
 
-create table c_mapping(
-    id int not null auto_increment comment 'id',
-    domain varchar(50) not null comment '域',
-    name varchar(50) not null comment '名称',
-    key varchar(100) not null comment 'key',
-    value varchar(100) not null comment 'value',
-    remark varchar(200) comment '描述',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    status_cd varchar(2) not null default '0' comment '数据状态,详细参考c_status表,0在用,1失效'
+CREATE TABLE c_mapping(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    domain VARCHAR(50) NOT NULL COMMENT '域',
+    `name` VARCHAR(50) NOT NULL COMMENT '名称',
+    `key` VARCHAR(100) NOT NULL COMMENT 'key',
+    `value` VARCHAR(100) NOT NULL COMMENT 'value',
+    remark VARCHAR(200) COMMENT '描述',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    status_cd VARCHAR(2) NOT NULL DEFAULT '0' COMMENT '数据状态,详细参考c_status表,0在用,1失效'
 );
 
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','日志开关','LOG_ON_OFF','ON','日志开关')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','耗时开关','COST_TIME_ON_OFF','ON','耗时开关')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','规则开关','RULE_ON_OFF','OFF','规则开关')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','不调规则服务的订单类型','NO_NEED_RULE_VALDATE_ORDER','Q','不调规则服务的订单类型')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','不保存订单信息','NO_SAVE_ORDER','Q','不保存订单信息')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','不用调用 下游系统的配置','NO_INVOKE_BUSINESS_SYSTEM','Q','不用调用 下游系统的配置(一般不存在这种情况,这里主要是在没有下游系统的情况下测试中心服务用)')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','不用调用 作废下游系统的配置','NO_INVALID_BUSINESS_SYSTEM','Q','不用调用 作废下游系统的配置 (一般不存在这种情况,这里主要是在没有下游系统的情况下测试中心服务用)')
-insert c_mapping(domain,name,key,value,remark) values('DOMAIN.COMMON','需要调用服务生成各个ID','NEED_INVOKE_SERVICE_GENERATE_ID','OFF','需要调用服务生成各个ID')
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','日志开关','LOG_ON_OFF','ON','日志开关');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','耗时开关','COST_TIME_ON_OFF','ON','耗时开关');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','规则开关','RULE_ON_OFF','OFF','规则开关');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','不调规则服务的订单类型','NO_NEED_RULE_VALDATE_ORDER','Q','不调规则服务的订单类型');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','不保存订单信息','NO_SAVE_ORDER','Q','不保存订单信息');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','不用调用 下游系统的配置','NO_INVOKE_BUSINESS_SYSTEM','Q','不用调用 下游系统的配置(一般不存在这种情况,这里主要是在没有下游系统的情况下测试中心服务用)');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','不用调用 作废下游系统的配置','NO_INVALID_BUSINESS_SYSTEM','Q','不用调用 作废下游系统的配置 (一般不存在这种情况,这里主要是在没有下游系统的情况下测试中心服务用)');
+INSERT c_mapping(domain,`name`,`key`,`value`,remark) VALUES('DOMAIN.COMMON','需要调用服务生成各个ID','NEED_INVOKE_SERVICE_GENERATE_ID','OFF','需要调用服务生成各个ID');
 
 -- c_app
-create table c_app(
-    id int not null auto_increment comment 'id',
-    app_id varchar(10) not null comment '应用ID',
-    name varchar(50) not null comment '名称 对应系统名称',
-    security_code varchar(64) not null comment '签名码 sign签名时用',
-    while_list_ip varchar(200) comment '白名单ip 多个之间用;隔开',
-    black_list_ip varchar(200) comment '黑名单ip 多个之间用;隔开',
-    remark varchar(200) comment '描述',
-    create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-    status_cd varchar(2) not null comment '数据状态,详细参考c_status表,0在用,1失效'
+CREATE TABLE c_app(
+    id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id',
+    app_id VARCHAR(10) NOT NULL COMMENT '应用ID',
+    `name` VARCHAR(50) NOT NULL COMMENT '名称 对应系统名称',
+    security_code VARCHAR(64) NOT NULL COMMENT '签名码 sign签名时用',
+    while_list_ip VARCHAR(200) COMMENT '白名单ip 多个之间用;隔开',
+    black_list_ip VARCHAR(200) COMMENT '黑名单ip 多个之间用;隔开',
+    remark VARCHAR(200) COMMENT '描述',
+    create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    status_cd VARCHAR(2) NOT NULL COMMENT '数据状态,详细参考c_status表,0在用,1失效'
+);
+
+-- 测试用
+
+insert into c_order_type(order_type_cd,`name`,description) values('Q','查询单','查询单');
+
+insert into c_app(app_id,`name`,security_code,remark,status_cd)
+values('8000418001','内部测试应用','WEBURFPKIFJUHNCJUEIKMKJUJHULSMNCHDY89KMC','记得删除','0');
+
+insert into c_route(app_id,service_id,order_type_cd,status_cd) values(
+'8000418001','1','Q','0'
 );
 
+insert into c_service(service_code,invoke_model,business_type_cd,`name`,seq,url,provide_app_id,status_cd)
+values('query.user.userInfo','1','Q','用户信息查询',1,'http://...','8000418001','0');
+
+
+
 
 

+ 3 - 3
java110-config/src/main/resources/db/db.properties

@@ -1,9 +1,9 @@
 #数据库设置
 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource  
 spring.datasource.driverClassName=com.mysql.jdbc.Driver  
-spring.datasource.url=jdbc:mysql://localhost:3306/mydatabases  
-spring.datasource.username=root  
-spring.datasource.password=123  
+spring.datasource.url=jdbc:mysql://192.168.31.199:3306/TT  
+spring.datasource.username=TT  
+spring.datasource.password=TT@12345678  
 #--------------------------
 # 下面为连接池的补充设置,应用到上面所有数据源中
 # 初始化大小,最小,最大

+ 21 - 0
java110-config/src/main/resources/mapper/center/CenterServiceDAOImplMapper.xml

@@ -91,5 +91,26 @@
             )
         ]]>
     </select>
+    <!--查询 所有有效 app信息-->
+    <select id="getAppRouteAndServiceInfoAll" resultType="Map">
+        <![CDATA[
+             SELECT ca.app_id,ca.name,ca.security_code,ca.while_list_ip,ca.black_list_ip,cr.invoke_limit_times,
+            cr.order_type_cd,cs.service_id,cs.business_type_cd,cs.invoke_model,
+            cs.messageQueueName,cs.method,cs.name,cs.provide_app_id,cs.retry_count,cs.seq,cs.service_code,
+            cs.timeout,cs.url FROM c_app ac,c_route cr,c_service cs
+            WHERE ac.status_cd = '0'
+            AND ac.app_id = cr.app_id
+            AND cr.status_cd = '0'
+            AND cr.service_id = cs.service_id
+            AND cs.status_cd = '0'
+        ]]>
+
+    </select>
+
+    <select id="getMappingInfoAll" resultType="com.java110.entity.mapping.Mapping">
+        <![CDATA[
+             SELECT cm.domain,cm.name,cm.key,cm.value,cm.remark from c_mapping cm where cm.status_cd = '0'
+        ]]>
+    </select>
 
 </mapper>