|
@@ -111,6 +111,40 @@ module.exports = app => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async _insertDatas(data, result) {
|
|
|
+ const select = await this.getDataById(data.select);
|
|
|
+ if (!select) throw '选中的甲供材料不存在';
|
|
|
+
|
|
|
+ const insertData = [];
|
|
|
+ for (let i = 0; i < data.count; i++) {
|
|
|
+ insertData.push({
|
|
|
+ uuid: this.uuid.v4(),
|
|
|
+ add_sid: this.ctx.stage.id,
|
|
|
+ add_uid: this.ctx.session.sessionUser.accountId,
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ sid: this.ctx.stage.id,
|
|
|
+ name: '',
|
|
|
+ order: select.order + i,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await transaction.query('Update ?? SET `order` = `order` + ? WHERE sid = ? and `order` >= ?', [this.tableName, data.count, this.ctx.stage.id, select.order]);
|
|
|
+ await transaction.insert(this.tableName, insertData);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ this.ctx.log(err);
|
|
|
+ await transaction.rollback();
|
|
|
+ throw '插入甲供材料错误';
|
|
|
+ }
|
|
|
+
|
|
|
+ result.add = await this.getAllDataByCondition({
|
|
|
+ where: { sid: this.ctx.stage.id, uuid: this.ctx.helper._.map(insertData, 'uuid') }
|
|
|
+ });
|
|
|
+ result.update = await this.db.query('SELECT * FROM ?? where sid = ? and `order` >= ?', [this.tableName, this.ctx.stage.id, select.order + data.count]);
|
|
|
+ }
|
|
|
+
|
|
|
async _delDatas (data) {
|
|
|
const datas = data instanceof Array ? data : [data];
|
|
|
const orgDatas = await this.getAllDataByCondition({where: {sid: this.ctx.stage.id, id: this.ctx.helper._.map(datas, 'id')} });
|
|
@@ -187,6 +221,7 @@ module.exports = app => {
|
|
|
if (data.del) {
|
|
|
result.del = await this._delDatas(data.del);
|
|
|
}
|
|
|
+ if (data.insert) await this._insertDatas(data.insert, result);
|
|
|
return result;
|
|
|
} catch (err) {
|
|
|
if (err) result.err = err;
|