ソースを参照

调整决策大屏单位查看权限及人员增加单位id

laiguoran 2 年 前
コミット
ecb10e544b

+ 2 - 1
app/controller/login_controller.js

@@ -305,7 +305,7 @@ module.exports = app => {
             }
             let pa;
             try {
-                if (ctx.session.loginError !== null) {
+                if (ctx.session.loginError !== null && ctx.session.loginError !== undefined) {
                     throw ctx.session.loginError;
                 }
                 if (!ctx.query.mobile) {
@@ -331,6 +331,7 @@ module.exports = app => {
                 }
             } catch (error) {
                 // this.log(error);
+                console.log(error);
                 ctx.session.loginError = error;
             }
             const errorMessage = ctx.session.loginError;

+ 27 - 15
app/controller/setting_controller.js

@@ -515,7 +515,6 @@ module.exports = app => {
                 // 获取验证规则
                 const rule = ctx.service.projectAccount.rule('modify');
                 ctx.validate(rule);
-
                 const result = await ctx.service.projectAccount.save(ctx.request.body);
                 if (!result) {
                     throw '保存账号数据失败';
@@ -1084,9 +1083,14 @@ module.exports = app => {
                     where: { project_id: ctx.session.sessionProject.id, enable: 1 },
                     columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
                 });
-                const accountGroupList = accountGroup.map((item, idx) => {
-                    const groupList = accountList.filter(item => item.account_group === idx);
-                    return { groupName: item, groupList };
+                // const accountGroupList = accountGroup.map((item, idx) => {
+                //     const groupList = accountList.filter(item => item.account_group === idx);
+                //     return { groupName: item, groupList };
+                // });
+                const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
+                const accountGroupList = unitList.map(item => {
+                    const groupList = accountList.filter(item1 => item1.company === item.name);
+                    return { groupName: item.name, companyId: item.id, groupList };
                 });
                 const categoryData = await ctx.service.category.getAllCategory(ctx.session.sessionProject.id);
                 const tenders = await ctx.service.tender.getList('', null, 1);
@@ -1125,25 +1129,25 @@ module.exports = app => {
                         ctx.session.sessionProject.showDataCollect = data.data_collect ? 1 : 0;
                         break;
                     case 'add-audit':
-                        // 判断该用户的组是否已加入到表中,已加入则提示无需添加
+                        // 判断该用户是否已加入到表中,已加入则提示无需添加
                         const auditInfo = await ctx.service.datacollectAudit.getDataByCondition({ pid: projectId, uid: data.id });
                         if (auditInfo) {
                             throw '该用户已存在权限中,无需重复添加';
                         }
-                        const accountInfo = await ctx.service.projectAccount.getDataById(data.id);
-                        const groupInfo = await ctx.service.datacollectAudit.getGroupInfo(projectId, accountInfo.account_group);
-                        if (groupInfo) {
-                            throw '该用户所在单位已存在权限中,无需单独添加';
-                        }
-                        await ctx.service.datacollectAudit.saveAudit(projectId, accountInfo.account_group, data.id);
+                        // const accountInfo = await ctx.service.projectAccount.getDataById(data.id);
+                        // const companyInfo = await ctx.service.datacollectAudit.getCompanyInfo(projectId, accountInfo.company_id);
+                        // if (companyInfo) {
+                        //     throw '该用户所在单位已存在权限中,无需单独添加';
+                        // }
+                        await ctx.service.datacollectAudit.saveAudit(projectId, data.id);
                         responseData.data = await ctx.service.datacollectAudit.getList(projectId);
                         break;
-                    case 'add-group':
-                        const groupInfo2 = await ctx.service.datacollectAudit.getGroupInfo(projectId, data.id);
-                        if (groupInfo2) {
+                    case 'add-company':
+                        const companyInfo = await ctx.service.datacollectAudit.getCompanyInfo(projectId, data.id);
+                        if (companyInfo) {
                             throw '该单位已存在权限中,无需重复添加';
                         }
-                        await ctx.service.datacollectAudit.saveGroup(projectId, data.id);
+                        await ctx.service.datacollectAudit.saveCompany(projectId, data.id);
                         responseData.data = await ctx.service.datacollectAudit.getList(projectId);
                         break;
                     case 'del-audit':
@@ -1162,6 +1166,14 @@ module.exports = app => {
                         await ctx.service.datacollectAudit.delAudit(data.id);
                         responseData.data = await ctx.service.datacollectAudit.getList(projectId);
                         break;
+                    case 'del-company':
+                        const companyInfo2 = await ctx.service.datacollectAudit.getDataById(data.id);
+                        if (!companyInfo2) {
+                            throw '该单位已不存在权限中,移除失败';
+                        }
+                        await ctx.service.datacollectAudit.delAudit(data.id);
+                        responseData.data = await ctx.service.datacollectAudit.getList(projectId);
+                        break;
                     case 'tender':
                         if (ctx.session.sessionProject.page_show.addDataCollect !== parseInt(data.add_datacollect)) {
                             ctx.session.sessionProject.page_show.addDataCollect = parseInt(data.add_datacollect);

+ 27 - 4
app/middleware/session_auth.js

@@ -44,13 +44,36 @@ module.exports = options => {
                 if (sessionUser.is_admin) {
                     showDataCollect = 1;
                 } else {
-                    const grounpInfo = yield this.service.datacollectAudit.getGroupInfo(projectData.id, accountInfo.account_group);
-                    if (grounpInfo) {
+                    const auditInfo = yield this.service.datacollectAudit.getDataByCondition({ pid: projectData.id, uid: accountInfo.id });
+                    if (auditInfo) {
                         showDataCollect = 1;
                     } else {
-                        const auditInfo = yield this.service.datacollectAudit.getDataByCondition({ pid: projectData.id, uid: accountInfo.id });
-                        if (auditInfo) {
+                        let companyInfo = null;
+                        if (accountInfo.company_id) {
+                            companyInfo = yield this.service.datacollectAudit.getDataByCondition({
+                                pid: projectData.id,
+                                company_id: accountInfo.company_id
+                            });
+                        } else {
+                            const cuInfo = yield this.service.constructionUnit.getDataByCondition({
+                                pid: projectData.id,
+                                name: accountInfo.company
+                            });
+                            if (cuInfo) {
+                                companyInfo = yield this.service.datacollectAudit.getDataByCondition({
+                                    pid: projectData.id,
+                                    company_id: cuInfo.id,
+                                });
+                                yield this.service.projectAccount.update({ company_id: cuInfo.id }, { id: accountInfo.id });
+                            }
+                        }
+                        if (companyInfo) {
                             showDataCollect = 1;
+                        } else {
+                            const grounpInfo = yield this.service.datacollectAudit.getGroupInfo(projectData.id, accountInfo.account_group);
+                            if (grounpInfo) {
+                                showDataCollect = 1;
+                            }
                         }
                     }
                 }

+ 7 - 3
app/service/construction_unit.js

@@ -73,9 +73,15 @@ module.exports = app => {
                     }
                     data.create_time = new Date();
                 }
+                const operate = id === 0 ? await transaction.insert(this.tableName, data) :
+                    await transaction.update(this.tableName, data);
+                if (id === 0 && operate.affectedRows === 1) data.id = operate.insertId;
                 // 并修改用户的用户组及单位名称
                 const updateRow = {};
-                if (data.name) updateRow.company = data.name;
+                if (data.name) {
+                    updateRow.company = data.name;
+                    updateRow.company_id = data.id;
+                }
                 if (data.type) updateRow.account_group = data.type;
                 if (!this._.isEmpty(updateRow)) {
                     const info = id !== 0 ? await this.getDataById(id) : null;
@@ -93,8 +99,6 @@ module.exports = app => {
                     //     }
                     // );
                 }
-                const operate = id === 0 ? await transaction.insert(this.tableName, data) :
-                    await transaction.update(this.tableName, data);
                 transaction.commit();
                 const result = operate.affectedRows > 0;
                 return result;

+ 36 - 3
app/service/datacollect_audit.js

@@ -21,10 +21,15 @@ module.exports = app => {
             return await this.db.queryOne(sql, sqlParam);
         }
 
-        async saveAudit(pid, groupid, uid) {
+        async getCompanyInfo(pid, companyId) {
+            const sql = 'SELECT * FROM ?? WHERE pid = ? AND company_id = ? AND uid is NULL';
+            const sqlParam = [this.tableName, pid, companyId];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
+        async saveAudit(pid, uid) {
             const data = {
                 pid,
-                groupid,
                 uid,
                 create_time: new Date(),
             };
@@ -50,6 +55,31 @@ module.exports = app => {
             }
         }
 
+        async saveCompany(pid, companyId) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                // const companyInfo = await this.ctx.service.constructionUnit.getDataById(companyId);
+                // if (!companyInfo) throw '单位不存在';
+                // await transaction.delete(this.tableName, { pid, company_id: companyId });
+                // const nullCompanyList = await this.getAllDataByCondition({ where: { pid, company_id: null } });
+                // if (nullCompanyList.length > 0) {
+                //     const userList = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { company: companyInfo.name } });
+                //     await transaction.delete(this.tableName, { pid, uid: this._.map(userList, 'id') });
+                // }
+                const data = {
+                    pid,
+                    company_id: companyId,
+                    create_time: new Date(),
+                };
+                await transaction.insert(this.tableName, data);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
         async delAudit(id) {
             return await this.db.delete(this.tableName, { id });
         }
@@ -60,8 +90,11 @@ module.exports = app => {
                 if (l.uid) {
                     const accountInfo = await this.ctx.service.projectAccount.getDataById(l.uid);
                     l.name = accountInfo.name;
-                } else {
+                } else if (l.groupid) {
                     l.name = accountGroup[l.groupid];
+                } else if (l.company_id) {
+                    const companyInfo = await this.ctx.service.constructionUnit.getDataById(l.company_id);
+                    l.name = companyInfo ? companyInfo.name : null;
                 }
             }
             return list;

+ 9 - 0
app/service/project_account.js

@@ -413,6 +413,15 @@ module.exports = app => {
                 delete data._csrf_j;
             }
             const id = data.id !== undefined ? parseInt(data.id) : 0;
+            if (data.company !== undefined) {
+                if (!data.company) {
+                    throw '参数有误';
+                } else {
+                    const companyInfo = await this.ctx.service.constructionUnit.getDataByCondition({ pid: this.ctx.session.sessionProject.id, name: data.company });
+                    if (!companyInfo) throw '单位不存在';
+                    data.company_id = companyInfo.id;
+                }
+            }
             if (id > 0) {
                 // 修改操作时
                 delete data.create_time;

+ 17 - 9
app/view/setting/datacollect_modal.ejs

@@ -82,7 +82,7 @@
                                     <dt><a href="javascript: void(0);" class="acc-btn" data-groupid="<%- idx %>"
                                            data-type="hide"><i class="fa fa-plus-square"></i></a> <%- group.groupName %></dt>
                                     <div class="dd-content" data-toggleid="<%- idx %>">
-                                        <dd class="border-bottom p-2 mb-0" data-groupid="<%- idx %>"><p class="mb-0 d-flex"><span class="text-primary">该单位下所有组员</span></p></dd>
+                                        <dd class="border-bottom p-2 mb-0" data-companyid="<%- group.companyId %>"><p class="mb-0 d-flex"><span class="text-primary">该单位下所有组员</span></p></dd>
                                         <% group.groupList.forEach(item => { %>
                                             <% if (item.id !== ctx.session.sessionUser.accountId) { %>
                                                 <dd class="border-bottom p-2 mb-0 " data-id="<%- item.id %>">
@@ -99,7 +99,11 @@
                         <div class="card mt-1">
                             <ul class="list-unstyled modal-height-500" id="audit-list" style="overflow: auto">
                                 <% for (const audit of dataCollectAudits) { %>
-                                <li class="border-bottom p-2 mb-0"><a href="javascript:void(0)" class="text-danger pull-right" data-id="<%- audit.id %>" data-type="<% if (audit.uid) { %>audit<% } else { %>group<% } %>"><i class="fa fa-remove text-danger remove-audit"></i></a><%- audit.name %><small class="text-muted ml-1">账号<% if (!audit.uid) { %>组<% } %></small></li>
+                                <li class="border-bottom p-2 mb-0">
+                                    <a href="javascript:void(0)" class="text-danger pull-right" data-id="<%- audit.id %>" data-type="<% if (audit.uid) { %>audit<% } else if (audit.groupid) { %>group<% } else { %>company<% } %>">
+                                        <i class="fa fa-remove text-danger remove-audit"></i></a><%- audit.name %>
+                                    <small class="text-muted ml-1"><% if (audit.company_id) { %>参建单位<% } else { %>账号<% if (!audit.uid) { %>组<% } %><% } %></small>
+                                </li>
                                 <% } %>
                                     <!--<li class="border-bottom p-2 mb-0"><a href="" class="text-danger pull-right"><i class="fa fa-remove text-danger"></i></a>梁琪波<small class="text-muted ml-1">账号</small></li>-->
                             </ul>
@@ -144,7 +148,7 @@
                             html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
                         </a> ${group.groupName}</dt>
                         <div class="dd-content" data-toggleid="${idx}">
-                        <dd class="border-bottom p-2 mb-0" data-groupid="${idx}"><p class="mb-0 d-flex"><span class="text-primary">该单位下所有组员</span></p></dd>`
+                        <dd class="border-bottom p-2 mb-0" data-companyid="${group.companyId}"><p class="mb-0 d-flex"><span class="text-primary">该单位下所有组员</span></p></dd>`
                             group.groupList.forEach(item => {
                                 if (item.id !== cur_uid) {
                                     html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
@@ -183,13 +187,13 @@
         // 添加到成员中
         $('dl').on('click', 'dd', function () {
             const id = parseInt($(this).data('id'));
-            const groupid = parseInt($(this).data('groupid'));
+            const compnayId = parseInt($(this).data('companyid'));
             if (!isNaN(id) && id !== 0) {
                 postData('/setting/datacollect/save', { type: 'add-audit', id }, function (result) {
                     setList(result);
                 })
-            } else if (!isNaN(groupid) && groupid !== 0) {
-                postData('/setting/datacollect/save', { type: 'add-group', id: groupid }, function (result) {
+            } else if (!isNaN(compnayId) && compnayId !== 0) {
+                postData('/setting/datacollect/save', { type: 'add-company', id: compnayId }, function (result) {
                     setList(result);
                 })
             }
@@ -201,18 +205,22 @@
                 postData('/setting/datacollect/save', { type: 'del-audit', id: $(this).attr('data-id') }, function (result) {
                     setList(result);
                 })
-            } else {
+            } else if ($(this).attr('data-type') === 'group') {
                 postData('/setting/datacollect/save', { type: 'del-group', id: $(this).attr('data-id') }, function (result) {
                     setList(result);
                 })
+            } else if ($(this).attr('data-type') === 'company') {
+                postData('/setting/datacollect/save', { type: 'del-company', id: $(this).attr('data-id') }, function (result) {
+                    setList(result);
+                })
             }
         });
 
         function setList(datas) {
             let list = '';
             for (const audit of datas) {
-                list += '<li class="border-bottom p-2 mb-0"><a href="javascript:void(0)" class="text-danger pull-right" data-id="'+ audit.id +'"' + ' data-type="'+ (audit.uid ? 'audit' : 'group') +'">' +
-                    '<i class="fa fa-remove text-danger remove-audit"></i></a>'+ audit.name +'<small class="text-muted ml-1">账号'+ (!audit.uid ? '组' : '') +'</small></li>';
+                list += '<li class="border-bottom p-2 mb-0"><a href="javascript:void(0)" class="text-danger pull-right" data-id="'+ audit.id +'"' + ' data-type="'+ (audit.uid ? 'audit' : (audit.groupid ? 'group' : 'company')) +'">' +
+                    '<i class="fa fa-remove text-danger remove-audit"></i></a>'+ audit.name +'<small class="text-muted ml-1">'+ (audit.company_id ? '参建单位' : '账号'+ (!audit.uid ? '组' : '')) +'</small></li>';
             }
             $('#audit-list').html(list);
         }

+ 3 - 0
sql/update.sql

@@ -0,0 +1,3 @@
+ALTER TABLE `zh_project_account` ADD `company_id` INT NULL DEFAULT NULL COMMENT '所属参建单位id' AFTER `company`;
+
+ALTER TABLE `zh_datacollect_audit` ADD `company_id` INT NULL DEFAULT NULL COMMENT '参建单位id' AFTER `pid`;