Browse Source

同一计价规范下,根据0号台账、工程量清单两种模式调用不一样基础数据

MaiXinRong 5 years ago
parent
commit
5a9a7628d9

+ 12 - 0
app/const/tender.js

@@ -56,6 +56,17 @@ const measureType = {
     },
 };
 
+const valuationField = function (mt) {
+    switch (mt) {
+        case measureType.tz.value:
+            return { std_bills: 'bill_id', std_xmj: 'chapter_id', template: 'template_id' };
+        case measureType.gcl.value:
+            return { std_bills: 'list_bill_id', std_xmj: 'list_chapter_id', template: 'list_template_id' };
+        default:
+            return null;
+    }
+};
+
 const imType = {
     zl: { value: 0, name: '总量控制' },
     tz: { value: 1, name: '0号台账' },
@@ -77,4 +88,5 @@ module.exports = {
     manageTableCol,
     measureType,
     imType,
+    valuationField,
 };

+ 6 - 3
app/controller/ledger_controller.js

@@ -120,7 +120,8 @@ module.exports = app => {
                         auditHistory.push(await ctx.service.ledgerAudit.getAuditors(ctx.tender.id, i));
                     }
                 }
-                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(ctx.tender.data.valuation);
+                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(
+                    ctx.tender.data.valuation, ctx.tender.data.measure_type);
                 const renderData = {
                     tender: tender.data,
                     tenderInfo: tender.info,
@@ -151,7 +152,8 @@ module.exports = app => {
 
                 await this.layout('ledger/explode.ejs', renderData, 'ledger/explode_modal.ejs');
             } catch (err) {
-                this.log(err);
+                ctx.helper.log(err);
+                this.postError(err, '标段数据错误');
                 await this.redirect('/dashboard');
             }
         }
@@ -479,7 +481,8 @@ module.exports = app => {
                 const responseData = { err: 0, msg: '', data: {}, };
                 switch (ueType) {
                     case 'tz':
-                        const templateId = await this.ctx.service.valuation.getValuationTemplate(this.ctx.tender.data.valuation);
+                        const templateId = await this.ctx.service.valuation.getValuationTemplate(
+                            this.ctx.tender.data.valuation, this.ctx.tender.data.measure_type);
                         responseData.data = await ctx.service.ledger.importExcel(templateId, data);
                         break;
                     case 'gcl2xmj':

+ 4 - 2
app/controller/revise_controller.js

@@ -72,7 +72,8 @@ module.exports = app => {
                     }
                 }
                 const addValid = await this._getAddReviseValid(ctx);
-                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(ctx.tender.data.valuation);
+                const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(
+                    ctx.tender.data.valuation, ctx.tender.data.measure_type);
                 const renderData = {
                     tender: ctx.tender.data,
                     tenderMenu: this.menu.tenderMenu,
@@ -214,7 +215,8 @@ module.exports = app => {
                 ? JSON.parse(await fs.readFileSync(this.ctx.app.config.filePath + revise.pos_file, 'utf8'))
                 : await ctx.service.revisePos.getData(ctx.tender.id);
             const [ledgerSpread, posSpread] = this._getSpreadSetting(revise);
-            const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(ctx.tender.data.valuation);
+            const [stdBills, stdChapters] = await this.ctx.service.valuation.getValuationStdList(
+                ctx.tender.data.valuation, ctx.tender.data.measure_type);
             const curAuditor = await ctx.service.reviseAudit.getCurAuditor(revise.id, revise.times);
             const auditors = await ctx.service.reviseAudit.getAuditors(revise.id, revise.times);
             const user = await ctx.service.projectAccount.getAccountInfoById(revise.uid);

+ 9 - 8
app/controller/tender_controller.js

@@ -391,11 +391,12 @@ module.exports = app => {
                     throw '标段数据错误';
                 }
                 if (!tender.measure_type) {
-                    await ctx.service.tender.update({ measure_type: type }, { id: tender.id });
+                    await ctx.service.tender.setTenderType(tender, parseInt(type));
                 }
                 ctx.redirect('/tender/' + tenderId);
             } catch (error) {
-                this.log(error);
+                ctx.helper.log(error);
+                this.postError(error, '设置标段类型错误');
                 ctx.redirect('/list');
             }
         }
@@ -438,7 +439,7 @@ module.exports = app => {
                 };
                 await this.layout('tender/cooperation.ejs', renderData, 'tender/cooperationModal.ejs');
             } catch (error) {
-                this.log(error);
+                ctx.helper.log(error);
                 this.ctx.redirect('/tender/' + tenderId);
             }
         }
@@ -459,7 +460,7 @@ module.exports = app => {
                     throw '新增标段失败';
                 }
             } catch (error) {
-                this.log(error);
+                ctx.helper.log(error);
                 this.setMessage(error.toString(), this.messageType.ERROR);
             }
 
@@ -515,7 +516,7 @@ module.exports = app => {
 
                 this.setMessage('保存标段数据成功', this.messageType.SUCCESS);
             } catch (error) {
-                this.setMessage(error.toString(), this.messageType.ERROR);
+                this.postError(error, '保存标段数据失败');
             }
             ctx.redirect(ctx.request.header.referer);
         }
@@ -542,7 +543,7 @@ module.exports = app => {
 
                 this.setMessage('删除标段成功', this.messageType.SUCCESS);
             } catch (error) {
-                this.setMessage(error.toString(), this.messageType.ERROR);
+                this.postError(error, '删除标段失败');
             }
 
             ctx.redirect(ctx.request.header.referer);
@@ -579,7 +580,7 @@ module.exports = app => {
                     throw '更新规则失败';
                 }
             } catch (err) {
-                this.log(err);
+                ctx.helper.log(err);
                 responseData.err = 1;
                 responseData.msg = err.toString();
             }
@@ -608,7 +609,7 @@ module.exports = app => {
                     throw '更新规则失败';
                 }
             } catch (err) {
-                this.log(err);
+                ctx.helper.log(err);
                 responseData.err = 1;
                 responseData.msg = err.toString();
             }

+ 22 - 8
app/service/tender.js

@@ -162,7 +162,6 @@ module.exports = app => {
          */
         async add(data) {
             let result = false;
-            const templateId = await this.ctx.service.valuation.getValuationTemplate(data.valuation);
             this.transaction = await this.db.beginTransaction();
             try {
                 // 获取当前用户信息
@@ -186,13 +185,6 @@ module.exports = app => {
                     throw '新增标段数据失败';
                 }
 
-                // 获取标段项目节点模板
-                const tenderNodeTemplateData = await this.ctx.service.tenderNodeTemplate.getData(templateId);
-                // 复制模板数据到标段数据表
-                result = await this.ctx.service.ledger.innerAdd(tenderNodeTemplateData, operate.insertId, this.transaction);
-                if (!result) {
-                    throw '新增标段项目节点失败';
-                }
 
                 // 获取合同支付模板 并添加到标段
                 result = await this.ctx.service.pay.addDefaultPayData(operate.insertId, this.transaction);
@@ -341,6 +333,28 @@ module.exports = app => {
             this.ctx.tender = tender;
         }
 
+        async setTenderType(tender, type) {
+            const templateId = await this.ctx.service.valuation.getValuationTemplate(tender.valuation, type);
+            if (templateId === -1) throw '该模式下,台账模板不存在';
+
+            // 获取标段项目节点模板
+            const tenderNodeTemplateData = await this.ctx.service.tenderNodeTemplate.getData(templateId);
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.update(this.tableName, {id: tender.id, measure_type: type});
+
+                // 复制模板数据到标段数据表
+                const result = await this.ctx.service.ledger.innerAdd(tenderNodeTemplateData, tender.id, conn);
+                if (!result) {
+                    throw '初始化台账失败';
+                }
+                await conn.commit();
+            } catch (err) {
+                await conn.rollback();
+                throw err;
+            }
+        }
+
     }
 
     return Tender;

+ 17 - 5
app/service/valuation.js

@@ -8,6 +8,8 @@
  * @version
  */
 
+const tenderConst = require('../const/tender');
+
 module.exports = app => {
 
     class Valuation extends app.BaseService {
@@ -32,15 +34,25 @@ module.exports = app => {
             });
         }
 
-        async getValuationTemplate(id) {
+        async getValuationTemplate(id, measureType) {
+            const valuationField = tenderConst.valuationField(measureType);
+            if (!valuationField) return -1;
+
             const valuation = await this.getDataById(id);
-            return parseInt(valuation.template_id);
+            return parseInt(valuation[valuationField.template]);
         }
 
-        async getValuationStdList(id) {
+        async getValuationStdList(id, measureType) {
+            const valuationField = tenderConst.valuationField(measureType);
+            if (!valuationField) return [[], []];
+
             const valuation = await this.getDataById(id);
-            const billsId = this._.map(valuation.bill_id.split(','), this._.toInteger);
-            const chaptersId = this._.map(valuation.chapter_id.split(','), this._.toInteger);
+            const billsId = valuation[valuationField.std_bills]
+                ? this._.map(valuation[valuationField.std_bills].split(','), this._.toInteger)
+                : [-1];
+            const chaptersId = valuation[valuationField.std_xmj]
+                ? this._.map(valuation[valuationField.std_xmj].split(','), this._.toInteger)
+                : [-1];
             const sql = 'SELECT `id`, `name`' +
                 '  From ?? ' +
                 '  WHERE `id` in ( ? ) ORDER BY FIELD(`id`, ?)';