|
|
@@ -1265,21 +1265,39 @@ module.exports = app => {
|
|
|
const AIDify = require('../lib/ai_dify');
|
|
|
const aiDify = new AIDify({ apiKey: ctx.difyInfo.apiKey.image2PosCalcDetail, baseUrl: ctx.difyInfo.baseUrl });
|
|
|
const transResult = await aiDify.posCalcDetailRead(validColSet, data.billsName, data.keyword, data.files);
|
|
|
- const rows = transResult.res.split('\n').filter(x => { return !!x; });
|
|
|
- rows.shift();
|
|
|
- const pcdData = rows.map(x => {
|
|
|
- const rd = x.split('|');
|
|
|
- const nd = { pid: pos.id, lid: pos.lid };
|
|
|
- for (const [i, c] of validColSet.entries()) {
|
|
|
- if (c.type === 'num') {
|
|
|
- nd[c.field] = ctx.helper._.toNumber(rd[i]);
|
|
|
- } else {
|
|
|
- nd[c.field] = rd[i];
|
|
|
+ if (!transResult.res) throw '未识别出设计量明细、附属工程量';
|
|
|
+
|
|
|
+ let responseData = {};
|
|
|
+ const [detail, ancGcl] = transResult.res.split(`\n==+ancGcl+==\n`);
|
|
|
+ if (detail) {
|
|
|
+ const rows = detail.split('\n').filter(x => { return !!x; });
|
|
|
+ rows.shift();
|
|
|
+ const pcdData = rows.map(x => {
|
|
|
+ const rd = x.split('|');
|
|
|
+ const nd = { pid: pos.id, lid: pos.lid };
|
|
|
+ for (const [i, c] of validColSet.entries()) {
|
|
|
+ if (c.type === 'num') {
|
|
|
+ nd[c.field] = ctx.helper._.toNumber(rd[i]);
|
|
|
+ } else {
|
|
|
+ nd[c.field] = rd[i];
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- return nd;
|
|
|
- });
|
|
|
- const responseData = await ctx.service.posCalcDetail.updateDatas({ add: pcdData });
|
|
|
+ return nd;
|
|
|
+ });
|
|
|
+ responseData = await ctx.service.posCalcDetail.updateDatas({ add: pcdData });
|
|
|
+ }
|
|
|
+ if (ancGcl) {
|
|
|
+ const existAncGcl = await ctx.service.ancillaryGcl.getAllDataByCondition({ where: { pid: pos.id }, orders: [['g_order', 'desc']]});
|
|
|
+ const maxOrder = existAncGcl.length > 0 ? existAncGcl[0].g_order : 0;
|
|
|
+ const agRows = ancGcl.split('\n').filter(x => { return !!x; });
|
|
|
+ agRows.shift();
|
|
|
+ const agData = agRows.map((x, i) => {
|
|
|
+ const rd = x.split('|');
|
|
|
+ return { pid: pos.id, lid: pos.lid, name: rd[0] || '', unit: rd[1] || 0, quantity: ctx.helper._.toNumber(rd[2]) || 0, g_order: i + maxOrder + 1 };
|
|
|
+ });
|
|
|
+ if (agData.length > 0) responseData.ancGcl = await ctx.service.ancillaryGcl.updateDatas({ add: agData });
|
|
|
+ console.log(responseData.ancGcl);
|
|
|
+ }
|
|
|
ctx.body = { err: 0, msg: '', data: responseData };
|
|
|
}
|
|
|
async _aiComplieSteelPos(ctx, bills, data) {
|