Commit cf023d17 by 兰国旗

去除缓存,恢复

parent e25361fe
const system = require("../../../system"); const system = require("../../../system");
const Dao = require("../../dao.base"); const Dao = require("../../dao.base");
const sha256 = require('sha256');
class MediaaggregationDao extends Dao { class MediaaggregationDao extends Dao {
constructor() { constructor() {
...@@ -19,11 +18,12 @@ class MediaaggregationDao extends Dao { ...@@ -19,11 +18,12 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_product where deleted_at is null and product_type_code = :product_type_code and is_enabled = 1 order by sequence desc"; var dataCount = "select count(1) as dataCount from mc_product where deleted_at is null and product_type_code = :product_type_code and is_enabled = 1 ";
var sql = "select * from mc_product where deleted_at is null and product_type_code = :product_type_code and is_enabled = 1 order by sequence desc"; var sql = "select * from mc_product where deleted_at is null and product_type_code = :product_type_code and is_enabled = 1 order by sequence desc";
var optionType = "get"; var list = await this.customQuery(sql, params);
var functionName = "productList"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params); var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -35,11 +35,13 @@ class MediaaggregationDao extends Dao { ...@@ -35,11 +35,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_rotation_chart where deleted_at is null and pic_type = 2 and is_enabled = 1 order by sequence desc"; var dataCount = "select count(1) as dataCount from mc_rotation_chart where deleted_at is null and pic_type = 2 and is_enabled = 1 ";
var sql = "select * from mc_rotation_chart where deleted_at is null and pic_type = 2 and is_enabled = 1 order by sequence desc"; var sql = "select * from mc_rotation_chart where deleted_at is null and pic_type = 2 and is_enabled = 1 order by sequence desc";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "rotationChartList"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -52,11 +54,13 @@ class MediaaggregationDao extends Dao { ...@@ -52,11 +54,13 @@ class MediaaggregationDao extends Dao {
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_rotation_chart where deleted_at is null and pic_type = 1 and is_enabled = 1 order by sequence desc"; var dataCount = "select count(1) as dataCount from mc_rotation_chart where deleted_at is null and pic_type = 1 and is_enabled = 1";
var sql = "select * from mc_rotation_chart where deleted_at is null and pic_type = 1 and is_enabled = 1 order by sequence desc"; var sql = "select * from mc_rotation_chart where deleted_at is null and pic_type = 1 and is_enabled = 1 order by sequence desc";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "tablePicList"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -68,11 +72,13 @@ class MediaaggregationDao extends Dao { ...@@ -68,11 +72,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_second_level_need_config where deleted_at is null "; var dataCount = "select count(1) as dataCount from mc_second_level_need_config where deleted_at is null ";
var sql = "select * from mc_second_level_need_config where deleted_at is null "; var sql = "select * from mc_second_level_need_config where deleted_at is null ";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "needProductList"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -85,11 +91,13 @@ class MediaaggregationDao extends Dao { ...@@ -85,11 +91,13 @@ class MediaaggregationDao extends Dao {
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_popular_recommendation where deleted_at is null and is_enabled = 1 "; var dataCount = "select count(1) as dataCount from mc_popular_recommendation where deleted_at is null and is_enabled = 1 ";
var sql = "select * from mc_popular_recommendation where deleted_at is null and is_enabled = 1 "; var sql = "select * from mc_popular_recommendation where deleted_at is null and is_enabled = 1 ";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "popularRecommendationList"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -101,11 +109,13 @@ class MediaaggregationDao extends Dao { ...@@ -101,11 +109,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_product_type where deleted_at is null and p_id = 0 order by sequence asc"; var dataCount = "select count(1) as dataCount from mc_product_type where deleted_at is null and p_id = 0 ";
var sql = "select * from mc_product_type where deleted_at is null and p_id = 0 order by sequence asc"; var sql = "select * from mc_product_type where deleted_at is null and p_id = 0 order by sequence asc";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "productTypeFirst"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -120,11 +130,13 @@ class MediaaggregationDao extends Dao { ...@@ -120,11 +130,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_product_type where deleted_at is null and p_code = :p_code order by sequence desc"; var dataCount = "select count(1) as dataCount from mc_product_type where deleted_at is null and p_code = :p_code ";
var sql = "select * from mc_product_type where deleted_at is null and p_code = :p_code order by sequence desc"; var sql = "select * from mc_product_type where deleted_at is null and p_code = :p_code order by sequence desc";
var optionType = "get"; var list = await this.customQuery(sql, params);
var functionName = "productTypeSecend"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params); var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
/** /**
...@@ -134,11 +146,8 @@ class MediaaggregationDao extends Dao { ...@@ -134,11 +146,8 @@ class MediaaggregationDao extends Dao {
var params = { var params = {
code: req.actionBody.code code: req.actionBody.code
}; };
var countSql = "select count(1) as dataCount from mc_product where deleted_at is null and is_enabled = 1 and code = :code ";
var sql = "select * from mc_product where deleted_at is null and is_enabled = 1 and code = :code "; var sql = "select * from mc_product where deleted_at is null and is_enabled = 1 and code = :code ";
var optionType = "get"; var returnRes = await this.customQuery(sql, params);
var functionName = "productDetail";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
return returnRes; return returnRes;
} }
...@@ -150,11 +159,13 @@ class MediaaggregationDao extends Dao { ...@@ -150,11 +159,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_bottom_menu_config where deleted_at is null "; var dataCount = "select count(1) as dataCount from mc_bottom_menu_config where deleted_at is null ";
var sql = "select * from mc_bottom_menu_config where deleted_at is null "; var sql = "select * from mc_bottom_menu_config where deleted_at is null ";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "bottomMenuConfig"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -166,11 +177,13 @@ class MediaaggregationDao extends Dao { ...@@ -166,11 +177,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_cycle_product where deleted_at is null order by sequence asc"; var dataCount = "select count(1) as dataCount from mc_cycle_product where deleted_at is null ";
var sql = "select * from mc_cycle_product where deleted_at is null order by sequence asc "; var sql = "select * from mc_cycle_product where deleted_at is null order by sequence desc";
var optionType = "get"; var list = await this.customQuery(sql);
var functionName = "cycleProduct"; returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName); var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -187,11 +200,13 @@ class MediaaggregationDao extends Dao { ...@@ -187,11 +200,13 @@ class MediaaggregationDao extends Dao {
rows: [] rows: []
}; };
var countSql = "select count(1) as dataCount from mc_second_level_need_config where deleted_at is null and code = :code "; var dataCount = "select count(1) as dataCount from mc_second_level_need_config where deleted_at is null and code = :code ";
var sql = "select * from mc_second_level_need_config where deleted_at is null and code = :code"; var sql = "select * from mc_second_level_need_config where deleted_at is null and code = :code";
var optionType = "get"; var list = await this.customQuery(sql, params);
var functionName = "secondLevelNeedConfig" returnRes.rows = list;
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params); var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -210,17 +225,18 @@ class MediaaggregationDao extends Dao { ...@@ -210,17 +225,18 @@ class MediaaggregationDao extends Dao {
}; };
if (apiType && apiType == '1') {//二类产品资质选项(选取数据线索的数据) if (apiType && apiType == '1') {//二类产品资质选项(选取数据线索的数据)
var countSql = "select count(1) as dataCount from mc_clue_maintenance where deleted_at is null"; var dataCount = "select count(1) as dataCount from mc_clue_maintenance where deleted_at is null";
var sql = "select clue_info from mc_clue_maintenance where deleted_at is null"; var sql = "select clue_info from mc_clue_maintenance where deleted_at is null";
var functionName = "clueMaintenance";
} }
if (apiType && apiType == '2') {//留资表单产品列表(我需要) if (apiType && apiType == '2') {//留资表单产品列表(我需要)
var countSql = "select count(1) as dataCount from mc_clue_maintenance where deleted_at is null and code = :code "; var dataCount = "select count(1) as dataCount from mc_clue_maintenance where deleted_at is null and code = :code ";
var sql = "select clue_info from mc_clue_maintenance where deleted_at is null and code = :code "; var sql = "select clue_info from mc_clue_maintenance where deleted_at is null and code = :code ";
var functionName = "clueMaintenanceCode";
} }
var optionType = "get"; var list = await this.customQuery(sql, params);
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params); returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes; return returnRes;
} }
...@@ -236,67 +252,14 @@ class MediaaggregationDao extends Dao { ...@@ -236,67 +252,14 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数 total: 0,//总记录条数
rows: [] rows: []
}; };
var functionName; var dataCount = "select count(1) as dataCount from mc_cycle_product where deleted_at is null and cycle_type = :cycle_type ";
var sql = "select * from mc_cycle_product where deleted_at is null and cycle_type = :cycle_type order by sequence asc"; var sql = "select * from mc_cycle_product where deleted_at is null and cycle_type = :cycle_type";
var countSql = "select count(1) as dataCount from mc_cycle_product where deleted_at is null and cycle_type = :cycle_type order by sequence asc "; var list = await this.customQuery(sql, params);
returnRes.rows = list;
switch (req.actionBody.cycle_type) { var tmpResultCount = await this.customQuery(dataCount, params);
case "1": returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
functionName = "cycleProductSecend1";
break;
case "2":
functionName = "cycleProductSecend2";
break;
case "3":
functionName = "cycleProductSecend3";
break;
}
var optionType = "get";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
return returnRes; return returnRes;
} }
async redisInfo(sql, countSql, optionType, functionName, params = {}) {
var template = "mediaaggregation";
let shaStr; // 将linkObj转为字符串并计算出sha256的值
let rtn; // 根据shaStr从redis库中查询返回的值。
let rtnObj = {
total: 0,//总记录条数
rows: []
};
shaStr = await sha256(JSON.stringify(params));
shaStr = template + "_" + shaStr + "_" + functionName;
rtn = await this.redisClient.get(shaStr);
if (params) {
var list = await this.customQuery(sql, params);
var dataCount = await this.customQuery(countSql, params);
} else {
var list = await this.customQuery(sql);
var dataCount = await this.customQuery(countSql);
}
if (optionType == "get") {
if (rtn) {
rtnObj.rows = JSON.parse(rtn);
rtnObj.total = dataCount && dataCount.length > 0 ? dataCount[0].dataCount : 0;
return rtnObj;
} else {
rtnObj.rows = list;
rtnObj.total = dataCount && dataCount.length > 0 ? dataCount[0].dataCount : 0;
await this.redisClient.set(shaStr, JSON.stringify(rtnObj));
await this.redisClient.client.expire(shaStr, 5);
rtn = await this.redisClient.get(shaStr);
if (rtn) {
return rtnObj;
}
}
}
if (optionType == "del") {
await this.redisClient.delete(shaStr);
}
}
} }
module.exports = MediaaggregationDao; module.exports = MediaaggregationDao;
\ No newline at end of file
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