feat: analysis admin
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
package analysisadminlogic
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
const adminImageTimeLayout = "2006-01-02 15:04"
|
||||
|
||||
func outParams(msg string) *analysis.Response {
|
||||
return common.OutResponse(utils.ErrorParams, msg)
|
||||
}
|
||||
|
||||
func formatGender(gender uint32) string {
|
||||
switch gender {
|
||||
case 1:
|
||||
return "男"
|
||||
case 2:
|
||||
return "女"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func userStatus(row dao.User) int {
|
||||
status := utils.NumberOne
|
||||
if row.IsRegistered == uint8(utils.StatusOk) {
|
||||
status = utils.NumberTwo
|
||||
}
|
||||
if row.IsFaceVerified == uint8(utils.StatusOk) {
|
||||
status = utils.NumberThree
|
||||
}
|
||||
if row.IsProfileCompleted == uint8(utils.StatusOk) {
|
||||
status = utils.NumberFour
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func idStrings(ids []int64) []string {
|
||||
out := make([]string, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id < utils.NumberOne {
|
||||
continue
|
||||
}
|
||||
out = append(out, strconv.FormatInt(id, utils.NumberTen))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func loadImageLogs(userIds []int64) (map[int64]dao.UserImageLog, error) {
|
||||
out := make(map[int64]dao.UserImageLog, len(userIds))
|
||||
if len(userIds) == utils.NumberZero {
|
||||
return out, nil
|
||||
}
|
||||
var rows []dao.UserImageLog
|
||||
err := model.UserImageLogModel{}.Init().Items(modelbase.Params{
|
||||
In: map[string][]string{"user_id": idStrings(userIds)},
|
||||
Order: "detection_time desc",
|
||||
}, &rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, row := range rows {
|
||||
if _, ok := out[row.UserId]; ok {
|
||||
continue
|
||||
}
|
||||
out[row.UserId] = row
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func formatImageContents(data map[string]string) map[string]string {
|
||||
result := make(map[string]string, len(data))
|
||||
for k, v := range data {
|
||||
switch k {
|
||||
case "health_score":
|
||||
parts := strings.Split(v, "/")
|
||||
result[k] = strings.TrimSpace(parts[0])
|
||||
default:
|
||||
result[k] = strings.TrimSuffix(v, "%")
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func buildImageDetail(detail *dao.Image) dao.ImageDetailResource {
|
||||
var images map[string]interface{}
|
||||
if detail.Images != utils.StringEmpty {
|
||||
_ = jsoniter.UnmarshalFromString(detail.Images, &images)
|
||||
}
|
||||
|
||||
var contents map[string]string
|
||||
if detail.Contents != utils.StringEmpty {
|
||||
var raw map[string]string
|
||||
if err := jsoniter.UnmarshalFromString(detail.Contents, &raw); err == nil {
|
||||
contents = formatImageContents(raw)
|
||||
} else {
|
||||
contents = map[string]string{}
|
||||
}
|
||||
}
|
||||
|
||||
return dao.ImageDetailResource{
|
||||
Id: detail.Id,
|
||||
UserId: detail.UserId,
|
||||
TaskId: detail.TaskId,
|
||||
Images: images,
|
||||
Contents: contents,
|
||||
Cover: detail.Cover,
|
||||
CreateTime: detail.CreateTime.Format(adminImageTimeLayout),
|
||||
}
|
||||
}
|
||||
|
||||
func queryAdminImageLogs(userId int64, page, size int32) ([]dao.ImageLogResource, error) {
|
||||
var rows []dao.Image
|
||||
_, err := model.ImageModel{}.Init().Page(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"user_id": strconv.FormatInt(userId, utils.NumberTen),
|
||||
"status": strconv.Itoa(utils.StatusOk),
|
||||
},
|
||||
Order: "id desc",
|
||||
Page: int(page),
|
||||
Size: int(size),
|
||||
}, &rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(rows) == utils.NumberZero {
|
||||
return nil, nil
|
||||
}
|
||||
list := make([]dao.ImageLogResource, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
contents := map[string]string{}
|
||||
if row.Contents != utils.StringEmpty {
|
||||
var raw map[string]string
|
||||
if err = jsoniter.UnmarshalFromString(row.Contents, &raw); err == nil {
|
||||
if formatted := formatImageContents(raw); formatted != nil {
|
||||
contents = formatted
|
||||
}
|
||||
}
|
||||
}
|
||||
list = append(list, dao.ImageLogResource{
|
||||
Id: row.Id,
|
||||
UserId: row.UserId,
|
||||
Cover: row.Cover,
|
||||
Contents: contents,
|
||||
TaskId: row.TaskId,
|
||||
CreateTime: row.CreateTime.Format(adminImageTimeLayout),
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package analysisadminlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserArchiveLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserArchiveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserArchiveLogic {
|
||||
return &UserArchiveLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserArchiveLogic) UserArchive(in *analysis.AdminUserArchiveReq) (*analysis.Response, error) {
|
||||
var req validator.AdminUserArchiveValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outParams(msg), nil
|
||||
}
|
||||
if _, fail := common.RequireAdmin(l.ctx); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
list, err := queryAdminImageLogs(req.UserId, req.Page, req.Size)
|
||||
if err != nil {
|
||||
l.Errorf("admin user archive: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if len(list) == utils.NumberZero {
|
||||
return common.OkResponse(nil), nil
|
||||
}
|
||||
return common.OkResponse(list), nil
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package analysisadminlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserDetailLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailLogic {
|
||||
return &UserDetailLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserDetailLogic) UserDetail(in *analysis.AdminUserDetailReq) (*analysis.Response, error) {
|
||||
var req validator.AdminUserDetailValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outParams(msg), nil
|
||||
}
|
||||
if _, fail := common.RequireAdmin(l.ctx); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
var detail dao.Image
|
||||
err := model.ImageModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(req.Id, utils.NumberTen)},
|
||||
}, &detail)
|
||||
if err != nil {
|
||||
l.Errorf("admin user detail: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if detail.Id <= utils.NumberZero {
|
||||
return common.OkResponse(nil), nil
|
||||
}
|
||||
return common.OkResponse(buildImageDetail(&detail)), nil
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package analysisadminlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
userpb "lone-services/rpc/user/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type UserListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
|
||||
return &UserListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserListLogic) UserList(in *analysis.AdminUserListReq) (*analysis.Response, error) {
|
||||
var req validator.AdminUserListValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outParams(msg), nil
|
||||
}
|
||||
if _, fail := common.RequireAdmin(l.ctx); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
params := modelbase.Params{
|
||||
Order: "id desc",
|
||||
Page: int(req.Page),
|
||||
Size: int(req.Size),
|
||||
}
|
||||
|
||||
if req.Keyword != utils.StringEmpty {
|
||||
bizIds, err := l.filterBizIds(req.Keyword)
|
||||
if err != nil {
|
||||
l.Errorf("admin user list filter: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if len(bizIds) == utils.NumberZero {
|
||||
return common.OkResponse(modelbase.PageResult{Items: []dao.AdminUserListItem{}}), nil
|
||||
}
|
||||
params.In = map[string][]string{"id": idStrings(bizIds)}
|
||||
}
|
||||
|
||||
var users []dao.User
|
||||
page, err := model.UserModel{}.Init().Page(params, &users)
|
||||
if err != nil {
|
||||
l.Errorf("admin user list page: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if len(users) == utils.NumberZero {
|
||||
page.Items = []dao.AdminUserListItem{}
|
||||
return common.OkResponse(page), nil
|
||||
}
|
||||
|
||||
pageIds := make([]int64, 0, len(users))
|
||||
for _, row := range users {
|
||||
pageIds = append(pageIds, row.Id)
|
||||
}
|
||||
|
||||
profiles, err := l.loadProfiles(pageIds)
|
||||
if err != nil {
|
||||
l.Errorf("admin user list profiles: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
logs, err := loadImageLogs(pageIds)
|
||||
if err != nil {
|
||||
l.Errorf("admin user list logs: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]dao.AdminUserListItem, 0, len(users))
|
||||
for _, row := range users {
|
||||
item := dao.AdminUserListItem{
|
||||
Id: row.Id,
|
||||
Status: userStatus(row),
|
||||
CreatedAt: row.CreatedAt,
|
||||
}
|
||||
if profile, ok := profiles[row.Id]; ok {
|
||||
item.Name = profile.GetName()
|
||||
item.Avatar = profile.GetAvatar()
|
||||
mobile, _ := utils.DecryptPhone(profile.GetMobile())
|
||||
item.Mobile = mobile
|
||||
item.Gender = profile.GetGender()
|
||||
item.GenderText = formatGender(item.Gender)
|
||||
item.Birthday = profile.GetBirthday()
|
||||
item.Age = utils.CalcAgeStr(item.Birthday)
|
||||
} else {
|
||||
item.GenderText = formatGender(utils.NumberZero)
|
||||
}
|
||||
if logRow, ok := logs[row.Id]; ok {
|
||||
item.DetectionNumber = logRow.DetectionNumber
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
page.Items = items
|
||||
return common.OkResponse(page), nil
|
||||
}
|
||||
|
||||
func (l *UserListLogic) filterBizIds(keyword string) ([]int64, error) {
|
||||
if l.svcCtx.UserSvcName == utils.StringEmpty {
|
||||
return nil, status.Error(codes.FailedPrecondition, "user service empty")
|
||||
}
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := userpb.NewUserClient(cli.Conn()).InternalUsersByBiz(l.ctx, &userpb.InternalUsersByBizReq{
|
||||
ClientCode: dao.ClientCodeUserSkin,
|
||||
Keyword: keyword,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]int64, 0, len(res.GetItems()))
|
||||
for _, item := range res.GetItems() {
|
||||
if item.GetBizId() > utils.NumberZero {
|
||||
ids = append(ids, item.GetBizId())
|
||||
}
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (l *UserListLogic) loadProfiles(bizIds []int64) (map[int64]*userpb.BizUserItem, error) {
|
||||
out := make(map[int64]*userpb.BizUserItem, len(bizIds))
|
||||
if len(bizIds) == utils.NumberZero {
|
||||
return out, nil
|
||||
}
|
||||
if l.svcCtx.UserSvcName == utils.StringEmpty {
|
||||
return nil, status.Error(codes.FailedPrecondition, "user service empty")
|
||||
}
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := userpb.NewUserClient(cli.Conn()).InternalUsersByBiz(l.ctx, &userpb.InternalUsersByBizReq{
|
||||
ClientCode: dao.ClientCodeUserSkin,
|
||||
BizIds: bizIds,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range res.GetItems() {
|
||||
out[item.GetBizId()] = item
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package analysisdevicelogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
userpb "lone-services/rpc/user/pb"
|
||||
"lone-services/services/analysis/internal/dao"
|
||||
"lone-services/services/analysis/internal/face"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type FaceLoginLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewFaceLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FaceLoginLogic {
|
||||
return &FaceLoginLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
type faceLoginResult struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
Info jsoniter.RawMessage `json:"info"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func (l *FaceLoginLogic) FaceLogin(in *analysis.FaceLoginReq) (*analysis.Response, error) {
|
||||
var req validator.FaceLoginValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
if len(req.File) == utils.NumberZero && req.FilePath == utils.StringEmpty {
|
||||
return common.FailResponse(utils.ErrorFileUpFailed), nil
|
||||
}
|
||||
|
||||
imgPath, cleanup, err := face.PrepareImagePath(req.File, req.FilePath)
|
||||
if err != nil {
|
||||
l.Errorf("face login prepare image: %v", err)
|
||||
return common.FailResponse(utils.ErrorFileUpFailed), nil
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
vector, err := face.GetFaceVector(imgPath)
|
||||
if err != nil {
|
||||
l.Errorf("face login vector: %v", err)
|
||||
return common.FailResponse(utils.ErrorNotFace), nil
|
||||
}
|
||||
|
||||
userID, score, err := face.SearchUser(vector)
|
||||
l.Infof("face login user_id=%d score=%v err=%v", userID, score, err)
|
||||
if err != nil {
|
||||
return common.FailResponse(utils.ErrorFaceNotMatch), nil
|
||||
}
|
||||
|
||||
clientCode := req.ClientCode
|
||||
if clientCode == utils.StringEmpty {
|
||||
clientCode = dao.ClientCodeUserSkin
|
||||
}
|
||||
if l.svcCtx.UserSvcName == utils.StringEmpty {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
|
||||
if err != nil {
|
||||
l.Errorf("face login user rpc: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
token, err := userpb.NewUserClient(cli.Conn()).InternalLoginByUserId(l.ctx, &userpb.InternalLoginByUserIdReq{
|
||||
UserId: userID,
|
||||
ClientCode: clientCode,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("face login issue token: %v", err)
|
||||
return common.FailResponse(utils.ErrorFaceNotMatch), nil
|
||||
}
|
||||
|
||||
status := utils.NumberOne
|
||||
bizId := parseSessionBizId(token.GetInfo())
|
||||
if bizId > utils.NumberZero {
|
||||
if row, loadErr := common.LoadAnalysisUser(bizId); loadErr == nil && row != nil {
|
||||
status = analysisUserStatus(*row)
|
||||
}
|
||||
}
|
||||
|
||||
var info jsoniter.RawMessage
|
||||
if token.GetInfo() != utils.StringEmpty {
|
||||
info = jsoniter.RawMessage(token.GetInfo())
|
||||
} else {
|
||||
info = jsoniter.RawMessage("{}")
|
||||
}
|
||||
return common.OkResponse(faceLoginResult{
|
||||
AccessToken: token.GetAccessToken(),
|
||||
RefreshToken: token.GetRefreshToken(),
|
||||
Info: info,
|
||||
Status: status,
|
||||
}), nil
|
||||
}
|
||||
|
||||
func parseSessionBizId(info string) int64 {
|
||||
if info == utils.StringEmpty {
|
||||
return utils.NumberZero
|
||||
}
|
||||
var sess struct {
|
||||
BizId int64 `json:"biz_id"`
|
||||
}
|
||||
if err := jsoniter.UnmarshalFromString(info, &sess); err != nil {
|
||||
return utils.NumberZero
|
||||
}
|
||||
return sess.BizId
|
||||
}
|
||||
|
||||
func analysisUserStatus(row dao.User) int {
|
||||
status := utils.NumberOne
|
||||
if row.IsRegistered == uint8(utils.StatusOk) {
|
||||
status = utils.NumberTwo
|
||||
}
|
||||
if row.IsFaceVerified == uint8(utils.StatusOk) {
|
||||
status = utils.NumberThree
|
||||
}
|
||||
if row.IsProfileCompleted == uint8(utils.StatusOk) {
|
||||
status = utils.NumberFour
|
||||
}
|
||||
return status
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/face"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
@@ -36,10 +37,13 @@ func (l *FaceBindLogic) FaceBind(in *analysis.FaceBindReq) (*analysis.Response,
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
bizId, _, fail := common.RequireBizUserId(l.ctx)
|
||||
bizId, loginUser, fail := common.RequireBizUserId(l.ctx)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
if loginUser.ID < utils.NumberOne {
|
||||
return common.FailResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
row, err := common.LoadAnalysisUser(bizId)
|
||||
if err != nil {
|
||||
@@ -50,6 +54,23 @@ func (l *FaceBindLogic) FaceBind(in *analysis.FaceBindReq) (*analysis.Response,
|
||||
return common.FailResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
imgPath, cleanup, err := face.PrepareImagePath(nil, req.FacePath)
|
||||
if err != nil {
|
||||
l.Errorf("face bind prepare image: %v", err)
|
||||
return common.FailResponse(utils.ErrorFileUpFailed), nil
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
vector, err := face.GetFaceVector(imgPath)
|
||||
if err != nil {
|
||||
l.Errorf("face bind vector: %v", err)
|
||||
return common.FailResponse(utils.ErrorNotFace), nil
|
||||
}
|
||||
if err = face.UpsertFace(loginUser.ID, vector); err != nil {
|
||||
l.Errorf("face bind milvus: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
_, err = model.UserModel{}.Init().Edit(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(bizId, utils.NumberTen)},
|
||||
}, map[string]interface{}{
|
||||
|
||||
@@ -11,6 +11,14 @@ import (
|
||||
"lone-services/services/analysis/internal/model"
|
||||
)
|
||||
|
||||
func RequireAdmin(ctx context.Context) (utils.UserInfo, *analysis.Response) {
|
||||
user := utils.GetUserFromCtx(ctx)
|
||||
if user.ID < utils.NumberOne {
|
||||
return user, FailResponse(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func RequireBizUserId(ctx context.Context) (int64, utils.UserInfo, *analysis.Response) {
|
||||
user := utils.GetUserFromCtx(ctx)
|
||||
if user.BizId < utils.NumberOne {
|
||||
|
||||
Reference in New Issue
Block a user