Procházet zdrojové kódy

feat: 添加weapp子项目详情接口,优化审批数据获取逻辑

Co-authored-by: Copilot <copilot@github.com>
lanjianrong před 1 měsícem
rodič
revize
53196aac3c

+ 73 - 0
app/controller/weapp_subp_controller.js

@@ -26,6 +26,79 @@ module.exports = app => {
             }
 
         }
+
+        async subProjectDetail(ctx) {
+            try {
+                const { id: subProjectId } = ctx.query;
+                if (!subProjectId) {
+                    ctx.body = { code: -1, msg: '子项目ID不能为空', data: null };
+                    return;
+                }
+                const subProject = await ctx.service.subProject.getDataById(subProjectId);
+                if (!subProject) {
+                    ctx.body = { code: -1, msg: '子项目不存在', data: null };
+                    return;
+                }
+                const pageShow = subProject.page_show ? JSON.parse(subProject.page_show) : {};
+                const auditList = [];
+                // 获取待审批的计量期列表
+                const auditStages = await ctx.service.stageAudit.getAuditStageByWap(ctx.projectAccount.id, subProjectId);
+                auditList.push(...(auditStages.map(item => ({ ...item, type: 'stage' }))));
+                // 获取待审批的变更期
+                const auditChanges = await ctx.service.changeAudit.getAuditChangeByWap(ctx.projectAccount.id, subProjectId);
+                auditList.push(...(auditChanges.map(item => ({ ...item, type: 'change' }))));
+                // 获取待审批的变更立项
+                if (pageShow.openChangeProject) {
+                    const changeProjects = await ctx.service.changeProjectAudit.getAuditChangeProjectByWap(ctx.projectAccount.id, subProjectId);
+                    auditList.push(...(changeProjects.map(item => ({ ...item, type: 'changeProject' }))));
+                }
+                // 获取待审批的变更申请
+                if (pageShow.openChangeApply) {
+                    const changeApplys = await ctx.service.changeApplyAudit.getAuditChangeApplyByWap(ctx.projectAccount.id, subProjectId);
+                    auditList.push(...(changeApplys.map(item => ({ ...item, type: 'changeApply' }))));
+                }
+                // 获取待审批的变更方案
+                if (pageShow.openChangePlan) {
+                    const changePlans = await ctx.service.changePlanAudit.getAuditChangePlanByWap(ctx.projectAccount.id, subProjectId);
+                    auditList.push(...(changePlans.map(item => ({ ...item, type: 'changePlan' }))));
+                }
+                // 获取待审批的台账修订
+                const ledgerRevises = await ctx.service.reviseAudit.getAuditReviseByWap(ctx.projectAccount.id, subProjectId);
+                auditList.push(...(ledgerRevises.map(item => ({ ...item, type: 'revise' }))));
+                // 获取待审批的预付款
+                const auditAdvance = await ctx.service.advanceAudit.getAuditAdvanceByWap(ctx.projectAccount.id, subProjectId);
+                auditList.push(...(auditAdvance.map(item => ({ ...item, type: 'advance' }))));
+                // 获取待审批的材料调差
+                if (pageShow.openMaterial) {
+                    const materialList = await ctx.service.materialAudit.getAuditMaterialByWap(ctx.projectAccount.id, subProjectId);
+                    auditList.push(...(materialList.map(item => ({ ...item, type: 'material' }))));
+                }
+                // 获取待审批的质量巡检单
+                if (pageShow.qualityInspection) {
+                    const qualityInspectionList = await ctx.service.qualityInspectionAudit.getAuditInspectionByWap(ctx.projectAccount.id, subProjectId);
+                    auditList.push(...(qualityInspectionList.map(item => ({ ...item, type: 'qualityInspection' }))));
+                }
+                // 获取待审批的安全巡检
+                if (pageShow.safeInspection) {
+                    const safeInspectionList = await ctx.service.safeInspectionAudit.getAuditInspectionByWap(ctx.projectAccount.id, subProjectId);
+                    auditList.push(...(safeInspectionList.map(item => ({ ...item, type: 'safeInspection' }))));
+                }
+                // 按照审批时间倒序排序
+                auditList.sort((a, b) => new Date(b.begin_time).getTime() - new Date(a.begin_time).getTime());
+                // 获取消息列表
+                const msgList = await ctx.service.message.getMsgList(ctx.project.id, subProjectId, 1);
+
+                ctx.body = {
+                    code: 0, msg: '', data: {
+                      auditList,
+                      msgList,
+                    },
+                };
+            } catch (error) {
+                this.log(error);
+                ctx.body = { code: -1, msg: '', data: null };
+            }
+        }
     }
 
     return WeappSubpController;

+ 1 - 0
app/router.js

@@ -1242,4 +1242,5 @@ module.exports = app => {
     app.get('/wx/weapp/userInfo', weappAuth, 'weappController.getUserInfo');
     app.get('/wx/weapp/dashboard', weappAuth, 'weappDashboardController.workspace');
     app.get('/wx/weapp/subp/list', weappAuth, 'weappSubpController.subProjectList');
+    app.get('/wx/weapp/subp/detail', weappAuth, 'weappSubpController.subProjectDetail');
 };

+ 3 - 2
app/service/advance_audit.js

@@ -791,7 +791,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditAdvanceByWap(auditorId) {
+        async getAuditAdvanceByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT ad.`id`, ad.`tid`, ad.`pay_ratio`, ad.`cur_amount`, ad.`prev_amount`, ad.`prev_total_amount`, ad.`type`, ad.`order`, ' +
                 // '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
@@ -799,7 +800,7 @@ module.exports = app => {
                 '    ti.`deal_info`, ti.`deal_param` ' +
                 '  FROM ?? AS aa, ?? AS ad, ?? As t, ?? AS ti ' +
                 '  WHERE aa.`audit_id` = ? and aa.`status` = ?' +
-                '    and aa.`vid` = ad.`id` and aa.`tid` = t.`id` and ti.`tid` = t.`id`';
+                '    and aa.`vid` = ad.`id` and aa.`tid` = t.`id` and ti.`tid` = t.`id`' + spSql;
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.advance.tableName,

+ 10 - 9
app/service/change_apply_audit.js

@@ -752,7 +752,7 @@ module.exports = app => {
          * ...
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _userCheckCancel(change) {
@@ -790,7 +790,7 @@ module.exports = app => {
          *                             四审 6 D uncheck      order改
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancel(change) {
@@ -855,7 +855,7 @@ module.exports = app => {
          *    三审 3 C uncheck
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelNo(change) {
@@ -913,7 +913,7 @@ module.exports = app => {
          * 会签未全部审批通过时,撤回仅修改本人状态
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelAnd(change) {
@@ -1138,7 +1138,7 @@ module.exports = app => {
             const sqlParam = [times, caId, caId];
             const user = await this.db.queryOne(sql, sqlParam);
             user.audit_order = 0;
-            group.unshift([ user ]);
+            group.unshift([user]);
             return group;
         }
 
@@ -1153,7 +1153,7 @@ module.exports = app => {
             const sqlParam = [times, caId, caId];
             const user = await this.db.queryOne(sql, sqlParam);
             user.audit_order = 0;
-            group.unshift([ user ]);
+            group.unshift([user]);
             return this.ctx.helper.groupAuditorsUniq(group);
         }
 
@@ -1398,9 +1398,10 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangeApplyByWap(auditorId) {
+        async getAuditChangeApplyByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
-                'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`caid`,' +
+                'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tidgetAuditChangePlanByWap`, sa.`caid`,' +
                 '    s.*,' +
                 '    t.`name` as `t_name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid`, ' +
                 '    ti.`deal_info`, ti.`decimal` ' +
@@ -1408,7 +1409,7 @@ module.exports = app => {
                 '    Left Join ?? AS s On sa.`caid` = s.`id`' +
                 '    Left Join ?? As t On sa.`tid` = t.`id`' +
                 '    Left Join ?? AS ti ON ti.`tid` = t.`id`' +
-                '  WHERE sa.`aid` = ? and sa.`status` = ?';
+                '  WHERE sa.`aid` = ? and sa.`status` = ?' + spSql;
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.changeApply.tableName,

+ 3 - 2
app/service/change_audit.js

@@ -329,14 +329,15 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangeByWap(uid) {
+        async getAuditChangeByWap(uid, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`sin_time`, ca.`name` As `caname`, ' +
                 '    c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`quality`, c.`total_price`,' +
                 '    t.`name`, t.`type`, t.`user_id`, ' +
                 '    ti.`deal_info`, ti.`decimal` ' +
                 '  FROM ?? AS ca, ?? AS c, ?? As t, ?? AS ti ' +
                 '  WHERE ca.`uid` = ? and ca.`status` = ? and (c.`status` = ? or c.`status` = ?)' +
-                '    and ca.`cid` = c.`cid` and ca.`tid` = t.`id` and ti.`tid` = t.`id`';
+                '    and ca.`cid` = c.`cid` and ca.`tid` = t.`id` and ti.`tid` = t.`id`' + spSql;
             const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, uid, auditConst.status.checking, auditConst.status.checking, auditConst.status.checkNoPre];
             const changes = await this.db.query(sql, sqlParam);
             for (const c of changes) {

+ 9 - 8
app/service/change_plan_audit.js

@@ -730,7 +730,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangePlanByWap(auditorId) {
+        async getAuditChangePlanByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`cpid`,' +
                 '    s.*,' +
@@ -740,7 +741,7 @@ module.exports = app => {
                 '    Left Join ?? AS s On sa.`cpid` = s.`id`' +
                 '    Left Join ?? As t On sa.`tid` = t.`id`' +
                 '    Left Join ?? AS ti ON ti.`tid` = t.`id`' +
-                '  WHERE sa.`aid` = ? and sa.`status` = ?';
+                '  WHERE sa.`aid` = ? and sa.`status` = ?' + spSql;
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.changePlan.tableName,
@@ -781,7 +782,7 @@ module.exports = app => {
          * ...
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _userCheckCancel(change) {
@@ -823,7 +824,7 @@ module.exports = app => {
          *                             四审 6 D uncheck      order改
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancel(change) {
@@ -907,7 +908,7 @@ module.exports = app => {
          *    三审 3 C uncheck
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelNo(change) {
@@ -965,7 +966,7 @@ module.exports = app => {
          * 会签未全部审批通过时,撤回仅修改本人状态
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelAnd(change) {
@@ -1209,7 +1210,7 @@ module.exports = app => {
             const sqlParam = [times, cpId, cpId];
             const user = await this.db.queryOne(sql, sqlParam);
             user.audit_order = 0;
-            group.unshift([ user ]);
+            group.unshift([user]);
             return group;
         }
 
@@ -1224,7 +1225,7 @@ module.exports = app => {
             const sqlParam = [times, cpId, cpId];
             const user = await this.db.queryOne(sql, sqlParam);
             user.audit_order = 0;
-            group.unshift([ user ]);
+            group.unshift([user]);
             return this.ctx.helper.groupAuditorsUniq(group);
         }
 

+ 10 - 9
app/service/change_project_audit.js

@@ -837,7 +837,7 @@ module.exports = app => {
          * ...
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _userCheckCancel(change) {
@@ -877,7 +877,7 @@ module.exports = app => {
          *                             四审 6 D uncheck      order改
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancel(change) {
@@ -932,7 +932,7 @@ module.exports = app => {
          * 审批人撤回审批终止,插入两条数据
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelStop(change) {
@@ -994,7 +994,7 @@ module.exports = app => {
          *    三审 3 C uncheck
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelNo(change) {
@@ -1052,7 +1052,7 @@ module.exports = app => {
          * 会签未全部审批通过时,撤回仅修改本人状态
          *
          * @param stage
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          * @private
          */
         async _auditCheckCancelAnd(change) {
@@ -1274,7 +1274,7 @@ module.exports = app => {
             const sqlParam = [times, cpId, cpId];
             const user = await this.db.queryOne(sql, sqlParam);
             user.audit_order = 0;
-            group.unshift([ user ]);
+            group.unshift([user]);
             return group;
         }
 
@@ -1289,7 +1289,7 @@ module.exports = app => {
             const sqlParam = [times, cpId, cpId];
             const user = await this.db.queryOne(sql, sqlParam);
             user.audit_order = 0;
-            group.unshift([ user ]);
+            group.unshift([user]);
             return this.ctx.helper.groupAuditorsUniq(group);
         }
 
@@ -1534,7 +1534,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditChangeProjectByWap(auditorId) {
+        async getAuditChangeProjectByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`cpid`,' +
                 '    s.*,' +
@@ -1544,7 +1545,7 @@ module.exports = app => {
                 '    Left Join ?? AS s On sa.`cpid` = s.`id`' +
                 '    Left Join ?? As t On sa.`tid` = t.`id`' +
                 '    Left Join ?? AS ti ON ti.`tid` = t.`id`' +
-                '  WHERE sa.`aid` = ? and sa.`status` = ?';
+                '  WHERE sa.`aid` = ? and sa.`status` = ?' + spSql;
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.changeProject.tableName,

+ 3 - 2
app/service/material_audit.js

@@ -1152,7 +1152,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditMaterialByWap(auditorId) {
+        async getAuditMaterialByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`mid`,' +
                 // '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
@@ -1163,7 +1164,7 @@ module.exports = app => {
                 '    Left Join ?? AS s On sa.`mid` = s.`id`' +
                 '    Left Join ?? As t On sa.`tid` = t.`id`' +
                 '    Left Join ?? AS ti ON ti.`tid` = t.`id`' +
-                '  WHERE sa.`aid` = ? and sa.`status` = ?';
+                '  WHERE sa.`aid` = ? and sa.`status` = ?' + spSql;
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.material.tableName,

+ 3 - 2
app/service/quality_inspection_audit.js

@@ -250,7 +250,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditInspectionByWap(auditorId) {
+        async getAuditInspectionByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`qiid`,' +
                 '    m.`code` As `mcode`, m.`status` As `mstatus`, m.`check_item`, m.`check_date`,' +
                 '    t.id As t_id, t.`name` As t_name, t.`project_id` As t_pid, t.`type` As t_type, t.`user_id` As t_uid, t.`status` As t_status, t.`spid`, ' +
@@ -259,7 +260,7 @@ module.exports = app => {
                 '  LEFT JOIN ?? AS m On ma.qiid = m.id' +
                 '  LEFT JOIN ?? As t On m.tid = t.id' +
                 '  LEFT JOIN ?? As ti On m.tid = ti.id' +
-                '  WHERE ma.`aid` = ? and (ma.`status` = ? OR ma.`status` = ?)' +
+                '  WHERE ma.`aid` = ? and (ma.`status` = ? OR ma.`status` = ?)' + spSql +
                 '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.qualityInspection.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, auditorId, auditConst.status.checking, auditConst.status.rectification];
             const result = await this.db.query(sql, sqlParam);

+ 3 - 2
app/service/revise_audit.js

@@ -817,7 +817,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditReviseByWap(auditorId) {
+        async getAuditReviseByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT ra.`audit_id`, ra.`times`, ra.`audit_order`, ra.`begin_time`, ra.`end_time`,' +
                 '    r.id, r.corder, r.uid, r.status, r.content, r.in_time, ' +
@@ -829,7 +830,7 @@ module.exports = app => {
                 '  Left Join ' + this.ctx.service.tender.tableName + ' AS t On r.tid = t.id' +
                 '  Left Join ' + this.ctx.service.tenderInfo.tableName + ' AS ti On r.tid = ti.tid' +
                 '  Left Join ' + this.ctx.service.projectAccount.tableName + ' As p On ra.audit_id = p.id' +
-                '  WHERE r.`valid` != 0 and ra.`audit_id` = ? and ra.`status` = ?' +
+                '  WHERE r.`valid` != 0 and ra.`audit_id` = ? and ra.`status` = ?' + spSql +
                 '  ORDER BY ra.`begin_time` DESC';
             const sqlParam = [auditorId, auditConst.status.checking];
             return await this.db.query(sql, sqlParam);

+ 3 - 2
app/service/safe_inspection_audit.js

@@ -250,7 +250,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditInspectionByWap(auditorId) {
+        async getAuditInspectionByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`qiid`,' +
                 '    m.`code` As `mcode`, m.`status` As `mstatus`, m.`check_item`, m.`check_date`,' +
                 '    t.id As t_id, t.`name` As t_name, t.`project_id` As t_pid, t.`type` As t_type, t.`user_id` As t_uid, t.`status` As t_status, t.`spid`, ' +
@@ -259,7 +260,7 @@ module.exports = app => {
                 '  LEFT JOIN ?? AS m On ma.qiid = m.id' +
                 '  LEFT JOIN ?? As t On m.tid = t.id' +
                 '  LEFT JOIN ?? As ti On m.tid = ti.id' +
-                '  WHERE ma.`aid` = ? and (ma.`status` = ? OR ma.`status` = ?)' +
+                '  WHERE ma.`aid` = ? and (ma.`status` = ? OR ma.`status` = ?)' + spSql +
                 '  ORDER BY ma.`begin_time` DESC';
             const sqlParam = [this.tableName, this.ctx.service.safeInspection.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, auditorId, auditConst.status.checking, auditConst.status.rectification];
             const result = await this.db.query(sql, sqlParam);

+ 3 - 2
app/service/stage_audit.js

@@ -1870,7 +1870,8 @@ module.exports = app => {
          * @param auditorId
          * @return {Promise<*>}
          */
-        async getAuditStageByWap(auditorId) {
+        async getAuditStageByWap(auditorId, spid = '') {
+            const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
                 // '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
@@ -1881,7 +1882,7 @@ module.exports = app => {
                 '    Left Join ?? AS s On sa.`sid` = s.`id`' +
                 '    Left Join ?? As t On sa.`tid` = t.`id`' +
                 '    Left Join ?? AS ti ON ti.`tid` = t.`id`' +
-                '  WHERE sa.`aid` = ? and sa.`status` = ?';
+                '  WHERE sa.`aid` = ? and sa.`status` = ?' + spSql;
             const sqlParam = [
                 this.tableName,
                 this.ctx.service.stage.tableName,