operation.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /**
  2. * Created by PC on 2018/5/29.
  3. */
  4. var express = require('express');
  5. var router = express.Router();
  6. var bodyParser = require('body-parser');
  7. var http=require("http");
  8. var async = require("async");
  9. var moment=require("moment");
  10. var sixtytwo = require('sixtytwo');
  11. var take=require("../models/T_token");
  12. var public=require("../common/public");
  13. var logs=require("../models/logs");
  14. var uploadLogs=require("../models/uploadLogs");
  15. var status=require("../models/t_status");
  16. // var processWarehouse=require("../models/t_processWarehouse");
  17. const random = require('random')
  18. var marketAnalysis=require("../models/t_marketAnalysis");
  19. var businessInfo=require("../models/t_businessInfo");
  20. var corporation = require("../models/t_corporation");
  21. router.use(bodyParser.json()); // for parsing application/json
  22. router.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
  23. var error = require("../models/error");
  24. // var public = require("../common/public");
  25. //公用修改单条数据方法
  26. function update(query,change,model,callback) {
  27. model.updateOne(query, {"$set": change}, function (err, doc) {
  28. if (err) {
  29. callback(error.validator('tips')[2]);//数据库链接失败
  30. // console.log(err)
  31. return;
  32. } else if (doc.n == 1 && doc.ok == 1) {//成功
  33. callback(error.operation('tips')[1]);
  34. return;
  35. } else {
  36. callback(error.operation('tips')[0]);
  37. return;
  38. }
  39. });
  40. }
  41. //公用修改多条数据方法
  42. function updateMore(query,change,model,callback) {
  43. model.updateMany(query, {"$set": change}, function (err, doc) {
  44. if (err) {
  45. callback(error.validator('tips')[2]);//数据库链接失败
  46. return;
  47. } else if (doc.n > 0 ) {//成功
  48. callback(error.operation('tips')[1]);
  49. return;
  50. } else {
  51. callback(error.operation('tips')[1]);
  52. return;
  53. }
  54. });
  55. }
  56. //公用查询方法,分页返回总数
  57. function search(num,page,screen,query,queryOr,sortKey,model,callback) {
  58. async.parallel({
  59. list:function (back) {
  60. model.find(query,screen)
  61. .skip(num*(page-1))
  62. .limit(num)
  63. .or(queryOr)
  64. .sort(sortKey)
  65. .exec(function (err,doc) {
  66. if(err){
  67. callback(error.operation('tips')[2]);
  68. return;
  69. }else{
  70. back(null,doc)
  71. }
  72. });
  73. },
  74. count:function (back) {
  75. // model.count(query)
  76. model.countDocuments(query)
  77. .or(queryOr)
  78. .exec(function (err,docs) {
  79. if (err){
  80. console.log(err);
  81. callback(error.operation('tips')[2]);
  82. return;
  83. }else {
  84. back(null,docs);
  85. }
  86. })
  87. }
  88. },function (errs,result) {
  89. if(errs){
  90. callback(error.operation('tips')[2]);
  91. return;
  92. }else {
  93. var back = public.setJson(error.operation('tips')[3],"count",result.count);
  94. back = public.setJson(back,"list",result.list);
  95. callback(back);
  96. }
  97. })
  98. }
  99. //公用详情方法
  100. function detail(query,model,callback) {
  101. model.findOne(query,function (err,doc) {
  102. if(err||doc===null){
  103. callback(error.operation('tips')[2]);
  104. return;
  105. }else {
  106. var back = public.setJson(error.operation('tips')[3],"data",doc);
  107. callback(back);
  108. return;
  109. }
  110. })
  111. }
  112. //用于获取中卫市平台的认证信息,获取token
  113. //username,password分别为市平台的用户名和密码
  114. function Authentication(callback){//data请求内容
  115. //第一步先判断表里有没有数据 如果数据为0 或者大于1 则不对 清空数据 后 从省平台获取toke 插入数据库,直接返回token(end) 如果为1条则什么都不做,
  116. //第二步数据已经有了,判断token是否过期,没过期 直接返回(end);过期的话更新update然后返回(end)
  117. take.find(function (err,doc) {
  118. if(err){
  119. //
  120. var result=public.setJson({"success":1},"data",err);
  121. callback(result)
  122. }else {
  123. if(doc.length != 1){
  124. take.remove(function (err) {
  125. //清空数据库然后获取token插入
  126. var data=JSON.stringify({"username":"zhongwei","password":"zhongwei123456"});
  127. var opt = {
  128. host:'218.95.173.130',
  129. port:'9000',
  130. method:'POST',
  131. path:'/auth/security/access_token',
  132. headers:{
  133. "Content-Type": 'application/json',
  134. "Content-Length": data.length
  135. }
  136. }
  137. var body = '';
  138. var token = ""
  139. var req = http.request(opt, function(res) {
  140. //console.log("Got response: " + res.statusCode);
  141. res.on('data',function(d){
  142. body += d;
  143. body=JSON.parse(body);
  144. token=body.TOKEN;
  145. if(body.STATUS_CODE==200&&token!=""){
  146. var result={
  147. "success":0,
  148. "data":
  149. {"token":token,"AUTH_ID":body.AUTH_ID}
  150. };
  151. callback(result)
  152. }
  153. else {
  154. var result=public.setJson({"success":1},"data","获取token失败");
  155. callback(result)
  156. }
  157. }).on('end', function(){
  158. // console.log(res.headers)
  159. var takeAdd = new take({
  160. token:token,//token
  161. AUTH_ID:body.AUTH_ID,
  162. username:"zhongwei",//用户名
  163. password:"zhongwei123456"//密码
  164. });
  165. takeAdd.save(function (err) {
  166. // if(err){
  167. // var result=public.setJson({"success":1},"data",err);
  168. // callback(result)
  169. // }else {
  170. // var result={
  171. // "success":0,
  172. // "data":
  173. // {"token":token,"AUTH_ID":body.AUTH_ID}
  174. // };
  175. // callback(result)
  176. // }
  177. console.log(err)
  178. })
  179. });
  180. }).on('error', function(e) {
  181. console.log("Got error: " + e.message);
  182. });
  183. req.write(data);
  184. req.end();
  185. })
  186. }else{
  187. //只有一条数据
  188. //判断token是否过期
  189. if(moment().valueOf() - doc[0].begintime >= 86400){//过期 86400000
  190. //重新获取
  191. var data=JSON.stringify({"username":"zhongwei","password":"zhongwei123456"});
  192. var opt = {
  193. host:'218.95.173.130',
  194. port:'9000',
  195. method:'POST',
  196. path:'/auth/security/access_token',
  197. headers:{
  198. "Content-Type": 'application/json',
  199. "Content-Length": data.length
  200. }
  201. }
  202. var body = '';
  203. var token = "";
  204. var req = http.request(opt, function(res) {
  205. //console.log("Got response: " + res.statusCode);
  206. res.on('data',function(d){
  207. body += d;
  208. body=JSON.parse(body);
  209. token=body.TOKEN;
  210. if(body.STATUS_CODE==200&&token!=""){
  211. var result={
  212. "success":0,
  213. "data":
  214. {"token":token,"AUTH_ID":body.AUTH_ID}
  215. };
  216. callback(result)
  217. }
  218. else {
  219. var result=public.setJson({"success":1},"data","获取token失败");
  220. callback(result)
  221. }
  222. }).on('end', function(){
  223. take.updateOne({username:doc[0].username},{"$set":{token:token,AUTH_ID:body.AUTH_ID,begintime:moment().valueOf()}},function (err) {
  224. })
  225. });
  226. }).on('error', function(e) {
  227. console.log("Got error: " + e.message);
  228. });
  229. req.write(data);
  230. req.end();
  231. }else {
  232. var result={
  233. "success":0,
  234. "data":
  235. {"token":doc[0].token,"AUTH_ID":doc[0].AUTH_ID}
  236. };
  237. callback(result)
  238. }
  239. }
  240. }
  241. })
  242. }
  243. //主体部分接口
  244. function MainInterface(data,token,callback){
  245. data["REQ_TIME"] = moment().format("YYYY-MM-DD HH:mm:ss"),
  246. data["REQ_ID"] = moment().format("YYYYMMDDHHmmss")+(sixtytwo.toString(moment().valueOf())).substr(0,6),
  247. data=JSON.stringify(data);
  248. data=data+token;
  249. var opt = {
  250. host: '218.95.173.130',
  251. port: '9000',
  252. method: 'POST',
  253. path: '/interface-web/upload',
  254. headers: {
  255. "Content-Type": 'application/json'
  256. }
  257. }
  258. var body='';
  259. var back = ""
  260. var req = http.request(opt, function(res) {
  261. res.on('data',function(chunk){
  262. body+=chunk;
  263. var result=body.substring(0,body.lastIndexOf("}")+1);
  264. var token=body.substring(body.lastIndexOf("}")+1);
  265. result=JSON.parse(result);
  266. // console.log(result)
  267. switch (result.STATUS_CODE){
  268. case 200:
  269. back=public.setJson({"success":200},"data",result);
  270. back.token=token;
  271. // callback(data);
  272. break;
  273. case 40109:
  274. back=public.setJson({"success":40109},"data",typeof (result.RESULT)=="undefined"?"认证失败":result.RESULT);
  275. // callback(data);
  276. break;
  277. case 40103:
  278. back=public.setJson({"success":40103},"data",typeof (result.RESULT)=="undefined"?"无权限访问":result.RESULT);
  279. // callback(data);
  280. break;
  281. case 40104:
  282. back=public.setJson({"success":40104},"data",typeof (result.RESULT)=="undefined"?"token已过期":result.RESULT)
  283. // callback(data);
  284. break;
  285. case 500:
  286. back=public.setJson({"success":500},"data",typeof (result.RESULT)=="undefined"?"服务器未响应":result.RESULT)
  287. // callback(data);
  288. break;
  289. default:
  290. back=public.setJson({"success":result.STATUS_CODE},"data",result.RESULT);
  291. // back=public.setJson({"success":result.STATUS_CODE},"result.STATUS_CODE",result);
  292. // callback(data);
  293. }
  294. }).on('end', function(){
  295. callback(back);
  296. });
  297. }).on('error', function(e) {
  298. console.log("Got error: " + e.message);
  299. });
  300. req.write(data);
  301. req.end();
  302. }
  303. //生成上传日志
  304. function createUpLogs(name,code,obj,back) {//上传时的传入值和返回值
  305. var logs = new uploadLogs({
  306. BIZ_TYPE:obj.BIZ_TYPE,//
  307. ENTERPRISE_CODE:code,
  308. ENTERPRISE_NAME:name,
  309. LIST:obj.PARAM.LIST,//
  310. success:back.success,//
  311. RESULT:back.data,//
  312. });
  313. switch (obj.BIZ_TYPE.trim()) {
  314. case "TRACE_SEED":case"TRACE_PESTICIDE":case"TRACE_CHEMICAL_FERTILIZER":
  315. case "TRACE_PLANT_INPUTS":case"TRACE_PLANT_GROUND":case"TRACE_WEATHER_DETAL":case"TRACE_PLANT_AREA":
  316. case"TRACE_PLANT":case"TRACE_PLANT_PROCESS":case"TRACE_PLANT_WATER":case"TRACE_PLANT_PERTICIDE":
  317. case"TRACE_HARVEST":case"TRACE_PLANT_TRAN":
  318. logs.TYPE="种殖";
  319. break;
  320. case "TRACE_BREED_SOURCE":case "TRACE_FEED":case "TRACE_REGISTRATION":case "TRACE_BREED_INPUTS":case "TRACE_FEED_SITE":
  321. case "TRACE_COLONY_HOUSE":case "TRACE_BREED":case "TRACE_BREED_PROCESS":case "TRACE_BREED_HARVEST":case "TRACE_BREED_TRAN":
  322. logs.TYPE="养殖";
  323. break;
  324. case"TRACE_PRODUCTION_MATERIALS":case"TRACE_PRODUCTION_INPUTS":case"TRACE_PRODUCTION":case"TRACE_PRODUCTION_PROCESS":
  325. case"TRACE_DETECTION":case"TRACE_PACKAGE_CODING":case"TRACE_PRODUCTION_TRAN":
  326. logs.TYPE="生产加工";
  327. break;
  328. case "TRACE_ANIMAL_IN":case "TRACE_QUARANTINE":case "TRACE_PRODUCT_PROCESS":case "TRACE_MEAT_OUT":
  329. logs.TYPE="屠宰";
  330. break;
  331. case "TRACE_MARKET_IN":case "TRACE_MARKET_DETECTION":case "TRACE_MARKET_TRAN":
  332. logs.TYPE="批发";
  333. break;
  334. case "TRACE_RECALL":case "TRACE_DEALING":
  335. logs.TYPE="召回";
  336. break;
  337. default:
  338. logs.TYPE="";
  339. }
  340. logs.save(function (err) {
  341. if(err){
  342. console.log(err);
  343. }
  344. })
  345. }
  346. //生成日志
  347. function createLogs(data,back,path,type) {
  348. var logAdd = new logs({
  349. ENTERPRISE_CODE:(typeof(data.ENTERPRISE_CODE)=="undefined")?(typeof(data.SOCIAL_CREDIT_CODE)=="undefined"?"":data.SOCIAL_CREDIT_CODE):(data.ENTERPRISE_CODE),//企业编码
  350. ENTERPRISE_NAME:(typeof(data.ENTERPRISE_NAME)=="undefined")?(""):(data.ENTERPRISE_NAME),//企业名称
  351. username:(typeof(data.username)=="undefined")?(""):(data.username),//用户名
  352. token:(typeof(data.accessToken)=="undefined")?(""):(data.accessToken),//token
  353. path:path,//接口路径
  354. type:type,//接口类型
  355. time:Date.now(),//时间
  356. data:data,//调用数据
  357. back:(typeof (back)=="undefined")?"":back,//返回数据
  358. success:(typeof (back)=="undefined")?99:back.success,//是否成功
  359. platform:(typeof(data.platform)=="undefined")?(""):(data.platform)//0后台管理 1手持机
  360. });
  361. logAdd.save(function (err) {
  362. if(err){
  363. console.log(err);
  364. }
  365. })
  366. }
  367. //生成各种批次码
  368. function batch(code,str) {
  369. // "1"+object.ENTERPRISE_CODE+"11"+moment().valueOf()+"E",//采购批次码
  370. switch (str){
  371. case "种植":
  372. return "1"+code+"11"+moment().valueOf()+"A";
  373. break;
  374. case "收获":
  375. return "1"+code+"11"+moment().valueOf()+"B";
  376. break;
  377. case "采购":
  378. return "1"+code+"11"+moment().valueOf()+"E";
  379. break;
  380. case "处理":
  381. return "1"+code+"20"+moment().valueOf()+"C";
  382. break;
  383. case "生产":
  384. return "1"+code+"20"+moment().valueOf()+"D";
  385. break;
  386. case "配送":
  387. return "1"+code+"60"+moment().valueOf()+"F";
  388. break;
  389. case "辅料":
  390. return "1"+code+"20"+moment().valueOf()+"G";
  391. break;
  392. default:
  393. return "1"+code+"20"+moment().valueOf()+"Z";//啥也不是
  394. }
  395. }
  396. //验证传入的RFID标签数组是否全部初始化,
  397. //返回未初始化的标签数组,或者空数组[]
  398. function RFID(arr,callback) {
  399. status.find({TAG_CODE:{"$in":arr}},function (err,doc) {
  400. if(err){
  401. callback(-1);
  402. }else {
  403. if(doc.length == arr.length){
  404. //标签全部激活,返回空数组
  405. callback ([]);
  406. }else {
  407. //标签部分激活,返回未激活标签数组
  408. var list = [];
  409. doc.forEach(function (item) {
  410. list.push(item.TAG_CODE);
  411. });
  412. callback(public.arrayCut(arr,list));
  413. }
  414. }
  415. });
  416. }
  417. //生成各种批次码
  418. //enterpriceCode 企业代码 18位 productCode 产品代码 8位 procedureCode 流通顺序码
  419. function traceCode(enterpriceCode,productCode,procedureCode,milSecond = 0) {
  420. var TraceTypeCode = "2"; //溯源码第一位为1
  421. var milSecond = milSecond == 0 ? moment().valueOf():milSecond;
  422. var seqCode = milSecond.toString().substr(5,8);
  423. productCode = "00000000";
  424. var traceCode = TraceTypeCode + enterpriceCode + productCode + procedureCode + moment().format('YYYYMMDD') + seqCode + random.int(0, 9);
  425. return traceCode;
  426. }
  427. //获取企业或个人token,不存入Token表
  428. function getToken(data,callback) {
  429. data=JSON.stringify(data);
  430. var opt = {
  431. host:'218.95.173.130',
  432. port:'9000',
  433. method:'POST',
  434. path:'/auth/security/access_token',
  435. headers:{
  436. "Content-Type": 'application/json',
  437. "Content-Length": data.length
  438. }
  439. };
  440. var body = '';
  441. var req = http.request(opt, function(res) {
  442. //console.log("Got response: " + res.statusCode);
  443. res.on('data',function(d){
  444. body += d;
  445. body=JSON.parse(body);
  446. var token=body.TOKEN;
  447. if(body.STATUS_CODE==200&&token!=""){
  448. //获取token成功
  449. var result=public.setJson({"success":0},"msg",token);
  450. callback(result)
  451. }
  452. else {
  453. var result=public.setJson({"success":1},"msg","获取token失败,msgCode:"+body.STATUS_CODE);
  454. callback(result)
  455. }
  456. }).on('end', function(){
  457. // console.log(res.headers)
  458. });
  459. }).on('error', function(e) {
  460. console.log("Got error: " + e.message);
  461. });
  462. req.write(data);
  463. req.end();
  464. }
  465. //交易信息添加到marketAnalysis表
  466. function marketAnalysisAdd(data,url){
  467. businessInfo.find({SUPPLY_SOCIAL_CREDIT_CODE:data.SUPPLY_SOCIAL_CREDIT_CODE},function (err,doc) {
  468. if(err){
  469. // console.log(err);
  470. createLogs(data,err,url,"POST")
  471. return;
  472. }else {
  473. // console.log(doc)
  474. corporation.find({SOCIAL_CREDIT_CODE:data.SOCIAL_CREDIT_CODE},function (errs,docs) {
  475. if(errs){
  476. createLogs(data,err,url,"POST")
  477. // console.log(errs)
  478. return;
  479. }
  480. else {
  481. // var area=(docs.length==0?"":docs[0].AREA_NAME).split("-")
  482. var area=((data.AREA_NAME===""||typeof data.AREA_NAME === "undefined")?"":data.AREA_NAME.split("-"));
  483. var marketAnalysisAdd=new marketAnalysis({
  484. apiName:data.apiName,//环节名称
  485. VARIETY_NAME:data.VARIETY_NAME,//品种名称
  486. ENTERPRISE_CODE:data.ENTERPRISE_CODE,//企业编码
  487. ENTERPRISE_NAME:data.ENTERPRISE_NAME,//企业名称
  488. shortname:((doc.length===0||docs.length===0)?"":(docs[0].shortname===""?"中宁国际":docs[0].shortname)),//企业简称 没找到为"",简称为空则默认商户,判断为"中宁国际"
  489. type:data.type,//类型
  490. DEST_NAME:area==""?"":area.join(""),//到达地区名称
  491. province:typeof (area[0])=="undefined"||area[0]?"":area[0],//采交省
  492. city:typeof (area[1])=="undefined"||area[1]?"":area[1],//采交市
  493. area:typeof (area[2])=="undefined"||(area[2])==""?"":(area[2]),//采交区
  494. areaCODE:(docs.length==0?"":docs[0].AREA_CODE),//采交区编码
  495. traders:(docs.length==0?"":docs[0].COMP_NAME),//采交主体名称
  496. tradersCode:data.tradersCode,//采交主体编码
  497. shortTraders:(docs.length==0?"":docs[0].shortname),//采交主体简称
  498. unit:data.unit,//单位 不是重量,是计量单位,比如盒
  499. SPECIFICATION:parseFloat(data.SPECIFICATION).toFixed(3),//规格
  500. totalWeight:parseFloat(data.totalWeight).toFixed(3),//总重
  501. price:parseFloat(data.PRICE).toFixed(3),//单价
  502. number:parseFloat(data.AMOUNT).toFixed(3),//数量
  503. total:parseFloat(data.total).toFixed(3),//总价
  504. year:parseInt(moment().format("YYYY")),//年
  505. month:parseInt(moment().format("MM")),//月
  506. day:parseInt(moment().format("DD")),//日
  507. username:data.username,//操作用户
  508. })
  509. marketAnalysisAdd.save(function (err) {
  510. if(err){
  511. // console.log(err)
  512. createLogs(data,err,url,"POST")
  513. return;
  514. }
  515. })
  516. }
  517. })
  518. }
  519. })
  520. }
  521. const nodemailer = require('nodemailer');
  522. var result = {
  523. success:0,//0成功 1不成功
  524. msg:""//提示消息
  525. };
  526. const msgRcv = require("../models/t_msgRcv");
  527. //发送问题清单 type 1 表示 email; type 2 表示 站内短信
  528. //address:type为2时平台账户;type为1时Email地址
  529. //sender:发送人姓名
  530. function sendByEmailOrSms(type,address,content,callback) {
  531. var mailAccount = 'bellinggg@163.com';
  532. if(type==1)
  533. {
  534. let transporter = nodemailer.createTransport({
  535. // host: 'smtp.ethereal.email',
  536. service: '163', // 使用了内置传输发送邮件 查看支持列表:https://nodemailer.com/smtp/well-known/
  537. port: 465, // SMTP 端口
  538. secureConnection: true, // 使用了 SSL
  539. auth: {
  540. user: mailAccount,
  541. // 这里密码不是qq密码,是你设置的smtp授权码
  542. pass: 'xb51105110',
  543. }
  544. });
  545. let mailOptions = {
  546. from: '"中卫重要产品溯源平台" <'+ mailAccount +'>', // sender address
  547. to: address, // list of receivers
  548. subject: '平台数据问题报告', // Subject line
  549. // 发送text或者html格式
  550. // text: 'Hello world?', // plain text body
  551. html: content // html body
  552. };
  553. // send mail with defined transport object
  554. transporter.sendMail(mailOptions, (error, info) => {
  555. if (error) {
  556. result.msg = error.response;
  557. result.success = 1;//发送失败
  558. callback(result);
  559. }
  560. else
  561. {
  562. result.msg = info.response;
  563. result.success = 0;//发送成功
  564. callback(result);
  565. }
  566. });
  567. }
  568. else if(type == 2)
  569. {
  570. var msgRcvAdd = new msgRcv(
  571. {
  572. smsID:"SMS-"+sixtytwo.toString(moment().valueOf()),//smsID
  573. sendName:"中卫重要产品溯源平台",//发送人
  574. rcvName:address,//接收人
  575. title:"平台数据问题报告",//发送标题
  576. content:content,//发送消息
  577. }
  578. )
  579. msgRcvAdd.save(function (err) {
  580. if(err)
  581. {
  582. result.msg = error;
  583. result.success = 1;
  584. callback(result);
  585. }
  586. else
  587. {
  588. result.msg = "站内短信发送成功!";
  589. result.success = 0;//发送成功
  590. callback(result);
  591. }
  592. })
  593. }
  594. }
  595. //将数组转化为表格内容
  596. function qListToArray(qlist)
  597. {
  598. var content = "<table border=\"1\">\n" +
  599. "<tr>\n" +
  600. " <th>接口路径</th>\n" +
  601. " <th>接口名称</th>\n" +
  602. " <th>接口类型</th>\n" +
  603. " <th>问题描述</th>\n" +
  604. " </tr>";
  605. qlist.forEach(function (items) {
  606. content += "<tr>";
  607. content += "<td>"+items.API+"</td>";
  608. content += "<td>"+items.apiName+"</td>";
  609. content += "<td>"+items.interfaceType+"</td>";
  610. var desc = "";
  611. for(var i = 0 ; i < items.desc.length; i++)
  612. {
  613. desc += items.desc[i] + "<br>";
  614. }
  615. content += "<td>"+desc+"</td>"+"</tr>";
  616. });
  617. content += "</table>";
  618. return content;
  619. }
  620. //sample:
  621. // var qlist = [
  622. // {
  623. // API:"test3",
  624. // apiName:"test2",
  625. // interfaceType:"test1",
  626. // desc:[
  627. // "q1","q2"
  628. // ]
  629. // },{
  630. // API:"tesddd3",
  631. // apiName:"teddst2",
  632. // interfaceType:"tesddt1",
  633. // desc:[
  634. // "dddq1","dddq2"
  635. // ]
  636. // }
  637. // ]
  638. //
  639. // // console.log( qListToArray(qlist))
  640. //
  641. // var content = qListToArray(qlist);
  642. //
  643. // console.log(content)
  644. //
  645. // sendByEmailOrSms(1,"11169031@qq.com",content,function (callback) {
  646. // console.log(callback)
  647. // })
  648. exports.marketAnalysisAdd=marketAnalysisAdd;
  649. exports.update = update;
  650. exports.updateMore = updateMore;
  651. exports.Authentication=Authentication;
  652. exports.MainInterface=MainInterface;
  653. exports.search=search;
  654. exports.detail=detail;
  655. exports.createLogs=createLogs;
  656. exports.batch=batch;
  657. exports.RFID=RFID;
  658. exports.traceCode=traceCode;
  659. exports.getToken=getToken;
  660. exports.createUpLogs=createUpLogs;
  661. exports.sendByEmailOrSms=sendByEmailOrSms;
  662. exports.qListToArray=qListToArray;