Przeglądaj źródła

中控配置接口上传

maker 2 lat temu
rodzic
commit
c302d88fe4

+ 124 - 0
api/v1/task/central_control_conf.go

@@ -0,0 +1,124 @@
+package task
+
+import (
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+	"log-server/global"
+	"log-server/model/common/request"
+	"log-server/model/common/response"
+	"log-server/model/task"
+	taskRequest "log-server/model/task/request"
+	"log-server/utils"
+)
+
+type CentralControlApi struct {
+
+}
+
+//创建中控配置
+func (a *CentralControlApi) CreateCentralControlConf (c *gin.Context)  {
+	var conf task.CentralControlConf
+	_ = c.ShouldBindJSON(&conf)
+	if conf.Mirror == "" {
+		response.FailWithMessage("请传入镜像名称", c)
+		return
+	}
+	if conf.Script == "" {
+		response.FailWithMessage("请传入脚本名称", c)
+		return
+	}
+	if err := utils.Verify(conf, utils.GameChannelVerify); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	if err := centralControlService.CreateCentralControlConf(conf);err != nil {
+		global.GVA_LOG.Error("创建失败!", zap.Error(err))
+		response.FailWithMessage("创建失败", c)
+	} else {
+		response.OkWithMessage("创建成功", c)
+	}
+}
+
+//删除配置列表
+func (a *CentralControlApi) DeleteCentralControlConf(c *gin.Context) {
+	var conf task.CentralControlConf
+	 _ = c.ShouldBindJSON(&conf)
+
+	 //数据校验
+	 if err := utils.Verify(conf, utils.CentralControlConfVerify); err != nil {
+		 response.FailWithMessage(err.Error(), c)
+		 return
+	 }
+	if err := centralControlService.DeleteCentralControlConf(conf); err != nil {
+		global.GVA_LOG.Error("删除失败!", zap.Error(err))
+		response.FailWithMessage("删除失败", c)
+	} else {
+		response.OkWithMessage("删除成功", c)
+	}
+}
+
+//批量删除配置列表
+func (a *CentralControlApi) DeleteCentralControlConfByIds(c *gin.Context) {
+	var ids request.IdsReq
+	_ = c.ShouldBindJSON(&ids)
+	if err := centralControlService.DeleteCentralControlConfByIds(ids.Ids); err != nil {
+		global.GVA_LOG.Error("删除失败!", zap.Error(err))
+		response.FailWithMessage("删除失败", c)
+	} else {
+		response.OkWithMessage("删除成功", c)
+	}
+}
+
+//更新中控配置
+func (a *CentralControlApi) UpdateCentralControlConf (c *gin.Context)  {
+	var conf task.CentralControlConf
+	_ = c.ShouldBindJSON(&conf)
+	if err := utils.Verify(conf, utils.CentralControlConfVerify); err != nil{
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	if err := centralControlService.UpdateCentralControlConf(conf); err != nil{
+		global.GVA_LOG.Error("更新失败!", zap.Error(err))
+		response.FailWithMessage("更新失败", c)
+	} else {
+		response.OkWithMessage("更新成功", c)
+	}
+}
+
+func (a *CentralControlApi) GetCentralControlConfById (c *gin.Context)  {
+	var id request.GetById
+	_ = c.ShouldBindJSON(&id)
+	if err := utils.Verify(id, utils.IdVerify); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	if conf, err := centralControlService.GetCentralControlConfById(id.ID); err != nil{
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		response.OkWithDetailed(conf, "获取成功", c)
+	}
+}
+
+//获取中控配置列表
+func (a *CentralControlApi) GetCentralControlConfList (c *gin.Context)  {
+	//获取前端传值并校验
+	var pageInfo taskRequest.SearchCentralControlConfParams
+	_ = c.ShouldBindJSON(&pageInfo)
+	//页面信息校验
+	if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil{
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	if list, total, err := centralControlService.GetCentralControlConfList(pageInfo.CentralControlConf, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil{
+		global.GVA_LOG.Error("获取失败!", zap.Error(err))
+		response.FailWithMessage("获取失败", c)
+	} else {
+		response.OkWithDetailed(response.PageResult{
+			List:     list,
+			Total:    total,
+			Page:     pageInfo.Page,
+			PageSize: pageInfo.PageSize,
+		}, "获取成功", c)
+	}
+}

+ 2 - 0
api/v1/task/enter.go

@@ -5,9 +5,11 @@ import "log-server/service"
 type GroupTask struct {
 	GameTaskApi
 	TaskConfApi
+	CentralControlApi
 }
 
 var (
 	taskService = service.ServiceGroupApp.TaskServiceGroup.GameTask
 	taskConfService = service.ServiceGroupApp.TaskServiceGroup.TaskConfService
+	centralControlService = service.ServiceGroupApp.TaskServiceGroup.CentralControlService
 )

+ 2 - 1
initialize/router.go

@@ -22,7 +22,7 @@ func Routers() *gin.Engine {
 	computerRouter := router.RouterGroupApp.Computer
 	taskRouter := router.RouterGroupApp.Task
 	uploadFileRouter := router.RouterGroupApp.UploadFile
-
+	centralControlRouter := router.RouterGroupApp.CentralControl
 	ipLogRouter := router.RouterGroupApp.IpLog
 	idCardRouter := router.RouterGroupApp.IdCard
 	typeManageRouter := router.RouterGroupApp.TypeManage
@@ -71,6 +71,7 @@ func Routers() *gin.Engine {
 		idCardRouter.InitIdCardRouter(PublicGroup)                //身份证路由
 		taskRouter.InitGameTaskRouter(PublicGroup)
 		uploadFileRouter.InitUploadFileRouter(PublicGroup)
+		centralControlRouter.InitCentralControlRouter(PublicGroup)  //中控配置
 		rentComputerRouter.InitRentComputerRouter(PublicGroup)     //租机管理
 		rentComputerRouter.InitRentComputerShopRouter(PublicGroup) // 租机供应商管理
 		rentComputerRouter.InitRentSetMealRouter(PublicGroup)

+ 31 - 0
model/task/central_control_conf.go

@@ -0,0 +1,31 @@
+package task
+
+import "log-server/model/typeManage"
+
+type CentralControlConf struct {
+	Id            int                  `json:"id"`
+	Mirror        string               `json:"mirror"`         //镜像
+	Script        string               `json:"script"`         //脚本
+	CloneMode     string               `json:"clone_mode"`     //克隆模式
+	SimulatorType string               `json:"simulator_type"` //模拟器类型
+	Resolution    string               `json:"resolution"`     //分辨率
+	Zoom          string               `json:"zoom"`           //缩放
+	Timeout       int                  `json:"timeout"`        //超时时间
+	Cpu           int                  `json:"cpu"`            //cpu
+	MemorySize    int                  `json:"memory_size"`    //内存
+	TaskId        int                  `json:"task_id"`        //任务id
+	GameId        int                  `json:"game_id"`        //游戏id
+	Priority      string               `json:"priority"`       //优先级
+	GameType      int                  `json:"game_type"`   //任务类型
+	TxChannel     string               `json:"tx_channel"`     //'腾讯渠道号',
+	TxGameId      string               `json:"tx_game_id"`     //'腾讯游戏id',
+	MzChannel     string               `json:"mz_channel"`     //'魅族渠道号',
+	MzGameId      string               `json:"mz_game_id"`     //'魅族游戏id',
+	PayPrice      int                  `json:"pay_price"`      //'付费单价',
+	CreateTime    typeManage.LocalTime `json:"create_time"`
+	UpdateTime    typeManage.LocalTime `json:"update_time"`
+}
+
+func (CentralControlConf) TableName() string {
+	return "central_control_conf"
+}

+ 14 - 0
model/task/request/search_central_control_conf_params.go

@@ -0,0 +1,14 @@
+package request
+
+import (
+	"log-server/model/common/request"
+	"log-server/model/task"
+)
+
+type SearchCentralControlConfParams struct {
+	task.CentralControlConf
+	request.PageInfo
+	OrderKey string `json:"orderKey"` // 排序
+	Desc     bool   `json:"desc"`     // 排序方式:升序false(默认)|降序true
+}
+

+ 13 - 12
router/enter.go

@@ -13,18 +13,19 @@ import (
 )
 
 type RouterGroup struct {
-	System         system.RouterGroup
-	Example        example.RouterGroup
-	Loging         log.RouterGroup
-	Computer       log.ComputerRouter
-	TypeManage     typeManage.RouterGroup
-	Task           task.GameTaskRouter
-	UploadFile     task.UploadFileRouter
-	RentComputer   rentComputer.RouterGroup
-	DataStatistics dataStatistics.RouterGroup
-	FileManager    fileManager.RouterGroup
-	IpLog          log.IpLogRouter
-	IdCard         card.IdCardRouter
+	System             system.RouterGroup
+	Example            example.RouterGroup
+	Loging             log.RouterGroup
+	Computer           log.ComputerRouter
+	TypeManage         typeManage.RouterGroup
+	Task               task.GameTaskRouter
+	UploadFile         task.UploadFileRouter
+	CentralControl task.CentralControlRouter
+	RentComputer       rentComputer.RouterGroup
+	DataStatistics     dataStatistics.RouterGroup
+	FileManager        fileManager.RouterGroup
+	IpLog              log.IpLogRouter
+	IdCard             card.IdCardRouter
 }
 
 var RouterGroupApp = new(RouterGroup)

+ 29 - 0
router/task/central_control_conf.go

@@ -0,0 +1,29 @@
+package task
+
+import (
+"github.com/gin-gonic/gin"
+v1 "log-server/api/v1"
+	"log-server/middleware"
+)
+
+type CentralControlRouter struct {
+
+}
+
+func (r *CentralControlRouter) InitCentralControlRouter(Router *gin.RouterGroup) {
+	GameTaskRouter := Router.Group("gameTask")
+	centralControlConfApi := v1.ApiGroupApp.GroupTask.CentralControlApi
+	{
+		GameTaskRouter.POST("getCentralControlConfList", centralControlConfApi.GetCentralControlConfList)  //获取配置列表
+		GameTaskRouter.POST("getCentralControlConfById", centralControlConfApi.GetCentralControlConfById)  //通过id获取单个配置
+
+	}
+
+	centralControlConfApi1 := Router.Group("gameTask").Use(middleware.OperationRecord())
+	{
+		centralControlConfApi1.POST("createCentralControlConf", centralControlConfApi.CreateCentralControlConf)   //创建中控配置
+		centralControlConfApi1.POST("deleteCentralControlConf", centralControlConfApi.DeleteCentralControlConf)   //单个删除中控配置
+		centralControlConfApi1.DELETE("deleteCentralControlConfByIds", centralControlConfApi.DeleteCentralControlConfByIds)   //批量删除中控配置
+		centralControlConfApi1.POST("updateCentralControlConf", centralControlConfApi.UpdateCentralControlConf)   //更新中控配置
+	}
+}

+ 111 - 0
service/task/central_control_conf.go

@@ -0,0 +1,111 @@
+package task
+
+import (
+	"errors"
+	"fmt"
+	"gorm.io/gorm"
+	"log-server/global"
+	"log-server/model/common/request"
+	"log-server/model/task"
+)
+
+type CentralControlService struct {
+
+}
+
+//创建配置记录
+func (s *CentralControlService) CreateCentralControlConf(conf task.CentralControlConf) (err error) {
+	//查找是否有这个taskId的记录
+	var entity task.CentralControlConf
+	err = global.GVA_DB.Model(&task.CentralControlConf{}).Where("task_id", conf.TaskId).First(&entity).Error
+	//如果有,报错返回
+	if !errors.Is(err, gorm.ErrRecordNotFound) {
+		return errors.New("已有配置记录,请勿重复添加")
+	}
+	//如果没有,直接创建
+	return global.GVA_DB.Model(&task.CentralControlConf{}).Omit("create_time", "update_time").Create(&conf).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) {
+		return errors.New("此配置不存在,无法删除")
+	}
+	return global.GVA_DB.Model(&task.CentralControlConf{}).Delete(&entity).Error
+}
+
+//批量删除中控配置记录
+func (s *CentralControlService) DeleteCentralControlConfByIds(ids []int) (err error) {
+	err = global.GVA_DB.Model(&task.CentralControlConf{}).Delete("id in ?", ids).Error
+	return err
+}
+
+//更新中控配置列表
+func (s *CentralControlService) UpdateCentralControlConf(conf task.CentralControlConf) (err error) {
+	var entity task.CentralControlConf
+	err = global.GVA_DB.Model(&task.CentralControlConf{}).Where("task_id = ? and id != ?", conf.TaskId, conf.Id).First(&entity).Error
+	if !errors.Is(err, gorm.ErrRecordNotFound) {
+		return errors.New("已存在相同的task_id,无法更改")
+	}
+	return global.GVA_DB.Model(&task.CentralControlConf{}).Where("id", conf.Id).Updates(&conf).Error
+}
+
+//通过id获取单条配置
+func (s *CentralControlService) GetCentralControlConfById(id int) (conf task.CentralControlConf, err error) {
+	err = global.GVA_DB.Model(&task.CentralControlConf{}).Where("id", id).First(&conf).Error
+	return conf, err
+}
+
+//获取配置列表
+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.CentralControlConf
+
+	//先条件过滤
+	if conf.TaskId != 0 {
+		//条件过滤记录数
+		db = db.Where("task_id", conf.TaskId)
+	}
+
+	err = db.Count(&total).Error
+	if err != nil{
+		//如果出错直接返回
+		return confList, total, err
+	} else {
+		//先分页再排序
+		db = db.Limit(limit).Offset(offset)
+		if order != ""{
+			//传入排序字段,进行排序
+			//定义orderStr存储完整的排序字段
+			var  orderStr string
+			//为了避免sql注入,自己创建数组匹配
+			orderMap := make(map[string]bool, 3)
+			orderMap["task_id"] = true
+			orderMap["create_time"] = true
+			orderMap["update_time"] = true
+			if orderMap[order] {
+				if desc {
+					orderStr = order + " desc"
+				} else {
+					orderStr = order
+				}
+			} else {
+				//传入非法字段,不能排序
+				err = fmt.Errorf("传入非法字段 %v", order)
+				return confList, total, err
+			}
+			//排序
+			err = db.Order(orderStr).Find(&confList).Error
+		} else {
+			//没有传入排序字段,默认按照类型名称降序排序
+			err = db.Order("id desc").Find(&confList).Error
+		}
+	}
+	//是因为只有切片能排序,model没办法排序;还是说为了将数组返回至前端才find扫描至切片呢?
+	return confList, total, err
+}

+ 1 - 0
service/task/enter.go

@@ -3,4 +3,5 @@ package task
 type ServiceGroup struct {
 	GameTask
 	TaskConfService
+	CentralControlService
 }

+ 10 - 9
utils/verify.go

@@ -21,13 +21,14 @@ var (
 	PcVerify               = Rules{"PcCode": {NotEmpty()}, "User": {NotEmpty()}, "Supplier": {NotEmpty()}}
 
 	//自己添加的校验
-	GameChannelVerify       = Rules{"ChannelName": {NotEmpty()}, "ChannelDesc": {NotEmpty()}, "DisplaySequence": {NotEmpty()}}
-	GameListVerify          = Rules{"GameName": {NotEmpty()}, "GamePort": {NotEmpty()}, "LoginType": {NotEmpty()}}
-	LoginTypeVerify         = Rules{"LoginName": {NotEmpty()}, "LoginDesc": {NotEmpty()}}
-	ResponsiblePersonVerify = Rules{"Name": {NotEmpty()} }
-	AccountTypeVerify       = Rules{"TypeName": {NotEmpty()}}
-	GameTaskVerify          = Rules{"TaskId": {NotEmpty()}, "TaskName": {NotEmpty()}, "User": {NotEmpty()}, "NewRetained": {NotEmpty()}, "GamePortId": {NotEmpty()}}
-	TaskIdVerify            = Rules{"TaskId": {NotEmpty()}}
-	UpdateTargetVerify      = Rules{"TaskId": {NotEmpty()}, "CreateDate": {NotEmpty()}}
-	TaskConfVerify          = Rules{"User": {NotEmpty()}}
+	GameChannelVerify        = Rules{"ChannelName": {NotEmpty()}, "ChannelDesc": {NotEmpty()}, "DisplaySequence": {NotEmpty()}}
+	GameListVerify           = Rules{"GameName": {NotEmpty()}, "GamePort": {NotEmpty()}, "LoginType": {NotEmpty()}}
+	LoginTypeVerify          = Rules{"LoginName": {NotEmpty()}, "LoginDesc": {NotEmpty()}}
+	ResponsiblePersonVerify  = Rules{"Name": {NotEmpty()}}
+	AccountTypeVerify        = Rules{"TypeName": {NotEmpty()}}
+	GameTaskVerify           = Rules{"TaskId": {NotEmpty()}, "TaskName": {NotEmpty()}, "User": {NotEmpty()}, "NewRetained": {NotEmpty()}, "GamePortId": {NotEmpty()}}
+	TaskIdVerify             = Rules{"TaskId": {NotEmpty()}}
+	UpdateTargetVerify       = Rules{"TaskId": {NotEmpty()}, "CreateDate": {NotEmpty()}}
+	TaskConfVerify           = Rules{"User": {NotEmpty()}}
+	CentralControlConfVerify = Rules{"Cpu": {NotEmpty()}, "MemorySize": {NotEmpty()}, "TaskId": {NotEmpty()}, "GameId": {NotEmpty()}} //中控配置校验
 )