Explorar el Código

AI识别填写计量单元&设计量明细1.0

MaiXinRong hace 2 semanas
padre
commit
cdf3aaa755
Se han modificado 3 ficheros con 149 adiciones y 1 borrados
  1. 42 1
      app/controller/ledger_controller.js
  2. 11 0
      app/public/js/ledger.js
  3. 96 0
      app/service/pos.js

+ 42 - 1
app/controller/ledger_controller.js

@@ -667,7 +667,6 @@ module.exports = app => {
         //         await ctx.helper.saveStreamFile(stream, fileName);
 
         //         // 读取excel
-        //         console.log(ctx.query);
         //         const name = ctx.query.sheetName;
         //         if (!name) throw '未选择需要导入的工作簿';
         //         const wb = xlsx.readFile(fileName);
@@ -1212,6 +1211,45 @@ 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 '选择的清单不存在,请刷新页面后再试';
+
+            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 transResult = await aiInspect.posCalcDetailRead(validColSet, data.billsName, data.keyword, data.files);
+            const parts = transResult.res.split('\n==++==\n').filter(x => { return !!x; });
+            const pos = [];
+            const posInfoReg = new RegExp('{{.*}}', 'igm');
+            for (const p of parts) {
+                const newPos = { lid: bills.id };
+                const nameStr = p.match(posInfoReg)[0];
+                if (nameStr) {
+                    const pjson = nameStr.substr(1, nameStr.length - 2);
+                    const pinfo = JSON.parse(pjson);
+                    newPos.name = pinfo.pname;
+                }
+                const detail = p.substr(nameStr.length, p.length - nameStr.length);
+                const rows = detail.split('\n').filter(x => { return !!x; });
+                rows.shift();
+                newPos.calcDetail = 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;
+                });
+                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 aiComplie(ctx) {
             let stream;
             try {
@@ -1260,6 +1298,9 @@ module.exports = app => {
                     case 'pos':
                         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 });
+                        break;
                     default:
                         throw '暂不提供该ai识别内容';
                 }

+ 11 - 0
app/public/js/ledger.js

@@ -3501,6 +3501,16 @@ $(document).ready(function() {
             }
             return copyBlockList;
         },
+        afterPostData: function( result) {
+            pos.updateDatas(result.pos);
+            if (result.posCalcDetail) posCalcDetail.detail.updateDatas(result.posCalcDetail);
+            const ledgerResult = ledgerTree.loadPostData(result.ledger);
+            treeOperationObj.refreshTree(ledgerSheet, ledgerResult);
+            if (result.ancGcl) ancGcl.updateDatas(result.ancGcl);
+            if (result.ancGclDetail) ancGclDetail.detail.updateDatas(result.ancGclDetail);
+            removeLocalCache(copyBlockTag);
+            posOperationObj.loadCurPosData();
+        },
         pasteBlock: function(copyInfo) {
             const node = SpreadJsObj.getSelectObject(ledgerSheet);
             if (!node) {
@@ -6479,6 +6489,7 @@ $(document).ready(function() {
     });
     $('.ai-btn').click(function() {
         if (aiTrans.rela_type() === 'pos') aiTrans.transDetail(posCalcDetail.afterPostData);
+        if (aiTrans.rela_type() === 'bills') aiTrans.transDetail(posOperationObj.afterPostData);
     });
 });
 // 生成当前节点列表

+ 96 - 0
app/service/pos.js

@@ -578,6 +578,100 @@ module.exports = app => {
             result.ancGclDetail = { add: insertAncGclDetail };
             return result;
         }
+        async _addPosDataWithDetail(tid, data) {
+            if (!(data.pos instanceof Array)) throw '提交数据错误';
+
+            const result = { ledger: {}, pos: null };
+            const user_id = this.ctx.session.sessionUser.accountId;
+
+            const bills = await this.ctx.service.ledger.getDataById(data.lid);
+            const le = await this.ctx.service.ledgerExtra.getDataById(data.lid);
+            const calcTemplate = le && le.calc_template ? await this.ctx.service.calcTmpl.getTemplate(le.calc_template) : null;
+            const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
+            const existPos = await this.ctx.service.pos.getAllDataByCondition({ where : { lid: bills.id }, orders: [['porder', 'DESC']]});
+            const maxOrder = existPos.length > 0 ? existPos[0].porder : 0;
+            const updateBills = existPos.length > 0
+                ? { id: bills.id, sgfh_qty: bills.sgfh_qty, sjcl_qty: bills.sjcl_qty, qtcl_qty: bills.qtcl_qty, quantity: bills.quantity, ex_qty1: bills.ex_qty1 }
+                : { id: bills.id, sgfh_qty: 0, sjcl_qty: 0, qtcl_qty: 0, quantity: 0, ex_qty1: 0 };
+
+            const insertPos = [], insertDetail = [];
+            for (const [i, b] of data.pos.entries()) {
+                const nip = {};
+                insertPos.push(nip);
+                this._completeInsertPosData(tid, nip);
+                nip.lid = b.lid;
+                nip.name = b.name || '';
+                nip.porder = maxOrder + i + 1;
+
+                let sumQty = 0;
+                for (const [icd, cd] of b.calcDetail.entries()) {
+                    const newDetail = {
+                        id: this.uuid.v4(), tid: tid, lid: bills.id, pid: nip.id,
+                        create_user_id: user_id, update_user_id: user_id,
+                        pcd_order: icd+1,
+                    };
+                    if (data.calc_template === le.calc_template) {
+                        newDetail.str1 = cd.str1 || '';
+                        newDetail.str2 = cd.str2 || '';
+                        newDetail.str3 = cd.str3 || '';
+                        newDetail.str4 = cd.str4 || '';
+                        newDetail.num_a = cd.num_a || 0;
+                        newDetail.num_b = cd.num_b || 0;
+                        newDetail.num_c = cd.num_c || 0;
+                        newDetail.num_d = cd.num_d || 0;
+                        newDetail.num_e = cd.num_e || 0;
+                        newDetail.num_f = cd.num_f || 0;
+                        newDetail.num_g = cd.num_g || 0;
+                        newDetail.num_h = cd.num_h || 0;
+                        newDetail.num_i = cd.num_i || 0;
+                        newDetail.num_j = cd.num_j || 0;
+                        newDetail.num_k = cd.num_k || 0;
+                        newDetail.num_l = cd.num_l || 0;
+                        newDetail.num_m = cd.num_m || 0;
+                        newDetail.num_n = cd.num_n || 0;
+                        newDetail.num_o = cd.num_o || 0;
+                        newDetail.num_p = cd.num_p || 0;
+                        newDetail.num_q = cd.num_q || 0;
+                        newDetail.num_r = cd.num_r || 0;
+                        newDetail.num_s = cd.num_s || 0;
+                        newDetail.num_t = cd.num_t || 0;
+                        newDetail.num_u = cd.num_u || 0;
+                        newDetail.qty = cd.qty || 0;
+                        newDetail.expr = cd.expr || '';
+                        newDetail.spec = cd.spec || '';
+                    } else {
+                        this.ctx.service.posCalcDetail._loadDataAndCalc(newDetail, cd, {}, calcTemplate);
+                    }
+                    sumQty = this.ctx.helper.add(sumQty, newDetail.qty);
+                    insertDetail.push(newDetail);
+                }
+                this._calcExpr(nip, 'sgfh_qty', '', sumQty, precision);
+
+                nip.quantity = this.ctx.helper.add(nip.sgfh_qty, this.ctx.helper.add(nip.sjcl_qty, nip.qtcl_qty));
+                updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, nip.sgfh_qty);
+            }
+
+            const info = this.ctx.tender.info;
+            updateBills.quantity = this.ctx.helper.add(updateBills.sgfh_qty, this.ctx.helper.add(updateBills.sjcl_qty, updateBills.qtcl_qty));
+            updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
+            updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.insert(this.tableName, insertPos);
+                if (insertDetail.length > 0) await transaction.insert(this.ctx.service.posCalcDetail.tableName, insertDetail);
+                await transaction.update(this.ctx.service.ledger.tableName, updateBills);
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+            result.pos = insertPos;
+            updateBills.ledger_id = bills.ledger_id;
+            result.ledger.update = [updateBills];
+            result.posCalcDetail = { add: insertDetail };
+            return result;
+        }
 
         /**
          * 保存部位明细数据
@@ -601,6 +695,8 @@ module.exports = app => {
                     return await this._insertPosData(tid, data.updateData);
                 case 'paste-block':
                     return await this.pasteBlockData(tid, data.updateData);
+                case 'add-with-detail':
+                    return await this._addPosDataWithDetail(tid, data.updateData);
             }
         }