| | |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-swagger2</artifactId> |
| | | <groupId>com.java110</groupId> |
| | | <artifactId>java110-event</artifactId> |
| | | </dependency> |
| | | <!-- swagger-ui --> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-swagger-ui</artifactId> |
| | | </dependency> |
| | | |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>junit</groupId> |
| | |
| | | package com.java110.api; |
| | | |
| | | import com.java110.core.annotation.Java110ListenerDiscovery; |
| | | import com.java110.event.service.api.ServiceDataFlowEventPublishing; |
| | | import com.java110.service.init.ServiceStartInit; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | |
| | | * @date 2016年8月6日 |
| | | * @tag |
| | | */ |
| | | @SpringBootApplication(scanBasePackages={"com.java110.service","com.java110.api","com.java110.core","com.java110.event.center","com.java110.cache"}) |
| | | @SpringBootApplication(scanBasePackages={"com.java110.service","com.java110.api","com.java110.core","com.java110.event.service.api","com.java110.cache"}) |
| | | @EnableDiscoveryClient |
| | | |
| | | @Java110ListenerDiscovery(listenerPublishClass = ServiceDataFlowEventPublishing.class, |
| | | basePackages = {"com.java110.api.listener"}) |
| | | @EnableSwagger2 |
| | | //@EnableConfigurationProperties(EventProperties.class) |
| | | public class ApiApplicationStart { |
| | |
| | | |
| | | |
| | | public static void main(String[] args) throws Exception{ |
| | | SpringApplication.run(ApiApplicationStart.class, args); |
| | | ApplicationContext context = SpringApplication.run(ApiApplicationStart.class, args); |
| | | |
| | | //服务启动加载 |
| | | ServiceStartInit.initSystemConfig(context); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package com.java110.api.listener; |
| | | |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.entity.center.AppService; |
| | | import com.java110.event.service.api.ServiceDataFlowListener; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.HttpServerErrorException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | /** |
| | | * Created by wuxw on 2018/11/15. |
| | | */ |
| | | public abstract class AbstractServiceApiDataFlowListener implements ServiceDataFlowListener { |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplateNoLoadBalanced; |
| | | |
| | | /** |
| | | * 请求落地方 |
| | | * @param dataFlowContext |
| | | * @param service |
| | | * @param httpEntity |
| | | */ |
| | | protected void doRequest(DataFlowContext dataFlowContext, AppService service, HttpEntity<String> httpEntity) { |
| | | |
| | | ResponseEntity responseEntity= null; |
| | | //配置c_service 时请注意 如果是以out 开头的调用外部的地址 |
| | | RestTemplate tmpRestTemplate = service.getServiceCode().startsWith("out.")?restTemplateNoLoadBalanced:restTemplate; |
| | | |
| | | try { |
| | | if (CommonConstant.HTTP_METHOD_GET.equals(service.getMethod())) { |
| | | String requestUrl = dataFlowContext.getRequestHeaders().get("REQUEST_URL"); |
| | | if (!StringUtil.isNullOrNone(requestUrl)) { |
| | | String param = requestUrl.contains("?") ? requestUrl.substring(requestUrl.indexOf("?"), requestUrl.length()) : ""; |
| | | if (service.getUrl().contains("?")) { |
| | | requestUrl = service.getUrl() + "&" + param; |
| | | } else { |
| | | requestUrl = service.getUrl() + "?" + param; |
| | | } |
| | | } |
| | | responseEntity = tmpRestTemplate.exchange(requestUrl, HttpMethod.GET, httpEntity, String.class); |
| | | } else if (CommonConstant.HTTP_METHOD_PUT.equals(service.getMethod())) { |
| | | responseEntity = tmpRestTemplate.exchange(service.getUrl(), HttpMethod.PUT, httpEntity, String.class); |
| | | } else if (CommonConstant.HTTP_METHOD_DELETE.equals(service.getMethod())) { |
| | | String requestUrl = dataFlowContext.getRequestHeaders().get("REQUEST_URL"); |
| | | if (!StringUtil.isNullOrNone(requestUrl)) { |
| | | String param = requestUrl.contains("?") ? requestUrl.substring(requestUrl.indexOf("?"), requestUrl.length()) : ""; |
| | | if (service.getUrl().contains("?")) { |
| | | requestUrl = service.getUrl() + "&" + param; |
| | | } else { |
| | | requestUrl = service.getUrl() + "?" + param; |
| | | } |
| | | } |
| | | responseEntity = tmpRestTemplate.exchange(requestUrl, HttpMethod.DELETE, httpEntity, String.class); |
| | | } else { |
| | | responseEntity = tmpRestTemplate.exchange(service.getUrl(), HttpMethod.POST, httpEntity, String.class); |
| | | } |
| | | }catch (HttpServerErrorException e){ |
| | | responseEntity = new ResponseEntity<String>("请求下游系统异常异常,"+e.getResponseBodyAsString(),e.getStatusCode()); |
| | | |
| | | } |
| | | |
| | | dataFlowContext.setResponseEntity(responseEntity); |
| | | } |
| | | |
| | | |
| | | public RestTemplate getRestTemplate() { |
| | | return restTemplate; |
| | | } |
| | | |
| | | public void setRestTemplate(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | |
| | | public RestTemplate getRestTemplateNoLoadBalanced() { |
| | | return restTemplateNoLoadBalanced; |
| | | } |
| | | |
| | | public void setRestTemplateNoLoadBalanced(RestTemplate restTemplateNoLoadBalanced) { |
| | | this.restTemplateNoLoadBalanced = restTemplateNoLoadBalanced; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.api.listener; |
| | | |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.constant.ServiceCodeConstant; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.annotation.Java110Listener; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.entity.center.AppService; |
| | | import com.java110.event.service.api.ServiceDataFlowEvent; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | /** |
| | | * 保存 用户信息 侦听 |
| | | * Created by wuxw on 2018/5/18. |
| | | */ |
| | | @Java110Listener("transferServiceListener") |
| | | public class TransferServiceListener extends AbstractServiceApiDataFlowListener{ |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(TransferServiceListener.class); |
| | | |
| | | |
| | | |
| | | @Override |
| | | public String getServiceCode() { |
| | | return ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int getOrder() { |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void soService(ServiceDataFlowEvent event) { |
| | | //获取数据上下文对象 |
| | | DataFlowContext dataFlowContext = event.getDataFlowContext(); |
| | | AppService service = event.getAppService(); |
| | | String paramIn = dataFlowContext.getReqData(); |
| | | HttpHeaders header = new HttpHeaders(); |
| | | for(String key : dataFlowContext.getRequestCurrentHeaders().keySet()){ |
| | | header.add(key,dataFlowContext.getRequestCurrentHeaders().get(key)); |
| | | } |
| | | HttpEntity<String> httpEntity = new HttpEntity<String>(paramIn, header); |
| | | //http://user-service/test/sayHello |
| | | super.doRequest(dataFlowContext, service, httpEntity); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | package com.java110.api.rest; |
| | | |
| | | import com.java110.api.smo.IApiServiceSMO; |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.core.base.controller.BaseController; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * |
| | |
| | | */ |
| | | @RestController |
| | | |
| | | @Api(value = "Rest Api 用户服务") |
| | | @RequestMapping(path = "/rest") |
| | | public class RestApi { |
| | | @RequestMapping(path = "/api") |
| | | @Api(value = "对外统一提供服务接口服务") |
| | | public class RestApi extends BaseController { |
| | | |
| | | |
| | | @Autowired |
| | | private IApiServiceSMO apiServiceSMOImpl; |
| | | /** |
| | | * 健康检查 服务 |
| | | * @return |
| | | */ |
| | | @RequestMapping(path = "/health",method = RequestMethod.GET) |
| | | @ApiOperation(value="服务健康检查", notes="test: 返回 2XX 表示服务正常") |
| | | //@ApiImplicitParam(paramType="query", name = "userNumber", value = "用户编号", required = true, dataType = "Integer") |
| | | public String health(){ |
| | | return ""; |
| | | } |
| | | |
| | | @ApiOperation(value="保存用户信息", notes="test: res_code 为0000表示成功,其他表示失败") |
| | | @ApiImplicitParam(paramType="save", name = "info", value = "用户编号", required = true, dataType = "String") |
| | | @RequestMapping(path = "/saveUser",method = RequestMethod.PUT) |
| | | public String saveUser(@RequestParam("info") String info){ |
| | | return "{}"; |
| | | |
| | | /** |
| | | * 资源请求 post方式 |
| | | * @param service 请求接口方式 |
| | | * @param postInfo post内容 |
| | | * @param request 请求对象 查询头信息 url等信息 |
| | | * @return http status 200 成功 其他失败 |
| | | */ |
| | | |
| | | @RequestMapping(path = "/{service:.+}",method = RequestMethod.POST ) |
| | | @ApiOperation(value="资源post请求", notes="test: 返回 2XX 表示服务正常") |
| | | @ApiImplicitParam(paramType="query", name = "method", value = "用户编号", required = true, dataType = "String") |
| | | public ResponseEntity<String> servicePost(@PathVariable String service, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request){ |
| | | ResponseEntity<String> responseEntity = null; |
| | | try { |
| | | Map<String, String> headers = new HashMap<String, String>(); |
| | | this.getRequestInfo(request, headers); |
| | | headers.put(CommonConstant.HTTP_SERVICE,service); |
| | | headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_POST); |
| | | responseEntity = apiServiceSMOImpl.service(postInfo,headers); |
| | | }catch (Throwable e){ |
| | | logger.error("请求post 方法["+service+"]失败:",e); |
| | | return new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } |
| | | |
| | | return responseEntity; |
| | | } |
| | | |
| | | /** |
| | | * 资源请求 get方式 |
| | | * @param service 请求接口方式 |
| | | * @param request 请求对象 查询头信息 url等信息 |
| | | * @return http status 200 成功 其他失败 |
| | | */ |
| | | |
| | | @RequestMapping(path = "/{service:.+}",method = RequestMethod.GET ) |
| | | @ApiOperation(value="资源get请求", notes="test: 返回 2XX 表示服务正常") |
| | | @ApiImplicitParam(paramType="query", name = "service", value = "用户编号", required = true, dataType = "String") |
| | | public ResponseEntity<String> serviceGet(@PathVariable String service, |
| | | HttpServletRequest request){ |
| | | ResponseEntity<String> responseEntity = null; |
| | | try { |
| | | Map<String, String> headers = new HashMap<String, String>(); |
| | | this.getRequestInfo(request, headers); |
| | | headers.put(CommonConstant.HTTP_SERVICE,service); |
| | | headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_GET); |
| | | responseEntity = apiServiceSMOImpl.service("",headers); |
| | | }catch (Throwable e){ |
| | | logger.error("请求get 方法["+service+"]失败:",e); |
| | | return new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } |
| | | |
| | | return responseEntity; |
| | | } |
| | | |
| | | /** |
| | | * 资源请求 put方式 |
| | | * @param service 请求接口方式 |
| | | * @param postInfo 修改内容 |
| | | * @param request 请求对象 查询头信息 url等信息 |
| | | * @return http status 200 成功 其他失败 |
| | | */ |
| | | |
| | | @RequestMapping(path = "/{service:.+}",method = RequestMethod.PUT ) |
| | | @ApiOperation(value="资源put请求", notes="test: 返回 2XX 表示服务正常") |
| | | @ApiImplicitParam(paramType="query", name = "service", value = "用户编号", required = true, dataType = "String") |
| | | public ResponseEntity<String> servicePut(@PathVariable String service, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request){ |
| | | ResponseEntity<String> responseEntity = null; |
| | | try { |
| | | Map<String, String> headers = new HashMap<String, String>(); |
| | | this.getRequestInfo(request, headers); |
| | | headers.put(CommonConstant.HTTP_SERVICE,service); |
| | | headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_PUT); |
| | | responseEntity = apiServiceSMOImpl.service(postInfo,headers); |
| | | }catch (Throwable e){ |
| | | logger.error("请求put 方法["+service+"]失败:",e); |
| | | return new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } |
| | | |
| | | return responseEntity; |
| | | } |
| | | |
| | | /** |
| | | * 资源请求 delete方式 |
| | | * @param service 请求接口方式 |
| | | * @param request 请求对象 查询头信息 url等信息 |
| | | * @return http status 200 成功 其他失败 |
| | | */ |
| | | |
| | | @RequestMapping(path = "/{service:.+}",method = RequestMethod.DELETE ) |
| | | @ApiOperation(value="资源delete请求", notes="test: 返回 2XX 表示服务正常") |
| | | @ApiImplicitParam(paramType="query", name = "method", value = "用户编号", required = true, dataType = "String") |
| | | public ResponseEntity<String> serviceDelete(@PathVariable String service, |
| | | HttpServletRequest request){ |
| | | ResponseEntity<String> responseEntity = null; |
| | | try { |
| | | Map<String, String> headers = new HashMap<String, String>(); |
| | | this.getRequestInfo(request, headers); |
| | | headers.put(CommonConstant.HTTP_SERVICE,service); |
| | | headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_DELETE); |
| | | responseEntity = apiServiceSMOImpl.service("",headers); |
| | | }catch (Throwable e){ |
| | | logger.error("请求delete 方法["+service+"]失败:",e); |
| | | return new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } |
| | | |
| | | return responseEntity; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取请求信息 |
| | | * @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); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | |
| | | public IApiServiceSMO getApiServiceSMOImpl() { |
| | | return apiServiceSMOImpl; |
| | | } |
| | | |
| | | public void setApiServiceSMOImpl(IApiServiceSMO apiServiceSMOImpl) { |
| | | this.apiServiceSMOImpl = apiServiceSMOImpl; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.api.smo; |
| | | |
| | | import com.java110.common.exception.SMOException; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 中心服务 SMO 业务逻辑接口 |
| | | * Created by wuxw on 2018/4/13. |
| | | */ |
| | | public interface IApiServiceSMO { |
| | | |
| | | /** |
| | | * 业务统一处理服务方法 |
| | | * @param reqJson 请求报文json |
| | | * @return |
| | | */ |
| | | public ResponseEntity<String> service(String reqJson, Map<String, String> headers) throws SMOException; |
| | | } |
| New file |
| | |
| | | package com.java110.api.smo.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.api.smo.IApiServiceSMO; |
| | | 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.kafka.KafkaFactory; |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.context.ApiDataFlow; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.core.factory.DataFlowFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.entity.center.AppRoute; |
| | | import com.java110.entity.center.AppService; |
| | | import com.java110.entity.center.DataFlowLinksCost; |
| | | import com.java110.event.service.api.ServiceDataFlowEventPublishing; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import org.apache.commons.lang3.math.NumberUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * 中心服务处理类 |
| | | * Created by wuxw on 2018/4/13. |
| | | */ |
| | | @Service("apiServiceSMOImpl") |
| | | //@Transactional |
| | | public class ApiServiceSMOImpl extends LoggerEngine implements IApiServiceSMO { |
| | | |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplateNoLoadBalanced; |
| | | |
| | | @Autowired |
| | | private IQueryServiceSMO queryServiceSMOImpl; |
| | | |
| | | /** |
| | | * 服务调度 |
| | | * @param reqJson 请求报文json |
| | | * @param headers |
| | | * @return |
| | | * @throws SMOException |
| | | */ |
| | | @Override |
| | | public ResponseEntity<String> service(String reqJson, Map<String, String> headers) throws SMOException{ |
| | | |
| | | ApiDataFlow dataFlow = null; |
| | | |
| | | //JSONObject responseJson = null; |
| | | |
| | | ResponseEntity<String> responseEntity = null; |
| | | |
| | | String resJson = ""; |
| | | |
| | | try { |
| | | //在post和 put 时才存在报文加密的情况 |
| | | if("POST,PUT".contains(headers.get(CommonConstant.HTTP_METHOD))){ |
| | | reqJson = decrypt(reqJson,headers); |
| | | } |
| | | |
| | | //1.0 创建数据流 |
| | | dataFlow = DataFlowFactory.newInstance(ApiDataFlow.class).builder(reqJson,headers); |
| | | |
| | | //2.0 加载配置信息 |
| | | initConfigData(dataFlow); |
| | | |
| | | //3.0 校验 APPID是否有权限操作serviceCode |
| | | judgeAuthority(dataFlow); |
| | | |
| | | //6.0 调用下游系统 |
| | | invokeBusinessSystem(dataFlow); |
| | | |
| | | responseEntity = dataFlow.getResponseEntity(); |
| | | |
| | | } catch (DecryptException e){ //解密异常 |
| | | responseEntity = new ResponseEntity<String>("解密异常:"+e.getMessage(), HttpStatus.NON_AUTHORITATIVE_INFORMATION); |
| | | }catch (BusinessException e) { |
| | | responseEntity = new ResponseEntity<String>("业务处理异常:"+e.getMessage(), HttpStatus.BAD_REQUEST); |
| | | } catch (NoAuthorityException e) { |
| | | responseEntity = new ResponseEntity<String>("鉴权失败:"+e.getMessage(), HttpStatus.UNAUTHORIZED); |
| | | } catch (InitConfigDataException e){ |
| | | responseEntity = new ResponseEntity<String>("初始化失败:"+e.getMessage(), HttpStatus.BAD_REQUEST); |
| | | }catch (Exception e) { |
| | | logger.error("内部异常:",e); |
| | | responseEntity = new ResponseEntity<String>("内部异常:"+e.getMessage()+e.getLocalizedMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | |
| | | } finally { |
| | | if(dataFlow != null) { |
| | | //这里记录日志 |
| | | Date endDate = DateUtil.getCurrentDate(); |
| | | |
| | | dataFlow.setEndDate(endDate); |
| | | //添加耗时 |
| | | //DataFlowFactory.addCostTime(dataFlow, "service", "业务处理总耗时", dataFlow.getStartDate(), dataFlow.getEndDate()); |
| | | //保存耗时 |
| | | //saveCostTimeLogMessage(dataFlow); |
| | | //处理返回报文鉴权 |
| | | //AuthenticationFactory.putSign(dataFlow); |
| | | } |
| | | if (responseEntity == null){ |
| | | //resJson = encrypt(responseJson.toJSONString(),headers); |
| | | responseEntity = new ResponseEntity<String>(resJson, HttpStatus.OK); |
| | | } |
| | | //这里保存耗时,以及日志 |
| | | return responseEntity; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 抒写返回头信息 |
| | | * @param dataFlow |
| | | */ |
| | | private void putResponseHeader(DataFlow dataFlow,Map<String,String> headers) { |
| | | headers.put("responseTime", DateUtil.getDefaultFormateTimeString(new Date())); |
| | | headers.put("transactionId",dataFlow.getTransactionId()); |
| | | } |
| | | |
| | | /** |
| | | * 解密 |
| | | * @param reqJson |
| | | * @return |
| | | */ |
| | | private String decrypt(String reqJson,Map<String,String> headers) throws DecryptException{ |
| | | try { |
| | | if (MappingConstant.VALUE_ON.equals(headers.get(CommonConstant.ENCRYPT))) { |
| | | logger.debug("解密前字符:" + reqJson); |
| | | reqJson = new String(AuthenticationFactory.decrypt(reqJson.getBytes("UTF-8"), AuthenticationFactory.loadPrivateKey(MappingConstant.KEY_PRIVATE_STRING) |
| | | , NumberUtils.isNumber(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) ? Integer.parseInt(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) : |
| | | Integer.parseInt(MappingCache.getValue(MappingConstant.KEY_DEFAULT_DECRYPT_KEY_SIZE))),"UTF-8"); |
| | | logger.debug("解密后字符:" + reqJson); |
| | | } |
| | | }catch (Exception e){ |
| | | throw new DecryptException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR,"解密失败"); |
| | | } |
| | | |
| | | return reqJson; |
| | | } |
| | | |
| | | /** |
| | | * 加密 |
| | | * @param resJson |
| | | * @param headers |
| | | * @return |
| | | */ |
| | | private String encrypt(String resJson,Map<String,String> headers){ |
| | | try { |
| | | if (MappingConstant.VALUE_ON.equals(headers.get(CommonConstant.ENCRYPT))) { |
| | | logger.debug("加密前字符:" + resJson); |
| | | resJson = new String(AuthenticationFactory.encrypt(resJson.getBytes("UTF-8"), AuthenticationFactory.loadPubKey(MappingConstant.KEY_PUBLIC_STRING) |
| | | , NumberUtils.isNumber(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) ? Integer.parseInt(headers.get(CommonConstant.ENCRYPT_KEY_SIZE)) : |
| | | Integer.parseInt(MappingCache.getValue(MappingConstant.KEY_DEFAULT_DECRYPT_KEY_SIZE))),"UTF-8"); |
| | | logger.debug("加密后字符:" + resJson); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("加密失败:",e); |
| | | } |
| | | return resJson; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 2.0初始化配置信息 |
| | | * |
| | | * @param dataFlow |
| | | */ |
| | | private void initConfigData(ApiDataFlow dataFlow) { |
| | | Date startDate = DateUtil.getCurrentDate(); |
| | | //查询配置信息,并将配置信息封装到 dataFlow 对象中 |
| | | List<AppRoute> appRoutes = AppRouteCache.getAppRoute(dataFlow.getAppId()); |
| | | |
| | | if (appRoutes == null) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "initConfigData", "加载配置耗时", startDate); |
| | | throw new InitConfigDataException(ResponseConstant.RESULT_CODE_INNER_ERROR,"当前没有获取到AppId对应的信息,appId = "+dataFlow.getAppId()); |
| | | } |
| | | for(AppRoute appRoute: appRoutes) { |
| | | dataFlow.addAppRoutes(appRoute); |
| | | } |
| | | // |
| | | if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){ |
| | | dataFlow.setDataFlowId(GenerateCodeFactory.getDataFlowId()); |
| | | } |
| | | |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "initConfigData", "加载配置耗时", startDate); |
| | | } |
| | | |
| | | /** |
| | | * 3.0判断 AppId 是否 有serviceCode权限 |
| | | * |
| | | * @param dataFlow |
| | | * @throws RuntimeException |
| | | */ |
| | | private void judgeAuthority(ApiDataFlow dataFlow) throws NoAuthorityException { |
| | | Date startDate = DateUtil.getCurrentDate(); |
| | | |
| | | if (StringUtil.isNullOrNone(dataFlow.getAppId()) || dataFlow.getAppRoutes().size() == 0 ) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "APP_ID 为空或不正确"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrNone(dataFlow.getTransactionId())) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "TRANSACTION_ID 不能为空"); |
| | | } |
| | | |
| | | if(!StringUtil.isNullOrNone(dataFlow.getAppRoutes().get(0).getSecurityCode())){ |
| | | String sign = AuthenticationFactory.apiDataFlowMd5(dataFlow); |
| | | if(!sign.equals(dataFlow.getReqSign().toLowerCase())){ |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "签名失败"); |
| | | } |
| | | } |
| | | |
| | | if (StringUtil.isNullOrNone(dataFlow.getRequestTime()) || !DateUtil.judgeDate(dataFlow.getRequestTime(), DateUtil.DATE_FORMATE_STRING_DEFAULT)) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "requestTime 格式不对,遵循yyyyMMddHHmmss格式"); |
| | | } |
| | | |
| | | |
| | | //判断 AppId 是否有权限操作相应的服务 |
| | | AppService appService = DataFlowFactory.getService(dataFlow, dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |
| | | |
| | | //这里调用缓存 查询缓存信息 |
| | | if (appService == null) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "AppId 没有权限访问 serviceCode = " + dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |
| | | } |
| | | |
| | | //检验白名单 |
| | | List<String> whileListIp = dataFlow.getAppRoutes().get(0).getWhileListIp(); |
| | | if (whileListIp != null && whileListIp.size() > 0 && !whileListIp.contains(dataFlow.getIp())) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "当前IP被限制不能访问服务"); |
| | | } |
| | | |
| | | //检查黑名单 |
| | | List<String> backListIp = dataFlow.getAppRoutes().get(0).getBackListIp(); |
| | | if (backListIp != null && backListIp.size() > 0&& backListIp.contains(dataFlow.getIp())) { |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "当前IP被限制不能访问服务"); |
| | | } |
| | | //添加耗时 |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 6.0 调用下游系统 |
| | | * |
| | | * @param dataFlow |
| | | * @throws BusinessException |
| | | */ |
| | | private void invokeBusinessSystem(ApiDataFlow dataFlow) throws BusinessException { |
| | | Date startDate = DateUtil.getCurrentDate(); |
| | | //拿到当前服务 |
| | | AppService appService = DataFlowFactory.getService(dataFlow, dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |
| | | //这里对透传类处理 |
| | | if("NT".equals(appService.getIsInstance())){ |
| | | dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER); |
| | | }else{ |
| | | dataFlow.setApiCurrentService(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |
| | | } |
| | | ServiceDataFlowEventPublishing.multicastEvent(dataFlow,appService); |
| | | DataFlowFactory.addCostTime(dataFlow, "invokeBusinessSystem", "调用下游系统耗时", startDate); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 保存日志信息 |
| | | * @param requestJson |
| | | */ |
| | | private void saveLogMessage(String requestJson,String responseJson){ |
| | | |
| | | try{ |
| | | if(MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_LOG_ON_OFF))){ |
| | | JSONObject log = new JSONObject(); |
| | | log.put("request",requestJson); |
| | | log.put("response",responseJson); |
| | | KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_LOG_NAME,"",log.toJSONString()); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("报错日志出错了,",e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存耗时信息 |
| | | * @param dataFlow |
| | | */ |
| | | private void saveCostTimeLogMessage(DataFlow dataFlow){ |
| | | try{ |
| | | if(MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_COST_TIME_ON_OFF))){ |
| | | List<DataFlowLinksCost> dataFlowLinksCosts = dataFlow.getLinksCostDates(); |
| | | JSONObject costDate = new JSONObject(); |
| | | JSONArray costDates = new JSONArray(); |
| | | JSONObject newObj = null; |
| | | for(DataFlowLinksCost dataFlowLinksCost : dataFlowLinksCosts){ |
| | | newObj = JSONObject.parseObject(JSONObject.toJSONString(dataFlowLinksCost)); |
| | | newObj.put("dataFlowId",dataFlow.getDataFlowId()); |
| | | newObj.put("transactionId",dataFlow.getTransactionId()); |
| | | costDates.add(newObj); |
| | | } |
| | | costDate.put("costDates",costDates); |
| | | |
| | | KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_COST_TIME_LOG_NAME,"",costDate.toJSONString()); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("报错日志出错了,",e); |
| | | } |
| | | } |
| | | |
| | | |
| | | public RestTemplate getRestTemplate() { |
| | | return restTemplate; |
| | | } |
| | | |
| | | public void setRestTemplate(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | |
| | | public IQueryServiceSMO getQueryServiceSMOImpl() { |
| | | return queryServiceSMOImpl; |
| | | } |
| | | |
| | | public void setQueryServiceSMOImpl(IQueryServiceSMO queryServiceSMOImpl) { |
| | | this.queryServiceSMOImpl = queryServiceSMOImpl; |
| | | } |
| | | |
| | | public RestTemplate getRestTemplateNoLoadBalanced() { |
| | | return restTemplateNoLoadBalanced; |
| | | } |
| | | |
| | | public void setRestTemplateNoLoadBalanced(RestTemplate restTemplateNoLoadBalanced) { |
| | | this.restTemplateNoLoadBalanced = restTemplateNoLoadBalanced; |
| | | } |
| | | } |
| | |
| | | maxTotal: 100 |
| | | maxIdle: 20 |
| | | maxWaitMillis: 20000 |
| | | host: 192.168.31.199 |
| | | host: hc.java110.com |
| | | port: 6379 |
| | | |
| | | eureka: |
| | |
| | | leaseExpirationDurationInSeconds: 30 |
| | | client: |
| | | serviceUrl: |
| | | defaultZone: http://192.168.31.199:8761/eureka/ |
| | | defaultZone: http://hc.java110.com:8761/eureka/ |
| | | #defaultZone: http://localhost:8761/eureka/ |
| | | server: |
| | | port: 8008 |
| | |
| | | enabled: true |
| | | force: true |
| | | application: |
| | | name: api |
| | | name: api-service |
| | | redis: |
| | | database: 0 |
| | | host: 192.168.31.199 |
| | | host: hc.java110.com |
| | | port: 6379 |
| | | pool: |
| | | max-active: 300 |
| | |
| | | kafka: |
| | | consumer: |
| | | zookeeper: |
| | | connect: 192.168.31.199:2181 |
| | | servers: 192.168.31.199:9092 |
| | | connect: hc.java110.com:2181 |
| | | servers: hc.java110.com:9092 |
| | | enable: |
| | | auto: |
| | | commit: true |
| | |
| | | |
| | | producer: |
| | | zookeeper: |
| | | connect: 192.168.31.199:2181 |
| | | servers: 192.168.31.199:9092 |
| | | connect: hc.java110.com:2181 |
| | | servers: hc.java110.com:9092 |
| | | retries: 0 |
| | | batch: |
| | | size: 4096 |
| | |
| | | enabled: true |
| | | force: true |
| | | application: |
| | | name: api |
| | | name: api-service |
| | | redis: |
| | | database: 0 |
| | | host: 135.192.86.200 |
| | |
| | | enabled: true |
| | | force: true |
| | | application: |
| | | name: api |
| | | name: api-service |
| | | redis: |
| | | database: 0 |
| | | host: 135.192.86.200 |
| | |
| | | spring: |
| | | profiles: |
| | | active: prod |
| | | active: dev |
| | |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(path = "/httpApi/service/{serviceCode}",method= RequestMethod.POST) |
| | | @RequestMapping(path = "/httpApi/service/{serviceCode:.+}",method= RequestMethod.POST) |
| | | public String servicePostTransfer(@PathVariable String serviceCode, @RequestBody String orderInfo, HttpServletRequest request, |
| | | HttpServletResponse response) { |
| | | String resData = ""; |
| | |
| | | maxTotal: 100 |
| | | maxIdle: 20 |
| | | maxWaitMillis: 20000 |
| | | host: 192.168.31.199 |
| | | host: hc.java110.com |
| | | port: 6379 |
| | | |
| | | eureka: |
| | |
| | | leaseExpirationDurationInSeconds: 30 |
| | | client: |
| | | serviceUrl: |
| | | defaultZone: http://192.168.31.199:8761/eureka/ |
| | | defaultZone: http://hc.java110.com:8761/eureka/ |
| | | #defaultZone: http://localhost:8761/eureka/ |
| | | server: |
| | | port: 8001 |
| | |
| | | name: center-service |
| | | redis: |
| | | database: 0 |
| | | host: 192.168.31.199 |
| | | host: hc.java110.com |
| | | port: 6379 |
| | | pool: |
| | | max-active: 300 |
| | |
| | | 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 |
| | | url: jdbc:mysql://hc.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8 |
| | | maxPoolPreparedStatementPerConnectionSize: 20 |
| | | password: TT@12345678 |
| | | testOnBorrow: false |
| | |
| | | kafka: |
| | | consumer: |
| | | zookeeper: |
| | | connect: 192.168.31.199:2181 |
| | | servers: 192.168.31.199:9092 |
| | | connect: hc.java110.com:2181 |
| | | servers: hc.java110.com:9092 |
| | | enable: |
| | | auto: |
| | | commit: true |
| | |
| | | |
| | | producer: |
| | | zookeeper: |
| | | connect: 192.168.31.199:2181 |
| | | servers: 192.168.31.199:9092 |
| | | connect: hc.java110.com:2181 |
| | | servers: hc.java110.com:9092 |
| | | retries: 0 |
| | | batch: |
| | | size: 4096 |
| | |
| | | spring: |
| | | profiles: |
| | | active: prod |
| | | active: dev |
| | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | /** |
| | | * 数据查询对象 |
| | |
| | | private JSONObject responseInfo; |
| | | |
| | | private ServiceSql serviceSql; |
| | | |
| | | //rest 返回对象 |
| | | private ResponseEntity responseEntity; |
| | | |
| | | |
| | | |
| | |
| | | this.serviceSql = serviceSql; |
| | | } |
| | | |
| | | public ResponseEntity getResponseEntity() { |
| | | return responseEntity; |
| | | } |
| | | |
| | | public void setResponseEntity(ResponseEntity responseEntity) { |
| | | this.responseEntity = responseEntity; |
| | | } |
| | | |
| | | /** |
| | | * { |
| | |
| | | public final static String INSTANCE_N = "N"; |
| | | |
| | | |
| | | public final static String HTTP_SERVICE = "SERVICE"; |
| | | public final static String HTTP_METHOD = "METHOD"; |
| | | public final static String HTTP_APP_ID = "app_id"; |
| | | public final static String HTTP_TRANSACTION_ID = "transaction_id"; |
| | | public final static String HTTP_REQ_TIME = "req_time"; |
| | | public final static String HTTP_SIGN = "sign"; |
| | | |
| | | |
| | | public final static String HTTP_METHOD_POST = "POST"; |
| | | public final static String HTTP_METHOD_PUT = "PUT"; |
| | | public final static String HTTP_METHOD_GET = "GET"; |
| | | public final static String HTTP_METHOD_DELETE = "DELETE"; |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | public static final String SERVICE_CODE_DELETE_COMMENT_INFO = "delete.comment.info"; |
| | | |
| | | |
| | | /** |
| | | * 透传服务 |
| | | */ |
| | | public static final String SERVICE_CODE_DO_SERVICE_TRANSFER = "do.service.transfer"; |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | `name` VARCHAR(50) NOT NULL COMMENT '服务名称', |
| | | seq INT NOT NULL COMMENT '顺序 只有同步方式下根据seq从小到大调用接口', |
| | | messageQueueName VARCHAR(50) COMMENT '消息队里名称 只有异步时有用', |
| | | is_instance varchar(2) not null default 'N' comment '是否Instance Y 需要,N不需要', |
| | | is_instance varchar(2) not null default 'N' comment '是否Instance Y 需要,N不需要,NT透传类', |
| | | url VARCHAR(200) COMMENT '目标地址', |
| | | method VARCHAR(50) COMMENT '方法 空 为http post LOCAL_SERVICE 为调用本地服务 其他为webservice方式调用', |
| | | timeout INT NOT NULL DEFAULT 60 COMMENT '超时时间', |
| | |
| | | ) |
| | | CREATE INDEX idx_s_member_store_store_id ON s_member_store(store_id); |
| | | CREATE INDEX idx_s_member_store_b_id ON s_member_store(b_id); |
| | | -- 物业费 停车费 |
| | | CREATE TABLE s_store_fee( |
| | | fee_id VARCHAR(30) NOT NULL COMMENT 'ID', |
| | | b_id VARCHAR(30) NOT NULL COMMENT '业务Id', |
| | | store_id VARCHAR(30) NOT NULL COMMENT '商店ID', |
| | | user_id VARCHAR(30) NOT NULL COMMENT '用户ID', |
| | | fee_type_cd VARCHAR(10) NOT NULL COMMENT '费用类型,物业费,停车费 请查看store_fee_type表', |
| | | fee_money VARCHAR(20) NOT NULL COMMENT '费用金额', |
| | | fee_time VARCHAR(10) NOT NULL COMMENT '费用周期,一个月,半年,或一年 请查看store_fee_time表', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | start_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '开始时间', |
| | | end_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '结束时间', |
| | | status_cd VARCHAR(2) NOT NULL DEFAULT '0' COMMENT '数据状态,详细参考c_status表,S 保存,0, 在用 1失效', |
| | | UNIQUE KEY (fee_id) |
| | | ); |
| | | CREATE INDEX idx_store_fee_fee_id ON s_store_fee(fee_id); |
| | | CREATE INDEX idx_store_fee_b_id ON s_store_fee(b_id); |
| | | |
| | | CREATE TABLE s_store_house( |
| | | house_id VARCHAR(30) NOT NULL COMMENT 'ID', |
| | | house_num VARCHAR(30) NOT NULL COMMENT '门牌号', |
| | | house_name VARCHAR(50) NOT NULL COMMENT '住户名称', |
| | | house_phone VARCHAR(11) COMMENT '住户联系号码', |
| | | house_area VARCHAR(30) NOT NULL COMMENT '房屋面积', |
| | | fee_type_cd VARCHAR(10) NOT NULL COMMENT '费用类型 store_fee_type表', |
| | | fee_price VARCHAR(30) NOT NULL COMMENT '费用单价', |
| | | user_id VARCHAR(10) NOT NULL COMMENT '录入人', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', |
| | | status_cd VARCHAR(2) NOT NULL DEFAULT '0' COMMENT '数据状态,详细参考c_status表,S 保存,0, 在用 1失效', |
| | | UNIQUE KEY (house_id) |
| | | ); |
| | | |
| | | CREATE TABLE s_store_house_attr( |
| | | attr_id VARCHAR(30) NOT NULL COMMENT '属性id', |
| | | house_id VARCHAR(30) NOT NULL COMMENT '用户ID', |
| | | spec_cd VARCHAR(12) NOT NULL COMMENT '规格id,参考spec表', |
| | | VALUE VARCHAR(50) NOT NULL COMMENT '属性值', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | status_cd VARCHAR(2) NOT NULL DEFAULT '0' COMMENT '数据状态,详细参考c_status表,S 保存,0, 在用 1失效', |
| | | UNIQUE KEY (attr_id) |
| | | ); |
| | | |
| | | |
| | | -- 店铺种类 |
| | | create table store_type( |
| | |
| | | unique KEY (store_type_cd) |
| | | ); |
| | | |
| | | -- 收费类型表 |
| | | CREATE TABLE store_fee_type( |
| | | id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id', |
| | | domain VARCHAR(20) NOT NULL COMMENT '域', |
| | | fee_type_cd VARCHAR(12) NOT NULL COMMENT '收费类型 物业费 停车费等', |
| | | `name` VARCHAR(50) NOT NULL COMMENT '收费类型编码', |
| | | description VARCHAR(200) COMMENT '描述', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | UNIQUE KEY (fee_type_cd) |
| | | ); |
| | | |
| | | -- 收费周期表 |
| | | CREATE TABLE store_fee_time( |
| | | id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id', |
| | | domain VARCHAR(20) NOT NULL COMMENT '域', |
| | | fee_time_cd VARCHAR(12) NOT NULL COMMENT '费用周期编码 一年,半年等', |
| | | `name` VARCHAR(50) NOT NULL COMMENT '收费类型编码', |
| | | description VARCHAR(200) COMMENT '描述', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | UNIQUE KEY (fee_time_cd) |
| | | ); |
| | | |
| | | insert into store_type(domain,store_type_cd,name,description) values('CORE_STROE','870000000001','小区','小区'); |
| | | insert into store_type(domain,store_type_cd,name,description) values('CORE_STROE','870000000002','物业','物业'); |
| | | insert into store_type(domain,store_type_cd,name,description) values('CORE_STROE','870000000003','物流公司','物流公司'); |
| | |
| | | |
| | | while( reqHeaderEnum.hasMoreElements() ) { |
| | | String headerName = (String)reqHeaderEnum.nextElement(); |
| | | headers.put(headerName, request.getHeader(headerName)); |
| | | headers.put(headerName.toLowerCase(), request.getHeader(headerName)); |
| | | } |
| | | |
| | | headers.put("IP",getIpAddr(request)); |
| | |
| | | import com.java110.entity.center.Business; |
| | | import com.java110.entity.center.DataFlowLinksCost; |
| | | import com.java110.entity.center.DataFlowLog; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | |
| | | afterBuilder((DataFlowContext) dataFlowContext); |
| | | return dataFlowContext; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 预处理 |
| | |
| | | } |
| | | |
| | | |
| | | public void setResponseEntity(ResponseEntity responseEntity){ |
| | | |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package com.java110.core.context; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.entity.center.AppRoute; |
| | | import com.java110.entity.center.Business; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 主要用于离散成对象 httpApi service 请求过程消息记录和返回记录 |
| | | * Created by wuxw on 2018/4/13. |
| | | */ |
| | | public class ApiDataFlow extends AbstractDataFlowContext { |
| | | |
| | | private String appId; |
| | | |
| | | private String ip; |
| | | |
| | | private String apiCurrentService; |
| | | |
| | | private String reqSign; |
| | | |
| | | private String resSign; |
| | | |
| | | private String requestURL; |
| | | |
| | | |
| | | private List<AppRoute> appRoutes = new ArrayList<AppRoute>(); |
| | | //请求业务系统报文 |
| | | private JSONObject requestBusinessJson; |
| | | |
| | | //业务系统返回报文 |
| | | private JSONObject responseBusinessJson; |
| | | //rest 返回对象 |
| | | private ResponseEntity responseEntity; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public ApiDataFlow(Date startDate, String code){ |
| | | super(startDate,code); |
| | | } |
| | | |
| | | public void setAppId(String appId) { |
| | | this.appId = appId; |
| | | } |
| | | |
| | | |
| | | |
| | | public void setReqSign(String reqSign) { |
| | | this.reqSign = reqSign; |
| | | } |
| | | |
| | | |
| | | |
| | | public void setResSign(String resSign) { |
| | | this.resSign = resSign; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public String getAppId() { |
| | | return appId; |
| | | } |
| | | |
| | | |
| | | |
| | | public String getReqSign() { |
| | | return reqSign; |
| | | } |
| | | |
| | | @Override |
| | | public Orders getOrder() { |
| | | return this; |
| | | } |
| | | |
| | | public String getResSign() { |
| | | return resSign; |
| | | } |
| | | |
| | | |
| | | |
| | | public String getRequestURL() { |
| | | return requestURL; |
| | | } |
| | | |
| | | public void setRequestURL(String requestURL) { |
| | | this.requestURL = requestURL; |
| | | } |
| | | |
| | | |
| | | public List<AppRoute> getAppRoutes() { |
| | | return appRoutes; |
| | | } |
| | | |
| | | public void addAppRoutes(AppRoute appRoute) { |
| | | this.appRoutes.add(appRoute); |
| | | } |
| | | |
| | | public String getIp() { |
| | | return ip; |
| | | } |
| | | |
| | | public void setIp(String ip) { |
| | | this.ip = ip; |
| | | } |
| | | |
| | | public ApiDataFlow doBuilder(String reqInfo, Map<String,String> headerAll) throws Exception{ |
| | | |
| | | try{ |
| | | JSONObject reqInfoObj = JSONObject.parseObject(reqInfo); |
| | | |
| | | this.setReqData(reqInfo); |
| | | this.setReqJson(reqInfoObj); |
| | | this.setDataFlowId("-1"); |
| | | this.setAppId(headerAll.get(CommonConstant.HTTP_APP_ID)); |
| | | this.setTransactionId(headerAll.get(CommonConstant.HTTP_TRANSACTION_ID)); |
| | | this.setReqSign(headerAll.get(CommonConstant.HTTP_SIGN)); |
| | | this.setRequestTime(headerAll.get(CommonConstant.HTTP_REQ_TIME)); |
| | | |
| | | if (headerAll != null){ |
| | | this.requestHeaders.putAll(headerAll); |
| | | this.requestCurrentHeaders.putAll(headerAll); |
| | | this.setRequestURL(requestHeaders.get("REQUEST_URL")); |
| | | this.setIp(requestHeaders.get("IP")); |
| | | } |
| | | |
| | | |
| | | }catch (Exception e){ |
| | | |
| | | throw e; |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * 透传时构建对象 |
| | | * @param reqInfo |
| | | * @param headerAll |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ApiDataFlow builderTransfer(String reqInfo, Map<String,String> headerAll) throws Exception{ |
| | | |
| | | try{ |
| | | this.setReqData(reqInfo); |
| | | this.setDataFlowId("-1"); |
| | | this.setAppId(headerAll.get(CommonConstant.HTTP_APP_ID)); |
| | | this.setTransactionId(headerAll.get(CommonConstant.HTTP_TRANSACTION_ID)); |
| | | this.setReqSign(headerAll.get(CommonConstant.HTTP_SIGN)); |
| | | this.setRequestTime(headerAll.get(CommonConstant.HTTP_REQ_TIME)); |
| | | |
| | | if (headerAll != null){ |
| | | this.requestHeaders.putAll(headerAll); |
| | | this.requestCurrentHeaders.putAll(headerAll); |
| | | this.setRequestURL(requestHeaders.get("REQUEST_URL")); |
| | | this.setIp(requestHeaders.get("IP")); |
| | | } |
| | | |
| | | |
| | | }catch (Exception e){ |
| | | |
| | | throw e; |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public String getServiceCode() { |
| | | return apiCurrentService; |
| | | } |
| | | |
| | | public void setApiCurrentService(String apiCurrentService) { |
| | | this.apiCurrentService = apiCurrentService; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void setResponseEntity(ResponseEntity responseEntity){ |
| | | this.responseEntity = responseEntity; |
| | | } |
| | | |
| | | |
| | | public ResponseEntity getResponseEntity(){ |
| | | return responseEntity; |
| | | } |
| | | } |
| | |
| | | import com.java110.entity.center.Business; |
| | | import com.java110.entity.center.DataFlowLinksCost; |
| | | import com.java110.entity.center.DataFlowLog; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | public String getbId(); |
| | | |
| | | //业务编码,如果是批量受理就取第一个 |
| | | public String getServiceCode(); |
| | | |
| | | public void setResponseEntity(ResponseEntity responseEntity); |
| | | |
| | | |
| | | } |
| | |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.StringUtil; |
| | | |
| | | import com.java110.core.context.ApiDataFlow; |
| | | import com.java110.core.context.DataFlow; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * dataFlow 对象签名 |
| | | * @param dataFlow |
| | | * @return |
| | | */ |
| | | public static String apiDataFlowMd5(ApiDataFlow dataFlow) throws NoAuthorityException{ |
| | | if(dataFlow == null){ |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR,"MD5签名过程中出现错误"); |
| | | } |
| | | String reqInfo = dataFlow.getTransactionId() + dataFlow.getRequestTime() + dataFlow.getAppId(); |
| | | reqInfo += "GET,DELETE".equals(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_METHOD))? |
| | | dataFlow.getRequestHeaders().get("REQUEST_URL") :dataFlow.getReqData(); |
| | | reqInfo += dataFlow.getAppRoutes().get(0).getSecurityCode(); |
| | | return md5(reqInfo); |
| | | } |
| | | |
| | | /** |
| | | * md5加密 |
| | | * @param transactionId 流水 |
| | | * @param appId 应用ID |
| | |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.core.context.AbstractDataFlowContext; |
| | | import com.java110.core.context.ApiDataFlow; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.entity.center.AppRoute; |
| | | import com.java110.entity.center.AppService; |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取单个路由 |
| | | * @param dataFlow |
| | | * @param serviceCode |
| | | * @return |
| | | */ |
| | | public static AppRoute getRoute(ApiDataFlow dataFlow, String serviceCode){ |
| | | if (dataFlow.getAppRoutes().size() == 0){ |
| | | throw new RuntimeException("当前没有获取到AppId对应的信息"); |
| | | } |
| | | |
| | | List<AppRoute> appRoutes = dataFlow.getAppRoutes(); |
| | | for(AppRoute appRoute : appRoutes) { |
| | | if (StatusConstant.STATUS_CD_VALID.equals(appRoute.getStatusCd()) |
| | | &&appRoute.getAppService().getServiceCode().equals(serviceCode)){ |
| | | return appRoute; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 获取单个服务 |
| | | * @param dataFlow |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取单个服务 |
| | | * @param dataFlow |
| | | * @param serviceCode |
| | | * @return |
| | | */ |
| | | public static AppService getService(ApiDataFlow dataFlow, String serviceCode){ |
| | | AppRoute route = getRoute(dataFlow, serviceCode); |
| | | if(route == null){ |
| | | return null; |
| | | } |
| | | return route.getAppService(); |
| | | } |
| | | |
| | | /** |
| | | * 获取Order信息 |
| | | * @param dataFlow |
| | | * @return |
| New file |
| | |
| | | package com.java110.event.service.api; |
| | | |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.entity.center.AppService; |
| | | |
| | | import java.util.EventObject; |
| | | |
| | | /** |
| | | * |
| | | * 服务事件 |
| | | * Created by wuxw on 2018/5/18. |
| | | */ |
| | | public class ServiceDataFlowEvent extends EventObject { |
| | | |
| | | private DataFlowContext dataFlowContext; |
| | | private AppService appService; |
| | | /** |
| | | * Constructs a prototypical Event. |
| | | * |
| | | * @param source The object on which the Event initially occurred. |
| | | * @throws IllegalArgumentException if source is null. |
| | | */ |
| | | public ServiceDataFlowEvent(Object source, DataFlowContext dataFlowContext,AppService appService) { |
| | | super(source); |
| | | this.dataFlowContext = dataFlowContext; |
| | | this.appService = appService; |
| | | } |
| | | |
| | | |
| | | public DataFlowContext getDataFlowContext() { |
| | | return dataFlowContext; |
| | | } |
| | | |
| | | /*public void setDataFlowContext(DataFlowContext dataFlowContext) { |
| | | this.dataFlowContext = dataFlowContext; |
| | | }*/ |
| | | |
| | | public AppService getAppService(){ |
| | | return appService; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.event.service.api; |
| | | |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.exception.BusinessException; |
| | | import com.java110.common.factory.ApplicationContextFactory; |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.entity.center.AppService; |
| | | import com.java110.event.center.DataFlowListenerOrderComparator; |
| | | import com.java110.event.service.BusinessServiceDataFlowEvent; |
| | | import com.java110.event.service.BusinessServiceDataFlowListener; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.Executor; |
| | | import java.util.concurrent.Executors; |
| | | |
| | | /** |
| | | * 数据流 事件发布 |
| | | * Created by wuxw on 2018/4/17. |
| | | */ |
| | | public class ServiceDataFlowEventPublishing extends LoggerEngine { |
| | | |
| | | private static Executor taskExecutor; |
| | | |
| | | //默认 线程数 100 |
| | | private final static int DEFAULT_THREAD_NUM = 100; |
| | | |
| | | /** |
| | | * 保存侦听实例信息,一般启动时加载 |
| | | */ |
| | | private final static List<String> listeners = new ArrayList<String>(); |
| | | |
| | | /** |
| | | * 根据 事件类型查询侦听 |
| | | */ |
| | | private final static Map<String,List<ServiceDataFlowListener>> cacheListenersMap = new HashMap<String, List<ServiceDataFlowListener>>(); |
| | | |
| | | /** |
| | | * 添加 侦听,这个只有启动时,单线程 处理,所以是线程安全的 |
| | | * @param listener |
| | | */ |
| | | public static void addListener(String listener){ |
| | | listeners.add(listener); |
| | | } |
| | | |
| | | /** |
| | | * 获取侦听(全部侦听) |
| | | * @return |
| | | */ |
| | | public static List<String> getListeners(){ |
| | | return listeners; |
| | | } |
| | | |
| | | /** |
| | | * 根据是否实现了某个接口,返回侦听 |
| | | * @param serviceCode |
| | | * @since 1.8 |
| | | * @return |
| | | */ |
| | | public static List<ServiceDataFlowListener> getListeners(String serviceCode){ |
| | | |
| | | Assert.hasLength(serviceCode,"获取需要发布的事件处理侦听时,传递事件为空,请检查"); |
| | | |
| | | //先从缓存中获取,为了提升效率 |
| | | if(cacheListenersMap.containsKey(serviceCode)){ |
| | | return cacheListenersMap.get(serviceCode); |
| | | } |
| | | |
| | | List<ServiceDataFlowListener> dataFlowListeners = new ArrayList<ServiceDataFlowListener>(); |
| | | for(String listenerBeanName : getListeners()){ |
| | | ServiceDataFlowListener listener = ApplicationContextFactory.getBean(listenerBeanName,ServiceDataFlowListener.class); |
| | | if(serviceCode.equals(listener.getServiceCode())){ |
| | | dataFlowListeners.add(listener); |
| | | } |
| | | } |
| | | |
| | | //这里排序 |
| | | DataFlowListenerOrderComparator.sort(dataFlowListeners); |
| | | |
| | | //将数据放入缓存中 |
| | | cacheListenersMap.put(serviceCode,dataFlowListeners); |
| | | return dataFlowListeners; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发布事件 |
| | | * @param dataFlowContext |
| | | */ |
| | | public static void multicastEvent(DataFlowContext dataFlowContext,AppService appService) throws BusinessException{ |
| | | Assert.notNull(dataFlowContext.getServiceCode(),"当前没有可处理的业务信息!"); |
| | | multicastEvent(dataFlowContext.getServiceCode(),dataFlowContext,appService,null); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发布事件 |
| | | * @param serviceCode |
| | | * @param dataFlowContext |
| | | */ |
| | | public static void multicastEvent(String serviceCode,DataFlowContext dataFlowContext,AppService appService) throws BusinessException{ |
| | | multicastEvent(serviceCode,dataFlowContext,appService,null); |
| | | } |
| | | |
| | | /** |
| | | * 发布事件 |
| | | * @param serviceCode |
| | | * @param dataFlowContext 这个订单信息,以便于 侦听那边需要用 |
| | | */ |
| | | public static void multicastEvent(String serviceCode, DataFlowContext dataFlowContext, AppService appService, String asyn) throws BusinessException{ |
| | | try { |
| | | ServiceDataFlowEvent targetDataFlowEvent = new ServiceDataFlowEvent(serviceCode,dataFlowContext,appService); |
| | | |
| | | multicastEvent(serviceCode,targetDataFlowEvent, asyn); |
| | | }catch (Exception e){ |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"发布侦听失败,失败原因为:"+e); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发布事件 |
| | | * @param event |
| | | * @param asyn A 表示异步处理 |
| | | */ |
| | | public static void multicastEvent(String serviceCode,final ServiceDataFlowEvent event, String asyn) { |
| | | for (final ServiceDataFlowListener listener : getListeners(serviceCode)) { |
| | | |
| | | if(CommonConstant.PROCESS_ORDER_ASYNCHRONOUS.equals(asyn)){ //异步处理 |
| | | |
| | | Executor executor = getTaskExecutor(); |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | invokeListener(listener, event); |
| | | } |
| | | }); |
| | | break; |
| | | } |
| | | else { |
| | | invokeListener(listener, event); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Return the current task executor for this multicaster. |
| | | */ |
| | | protected static synchronized Executor getTaskExecutor() { |
| | | if(taskExecutor == null) { |
| | | taskExecutor = Executors.newFixedThreadPool(DEFAULT_THREAD_NUM); |
| | | } |
| | | return taskExecutor; |
| | | } |
| | | |
| | | /** |
| | | * Invoke the given listener with the given event. |
| | | * @param listener the ApplicationListener to invoke |
| | | * @param event the current event to propagate |
| | | * @since 4.1 |
| | | */ |
| | | @SuppressWarnings({"unchecked", "rawtypes"}) |
| | | protected static void invokeListener(ServiceDataFlowListener listener, ServiceDataFlowEvent event) { |
| | | try { |
| | | listener.soService(event); |
| | | }catch (Exception e){ |
| | | LoggerEngine.error("发布侦听失败",e); |
| | | throw new RuntimeException("发布侦听失败,"+listener+ event + e); |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.event.service.api; |
| | | |
| | | import com.java110.event.app.order.Ordered; |
| | | import com.java110.event.service.BusinessServiceDataFlowEvent; |
| | | |
| | | import java.util.EventListener; |
| | | |
| | | /** |
| | | * 通用事件处理, |
| | | * Created by wuxw on 2018/4/17. |
| | | */ |
| | | public interface ServiceDataFlowListener extends EventListener,Ordered { |
| | | |
| | | /** |
| | | * 业务 编码 |
| | | * @return |
| | | */ |
| | | public String getServiceCode(); |
| | | |
| | | public void soService(ServiceDataFlowEvent event); |
| | | } |
| | |
| | | <artifactId>testng</artifactId> |
| | | <version>RELEASE</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-swagger2</artifactId> |
| | | </dependency> |
| | | <!-- swagger-ui --> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | | <artifactId>springfox-swagger-ui</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | </project> |
| | |
| | | import com.java110.core.base.controller.BaseController; |
| | | import com.java110.entity.service.DataQuery; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | |
| | | * Created by wuxw on 2018/4/20. |
| | | */ |
| | | @RestController |
| | | @Api(value = "查询业务统一提供服务") |
| | | public class BusinessApi extends BaseController { |
| | | |
| | | @Autowired |
| | |
| | | * @return |
| | | */ |
| | | @RequestMapping(path = "/businessApi/query",method= RequestMethod.POST) |
| | | public String queryPost(@RequestBody String businessInfo) { |
| | | @ApiOperation(value="业务查询post请求", notes="test: 返回 2XX 表示服务正常") |
| | | @ApiImplicitParam(paramType="query", name = "method", value = "用户编号", required = true, dataType = "String") |
| | | public ResponseEntity<String> queryPost(@RequestBody String businessInfo) { |
| | | try { |
| | | DataQuery dataQuery = DataQueryFactory.newInstance().builder(businessInfo); |
| | | initConfig(dataQuery); |
| | | queryServiceSMOImpl.commonQueryService(dataQuery); |
| | | return dataQuery.getResponseInfo().toJSONString(); |
| | | return dataQuery.getResponseEntity(); |
| | | }catch (Exception e){ |
| | | logger.error("请求订单异常",e); |
| | | return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString(); |
| | | //DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString(); |
| | | return new ResponseEntity<String>("请求发生异常,"+e.getMessage()+e, HttpStatus.INTERNAL_SERVER_ERROR); |
| | | |
| | | } |
| | | } |
| | | @Deprecated |
| | |
| | | import com.java110.service.dao.IQueryServiceDAO; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Override |
| | | public void commonQueryService(DataQuery dataQuery) throws BusinessException { |
| | | //查询缓存查询 对应处理的ServiceSql |
| | | ResponseEntity<String> responseEntity = null; |
| | | try { |
| | | ServiceSql currentServiceSql = ServiceSqlCache.getServiceSql(dataQuery.getServiceCode()); |
| | | if (currentServiceSql == null) { |
| | |
| | | return ; |
| | | } |
| | | doExecuteProc(dataQuery); |
| | | responseEntity = new ResponseEntity<String>(dataQuery.getResponseInfo().toJSONString(), HttpStatus.OK); |
| | | }catch (BusinessException e){ |
| | | logger.error("公用查询异常:",e); |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | e.getMessage())); |
| | | /*dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | e.getMessage()));*/ |
| | | responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } |
| | | dataQuery.setResponseEntity(responseEntity); |
| | | |
| | | } |
| | | @Override |