71 lines
1.9 KiB
Go
71 lines
1.9 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.TrainSizeLinks = dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(id))
|
||
|
// 关联地图列表
|
||
|
projectLink.PublishedGiLinks = dto.ConvertFromPublishedGiLink(QueryPublishedGi(id))
|
||
|
return projectLink
|
||
|
}
|
||
|
|
||
|
// 通过地图ID获取列车尺寸列表
|
||
|
func QueryTrainSizeByMapId(mid int32) []*dto.TrainSizeDto {
|
||
|
pl, err := dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Mid.Eq(mid)).First()
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
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) {
|
||
|
for _, sid := range sids {
|
||
|
dbquery.ProjectTrainSizeLink.Save(&model.ProjectTrainSizeLink{
|
||
|
Pid: pid,
|
||
|
Sid: *sid,
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 保存项目地图关联关系
|
||
|
func saveProjectMapLink(pid int32, mids []*int32) {
|
||
|
for _, mid := range mids {
|
||
|
dbquery.ProjectPublishLink.Save(&model.ProjectPublishLink{
|
||
|
Pid: pid,
|
||
|
Mid: *mid,
|
||
|
})
|
||
|
}
|
||
|
}
|