Browse Source

所属项目相关

MaiXinRong 1 year ago
parent
commit
2297070df3

+ 6 - 0
app/controller/tender_controller.js

@@ -57,6 +57,7 @@ module.exports = app => {
                 }
                 }
                 const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
                 const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
                 const valuations = await this.ctx.service.valuation.getProjectValidValuation(this.ctx.session.sessionProject.id);
                 const valuations = await this.ctx.service.valuation.getProjectValidValuation(this.ctx.session.sessionProject.id);
+                const subProject = await this.ctx.service.subProject.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin, true);
                 const renderData = {
                 const renderData = {
                     tenderList,
                     tenderList,
                     tenderConst,
                     tenderConst,
@@ -70,6 +71,7 @@ module.exports = app => {
                     uid: this.ctx.session.sessionUser.accountId,
                     uid: this.ctx.session.sessionUser.accountId,
                     pid: this.ctx.session.sessionProject.id,
                     pid: this.ctx.session.sessionProject.id,
                     colSet: this.colSet,
                     colSet: this.colSet,
+                    subProject,
                 };
                 };
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.is_finish = false;
                 renderData.is_finish = false;
@@ -92,6 +94,7 @@ module.exports = app => {
                 }
                 }
                 const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
                 const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
                 const valuations = await this.ctx.service.valuation.getProjectValidValuation(this.ctx.session.sessionProject.id);
                 const valuations = await this.ctx.service.valuation.getProjectValidValuation(this.ctx.session.sessionProject.id);
+                const subProject = await this.ctx.service.subProject.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin, true);
                 const renderData = {
                 const renderData = {
                     tenderList,
                     tenderList,
                     tenderConst,
                     tenderConst,
@@ -105,6 +108,7 @@ module.exports = app => {
                     uid: this.ctx.session.sessionUser.accountId,
                     uid: this.ctx.session.sessionUser.accountId,
                     pid: this.ctx.session.sessionProject.id,
                     pid: this.ctx.session.sessionProject.id,
                     colSet: this.colSet,
                     colSet: this.colSet,
+                    subProject,
                 };
                 };
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.is_finish = true;
                 renderData.is_finish = true;
@@ -135,6 +139,7 @@ module.exports = app => {
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.is_finish = false;
                 renderData.is_finish = false;
                 renderData.colSet = this.colSet;
                 renderData.colSet = this.colSet;
+                renderData.subProject = await this.ctx.service.subProject.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin, true);
                 await this.layout(view, renderData, modal);
                 await this.layout(view, renderData, modal);
             } catch (err) {
             } catch (err) {
                 this.log(err);
                 this.log(err);
@@ -162,6 +167,7 @@ module.exports = app => {
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.selfCategoryLevel = await this.ctx.service.projectAccount.getSelfCategoryLevel(this.ctx.session.sessionUser.accountId);
                 renderData.is_finish = true;
                 renderData.is_finish = true;
                 renderData.colSet = this.colSet;
                 renderData.colSet = this.colSet;
+                renderData.subProject = await this.ctx.service.subProject.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin, true);
                 await this.layout(view, renderData, modal);
                 await this.layout(view, renderData, modal);
             } catch (err) {
             } catch (err) {
                 this.log(err);
                 this.log(err);

+ 19 - 4
app/public/js/settle_select.js

@@ -30,16 +30,31 @@ $(document).ready(() => {
         calcFields: ['total_price', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'],
         calcFields: ['total_price', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'],
         calcFun: function(node) {
         calcFun: function(node) {
             if (!node.children || node.children.length === 0) {
             if (!node.children || node.children.length === 0) {
-                node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
+                node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
+                node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
+                node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
+                node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
+                node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
+                node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
+                node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
+                node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
+                node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
+                node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
+            }
+            node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
+            node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
+            node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
+            if (!node.children || node.children.length === 0) {
                 if (node.end_contract_qty) {
                 if (node.end_contract_qty) {
                     node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
                     node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
                 } else {
                 } else {
                     node.end_correct_tp = node.end_gather_tp;
                     node.end_correct_tp = node.end_gather_tp;
                 }
                 }
             }
             }
-            node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
             node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
             node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
             node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
             node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
+            node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
+            node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
         }
         }
     };
     };
     const settleTree = createNewPathTree('stage', settleTreeSetting);
     const settleTree = createNewPathTree('stage', settleTreeSetting);
@@ -178,8 +193,8 @@ $(document).ready(() => {
                     node.settle_status = status.length === 1 ? status[0] : 1;
                     node.settle_status = status.length === 1 ? status[0] : 1;
                 } else {
                 } else {
                     node.undoneDeal = node.end_contract_qty
                     node.undoneDeal = node.end_contract_qty
-                        ? !checkZero(ZhCalc.sub(node.end_contract_qty, node.quantity))
-                        : !checkZero(ZhCalc.sub(node.end_contract_tp, node.total_price));
+                        ? !checkZero(ZhCalc.sub(node.end_contract_qty, node.final_1_qty))
+                        : !checkZero(ZhCalc.sub(node.end_contract_tp, node.final_1_tp));
                     node.undone = !!node.undoneDeal || !!node.undoneChange;
                     node.undone = !!node.undoneDeal || !!node.undoneChange;
                 }
                 }
             }
             }

+ 3 - 0
app/public/js/tender_list_base.js

@@ -327,6 +327,7 @@ function bindTenderUrl() {
         const tid = parseInt($(this).parent().attr('tid'));
         const tid = parseInt($(this).parent().attr('tid'));
         const tender = _.find(tenders, {id: tid});
         const tender = _.find(tenders, {id: tid});
         $('[name=name]', '#edit-bd').val(tender.name);
         $('[name=name]', '#edit-bd').val(tender.name);
+        $('[name=spid]', '#edit-bd').val(tender.spid);
         $('input[type=radio]', '#add-bd').prop('checked', false);
         $('input[type=radio]', '#add-bd').prop('checked', false);
         $('option[value=0]', '#edit-bd').prop('selected', true);
         $('option[value=0]', '#edit-bd').prop('selected', true);
         for (const c of tender.category) {
         for (const c of tender.category) {
@@ -442,6 +443,7 @@ $(document).ready(() => {
             name: cleanSymbols($('[name=name]', '#add-bd').val()),
             name: cleanSymbols($('[name=name]', '#add-bd').val()),
             valuation: $('[name=valuation]:checked').val(),
             valuation: $('[name=valuation]:checked').val(),
             category: [],
             category: [],
+            spid: $('[name=spid]', '#add-bd').val()
         };
         };
         if (!data.name || data.name === '') {
         if (!data.name || data.name === '') {
             // TODO 提示用户
             // TODO 提示用户
@@ -477,6 +479,7 @@ $(document).ready(() => {
             id: parseInt($(this).attr('tid')),
             id: parseInt($(this).attr('tid')),
             name: cleanSymbols($('[name=name]', '#edit-bd').val()),
             name: cleanSymbols($('[name=name]', '#edit-bd').val()),
             category: [],
             category: [],
+            spid: $('[name=spid]', '#edit-bd').val(),
         };
         };
         if (!data.name || data.name === '') {
         if (!data.name || data.name === '') {
             // TODO 提示用户
             // TODO 提示用户

+ 33 - 2
app/service/sub_project.js

@@ -24,13 +24,13 @@ module.exports = app => {
             this.tableName = 'sub_project';
             this.tableName = 'sub_project';
         }
         }
 
 
-        async getSubProject(pid, uid, admin) {
+        async getSubProject(pid, uid, admin, filterFolder = false) {
             let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
             let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
             if (admin) return result;
             if (admin) return result;
 
 
             const permission = await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
             const permission = await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
             result = result.filter(x => {
             result = result.filter(x => {
-                if (x.is_folder) return true;
+                if (x.is_folder) return !filterFolder;
                 const pb = permission.find(y => { return x.id === y.spid});
                 const pb = permission.find(y => { return x.id === y.spid});
                 if (!pb) return false;
                 if (!pb) return false;
                 x.user_permission = pb;
                 x.user_permission = pb;
@@ -349,10 +349,16 @@ module.exports = app => {
 
 
         async setRelaTender(data) {
         async setRelaTender(data) {
             const subProject = await this.getDataById(data.id);
             const subProject = await this.getDataById(data.id);
+            const orgRelaTenderId = subProject.rela_tender.split(',');
             const conn = await this.db.beginTransaction();
             const conn = await this.db.beginTransaction();
             try {
             try {
                 await conn.update(this.tableName, data);
                 await conn.update(this.tableName, data);
                 await conn.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender: data.rela_tender });
                 await conn.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender: data.rela_tender });
+                const relaTenderId = data.rela_tender.split(',');
+                const removeTenderId = orgRelaTenderId.filter(x => { return relaTenderId.indexOf(x) < 0});
+                const addTenderId = relaTenderId.filter(x => { return orgRelaTenderId.indexOf(x) < 0});
+                if (removeTenderId.length > 0) await conn.update(this.ctx.service.tender.tableName, { id: removeTenderId, spid: '' });
+                if (removeTenderId.length > 0) await conn.update(this.ctx.service.tender.tableName, { id: addTenderId, spid: data.id });
                 await conn.commit();
                 await conn.commit();
                 return data;
                 return data;
             } catch (error) {
             } catch (error) {
@@ -362,6 +368,31 @@ module.exports = app => {
 
 
         }
         }
 
 
+        async addRelaTender(transaction, spid, tid) {
+            if (!transaction) throw '未定义事务';
+
+            const subProject = await this.getDataById(spid);
+            const rela = subProject.rela_tender.split(',');
+            if (rela.indexOf(tid + '') >= 0) return;
+
+            rela.push(tid + '');
+            const rela_tender = rela.join(',');
+            await transaction.update(this.tableName, { id: spid, rela_tender});
+            await transaction.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender});
+        }
+
+        async removeRelaTender(transaction, spid, tid) {
+            if (!transaction) throw '未定义事务';
+
+            const subProject = await this.getDataById(spid);
+            const rela = subProject.rela_tender.split(',');
+            if (rela.indexOf(tid + '') < 0) return;
+
+            const rela_tender = rela.filter(x => { return x === tid + ''}).join(',');
+            await transaction.update(this.tableName, { id: spid, rela_tender});
+            await transaction.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender});
+        }
+
         async setManagement(data) {
         async setManagement(data) {
             const subProject = await this.getDataById(data.id);
             const subProject = await this.getDataById(data.id);
             if (subProject.management === data.management) return data;
             if (subProject.management === data.management) return data;

+ 20 - 5
app/service/tender.js

@@ -16,7 +16,7 @@ const path = require('path');
 const commonQueryColumns = [
 const commonQueryColumns = [
     'id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id', 'valuation', 'create_time',
     'id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id', 'valuation', 'create_time',
     'total_price', 'deal_tp', 'copy_id', 's2b_gxby_check', 's2b_gxby_limit', 's2b_dagl_check', 's2b_dagl_limit', 'has_rela', 'his_id', 'rpt_show_level',
     'total_price', 'deal_tp', 'copy_id', 's2b_gxby_check', 's2b_gxby_limit', 's2b_dagl_check', 's2b_dagl_limit', 'has_rela', 'his_id', 'rpt_show_level',
-    'build_status', 'settle_order',
+    'build_status', 'settle_order', 'spid',
 ];
 ];
 
 
 module.exports = app => {
 module.exports = app => {
@@ -92,7 +92,7 @@ module.exports = app => {
             let sqlParam = [];
             let sqlParam = [];
             if (listStatus === 'manage') {
             if (listStatus === 'manage') {
                 // 管理页面只取属于自己创建的标段
                 // 管理页面只取属于自己创建的标段
-                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, t.`total_price`, t.`deal_tp`,' +
+                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, t.`total_price`, t.`deal_tp`, t.`spid`,' +
                     '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
                     '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
                     '  FROM ?? As t ' +
                     '  FROM ?? As t ' +
                     '  Left Join ?? As pa ' +
                     '  Left Join ?? As pa ' +
@@ -101,7 +101,7 @@ module.exports = app => {
                 sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId];
                 sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId];
             } else if (getAll === 1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) {
             } else if (getAll === 1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) {
                 // 具有查看所有标段权限的用户查阅标段
                 // 具有查看所有标段权限的用户查阅标段
-                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, t.`total_price`, t.`deal_tp`,' +
+                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, t.`total_price`, t.`deal_tp`, t.`spid`,' +
                     '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
                     '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
                     '  FROM ?? As t ' +
                     '  FROM ?? As t ' +
                     '  Left Join ?? As pa ' +
                     '  Left Join ?? As pa ' +
@@ -271,6 +271,7 @@ module.exports = app => {
                     create_time: new Date(),
                     create_time: new Date(),
                     category: JSON.stringify(data.category),
                     category: JSON.stringify(data.category),
                     valuation: data.valuation,
                     valuation: data.valuation,
+                    spid: data.spid,
                 };
                 };
                 const operate = await this.transaction.insert(this.tableName, insertData);
                 const operate = await this.transaction.insert(this.tableName, insertData);
 
 
@@ -279,6 +280,7 @@ module.exports = app => {
                     throw '新增标段数据失败';
                     throw '新增标段数据失败';
                 }
                 }
                 await this.ctx.service.tenderCache.insertTenderCache(this.transaction, operate.insertId, sessionUser.accountId);
                 await this.ctx.service.tenderCache.insertTenderCache(this.transaction, operate.insertId, sessionUser.accountId);
+                if (data.spid) await ctx.service.subProject.addRelaTender(this.transaction, data.spid, operate.insertId);
 
 
 
 
                 // 获取合同支付模板 并添加到标段
                 // 获取合同支付模板 并添加到标段
@@ -320,6 +322,7 @@ module.exports = app => {
          */
          */
         async save(postData, id = 0) {
         async save(postData, id = 0) {
             id = parseInt(id);
             id = parseInt(id);
+            const tender = await this.getDataById(id);
 
 
             const rowData = {
             const rowData = {
                 id,
                 id,
@@ -327,8 +330,20 @@ module.exports = app => {
                 type: postData.type,
                 type: postData.type,
                 category: JSON.stringify(postData.category),
                 category: JSON.stringify(postData.category),
             };
             };
-            const result = await this.db.update(this.tableName, rowData);
-            return result.affectedRows > 0;
+            const conn = await this.db.beginTransaction();
+            try {
+                if (tender.spid !== postData.spid) {
+                    if (postData.spid) await this.ctx.service.subProject.addRelaTender(conn, postData.spid, id);
+                    if (tender.spid) await this.ctx.service.subProject.removeRelaTender(conn, postData.spid, id);
+                }
+                rowData.spid = postData.spid || '';
+                const result = await conn.update(this.tableName, rowData);
+                await conn.commit();
+                return result.affectedRows > 0;
+            } catch(err) {
+                await conn.rollback();
+                throw err;
+            }
         }
         }
 
 
         /**
         /**

+ 16 - 0
app/view/tender/manage_modal.ejs

@@ -11,6 +11,15 @@
                     <input class="form-control form-control-sm"  placeholder="输入标段名称" type="text" name="name">
                     <input class="form-control form-control-sm"  placeholder="输入标段名称" type="text" name="name">
                 </div>
                 </div>
                 <div class="form-group">
                 <div class="form-group">
+                    <label>所属项目</label>
+                    <select class="form-control form-control-sm" name="spid">
+                        <option value="">无</option>
+                        <% for (const sp of subProject) { %>
+                        <option name="<%- sp.id %>"><%- sp.name %></option>
+                        <% } %>
+                    </select>
+                </div>
+                <div class="form-group">
                     <style>
                     <style>
                         .tooltip-inner {
                         .tooltip-inner {
                             max-width: initial;
                             max-width: initial;
@@ -46,6 +55,13 @@
                     <label>标段名称<b class="text-danger">*</b></label>
                     <label>标段名称<b class="text-danger">*</b></label>
                     <input class="form-control form-control-sm"  placeholder="输入标段名称" type="text" name="name">
                     <input class="form-control form-control-sm"  placeholder="输入标段名称" type="text" name="name">
                 </div>
                 </div>
+                <label>所属项目</label>
+                <select class="form-control form-control-sm" name="spid">
+                    <option value="">无</option>
+                    <% for (const sp of subProject) { %>
+                    <option value="<%- sp.id %>"><%- sp.name %></option>
+                    <% } %>
+                </select>
             </div>
             </div>
             <div class="modal-footer">
             <div class="modal-footer">
                 <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
                 <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>

+ 9 - 0
app/view/tender/modal.ejs

@@ -11,6 +11,15 @@
                     <input class="form-control form-control-sm"  placeholder="输入标段名称" type="text" name="name">
                     <input class="form-control form-control-sm"  placeholder="输入标段名称" type="text" name="name">
                 </div>
                 </div>
                 <div class="form-group">
                 <div class="form-group">
+                    <label>所属项目</label>
+                    <select class="form-control form-control-sm" name="spid">
+                        <option value="">无</option>
+                        <% for (const sp of subProject) { %>
+                        <option value="<%- sp.id %>"><%- sp.name %></option>
+                        <% } %>
+                    </select>
+                </div>
+                <div class="form-group">
                     <style>
                     <style>
                         .tooltip-inner {
                         .tooltip-inner {
                             max-width: initial;
                             max-width: initial;

+ 41 - 0
db_script/belong_spid.js

@@ -0,0 +1,41 @@
+const BaseUtil = require('./baseUtils');
+const querySql = BaseUtil.querySql;
+
+const checkProject = async function(project) {
+    const subProject = await querySql('SELECT * From zh_sub_project where project_id = ?', [project.id]);
+    if (subProject.length === 0) return;
+
+    const updateData = [];
+    subProject.forEach(x => {
+        if (!x.rela_tender) return;
+
+        const relaTenderId = x.rela_tender.split(',');
+        relaTenderId.forEach(r => { updateData.push({ id: r, spid: x.id }); });
+    });
+    if (updateData.length === 0) return;
+    for (const ud of updateData) {
+        await querySql('UPDATE zh_tender SET spid = ? WHERE id = ?', [ud.spid, ud.id]);
+    }
+};
+
+const doComplete = async function(project_id) {
+    try {
+        const project = project_id
+            ? await querySql('Select * From zh_project where id = ?', [project_id])
+            : await querySql('Select * From zh_project');
+        for (const p of project) {
+            console.log(`Update Project ${p.code}(${p.id}):`);
+            await checkProject(p);
+        }
+    } catch (err) {
+        console.log(err);
+    }
+    BaseUtil.closePool();
+};
+
+const projectId = process.argv[3];
+if (projectId) {
+    doComplete(projectId);
+} else {
+    doComplete()
+}

+ 3 - 0
sql/update.sql

@@ -54,3 +54,6 @@ ADD COLUMN `final_auditor_str` varchar(50) NOT NULL DEFAULT '' COMMENT '终审
 ALTER TABLE `zh_project_account`
 ALTER TABLE `zh_project_account`
 ADD COLUMN `dsk_account` json NULL COMMENT '大司空账号信息' AFTER `notice_again`,
 ADD COLUMN `dsk_account` json NULL COMMENT '大司空账号信息' AFTER `notice_again`,
 ADD COLUMN `dsk_projects` json NULL COMMENT '大司空项目信息' AFTER `dsk_account`;
 ADD COLUMN `dsk_projects` json NULL COMMENT '大司空项目信息' AFTER `dsk_account`;
+
+ALTER TABLE `zh_tender`
+ADD COLUMN `spid` varchar(36) NOT NULL DEFAULT '' COMMENT 'zh_sub_project.id' AFTER `s_type`;