1个文件已删除
17个文件已修改
2 文件已重命名
6个文件已添加
| | |
| | | "value": "具体值" |
| | | }] |
| | | }, |
| | | "business": [{ |
| | | // 如果是批量方式 写成 "business":[{....}] |
| | | "business": { |
| | | "serviceCode": "queryCustInfo", |
| | | "serviceName": "查询客户", |
| | | "remark": "备注", |
| | |
| | | "specCd": "配置的字段ID", |
| | | "value": "具体值" |
| | | }] |
| | | }] |
| | | } |
| | | } |
| | |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | | import com.java110.core.factory.DataFlowFactory; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.entity.center.AppRoute; |
| | | import com.java110.entity.center.AppService; |
| | | import com.java110.entity.center.Business; |
| | |
| | | } |
| | | // |
| | | if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){ |
| | | dataFlow.setDataFlowId(SequenceUtil.getDataFlowId()); |
| | | dataFlow.setDataFlowId(GenerateCodeFactory.getDataFlowId()); |
| | | } |
| | | |
| | | //添加耗时 |
| | |
| | | package com.java110.code.api; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.code.smo.IPrimaryKeyServiceSMO; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.exception.ResponseErrorException; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.core.base.controller.BaseController; |
| | | import com.java110.core.context.CodeDataFlow; |
| | | import com.java110.core.factory.DataFlowFactory; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | import com.java110.feign.code.ICodeApi; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * ID 生成 |
| | | * Created by wuxw on 2018/6/3. |
| | | */ |
| | | @RestController |
| | | public class CodeApi extends BaseController { |
| | | public class CodeApi extends BaseController implements ICodeApi { |
| | | |
| | | @Autowired |
| | | IPrimaryKeyServiceSMO primaryKeyServiceSMOImpl; |
| | | |
| | | @RequestMapping(path = "/codeApi/generate",method= RequestMethod.GET) |
| | | @RequestMapping(path = "/codeApi/generate", method = RequestMethod.GET) |
| | | public String generateGet(HttpServletRequest request) { |
| | | return DataTransactionFactory.createCodeResponseJson(ResponseConstant.NO_TRANSACTION_ID,"-1", |
| | | ResponseConstant.RESULT_CODE_ERROR,"不支持Get方法请求").toJSONString(); |
| | | return DataTransactionFactory.createCodeResponseJson(ResponseConstant.NO_TRANSACTION_ID, "-1", |
| | | ResponseConstant.RESULT_CODE_ERROR, "不支持Get方法请求").toJSONString(); |
| | | } |
| | | |
| | | @RequestMapping(path = "/codeApi/generate",method= RequestMethod.POST) |
| | | public String generatePost(@RequestBody String orderInfo,HttpServletRequest request) { |
| | | @RequestMapping(path = "/codeApi/generate", method = RequestMethod.POST) |
| | | public String generatePost(@RequestBody String orderInfo, HttpServletRequest request) { |
| | | Map<String, String> headers = new HashMap<String, String>(); |
| | | try { |
| | | getRequestInfo(request, headers); |
| | | //预校验 |
| | | preValiateOrderInfo(orderInfo,headers); |
| | | CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(orderInfo,null); |
| | | preValiateOrderInfo(orderInfo, headers); |
| | | CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(orderInfo, null); |
| | | primaryKeyServiceSMOImpl.generateCode(dataFlow); |
| | | return dataFlow.getResJson().toJSONString(); |
| | | }catch (Exception e){ |
| | | logger.error("请求订单异常",e); |
| | | return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString(); |
| | | } catch (Exception e) { |
| | | logger.error("请求订单异常", e); |
| | | return DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR, e.getMessage() + e).toJSONString(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取请求信息 |
| | | * |
| | | * @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); |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 这里预校验,请求报文中不能有 dataFlowId |
| | | * |
| | | * @param orderInfo |
| | | */ |
| | | private void preValiateOrderInfo(String orderInfo,Map<String, String> headers) { |
| | | private void preValiateOrderInfo(String orderInfo, Map<String, String> headers) { |
| | | |
| | | Assert.jsonObjectHaveKey(orderInfo,"prefix","没有包含prefix"); |
| | | Assert.jsonObjectHaveKey(orderInfo, "prefix", "没有包含prefix"); |
| | | |
| | | Assert.jsonObjectHaveKey(orderInfo,"transactionId","没有包含transactionId"); |
| | | Assert.jsonObjectHaveKey(orderInfo, "transactionId", "没有包含transactionId"); |
| | | |
| | | } |
| | | |
| | |
| | | public void setPrimaryKeyServiceSMOImpl(IPrimaryKeyServiceSMO primaryKeyServiceSMOImpl) { |
| | | this.primaryKeyServiceSMOImpl = primaryKeyServiceSMOImpl; |
| | | } |
| | | |
| | | /** |
| | | * 生成 编码 |
| | | * |
| | | * @param prefix 前缀 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String generateCode(String prefix) { |
| | | |
| | | try { |
| | | JSONObject requestInfo = new JSONObject(); |
| | | |
| | | //封装符合构建CodeDataFlow对象的JSON对象参数 |
| | | builderRequestInfo(prefix, requestInfo); |
| | | |
| | | CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(requestInfo.toJSONString(), null); |
| | | |
| | | //生成编码 |
| | | primaryKeyServiceSMOImpl.generateCode(dataFlow); |
| | | |
| | | if (!ResponseConstant.RESULT_CODE_SUCCESS.equals(dataFlow.getResJson().getString("code"))) { |
| | | throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "生成oId编码失败 " |
| | | + dataFlow.getResJson().getString("message")); |
| | | } |
| | | |
| | | return dataFlow.getResJson().getString("id"); |
| | | } catch (Exception e) { |
| | | logger.error("请求订单异常", e); |
| | | return ResponseConstant.RESULT_CODE_ERROR; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 封装符合构建CodeDataFlow对象的JSON对象参数 |
| | | * |
| | | * @param prefix 前缀 |
| | | * @param requestInfo 构建的请求JSON对象 |
| | | */ |
| | | private void builderRequestInfo(String prefix, JSONObject requestInfo) { |
| | | requestInfo.put("transactionId", UUID.randomUUID().toString().replace("-", "")); |
| | | requestInfo.put("prefix", prefix); |
| | | requestInfo.put("requestTime", DateUtil.getNowDefault()); |
| | | } |
| | | } |
| New file |
| | |
| | | -- 日志表 |
| | | |
| | | create table l_transaction_log( |
| | | log_id varchar(30) not null keY unique COMMENT 'id', |
| | | transaction_id VARCHAR(30) NOT NULL COMMENT '外部交易流水', |
| | | contract_id varchar(64) not null comment '上下文ID', |
| | | ip varchar(20) not null comment '日志产生主机IP', |
| | | port varchar(10) not null comment '日志产生端口', |
| | | src_ip varchar(20) comment '调用方IP', |
| | | src_port varchar(10) comment '调用方端口', |
| | | app_id varchar(30) not null comment '调用方应用ID', |
| | | user_id varchar(30) comment '用户ID', |
| | | service_code varchar(50) comment '服务编码', |
| | | service_name varchar(50) comment '服务名称', |
| | | timestamp TIMESTAMP NOT NULL comment '日志交互时间,时间戳', |
| | | status_cd varchar(2) not null comment '交互状态 S 成功 F 失败', |
| | | month INT NOT NULL default month(CURRENT_DATE) comment '月份', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | PRIMARY KEY (log_id) |
| | | ) |
| | | partition BY RANGE (month) ( |
| | | partition transaction_log_1 VALUES LESS THAN (2), |
| | | partition transaction_log_2 VALUES LESS THAN (3), |
| | | partition transaction_log_3 VALUES LESS THAN (4), |
| | | partition transaction_log_4 VALUES LESS THAN (5), |
| | | partition transaction_log_5 VALUES LESS THAN (6), |
| | | partition transaction_log_6 VALUES LESS THAN (7), |
| | | partition transaction_log_7 VALUES LESS THAN (8), |
| | | partition transaction_log_8 VALUES LESS THAN (9), |
| | | partition transaction_log_9 VALUES LESS THAN (10), |
| | | partition transaction_log_10 VALUES LESS THAN (11), |
| | | partition transaction_log_11 VALUES LESS THAN (12), |
| | | partition transaction_log_12 VALUES LESS THAN (13) |
| | | ); |
| | | |
| | | |
| | | |
| | | -- 日志原始内容表 |
| | | |
| | | create table l_transaction_log_message( |
| | | log_id varchar(30) not null unique FOREIGN KEY REFERENCES l_transaction_log(log_id) COMMENT 'id', |
| | | request_header LONGTEXT COMMENT '请求头信息', |
| | | response_header LONGTEXT COMMENT '返回头信息', |
| | | request_message LONGTEXT comment '请求报文', |
| | | response_message LONGTEXT comment '返回报文', |
| | | remark varchar(200) comment '备注', |
| | | month INT NOT NULL default month(CURRENT_DATE) comment '月份', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' |
| | | ) |
| | | partition BY RANGE (month) ( |
| | | partition transaction_log_message_1 VALUES LESS THAN (2), |
| | | partition transaction_log_message_2 VALUES LESS THAN (3), |
| | | partition transaction_log_message_3 VALUES LESS THAN (4), |
| | | partition transaction_log_message_4 VALUES LESS THAN (5), |
| | | partition transaction_log_message_5 VALUES LESS THAN (6), |
| | | partition transaction_log_message_6 VALUES LESS THAN (7), |
| | | partition transaction_log_message_7 VALUES LESS THAN (8), |
| | | partition transaction_log_message_8 VALUES LESS THAN (9), |
| | | partition transaction_log_message_9 VALUES LESS THAN (10), |
| | | partition transaction_log_message_10 VALUES LESS THAN (11), |
| | | partition transaction_log_message_11 VALUES LESS THAN (12), |
| | | partition transaction_log_message_12 VALUES LESS THAN (13) |
| | | ); |
| | | |
| New file |
| | |
| | | package com.java110.log.dao; |
| | | |
| | | import com.java110.common.exception.DAOException; |
| | | import com.java110.entity.order.BusiOrder; |
| | | import com.java110.entity.order.BusiOrderAttr; |
| | | import com.java110.entity.order.OrderList; |
| | | import com.java110.entity.order.OrderListAttr; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 购物车,订单项信息管理 |
| | | * |
| | | * 增加,查询 |
| | | * 没有查询,理论上购物车信息,不允许删除和修改 |
| | | * |
| | | * Created by wuxw on 2016/12/27. |
| | | */ |
| | | public interface LogServiceDao { |
| | | |
| | | /** |
| | | * 保存日志 |
| | | * 相关表 l_transaction_log |
| | | * @param logMessageParams 日志参数信息 |
| | | */ |
| | | public void saveTransactionLog(Map logMessageParams) throws DAOException; |
| | | |
| | | /** |
| | | * 保存日志(交互报文) |
| | | * 相关表 l_transaction_log_message |
| | | * @param logMessageParams 日志参数信息 |
| | | */ |
| | | public void saveTransactionLogMessage(Map logMessageParams) throws DAOException; |
| | | } |
| | |
| | | package com.java110.log.dao.impl; |
| | | |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.exception.DAOException; |
| | | import com.java110.core.base.dao.BaseServiceDao; |
| | | import com.java110.entity.order.BusiOrder; |
| | | import com.java110.entity.order.BusiOrderAttr; |
| | | import com.java110.entity.order.OrderList; |
| | | import com.java110.entity.order.OrderListAttr; |
| | | import com.java110.log.dao.logServiceDao; |
| | | import com.java110.log.dao.LogServiceDao; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 日志服务 与数据库交互 |
| | |
| | | */ |
| | | |
| | | @Service("logServiceDaoImpl") |
| | | @Transactional |
| | | public class LogServiceDaoImpl extends BaseServiceDao implements logServiceDao { |
| | | //@Transactional |
| | | public class LogServiceDaoImpl extends BaseServiceDao implements LogServiceDao { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(LogServiceDaoImpl.class); |
| | | |
| | | /** |
| | | * 保存日志 |
| | | * @param logMessageParams 日志参数信息 |
| | | */ |
| | | @Override |
| | | public void saveTransactionLog(Map logMessageParams) throws DAOException { |
| | | logger.debug("save log params :{}",logMessageParams); |
| | | try{ |
| | | int row = sqlSessionTemplate.insert("logServiceDaoImpl.saveTransactionLog",logMessageParams); |
| | | if(row < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_CODE_INNER_ERROR,"save log error, nothing to save"); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("save log error:",e); |
| | | throw new DAOException(ResponseConstant.RESULT_CODE_INNER_ERROR,"save log error"+e); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 保存日志(交互报文) |
| | | * @param logMessageParams 日志参数信息 |
| | | */ |
| | | @Override |
| | | public void saveTransactionLogMessage(Map logMessageParams) throws DAOException{ |
| | | logger.debug("save log message params :{}",logMessageParams); |
| | | try{ |
| | | int row = sqlSessionTemplate.insert("logServiceDaoImpl.saveTransactionLogMessage",logMessageParams); |
| | | if(row < 1){ |
| | | throw new DAOException(ResponseConstant.RESULT_CODE_INNER_ERROR,"save log error, nothing to save"); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("save log error:",e); |
| | | throw new DAOException(ResponseConstant.RESULT_CODE_INNER_ERROR,"save log error"+e); |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * kafka侦听 |
| | | * 接受到的信息报文格式为: |
| | | * { |
| | | * "transactionId":"交易流水号", |
| | | * "dataFlowId":"上下文对象", |
| | | * "ip":"ip", |
| | | * "port":"端口", |
| | | * "srcIp":"调用方IP", |
| | | * "srcPort":"调用方端口", |
| | | * "appId":"应用ID", |
| | | * "userId":"用户ID", |
| | | * "serviceCode":"服务编码", |
| | | * "serviceName":"服务名称", |
| | | * "timestamp":"时间储", |
| | | * "logStatus":"记录状态", |
| | | * "requestMessage":"请求信息", |
| | | * "responseMessage":"返回信息" |
| | | * } |
| | | * Created by wuxw on 2018/4/15. |
| | | */ |
| | | public class LogServiceKafka extends BaseController { |
| | |
| | | |
| | | @KafkaListener(topics = {KafkaConstant.TOPIC_LOG_NAME}) |
| | | public void listen(ConsumerRecord<?, ?> record) { |
| | | logger.info("kafka的key: " + record.key()); |
| | | logger.info("kafka的value: " + record.value().toString()); |
| | | String orderInfo = record.value().toString(); |
| | | BusinessServiceDataFlow businessServiceDataFlow = null; |
| | | JSONObject responseJson = null; |
| | | try { |
| | | Map<String, String> headers = new HashMap<String, String>(); |
| | | //预校验 |
| | | preValiateOrderInfo(orderInfo); |
| | | businessServiceDataFlow = this.writeDataToDataFlowContext(orderInfo, headers); |
| | | //responseJson = logServiceSMOImpl.service(businessServiceDataFlow); |
| | | }catch (InitDataFlowContextException e){ |
| | | logger.error("请求报文错误,初始化 BusinessServiceDataFlow失败"+orderInfo,e); |
| | | responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo,ResponseConstant.RESULT_PARAM_ERROR,e.getMessage(),null); |
| | | }catch (InitConfigDataException e){ |
| | | logger.error("请求报文错误,加载配置信息失败"+orderInfo,e); |
| | | responseJson = DataTransactionFactory.createNoBusinessTypeBusinessResponseJson(orderInfo,ResponseConstant.RESULT_PARAM_ERROR,e.getMessage(),null); |
| | | }catch (Exception e){ |
| | | logger.error("请求订单异常",e); |
| | | responseJson = DataTransactionFactory.createBusinessResponseJson(businessServiceDataFlow,ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e, |
| | | null); |
| | | }finally { |
| | | logger.debug("当前请求报文:" + orderInfo +", 当前返回报文:" +responseJson.toJSONString()); |
| | | //只有business 和 instance 过程才做通知消息 |
| | | if(!StatusConstant.REQUEST_BUSINESS_TYPE_BUSINESS.equals(responseJson.getString("businessType")) |
| | | && !StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(responseJson.getString("businessType"))){ |
| | | return ; |
| | | } |
| | | try { |
| | | KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_NOTIFY_CENTER_SERVICE_NAME, "", responseJson.toJSONString()); |
| | | }catch (Exception e){ |
| | | logger.error("用户服务通知centerService失败"+responseJson,e); |
| | | //这里保存异常信息 |
| | | } |
| | | } |
| | | logger.info("LogServiceKafka receive message: {}", record.value().toString()); |
| | | String logMessage = record.value().toString(); |
| | | logServiceSMOImpl.saveLogMessage(logMessage); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 这里预校验,请求报文中不能有 dataFlowId |
| | | * @param orderInfo |
| | | */ |
| | | private void preValiateOrderInfo(String orderInfo) { |
| | | /* if(JSONObject.parseObject(orderInfo).getJSONObject("orders").containsKey("dataFlowId")){ |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_ERROR,"报文中不能存在dataFlowId节点"); |
| | | }*/ |
| | | } |
| | | |
| | | public ILogServiceSMO getLogServiceSMOImpl() { |
| | | return logServiceSMOImpl; |
| | |
| | | */ |
| | | public interface ILogServiceSMO { |
| | | |
| | | /** |
| | | * 保存日志信息 |
| | | * { |
| | | * "transactionId":"交易流水号", |
| | | * "dataFlowId":"上下文对象", |
| | | * "ip":"ip", |
| | | * "port":"端口", |
| | | * "srcIp":"调用方IP", |
| | | * "srcPort":"调用方端口", |
| | | * "appId":"应用ID", |
| | | * "userId":"用户ID", |
| | | * "serviceCode":"服务编码", |
| | | * "serviceName":"服务名称", |
| | | * "timestamp":"时间储", |
| | | * "logStatus":"记录状态", |
| | | * "requestMessage":"请求信息", |
| | | * "responseMessage":"返回信息" |
| | | * } |
| | | * @param logMessage 需要保存的日志信息 |
| | | * 从kafka 中读取日志消息保存 |
| | | */ |
| | | public void saveLogMessage(String logMessage); |
| | | |
| | | } |
| | |
| | | package com.java110.log.smo.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.exception.GenerateCodeException; |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.log.dao.LogServiceDao; |
| | | import com.java110.log.smo.ILogServiceSMO; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.rmi.NoSuchObjectException; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 订单服务业务逻辑处理实现类 |
| | | * 日志 消息处理类 |
| | | * Created by wuxw on 2017/4/11. |
| | | */ |
| | | @Service("orderServiceSMOImpl") |
| | | @Service("logServiceSMOImpl") |
| | | @Transactional |
| | | public class LogServiceSMOImpl extends BaseServiceSMO implements ILogServiceSMO { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(LogServiceSMOImpl.class); |
| | | |
| | | @Autowired |
| | | private LogServiceDao logServiceDaoImpl; |
| | | |
| | | /** |
| | | * 保存日志信息 |
| | | * @param logMessage 需要保存的日志信息 |
| | | */ |
| | | @Override |
| | | public void saveLogMessage(String logMessage) { |
| | | logger.debug("received log message : {}" ,logMessage); |
| | | |
| | | try{ |
| | | doSaveLogMessage(logMessage); |
| | | }catch (Exception e){ |
| | | logger.error("save log message error :",e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @param logMessage 需要保存的日志信息 |
| | | */ |
| | | private void doSaveLogMessage(String logMessage) throws Exception { |
| | | |
| | | JSONObject logMessageObj = JSONObject.parseObject(logMessage); |
| | | //校验 |
| | | validateLogMessage(logMessageObj); |
| | | |
| | | // 调用服务生成log_id |
| | | String log_id = GenerateCodeFactory.getInnerTransactionId(); |
| | | |
| | | // 封装日志保存参数 |
| | | Map logMessageParams= new HashMap(); |
| | | logMessageParams.put("logId",log_id); |
| | | builderLogMessageParams(logMessageParams,logMessageObj); |
| | | |
| | | //保存日志 |
| | | logServiceDaoImpl.saveTransactionLog(logMessageParams); |
| | | //保存日志(交互报文) |
| | | logServiceDaoImpl.saveTransactionLogMessage(logMessageParams); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 封装日志保存参数 |
| | | * @param logMessageParams 日志保存参数 |
| | | */ |
| | | private void builderLogMessageParams(Map logMessageParams,JSONObject logMessageObj) throws Exception{ |
| | | |
| | | logMessageParams.putAll(logMessageObj); |
| | | //#{requestHeader},#{responseHeader},#{requestMessage},#{responseMessage},#{remark} |
| | | String requestMessage = logMessageObj.getString("requestMessage"); |
| | | String responseMessage = logMessageObj.getString("responseMessage"); |
| | | |
| | | JSONObject requestMessageObj = JSONObject.parseObject(requestMessage); |
| | | JSONObject responseMessageObj = JSONObject.parseObject(responseMessage); |
| | | |
| | | logMessageParams.put("requestHeader",requestMessageObj.getString("headers")); |
| | | logMessageParams.put("requestMessage",requestMessageObj.getString("body")); |
| | | logMessageParams.put("responseHeader",responseMessageObj.getString("headers")); |
| | | logMessageParams.put("responseMessage",responseMessageObj.getString("body")); |
| | | |
| | | logMessageParams.put("timestamp", DateUtil.getDefaultDateFromString(logMessageObj.getString("timestamp"))); |
| | | } |
| | | |
| | | /** |
| | | * 校验 日志报文 必填节点是否存在 |
| | | * @param logMessageObj JSON 化的日志信息 |
| | | */ |
| | | private void validateLogMessage(JSONObject logMessageObj){ |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"transactionId","can not find transactionId node or transactionId is null"); |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"dataFlowId","can not find dataFlowId node or dataFlowId is null"); |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"ip","can not find ip node or ip is null"); |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"port","can not find port node or port is null"); |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"appId","can not find appId node or appId is null"); |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"timestamp","can not find timestamp node or timestamp is null"); |
| | | |
| | | Assert.hasKeyAndValue(logMessageObj,"logStatus","can not find logStatus node or logStatus is null"); |
| | | |
| | | Assert.hasKey(logMessageObj,"requestMessage","can not find requestMessage node "); |
| | | |
| | | Assert.hasKey(logMessageObj,"responseMessage","can not find responseMessage node "); |
| | | } |
| | | |
| | | |
| | | public LogServiceDao getLogServiceDaoImpl() { |
| | | return logServiceDaoImpl; |
| | | } |
| | | |
| | | public void setLogServiceDaoImpl(LogServiceDao logServiceDaoImpl) { |
| | | this.logServiceDaoImpl = logServiceDaoImpl; |
| | | } |
| | | } |
| | |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.constant.ServiceCodeConstant; |
| | | import com.java110.common.constant.StatusConstant; |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.SequenceUtil; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | import com.java110.entity.center.Business; |
| | |
| | | |
| | | if(businessUser.getInteger("userId") < 0){ |
| | | //生成userId |
| | | String userId = SequenceUtil.getUserId(); |
| | | String userId = GenerateCodeFactory.getUserId(); |
| | | businessUser.put("userId",userId); |
| | | } |
| | | dataFlowContext.addParamOut("userId",businessUser.getString("userId")); |
| | |
| | | Assert.jsonObjectHaveKey(userAttr,"attrId","businessUserAttr 节点下没有包含 attrId 节点"); |
| | | |
| | | if(userAttr.getInteger("attrId") < 0){ |
| | | String attrId = SequenceUtil.getAttrId(); |
| | | String attrId = GenerateCodeFactory.getAttrId(); |
| | | userAttr.put("attrId",attrId); |
| | | } |
| | | |
| | |
| | | isNotNull(info,key,message); |
| | | } |
| | | |
| | | /** |
| | | * 判断 jsonObject 是否为空 |
| | | * @param info |
| | | * @param key |
| | | * @param message |
| | | */ |
| | | public static void hasKeyAndValue(Map info,String key,String message){ |
| | | isNotNull(info,key,message); |
| | | hasLength(info.get(key)== null?"":info.get(key).toString(),message); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 判断json是否为空 |
| | |
| | | |
| | | public static JSONObject createRequestTcpContJson(String serviceCode) { |
| | | //获取交易流水 |
| | | String transactionId = SequenceUtil.getTransactionId(); |
| | | String transactionId = "-1"; |
| | | tcpContJson = new JSONObject(); |
| | | tcpContJson.put("transactionId", transactionId); |
| | | tcpContJson.put("serviceCode", serviceCode); |
| New file |
| | |
| | | -- 日志表 |
| | | |
| | | create table l_transaction_log( |
| | | log_id varchar(30) not null keY unique COMMENT 'id', |
| | | transaction_id VARCHAR(30) NOT NULL COMMENT '外部交易流水', |
| | | contract_id varchar(64) not null comment '上下文ID', |
| | | ip varchar(20) not null comment '日志产生主机IP', |
| | | port varchar(10) not null comment '日志产生端口', |
| | | src_ip varchar(20) comment '调用方IP', |
| | | src_port varchar(10) comment '调用方端口', |
| | | app_id varchar(30) not null comment '调用方应用ID', |
| | | user_id varchar(30) comment '用户ID', |
| | | service_code varchar(50) comment '服务编码', |
| | | service_name varchar(50) comment '服务名称', |
| | | timestamp TIMESTAMP NOT NULL comment '日志交互时间,时间戳', |
| | | status_cd varchar(2) not null comment '交互状态 S 成功 F 失败', |
| | | month INT NOT NULL default month(CURRENT_DATE) comment '月份', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | | PRIMARY KEY (log_id) |
| | | ) |
| | | partition BY RANGE (month) ( |
| | | partition transaction_log_1 VALUES LESS THAN (2), |
| | | partition transaction_log_2 VALUES LESS THAN (3), |
| | | partition transaction_log_3 VALUES LESS THAN (4), |
| | | partition transaction_log_4 VALUES LESS THAN (5), |
| | | partition transaction_log_5 VALUES LESS THAN (6), |
| | | partition transaction_log_6 VALUES LESS THAN (7), |
| | | partition transaction_log_7 VALUES LESS THAN (8), |
| | | partition transaction_log_8 VALUES LESS THAN (9), |
| | | partition transaction_log_9 VALUES LESS THAN (10), |
| | | partition transaction_log_10 VALUES LESS THAN (11), |
| | | partition transaction_log_11 VALUES LESS THAN (12), |
| | | partition transaction_log_12 VALUES LESS THAN (13) |
| | | ); |
| | | |
| | | |
| | | |
| | | -- 日志原始内容表 |
| | | |
| | | create table l_transaction_log_message( |
| | | log_id varchar(30) not null unique FOREIGN KEY REFERENCES l_transaction_log(log_id) COMMENT 'id', |
| | | request_header LONGTEXT COMMENT '请求头信息', |
| | | response_header LONGTEXT COMMENT '返回头信息', |
| | | request_message LONGTEXT comment '请求报文', |
| | | response_message LONGTEXT comment '返回报文', |
| | | remark varchar(200) comment '备注', |
| | | month INT NOT NULL default month(CURRENT_DATE) comment '月份', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' |
| | | ) |
| | | partition BY RANGE (month) ( |
| | | partition transaction_log_message_1 VALUES LESS THAN (2), |
| | | partition transaction_log_message_2 VALUES LESS THAN (3), |
| | | partition transaction_log_message_3 VALUES LESS THAN (4), |
| | | partition transaction_log_message_4 VALUES LESS THAN (5), |
| | | partition transaction_log_message_5 VALUES LESS THAN (6), |
| | | partition transaction_log_message_6 VALUES LESS THAN (7), |
| | | partition transaction_log_message_7 VALUES LESS THAN (8), |
| | | partition transaction_log_message_8 VALUES LESS THAN (9), |
| | | partition transaction_log_message_9 VALUES LESS THAN (10), |
| | | partition transaction_log_message_10 VALUES LESS THAN (11), |
| | | partition transaction_log_message_11 VALUES LESS THAN (12), |
| | | partition transaction_log_message_12 VALUES LESS THAN (13) |
| | | ); |
| | | |
| 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="logServiceDaoImpl"> |
| | | |
| | | <!--保存日志--> |
| | | <insert id="saveTransactionLog" parameterType="java.util.HashMap" > |
| | | insert into l_transaction_log |
| | | (log_id,transaction_id,contract_id,ip,port,src_ip,src_port,app_id,user_id,service_code,service_name,timestamp,status_cd) |
| | | values |
| | | (#{logId},#{transactionId},#{dataFlowId},#{ip},#{port},#{srcIp},#{srcPort},#{appId},#{userId},#{serviceCode},#{serviceName},#{timestamp},#{logStatus}) |
| | | </insert> |
| | | |
| | | <!--保存日志(交互报文)--> |
| | | <insert id="saveTransactionLogMessage" parameterType="java.util.HashMap" > |
| | | insert into l_transaction_log_message |
| | | (log_id,request_header,response_header,request_message,response_message,remark) |
| | | values |
| | | (#{logId},#{requestHeader},#{responseHeader},#{requestMessage},#{responseMessage},#{remark}) |
| | | </insert> |
| | | |
| | | |
| | | </mapper> |
| | |
| | | * @return |
| | | */ |
| | | public String getTimestamp(){ |
| | | return DateUtil.getCurrentDate().getTime()+""; |
| | | return DateUtil.getNowDefault(); |
| | | } |
| | | |
| | | |
| | |
| | | public class BusinessServiceDataFlow extends AbstractDataFlowContext { |
| | | |
| | | |
| | | |
| | | |
| | | private String bId; |
| | | |
| | | private Map<String,Object> paramOut; |
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.SequenceUtil; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.entity.center.AppRoute; |
| | | import com.java110.entity.center.Business; |
| | |
| | | Business business = null; |
| | | JSONObject reqInfoObj = JSONObject.parseObject(reqInfo); |
| | | JSONObject orderObj = reqInfoObj.getJSONObject("orders"); |
| | | JSONArray businessArray = reqInfoObj.getJSONArray("business"); |
| | | Object businessObj = reqInfoObj.get("business"); |
| | | JSONArray businessArray = null; |
| | | if(businessObj instanceof JSONObject){ |
| | | businessArray = new JSONArray(); |
| | | businessArray.add(reqInfoObj.getJSONObject("business")); |
| | | }else if(businessObj instanceof JSONArray){ |
| | | businessArray = reqInfoObj.getJSONArray("business"); |
| | | }else{ |
| | | // 不做处理 |
| | | } |
| | | |
| | | this.setReqData(reqInfo); |
| | | this.setReqJson(reqInfoObj); |
| | | this.setDataFlowId(orderObj.containsKey("dataFlowId")?orderObj.getString("dataFlowId"):"-1"); |
| | |
| | | this.setReqData(reqInfo); |
| | | this.setDataFlowId("-1"); |
| | | this.setAppId(headerAll.get("appId")); |
| | | this.setTransactionId(StringUtil.isNullOrNone(headerAll.get("transactionId"))? SequenceUtil.getTransactionId():headerAll.get("transactionId")); |
| | | this.setTransactionId(StringUtil.isNullOrNone(headerAll.get("transactionId"))? GenerateCodeFactory.getTransactionId():headerAll.get("transactionId")); |
| | | this.setUserId(StringUtil.isNullOrNone(headerAll.get("userId"))? "-1":headerAll.get("userId")); |
| | | this.setOrderTypeCd("T"); |
| | | this.setRemark(StringUtil.isNullOrNone(headerAll.get("remark"))? "":headerAll.get("remark")); |
| | |
| | | import com.java110.common.constant.StatusConstant; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.SequenceUtil; |
| | | import com.java110.core.context.AbstractDataFlowContext; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.entity.center.AppRoute; |
| | |
| | | */ |
| | | public static Map getOrder(DataFlow dataFlow){ |
| | | Map order = new HashMap(); |
| | | dataFlow.setoId(SequenceUtil.getOId()); |
| | | dataFlow.setoId(GenerateCodeFactory.getOId()); |
| | | order.put("oId",dataFlow.getoId()); |
| | | order.put("appId",dataFlow.getAppId()); |
| | | order.put("extTransactionId",dataFlow.getTransactionId()); |
| | |
| | | { |
| | | attrMap = new HashMap(); |
| | | attrMap.put("oId",dataFlow.getoId()); |
| | | attrMap.put("attrId",SequenceUtil.getAttrId()); |
| | | attrMap.put("attrId", GenerateCodeFactory.getAttrId()); |
| | | attrMap.put("specCd",attrs.getJSONObject(attrIndex).getString("specCd")); |
| | | attrMap.put("value",attrs.getJSONObject(attrIndex).getString("value")); |
| | | orderAttrs.add(attrMap); |
| | |
| | | if(business == null){ |
| | | continue; |
| | | } |
| | | business.setbId(SequenceUtil.getBId()); |
| | | business.setbId(GenerateCodeFactory.getBId()); |
| | | busiMap = new HashMap(); |
| | | busiMap.put("oId",dataFlow.getoId()); |
| | | busiMap.put("businessTypeCd",getService(dataFlow,business.getServiceCode()).getBusinessTypeCd()); |
| | |
| | | busiMap.put("businessTypeCd",StatusConstant.REQUEST_BUSINESS_TYPE_DELETE); |
| | | busiMap.put("remark",message); |
| | | busiMap.put("statusCd",StatusConstant.STATUS_CD_DELETE_ORDER); |
| | | busiMap.put("bId",SequenceUtil.getBId()); |
| | | busiMap.put("bId", GenerateCodeFactory.getBId()); |
| | | business.add(busiMap); |
| | | return business; |
| | | } |
| | |
| | | for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) { |
| | | attrMap = new HashMap(); |
| | | attrMap.put("bId", business.getbId()); |
| | | attrMap.put("attrId", SequenceUtil.getAttrId()); |
| | | attrMap.put("attrId", GenerateCodeFactory.getAttrId()); |
| | | attrMap.put("specCd", attrs.getJSONObject(attrIndex).getString("specCd")); |
| | | attrMap.put("value", attrs.getJSONObject(attrIndex).getString("value")); |
| | | businessAttrs.add(attrMap); |
| | |
| | | private static JSONObject getTransactionBusinessBaseJson(DataFlow dataFlow,String businessType){ |
| | | JSONObject notifyMessage = JSONObject.parseObject("{\"orders\":{},\"business\":{}}"); |
| | | JSONObject orders = notifyMessage.getJSONObject("orders"); |
| | | orders.put("transactionId",SequenceUtil.getTransactionId()); |
| | | orders.put("transactionId", GenerateCodeFactory.getTransactionId()); |
| | | orders.put("dataFlowId",dataFlow.getDataFlowId()); |
| | | orders.put("orderTypeCd",dataFlow.getOrderTypeCd()); |
| | | orders.put("requestTime",DateUtil.getyyyyMMddhhmmssDateString()); |
| | |
| | | package com.java110.core.factory; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.JSONPath; |
| | |
| | | import com.java110.common.constant.OrderTypeCdConstant; |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.constant.StatusConstant; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.SequenceUtil; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.core.context.DataFlowContext; |
| | |
| | | JSONObject paramIn = JSONObject.parseObject("{\"orders\":{},\"business\":[]}"); |
| | | JSONObject orders = paramIn.getJSONObject("orders"); |
| | | orders.put("appId",appId); |
| | | orders.put("transactionId", SequenceUtil.getTransactionId()); |
| | | orders.put("transactionId", GenerateCodeFactory.getTransactionId()); |
| | | orders.put("userId",userId); |
| | | orders.put("orderTypeCd",orderTypeCd); |
| | | orders.put("requestTime",DateUtil.getNowDefault()); |
| File was renamed from java110-common/src/main/java/com/java110/common/util/SequenceUtil.java |
| | |
| | | package com.java110.common.util; |
| | | package com.java110.core.factory; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.cache.MappingCache; |
| | |
| | | import com.java110.common.exception.GenerateCodeException; |
| | | import com.java110.common.exception.ResponseErrorException; |
| | | import com.java110.common.factory.ApplicationContextFactory; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.feign.code.ICodeApi; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.rmi.NoSuchObjectException; |
| | |
| | | * 生成序列工具类 |
| | | * Created by wuxw on 2017/2/27. |
| | | */ |
| | | public class SequenceUtil { |
| | | public class GenerateCodeFactory { |
| | | |
| | | private static final long ONE_STEP = 1000000; |
| | | private static final Lock LOCK = new ReentrantLock(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取内部平台 交易流水 |
| | | * @return |
| | | * @throws NoSuchObjectException |
| | | */ |
| | | public static String getInnerTransactionId() throws Exception{ |
| | | return codeApi().generateCode(prefixMap.get("transactionId")); |
| | | } |
| | | |
| | | /** |
| | | * 获取交易流水ID |
| | | * |
| | | * @return |
| | |
| | | String responseMessage = restTemplate().postForObject(MappingCache.getValue(MappingConstant.KEY_CODE_PATH), |
| | | createCodeRequestJson(getTransactionId(),prefix,prefix).toJSONString(), String.class); |
| | | |
| | | if(ResponseConstant.RESULT_CODE_ERROR.equals(responseMessage)){ |
| | | throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "生成oId编码失败"); |
| | | } |
| | | Assert.jsonObjectHaveKey(responseMessage, "code", "编码生成系统 返回报文错误" + responseMessage); |
| | | |
| | | JSONObject resJson = JSONObject.parseObject(responseMessage); |
| | |
| | | return getCode(prefixMap.get("attrId")); |
| | | } |
| | | |
| | | /** |
| | | * 生成dataFlowId |
| | | * @return |
| | | * @throws GenerateCodeException |
| | | */ |
| | | public static String getDataFlowId() throws GenerateCodeException{ |
| | | /*if(!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))){ |
| | | return prefixMap.get("dataFlowId") + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H) + nextId("%08d"); |
| | | } |
| | | |
| | | return getCode(prefixMap.get("dataFlowId"));*/ |
| | | |
| | | return UUID.randomUUID().toString().replace("-","").toLowerCase(); |
| | | |
| | |
| | | return (RestTemplate) bean; |
| | | } |
| | | |
| | | /** |
| | | * 获取codeApi |
| | | * @return |
| | | * @throws NoSuchObjectException |
| | | */ |
| | | private static ICodeApi codeApi() throws NoSuchObjectException{ |
| | | |
| | | Object bean = ApplicationContextFactory.getBean("codeApi"); |
| | | |
| | | if(bean == null){ |
| | | throw new NoSuchObjectException("codeApi,请核实"); |
| | | } |
| | | |
| | | return (ICodeApi) bean; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * ID生成请求报文 |
| File was renamed from java110-common/src/main/java/com/java110/common/rule/RuleProtocol.java |
| | |
| | | package com.java110.common.rule; |
| | | package com.java110.core.factory; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.SequenceUtil; |
| | | |
| | | /** |
| | | * 创建校验单 请求报文协议 |
| | |
| | | * 工具类,提供于第三方系统调用组装请求报文 |
| | | * Created by wuxw on 2017/7/24. |
| | | */ |
| | | public class RuleProtocol { |
| | | public class RuleProtocolFactory { |
| | | |
| | | /** |
| | | * 创建头部 |
| | |
| | | * @param serviceCode |
| | | * @return |
| | | */ |
| | | public static JSONObject createTcpCont(String ruleType,String serviceCode){ |
| | | return createTcpCont(SequenceUtil.getTransactionId(),ruleType,serviceCode); |
| | | public static JSONObject createTcpCont(String ruleType,String serviceCode) throws Exception{ |
| | | return createTcpCont(GenerateCodeFactory.getInnerTransactionId(),ruleType,serviceCode); |
| | | } |
| | | |
| | | |
| | |
| | | * @param svcContParam |
| | | * @return |
| | | */ |
| | | public static String createValidateJson(String ruleType,String serviceCode,JSONObject svcContParam){ |
| | | return createValidateJson(SequenceUtil.getTransactionId(),ruleType,serviceCode,svcContParam); |
| | | public static String createValidateJson(String ruleType,String serviceCode,JSONObject svcContParam) throws Exception{ |
| | | return createValidateJson(GenerateCodeFactory.getInnerTransactionId(),ruleType,serviceCode,svcContParam); |
| | | } |
| | | |
| | | public static String createValidateJson(String transactionId,String ruleType,String serviceCode,JSONObject svcContParam){ |
| New file |
| | |
| | | package com.java110.feign.code; |
| | | |
| | | import com.java110.common.constant.ResponseConstant; |
| | | import com.java110.common.util.ProtocolUtil; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | /** |
| | | * 调用用户服务失败时,返回 |
| | | * Created by wuxw on 2017/4/5. |
| | | */ |
| | | public class CodeApiFallback implements ICodeApi{ |
| | | |
| | | |
| | | /** |
| | | * 生成编码 |
| | | * @param prefix 前缀 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String generateCode(String prefix) { |
| | | return ResponseConstant.RESULT_CODE_ERROR; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.feign.code; |
| | | |
| | | import org.springframework.cloud.netflix.feign.FeignClient; |
| | | |
| | | /** |
| | | * Created by wuxw on 2018/6/15. |
| | | */ |
| | | @FeignClient(name = "code-service", fallback = CodeApiFallback.class) |
| | | public interface ICodeApi { |
| | | |
| | | /** |
| | | * 生成 编码 |
| | | * @param prefix 前缀 |
| | | * @return |
| | | */ |
| | | public String generateCode(String prefix); |
| | | } |
| | |
| | | String headerMessage = (headers == null || headers.isEmpty())?"":JSONObject.toJSONString(headers); |
| | | message.put("headers",headerMessage); |
| | | message.put("body",dataInfo); |
| | | |
| | | return message; |
| | | } |
| | | |
| | |
| | | import com.java110.common.constant.CommonConstant; |
| | | import com.java110.core.factory.PageDataFactory; |
| | | import com.java110.common.util.Assert; |
| | | import com.java110.common.util.SequenceUtil; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.entity.service.PageData; |
| | | import org.aspectj.lang.JoinPoint; |
| | |
| | | } |
| | | str = sb.toString(); |
| | | if(Assert.isPageJsonObject(str)){ |
| | | pd = PageDataFactory.newInstance().builder(str).setTransactionId(SequenceUtil.getPageTransactionId()); |
| | | pd = PageDataFactory.newInstance().builder(str).setTransactionId(GenerateCodeFactory.getPageTransactionId()); |
| | | } |
| | | } |
| | | //对 get情况下的参数进行封装 |
| | | if(pd == null){ |
| | | pd = PageDataFactory.newInstance().setTransactionId(SequenceUtil.getPageTransactionId()); |
| | | pd = PageDataFactory.newInstance().setTransactionId(GenerateCodeFactory.getPageTransactionId()); |
| | | Map<String,String[]> params = request.getParameterMap(); |
| | | if(params != null && !params.isEmpty()) { |
| | | JSONObject paramObj = new JSONObject(); |