| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2025/12/05
- * @version
- */
- const maxStashCount = 5;
- module.exports = app => {
- class SpssStash extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'spss_stash';
- }
- async getSpssStashList(spid, spssType) {
- const result = await this.getAllDataByCondition({
- where: { spid, spss_type: spssType },
- columns: [ 'id', 'user_id', 'user_name', 'create_time' ],
- orders: [['create_time', 'desc']],
- });
- if (result.length > maxStashCount) {
- const id = [...result].reverse().slice(0, result.length - maxStashCount).map(x => { return x.id; });
- await this.db.delete(this.tableName, { id });
- return result.slice(0, maxStashCount);
- }
- return result;
- }
- async getSpssStash(id) {
- const data = await this.getDataById(id);
- data.spss_select = JSON.parse(data.spss_select);
- data.spss_result = JSON.parse(data.spss_result);
- return data;
- }
- async addSpssStash(type, select, result) {
- const data = {
- id: this.uuid.v4(), spid: this.ctx.subProject.id,
- user_id: this.ctx.session.sessionUser.accountId, user_name: this.ctx.session.sessionUser.name,
- spss_type: type,
- spss_select: JSON.stringify(select),
- spss_result: JSON.stringify(result),
- };
- await this.db.insert(this.tableName, data);
- }
- }
- return SpssStash;
- };
|