Browse Source

变更撤销修订第一版及部分bug修复

ellisran 1 năm trước cách đây
mục cha
commit
7daac72543

+ 33 - 0
app/controller/change_controller.js

@@ -1603,6 +1603,39 @@ module.exports = app => {
         }
 
         /**
+         * 变更令撤销修订
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async cancelRevise(ctx) {
+            try {
+                const changeData = await ctx.service.change.getDataByCondition({ cid: ctx.request.body.cid });
+                if (!changeData) {
+                    throw '变更令数据错误';
+                }
+                if (!(changeData.status === audit.flow.status.revise && (ctx.session.sessionUser.accountId === changeData.uid || ctx.session.sessionUser.accountId === ctx.session.sessionUser.is_admin))) {
+                    throw '您无权进行该操作';
+                }
+                // 重新审批
+                const result = await ctx.service.change.cancelRevise(changeData.cid, changeData.times);
+                if (!result) {
+                    throw '撤销修订失败';
+                }
+                ctx.body = {
+                    err: 0,
+                    url: ctx.request.header.referer,
+                    msg: '',
+                };
+            } catch (err) {
+                console.log(err);
+                ctx.body = {
+                    err: 1,
+                    msg: err,
+                };
+            }
+        }
+
+        /**
          * 获取变更清单
          * @param ctx
          * @return {Promise<void>}

+ 3 - 4
app/public/js/change_information_set.js

@@ -538,8 +538,7 @@ $(document).ready(() => {
                         // 需要判断是否已调用,已调用的则不能低于原有值大小
                         const usedInfo = _.find(changeUsedData, { cbid: select.id });
                         if (usedInfo && usedInfo.qty) {
-                            const minLimit = Math.ceil(ZhCalc.div(usedInfo.qty, select.camount) * 100);
-                            console.log(usedInfo.qty, minLimit);
+                            const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
                             if (validText < minLimit) {
                                 toastr.error('计量上限值至少大于等于 ' + minLimit);
                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -683,7 +682,7 @@ $(document).ready(() => {
                             // 需要判断是否已调用,已调用的则不能低于原有值大小
                             const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
                             if (usedInfo && usedInfo.qty) {
-                                const minLimit = Math.ceil(ZhCalc.div(usedInfo.qty, sortData[curRow].camount) * 100);
+                                const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
                                 if (validText < minLimit) {
                                     toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
                                     bPaste = false;
@@ -1013,7 +1012,7 @@ $(document).ready(() => {
                 const Commands = GC.Spread.Sheets.Commands;
                 const sel = changeSpreadSheet.getSelections()[0];
                 const col = changeSpreadSheet.zh_setting.cols[sel.col];
-                if (col && col.field !== 'changed_tp') {
+                if (col && col.field !== 'sa_tp') {
                     isUndo = true;
                 }
                 if (isUndo) {

+ 1 - 0
app/router.js

@@ -481,6 +481,7 @@ module.exports = app => {
     app.post('/tender/:id/change/approval', sessionAuth, tenderCheck, uncheckTenderCheck, tenderBuildCheck, 'changeController.approval');
     app.post('/tender/:id/change/check/again', sessionAuth, tenderCheck, uncheckTenderCheck, tenderBuildCheck, 'changeController.checkAgain');
     app.post('/tender/:id/change/check/revise', sessionAuth, tenderCheck, uncheckTenderCheck, tenderBuildCheck, 'changeController.checkRevise');
+    app.post('/tender/:id/change/cancel/revise', sessionAuth, tenderCheck, uncheckTenderCheck, tenderBuildCheck, 'changeController.cancelRevise');
 
     app.post('/tender/:id/change/:cid/check/codeRepeat', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.checkCodeRepeat');
     app.post('/tender/:id/change/:cid/info/copy', sessionAuth, tenderCheck, uncheckTenderCheck, 'changeController.copyChange');

+ 25 - 0
app/service/change.js

@@ -1479,6 +1479,8 @@ module.exports = app => {
                 const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
                     where: { cid: changeData.cid },
                 });
+                // 生成内容保存表至zh_change_history中,用于撤销修订回退
+                await this.ctx.service.changeHistory.saveHistory(this.transaction, changeData, changeList);
                 // 申请变更金额更新为上一次审批审批变更后数量,清空audit_amount值
                 const updateTpList = [];
                 for (const cl of changeList) {
@@ -1521,6 +1523,29 @@ module.exports = app => {
         }
 
         /**
+         * 撤销修订变更令
+         * @param { string } cid - 查询的清单
+         * @return {Promise<*>} - 可用的变更令列表
+         */
+        async cancelRevise(cid, times) {
+            // 初始化事务
+            this.transaction = await this.db.beginTransaction();
+            let result = false;
+            try {
+                await this.ctx.service.changeHistory.returnHistory(this.transaction, cid);
+                await this.transaction.delete(this.ctx.service.changeAudit.tableName, { cid, times });
+                await this.transaction.delete(this.ctx.service.changeHistory.tableName, { cid });
+                await this.transaction.commit();
+                result = true;
+            } catch (error) {
+                console.log(error);
+                await this.transaction.rollback();
+                result = false;
+            }
+            return result;
+        }
+
+        /**
          * 重新审批变更令
          * @param { string } cid - 查询的清单
          * @return {Promise<*>} - 可用的变更令列表

+ 112 - 0
app/service/change_history.js

@@ -0,0 +1,112 @@
+'use strict';
+
+/**
+ * 变更新增部位插入记录表
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+module.exports = app => {
+
+    class ChangeHistory extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'change_history';
+        }
+
+        async saveHistory(transaction, data, list) {
+            // const info_json = {
+            //     code: data.code,
+            //     w_code: data.code,
+            //     p_code: data.p_code,
+            //     name: data.name,
+            //     plan_code: data.plan_code,
+            //     peg: data.peg,
+            //     org_name: data.org_name,
+            //     org_code: data.org_code,
+            //     new_name: data.new_name,
+            //     new_code: data.new_code,
+            //     content: data.content,
+            //     basis: data.basis,
+            //     expr: data.expr,
+            //     memo: data.memo,
+            //     type: data.type,
+            //     class: data.class,
+            //     quality: data.quality,
+            //     company: data.company,
+            //     charge: data.charge,
+            // };
+            await transaction.insert(this.tableName, {
+                tid: data.tid,
+                cid: data.cid,
+                info_json: JSON.stringify(data),
+                list_json: JSON.stringify(list),
+            });
+        }
+
+        async returnHistory(transaction, cid) {
+            const data = await transaction.get(this.tableName, { cid });
+            if (!data) throw '撤销前数据不存在,无法撤销';
+            const change_update = {};
+            const oldInfo = JSON.parse(data.info_json);
+            for (const key in oldInfo) {
+                if (key !== 'cid' && key !== 'in_time') {
+                    change_update[key] = oldInfo[key];
+                }
+            }
+            const options = {
+                where: {
+                    cid,
+                },
+            };
+            await transaction.update(this.ctx.service.change.tableName, change_update, options);
+            const oldList = JSON.parse(data.list_json);
+            // 更新已调用清单id值
+            const sql1 = 'SELECT a.* FROM ?? as b LEFT JOIN ?? as a ON b.cbid = a.id WHERE b.cid = ? GROUP BY b.cbid';
+            const sqlParam1 = [this.ctx.service.stageChange.tableName, this.ctx.service.changeAuditList.tableName, cid];
+            const usedList = await transaction.query(sql1, sqlParam1);
+            // 先删后插
+            await transaction.delete(this.ctx.service.changeAuditList.tableName, { cid });
+            await transaction.insert(this.ctx.service.changeAuditList.tableName, oldList);
+            // 可能需要更新stage_change和stage_change_final的cbid
+            if (usedList.length > 0) {
+                const updateList = [];
+                const sql2 = 'SELECT * FROM ?? WHERE `cid` = ? AND `lid` != "0"';
+                const sqlParam2 = [this.ctx.service.changeAuditList.tableName, cid];
+                const newList = await transaction.query(sql2, sqlParam2);
+                // const newList = await transaction.select(this.tableName, { where: { cid: this.ctx.change.cid } });
+                for (const used of usedList) {
+                    const findFilter = { lid: used.lid, gcl_id: used.gcl_id, bwmx: used.bwmx };
+                    const findFilter2 = { lid: used.lid, gcl_id: used.gcl_id, bwmx: used.bwmx };
+                    if (used.mx_id) findFilter2.mx_id = used.mx_id;
+                    const newone = this._.find(newList, findFilter2) || this._.find(newList, findFilter);
+                    if (newone && newone.id !== used.cbid) {
+                        updateList.push({
+                            row: {
+                                cbid: newone.id,
+                            },
+                            where: {
+                                cid,
+                                cbid: used.id,
+                            },
+                        });
+                    }
+                }
+                if (updateList.length > 0) {
+                    await transaction.updateRows(this.ctx.service.stageChange.tableName, updateList);
+                    await transaction.updateRows(this.ctx.service.stageChangeFinal.tableName, updateList);
+                }
+            }
+        }
+    }
+
+    return ChangeHistory;
+};

+ 3 - 0
app/view/change/information.ejs

@@ -77,6 +77,9 @@
                         <a href="#sub-ap" data-category="up_change" data-toggle="modal" data-target="#sub-ap" class="btn btn-primary btn-sm">上报审批</a>
                     <% } else if (auditStatus === 2 || auditStatus === 9) { %>
                         <a href="#sub-sp2" data-category="up_change" data-toggle="modal" data-target="#sub-sp2" class="btn btn-primary btn-sm">重新上报</a>
+                        <% if (auditStatus === 9) { %>
+                            <a href="#sub-revoke" data-toggle="modal" data-target="#sub-revoke" class="btn btn-warning btn-sm">撤销修订</a>
+                        <% } %>
                     <% } else if (auditStatus === 3) { %>
                         <a href="#sp-list" data-toggle="modal" data-target="#sp-list" class="btn btn-outline-warning btn-sm text-muted">审批退回</a>
                     <% } else if (auditStatus === 4) { %>

+ 44 - 0
app/view/change/information_modal.ejs

@@ -350,6 +350,31 @@
             </div>
         </div>
     <% } %>
+    <% if (auditStatus === 9) { %>
+        <!--撤销修订-->
+        <div class="modal fade" id="sub-revoke"  role="dialog" aria-labelledby="myModalLabel">
+            <div class="modal-dialog" role="document">
+                <form id="reviseForm" class="modal-content" method="post" action="/tender/<%- tender.id %>/change/cancel/revise" onsubmit="return false;">
+                    <div class="modal-header">
+                        <h5 class="modal-title" id="myModalLabel">撤销修订</h5>
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                            <span aria-hidden="true">&times;</span>
+                        </button>
+                    </div>
+                    <div class="modal-body">
+                        <h5>撤销修订,所有修改的数据将全部会被还原。</h5>
+                        <h5>确认撤销修订?</h5>
+                    </div>
+                    <div class="modal-footer">
+                        <input type="hidden" name="cid" value="<%= change.cid %>">
+                        <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                        <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                        <button type="button" id="cancel-revise-btn" class="btn btn-primary btn-sm">确认</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+    <% } %>
 <% } %>
 
 <% if (auditStatus === 3 || auditStatus === 4 || auditStatus === 5 || auditStatus === 7 || auditStatus === 8) { %>
@@ -1260,4 +1285,23 @@
             }
         });
     })
+
+    $('#cancel-revise-btn').click(function () {
+        const data = {
+            cid: '<%- change.cid %>',
+        };
+        $.ajax({
+            url: '/tender/<%- tender.id %>/change/cancel/revise?_csrf_j=' + csrf,
+            type: 'post',
+            data: data,
+            dataTye: 'json',
+            success: function(response) {
+                if (response.err === 0) {
+                    window.location.href = response.url;
+                } else {
+                    toast(response.msg, 'error');
+                }
+            }
+        });
+    })
 </script>

+ 9 - 0
sql/update.sql

@@ -68,3 +68,12 @@ CREATE TABLE `zh_sub_project_info` (
 
 -- 更新所有已勾选计量不计价项目的负批复变更数量值清单为不计价
 UPDATE `calculation`.zh_change_audit_list SET `is_valuation` = 0 WHERE `id` IN (SELECT id FROM (SELECT a.id FROM `calculation`.zh_change_audit_list as a LEFT JOIN `calculation`.`zh_tender` as t ON a.tid = t.id LEFT JOIN `calculation`.`zh_project` as p ON p.id = t.project_id LEFT JOIN `calculation`.`zh_change` as c ON c.cid = a.cid WHERE c.`status` = 3 AND a.`spamount` < 0 AND p.fun_rela != '' AND p.fun_rela IS NOT NULL AND JSON_CONTAINS(p.fun_rela, JSON_OBJECT('minusNoValue', true))) as aa)
+
+CREATE TABLE `calculation`.`zh_change_history`  (
+  `id` int NOT NULL AUTO_INCREMENT,
+  `tid` int NOT NULL COMMENT '标段id',
+  `cid` varchar(255) NOT NULL COMMENT '变更令id',
+  `info_json` json NULL COMMENT '内容json值',
+  `list_json` json NULL COMMENT '清单json值',
+  PRIMARY KEY (`id`)
+) COMMENT = '变更令内容临时保存表,用于修订撤销';