text: const {getTransactionFunc} = require('../core/util')
  const {services} = require('../core/services')
  const {merge, omit,contains} = require('ramda')
  const {getConfig} = require('../core/config')
  const {setPreContext} = require('./pre-context')
  
  //递归获取方法
  const initFunc = (funName, conn) => {
      let injectsFuns = {};
      const {injects = [], apiFun} = services[funName];
      for (const inject of injects) {
          injectsFuns[inject] = initFunc(inject, conn);
      }
      return input => apiFun({...injectsFuns, conn}, input.input || input)
  }
  
  const matchAPIMiddleware = async (req, res, next) => {
  
      const funName = req.funName;
      const {apiFun, isTransaction} = services[funName] || {};
  
      if (apiFun) {
  
          const result = await  getTransactionFunc({
              func: initFunc(funName, req.body.conn),
              conn: req.body.conn,
              values: req.body.params || req.query || {},
              isTransaction
          });
  
          const setTokenFuns = getConfig('SET_TOKEN_FUN')||[];
          //如果是设置token//
          if(contains(funName,setTokenFuns) && result){
              setPreContext(req, result.token)
          }
  
          if (result === undefined) return res.json({code: 200, data: {}})
          if (!result.systemBizIsError) {
              res.json({code: 200, data: result})
          } else {
              res.json({code: 500, data: {error: '后台错误'}})
          }
  
      } else {
          res.json({code: 400, data: {error: '没找到方法'}})
      }
  }
  
  module.exports = {
      matchAPIMiddleware,
      initFunc
  }