const {searchHandle} = require('../tools/searchSql'); const {handle} = require('../tools/handle_cjs'); const d_solution = require("../database/d_solution"); const codeMap = require("../map/rcodeMap"); const {isEmpty, toNumber} = require("../tools/typeTool_cjs"); const {filePathToUrl} = require("../tools/filePathTool"); const {newsType} = require("../../map/newMap"); const dbField = require("../map/dbField"); 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, null, p, l, (item)=>{ if(item.coverPath){ item.coverPath = filePathToUrl(item.coverType,item.coverPath); }else{ item.coverPath = ''; } return item; }); } async function searchNews(type, key, sortKey = '', sortType = '', 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, { key: sortKey, type: sortType }, p, l, (item)=>{ if(item.coverPath){ item.coverPath = filePathToUrl(item.coverType,item.coverPath); }else{ item.coverPath = ''; } return item; } ); } async function searchAllNews(pType,type, key, p, l){ p = p || 1; l = l || 10; let _params = { } if(type !== 'all'){ _params.type = type; } if(key){ _params.key = key } pType = toNumber(pType); if(pType === dbField.db_base.newsType.news){ log.info(`新闻 未知${pType}`); _params.parentType = dbField.db_base.newsType.news; }else if(pType === dbField.db_base.newsType.solution){ log.info(`解决方案 未知${pType}`); _params.parentType = dbField.db_base.newsType.solution; }else{ // 不区分主类别 log.info(`pType 未知${pType} ${typeof pType}}`); } return await searchHandle( '搜索文章失败', d_solution.searchSolution, _params, null, p, l, (item)=>{ if(item.coverPath){ item.coverPath = filePathToUrl(item.coverType,item.coverPath); }else{ item.coverPath = ''; } return item; } ); } module.exports = { loadSolution, searchSolution, searchNews, searchAllNews, getSolutionInfo, }