c_solution.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 log = require("../logger").logger("c_solution","info")
  6. /**
  7. * 加载解决方案
  8. * @param key
  9. * @param p
  10. * @param l
  11. * @returns {Promise<*[]>}
  12. */
  13. async function loadSolution(key,p,l){
  14. p = p || 1;
  15. l = l || 10;
  16. let [err,res] = await handle(d_solution.loadSolution(key, p, l));
  17. if(err){
  18. console.log(err);
  19. return [err,null];
  20. }
  21. return [null,res];
  22. }
  23. async function getSolutionInfo(id)
  24. {
  25. let [err,res] = await handle(d_solution.getSolutionInfo(id));
  26. if(err){
  27. return [err,null];
  28. }
  29. let data = {};
  30. if(res.length){
  31. data = res[0];
  32. }else{
  33. return [
  34. {
  35. eCode:codeMap.NotFound,
  36. eMsg:`无法找到对应产品`
  37. },null]
  38. }
  39. return [null,data];
  40. }
  41. async function searchSolution(type, key, p, l)
  42. {
  43. p = p || 1;
  44. l = l || 10;
  45. let _params = {
  46. parentType: 1,
  47. }
  48. if(type !== 'all'){
  49. _params.type = type;
  50. }
  51. if(key){
  52. _params.key = key
  53. }
  54. return await searchHandle(
  55. '搜索产品失败',
  56. d_solution.searchSolution,
  57. _params,
  58. p,
  59. l);
  60. }
  61. async function searchNews(type, key, p, l)
  62. {
  63. p = p || 1;
  64. l = l || 10;
  65. let _params = {
  66. parentType: 2,
  67. }
  68. if(type !== 'all'){
  69. _params.type = type;
  70. }
  71. if(key){
  72. _params.key = key
  73. }
  74. return await searchHandle(
  75. '搜索新闻失败',
  76. d_solution.searchSolution,
  77. _params,
  78. p,
  79. l);
  80. }
  81. module.exports = {
  82. loadSolution,
  83. searchSolution,
  84. searchNews,
  85. getSolutionInfo
  86. }