//Scrippt的内容
// Script here
// 拼接kafka数据格式
var messages= {};
var targetAttrs = {};
if(facelib_ids != null) {
targetAttrs.facelibId = String(facelib_ids);
}
if(human_id != null) {
targetAttrs.humanId = String(human_id);
}
if(human_name != null) {
targetAttrs.name = String(human_name);
}
if(human_age != null) {
targetAttrs.registerAge = String(human_age);
}
if(birth_date != null) {
targetAttrs.bornTime = String(birth_date);
}
if(create_date != null) {
targetAttrs.createDate = String(create_date);
}
if(human_male != null) {
targetAttrs.registerGender = String(human_male);
}
if(human_province != null) {
targetAttrs.province = String(human_province);
}
if(human_city != null) {
targetAttrs.city = String(human_city);
}
if(certificate != null) {
targetAttrs.certificate = String(certificate);
}
if(human_credtype != null) {
targetAttrs.certificateType = String(human_credtype);
}
if(human_crednum != null) {
targetAttrs.certificateNumber = String(human_crednum);
}
messages.targetAttrs = targetAttrs;
//messages.targetAttrs = Packages.com.alibaba.fastjson.JSON.toJSONString(targetAttrs).toString();
//messages.targetAttrs = Packages.com.alibaba.fastjson.JSON.toJSONString(targetAttrs);
//接下来拼接humanData
var humanData = [];
var message2 = {};
if(error_code != null) {
message2.errorCode = String(error_code);
}
humanData.push(message2);
if(face_picurl != null) {
message2.image = String(face_picurl);
}
humanData.push(message2);
//拼接faces
var faces = [];
var face = {};
face.faceId = 1;
faces.push(face);
if(human_male != null) {
var genderJson = {};
genderJson.value = parseInt(human_male);
face.gender = genderJson
}
if(model != null) {
face.modelData = String(model);
}
faces.push(face);
message2.faces = faces;
humanData.push(message2);
messages.humanData = humanData;
//messages = Packages.com.alibaba.fastjson.JSON.toJSONString(messages);
//接下来把所有的内容拼接成一个完整的json
//var k_message = "[" + messages + "]";
//k_message = Packages.com.alibaba.fastjson.JSONObject.parseArray(k_message).toJSONString();
var k_message = [];
k_message.push(messages);
//Item的内容如下:
function getGender(human_male) {
switch(human_male) {
case 1: return "male";
case 2: return "female";
default: return "unknow";
}
}
function getModel(model) {
switch(smile) {
case 1: return "no";
case 2: return "yes";
default: return "unknow";
}
}
原文:https://www.cnblogs.com/ceicey/p/12655990.html