c_solution.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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} = require("../tools/typeTool_cjs");
  6. const log = require("../logger").logger("c_solution","info")
  7. /**
  8. * 加载解决方案
  9. * @param key
  10. * @param p
  11. * @param l
  12. * @returns {Promise<*[]>}
  13. */
  14. async function loadSolution(key,p,l){
  15. p = p || 1;
  16. l = l || 10;
  17. let [err,res] = await handle(d_solution.loadSolution(key, p, l));
  18. if(err){
  19. console.log(err);
  20. return [err,null];
  21. }
  22. return [null,res];
  23. }
  24. async function getSolutionInfo(id)
  25. {
  26. let [err,res] = await handle(d_solution.getSolutionInfo(id));
  27. if(err){
  28. return [err,null];
  29. }
  30. let data = {};
  31. if(res.length){
  32. data = res[0];
  33. }else{
  34. return [
  35. {
  36. eCode:codeMap.NotFound,
  37. eMsg:`无法找到对应产品`
  38. },null]
  39. }
  40. return [null,data];
  41. }
  42. async function searchSolution(type, key, p, l)
  43. {
  44. p = p || 1;
  45. l = l || 10;
  46. let _params = {
  47. parentType: 1,
  48. }
  49. if(type !== 'all'){
  50. _params.type = type;
  51. }
  52. if(key){
  53. _params.key = key
  54. }
  55. return await searchHandle(
  56. '搜索产品失败',
  57. d_solution.searchSolution,
  58. _params,
  59. p,
  60. l);
  61. }
  62. async function searchNews(type, key, p, l)
  63. {
  64. p = p || 1;
  65. l = l || 10;
  66. let _params = {
  67. parentType: 2,
  68. }
  69. if(type !== 'all'){
  70. _params.type = type;
  71. }
  72. if(key){
  73. _params.key = key
  74. }
  75. return await searchHandle(
  76. '搜索新闻失败',
  77. d_solution.searchSolution,
  78. _params,
  79. p,
  80. l);
  81. }
  82. async function searchAllNews(pType,type, key, p, l){
  83. p = p || 1;
  84. l = l || 10;
  85. let _params = { }
  86. if(pType !== 'all'){
  87. _params.pType = type;
  88. }
  89. if(type !== 'all'){
  90. _params.type = type;
  91. }
  92. if(key){
  93. _params.key = key
  94. }
  95. if(isEmpty(_params)){
  96. return [
  97. {
  98. eCode:codeMap.NotParam,
  99. eMsg:`搜索文章参数异常`
  100. },null]
  101. }
  102. return await searchHandle(
  103. '搜索文章失败',
  104. d_solution.searchSolution,
  105. _params,
  106. p,
  107. l);
  108. }
  109. module.exports = {
  110. loadSolution,
  111. searchSolution,
  112. searchNews,
  113. searchAllNews,
  114. getSolutionInfo
  115. }