Commit cf023d17 by 兰国旗

去除缓存,恢复

parent e25361fe
const system = require("../../../system");
const Dao = require("../../dao.base");
const sha256 = require('sha256');
class MediaaggregationDao extends Dao {
constructor() {
......@@ -19,11 +18,12 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
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 optionType = "get";
var functionName = "productList";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
var list = await this.customQuery(sql, params);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -35,11 +35,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
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 optionType = "get";
var functionName = "rotationChartList";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -52,11 +54,13 @@ class MediaaggregationDao extends Dao {
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 optionType = "get";
var functionName = "tablePicList";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -68,11 +72,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
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 optionType = "get";
var functionName = "needProductList";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -85,11 +91,13 @@ class MediaaggregationDao extends Dao {
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 optionType = "get";
var functionName = "popularRecommendationList";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -101,11 +109,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
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 optionType = "get";
var functionName = "productTypeFirst";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -120,11 +130,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
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 optionType = "get";
var functionName = "productTypeSecend";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
var list = await this.customQuery(sql, params);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
/**
......@@ -134,11 +146,8 @@ class MediaaggregationDao extends Dao {
var params = {
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 optionType = "get";
var functionName = "productDetail";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
var returnRes = await this.customQuery(sql, params);
return returnRes;
}
......@@ -150,11 +159,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
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 optionType = "get";
var functionName = "bottomMenuConfig";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -166,11 +177,13 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
rows: []
};
var countSql = "select count(1) as dataCount 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 asc ";
var optionType = "get";
var functionName = "cycleProduct";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName);
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 desc";
var list = await this.customQuery(sql);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -187,11 +200,13 @@ class MediaaggregationDao extends Dao {
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 optionType = "get";
var functionName = "secondLevelNeedConfig"
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
var list = await this.customQuery(sql, params);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -210,17 +225,18 @@ class MediaaggregationDao extends Dao {
};
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 functionName = "clueMaintenance";
}
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 functionName = "clueMaintenanceCode";
}
var optionType = "get";
var returnRes = this.redisInfo(sql, countSql, optionType, functionName, params);
var list = await this.customQuery(sql, params);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
return returnRes;
}
......@@ -236,67 +252,14 @@ class MediaaggregationDao extends Dao {
total: 0,//总记录条数
rows: []
};
var functionName;
var sql = "select * from mc_cycle_product where deleted_at is null and cycle_type = :cycle_type order by sequence asc";
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 ";
switch (req.actionBody.cycle_type) {
case "1":
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);
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";
var list = await this.customQuery(sql, params);
returnRes.rows = list;
var tmpResultCount = await this.customQuery(dataCount, params);
returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
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;
\ 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