| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 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,
- }
|