123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2024/3/5
- * @version
- */
- const JsonFields = [ 'info' ];
- const ProjectSetting = require('../const/project_setting');
- module.exports = app => {
- class ProjectColSet extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'project_col_set';
- }
- _analysisData(data) {
- if (!data) return;
- JsonFields.forEach(jf => { if(data[jf]) data[jf] = JSON.parse(data[jf]); });
- }
- async loadProjectColSet(id) {
- const result = await this.getDataById(id);
- this._analysisData(result);
- return result;
- }
- async initProjectColSet(id) {
- const data = ProjectSetting.defaultColSet;
- JsonFields.forEach(jf => { if(data[jf]) data[jf] = JSON.stringify(data[jf]); });
- data.id = id;
- await this.db.insert(this.tableName, data);
- }
- async getProjectColSet(id) {
- const curSet = await this.loadProjectColSet(id);
- if (curSet) return curSet;
- await this.initProjectColSet(id);
- return await this.loadProjectColSet(id);
- }
- async setProjectColSet(id, colSetType, colSet) {
- const data = {id};
- data[colSetType] = JSON.stringify(colSet);
- await this.defaultUpdate(data);
- }
- analysisColSetWithDefine(colSetDefine, colSet) {
- const result = [];
- for (const csd of colSetDefine) {
- const cs = colSet.find(x => { return x.field === csd.field });
- if (cs) {
- result.push({...csd, ...cs});
- } else {
- result.push({...csd});
- }
- }
- return result;
- }
- }
- return ProjectColSet;
- };
|