const {searchHandle} = require('../tools/searchSql'); const {handle} = require('../tools/handle'); const d_solution = require("../database/d_solution"); const codeMap = require("../map/rcodeMap"); const log = require("../logger").logger("c_solution","info") /** * 加载解决方案 * @param key * @param p * @param l * @returns {Promise<*[]>} */ async function loadSolution(key,p,l){ p = p || 1; l = l || 10; let [err,res] = await handle(d_solution.loadSolution(key, p, l)); if(err){ console.log(err); return [err,null]; } return [null,res]; } async function getSolutionInfo(id) { let [err,res] = await handle(d_solution.getSolutionInfo(id)); if(err){ return [err,null]; } let data = {}; if(res.length){ data = res[0]; }else{ return [ { eCode:codeMap.NotFound, eMsg:`无法找到对应产品` },null] } return [null,data]; } async function searchSolution(type, key, p, l) { p = p || 1; l = l || 10; let _params = { parentType: 1, } if(type !== 'all'){ _params.type = type; } if(key){ _params.key = key } return await searchHandle( '搜索产品失败', d_solution.searchSolution, _params, p, l); } async function searchNews(type, key, p, l) { p = p || 1; l = l || 10; let _params = { parentType: 2, } if(type !== 'all'){ _params.type = type; } if(key){ _params.key = key } return await searchHandle( '搜索新闻失败', d_solution.searchSolution, _params, p, l); } module.exports = { loadSolution, searchSolution, searchNews, getSolutionInfo }