Jelajahi Sumber

ai识别填写调整

MaiXinRong 15 jam lalu
induk
melakukan
cd9b7e6ba7

+ 1 - 1
app/base/base_bills_service.js

@@ -814,7 +814,7 @@ class BaseBillsSerivce extends TreeService {
                                 quantity: ag.quantity || 0, expr: ag.expr || '', calc_template: ag.calc_template || ''
                             };
                             pasteAncGclData.push(nig);
-                            if (!ag.calc_template) continue;
+                            if (!ag.calc_template || ag.calcDetail.length === 0) continue;
 
                             let sumQty = 0;
                             for (const cd of ag.calcDetail) {

+ 32 - 14
app/controller/ledger_controller.js

@@ -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) {

+ 9 - 2
app/public/js/ledger.js

@@ -4068,7 +4068,11 @@ $(document).ready(function() {
                 if (result.details) ancGclDetail.detail.updateDatas(result.details);
                 ancGclObj.loadCurAncillaryGcl();
             });
-        }
+        },
+        afterPostData: function(data) {
+            ancGcl.updateDatas(data);
+            ancGclObj.loadCurAncillaryGcl();
+        },
     };
     ancGclSpread.bind(spreadNS.Events.SelectionChanged, ancGclObj.selectionChanged);
     if (!readOnly) {
@@ -6518,7 +6522,10 @@ $(document).ready(function() {
                 return;
             }
 
-            if (aiTrans.rela_type() === 'pos') aiTrans.transDetail(posCalcDetail.afterPostData);
+            if (aiTrans.rela_type() === 'pos') aiTrans.transDetail(function(result) {
+                posCalcDetail.afterPostData(result);
+                if (result.ancGcl) ancGclObj.afterPostData(result.ancGcl);
+            });
             if (aiTrans.rela_type() === 'bills') aiTrans.transDetail(posOperationObj.afterPostData);
         });
     });