12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 'use strict';
- //基类服务
- const Service = require('egg').Service;
- const fs = require('fs');
- //项目基类服务
- module.exports = class BaseService extends Service {
-
- /*==================================通用方法=====================================*/
- /**
- * [fileExists 判断文件是否存在]
- * @param {[type]} filepath [description]
- * @return {[type]} [description]
- */
- async fileExists(filepath) {
- return new Promise((reslove,reject) => {
- fs.access(filepath,(err) => {
- if(err) {
- reslove(false);
- } else {
- reslove(true);
- }
- });
- });
- }
- /**
- * [create 数据添加服务]
- * @author szjcomo
- * @date 2020-11-02
- * @param {[type]} createBean [description]
- * @param {String} error [description]
- * @return {[type]} [description]
- */
- async create(createBean,useModel,error = '数据添加失败,请稍候重试') {
- let that = this;
- let result = await that.app.comoBean.create(createBean,useModel,error);
- return result;
- }
- /**
- * [delete 数据删除]
- * @author szjcomo
- * @date 2020-11-02
- * @param {[type]} deleteBean [description]
- * @param {[type]} useModel [description]
- * @param {String} error [description]
- * @return {[type]} [description]
- */
- async delete(deleteBean,useModel,error = '数据删除失败,请稍候重试') {
- let that = this;
- let result = await that.app.comoBean.delete(deleteBean,useModel,error);
- return result;
- }
- /**
- * [update 数据更新]
- * @author szjcomo
- * @date 2020-11-02
- * @param {[type]} updateBean [description]
- * @param {[type]} useModel [description]
- * @param {String} error [description]
- * @return {[type]} [description]
- */
- async update(updateBean,useModel,error = '数据更新失败,请稍候重试') {
- let that = this;
- let result = await that.app.comoBean.update(updateBean,useModel,error);
- return result;
- }
- /**
- * [select 数据查询]
- * @author szjcomo
- * @date 2020-11-02
- * @param {[type]} selectBean [description]
- * @param {[type]} useModel [description]
- * @param {String} error [description]
- * @param {Boolean} count [description]
- * @param {Boolean} all [description]
- * @return {[type]} [description]
- */
- async select(selectBean,useModel,error = '数据查询失败,请稍候重试',count = false,all = false) {
- let that = this;
- let result = await that.app.comoBean.select(selectBean,useModel,count,all,error);
- return result;
- }
- }
|