78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
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))
|
|
// TODO:前端修改完成后删除
|
|
// 关联列车尺寸列表
|
|
projectLink.TrainSizeLinks = dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(id))
|
|
return projectLink
|
|
}
|
|
|
|
// 更新项目关联关系
|
|
func UpdateProjectLink(req *dto.ProjectLinkReqDto) {
|
|
delProjectMapLink(req.Pid)
|
|
saveProjectMapLink(req.Pid, req.Mids)
|
|
|
|
// TODO:前端修改完成后删除
|
|
// 保存新关联关系
|
|
delProjectSizeLink(req.Pid)
|
|
saveProjectSize(req.Pid, req.Sids)
|
|
}
|
|
|
|
// 删除项目地图关联关系
|
|
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...)
|
|
}
|
|
|
|
// TODO: 以下代码前端修改完成后删除
|
|
// 通过地图ID获取列车尺寸列表
|
|
func QueryTrainSizeByMapId(mid int32) []*dto.TrainSizeDto {
|
|
pl, err := dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Mid.Eq(mid)).First()
|
|
if err != nil {
|
|
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
|
|
}
|
|
return dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(pl.Pid))
|
|
}
|
|
|
|
// 保存项目尺寸关联关系
|
|
func saveProjectSize(pid int32, sids []*int32) {
|
|
if len(sids) == 0 {
|
|
return
|
|
}
|
|
sizeInfos := make([]*model.ProjectTrainSizeLink, len(sids))
|
|
for i, sid := range sids {
|
|
sizeInfos[i] = &model.ProjectTrainSizeLink{Pid: pid, Sid: *sid}
|
|
}
|
|
dbquery.ProjectTrainSizeLink.Save(sizeInfos...)
|
|
}
|
|
|
|
// 删除项目列车尺寸关联关系
|
|
func delProjectSizeLink(pid int32) {
|
|
dbquery.ProjectTrainSizeLink.Where(dbquery.ProjectTrainSizeLink.Pid.Eq(pid)).Delete()
|
|
}
|