mapper案例
{
"base": {
"connName": "ConnBt",
"isRearEnd": true,
"isFrontEnd": true
},
"responseField": {
//按被保人身份证统计
"bbrcard": {
//控制第三方权限配置
"presetSql": [
//{
// "connName": "ConnIdc",
// "value": "",
// "name": ""
//}
],
//请求的结果处理
"njcResult": {
"args": [],
"moduleName": "~/Config/AppNodeJs/{ownerId}-plugins/{mkey}/{resField}",
"functionName": null
},
//请求的参数设置
"njcArgs": {
"args": [],
"moduleName": "~/Config/AppNodeJs/{ownerId}-plugins/{mkey}/{resField}-query",
"functionName": null
},
"guidMethod": "None",
//来源组合接口
"dataFromType": "Merge",
"original": "",
"auth": true,
//开启只执行responseField里面配置
"onlySqlList": true,
"source": [
{
"field": "policy",
"connName": "ConnBt",
"dataFromType": "Database",
//多条数据
"multi": true,
"sql": [
{
"value": "select max(bd_bbr),count(policy_id) count,max(bd_bbr_day),(select sum(bz_price) from bt_policy_item) bz_price from bt_policy where bd_bbr_idcard=@bdBbrIdcard",
"sortId": 1
}
]
},
{
"field": "user",
"connName": "ConnBo",
"dataFromType": "Database",
//多条数据
"multi": true,
"sql": [
{
"value": "select head_icon from bo_user where id_card=@bdBbrIdcard",
"sortId": 1
}
]
}
]
},
//按月统计分析
"bbrcard-items": {
"isList": true,
"show": "data_alias,data_value,data_type",
"selectSql": {
"sqlList": [
{
"value": "select tb_p.policy_id,max(tb_c.ic_name) ic_name,max(tb_s.status) status, max(tb_pi.bz_jf_method) bz_jf_method,min(bd_start_date) bd_start_date,max(bd_tbr) bd_tbr,max(bd_bbr) bd_bbr,max(bd_bbr_day) bd_bbr_day,sum(bz_price) bz_price,sum(mq_price) mq_price ",
"sortId": 10
},
{
"value": "from bt_policy tb_p left join bt_policy_item tb_pi on (tb_pi.policy_id=tb_p.policy_id) left join bt_company tb_c on(tb_c.ic_id=tb_p.ic_name)",
"sortId": 14
},
{
"value": " left join bt_policy_status tb_s on(tb_s.policy_id=tb_p.policy_id)",
"sortId": 14
},
{
"value": " where bd_bbr_idcard=@bdBbrIdcard group by tb_p.policy_id ",
"sortId": 15
}
]
},
"guidMethod": 0,
"dataFromType": 0,
"original": ""
}
},
"tables": [
{
"id": 1,
"name": "bt_policy",
"isPrimary": true,
"primaryColumn": [
{
"colName": "policy_id",
"alias": "policy_id",
"field": "policyId"
}
],
"type": "Table"
}
],
"columns": {
"bdStartDate": {
"tableId": 1,
"dataType": "datetime",
"name": "bd_start_date",
"alias": "bd_start_date",
"field": "bdStartDate",
"editPropertie": {
"format": "yyyy-MM-dd",
"showMethod": "Text",
"showMethodOut": "KV",
"isOriginal": false
},
"pagePropertie": {
"format": "yyyy-MM-dd",
"showMethod": "Text",
"showMethodOut": "KV",
"isOriginal": false
},
"isDate": true
},
"bdBbrDay": {
"tableId": 1,
"dataType": "datetime",
"name": "bd_bbr_day",
"alias": "bd_bbr_day",
"field": "bdBbrDay",
"isDate": true,
"editPropertie": {
"format": "yyyy-MM-dd",
"showMethod": "Text",
"showMethodOut": "KV",
"isOriginal": false
},
"pagePropertie": {
"format": "yyyy-MM-dd",
"showMethod": "Text",
"showMethodOut": "KV",
"isOriginal": false
}
}
}
}
//--获取所有的保单
//select max(bd_bbr),count(policy_id) count,max(bd_bbr_day),(select sum(bz_price) from bt_policy_item) bz_price from bt_policy where bd_bbr_idcard='360|nH/2tStjYAHDqBHJi0tCjg==|322'
//--统计保单信息
//select (select count(*) from bt_policy where bd_bbr_idcard=tb_p.bd_bbr_idcard) bd_count,max(bd_bbr) bd_bbr,max(bd_bbr_day) bd_bbr_day,sum(bz_price) bz_price from bt_policy tb_p left join bt_policy_item tb_pi on (tb_pi.policy_id=tb_p.policy_id) where bd_bbr_idcard='360|nH/2tStjYAHDqBHJi0tCjg==|322'
//--获取保障信息
//select * from bt_policy_item where policy_id in (select policy_id from bt_policy where bd_bbr_idcard='360|nH/2tStjYAHDqBHJi0tCjg==|322')
//--获取用户头像
//select head_icon from bt_auth_bo.bo_user where ID_CARD='350|nH/2tStjYAHDqBHJi0tCjg==|322'
//select max(tb_c.ic_name) ic_name, max(tb_pi.bz_jf_method) bz_jf_method,min(bd_start_date) bd_start_date,max(bd_tbr) bd_tbr,max(bd_bbr) bd_bbr,max(bd_bbr_day) bd_bbr_day,sum(bz_price) bz_price,sum(mq_price) mq_price from bt_policy tb_p left join bt_policy_item tb_pi on (tb_pi.policy_id=tb_p.policy_id) left join bt_company tb_c on(tb_c.ic_id=tb_p.ic_name) where bd_bbr_idcard='360|nH/2tStjYAHDqBHJi0tCjg==|322' group by tb_p.policy_id
mapper核心代码
处理的数据目录结构
field.js
var fnDataCamcel = require('../../Plugins/fn-common-data-camcel.js');
module.exports = function (callback, result, params, args) {
let argParams = JSON.parse(result);
let paramsT = JSON.parse(params);
if (paramsT._ori === "init") {
//最初数据
callback(null, argParams);
} else if (paramsT._ori === "convet") {
//转换后数据
if (argParams.Children) {
fnDataCamcel.mergeBsObject(argParams.Data, argParams.Children);
delete argParams.Children;
}
//扩展代码处理 end
if (paramsT["_nodejs"] !== "common-data-under") {
fnDataCamcel.toLowerCamcelByObject(argParams, paramsT["_null"] !== "true");
}
delete argParams.schema;
delete argParams.dimension;
if (argParams.children) {
fnDataCamcel.mergeBsObject(argParams.data, argParams.children);
delete argParams.children;
}
callback(null, argParams);
} else if (paramsT._dataFromType === "api") {
//api
let lastData = {
code: 0,
success: true
};
const dateKeys = Object.keys(argParams.data);
if (paramsT._dataFromType === "api" && argParams['error_code'] === '00' && dateKeys.length > 0) {
//const lastKey = dateKeys[dateKeys.length - 1]
//let item = argParams.data[lastKey];
//let spaceId = paramsT.spaceId;
//lastData.data = {
// "data_date": {
// name: dayjs.unix(lastKey).format('YYYY-MM-DD HH:mm:ss'),
// value: dayjs.unix(lastKey).format('YYYY-MM-DDTHH:mm:ss')
// }
//};
//if (paramsT["_nodejs"] !== "common-data-under") {
// fnDataCamcel.toLowerCamcelByObject(lastData, paramsT["_null"] !== "true");
//}
//lastData.t = argParams.data;
//callback(null, lastData);
callback(null, argParams);
} else if (paramsT._dataFromType === "api") {
//lastData.data = { }
//if (paramsT["_nodejs"] !== "common-data-under") {
// fnDataCamcel.toLowerCamcelByObject(lastData, paramsT["_null"] !== "true");
//}
//callback(null, lastData);
callback(null, argParams);
} else {
callback(null, argParams);
}
} else if (paramsT._dataFromType === "configFile") {
//静态数据
callback(null, argParams);
} else if (paramsT._dataFromType === "merge") {
//合并组合
callback(null, argParams);
} else if (argParams.Success === true) {
if (argParams.Children) {
fnDataCamcel.mergeBsObject(argParams.Data, argParams.Children);
delete argParams.Children;
}
//const dataT = argParams.Data;
//let lastData = {
// code: 0,
// success: true
//};
//if (dataT.power_used) {
// dataT.else_used = parseFloat(((dataT.power_used || 0) - (dataT.ups_used || 0) - (dataT.cooling_used || 0)).toFixed(2));
//}
//lastData.data = { }
//argParams = lastData;
//扩展代码处理 end
if (paramsT["_nodejs"] !== "common-data-under") {
fnDataCamcel.toLowerCamcelByObject(argParams, paramsT["_null"] !== "true");
}
delete argParams.schema;
delete argParams.dimension;
if (argParams.children) {
fnDataCamcel.mergeBsObject(argParams.data, argParams.children);
delete argParams.children;
}
callback(null, argParams);
} else {
callback(null, argParams);
}
};
field-query.js
var dayjs = require('../../Plugins/dayjs/dayjs.min.js');
var crypto = require('crypto');
var paramBody = require('./{{field}}-query-body.js');
// crypto.createHash('md5').update(plaintext).digest("hex");
module.exports = function (callback, argJson, rmt, args) {
let argParams = JSON.parse(argJson);
if (argParams._dataFromType === "api") {
//var dateS = dayjs(argParams._currentDayS).unix();//.add(8, 'hour')
//var dateE = dayjs(argParams._currentDayE).unix();//.add(8, 'hour')
//argParams.dateS = dateS;
//argParams.dateE = dateE;
//var post_data = { ...{ "start": dateS, "end": dateE }, ...paramBody[argParams.spaceId] };
//argParams["_pueId"] = paramBody[argParams.spaceId].ids[0];
//var post_data_str = JSON.stringify(post_data);
//var check = crypto.createHash('md5').update(post_data_str).digest("hex");
//argParams["request_method"] = "post";
////argParams["header_content_type"]= "*/*;charset=UTF-8";
//argParams["request_post_data"] = post_data_str;
//argParams["request_header_data"] = JSON.stringify({ "Cookie": argParams["GJ_Cookie"], "check": check });
//argParams["request_url"] = argParams["GJ_ROOT_URL"] + `/api/v2/tsdb/orig/agg`;
} else if (argParams._dataFromType === "databalse") {
//
} else if (argParams._dataFromType === "configfile") {
//
} else if (argParams._dataFromType === "merge") {
//
} else if (argParams._dataFromType === "json") {
//
}
callback(null, argParams);
};
field-query-body.js
module.exports = {}
详细说明详见
文档更新时间: 2021-06-28 08:00 作者:admin