|
|
@@ -10,6 +10,7 @@ import (
|
|
|
)
|
|
|
|
|
|
type CentralControlService struct {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//创建配置记录
|
|
|
@@ -26,7 +27,7 @@ func (s *CentralControlService) CreateCentralControlConf(conf task.CentralContro
|
|
|
}
|
|
|
|
|
|
//删除中控配置记录
|
|
|
-func (s *CentralControlService) DeleteCentralControlConf(conf task.CentralControlConf) (err error) {
|
|
|
+func (s *CentralControlService) DeleteCentralControlConf(conf task.CentralControlConf) (err error) {
|
|
|
var entity task.CentralControlConf
|
|
|
err = global.GVA_DB.Model(&task.CentralControlConf{}).Where("id", conf.Id).First(&entity).Error
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
@@ -58,36 +59,30 @@ func (s *CentralControlService) GetCentralControlConfById(id int) (conf task.Cen
|
|
|
}
|
|
|
|
|
|
//获取配置列表
|
|
|
-func (s *CentralControlService) GetCentralControlConfList(conf task.CentralControlConfList, info request.PageInfo, order string, desc bool) (list interface{}, total int64, err error) {
|
|
|
+func (s *CentralControlService) GetCentralControlConfList(conf task.CentralControlConf, info request.PageInfo, order string, desc bool) (list interface{}, total int64, err error){
|
|
|
//获取limit和offset
|
|
|
limit := info.PageSize
|
|
|
offset := (info.Page - 1) * info.PageSize
|
|
|
db := global.GVA_DB.Model(&task.CentralControlConf{})
|
|
|
- var confList []task.CentralControlConfList
|
|
|
+ var confList []task.CentralControlConf
|
|
|
|
|
|
- db = db.Select("central_control_conf.*, game_task.user")
|
|
|
- db = db.Joins("left join game_task on central_control_conf.task_id = game_task.task_id")
|
|
|
//先条件过滤
|
|
|
if conf.TaskId != 0 {
|
|
|
//条件过滤记录数
|
|
|
- db = db.Where("central_control_conf.task_id", conf.TaskId)
|
|
|
- }
|
|
|
-
|
|
|
- if conf.User != "" {
|
|
|
- db = db.Where("game_task.user LIKE ?", "%"+conf.User+"%")
|
|
|
+ db = db.Where("task_id", conf.TaskId)
|
|
|
}
|
|
|
|
|
|
err = db.Count(&total).Error
|
|
|
- if err != nil {
|
|
|
+ if err != nil{
|
|
|
//如果出错直接返回
|
|
|
return confList, total, err
|
|
|
} else {
|
|
|
//先分页再排序
|
|
|
db = db.Limit(limit).Offset(offset)
|
|
|
- if order != "" {
|
|
|
+ if order != ""{
|
|
|
//传入排序字段,进行排序
|
|
|
//定义orderStr存储完整的排序字段
|
|
|
- var orderStr string
|
|
|
+ var orderStr string
|
|
|
//为了避免sql注入,自己创建数组匹配
|
|
|
orderMap := make(map[string]bool, 3)
|
|
|
orderMap["task_id"] = true
|
|
|
@@ -95,7 +90,7 @@ func (s *CentralControlService) GetCentralControlConfList(conf task.CentralContr
|
|
|
orderMap["update_time"] = true
|
|
|
if orderMap[order] {
|
|
|
if desc {
|
|
|
- orderStr = "central_control_conf." + order + " desc"
|
|
|
+ orderStr = order + " desc"
|
|
|
} else {
|
|
|
orderStr = order
|
|
|
}
|
|
|
@@ -108,7 +103,7 @@ func (s *CentralControlService) GetCentralControlConfList(conf task.CentralContr
|
|
|
err = db.Order(orderStr).Find(&confList).Error
|
|
|
} else {
|
|
|
//没有传入排序字段,默认按照类型名称降序排序
|
|
|
- err = db.Order("central_control_conf.id desc").Find(&confList).Error
|
|
|
+ err = db.Order("id desc").Find(&confList).Error
|
|
|
}
|
|
|
}
|
|
|
//是因为只有切片能排序,model没办法排序;还是说为了将数组返回至前端才find扫描至切片呢?
|
|
|
@@ -116,8 +111,11 @@ func (s *CentralControlService) GetCentralControlConfList(conf task.CentralContr
|
|
|
}
|
|
|
|
|
|
//获取云配置列表
|
|
|
-func (s *CentralControlService) GetCloudConfList() (dataList []task.CentralControlConf, err error) {
|
|
|
+func (s *CentralControlService) GetCloudConfList() (dataList []task.CentralControlTaskConf, err error) {
|
|
|
//获取所有的中控配置列表
|
|
|
- err = global.GVA_DB.Model(&task.CentralControlConf{}).Find(&dataList).Error
|
|
|
+ db := global.GVA_DB.Model(&task.CentralControlConf{})
|
|
|
+ db = db.Select("central_control_conf.*,game_task.task_name").Joins("left join game_task on central_control_conf.task_id = game_task.task_id")
|
|
|
+ err = db.Find(&dataList).Error
|
|
|
+ //err = global.GVA_DB.Model(&task.CentralControlConf{}).Find(&dataList).Error
|
|
|
return
|
|
|
-}
|
|
|
+}
|