Sfoglia il codice sorgente

计算模板限制个数读取标段配置

MaiXinRong 2 giorni fa
parent
commit
2e8501e993
2 ha cambiato i file con 26 aggiunte e 1 eliminazioni
  1. 23 1
      app/service/calc_tmpl.js
  2. 3 0
      sql/update.sql

+ 23 - 1
app/service/calc_tmpl.js

@@ -170,6 +170,23 @@ module.exports = app => {
             await this.analysisTemplate(result);
             return result;
         }
+        async getProjectCalcTmplSet () {
+            if (this.projectSet) return;
+            const defaultSet = { posCalc: { validCount: 50 }, cost: { validCount: 10 } };
+            const project = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
+            if (!project.calc_tmpl_set) {
+                this.projectSet = defaultSet;
+            } else {
+                this.projectSet = JSON.parse(project.calc_tmpl_set);
+                for (const prop in defaultSet) {
+                    if (this.projectSet[prop]) {
+                        this.projectSet[prop] = this.ctx.helper._.assign(defaultSet[prop], this.projectSet[prop]);
+                    } else {
+                        this.projectSet[prop] = defaultSet[prop];
+                    }
+                }
+            }
+        }
 
         //-------------------------- 以下方法不可随意修改 --------------------------
         // 根据列设置计算spreadjs配置相关,方法命名须严格按照【方法_类型】命名
@@ -360,8 +377,9 @@ module.exports = app => {
 
         async _addTemplate(name, type, folder_id) {
             if (ValidTemplateType.indexOf(type) < 0) throw '新增的模板类型非法';
+            await this.getProjectCalcTmplSet();
             const count = await this.count({pid: this.ctx.session.sessionProject.id, type});
-            if (count > this.TemplateRela[type].ValidCount) throw '已达模板使用上限';
+            if (count >= this.projectSet[type].validCount) throw '已达模板使用上限';
 
             const relaConst = this.TemplateRela[type];
             const insertData = {
@@ -501,6 +519,10 @@ module.exports = app => {
             const org = await this.getDataById(id);
             if (!org || org.pid !== this.ctx.session.sessionProject.id) throw '复制的模板不存在,请刷新后重试';
 
+            await this.getProjectCalcTmplSet();
+            const count = await this.count({pid: this.ctx.session.sessionProject.id, type});
+            if (count >= this.projectSet[org.type].validCount) throw '已达模板使用上限';
+
             const insertData = {
                 id: this.uuid.v4(),
                 pid: this.ctx.session.sessionProject.id,

+ 3 - 0
sql/update.sql

@@ -395,6 +395,9 @@ ADD COLUMN `num_u` decimal(24, 8) NOT NULL DEFAULT 0.00000000 COMMENT '数值7'
 ALTER TABLE `zh_calc_tmpl`
 ADD COLUMN `folder_id` varchar(36) NOT NULL DEFAULT '' COMMENT '分类id(zh_calc_tmpl_folder.id)' AFTER `tid`;
 
+ALTER TABLE `calculation`.`zh_project`
+ADD COLUMN `calc_tmpl_set` json NULL COMMENT '计算模板配置' AFTER `common_json`;
+
 ------------------------------------
 -- 表数据
 ------------------------------------