65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package analysisdevicelogic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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 DisplayLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewDisplayLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DisplayLogic {
|
|
return &DisplayLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *DisplayLogic) Display(in *analysis.DeviceDisplayReq) (*analysis.Response, error) {
|
|
var req validator.DeviceDisplayValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return common.OutResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
loginUser := utils.GetUserFromCtx(l.ctx)
|
|
if !loginUser.Valid || loginUser.ID < utils.NumberOne {
|
|
return common.FailResponse(utils.ErrorNoLogin), nil
|
|
}
|
|
|
|
var task dao.ImageAnalysis
|
|
err := model.ImageAnalysisModel{}.Init().GetOne(modelbase.Params{
|
|
Eq: map[string]string{"task_id": req.TaskId},
|
|
}, &task)
|
|
if err != nil {
|
|
l.Errorf("device display get analysis: %v", err)
|
|
return common.FailResponse(utils.Fail), nil
|
|
}
|
|
|
|
if task.Status == dao.AnalysisStatusDone && task.Qrcode != utils.StringEmpty {
|
|
return common.OkResponse(dao.ReportDisplayResource{
|
|
Status: dao.DisplayStatusReady,
|
|
Qrcode: task.Qrcode,
|
|
}), nil
|
|
}
|
|
|
|
return common.OkResponse(dao.ReportDisplayResource{
|
|
Status: dao.DisplayStatusWaiting,
|
|
Qrcode: utils.StringEmpty,
|
|
}), nil
|
|
}
|