初始
This commit is contained in:
@ -0,0 +1,153 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2024-06-21 15:23:29
|
||||
// 生成路径: internal/app/system/logic/manage_operation_log.go
|
||||
// 生成人:gfast
|
||||
// desc:无人机指令日志
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterManageOperationLog(New())
|
||||
}
|
||||
|
||||
func New() *sManageOperationLog {
|
||||
return &sManageOperationLog{}
|
||||
}
|
||||
|
||||
type sManageOperationLog struct{}
|
||||
|
||||
func (s *sManageOperationLog) List(ctx context.Context, req *system.ManageOperationLogSearchReq) (listRes *system.ManageOperationLogSearchRes, err error) {
|
||||
listRes = new(system.ManageOperationLogSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.ManageOperationLog.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.ManageOperationLog.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.Sn != "" {
|
||||
m = m.Where(dao.ManageOperationLog.Columns().Sn+" = ?", req.Sn)
|
||||
}
|
||||
if req.Method != "" {
|
||||
m = m.Where(dao.ManageOperationLog.Columns().Method+" = ?", req.Method)
|
||||
}
|
||||
if req.Direction != "" {
|
||||
m = m.Where(dao.ManageOperationLog.Columns().Direction+" = ?", req.Direction)
|
||||
}
|
||||
if req.Code != "" {
|
||||
m = m.Where(dao.ManageOperationLog.Columns().Code+" = ?", gconv.Int(req.Code))
|
||||
}
|
||||
if req.Operator != "" {
|
||||
m = m.Where(dao.ManageOperationLog.Columns().Operator+" = ?", gconv.Int64(req.Operator))
|
||||
}
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.ManageOperationLogInfoRes
|
||||
err = m.Fields(system.ManageOperationLogSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.ManageOperationLogListRes, len(res))
|
||||
for k, v := range res {
|
||||
ren := "系统"
|
||||
if v.Operator != 0 {
|
||||
value, _ := dao.SysUser.Ctx(ctx).WherePri(v.Operator).Fields("user_nickname").Value()
|
||||
ren = value.String()
|
||||
}
|
||||
listRes.List[k] = &model.ManageOperationLogListRes{
|
||||
Id: v.Id,
|
||||
Sn: v.Sn,
|
||||
Method: v.Method,
|
||||
Direction: v.Direction,
|
||||
Code: v.Code,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Operator: v.Operator,
|
||||
OperatorRen: ren,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageOperationLog) GetById(ctx context.Context, id int64) (res *model.ManageOperationLogInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.ManageOperationLog.Ctx(ctx).WithAll().Where(dao.ManageOperationLog.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageOperationLog) Add(ctx context.Context, req *system.ManageOperationLogAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ManageOperationLog.Ctx(ctx).Insert(do.ManageOperationLog{
|
||||
Sn: req.Sn,
|
||||
Method: req.Method,
|
||||
Direction: req.Direction,
|
||||
Code: req.Code,
|
||||
Operator: req.Operator,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageOperationLog) Edit(ctx context.Context, req *system.ManageOperationLogEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ManageOperationLog.Ctx(ctx).WherePri(req.Id).Update(do.ManageOperationLog{
|
||||
Sn: req.Sn,
|
||||
Method: req.Method,
|
||||
Direction: req.Direction,
|
||||
Code: req.Code,
|
||||
Operator: req.Operator,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageOperationLog) Delete(ctx context.Context, ids []int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ManageOperationLog.Ctx(ctx).Delete(dao.ManageOperationLog.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func AddLog(ctx context.Context, sn, method, direction string, code int) error {
|
||||
req := system.ManageOperationLogAddReq{
|
||||
Sn: sn,
|
||||
Method: method,
|
||||
Direction: direction,
|
||||
Code: code,
|
||||
}
|
||||
user := ct.New().GetLoginUser(ctx)
|
||||
if user != nil {
|
||||
req.Operator = int64(user.Id)
|
||||
}
|
||||
err := service.ManageOperationLog().Add(ctx, &req)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user