ff67c84f18
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 4m7s
128 lines
4.0 KiB
Go
128 lines
4.0 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"joylink.club/bj-rtsts-server/config"
|
|
"strings"
|
|
"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[*dto.ProjectRunConfigDto] {
|
|
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[*dto.ProjectRunConfigDto]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToRunConfigFromSlice(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 checkRunConfig(jsonConfigStr string) *sys_error.BusinessError {
|
|
var configMap config.ThirdPartyConfig
|
|
err := json.Unmarshal([]byte(jsonConfigStr), &configMap)
|
|
if err != nil {
|
|
return sys_error.New("运行环境序列化错误", err)
|
|
}
|
|
checkSameMap := make(map[string]bool)
|
|
for _, simConfig := range configMap.PcSimConfigs {
|
|
if simConfig.ConfigName == "" || len(strings.TrimSpace(simConfig.ConfigName)) == 0 {
|
|
return sys_error.New(fmt.Sprintf("车载运行配置名称不能为空 配置ip:%v,端口%v", simConfig.PcSimIp, simConfig.PcSimPort), err)
|
|
}
|
|
if checkSameMap[simConfig.ConfigName] {
|
|
return sys_error.New(fmt.Sprintf("车载运行配置重复的名称:%v", simConfig.ConfigName), err)
|
|
}
|
|
checkSameMap[simConfig.ConfigName] = true
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 创建项目运行环境
|
|
func CreateProjectRunConfig(dd *dto.ProjectRunConfigReqDto) bool {
|
|
if checkErr := checkRunConfig(dd.ConfigContent); checkErr != nil {
|
|
panic(checkErr)
|
|
}
|
|
|
|
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 QueryRunConfig(id int32) *dto.ProjectRunConfigDto {
|
|
if id == 0 {
|
|
return nil
|
|
}
|
|
query, err := dbquery.ProjectRunConfig.Where(dbquery.ProjectRunConfig.ID.Eq(id)).Find()
|
|
if err != nil {
|
|
panic(sys_error.New("查询失败", err))
|
|
}
|
|
if len(query) == 0 {
|
|
return nil
|
|
}
|
|
return dto.ConvertToRunConfigDto(query[0])
|
|
}
|
|
|
|
// 更新项目运行环境
|
|
func UpdateProjectRunConfig(id int32, dd *dto.ProjectRunConfigReqDto) bool {
|
|
if checkErr := checkRunConfig(dd.ConfigContent); checkErr != nil {
|
|
panic(checkErr)
|
|
}
|
|
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()
|
|
}
|