初始
This commit is contained in:
171
internal/app/system/logic/manageTask/manage_task.go
Normal file
171
internal/app/system/logic/manageTask/manage_task.go
Normal file
@ -0,0 +1,171 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-12-12 15:21:22
|
||||
// 生成路径: internal/app/system/logic/manage_task.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.RegisterManageTask(New())
|
||||
}
|
||||
|
||||
func New() *sManageTask {
|
||||
return &sManageTask{}
|
||||
}
|
||||
|
||||
type sManageTask struct{}
|
||||
|
||||
func (s *sManageTask) List(ctx context.Context, req *system.ManageTaskSearchReq) (listRes *system.ManageTaskSearchRes, err error) {
|
||||
listRes = new(system.ManageTaskSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.ManageTask.Ctx(ctx).WithAll().As("a")
|
||||
if req.Id != "" {
|
||||
m = m.Where("a."+dao.ManageTask.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
if req.TaskName != "" {
|
||||
m = m.Where("a."+dao.ManageTask.Columns().TaskName+" like ?", "%"+req.TaskName+"%")
|
||||
}
|
||||
if req.MqClientId != "" {
|
||||
m = m.Where(dao.ManageTask.Columns().MqClientId+" = ?", gconv.Int64(req.MqClientId))
|
||||
}
|
||||
if req.AirLine != "" {
|
||||
m = m.Where("a."+dao.ManageTask.Columns().AirLine+" = ?", gconv.Int64(req.AirLine))
|
||||
}
|
||||
if req.ProjectId != "" {
|
||||
m = m.Where("a."+dao.ManageTask.Columns().ProjectId+" = ?", gconv.Int64(req.ProjectId))
|
||||
}
|
||||
if len(req.DateRange) != 0 {
|
||||
m = m.Where("a."+dao.ManageTask.Columns().CreatedAt+" >=? AND "+"a."+dao.ManageTask.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
|
||||
}
|
||||
m = m.LeftJoin("manage_airline", "b", "a.air_line=b.id").
|
||||
LeftJoin("manage_device", "c", "a.mq_client_id=c.id").
|
||||
Fields("a.*,b.air_line as airLineName,c.device_name as deviceName")
|
||||
array, err := m.Array()
|
||||
listRes.Total = len(array)
|
||||
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.ManageTaskInfoRes
|
||||
err = m.Page(req.PageNum, req.PageSize).Order("a." + order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.ManageTaskListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.ManageTaskListRes{
|
||||
Id: v.Id,
|
||||
TaskName: v.TaskName,
|
||||
FlightId: v.FlightId,
|
||||
TaskType: v.TaskType,
|
||||
ExecuteTime: v.ExecuteTime,
|
||||
WaylineType: v.WaylineType,
|
||||
AirLine: v.AirLine,
|
||||
ProjectId: v.ProjectId,
|
||||
RthAltitude: v.RthAltitude,
|
||||
RthMode: v.RthMode,
|
||||
OutOfControlAction: v.OutOfControlAction,
|
||||
ExitWaylineWhenRcLost: v.ExitWaylineWhenRcLost,
|
||||
CreateBy: v.CreateBy,
|
||||
UpdateBy: v.UpdateBy,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Remark: v.Remark,
|
||||
AirLineName: v.AirLineName,
|
||||
DeviceName: v.DeviceName,
|
||||
MqClientId: v.MqClientId,
|
||||
}
|
||||
//判断当前数据是否有开启定时任务
|
||||
count, _ := dao.ManageTaskCron.Ctx(ctx).WithAll().Where(dao.ManageTaskCron.Columns().TaskId, v.Id).Count()
|
||||
if count > 0 {
|
||||
listRes.List[k].IsCron = 1
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageTask) GetById(ctx context.Context, id int64) (res *model.ManageTaskInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.ManageTask.Ctx(ctx).WithAll().Where(dao.ManageTask.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageTask) Add(ctx context.Context, req *system.ManageTaskAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ManageTask.Ctx(ctx).Insert(do.ManageTask{
|
||||
TaskName: req.TaskName,
|
||||
//FlightId: strings.ReplaceAll(uuid.NewV4().String(), "-", ""),
|
||||
//TaskType: req.TaskType,
|
||||
//ExecuteTime: req.ExecuteTime,
|
||||
WaylineType: req.WaylineType,
|
||||
Airport: req.Airport,
|
||||
AirLine: req.AirLine,
|
||||
ProjectId: req.ProjectId,
|
||||
RthAltitude: req.RthAltitude,
|
||||
RthMode: req.RthMode,
|
||||
OutOfControlAction: req.OutOfControlAction,
|
||||
ExitWaylineWhenRcLost: req.ExitWaylineWhenRcLost,
|
||||
CreateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
Remark: req.Remark,
|
||||
MqClientId: req.MqClientId,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageTask) Edit(ctx context.Context, req *system.ManageTaskEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ManageTask.Ctx(ctx).WherePri(req.Id).Update(do.ManageTask{
|
||||
TaskName: req.TaskName,
|
||||
//TaskType: req.TaskType,
|
||||
//ExecuteTime: req.ExecuteTime,
|
||||
WaylineType: req.WaylineType,
|
||||
Airport: req.Airport,
|
||||
AirLine: req.AirLine,
|
||||
ProjectId: req.ProjectId,
|
||||
RthAltitude: req.RthAltitude,
|
||||
RthMode: req.RthMode,
|
||||
OutOfControlAction: req.OutOfControlAction,
|
||||
ExitWaylineWhenRcLost: req.ExitWaylineWhenRcLost,
|
||||
UpdateBy: ct.New().GetLoginUser(ctx).Id,
|
||||
Remark: req.Remark,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sManageTask) Delete(ctx context.Context, ids int64) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.ManageTask.Ctx(ctx).Unscoped().Delete(dao.ManageTask.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user