|
@@ -10,6 +10,8 @@
|
|
|
|
|
|
const tenderConst = require('../const/tender');
|
|
|
const auditConst = require('../const/audit');
|
|
|
+const fs = require('fs');
|
|
|
+const path = require('path');
|
|
|
const commonQueryColumns = ['id', 'project_id', 'name', 'status', 'category', 'ledger_times', 'ledger_status', 'measure_type', 'user_id'];
|
|
|
|
|
|
module.exports = app => {
|
|
@@ -75,38 +77,50 @@ module.exports = app => {
|
|
|
*
|
|
|
* @return {Array} - 返回标段数据
|
|
|
*/
|
|
|
- async getList() {
|
|
|
+ async getList(listStatus) {
|
|
|
// 获取当前项目信息
|
|
|
const session = this.ctx.session;
|
|
|
- // tender 163条数据,project_account 68条数据测试
|
|
|
- // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
|
|
|
- const 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`, '+
|
|
|
- ' pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
|
|
|
- // ' FROM ?? As t, ?? As pa ' +
|
|
|
- // ' WHERE t.`project_id` = ? AND t.`user_id` = pa.`id` AND (' +
|
|
|
- ' FROM ?? As t ' +
|
|
|
- ' Left Join ?? As pa ' +
|
|
|
- ' ON t.`user_id` = pa.`id` ' +
|
|
|
- ' WHERE t.`project_id` = ? AND (' +
|
|
|
- // 创建的标段
|
|
|
- ' t.`user_id` = ?' +
|
|
|
- // 参与审批 台账 的标段
|
|
|
- ' OR (t.`ledger_status` != ' + auditConst.ledger.status.uncheck + ' AND ' +
|
|
|
- ' t.id IN ( SELECT la.`tender_id` FROM ?? As la WHERE la.`audit_id` = ? GROUP BY la.`tender_id`))' +
|
|
|
- // 参与审批 计量期 的标段
|
|
|
- ' OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
|
|
|
- ' t.id IN ( SELECT sa.`tid` FROM ?? As sa WHERE sa.`aid` = ? GROUP BY sa.`tid`))' +
|
|
|
- // 参与审批 变更令 的标段
|
|
|
- ' OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
|
|
|
- ' t.id IN ( SELECT ca.`tid` FROM ?? AS ca WHERE ca.`uid` = ? GROUP BY ca.`tid`))' +
|
|
|
- // 未参与,但可见的标段
|
|
|
- ')';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId,
|
|
|
- this.ctx.service.ledgerAudit.tableName, session.sessionUser.accountId,
|
|
|
- this.ctx.service.stageAudit.tableName, session.sessionUser.accountId,
|
|
|
- this.ctx.service.changeAudit.tableName, session.sessionUser.accountId];
|
|
|
-
|
|
|
- //console.log(this.db.format(sql, sqlParam));
|
|
|
+ let sql = '';
|
|
|
+ let sqlParam = [];
|
|
|
+ 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`, ' +
|
|
|
+ ' pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
|
|
|
+ ' FROM ?? As t ' +
|
|
|
+ ' Left Join ?? As pa ' +
|
|
|
+ ' ON t.`user_id` = pa.`id` ' +
|
|
|
+ ' WHERE t.`project_id` = ? AND t.`user_id` = ?';
|
|
|
+ sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId];
|
|
|
+ } else {
|
|
|
+ // tender 163条数据,project_account 68条数据测试
|
|
|
+ // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
|
|
|
+ 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`, ' +
|
|
|
+ ' pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
|
|
|
+ // ' FROM ?? As t, ?? As pa ' +
|
|
|
+ // ' WHERE t.`project_id` = ? AND t.`user_id` = pa.`id` AND (' +
|
|
|
+ ' FROM ?? As t ' +
|
|
|
+ ' Left Join ?? As pa ' +
|
|
|
+ ' ON t.`user_id` = pa.`id` ' +
|
|
|
+ ' WHERE t.`project_id` = ? AND (' +
|
|
|
+ // 创建的标段
|
|
|
+ ' t.`user_id` = ?' +
|
|
|
+ // 参与审批 台账 的标段
|
|
|
+ ' OR (t.`ledger_status` != ' + auditConst.ledger.status.uncheck + ' AND ' +
|
|
|
+ ' t.id IN ( SELECT la.`tender_id` FROM ?? As la WHERE la.`audit_id` = ? GROUP BY la.`tender_id`))' +
|
|
|
+ // 参与审批 计量期 的标段
|
|
|
+ ' OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
|
|
|
+ ' t.id IN ( SELECT sa.`tid` FROM ?? As sa WHERE sa.`aid` = ? GROUP BY sa.`tid`))' +
|
|
|
+ // 参与审批 变更令 的标段
|
|
|
+ ' OR (t.`ledger_status` = ' + auditConst.ledger.status.checked + ' AND ' +
|
|
|
+ ' t.id IN ( SELECT ca.`tid` FROM ?? AS ca WHERE ca.`uid` = ? GROUP BY ca.`tid`))' +
|
|
|
+ // 未参与,但可见的标段
|
|
|
+ ')';
|
|
|
+ sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId,
|
|
|
+ this.ctx.service.ledgerAudit.tableName, session.sessionUser.accountId,
|
|
|
+ this.ctx.service.stageAudit.tableName, session.sessionUser.accountId,
|
|
|
+ this.ctx.service.changeAudit.tableName, session.sessionUser.accountId];
|
|
|
+ }
|
|
|
+ // console.log(this.db.format(sql, sqlParam));
|
|
|
const list = await this.db.query(sql, sqlParam);
|
|
|
for (const l of list) {
|
|
|
l.category = l.category && l.category !== '' ? JSON.parse(l.category) : null;
|
|
@@ -239,6 +253,18 @@ module.exports = app => {
|
|
|
await transaction.delete(this.ctx.service.stagePos.tableName, {tid: id});
|
|
|
await transaction.delete(this.ctx.service.stageDetail.tableName, {tid: id});
|
|
|
//await transaction.delete(this.ctx.service.stagePay.tableName, {tid: id});
|
|
|
+ await transaction.delete(this.ctx.service.change.tableName, {tid: id});
|
|
|
+ await transaction.delete(this.ctx.service.changeAudit.tableName, {tid: id});
|
|
|
+ await transaction.delete(this.ctx.service.changeAuditList.tableName, {tid: id});
|
|
|
+ await transaction.delete(this.ctx.service.changeCompany.tableName, {tid: id});
|
|
|
+ // 先删除附件文件
|
|
|
+ const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { tid: id } });
|
|
|
+ if (attList.length !== 0) {
|
|
|
+ for (const att of attList) {
|
|
|
+ await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await transaction.delete(this.ctx.service.changeAtt.tableName, {tid: id});
|
|
|
await transaction.commit();
|
|
|
return true;
|
|
|
} catch (err) {
|
|
@@ -288,4 +314,4 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
return Tender;
|
|
|
-};
|
|
|
+};
|