|
@@ -0,0 +1,134 @@
|
|
|
+/**
|
|
|
+ * Created by Tony on 2021/3/30.
|
|
|
+ */
|
|
|
+
|
|
|
+const BaseService = require('../base/base_service');
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+
|
|
|
+ class RptArchive extends BaseService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ this.tableName = 'rpt_archive';
|
|
|
+ this.dataId = 'archive_id';
|
|
|
+ }
|
|
|
+
|
|
|
+ async getArchiveById(id) {
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('archive_id', {
|
|
|
+ value: id,
|
|
|
+ operate: '=',
|
|
|
+ });
|
|
|
+ this.sqlBuilder.columns = ['archive_id', 'prj_id', 'stage_id', 'content'];
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
|
|
|
+ const list = await this.db.query(sql, sqlParam);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getPrjStgArchive(prjId, stgId) {
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('prj_id', {
|
|
|
+ value: prjId,
|
|
|
+ operate: '=',
|
|
|
+ });
|
|
|
+ this.sqlBuilder.setAndWhere('stage_id', {
|
|
|
+ value: stgId,
|
|
|
+ operate: '=',
|
|
|
+ });
|
|
|
+ this.sqlBuilder.columns = ['archive_id', 'prj_id', 'stage_id', 'content'];
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
|
|
|
+ const list = await this.db.query(sql, sqlParam);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ async createArchive(prj_id, stg_id, archiveArr) {
|
|
|
+ let rst = null;
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const data = {
|
|
|
+ prj_id,
|
|
|
+ stg_id,
|
|
|
+ content: JSON.stringify(archiveArr),
|
|
|
+ };
|
|
|
+ // console.log(data);
|
|
|
+ rst = await this.transaction.insert(this.tableName, data);
|
|
|
+ await this.transaction.commit();
|
|
|
+ } catch (ex) {
|
|
|
+ console.log(ex);
|
|
|
+ // 回滚
|
|
|
+ await this.transaction.rollback();
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ }
|
|
|
+ //
|
|
|
+ // async addInitialStageData(tender_id, stage, preStage) {
|
|
|
+ // // 在加stage的时候需要挂上这个,copy之前的签名人
|
|
|
+ // const rst = [];
|
|
|
+ // const preRoleRelList = await this.getRoleRptRelByTenderId(tender_id, preStage.id);
|
|
|
+ // for (const rptRoleRel of preRoleRelList) {
|
|
|
+ // const relList = JSON.parse(rptRoleRel.rel_content);
|
|
|
+ // // const newRptRoleRel = {tender_id: tender_id, rpt_id: rptRoleRel.rpt_id, sid: stage.id, rel_content: ''};
|
|
|
+ // const newRelList = [];
|
|
|
+ // for (const role of relList) {
|
|
|
+ // const newRole = {};
|
|
|
+ // newRelList.push(newRole);
|
|
|
+ // for (const key in role) {
|
|
|
+ // if (key !== 'sign_date') {
|
|
|
+ // newRole[key] = role[key];
|
|
|
+ // } else {
|
|
|
+ // newRole[key] = '';
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // rst.push(await this.createRoleRelationship(tender_id, rptRoleRel.rpt_id, stage.id, newRelList));
|
|
|
+ // await this.createRoleRelationship(tender_id, rptRoleRel.rpt_id, stage.id, newRelList); // 暂时用不到,就先不返回结果
|
|
|
+ // }
|
|
|
+ // return rst;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // async updateRoleRelationship(id, tender_id, rpt_id, sid, relArr) {
|
|
|
+ // let rst = null;
|
|
|
+ // if (id < 0) {
|
|
|
+ // rst = await this.createRoleRelationship(tender_id, rpt_id, sid, relArr);
|
|
|
+ // } else {
|
|
|
+ // this.transaction = await this.db.beginTransaction();
|
|
|
+ // try {
|
|
|
+ // const data = { id, tender_id, rpt_id, sid, rel_content: JSON.stringify(relArr) };
|
|
|
+ // rst = await this.transaction.update(this.tableName, data);
|
|
|
+ // await this.transaction.commit();
|
|
|
+ // } catch (ex) {
|
|
|
+ // console.log(ex);
|
|
|
+ // // 回滚
|
|
|
+ // await this.transaction.rollback();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return rst;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // async updateMultiRoleRelationship(orgParams, newRelArr) {
|
|
|
+ // for (let idx = 0; idx < orgParams.length; idx++) {
|
|
|
+ // const param = orgParams[idx];
|
|
|
+ // const data = { tender_id: param[0], sid: param[1], rpt_id: param[2] };
|
|
|
+ // this.transaction = await this.db.beginTransaction();
|
|
|
+ // try {
|
|
|
+ // await this.transaction.delete(this.tableName, data);
|
|
|
+ // this.transaction.commit();
|
|
|
+ // await this.createRoleRelationship(param[0], param[2], param[1], newRelArr);
|
|
|
+ // } catch (ex) {
|
|
|
+ // console.log(ex.toString());
|
|
|
+ // // 回滚
|
|
|
+ // await this.transaction.rollback();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ return RptArchive;
|
|
|
+};
|