Commit 5bdb26e3 by 兰国旗

laolan

parents b3f2ffe4 004ce0d4
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
class Push360Service extends ServiceBase {
constructor() {
super();
this.pushlogDao = system.getObject("db.common.pushlogDao");
this.ordercontactsDao = system.getObject("db.dbcorder.ordercontactsDao");
this.push360Url = settings.push360Url();
this.auth360Url = settings.auth360Url();
}
//推送数据至360
async pushTmStatus(actionBody) {
let status = 0;
if (actionBody.tmStatus == "WAITCOMMIT" || actionBody.tmStatus == "ddj") {
status = 30;
}
if (actionBody.tmStatus == "ROBOT") {
status = 40;
}
let order_id = actionBody.orderNo;
try {
var rc = system.getObject("util.execClient");
let rtn = await rc.exec360GetToken(this.auth360Url)
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPost data is empty");
}
let tokenResult = JSON.parse(rtn.stdout);
let token = tokenResult.access_token;
let url = this.push360Url + '/api/v1/eshop/GsbOrderUpdate?token=' + token;
let pushObj = {
order_id: order_id,
status: status
}
let result = await rc.execPost(pushObj, url);
var logObj = {
appid: "",
appkey: "",
op: url,
content: JSON.stringify(actionBody),
resultInfo: result ? JSON.stringify(result) : ""
};
if (!result || !result.stdout) {
logObj["returnType"] = "0";
logObj["opTitle"] = "数据推送ali返回失败";
this.pushlogDao.create(logObj);
return system.getResultFail(-502, "execPost data is empty");
} else {
logObj["returnType"] = "1";
logObj["opTitle"] = "数据推送ali返回成功";
this.pushlogDao.create(logObj);
let stdout = JSON.parse(result.stdout);
return system.getResultSuccess(stdout);
}
} catch (e) {
this.pushlogDao.create({
appid: "",
appkey: "",
logLevel: "3",
op: this.push360Url,
content: JSON.stringify(actionBody),
resultInfo: JSON.stringify(e.stack),
returnType: "0",
opTitle: "数据推送360---异常"
});
return system.getResultFail(-500, JSON.stringify(e.stack));
}
}
//发送短信
async sendMessage(actionBody) {
try {
let orderNo = actionBody.orderNo;
//获取联系人信息
let item = await this.ordercontactsDao.getItemByOrderNo(actionBody.orderNo);
let deliveryInfo = actionBody.deliveryInfo;
if (!item) {
return system.getResultFail(-1, '获取联系人信息失败');
}
let mobile = item.mobile;//联系人手机号
let tmRegistNum = actionBody.registNumInfo.tmRegistNum;//申请号
let tmName = deliveryInfo.tm.tmName;//商标名称
let uploadFileName = actionBody.officialInfo.uploadFileName;//文件名
let oneNcl = deliveryInfo.nclones[0].code;//大类
let templateId = 1;
let failType = {
"2": "商标注册申请补正通知书",
"4": "商标注册申请不予受理通知书",
"5": "商标注册同日申请补送使用证据通知书",
"7": "商标驳回通知书",
"8": "商标部分驳回通知书",
"201": "超时未补正"
}
if (failType.hasOwnProperty(actionBody.tmStatus)) {
templateId = 2;
}
var rc = system.getObject("util.execClient");
let rtn = await rc.exec360GetToken(this.auth360Url)
if (!rtn || !rtn.stdout) {
return system.getResult(null, "restPost data is empty");
}
let tokenResult = JSON.parse(rtn.stdout);
let token = tokenResult.access_token;
let url = this.push360Url + '/api/v1/GsbSendsms';
let params = tmName + "|" + oneNcl + "|" + tmRegistNum + "|" + uploadFileName;
let subData = "token=" + token + "&mobile=" + mobile + "&templated=" + templateId + "&replaceContent=" + params;
let result = await rc.execGet(subData, url);
var logObj = {
appid: "",
appkey: "",
op: url,
content: JSON.stringify(actionBody),
resultInfo: result ? JSON.stringify(result) : ""
};
if (!result || !result.stdout) {
logObj["returnType"] = "0";
logObj["opTitle"] = "数据推送360返回失败";
this.pushlogDao.create(logObj);
return system.getResultFail(-502, "execPost data is empty");
} else {
logObj["returnType"] = "1";
logObj["opTitle"] = "数据推送360返回成功";
this.pushlogDao.create(logObj);
let stdout = JSON.parse(result.stdout);
return system.getResultSuccess(stdout);
}
} catch (e) {
this.pushlogDao.create({
appid: "",
appkey: "",
logLevel: "3",
op: this.push360Url,
content: JSON.stringify(actionBody),
resultInfo: JSON.stringify(e.stack),
returnType: "0",
opTitle: "数据推送360短信---异常"
});
return system.getResultFail(-500, JSON.stringify(e.stack));
}
}
}
module.exports = Push360Service;
...@@ -14,6 +14,7 @@ class OrderInfoService extends ServiceBase { ...@@ -14,6 +14,7 @@ class OrderInfoService extends ServiceBase {
this.moneyJourneyDao = system.getObject("db.dbcpay.moneyjourneyDao"); this.moneyJourneyDao = system.getObject("db.dbcpay.moneyjourneyDao");
this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao"); this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao");
this.orderRegionDao = system.getObject("db.dbcorder.orderregionDao"); this.orderRegionDao = system.getObject("db.dbcorder.orderregionDao");
this.push360Sve = system.getObject('service.common.push360Sve');
} }
//----------------------订单创建-----------start---------------- //----------------------订单创建-----------start----------------
...@@ -1414,13 +1415,20 @@ class OrderInfoService extends ServiceBase { ...@@ -1414,13 +1415,20 @@ class OrderInfoService extends ServiceBase {
deliveryInfo.nclones[tbCodeIndex].tmStatusName = "待递交"; deliveryInfo.nclones[tbCodeIndex].tmStatusName = "待递交";
orderLog.opContent = "尊敬的用户,您的商标:“" + deliveryInfo.tm.tmName + "”第" + deliveryInfo.nclones[tbCodeIndex].code + "类,办理状态更新为【待递交】"; orderLog.opContent = "尊敬的用户,您的商标:“" + deliveryInfo.tm.tmName + "”第" + deliveryInfo.nclones[tbCodeIndex].code + "类,办理状态更新为【待递交】";
}//待提交 }//待提交
else if (actionBody.tmStatus == "ROBOT") { else if (actionBody.tmStatus == "ROBOT" || actionBody.tmStatus == "ROBOTPAY") {
deliveryInfo.deliveryStatus = "ydj"; deliveryInfo.deliveryStatus = "ydj";
deliveryInfo.deliveryStatusName = "已递交"; deliveryInfo.deliveryStatusName = "已递交";
deliveryInfo.nclones[tbCodeIndex].tmStatus = "ydj"; deliveryInfo.nclones[tbCodeIndex].tmStatus = "ydj";
deliveryInfo.nclones[tbCodeIndex].tmStatusName = "已递交"; deliveryInfo.nclones[tbCodeIndex].tmStatusName = "已递交";
orderLog.opContent = "尊敬的用户,您的商标:“" + deliveryInfo.tm.tmName + "”第" + deliveryInfo.nclones[tbCodeIndex].code + "类,办理状态更新为【已递交】"; orderLog.opContent = "尊敬的用户,您的商标:“" + deliveryInfo.tm.tmName + "”第" + deliveryInfo.nclones[tbCodeIndex].code + "类,办理状态更新为【已递交】";
}//已提交--自己系统中存在此状态(升级后不存在,目前没有升级) }//已提交--自己系统中存在此状态(升级后不存在,目前没有升级)
else if (actionBody.tmStatus == "FILLEXCEPTION" ) {
actionBody.submitTime = actionBody.submitTime || new Date();
deliveryInfo.deliveryStatus = "djyc";
deliveryInfo.deliveryStatusName = "递交异常";
deliveryInfo.nclones[tbCodeIndex].tmStatusName = "递交异常";
orderLog.opContent = "尊敬的用户,您的商标:“" + deliveryInfo.tm.tmName + "”第" + deliveryInfo.nclones[tbCodeIndex].code + "类,办理状态更新为【递交异常】";
}//已收提交
else if (actionBody.tmStatus == "RECVCOMMIT" || actionBody.tmStatus == "ydj") { else if (actionBody.tmStatus == "RECVCOMMIT" || actionBody.tmStatus == "ydj") {
actionBody.submitTime = actionBody.submitTime || new Date(); actionBody.submitTime = actionBody.submitTime || new Date();
updateOrderFields.orderStatus = 8; updateOrderFields.orderStatus = 8;
...@@ -1464,7 +1472,12 @@ class OrderInfoService extends ServiceBase { ...@@ -1464,7 +1472,12 @@ class OrderInfoService extends ServiceBase {
deliveryInfo.opNotes = actionBody.opNotes || ""; deliveryInfo.opNotes = actionBody.opNotes || "";
this.putOrderDelivery(deliveryInfo, actionBody.orderNo); this.putOrderDelivery(deliveryInfo, actionBody.orderNo);
//商标状态推送 360
if(orderItem.uapp_id == 50){
actionBody.deliveryInfo = deliveryInfo;
this.push360Sve.pushTmStatus(actionBody);
this.push360Sve.sendMessage(actionBody)
}
} catch (error) { } catch (error) {
console.log("error------------------------", e.stack); console.log("error------------------------", e.stack);
} }
......
...@@ -7,7 +7,7 @@ class ExecClient { ...@@ -7,7 +7,7 @@ class ExecClient {
this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}"; this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}";
this.cmdGetPattern = "curl -G -X GET '{url}'"; this.cmdGetPattern = "curl -G -X GET '{url}'";
this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}"; this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}";
this.cmd360Token = "curl -u gongsibao:qPa4PsVsxbQ847i5pOKSmfPKrzRoNKqx -d '{data}' -X POST {url}"
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
...@@ -41,6 +41,12 @@ class ExecClient { ...@@ -41,6 +41,12 @@ class ExecClient {
console.log(cmd); console.log(cmd);
return cmd; return cmd;
} }
Fetch360TokenCmd(subData,url){
let cmd = this.cmd360Token.replace(
/\{data\}/g, subData).replace(/\{url\}/g, url);
console.log(cmd);
return cmd;
}
async execPost(subData, url) { async execPost(subData, url) {
let cmd = this.FetchPostCmd(subData, url); let cmd = this.FetchPostCmd(subData, url);
var result = await this.exec(cmd); var result = await this.exec(cmd);
...@@ -56,6 +62,29 @@ class ExecClient { ...@@ -56,6 +62,29 @@ class ExecClient {
var result = await this.exec2(cmd); var result = await this.exec2(cmd);
return result; return result;
} }
async exec360GetToken(url){
const qs = require('qs')
let obj = {"scope":"smart_business","grant_type":"client_credentials"}
// if(settings.env == 'dev'){
// const rs = await axios({
// method: 'post',
// url: url,
// data:qs.stringify(obj),
// auth: {
// username:"gongsibao",
// password:"qPa4PsVsxbQ847i5pOKSmfPKrzRoNKqx"
// }
// })
// const ret ={
// stdout:JSON.stringify(rs.data)
// }
// return ret;
// }
let cmd = this.Fetch360TokenCmd(qs.stringify(obj),url);
console.log(cmd);
var result = await this.exec(cmd);
return result;
}
FetchGetCmd(subData, url) { FetchGetCmd(subData, url) {
var cmd = this.cmdGetPattern.replace( var cmd = this.cmdGetPattern.replace(
......
...@@ -42,6 +42,20 @@ var settings = { ...@@ -42,6 +42,20 @@ var settings = {
return "http://gsb.qifu.gongsibao.com:4012/"; return "http://gsb.qifu.gongsibao.com:4012/";
} }
}, },
push360Url:function(){
if(this.env == 'dev'){
return "http://180.163.239.98:38086/";
} else {
return "http://180.163.239.98:38086/";
}
},
auth360Url:function(){
if(this.env == 'dev'){
return "https://oauth2.e.360.cn/site/token";
} else {
return "https://oauth2.e.360.cn/site/token";
}
},
apiconfig: { apiconfig: {
opLogUrl: function () { opLogUrl: function () {
return settings.reqEsAddr() + "center_order_log/_doc?pretty"; return settings.reqEsAddr() + "center_order_log/_doc?pretty";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment