d_solution.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const mysql = require('./mysql');
  2. const {searchSql,limitSql} = require("../tools/searchSql");
  3. const log = require("../logger").logger("d_solution","info");
  4. function loadSolution(key, page, limit) {
  5. let sql = ``;
  6. let values = [];
  7. sql += `SELECT
  8. news.id,
  9. news.remark,
  10. news.title as name,
  11. news.image,
  12. news.source_val as source,
  13. news.sourceType
  14. FROM
  15. hfy_news as news ,
  16. hfy_news_type as n_type
  17. WHERE
  18. news.type_id = n_type.type_id
  19. and n_type.parent_type = 1
  20. and n_type.type_key = ?`;
  21. values = [key];
  22. let _limitSql = limitSql(limit,page);
  23. sql += _limitSql.sql;
  24. values.push(..._limitSql.values);
  25. // log.info(sql);
  26. return mysql.pq(sql, values);
  27. }
  28. function searchSolution(type='array',searchParam,page,limit){
  29. let sql;
  30. let values = [];
  31. if(type === 'count'){
  32. sql = `
  33. select
  34. count(*) as total
  35. FROM hfy_news AS news
  36. INNER JOIN hfy_news_type AS n_type
  37. ON news.type_id = n_type.type_id`;
  38. }else{
  39. sql = `
  40. SELECT
  41. news.id,
  42. news.remark,
  43. news.title,
  44. news.title as name,
  45. news.image,
  46. news.coverId,
  47. f.filePath as coverPath,
  48. f.fileType as coverType,
  49. news.source,
  50. news.sourceType,
  51. n_type.type_key
  52. FROM hfy_news AS news
  53. LEFT JOIN hfy_files as f ON news.coverId = f.fileId
  54. INNER JOIN hfy_news_type AS n_type ON news.type_id = n_type.type_id
  55. `;
  56. }
  57. sql += ` where 1=1 `
  58. if(searchParam.parentType) {
  59. sql += ` and n_type.parent_type = ?`
  60. values.push(searchParam.parentType);
  61. }
  62. if(searchParam.key){
  63. sql += ` and news.title like '%${searchParam.key}%'`
  64. }
  65. if(searchParam.type){
  66. sql += ` and n_type.type_key = ?`
  67. values.push(searchParam.type)
  68. }
  69. // console.log(sql);
  70. // console.log(values);
  71. return searchSql(mysql.pq,type,sql,values,limit,page);
  72. }
  73. function getSolutionInfo(id) {
  74. let sql = ``;
  75. let values = [];
  76. sql += `SELECT
  77. news.*
  78. FROM
  79. hfy_news as news
  80. WHERE
  81. news.id = ?`;
  82. values = [id];
  83. return mysql.pq(sql, values);
  84. }
  85. module.exports = {
  86. loadSolution,
  87. searchSolution,
  88. getSolutionInfo
  89. }