|
@@ -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;
|