|
|
@@ -1192,7 +1192,7 @@ module.exports = app => {
|
|
|
|
|
|
const validColSet = data.template.col_set.filter(x => { return !x.expr; });
|
|
|
const AIInspect = require('../lib/ai_inspect');
|
|
|
- const aiInspect = new AIInspect({ apiKey: 'app-BIOhBbFlNSakoRGKU91e2ksJ', baseUrl: 'http://39.108.81.93:8080/v1' });
|
|
|
+ const aiInspect = new AIInspect({ apiKey: ctx.difyInfo.apiKey.image2PosCalcDetail, baseUrl: ctx.difyInfo.baseUrl });
|
|
|
const transResult = await aiInspect.posCalcDetailRead(validColSet, data.billsName, data.keyword, data.files);
|
|
|
const rows = transResult.res.split('\n').filter(x => { return !!x; });
|
|
|
rows.shift();
|
|
|
@@ -1211,13 +1211,10 @@ module.exports = app => {
|
|
|
const responseData = await ctx.service.posCalcDetail.updateDatas({ add: pcdData });
|
|
|
ctx.body = { err: 0, msg: '', data: responseData };
|
|
|
}
|
|
|
- async _aiCompliePosAndDetail(ctx, data) {
|
|
|
- const bills = await this.ctx.service.ledger.getDataById(data.bills);
|
|
|
- if (!bills) throw '选择的清单不存在,请刷新页面后再试';
|
|
|
-
|
|
|
+ async _aiComplieSteelPos(ctx, bills, data) {
|
|
|
const validColSet = data.template.col_set.filter(x => { return !x.expr; });
|
|
|
const AIInspect = require('../lib/ai_inspect');
|
|
|
- const aiInspect = new AIInspect({ apiKey: 'app-FtAs299O9xFzTOVB4TlaZ73O', baseUrl: 'http://39.108.81.93:8080/v1' });
|
|
|
+ const aiInspect = new AIInspect({ apiKey: ctx.difyInfo.apiKey.image2Pos, baseUrl: ctx.difyInfo.baseUrl });
|
|
|
const transResult = await aiInspect.posCalcDetailRead(validColSet, data.billsName, data.keyword, data.files);
|
|
|
const parts = transResult.res.split('\n==++==\n').filter(x => { return !!x; });
|
|
|
const pos = [];
|
|
|
@@ -1230,7 +1227,8 @@ module.exports = app => {
|
|
|
const pinfo = JSON.parse(pjson);
|
|
|
newPos.name = pinfo.pname;
|
|
|
}
|
|
|
- const detail = p.substr(nameStr.length, p.length - nameStr.length);
|
|
|
+ const detailStr = p.substr(nameStr.length, p.length - nameStr.length);
|
|
|
+ const [detail, ancGcl] = detailStr.split(`\n==+ancGcl+==\n`);
|
|
|
const rows = detail.split('\n').filter(x => { return !!x; });
|
|
|
rows.shift();
|
|
|
newPos.calcDetail = rows.map(x => {
|
|
|
@@ -1245,11 +1243,47 @@ module.exports = app => {
|
|
|
}
|
|
|
return nd;
|
|
|
});
|
|
|
+ const agRows = ancGcl.split('\n').filter(x => { return !!x; });
|
|
|
+ agRows.shift();
|
|
|
+ newPos.ancGcl = agRows.map(x => {
|
|
|
+ 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 };
|
|
|
+ });
|
|
|
pos.push(newPos);
|
|
|
}
|
|
|
const responseData = await ctx.service.pos.savePosData({ updateType: 'add-with-detail', updateData: { lid: bills.id, pos} }, ctx.tender.id);
|
|
|
ctx.body = { err: 0, msg: '', data: responseData };
|
|
|
}
|
|
|
+ async _aiComplieConcretePos(ctx, bills, data) {
|
|
|
+ const validColSet = data.template.col_set.filter(x => { return !x.expr; });
|
|
|
+ const AIInspect = require('../lib/ai_inspect');
|
|
|
+ const aiInspect = new AIInspect({ apiKey: ctx.difyInfo.apiKey.image2PosQty, baseUrl: ctx.difyInfo.baseUrl });
|
|
|
+ const transResult = await aiInspect.posCalcDetailRead(validColSet, data.billsName, data.keyword, data.files);
|
|
|
+ const parts = transResult.res.split('\n==++==\n').filter(x => { return !!x; });
|
|
|
+ const pos = [];
|
|
|
+ for (const p of parts) {
|
|
|
+ const newPos = { lid: bills.id };
|
|
|
+ const pInfo = JSON.parse(p);
|
|
|
+ newPos.name = pInfo.name;
|
|
|
+ newPos.sgfh_qty = ctx.helper._.toNumber(pInfo.qty) || 0;
|
|
|
+ }
|
|
|
+ const responseData = await ctx.service.pos.savePosData({ updateType: 'add-with-detail', updateData: { lid: bills.id, pos} }, ctx.tender.id);
|
|
|
+ ctx.body = { err: 0, msg: '', data: responseData };
|
|
|
+ }
|
|
|
+ async _aiCompliePosAndDetail(ctx, data) {
|
|
|
+ const bills = await this.ctx.service.ledger.getDataById(data.bills);
|
|
|
+ if (!bills) throw '选择的清单不存在,请刷新页面后再试';
|
|
|
+
|
|
|
+ switch(data.billsType) {
|
|
|
+ case '钢筋':
|
|
|
+ case '钢绞线':
|
|
|
+ return this._aiComplieSteelPos(ctx, bills, data);
|
|
|
+ case '混凝土':
|
|
|
+ return this._aiComplieConcretePos(ctx, bills, data);
|
|
|
+ default: throw `暂不支持清单类型为${data.billsType}的清单,进行ai识别填写`
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
async aiComplie(ctx) {
|
|
|
let stream;
|
|
|
try {
|
|
|
@@ -1265,6 +1299,7 @@ module.exports = app => {
|
|
|
const rela_template = parts.field.rela_template;
|
|
|
const template = await ctx.service.calcTmpl.getTemplate(rela_template);
|
|
|
const keyword = parts.field.rela_keyword;
|
|
|
+ const billsType = parts.field.rela_billsType;
|
|
|
|
|
|
const uploadfiles = [];
|
|
|
while (stream !== undefined) {
|
|
|
@@ -1299,7 +1334,7 @@ module.exports = app => {
|
|
|
await this._aiCompliePosCalcDetail(ctx, { billsName, template, pos: rela_id, files: result, keyword });
|
|
|
break;
|
|
|
case 'bills':
|
|
|
- await this._aiCompliePosAndDetail(ctx, { billsName, template, bills: rela_id, files: result, keyword });
|
|
|
+ await this._aiCompliePosAndDetail(ctx, { billsName, template, bills: rela_id, files: result, keyword, billsType });
|
|
|
break;
|
|
|
default:
|
|
|
throw '暂不提供该ai识别内容';
|