Parcourir la source

决策大屏定制大屏调整

ellisran il y a 2 mois
Parent
commit
f35830400d

+ 5 - 1
app/controller/datacollect_controller.js

@@ -84,7 +84,11 @@ module.exports = app => {
                     jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.datacollect.index),
                 };
                 if (is_dz2) {
-                    const commonJson = projectData.common_json ? JSON.parse(projectData.common_json) : null;
+                    // 判断并更新common_json
+                    if (!ctx.subProject.common_json) {
+                        ctx.subProject.common_json = await ctx.service.subProject.updateCommonJsonDaping06(ctx.subProject, projectData);
+                    }
+                    const commonJson = ctx.subProject.common_json ? JSON.parse(ctx.subProject.common_json) : null;
                     renderData.daping06Set = commonJson && commonJson.daPing06_set ? commonJson.daPing06_set : ctx.helper._.cloneDeep(projectSettingConst.daPing06Set);
                     const glCategory = categoryData.find(item => item.name === '管理类别');
                     const dpCategory = [];

+ 5 - 2
app/controller/sub_proj_setting_controller.js

@@ -445,7 +445,10 @@ module.exports = app => {
                 if (is_dz2) {
                     const projectData = await this.ctx.service.project.getDataById(ctx.subProject.project_id);
                     // 获取分类及对应值
-                    const commonJson = projectData.common_json ? JSON.parse(projectData.common_json) : null;
+                    if (!ctx.subProject.common_json) {
+                        ctx.subProject.common_json = await ctx.service.subProject.updateCommonJsonDaping06(ctx.subProject, projectData);
+                    }
+                    const commonJson = ctx.subProject.common_json ? JSON.parse(ctx.subProject.common_json) : null;
                     renderData.daPing06Set = commonJson && commonJson.daPing06_set ? commonJson.daPing06_set : ctx.helper._.cloneDeep(projectSettingConst.daPing06Set);
                 }
                 await this.layout('sp_setting/datacollect.ejs', renderData, 'sp_setting/datacollect_modal.ejs');
@@ -511,7 +514,7 @@ module.exports = app => {
                         };
                         break;
                     case 'save-dp06':
-                        responseData.data = await ctx.service.project.saveCommonJson(ctx.subProject.project_id, 'daPing06_set', data.daPing06Set);
+                        responseData.data = await ctx.service.subProject.saveCommonJson(ctx.subProject.id, 'daPing06_set', data.daPing06Set);
                         break;
                     default:
                         throw '参数有误';

+ 65 - 0
app/service/sub_project.js

@@ -608,6 +608,71 @@ module.exports = app => {
             });
             return result.affectedRows === 1;
         }
+
+        async saveCommonJson(id, field, datas) {
+            const subProject = await this.getDataById(id);
+            subProject.common_json = subProject.common_json ? JSON.parse(subProject.common_json) : {};
+            const updateData = {
+                id,
+            };
+            subProject.common_json[field] = datas;
+            updateData.common_json = JSON.stringify(subProject.common_json);
+            const result = await this.db.update(this.tableName, updateData);
+            return result.affectedRows === 1;
+        }
+
+        async updateCommonJsonDaping06(subProject, projectData) {
+            const categoryData = await this.ctx.service.category.getAllCategory(subProject);
+            const projCommonJson = projectData.common_json ? JSON.parse(projectData.common_json) : null;
+            const projDaping06Set = projCommonJson && projCommonJson.daPing06_set ? projCommonJson.daPing06_set : null;
+            if (projDaping06Set) {
+                const subProjDaping06Set = {};
+                const orgCategoryData = await this.ctx.service.category.getOrgAllCategory(projectData.id);
+                const orgCb = this._.find(orgCategoryData, { id: projDaping06Set.cb }) || null;
+                const orgSr = this._.find(orgCategoryData, { id: projDaping06Set.sr }) || null;
+                if (orgCb) {
+                    const newCb = this._.find(categoryData, { name: orgCb.name });
+                    if (newCb) {
+                        subProjDaping06Set.cb = newCb.id;
+                        const orgCbv = this._.find(orgCb.value, { id: projDaping06Set.cb_value }) || null;
+                        if (orgCbv && orgCbv.value) {
+                            const newCbv = this._.find(newCb.value, { value: orgCbv.value });
+                            if (newCbv) {
+                                subProjDaping06Set.cb_value = newCbv.id;
+                            }
+                        }
+                    }
+                }
+                if (orgSr) {
+                    const newSr = this._.find(categoryData, { name: orgSr.name });
+                    if (newSr) {
+                        subProjDaping06Set.sr = newSr.id;
+                        const orgSrv = this._.find(orgSr.value, { id: projDaping06Set.sr_value }) || null;
+                        if (orgSrv && orgSrv.value) {
+                            const newSrv = this._.find(newSr.value, { value: orgSrv.value });
+                            if (newSrv) {
+                                subProjDaping06Set.sr_value = newSrv.id;
+                            }
+                        }
+                    }
+                }
+                const newCbShow = [];
+                const orgGlCategory = orgCategoryData.find(item => item.name === '管理类别');
+                for (const d of projDaping06Set.cb_show) {
+                    const org = orgGlCategory && orgGlCategory.value ? this._.find(orgGlCategory.value, { id: d }) || null : null;
+                    if (org && org.value) {
+                        const newGlCategory = categoryData.find(item => item.name === '管理类别');
+                        const newOrg = newGlCategory && newGlCategory.value ? this._.find(newGlCategory.value, { value: org.value }) : '';
+                        if (newOrg) {
+                            newCbShow.push(newOrg.id);
+                        }
+                    }
+                }
+                subProjDaping06Set.cb_show = newCbShow;
+                await this.saveCommonJson(subProject.id, 'daPing06_set', subProjDaping06Set);
+                return JSON.stringify({ daPing06_set: subProjDaping06Set });
+            }
+        }
     }
 
     return SubProject;

+ 2 - 1
sql/update.sql

@@ -13,7 +13,8 @@ ADD COLUMN `fun_rela` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NU
 ADD COLUMN `data_collect` tinyint(1) NOT NULL DEFAULT 0 COMMENT '决策大屏是否显示及对应大屏编号' AFTER `fun_rela`,
 ADD COLUMN `data_collect_pages` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '需要展示的大屏字符串,以,分隔' AFTER `data_collect`,
 ADD COLUMN `fun_set` varchar(5000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '项目设置页内容json' AFTER `data_collect_pages`,
-ADD COLUMN `payment_setting` JSON NULL DEFAULT NULL COMMENT '支付审批模块设置' AFTER `fun_set`;
+ADD COLUMN `payment_setting` JSON NULL DEFAULT NULL COMMENT '支付审批模块设置' AFTER `fun_set`,
+ADD COLUMN `common_json` json NULL COMMENT '通用json,没有sql查询值必要的可放这' AFTER `payment_setting`;
 
 ALTER TABLE `zh_category`
 ADD COLUMN `spid` varchar(36) NOT NULL DEFAULT '' COMMENT '子项目id(uuid)' AFTER `pid`;