'use strict'; const { CrudService } = require('naf-framework-mongoose-free/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const _ = require('lodash'); const assert = require('assert'); // class UserService extends CrudService { constructor(ctx) { super(ctx, 'user'); this.redis = this.app.redis; this.deleteUserKey = 'deleteUser:'; this.redisTimeout = this.app.config.redisTimeout; } /** * 生成操作key * @param {String} opera_id 操作人id * @param {String} target 操作对象数据 */ async getDeleteUserKey(opera_id, target) { // 生成key const key = `${this.deleteUserKey}${opera_id}`; // 存储该key可操作的人 await this.redis.set(key, target, 'EX', this.redisTimeout); // 返回key return key; } /** * 解析key数据 * @param {Object} key 操作key */ async getKeyData(key) { const target = await this.redis.get(key); if (target) await this.redis.del(key); const arr = key.split(this.deleteUserKey); const opera_id = _.last(arr); return { opera_id, target }; } } module.exports = UserService;