12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- '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(pid, spid) {
- const result = await this.getDataByCondition({ pid, spid });
- this._analysisData(result);
- return result;
- }
- async initProjectColSet(pid, spid) {
- const data = JSON.parse(JSON.stringify(ProjectSetting.defaultColSet));
- JsonFields.forEach(jf => { if(data[jf]) data[jf] = JSON.stringify(data[jf]); });
- data.pid = pid;
- data.spid = spid;
- await this.db.insert(this.tableName, data);
- }
- async getProjectColSet(pid, spid) {
- const curSet = await this.loadProjectColSet(pid, spid);
- if (curSet) return curSet;
- await this.initProjectColSet(pid, spid);
- return await this.loadProjectColSet(pid, spid);
- }
- async setProjectColSet(pid, spid, colSetType, colSet) {
- const data = {};
- data[colSetType] = JSON.stringify(colSet);
- await this.defaultUpdate(data, { where: { pid, spid } });
- }
- 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;
- };
|