| | |
| | | "serviceCode": "querycustinfo", |
| | | "serviceName": "查询客户", |
| | | "remark": "备注", |
| | | "datas": [{ |
| | | "datas": { |
| | | "params": { |
| | | //这个做查询时的参数 |
| | | } |
| | | //这里是具体业务 |
| | | }], |
| | | "attrs": [{ |
| | | "specCd": "配置的字段id", |
| | | "value": "具体值" |
| | | }] |
| | | } |
| | | }] |
| | | } |
| New file |
| | |
| | | {//这个是相应的业务系统返回的结果,(受理为空,查询时不为空) |
| | | "response": { |
| | | "code": "1999", |
| | | "message": "具体值" |
| | | } |
| | | //相应内容 |
| | | } |
| | |
| | | "serviceCode": "queryCustInfo", |
| | | "serviceName": "查询客户", |
| | | "remark": "备注", |
| | | "datas": [{ |
| | | "datas": { |
| | | "params": { |
| | | //这个做查询时的参数 |
| | | } |
| | | //这里是具体业务 |
| | | }], |
| | | }, |
| | | "attrs": [{ |
| | | "specCd": "配置的字段ID", |
| | | "value": "具体值" |
| | |
| | | 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.entity.center.AppRoute; |
| | | import com.java110.entity.mapping.Mapping; |
| | | 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() { |
| | | |
| | |
| | | |
| | | //2.0 分装 Mapping |
| | | flushMapping(); |
| | | |
| | | //3.0 分装 ServiceSql |
| | | flushServiceSql(); |
| | | } |
| | | |
| | | /** |
| | | * 3.0 分装 ServiceSql |
| | | */ |
| | | private void flushServiceSql() { |
| | | List<ServiceSql> serviceSqls = queryServiceDAOImpl.qureyServiceSqlAll(); |
| | | |
| | | if(serviceSqls == null || serviceSqls.size() == 0){ |
| | | return; |
| | | } |
| | | for(ServiceSql serviceSql: serviceSqls){ |
| | | ServiceSqlCache.setServiceSql(serviceSql); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | public void setCenterServiceDAOImpl(ICenterServiceDAO centerServiceDAOImpl) { |
| | | this.centerServiceDAOImpl = centerServiceDAOImpl; |
| | | } |
| | | |
| | | public IQueryServiceDAO getQueryServiceDAOImpl() { |
| | | return queryServiceDAOImpl; |
| | | } |
| | | |
| | | public void setQueryServiceDAOImpl(IQueryServiceDAO queryServiceDAOImpl) { |
| | | this.queryServiceDAOImpl = queryServiceDAOImpl; |
| | | } |
| | | } |
| | |
| | | import com.java110.common.util.*; |
| | | import com.java110.entity.center.*; |
| | | import com.java110.event.center.DataFlowEventPublishing; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private IQueryServiceSMO queryServiceSMOImpl; |
| | | |
| | | @Override |
| | | public String service(String reqJson, Map<String, String> headers) throws SMOException{ |
| | |
| | | responseJson = ResponseTemplateUtil.createOrderResponseJson(dataFlow.getTransactionId(), |
| | | ResponseConstant.NO_NEED_SIGN, e.getResult().getCode(), e.getMessage()); |
| | | } catch (Exception e) { |
| | | logger.error("内部异常了:",e); |
| | | responseJson = ResponseTemplateUtil.createOrderResponseJson(dataFlow == null |
| | | ? ResponseConstant.NO_TRANSACTION_ID |
| | | : dataFlow.getTransactionId(), |
| | |
| | | Date startDate = DateUtil.getCurrentDate(); |
| | | Date businessStartDate = null; |
| | | List<Business> synchronousBusinesses = DataFlowFactory.getSynchronousBusinesses(dataFlow); |
| | | |
| | | if(synchronousBusinesses == null || synchronousBusinesses.size() == 0){ |
| | | return ; |
| | | } |
| | | AppService service = null; |
| | | JSONObject requestBusinessJson = null; |
| | | JSONArray responseBusinesses = new JSONArray(); |
| | |
| | | if(service.getMethod() == null || "".equals(service.getMethod())) {//post方式 |
| | | //http://user-service/test/sayHello |
| | | responseMessage = restTemplate.postForObject(service.getUrl(),dataFlow.getRequestBusinessJson().toJSONString(),String.class); |
| | | }else if(CommonConstant.INVOKE_BUSINESS_MODEL_LOCAL.equals(service.getMethod())){ |
| | | //调用本地服务 |
| | | responseMessage = ""; |
| | | }else{//webservice方式 |
| | | responseMessage = (String) WebServiceAxisClient.callWebService(service.getUrl(),service.getMethod(), |
| | | new Object[]{dataFlow.getRequestBusinessJson().toJSONString()}, |
| | |
| | | //发布事件 |
| | | DataFlowEventPublishing.multicastEvent(service.getServiceCode(),dataFlow); |
| | | |
| | | responseBusinesses.add(dataFlow.getResponseBusinessJson().getJSONArray("business")); |
| | | responseBusinesses.add(dataFlow.getResponseBusinessJson()); |
| | | |
| | | DataFlowFactory.addCostTime(dataFlow, business.getServiceCode(), "调用"+business.getServiceName()+"耗时", businessStartDate); |
| | | saveLogMessage(dataFlow.getRequestBusinessJson(),dataFlow.getResponseBusinessJson()); |
| | |
| | | Date startDate = DateUtil.getCurrentDate(); |
| | | //6.3 处理异步,按消息队里处理 |
| | | List<Business> asynchronousBusinesses = DataFlowFactory.getAsynchronousBusinesses(dataFlow); |
| | | |
| | | if(asynchronousBusinesses == null || asynchronousBusinesses.size() == 0){ |
| | | return ; |
| | | } |
| | | |
| | | try { |
| | | for (Business business : asynchronousBusinesses) { |
| | |
| | | public void setRestTemplate(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | |
| | | public IQueryServiceSMO getQueryServiceSMOImpl() { |
| | | return queryServiceSMOImpl; |
| | | } |
| | | |
| | | public void setQueryServiceSMOImpl(IQueryServiceSMO queryServiceSMOImpl) { |
| | | this.queryServiceSMOImpl = queryServiceSMOImpl; |
| | | } |
| | | } |
| | |
| | | concurrency: 10 |
| | | |
| | | producer: |
| | | zookeeper: |
| | | connect: 192.168.31.199:2181 |
| | | servers: 192.168.31.199:9092 |
| | | retries: 0 |
| | | batch: |
| | |
| | | |
| | | private String remark; |
| | | |
| | | private JSONArray datas; |
| | | private JSONObject datas; |
| | | |
| | | private JSONArray attrs; |
| | | //返回 编码 |
| | |
| | | this.remark = remark; |
| | | } |
| | | |
| | | public JSONArray getDatas() { |
| | | public JSONObject getDatas() { |
| | | return datas; |
| | | } |
| | | |
| | | public void setDatas(JSONArray datas) { |
| | | public void setDatas(JSONObject datas) { |
| | | this.datas = datas; |
| | | } |
| | | |
| | |
| | | this.setServiceCode(businessObj.getString("serviceCode")); |
| | | this.setServiceName(businessObj.getString("serviceName")); |
| | | this.setRemark(businessObj.getString("remark")); |
| | | this.setDatas(businessObj.getJSONArray("datas")); |
| | | this.setDatas(businessObj.getJSONObject("datas")); |
| | | this.setAttrs(businessObj.getJSONArray("attrs")); |
| | | if(businessObj.containsKey("response")){ |
| | | this.setCode(businessObj.getJSONObject("response").getString("code")); |
| | |
| | | |
| | | |
| | | }catch (Exception e){ |
| | | |
| | | throw e; |
| | | } |
| | | return this; |
| New file |
| | |
| | | package com.java110.entity.service; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | /** |
| | | * 数据查询对象 |
| | | * Created by wuxw on 2018/4/19. |
| | | */ |
| | | public class DataQuery { |
| | | |
| | | //服务编码 |
| | | private String serviceCode; |
| | | |
| | | private String templateKey; |
| | | |
| | | //请求参数 |
| | | private JSONObject requestParams; |
| | | |
| | | //返回信息 |
| | | private JSONObject responseInfo; |
| | | |
| | | private ServiceSql serviceSql; |
| | | |
| | | |
| | | |
| | | public String getTemplateKey() { |
| | | return templateKey; |
| | | } |
| | | |
| | | public void setTemplateKey(String templateKey) { |
| | | this.templateKey = templateKey; |
| | | } |
| | | |
| | | public String getServiceCode() { |
| | | return serviceCode; |
| | | } |
| | | |
| | | public void setServiceCode(String serviceCode) { |
| | | this.serviceCode = serviceCode; |
| | | } |
| | | |
| | | |
| | | public JSONObject getRequestParams() { |
| | | return requestParams; |
| | | } |
| | | |
| | | public void setRequestParams(JSONObject requestParams) { |
| | | this.requestParams = requestParams; |
| | | } |
| | | |
| | | public JSONObject getResponseInfo() { |
| | | return responseInfo; |
| | | } |
| | | |
| | | public void setResponseInfo(JSONObject responseInfo) { |
| | | this.responseInfo = responseInfo; |
| | | } |
| | | |
| | | public ServiceSql getServiceSql() { |
| | | return serviceSql; |
| | | } |
| | | |
| | | public void setServiceSql(ServiceSql serviceSql) { |
| | | this.serviceSql = serviceSql; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * { |
| | | "bId":"12345678", |
| | | "serviceCode": "querycustinfo", |
| | | "serviceName": "查询客户", |
| | | "remark": "备注", |
| | | "datas": { |
| | | "params": { |
| | | //这个做查询时的参数 |
| | | } |
| | | //这里是具体业务 |
| | | } |
| | | } |
| | | * 构建DataQuery |
| | | * @return |
| | | */ |
| | | public DataQuery builder(String businessInfo){ |
| | | JSONObject businessInfoObj = JSONObject.parseObject(businessInfo); |
| | | JSONObject currentBusinessInfo = null; |
| | | //这里为了兼容 centerService |
| | | if(businessInfoObj.containsKey("business")){ |
| | | if(businessInfoObj.get("business") instanceof JSONObject){ |
| | | currentBusinessInfo = (JSONObject) businessInfoObj.get("business"); |
| | | }else if(businessInfoObj.get("business") instanceof JSONArray){ |
| | | currentBusinessInfo = ((JSONArray) businessInfoObj.get("business")).getJSONObject(0); |
| | | }else { |
| | | return null; |
| | | } |
| | | }else{ |
| | | currentBusinessInfo = businessInfoObj; |
| | | } |
| | | this.setServiceCode(currentBusinessInfo.getString("serviceCode")); |
| | | this.setRequestParams(currentBusinessInfo.getJSONObject("datas").getJSONObject("params")); |
| | | return this; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.entity.service; |
| | | |
| | | import java.io.Serializable; |
| | | import java.lang.reflect.Array; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * c_service_sql 信息封装 |
| | | * Created by wuxw on 2018/4/19. |
| | | */ |
| | | public class ServiceSql implements Serializable{ |
| | | |
| | | private String serviceCode; |
| | | |
| | | private String name; |
| | | |
| | | private String params; |
| | | |
| | | private String queryModel; |
| | | |
| | | private String sql; |
| | | |
| | | private String proc; |
| | | |
| | | private String template; |
| | | |
| | | private String statusCd; |
| | | |
| | | private String remark; |
| | | |
| | | public String getServiceCode() { |
| | | return serviceCode; |
| | | } |
| | | |
| | | public void setServiceCode(String serviceCode) { |
| | | this.serviceCode = serviceCode; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getParams() { |
| | | return params; |
| | | } |
| | | |
| | | public List<String> getParamList(){ |
| | | if(params != null && !"".equals(params)){ |
| | | return Arrays.asList(params.split(",")); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public void setParams(String params) { |
| | | this.params = params; |
| | | } |
| | | |
| | | public String getQueryModel() { |
| | | return queryModel; |
| | | } |
| | | |
| | | public void setQueryModel(String queryModel) { |
| | | this.queryModel = queryModel; |
| | | } |
| | | |
| | | public String getSql() { |
| | | return sql; |
| | | } |
| | | |
| | | public void setSql(String sql) { |
| | | this.sql = sql; |
| | | } |
| | | |
| | | public String getProc() { |
| | | return proc; |
| | | } |
| | | |
| | | public void setProc(String proc) { |
| | | this.proc = proc; |
| | | } |
| | | |
| | | public String getTemplate() { |
| | | return template; |
| | | } |
| | | |
| | | public void setTemplate(String template) { |
| | | this.template = template; |
| | | } |
| | | |
| | | public String getStatusCd() { |
| | | return statusCd; |
| | | } |
| | | |
| | | public void setStatusCd(String statusCd) { |
| | | this.statusCd = statusCd; |
| | | } |
| | | |
| | | public String getRemark() { |
| | | return remark; |
| | | } |
| | | |
| | | public void setRemark(String remark) { |
| | | this.remark = remark; |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.java110.common.cache; |
| | | |
| | | import com.java110.common.util.SerializeUtil; |
| | | import com.java110.entity.service.ServiceSql; |
| | | |
| | | /** |
| | | * 缓存 |
| | | * Created by wuxw on 2018/4/19. |
| | | */ |
| | | public class ServiceSqlCache extends BaseCache { |
| | | |
| | | /** |
| | | * 查询 服务sql |
| | | * @param serviceCode |
| | | * @return |
| | | */ |
| | | public static ServiceSql getServiceSql(String serviceCode){ |
| | | |
| | | Object obj = SerializeUtil.unserialize(getJedis().get(serviceCode.getBytes())); |
| | | if(obj instanceof ServiceSql){ |
| | | return (ServiceSql) obj; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 存储对象 |
| | | * @param serviceSql |
| | | */ |
| | | public static void setServiceSql(ServiceSql serviceSql){ |
| | | getJedis().set(serviceSql.getServiceCode().getBytes(),SerializeUtil.serialize(serviceSql)); |
| | | } |
| | | } |
| | |
| | | |
| | | public final static String INVOKE_BUSINESS_MODEL_LOCAL = "LOCAL_SERVICE"; //调用本地 |
| | | |
| | | public final static String QUERY_MODEL_SQL = "1"; |
| | | public final static String QUERY_MODEL_PROC = "2"; |
| | | |
| | | } |
| | |
| | | public final static String RESULT_CODE_RULE_ERROR = "1995"; |
| | | |
| | | /** |
| | | * 参数不正确 |
| | | */ |
| | | public final static String RESULT_PARAM_ERROR = "1994"; |
| | | |
| | | /** |
| | | * 没有从报文中获取到 请求流水 |
| | | */ |
| | | public final static String NO_TRANSACTION_ID = "-1"; |
| New file |
| | |
| | | package com.java110.common.factory; |
| | | |
| | | import com.java110.common.cache.ServiceSqlCache; |
| | | import com.java110.entity.service.DataQuery; |
| | | import com.java110.entity.service.ServiceSql; |
| | | |
| | | /** |
| | | * 数据查询工厂类 |
| | | * Created by wuxw on 2018/4/19. |
| | | */ |
| | | public class DataQueryFactory { |
| | | |
| | | public static DataQuery newInstance(){ |
| | | return new DataQuery(); |
| | | } |
| | | |
| | | public static ServiceSql getServiceSql(DataQuery dataQuery){ |
| | | return ServiceSqlCache.getServiceSql(dataQuery.getServiceCode()); |
| | | } |
| | | } |
| | |
| | | public static JSONObject createCommonResponseJson(DataFlow dataFlow){ |
| | | return dataFlow.getResponseBusinessJson(); |
| | | } |
| | | |
| | | /** |
| | | * 业务系统返回报文模板 |
| | | * @param code |
| | | * @param message |
| | | * @param |
| | | * @return |
| | | */ |
| | | public static JSONObject createBusinessResponseJson(String code, String message){ |
| | | return createBusinessResponseJson(code, message,null); |
| | | } |
| | | /** |
| | | * 业务系统返回报文模板 |
| | | * @param code |
| | | * @param message |
| | | * @param info |
| | | * @return |
| | | */ |
| | | public static JSONObject createBusinessResponseJson(String code, String message, JSONObject info){ |
| | | JSONObject responseMessage = JSONObject.parseObject("{\"response\":{}}"); |
| | | |
| | | JSONObject response = responseMessage.getJSONObject("response"); |
| | | |
| | | response.put("code",code); |
| | | response.put("message",message); |
| | | if(info != null) { |
| | | responseMessage.putAll(info); |
| | | } |
| | | |
| | | return responseMessage; |
| | | } |
| | | } |
| | |
| | | status_cd VARCHAR(2) NOT NULL COMMENT '数据状态,详细参考c_status表,0在用,1失效' |
| | | ); |
| | | |
| | | -- c_service_sql |
| | | CREATE TABLE c_service_sql( |
| | | id INT NOT NULL AUTO_INCREMENT KEY COMMENT 'id', |
| | | service_code VARCHAR(50) NOT NULL COMMENT '对应c_service表', |
| | | `name` VARCHAR(50) NOT NULL COMMENT '名称', |
| | | params VARCHAR(500) NOT NULL COMMENT '参数', |
| | | query_model VARCHAR(1) NOT NULL COMMENT '查询方式 1、sql,2、存储过程', |
| | | `sql` LONGTEXT COMMENT '执行sql', |
| | | proc VARCHAR(200) COMMENT '存储过程名称', |
| | | template LONGTEXT COMMENT '输出模板', |
| | | 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','查询单','查询单'); |
| | |
| | | '8000418001','1','Q','0' |
| | | ); |
| | | |
| | | insert into c_route(app_id,service_id,order_type_cd,status_cd) values( |
| | | '8000418001','3','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'); |
| | | |
| | | insert into c_service(service_code,invoke_model,business_type_cd,`name`,seq,url,provide_app_id,status_cd) |
| | | values('query.order.orderInfo','1','Q','订单信息',1,'http://localhost:8001/queryApi/query','8000418001','0'); |
| | | |
| | | INSERT INTO c_service_sql(service_code,`name`,params,query_model,`sql`,proc,template,remark,status_cd) |
| | | VALUES('query.order.orderInfo','订单信息','oId','1','{ |
| | | "param1":"SELECT co.app_id appId,co.create_time createTime,co.ext_transaction_id extTransactionId,co.finish_time finishTime |
| | | ,co.order_type_cd orderTypeCd,co.o_id oId ,co.remark remark ,co.request_time requestTime ,co.user_id userId,co.status_cd statusCd |
| | | FROM c_orders co WHERE co.o_id = #oId#", |
| | | "param2":"SELECT cb.b_id bId, cb.business_type_cd businessTypeCd,cb.create_time createTime,cb.finish_time finishTime ,cb.o_id oId, |
| | | cb.remark remark,cb.status_cd statusCd FROM c_business cb WHERE cb.o_id = #oId#" |
| | | }','','{"PARAM:"{ |
| | | "param1": "$.#order#Object", |
| | | "param2": "$.#business#Array" |
| | | },"TEMPLATE":"{ |
| | | "response": { |
| | | "code": "0000", |
| | | "message": "成功" |
| | | } |
| | | }"}','','0'); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="queryServiceDAOImpl"> |
| | | |
| | | <resultMap type="com.java110.entity.service.ServiceSql" id="serviceSqlMap"> |
| | | <result column="service_code" jdbcType="VARCHAR" property="serviceCode"/> |
| | | <result column="name" jdbcType="VARCHAR" property="name"/> |
| | | <result column="params" jdbcType="VARCHAR" property="params"/> |
| | | <result column="query_model" jdbcType="VARCHAR" property="queryModel"/> |
| | | <result column="sql" jdbcType="CLOB" property="sql"/> |
| | | <result column="proc" jdbcType="VARCHAR" property="proc"/> |
| | | <result column="template" jdbcType="CLOB" property="template"/> |
| | | <result column="status_cd" jdbcType="VARCHAR" property="statusCd"/> |
| | | <result column="remark" jdbcType="VARCHAR" property="remark"/> |
| | | </resultMap> |
| | | |
| | | <parameterMap type="java.util.Map" id="qryProcParam"> |
| | | <parameter property="resMsg" javaType="java.lang.String" jdbcType="CLOB" mode="OUT" /> |
| | | </parameterMap> |
| | | |
| | | <!--保存订单信息 c_orders 中 --> |
| | | <select id="executeSql" parameterType="String" resultType="Map"> |
| | | ${value} |
| | | </select> |
| | | |
| | | <select id="executeProc" parameterMap="qryProcParam"> |
| | | {call ${procNameInfo}?)} |
| | | </select> |
| | | |
| | | <select id="qureyServiceSqlAll" resultMap="serviceSqlMap"> |
| | | SELECT css.service_code,css.name,css.params,css.query_model,css.sql, |
| | | css.proc,css.template,css.remark,css.status_cd |
| | | FROM c_service_sql css WHERE css.status_cd = '0' |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | */ |
| | | public static Class<DataFlowEvent> getEvent(String serviceCode) throws BusinessException{ |
| | | Class<DataFlowEvent> targetEvent = events.get(serviceCode); |
| | | Assert.notNull(targetEvent,"改服务未注册该事件[serviceCode = "+serviceCode+"],系统目前不支持!"); |
| | | //Assert.notNull(targetEvent,"改服务未注册该事件[serviceCode = "+serviceCode+"],系统目前不支持!"); |
| | | return targetEvent; |
| | | } |
| | | |
| | |
| | | try { |
| | | Class<DataFlowEvent> dataFlowEventClass = getEvent(serviceCode); |
| | | |
| | | if(dataFlowEventClass == null){ |
| | | return ; |
| | | } |
| | | |
| | | Class[] parameterTypes = {Object.class, DataFlow.class}; |
| | | |
| | | Constructor constructor = dataFlowEventClass.getClass().getConstructor(parameterTypes); |
| New file |
| | |
| | | package com.java110.service.dao; |
| | | |
| | | import com.java110.entity.service.ServiceSql; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 查询数据交互接口 |
| | | * Created by wuxw on 2018/4/20. |
| | | */ |
| | | public interface IQueryServiceDAO { |
| | | |
| | | /** |
| | | * 执行sql |
| | | * @param sql |
| | | * @return |
| | | */ |
| | | public List<Map> executeSql(String sql); |
| | | |
| | | /** |
| | | * 执行存储过程 |
| | | * @param paramsInfo |
| | | * @return |
| | | */ |
| | | public String executeProc(Map<String,Object> paramsInfo); |
| | | |
| | | public List<ServiceSql> qureyServiceSqlAll(); |
| | | } |
| New file |
| | |
| | | package com.java110.service.dao.impl; |
| | | |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.base.dao.BaseServiceDao; |
| | | import com.java110.entity.service.ServiceSql; |
| | | import com.java110.service.dao.IQueryServiceDAO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | /** |
| | | * Created by wuxw on 2018/4/20. |
| | | */ |
| | | @Service("queryServiceDAOImpl") |
| | | @Transactional |
| | | public class QueryServiceDAOImpl extends BaseServiceDao implements IQueryServiceDAO { |
| | | @Override |
| | | public List<Map> executeSql(String sql) { |
| | | logger.debug("----【queryServiceDAOImpl.executeSql】入参 : "+sql); |
| | | return sqlSessionTemplate.selectList("queryServiceDAOImpl.executeSql",sql); |
| | | } |
| | | |
| | | @Override |
| | | public String executeProc(Map<String,Object> paramsInfo) { |
| | | String paramsInfoStr = ""; |
| | | for (String key : paramsInfo.keySet()){ |
| | | if("procName".equals(key)){ |
| | | paramsInfoStr += (paramsInfo.get("procName") + "("); |
| | | }else{ |
| | | if(StringUtil.isNullOrNone(paramsInfo.get(key))){ |
| | | paramsInfoStr += "'',"; |
| | | }else{ |
| | | paramsInfoStr += "'"+paramsInfo.get(key)+"',"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | paramsInfo.put("paramsInfo",paramsInfoStr); |
| | | |
| | | sqlSessionTemplate.selectOne("queryServiceDAOImpl.executeProc",paramsInfo); |
| | | |
| | | return paramsInfo.get("resMsg") ==null ?"" :paramsInfo.get("resMsg").toString(); |
| | | } |
| | | |
| | | /** |
| | | * 查询 ServiceSql |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<ServiceSql> qureyServiceSqlAll() { |
| | | return sqlSessionTemplate.selectList("queryServiceDAOImpl.qureyServiceSqlAll"); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.service.rest; |
| | | |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.factory.DataQueryFactory; |
| | | import com.java110.common.util.ResponseTemplateUtil; |
| | | import com.java110.core.base.controller.BaseController; |
| | | import com.java110.entity.service.DataQuery; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 查询服务 |
| | | * Created by wuxw on 2018/4/20. |
| | | */ |
| | | @RestController |
| | | public class QueryApi extends BaseController { |
| | | |
| | | @Autowired |
| | | private IQueryServiceSMO queryServiceSMOImpl; |
| | | |
| | | @RequestMapping(path = "/queryApi/query",method= RequestMethod.GET) |
| | | public String queryGet(HttpServletRequest request) { |
| | | return ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,"不支持Get方法请求").toJSONString(); |
| | | } |
| | | |
| | | /** |
| | | * { |
| | | "bId":"12345678", |
| | | "serviceCode": "querycustinfo", |
| | | "serviceName": "查询客户", |
| | | "remark": "备注", |
| | | "datas": { |
| | | "params": { |
| | | //这个做查询时的参数 |
| | | } |
| | | //这里是具体业务 |
| | | } |
| | | } |
| | | * @param businessInfo |
| | | * @return |
| | | */ |
| | | @RequestMapping(path = "/queryApi/query",method= RequestMethod.POST) |
| | | public String servicePost(@RequestBody String businessInfo) { |
| | | try { |
| | | DataQuery dataQuery = DataQueryFactory.newInstance().builder(businessInfo); |
| | | initConfig(dataQuery); |
| | | queryServiceSMOImpl.commonQueryService(dataQuery); |
| | | return dataQuery.getResponseInfo().toJSONString(); |
| | | }catch (Exception e){ |
| | | logger.error("请求订单异常",e); |
| | | return ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化配置 |
| | | * @param dataQuery |
| | | */ |
| | | private void initConfig(DataQuery dataQuery){ |
| | | dataQuery.setServiceSql(DataQueryFactory.getServiceSql(dataQuery)); |
| | | } |
| | | |
| | | public IQueryServiceSMO getQueryServiceSMOImpl() { |
| | | return queryServiceSMOImpl; |
| | | } |
| | | |
| | | public void setQueryServiceSMOImpl(IQueryServiceSMO queryServiceSMOImpl) { |
| | | this.queryServiceSMOImpl = queryServiceSMOImpl; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.service.smo; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.exception.BusinessException; |
| | | import com.java110.entity.service.DataQuery; |
| | | |
| | | /** |
| | | * 公用查询处理 |
| | | * Created by wuxw on 2018/4/19. |
| | | */ |
| | | public interface IQueryServiceSMO { |
| | | |
| | | /** |
| | | * c_common_sql |
| | | * 公共查询服务 |
| | | * @return |
| | | * @throws BusinessException |
| | | */ |
| | | public void commonQueryService(DataQuery dataQuery) throws BusinessException; |
| | | } |
| New file |
| | |
| | | package com.java110.service.smo.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.JSONPath; |
| | | import com.java110.common.cache.ServiceSqlCache; |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.exception.BusinessException; |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.ResponseTemplateUtil; |
| | | import com.java110.entity.service.DataQuery; |
| | | import com.java110.entity.service.ServiceSql; |
| | | import com.java110.service.dao.IQueryServiceDAO; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | /** |
| | | * Created by wuxw on 2018/4/19. |
| | | */ |
| | | @Service("queryServiceSMOImpl") |
| | | @Transactional |
| | | public class QueryServiceSMOImpl extends LoggerEngine implements IQueryServiceSMO { |
| | | |
| | | @Autowired |
| | | private IQueryServiceDAO queryServiceDAOImpl; |
| | | |
| | | @Override |
| | | public void commonQueryService(DataQuery dataQuery) throws BusinessException { |
| | | //查询缓存查询 对应处理的ServiceSql |
| | | try { |
| | | ServiceSql currentServiceSql = ServiceSqlCache.getServiceSql(dataQuery.getServiceCode()); |
| | | if (currentServiceSql == null) { |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"未提供该服务 serviceCode = " + dataQuery.getServiceCode()); |
| | | } |
| | | if ("".equals(currentServiceSql.getQueryModel())) { |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员"); |
| | | } |
| | | dataQuery.setServiceSql(currentServiceSql); |
| | | if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) { |
| | | doExecuteSql(dataQuery); |
| | | return; |
| | | } |
| | | doExecuteProc(dataQuery); |
| | | }catch (BusinessException e){ |
| | | logger.error("公用查询异常:",e); |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, |
| | | e.getMessage())); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * {"PARAM:"{ |
| | | "param1": "$.a.#A#Object", |
| | | "param2": "$.a.b.A#B#Array", |
| | | "param3": "$.a.b.c.A.B#C#Array" |
| | | },"TEMPLATE":"{}" |
| | | } |
| | | * 执行sql |
| | | * @param dataQuery |
| | | */ |
| | | private void doExecuteSql(DataQuery dataQuery) throws BusinessException{ |
| | | |
| | | JSONObject templateObj = JSONObject.parseObject(dataQuery.getServiceSql().getTemplate()); |
| | | JSONObject templateParams = templateObj.getJSONObject("PARAM"); |
| | | JSONObject business = JSONObject.parseObject(templateObj.getString("TEMPLATE")); |
| | | String template = ""; |
| | | String[] values = null; |
| | | JSONObject currentJsonObj = null; |
| | | JSONArray currentJsonArr = null; |
| | | for(String key:templateParams.keySet()){ |
| | | template = templateParams.getString(key); |
| | | if(!template.startsWith("$.")){ |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,value 必须以$.开头"); |
| | | } |
| | | values = template.split("#"); |
| | | |
| | | if(values == null || values.length != 3){ |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,value 必须有两个#号"); |
| | | } |
| | | Object o = JSONPath.eval(business,values[0]); |
| | | dataQuery.setTemplateKey(key); |
| | | if(o instanceof JSONObject){ |
| | | currentJsonObj = (JSONObject)o; |
| | | doJsonObject(currentJsonObj,dataQuery,values); |
| | | }else if(o instanceof JSONArray){ |
| | | currentJsonArr = (JSONArray) o; |
| | | doJsonArray(currentJsonArr,dataQuery,values); |
| | | }else{ |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,value 值 和 TEMPLATE 配置不一致"); |
| | | } |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",business)); |
| | | } |
| | | |
| | | /** |
| | | * 处理 jsonObject |
| | | * @param obj |
| | | * @param dataQuery |
| | | * @param values |
| | | */ |
| | | private void doJsonObject(JSONObject obj,DataQuery dataQuery,String[] values){ |
| | | try { |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | JSONObject sqlObj = JSONObject.parseObject(dataQuery.getServiceSql().getSql()); |
| | | |
| | | String currentSql = sqlObj.getString(dataQuery.getTemplateKey()); |
| | | String[] sqls = currentSql.split("#"); |
| | | String currentSqlNew = ""; |
| | | for (int sqlIndex = 0; sqlIndex < sqls.length; sqlIndex++) { |
| | | if (sqlIndex % 2 == 0) { |
| | | currentSqlNew += sqls[sqlIndex]; |
| | | continue; |
| | | } |
| | | if (sqls[sqlIndex].startsWith("PARENT_")) { |
| | | for (String key : obj.keySet()) { |
| | | if (sqls[sqlIndex].substring("PARENT_".length()).equals(key)) { |
| | | currentSqlNew += obj.get(key) instanceof Integer |
| | | ? obj.getInteger(key) : "'" + obj.getString(key) + "'"; |
| | | continue; |
| | | } |
| | | } |
| | | } else { |
| | | currentSqlNew += params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "'" + params.getString(sqls[sqlIndex]) + "'"; |
| | | } |
| | | } |
| | | |
| | | List<Map> results = queryServiceDAOImpl.executeSql(currentSqlNew); |
| | | |
| | | if (results == null || results.size() == 0) { |
| | | obj.put(values[1], new JSONObject()); |
| | | return; |
| | | } |
| | | if (values[2].equals("Object")) { |
| | | obj.put(values[1], JSONObject.parseObject(JSONObject.toJSONString(results.get(0)))); |
| | | } else if (values[2].equals("Array")) { |
| | | obj.put(values[1], JSONArray.parseArray(JSONArray.toJSONString(results))); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("数据交互异常:",e); |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"数据交互异常。。。"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理JSONArray |
| | | * @param objs |
| | | * @param dataQuery |
| | | * @param values |
| | | */ |
| | | private void doJsonArray(JSONArray objs,DataQuery dataQuery,String[] values){ |
| | | |
| | | for (int objIndex = 0 ; objIndex < objs.size();objIndex ++){ |
| | | doJsonObject(objs.getJSONObject(objIndex),dataQuery,values); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 执行存储 |
| | | * @param dataQuery |
| | | */ |
| | | private void doExecuteProc(DataQuery dataQuery){ |
| | | Map info = new TreeMap(); |
| | | info.put("procName",dataQuery.getServiceSql().getProc()); |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | info.putAll(params); |
| | | |
| | | String jsonStr = queryServiceDAOImpl.executeProc(info); |
| | | |
| | | if(!Assert.isJsonObject(jsonStr)){ |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",JSONObject.parseObject(jsonStr))); |
| | | } |
| | | |
| | | |
| | | public IQueryServiceDAO getQueryServiceDAOImpl() { |
| | | return queryServiceDAOImpl; |
| | | } |
| | | |
| | | public void setQueryServiceDAOImpl(IQueryServiceDAO queryServiceDAOImpl) { |
| | | this.queryServiceDAOImpl = queryServiceDAOImpl; |
| | | } |
| | | } |