| | |
| | | package com.java110.center.smo.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.common.cache.ServiceSqlCache; |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.exception.SMOException; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | import com.java110.entity.center.AppRoute; |
| | | import com.java110.entity.mapping.Mapping; |
| | | import com.java110.entity.service.DataQuery; |
| | | import com.java110.entity.service.ServiceSql; |
| | | import com.java110.service.dao.IQueryServiceDAO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Autowired |
| | | ICenterServiceDAO centerServiceDAOImpl; |
| | | |
| | | @Autowired |
| | | IQueryServiceDAO queryServiceDAOImpl; |
| | | |
| | | @Override |
| | | public void flush() { |
| | | public void flush(DataQuery dataQuery) throws SMOException{ |
| | | |
| | | |
| | | |
| | | //1.0 封装 AppRoute |
| | | flushAppRoute(); |
| | | flushAppRoute(dataQuery); |
| | | |
| | | //2.0 分装 Mapping |
| | | flushMapping(); |
| | | flushMapping(dataQuery); |
| | | |
| | | //3.0 分装 ServiceSql |
| | | flushServiceSql(dataQuery); |
| | | |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS,"刷新成功")); |
| | | } |
| | | |
| | | /** |
| | | * 用来系统启动刷新 |
| | | */ |
| | | @Override |
| | | public void startFlush() { |
| | | //1.0 封装 AppRoute |
| | | doFlushAppRoute(); |
| | | |
| | | //2.0 分装 Mapping |
| | | doFlushMapping(); |
| | | |
| | | //3.0 分装 ServiceSql |
| | | doFlushServiceSql(); |
| | | } |
| | | |
| | | private void checkCacheParam(DataQuery dataQuery) throws SMOException{ |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | if(params == null || !params.containsKey(CommonConstant.CACHE_PARAM_NAME)){ |
| | | throw new SMOException(ResponseConstant.RESULT_PARAM_ERROR,"请求报文错误,未包含字段 "+CommonConstant.CACHE_PARAM_NAME); |
| | | } |
| | | } |
| | | /** |
| | | * 3.0 分装 ServiceSql |
| | | */ |
| | | private void flushServiceSql(DataQuery dataQuery) { |
| | | |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | if(!CommonConstant.CACHE_SERVICE_SQL.equals(params.getString(CommonConstant.CACHE_PARAM_NAME))){ |
| | | return ; |
| | | } |
| | | // 刷新 |
| | | doFlushServiceSql(); |
| | | } |
| | | |
| | | private void doFlushServiceSql() { |
| | | List<ServiceSql> serviceSqls = queryServiceDAOImpl.qureyServiceSqlAll(); |
| | | |
| | | if(serviceSqls == null || serviceSqls.size() == 0){ |
| | | return; |
| | | } |
| | | //删除原始数据 |
| | | ServiceSqlCache.removeData(ServiceSqlCache._SUFFIX_SERVICE_SQL); |
| | | |
| | | for(ServiceSql serviceSql: serviceSqls){ |
| | | ServiceSqlCache.setServiceSql(serviceSql); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新 Mapping 数据 |
| | | */ |
| | | private void flushMapping() { |
| | | private void flushMapping(DataQuery dataQuery) { |
| | | |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | |
| | | if(!CommonConstant.CACHE_MAPPING.equals(params.getString(CommonConstant.CACHE_PARAM_NAME))){ |
| | | return ; |
| | | } |
| | | |
| | | doFlushMapping(); |
| | | } |
| | | |
| | | private void doFlushMapping() { |
| | | List<Mapping> mappings = centerServiceDAOImpl.getMappingInfoAll(); |
| | | |
| | | //删除原始数据 |
| | | MappingCache.removeData(MappingCache._SUFFIX_MAPPING); |
| | | for(Mapping mapping : mappings){ |
| | | MappingCache.setVaule(mapping); |
| | | } |
| | |
| | | /** |
| | | * 刷新AppRoute数据 |
| | | */ |
| | | private void flushAppRoute(){ |
| | | private void flushAppRoute(DataQuery dataQuery){ |
| | | |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | |
| | | if(!CommonConstant.CACHE_APP_ROUTE_SERVICE.equals(params.getString(CommonConstant.CACHE_PARAM_NAME))){ |
| | | return ; |
| | | } |
| | | doFlushAppRoute(); |
| | | |
| | | } |
| | | |
| | | private void doFlushAppRoute() { |
| | | List<Map> appInfos = centerServiceDAOImpl.getAppRouteAndServiceInfoAll(); |
| | | Map<String,List<AppRoute>> appRoustsMap = new HashMap<String,List<AppRoute>>(); |
| | | List<AppRoute> appRoutes = null; |
| | |
| | | appRoustsMap.put(appInfo.get("app_id").toString(),appRoutes); |
| | | } |
| | | } |
| | | //删除原始数据 |
| | | AppRouteCache.removeData(AppRouteCache._SUFFIX_APP_ROUTE); |
| | | |
| | | for (String appId : appRoustsMap.keySet()) { |
| | | AppRouteCache.setAppRoute(appRoustsMap.get(appId)); |
| | | } |
| | | |
| | | } |
| | | |
| | | public ICenterServiceDAO getCenterServiceDAOImpl() { |
| | |
| | | public void setCenterServiceDAOImpl(ICenterServiceDAO centerServiceDAOImpl) { |
| | | this.centerServiceDAOImpl = centerServiceDAOImpl; |
| | | } |
| | | |
| | | public IQueryServiceDAO getQueryServiceDAOImpl() { |
| | | return queryServiceDAOImpl; |
| | | } |
| | | |
| | | public void setQueryServiceDAOImpl(IQueryServiceDAO queryServiceDAOImpl) { |
| | | this.queryServiceDAOImpl = queryServiceDAOImpl; |
| | | } |
| | | } |