c_solution.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. const {searchHandle} = require('../tools/searchSql');
  2. const {handle} = require('../tools/handle_cjs');
  3. const d_solution = require("../database/d_solution");
  4. const codeMap = require("../map/rcodeMap");
  5. const {isEmpty, toNumber} = require("../tools/typeTool_cjs");
  6. const {filePathToUrl} = require("../tools/filePathTool");
  7. const {newsType} = require("../../map/newMap");
  8. const dbField = require("../map/dbField");
  9. const log = require("../logger").logger("c_solution","info")
  10. /**
  11. * 加载解决方案
  12. * @param key
  13. * @param p
  14. * @param l
  15. * @returns {Promise<*[]>}
  16. */
  17. async function loadSolution(key,p,l){
  18. p = p || 1;
  19. l = l || 10;
  20. let [err,res] = await handle(d_solution.loadSolution(key, p, l));
  21. if(err){
  22. console.log(err);
  23. return [err,null];
  24. }
  25. return [null,res];
  26. }
  27. async function getSolutionInfo(id)
  28. {
  29. let [err,res] = await handle(d_solution.getSolutionInfo(id));
  30. if(err){
  31. return [err,null];
  32. }
  33. let data = {};
  34. if(res.length){
  35. data = res[0];
  36. }else{
  37. return [
  38. {
  39. eCode:codeMap.NotFound,
  40. eMsg:`无法找到对应产品`
  41. },null]
  42. }
  43. return [null,data];
  44. }
  45. async function searchSolution(type, key, p, l)
  46. {
  47. p = p || 1;
  48. l = l || 10;
  49. let _params = {
  50. parentType: 1,
  51. }
  52. if(type !== 'all'){
  53. _params.type = type;
  54. }
  55. if(key){
  56. _params.key = key
  57. }
  58. return await searchHandle(
  59. '搜索产品失败',
  60. d_solution.searchSolution,
  61. _params,
  62. p,
  63. l,
  64. (item)=>{
  65. if(item.coverPath){
  66. item.coverPath = filePathToUrl(item.coverType,item.coverPath);
  67. }else{
  68. item.coverPath = '';
  69. }
  70. return item;
  71. });
  72. }
  73. async function searchNews(type, key, p, l)
  74. {
  75. p = p || 1;
  76. l = l || 10;
  77. let _params = {
  78. parentType: 2,
  79. }
  80. if(type !== 'all'){
  81. _params.type = type;
  82. }
  83. if(key){
  84. _params.key = key
  85. }
  86. return await searchHandle(
  87. '搜索新闻失败',
  88. d_solution.searchSolution,
  89. _params,
  90. p,
  91. l,
  92. (item)=>{
  93. if(item.coverPath){
  94. item.coverPath = filePathToUrl(item.coverType,item.coverPath);
  95. }else{
  96. item.coverPath = '';
  97. }
  98. return item;
  99. }
  100. );
  101. }
  102. async function searchAllNews(pType,type, key, p, l){
  103. p = p || 1;
  104. l = l || 10;
  105. let _params = { }
  106. if(type !== 'all'){
  107. _params.type = type;
  108. }
  109. if(key){
  110. _params.key = key
  111. }
  112. pType = toNumber(pType);
  113. if(pType === dbField.db_base.newsType.news){
  114. log.info(`新闻 未知${pType}`);
  115. _params.parentType = dbField.db_base.newsType.news;
  116. }else if(pType === dbField.db_base.newsType.solution){
  117. log.info(`解决方案 未知${pType}`);
  118. _params.parentType = dbField.db_base.newsType.solution;
  119. }else{
  120. // 不区分主类别
  121. log.info(`pType 未知${pType} ${typeof pType}}`);
  122. }
  123. return await searchHandle(
  124. '搜索文章失败',
  125. d_solution.searchSolution,
  126. _params,
  127. p,
  128. l,
  129. (item)=>{
  130. if(item.coverPath){
  131. item.coverPath = filePathToUrl(item.coverType,item.coverPath);
  132. }else{
  133. item.coverPath = '';
  134. }
  135. return item;
  136. }
  137. );
  138. }
  139. module.exports = {
  140. loadSolution,
  141. searchSolution,
  142. searchNews,
  143. searchAllNews,
  144. getSolutionInfo,
  145. }