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) { if len(mids) == 0 { return } mapInfos := make([]*model.ProjectPublishLink, len(mids)) for i, mid := range mids { mapInfos[i] = &model.ProjectPublishLink{Pid: pid, Mid: *mid} } dbquery.ProjectPublishLink.Save(mapInfos...) }