Jelajahi Sumber

feat: 计量附件删除逻辑优化

lanjianrong 4 tahun lalu
induk
melakukan
3011d2b092
4 mengubah file dengan 52 tambahan dan 45 penghapusan
  1. 39 34
      app/controller/stage_controller.js
  2. 8 8
      app/public/js/stage.js
  3. 2 3
      app/service/stage_att.js
  4. 3 0
      sql/update.sql

+ 39 - 34
app/controller/stage_controller.js

@@ -38,7 +38,7 @@ module.exports = app => {
             ctx.showProject = true;
             ctx.showTender = true;
             ctx.showTitle = true;
-            ctx.reUploadPermission = false;
+            // ctx.reUploadPermission = false;
         }
 
         /**
@@ -342,16 +342,16 @@ module.exports = app => {
                 const qtyData = ctx.helper.checkBillsWithPos(ledgerData, posData, ['contract_qty', 'qc_qty']);
                 qtyData.error.forEach(x => { x.errorType = 'qty'; });
                 const tpData = ctx.helper.checkBillsTp(ledgerData, [
-                    {qty: 'contract_qty', tp: 'contract_tp'}, {qty: 'qc_qty', tp: 'qc_tp'}
+                    { qty: 'contract_qty', tp: 'contract_tp' }, { qty: 'qc_qty', tp: 'qc_tp' },
                 ], this.ctx.tender.info.decimal);
                 tpData.error.forEach(x => { x.errorType = 'tp'; });
                 ctx.body = { err: 0, msg: '', data: {
-                        error: [...qtyData.error, ...tpData.error],
-                        source: {
-                            bills: [...qtyData.source.bills, ...tpData.source.bills],
-                            pos: [...qtyData.source.pos, ...tpData.source.pos],
-                        },
-                    }};
+                    error: [...qtyData.error, ...tpData.error],
+                    source: {
+                        bills: [...qtyData.source.bills, ...tpData.source.bills],
+                        pos: [...qtyData.source.pos, ...tpData.source.pos],
+                    },
+                } };
             } catch (err) {
                 this.log(err);
                 ctx.body = this.ajaxErrorBody(err, '检查数据错误');
@@ -1266,27 +1266,27 @@ module.exports = app => {
          * 检查当前期当前用户是否在审核列表中,如果是的话允许再次上传附件
          * @param {Object} ctx 上下文
          */
-        _checkStageCanModifyRe(ctx) {
-            // 检查登录用户,是否可操作
-            if (ctx.stage.readOnly) {
-                if (ctx.stage.status === auditConst.status.checked) {
-                    // 当前期状态为完成,且提交人是审核列表中的则可再次上传
-                    if (ctx.stage.user_id === ctx.session.sessionUser.accountId || ctx.stage.auditors.findIndex(auditor => auditor.aid === ctx.session.sessionUser.accountId) !== -1) {
-                        // 再次上传的图片要给个标识,方便给前端进行编辑操作
-                        ctx.reUploadPermission = true;
-                        return;
-                    }
-
-                    throw '该计量期当前您无权操作';
-
-                } else {
-                    throw '该计量期当前您无权操作';
-                }
-            }
-            if (ctx.stage.revising) {
-                throw '台账修订中,请勿修改提交期数据';
-            }
-        }
+        // _checkStageCanModifyRe(ctx) {
+        //     // 检查登录用户,是否可操作
+        //     if (ctx.stage.readOnly) {
+        //         if (ctx.stage.status === auditConst.status.checked) {
+        //             // 当前期状态为完成,且提交人是审核列表中的则可再次上传
+        //             if (ctx.stage.user_id === ctx.session.sessionUser.accountId || ctx.stage.auditors.findIndex(auditor => auditor.aid === ctx.session.sessionUser.accountId) !== -1) {
+        //                 // 再次上传的图片要给个标识,方便给前端进行编辑操作
+        //                 ctx.reUploadPermission = true;
+        //                 return;
+        //             }
+
+        //             throw '该计量期当前您无权操作';
+
+        //         } else {
+        //             throw '该计量期当前您无权操作';
+        //         }
+        //     }
+        //     if (ctx.stage.revising) {
+        //         throw '台账修订中,请勿修改提交期数据';
+        //     }
+        // }
         /**
          * 上传附件
          * @param {Object} ctx - egg全局变量
@@ -1300,11 +1300,12 @@ module.exports = app => {
             };
             let stream;
             try {
-                this._checkStageCanModifyRe(ctx);
+                // this._checkStageCanModifyRe(ctx);
 
                 const parts = ctx.multipart({ autoFields: true });
                 const files = [];
                 let index = 0;
+                const extra_upload = ctx.stage.status === auditConst.status.checked;
                 while ((stream = await parts()) !== undefined) {
                     // 判断用户是否选择上传文件
                     if (!stream.filename) {
@@ -1338,10 +1339,11 @@ module.exports = app => {
                         fileext: fileInfo.ext,
                         filesize: Array.isArray(parts.field.size) ? parts.field.size[index] : parts.field.size,
                         filepath,
+                        extra_upload,
                     };
-                    if (ctx.reUploadPermission) {
-                        fileData.re_upload = 1;
-                    }
+                    // if (ctx.reUploadPermission) {
+                    //     fileData.re_upload = 1;
+                    // }
                     const result = await ctx.service.stageAtt.save(parts.field, fileData, ctx.session.sessionUser.accountId);
                     if (!result) {
                         throw '导入数据库保存失败';
@@ -1447,10 +1449,13 @@ module.exports = app => {
                 data: '',
             };
             try {
-                this._checkStageCanModifyRe(ctx);
+                // this._checkStageCanModifyRe(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 const fileInfo = await ctx.service.stageAtt.getDataById(data.id);
+                if (!fileInfo.extra_upload && ctx.stage.status === auditConst.status.checked) {
+                    throw '无权限删除';
+                }
                 if (fileInfo !== undefined && fileInfo !== '') {
                     // 先删除文件
                     await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));

+ 8 - 8
app/public/js/stage.js

@@ -3277,14 +3277,14 @@ $(document).ready(() => {
             // 附件uid等于当前用户id, 附件上传本人
             if (parseInt(cur_uid) === att.uid) {
                 $('#btn-att').show();
-                let showDel = false;
-                if (!curAuditor) {
-                    stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
-                    stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
-                    stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
-                } else {
-                    curAuditor.aid === parseInt(cur_uid) && (showDel = true)
-                }
+                const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
+                // if (!curAuditor) {
+                //     stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
+                //     stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
+                //     stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
+                // } else {
+                //     curAuditor.aid === parseInt(cur_uid) && (showDel = true)
+                // }
                 if (showDel) $('#btn-att a').eq(3).show();
                 // $('#btn-att a').eq(3).show();
                 $('#btn-att a').eq(2).hide();

+ 2 - 3
app/service/stage_att.js

@@ -65,8 +65,7 @@ module.exports = app => {
          * @return {void}
          */
         async getDataByTenderIdAndStageId(tid, sid) {
-            const { ctx } = this;
-            const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.re_upload, att.remark, att.in_time,' +
+            const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.extra_upload, att.remark, att.in_time,' +
                 ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`, leg.b_code as `b_code`' +
                 ' FROM ?? AS att,?? AS pa,?? AS leg' +
                 ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.tid = ? AND att.sid = ? ORDER BY att.id DESC';
@@ -82,7 +81,7 @@ module.exports = app => {
          */
         async getDataByFid(id) {
             const { ctx } = this;
-            const sql = 'SELECT att.id, att.lid, att.uid, att.filepath, att.filename, att.re_upload, att.fileext, att.filesize, att.remark, att.in_time,' +
+            const sql = 'SELECT att.id, att.lid, att.uid, att.filepath, att.filename, att.extra_upload, att.fileext, att.filesize, att.remark, att.in_time,' +
                 ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`,leg.b_code as `b_code`' +
                 ' FROM ?? AS att,?? AS pa,?? AS leg' +
                 ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.id = ? ORDER BY att.in_time DESC';

+ 3 - 0
sql/update.sql

@@ -9,3 +9,6 @@ ADD COLUMN `extra_upload` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否是审核
 ALTER TABLE `zh_pos`
 MODIFY COLUMN `gxby_status`  int(4) NULL DEFAULT -1 COMMENT '工序报验-状态' AFTER `real_qty`,
 MODIFY COLUMN `dagl_status`  int(4) NULL DEFAULT -1 COMMENT '档案管理-状态' AFTER `gxby_status`;
+
+ALTER TABLE `zh_stage_attachment`
+CHANGE COLUMN `re_upload` `extra_upload` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否为审核通过后再次上传的文件,0为否' ;