base.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. //基类服务
  3. const Service = require('egg').Service;
  4. const fs = require('fs');
  5. //项目基类服务
  6. module.exports = class BaseService extends Service {
  7. /*==================================通用方法=====================================*/
  8. /**
  9. * [fileExists 判断文件是否存在]
  10. * @param {[type]} filepath [description]
  11. * @return {[type]} [description]
  12. */
  13. async fileExists(filepath) {
  14. return new Promise((reslove,reject) => {
  15. fs.access(filepath,(err) => {
  16. if(err) {
  17. reslove(false);
  18. } else {
  19. reslove(true);
  20. }
  21. });
  22. });
  23. }
  24. /**
  25. * [create 数据添加服务]
  26. * @author szjcomo
  27. * @date 2020-11-02
  28. * @param {[type]} createBean [description]
  29. * @param {String} error [description]
  30. * @return {[type]} [description]
  31. */
  32. async create(createBean,useModel,error = '数据添加失败,请稍候重试') {
  33. let that = this;
  34. let result = await that.app.comoBean.create(createBean,useModel,error);
  35. return result;
  36. }
  37. /**
  38. * [delete 数据删除]
  39. * @author szjcomo
  40. * @date 2020-11-02
  41. * @param {[type]} deleteBean [description]
  42. * @param {[type]} useModel [description]
  43. * @param {String} error [description]
  44. * @return {[type]} [description]
  45. */
  46. async delete(deleteBean,useModel,error = '数据删除失败,请稍候重试') {
  47. let that = this;
  48. let result = await that.app.comoBean.delete(deleteBean,useModel,error);
  49. return result;
  50. }
  51. /**
  52. * [update 数据更新]
  53. * @author szjcomo
  54. * @date 2020-11-02
  55. * @param {[type]} updateBean [description]
  56. * @param {[type]} useModel [description]
  57. * @param {String} error [description]
  58. * @return {[type]} [description]
  59. */
  60. async update(updateBean,useModel,error = '数据更新失败,请稍候重试') {
  61. let that = this;
  62. let result = await that.app.comoBean.update(updateBean,useModel,error);
  63. return result;
  64. }
  65. /**
  66. * [select 数据查询]
  67. * @author szjcomo
  68. * @date 2020-11-02
  69. * @param {[type]} selectBean [description]
  70. * @param {[type]} useModel [description]
  71. * @param {String} error [description]
  72. * @param {Boolean} count [description]
  73. * @param {Boolean} all [description]
  74. * @return {[type]} [description]
  75. */
  76. async select(selectBean,useModel,error = '数据查询失败,请稍候重试',count = false,all = false) {
  77. let that = this;
  78. let result = await that.app.comoBean.select(selectBean,useModel,count,all,error);
  79. return result;
  80. }
  81. }