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

43 lines
1.1 KiB
Go
Raw Permalink 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.PublishedGiLinks = dto.ConvertFromPublishedGiLink(QueryProjectPublished(id))
return projectLink
}
// 更新项目关联关系
func UpdateProjectLink(req *dto.ProjectLinkReqDto) {
delProjectMapLink(req.Pid)
saveProjectMapLink(req.Pid, req.Mids)
}
// 删除项目地图关联关系
func delProjectMapLink(pid int32) {
dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Pid.Eq(pid)).Delete()
}
// 保存项目地图关联关系
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...)
}