Commit 28700514 by 宋毅

tj

parent 35a3df97
var WEBBase = require("../../web.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class NameAPI extends WEBBase{
class NameAPI extends WEBBase {
constructor() {
super();
this.redisClient = system.getObject("util.redisClient");
......@@ -29,16 +29,16 @@ class NameAPI extends WEBBase{
opResult = await this.getCache();
break;
case "getPreference"://偏好
opResult=await this.getPreference();
opResult = await this.getPreference();
break;
case "createName"://起名
opResult =await this.addOrderDelivery(pobj,pobj.actionBody);
opResult = await this.addOrderDelivery(pobj, pobj.actionBody);
break;
case "getNameDetail"://详情
opResult = await this.getNameDetail(pobj);
break;
case "getNames"://详情
opResult = await this.getNames(pobj,pobj.actionBody);
opResult = await this.getNames(req, pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
......@@ -51,7 +51,7 @@ class NameAPI extends WEBBase{
* 获取行业类别数据 後期可提出為一個service文件
* @returns {Promise<{}>}
*/
async getCache(){
async getCache() {
let cacheResult = {};
cacheResult.cache = cacheJson
return system.getResult(cacheResult);
......@@ -61,17 +61,17 @@ class NameAPI extends WEBBase{
* 获取偏好信息 後期可提出為一個service文件
* @returns {Promise<{}>}
*/
async getPreference(){
async getPreference() {
let preResult = {};
const key = 'qmbpreference';
let result = await this.redisClient.get(key)
if(result){
if (result) {
preResult.preference = JSON.parse(result);
return system.getResult(preResult);
}else{
const data = await this.restPostUrl({},this.centerCacheUrl+"preference_select");
if(data.code == 200){
await this.redisClient.set(key,JSON.stringify(data.data),2*3600)
} else {
const data = await this.restPostUrl({}, this.centerCacheUrl + "preference_select");
if (data.code == 200) {
await this.redisClient.set(key, JSON.stringify(data.data), 2 * 3600)
preResult.preference = data.data
return system.getResult(preResult);
}
......@@ -84,7 +84,7 @@ class NameAPI extends WEBBase{
* @param actionBody
* @returns {Promise<{msg: string, data: (*|null), bizmsg: *, status: number}|{msg: *, data: *, status: *}|{msg: *, data: (*|null), status: number}>}
*/
async addOrderDelivery(pobj,actionBody){
async addOrderDelivery(pobj, actionBody) {
if (!actionBody.orderId) {
return system.getResult(null, "orderId参数不能为空");
}
......@@ -106,46 +106,43 @@ class NameAPI extends WEBBase{
if (!actionBody.preference) {
return system.getResult(null, "preference参数不能为空");
}
await this.redisClient.set("ch"+JSON.stringify(actionBody.orderId),JSON.stringify(actionBody));
await this.redisClient.set("ch" + JSON.stringify(actionBody.orderId), JSON.stringify(actionBody));
return system.getResultSuccess();
}
//获取取名结果,并保存到数据库
async getNameDetail(pobj){
async getNameDetail(pobj) {
pobj.actionType = 'getOrderDeliveryInfo';
const opResult = await this.utilsOrderSve.getOrderDeliveryInfo(pobj, pobj.actionBody);
if(opResult.status != 0){
return system.getResult(null,opResult.msg);
if (opResult.status != 0) {
return system.getResult(null, opResult.msg);
}
if(opResult.data.hasOwnProperty('result_name')){
return system.getResult(opResult.data,'操作成功');
if (opResult.data.hasOwnProperty('result_name')) {
return system.getResult(opResult.data, '操作成功');
}
let actionBody =await this.redisClient.get('ch'+ JSON.stringify(pobj.actionBody.orderNo));
if(!actionBody){
let actionBody = await this.redisClient.get('ch' + JSON.stringify(pobj.actionBody.orderNo));
if (!actionBody) {
return system.getResult(null)
}
let nameResult = await this.restPostUrl(JSON.parse(actionBody),this.centerCacheUrl+"treasure_name");
if(nameResult.code == 200){
let nameResult = await this.restPostUrl(JSON.parse(actionBody), this.centerCacheUrl + "treasure_name");
if (nameResult.code == 200) {
pobj.actionType = 'addOrderDelivery';
pobj.actionBody = nameResult.data;
//取名结果存储
let result = await this.restPostUrl(pobj,this.centerOrderUrl + "action/nameOrder/springBoard");
return system.getResult(nameResult.data,"操作成功");
let result = await this.restPostUrl(pobj, this.centerOrderUrl + "action/nameOrder/springBoard");
return system.getResult(nameResult.data, "操作成功");
}
return system.getResult(null,'try again');
return system.getResult(null, 'try again');
}
async getNames(pobj,actionBody){
let rtn = await this.restClient.execPost(actionBody,this.aliGetNamesjavaUrl);
if (!rtn.stdout) {
return system.getResultFail();
}
var result = JSON.parse(rtn.stdout);
if(result) {
return system.getResultSuccess(result);
async getNames(req, actionBody) {
const result = await this.execPostByTimeOut(req, actionBody, this.aliGetNamesjavaUrl);
if (result.status != 0) {
return result;
}
return system.getResultFail(result);
const tmpData = result.data ? result.data.companyName : [];
return system.getResultSuccess(tmpData);
}
}
......@@ -153,7 +150,7 @@ const cacheJson = {
"科技类": ["网络科技", "电子商务", "信息技术", "游戏", "电子", "软件", "新材料", "生物科技", "教育科技", "环保科技", "信息科技"],
"许可类": ["投资管理", "金融", "资产", "商业保理", "融资租赁", "医疗器械", "人力资源", "食品", "劳务派遣"],
"服务类": ["广告", "文化传媒", "建筑装潢", "设计", "美容美发", "房地产中介", "物业管理", "商务咨询", "企业管理"],
"其他": ["贸易","实业","制造","服饰","化妆品","工程","农业","餐饮管理","物流"],
"其他": ["贸易", "实业", "制造", "服饰", "化妆品", "工程", "农业", "餐饮管理", "物流"],
}
......
......@@ -5,6 +5,7 @@ const md5 = require("MD5");
class WEBBase {
constructor() {
this.restClient = system.getObject("util.restClient");
this.execClientNew = system.getObject("util.execClientNew");
this.cacheManager = system.getObject("db.common.cacheManager");
this.logCtl = system.getObject("service.common.oplogSve");
this.toolSve = system.getObject("service.trademark.toolSve");
......@@ -73,5 +74,18 @@ class WEBBase {
var result = JSON.parse(rtn.stdout);
return result;
}
/**
* 带超时时间的post请求
* @param {*} req 请求信息
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间
*/
async execPostByTimeOut(req, params, url, ContentType, headData, timeOut = 60) {
const result = await this.execClientNew.execPostTimeOutByBusiness('sve.base', params, url, ContentType, headData, timeOut, req);
return result;
}
}
module.exports = WEBBase;
......@@ -60,7 +60,7 @@ var settings = {
},
aliGetNamesjavaUrl: function () {
if (this.env == "dev") {
return "192.168.210.240:80/getNames";
return "http://localhost:80/getNames";
} else {
return "http://aliossjava-service/getNames";
}
......
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