新增进货单时,AI自动解析自然语言
This commit is contained in:
@@ -38,3 +38,13 @@ export function needPrivilegeRecommenders(params) {
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/** 大模型解析订货信息为进货申请(不落库),请求可能较慢 */
|
||||
export function parseLbPurchaseApplyFromOrderInfo(data) {
|
||||
return request({
|
||||
url: '/lbPurchaseApply/parseFromOrderInfo',
|
||||
method: 'post',
|
||||
data,
|
||||
timeout: 120000
|
||||
})
|
||||
}
|
||||
|
||||
@@ -85,6 +85,19 @@
|
||||
|
||||
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="720px" @close="resetForm">
|
||||
<el-form ref="dataForm" :model="form" :rules="formRules" label-width="110px">
|
||||
<el-form-item label="订单信息">
|
||||
<el-input
|
||||
v-model="orderInfo"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入订货信息(自然语言),点击下方「AI解析」自动填充表单"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label=" ">
|
||||
<el-button type="primary" plain :loading="parseAiLoading" @click="handleParseFromOrderInfo">
|
||||
AI解析
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="申请人" prop="applyUser">
|
||||
@@ -107,11 +120,45 @@
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="同事电话">
|
||||
<el-input v-model="form.colleaguePhone" placeholder="请输入同事电话" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="试用日期">
|
||||
<el-input v-model="form.tryDate" placeholder="试用日期" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="年龄">
|
||||
<el-input v-model="form.age" placeholder="年龄" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="组长姓名" prop="teamLeader">
|
||||
<el-input v-model="form.teamLeader" placeholder="请输入组长姓名" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="从业经历">
|
||||
<el-input
|
||||
v-model="form.workExperience"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
placeholder="从业经历"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="申请日期" prop="applyDate">
|
||||
<el-date-picker
|
||||
@@ -156,8 +203,10 @@ import {
|
||||
deleteLbPurchaseApply,
|
||||
getLbPurchaseApplyList,
|
||||
needPrivilegeRecommenders,
|
||||
parseLbPurchaseApplyFromOrderInfo,
|
||||
updateLbPurchaseApply
|
||||
} from '@/api/lb-purchase-apply'
|
||||
import { getBusinessHeaders } from '@/utils/business-headers'
|
||||
|
||||
export default {
|
||||
name: 'LbPurchaseApply',
|
||||
@@ -166,6 +215,8 @@ export default {
|
||||
return {
|
||||
loading: false,
|
||||
submitLoading: false,
|
||||
parseAiLoading: false,
|
||||
orderInfo: '',
|
||||
list: [],
|
||||
total: 0,
|
||||
dialogVisible: false,
|
||||
@@ -188,7 +239,11 @@ export default {
|
||||
id: '',
|
||||
applyUser: '',
|
||||
applyPhone: '',
|
||||
tryDate: '',
|
||||
age: '',
|
||||
workExperience: '',
|
||||
colleagueName: '',
|
||||
colleaguePhone: '',
|
||||
teamLeader: '',
|
||||
applyDate: ''
|
||||
},
|
||||
@@ -270,6 +325,75 @@ export default {
|
||||
this.queryParams.current = current
|
||||
this.fetchList()
|
||||
},
|
||||
getTenantIdFromBusinessHeaders() {
|
||||
const headers = getBusinessHeaders()
|
||||
const value = headers && headers['X-Tenant-Id']
|
||||
return value ? String(value).trim() : ''
|
||||
},
|
||||
handleParseFromOrderInfo() {
|
||||
const text = (this.orderInfo || '').trim()
|
||||
if (!text) {
|
||||
this.$message.warning('请先填写订单信息')
|
||||
return
|
||||
}
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
if (!tenantId) {
|
||||
this.$message.error('未获取到租户ID,请先登录或配置业务请求头中的租户')
|
||||
return
|
||||
}
|
||||
this.parseAiLoading = true
|
||||
parseLbPurchaseApplyFromOrderInfo({ orderInfo: text, tenantId })
|
||||
.then((res) => {
|
||||
const payload = res && typeof res === 'object' ? res : {}
|
||||
const entity = payload.data !== undefined && payload.data !== null && typeof payload.data === 'object'
|
||||
? payload.data
|
||||
: payload
|
||||
this.applyParsedEntityToForm(entity)
|
||||
this.$message.success((payload.message) || '解析成功,已填入表单')
|
||||
})
|
||||
.finally(() => {
|
||||
this.parseAiLoading = false
|
||||
})
|
||||
},
|
||||
normalizeApplyDateValue(v) {
|
||||
if (v == null || v === '') return ''
|
||||
if (Array.isArray(v) && v.length >= 3) {
|
||||
const y = v[0]
|
||||
const m = String(v[1]).padStart(2, '0')
|
||||
const d = String(v[2]).padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
}
|
||||
const s = String(v)
|
||||
if (s.includes('T')) return s.slice(0, 10)
|
||||
return s.length >= 10 ? s.slice(0, 10) : s
|
||||
},
|
||||
applyParsedEntityToForm(entity) {
|
||||
if (!entity || typeof entity !== 'object') return
|
||||
const keys = [
|
||||
'applyUser',
|
||||
'applyPhone',
|
||||
'tryDate',
|
||||
'age',
|
||||
'workExperience',
|
||||
'colleagueName',
|
||||
'colleaguePhone',
|
||||
'teamLeader',
|
||||
'applyDate'
|
||||
]
|
||||
keys.forEach((k) => {
|
||||
const v = entity[k]
|
||||
if (v === undefined || v === null) return
|
||||
if (k === 'age') {
|
||||
this.form.age = v === '' ? '' : v
|
||||
return
|
||||
}
|
||||
if (k === 'applyDate') {
|
||||
this.form.applyDate = this.normalizeApplyDateValue(v)
|
||||
return
|
||||
}
|
||||
this.form[k] = v
|
||||
})
|
||||
},
|
||||
handleAdd() {
|
||||
this.dialogTitle = '新增进货申请'
|
||||
this.isEdit = false
|
||||
@@ -333,11 +457,16 @@ export default {
|
||||
handleEdit(row) {
|
||||
this.dialogTitle = '编辑进货申请'
|
||||
this.isEdit = true
|
||||
this.orderInfo = ''
|
||||
this.form = {
|
||||
id: row.id || '',
|
||||
applyUser: row.applyUser || '',
|
||||
applyPhone: row.applyPhone || '',
|
||||
tryDate: row.tryDate || '',
|
||||
age: row.age !== undefined && row.age !== null ? row.age : '',
|
||||
workExperience: row.workExperience || '',
|
||||
colleagueName: row.colleagueName || '',
|
||||
colleaguePhone: row.colleaguePhone || '',
|
||||
teamLeader: row.teamLeader || '',
|
||||
applyDate: row.applyDate || ''
|
||||
}
|
||||
@@ -377,10 +506,17 @@ export default {
|
||||
const payload = {
|
||||
applyUser: this.form.applyUser,
|
||||
applyPhone: this.form.applyPhone,
|
||||
tryDate: this.form.tryDate || undefined,
|
||||
age: this.form.age === '' || this.form.age === undefined || this.form.age === null
|
||||
? undefined
|
||||
: Number(this.form.age),
|
||||
workExperience: this.form.workExperience || undefined,
|
||||
colleagueName: this.form.colleagueName || undefined,
|
||||
colleaguePhone: this.form.colleaguePhone || undefined,
|
||||
teamLeader: this.form.teamLeader || undefined,
|
||||
applyDate: this.form.applyDate || undefined
|
||||
}
|
||||
if (payload.age !== undefined && Number.isNaN(payload.age)) delete payload.age
|
||||
if (this.isEdit) payload.id = this.form.id
|
||||
Object.keys(payload).forEach((key) => {
|
||||
if (payload[key] === undefined || payload[key] === '') delete payload[key]
|
||||
@@ -392,11 +528,16 @@ export default {
|
||||
this.resetFormData()
|
||||
},
|
||||
resetFormData() {
|
||||
this.orderInfo = ''
|
||||
this.form = {
|
||||
id: '',
|
||||
applyUser: '',
|
||||
applyPhone: '',
|
||||
tryDate: '',
|
||||
age: '',
|
||||
workExperience: '',
|
||||
colleagueName: '',
|
||||
colleaguePhone: '',
|
||||
teamLeader: '',
|
||||
applyDate: ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user