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

75 lines
2.2 KiB
Go
Raw Normal View History

package service
import (
"joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
)
// 获取项目的关联关系
func QueryProjectLinkInfo(id int32) *dto.ProjectLinkRspDto {
pro, proErr := dbquery.Project.Where(dbquery.Project.ID.Eq(id)).First()
if proErr != nil {
panic(proErr)
}
projectLink := dto.ConvertProjectLink(pro)
// 关联列车尺寸列表
projectLink.TrainSizeLinks = dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(id))
// 关联地图列表
2023-08-31 16:16:18 +08:00
projectLink.PublishedGiLinks = dto.ConvertFromPublishedGiLink(QueryProjectPublishedGi(id))
return projectLink
}
// 通过地图ID获取列车尺寸列表
func QueryTrainSizeByMapId(mid int32) []*dto.TrainSizeDto {
pl, err := dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Mid.Eq(mid)).First()
if err != nil {
2023-08-30 18:05:11 +08:00
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(pl.Pid))
}
// 更新项目关联关系
func UpdateProjectLink(req *dto.ProjectLinkReqDto) {
// 删除原来信息
delProjectSizeLink(req.Pid)
delProjectMapLink(req.Pid)
// 保存新关联关系
saveProjectSize(req.Pid, req.Sids)
saveProjectMapLink(req.Pid, req.Mids)
}
// 删除项目列车尺寸关联关系
func delProjectSizeLink(pid int32) {
dbquery.ProjectTrainSizeLink.Where(dbquery.ProjectTrainSizeLink.Pid.Eq(pid)).Delete()
}
// 删除项目地图关联关系
func delProjectMapLink(pid int32) {
dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Pid.Eq(pid)).Delete()
}
// 保存项目尺寸关联关系
func saveProjectSize(pid int32, sids []*int32) {
2023-08-31 16:16:18 +08:00
if len(sids) == 0 {
2023-09-01 10:46:22 +08:00
return
}
2023-09-01 10:46:22 +08:00
sizeInfos := make([]*model.ProjectTrainSizeLink, len(sids))
for i, sid := range sids {
sizeInfos[i] = &model.ProjectTrainSizeLink{Pid: pid, Sid: *sid}
}
dbquery.ProjectTrainSizeLink.Save(sizeInfos...)
}
// 保存项目地图关联关系
func saveProjectMapLink(pid int32, mids []*int32) {
2023-08-31 16:16:18 +08:00
if len(mids) == 0 {
2023-09-01 10:46:22 +08:00
return
}
mapInfos := make([]*model.ProjectPublishLink, len(mids))
for i, mid := range mids {
mapInfos[i] = &model.ProjectPublishLink{Pid: pid, Mid: *mid}
}
2023-09-01 10:46:22 +08:00
dbquery.ProjectPublishLink.Save(mapInfos...)
}