67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"strings"
|
|
|
|
"server/models"
|
|
"server/pkg/identity"
|
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
)
|
|
|
|
// BackendOcrController 租户端 OCR 识别(OA 应用)
|
|
// OCR 配置由平台端「AI管理 → OCR配置」统一维护(yz_platform_site_setting 标签)。
|
|
// 识别实现(视觉模型 / 专用 OCR)后续接入;当前返回配置状态占位。
|
|
type BackendOcrController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
func (c *BackendOcrController) jsonErr(httpStatus, bizCode int, msg string) {
|
|
c.Ctx.Output.SetStatus(httpStatus)
|
|
c.Data["json"] = map[string]any{"code": bizCode, "msg": msg}
|
|
_ = c.ServeJSON()
|
|
}
|
|
|
|
// Recognize POST /backend/ocr/recognize
|
|
// 入参 { image_base64 } 或 { image_url };占位阶段只校验配置并返回状态。
|
|
func (c *BackendOcrController) Recognize() {
|
|
if _, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend); err != nil {
|
|
code := identity.Status(err)
|
|
c.jsonErr(code, code, err.Error())
|
|
return
|
|
}
|
|
raw, _ := io.ReadAll(c.Ctx.Request.Body)
|
|
var req struct {
|
|
ImageBase64 string `json:"image_base64"`
|
|
ImageURL string `json:"image_url"`
|
|
Prompt string `json:"prompt"`
|
|
}
|
|
_ = json.Unmarshal(raw, &req)
|
|
if strings.TrimSpace(req.ImageBase64) == "" && strings.TrimSpace(req.ImageURL) == "" {
|
|
c.jsonErr(400, 400, "请上传图片")
|
|
return
|
|
}
|
|
|
|
all := models.GetPlatformSiteTagMap()
|
|
enabled := strings.TrimSpace(all["ocr_enabled"]) == "1"
|
|
if !enabled {
|
|
c.jsonErr(403, 403, "OCR 识别未启用,请联系平台管理员在「AI管理」中开启")
|
|
return
|
|
}
|
|
|
|
c.Data["json"] = map[string]any{
|
|
"code": 200,
|
|
"msg": "success",
|
|
"data": map[string]any{
|
|
"recognized": false,
|
|
"placeholder": true,
|
|
"message": "OCR 识别服务待接入,平台配置已生效",
|
|
"provider_id": all["ocr_provider_id"],
|
|
"model": all["ocr_model"],
|
|
},
|
|
}
|
|
_ = c.ServeJSON()
|
|
}
|