Commit 028a42f7 by 庄冰

template

parent facc8784
const system = require("../system");
const uuidv4 = require('uuid/v4');
const settings = require("../../config/settings");
const sha256 = require('sha256');
class APIBase {
constructor() {
this.cacheManager = system.getObject("db.common.cacheManager");
this.logClient = system.getObject("util.logClient");
this.queryAction = ["getTemplateAndLinkInfo"];
this.redisClient = system.getObject("util.redisClient");
}
async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"] ? req.headers["x-consumetag"].split("|") : null;
......@@ -36,12 +39,23 @@ class APIBase {
}
async doexec(gname, methodname, pobj, query, req) {
try {
var shaStr = await sha256(JSON.stringify(pobj));
//查询缓存
if (pobj && pobj.actionType && this.queryAction.indexOf(pobj.actionType) >= 0) {
var cacheRes = await this.redisClient.get(shaStr);
if (cacheRes) {
// return JSON.parse(cacheRes);
}
}
let xarg = await this.setContextParams(pobj, query, req);
if (xarg && xarg[0] < 0) {
return system.getResultFail(...xarg);
}
var rtn = await this[methodname](pobj, query, req);
this.logClient.log(pobj, req, rtn)
this.logClient.log(pobj, req, rtn);
if(rtn && rtn.status==0){
await this.redisClient.setWithEx(shaStr, JSON.stringify(rtn), 300);
}
return rtn;
} catch (e) {
this.logClient.log(pobj, req, null, e.stack);
......
......@@ -14,7 +14,7 @@ module.exports = (db, DataTypes) => {
describe: DataTypes.STRING,
pic_url: DataTypes.STRING,
is_enabled: DataTypes.INTEGER,
template_content: DataTypes.JSON,
template_content: DataTypes.TEXT,
form_id: DataTypes.INTEGER,
business_code:DataTypes.STRING,
notes: DataTypes.STRING,
......
......@@ -112,7 +112,7 @@ class TemplateinfoService extends ServiceBase {
if(!ab.code){
return system.getResultFail(-101,"模板编码不能为空");
}
if(!ab.hasOwnProperty("template_content")){
if(!ab.template_content){
return system.getResultFail(-102,"模板内容不能为空");
}
//根据模板编码获取模板信息
......@@ -205,6 +205,13 @@ class TemplateinfoService extends ServiceBase {
return system.getResultSuccess();
}
async update(qobj, tm = null) {
// 获取模板对应模板链接,并删除其redis缓存
if(qobj && qobj.id){
this.delRedisInfoByLinkByTempId(qobj.id);
}
return this.dao.update(qobj, tm);
}
/**
......@@ -221,7 +228,7 @@ class TemplateinfoService extends ServiceBase {
if(!ab.code){
return system.getResultFail(-101,"模板编码不能为空");
}
if(!ab.hasOwnProperty("template_content")){
if(!ab.template_content){
return system.getResultFail(-102,"模板内容不能为空");
}
// 获取对应模板
......
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