rts-sim-testing-service/service/projectRunConfig.go

83 lines
2.6 KiB
Go
Raw Normal View History

package service
import (
"fmt"
"time"
"joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/sys_error"
)
// 查询项目运行环境列表带分页
func PageProjectRunConfigQuery(query *dto.PageProjectRunConfigReqDto) *dto.PageDto {
d := dbquery.ProjectRunConfig
dq := d.Where()
if query.Name != "" {
dq = dq.Where(d.Name.Like(fmt.Sprintf("%%%s%%", query.Name)))
}
records, total, err := dq.Debug().Omit(d.ConfigContent).FindByPage(query.Offset(), query.Size)
if err != nil {
panic(sys_error.New("查询失败,数据库错误请联系运维人员", err))
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询项目运行环境列表
func ListProjectRunConfigQuery() []*dto.ProjectRunConfigDto {
records, err := dbquery.ProjectRunConfig.Debug().Omit(dbquery.ProjectRunConfig.ConfigContent).Find()
if err != nil {
panic(sys_error.New("查询失败,数据库错误请联系运维人员", err))
}
return dto.ConvertToRunConfigFromSlice(records)
}
// 创建项目运行环境
func CreateProjectRunConfig(dd *dto.ProjectRunConfigReqDto) bool {
d := model.ProjectRunConfig{
Name: dd.Name,
Description: dd.Description,
ConfigContent: dd.ConfigContent,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
err := dbquery.ProjectRunConfig.Save(&d)
if err != nil {
panic(sys_error.New("保存失败,数据库错误请联系运维人员", err))
}
return true
}
// 查询项目运行环境
func QueryProjectRunConfig(id int32) *dto.ProjectRunConfigDto {
query, err := dbquery.ProjectRunConfig.Where(dbquery.ProjectRunConfig.ID.Eq(id)).Debug().First()
if err != nil {
panic(sys_error.New("查询失败,不存在此信息", err))
}
return dto.ConvertToRunConfigDto(query)
}
// 更新项目运行环境
func UpdateProjectRunConfig(id int32, dd *dto.ProjectRunConfigReqDto) bool {
findOldQuery := dbquery.ProjectRunConfig
oldD, err := findOldQuery.Where(findOldQuery.ID.Eq(id)).Debug().First()
if oldD == nil || err != nil {
panic(sys_error.New("保存失败,不存在此信息", err))
}
oldD.Name = dd.Name
oldD.Description = dd.Description
oldD.ConfigContent = dd.ConfigContent
oldD.UpdateTime = time.Now()
_, err2 := findOldQuery.Updates(oldD)
if err2 != nil {
panic(sys_error.New("保存失败,请联系维护人员", err2))
}
return true
}
// 删除项目运行环境
func DeleteProjectRunConfigById(id int32) {
dbquery.ProjectRunConfig.Debug().Where(dbquery.ProjectRunConfig.ID.Eq(id)).Delete()
}