c_solution.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 searchHandle(
  59. '搜索产品失败',
  60. d_solution.searchSolution,
  61. _params,
  62. null,
  63. p,
  64. l,
  65. (item) => {
  66. if (item.coverPath) {
  67. item.coverPath = filePathToUrl(item.coverType, item.coverPath);
  68. } else {
  69. item.coverPath = '';
  70. }
  71. return item;
  72. });
  73. }
  74. async function searchNews(type, key, sortKey = '', sortType = '', p, l)
  75. {
  76. p = p || 1;
  77. l = l || 10;
  78. let _params = {
  79. parentType: 2,
  80. }
  81. if(type !== 'all'){
  82. _params.type = type;
  83. }
  84. if(key){
  85. _params.key = key
  86. }
  87. return searchHandle(
  88. '搜索新闻失败',
  89. d_solution.searchSolution,
  90. _params,
  91. {
  92. key: sortKey,
  93. type: sortType
  94. },
  95. p,
  96. l,
  97. (item) => {
  98. if (item.coverPath) {
  99. item.coverPath = filePathToUrl(item.coverType, item.coverPath);
  100. } else {
  101. item.coverPath = '';
  102. }
  103. return item;
  104. }
  105. );
  106. }
  107. async function searchAllNews(pType,type, key, p, l){
  108. p = p || 1;
  109. l = l || 10;
  110. let _params = { }
  111. if(type !== 'all'){
  112. _params.type = type;
  113. }
  114. if(key){
  115. _params.key = key
  116. }
  117. pType = toNumber(pType);
  118. if(pType === dbField.db_base.newsType.news){
  119. log.info(`新闻 未知${pType}`);
  120. _params.parentType = dbField.db_base.newsType.news;
  121. }else if(pType === dbField.db_base.newsType.solution){
  122. log.info(`解决方案 未知${pType}`);
  123. _params.parentType = dbField.db_base.newsType.solution;
  124. }else{
  125. // 不区分主类别
  126. log.info(`pType 未知${pType} ${typeof pType}`);
  127. }
  128. return searchHandle(
  129. '搜索文章失败',
  130. d_solution.searchSolution,
  131. _params,
  132. null,
  133. p,
  134. l,
  135. (item) => {
  136. if (item.coverPath) {
  137. item.coverPath = filePathToUrl(item.coverType, item.coverPath);
  138. } else {
  139. item.coverPath = '';
  140. }
  141. return item;
  142. }
  143. );
  144. }
  145. module.exports = {
  146. loadSolution,
  147. searchSolution,
  148. searchNews,
  149. searchAllNews,
  150. getSolutionInfo,
  151. }