|
@@ -334,6 +334,7 @@ module.exports = app => {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
const list = [];
|
|
|
+ const listGcl = [];
|
|
|
// const delList = [];
|
|
|
// const mb_idList = [];
|
|
|
for (const xmj of datas.xmjs) {
|
|
@@ -363,15 +364,30 @@ module.exports = app => {
|
|
|
is_join: xmj.is_join,
|
|
|
};
|
|
|
list.push(newLists);
|
|
|
+ if (this._.findIndex(listGcl, { gcl_id: xmj.gcl_id }) === -1) {
|
|
|
+ const newListGcl = {
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ order: this.ctx.material.order,
|
|
|
+ mid: this.ctx.material.id,
|
|
|
+ mb_id: mb,
|
|
|
+ gcl_id: xmj.gcl_id,
|
|
|
+ quantity: 0,
|
|
|
+ expr: '',
|
|
|
+ };
|
|
|
+ listGcl.push(newListGcl);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ // 维护list_gcl表
|
|
|
+
|
|
|
|
|
|
// 删除工料清单关联
|
|
|
// if (delList.length > 0) await transaction.delete(this.tableName, { id: delList });
|
|
|
// 新增工料清单关联
|
|
|
if (list.length > 0) {
|
|
|
const result = await transaction.insert(this.tableName, list);
|
|
|
- if (result.affectedRows === 0) {
|
|
|
+ const result2 = await transaction.insert(this.ctx.service.materialListGcl.tableName, listGcl);
|
|
|
+ if (result.affectedRows === 0 || result2.affectedRows === 0) {
|
|
|
throw '新增工料数据失败';
|
|
|
}
|
|
|
}
|
|
@@ -405,8 +421,13 @@ module.exports = app => {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 判断是否可删
|
|
|
+ const listGcl = [];
|
|
|
for (const xmj of datas.xmjs) {
|
|
|
await transaction.delete(this.tableName, { tid: this.ctx.tender.id, mid: this.ctx.material.id, mb_id: datas.mb_id, gcl_id: xmj.gcl_id, xmj_id: xmj.xmj_id, mx_id: xmj.mx_id });
|
|
|
+ if (this._.indexOf(listGcl, xmj.gcl_id) === -1) {
|
|
|
+ await transaction.delete(this.service.materialListGcl.tableName, { tid: this.ctx.tender.id, mid: this.ctx.material.id, mb_id: datas.mb_id, gcl_id: xmj.gcl_id });
|
|
|
+ listGcl.push(xmj.gcl_id);
|
|
|
+ }
|
|
|
}
|
|
|
// await transaction.delete(this.tableName, { id });
|
|
|
await this.calcQuantityByML(transaction, datas.mb_id);
|
|
@@ -437,6 +458,8 @@ module.exports = app => {
|
|
|
try {
|
|
|
const mb_id = datas.mb_id;
|
|
|
const updateDatas = [];
|
|
|
+ const updateListGcl = [];
|
|
|
+ const listGcl = [];
|
|
|
for (const xmj of datas.xmjs) {
|
|
|
const udata = {
|
|
|
row: {
|
|
@@ -453,8 +476,24 @@ module.exports = app => {
|
|
|
},
|
|
|
};
|
|
|
updateDatas.push(udata);
|
|
|
+ if (this._.indexOf(listGcl, xmj.gcl_id) === -1) {
|
|
|
+ listGcl.push(xmj.gcl_id);
|
|
|
+ updateListGcl.push({
|
|
|
+ row: {
|
|
|
+ expr: datas.expr,
|
|
|
+ quantity: datas.quantity,
|
|
|
+ },
|
|
|
+ where: {
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ mid: this.ctx.material.id,
|
|
|
+ mb_id,
|
|
|
+ gcl_id: xmj.gcl_id,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
if (updateDatas.length > 0) await transaction.updateRows(this.tableName, updateDatas);
|
|
|
+ if (updateListGcl.length > 0) await transaction.updateRows(this.service.materialListGcl.tableName, updateListGcl);
|
|
|
await this.calcQuantityByML(transaction, mb_id);
|
|
|
await transaction.commit();
|
|
|
return await this.getMaterialData(this.ctx.tender.id, this.ctx.material.id);
|