From 8b556ab416269a8f5145d02b45949a7c91aca5cd Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 17 Nov 2023 16:51:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=81=A2=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=86=85=E5=AE=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=AE=8C=E6=AF=95?= =?UTF-8?q?=E5=90=8E=E7=BB=9F=E4=B8=80=E5=88=A0=E9=99=A4=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/projectLink.go | 57 ++++++++++++++++++++++++++++++++++++++++++ dto/projectLink.go | 6 +++++ service/projectLink.go | 35 ++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/api/projectLink.go b/api/projectLink.go index db5a8a6..ea40021 100644 --- a/api/projectLink.go +++ b/api/projectLink.go @@ -17,6 +17,9 @@ func InitProjectLinkRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl authed := api.Group("/v1/projectLink").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware) authed.GET("/info/:id", queryProjectLinkInfo) authed.POST("", saveProjectLinkInfo) + // TODO: 前端修改完成后删除 + authed.GET("/mapInfo/trainSize/:id", queryTrainSizeByMapId) + authed.GET("/project/trainSize/:id", queryTrainSizeByPId) } // 查询项目的所有关联信息 @@ -69,3 +72,57 @@ func saveProjectLinkInfo(c *gin.Context) { service.UpdateProjectLink(&req) c.JSON(http.StatusOK, true) } + +// TODO:前端修改完成后删除 +// 通过项目ID查询项目的关联列车尺寸信息 +// +// @Summary 通过项目ID查询项目的关联列车尺寸信息 +// +// @Security JwtAuth +// +// @Description 通过项目ID查询项目的关联列车尺寸信息 +// @Tags 项目关联信息Api +// @Accept json +// @Produce json +// @Param id path int true "地图ID" +// @Success 200 {object} dto.TrainSizeDto +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/projectLink/project/trainSize/{id} [get] +func queryTrainSizeByMapId(c *gin.Context) { + id, exist := c.Params.Get("id") + if !exist { + panic(sys_error.New("查询失败,缺少id")) + } + slog.Debug("传入参数id为" + id) + int64Id, _ := strconv.ParseInt(id, 10, 64) + c.JSON(http.StatusOK, service.QueryTrainSizeByMapId(int32(int64Id))) +} + +// 通过地图ID查询项目的关联列车尺寸信息 +// +// @Summary 通过地图ID查询项目的关联列车尺寸信息 +// +// @Security JwtAuth +// +// @Description 通过地图ID查询项目的关联列车尺寸信息 +// @Tags 项目关联信息Api +// @Accept json +// @Produce json +// @Param id path int true "地图ID" +// @Success 200 {object} dto.TrainSizeDto +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/projectLink/mapInfo/trainSize/{id} [get] +func queryTrainSizeByPId(c *gin.Context) { + id, exist := c.Params.Get("id") + if !exist { + panic(sys_error.New("查询失败,缺少id")) + } + slog.Debug("传入参数id为" + id) + int64Id, _ := strconv.ParseInt(id, 10, 64) + trainSizeArr := service.QueryProjectTrainSize(int32(int64Id)) + c.JSON(http.StatusOK, dto.ConvertFromTrainSizeDto(trainSizeArr)) +} diff --git a/dto/projectLink.go b/dto/projectLink.go index d25ff02..48fbd5e 100644 --- a/dto/projectLink.go +++ b/dto/projectLink.go @@ -7,11 +7,15 @@ type ProjectLinkRspDto struct { Name string `json:"name" form:"name"` Code string `json:"code" form:"code"` PublishedGiLinks []*PublishedGiLinkDto `json:"mapInfoLinks" form:"mapInfoLinks"` + // TODO:前端修改完成后删除 + TrainSizeLinks []*TrainSizeDto `json:"trainSizeLinks" form:"trainSizeLinks"` } type ProjectLinkReqDto struct { Pid int32 `json:"pid" form:"pid"` Mids []*int32 `json:"mids" form:"mids"` + // TODO:前端修改完成后删除 + Sids []*int32 `json:"sids" form:"sids"` } type PublishedGiLinkDto struct { @@ -27,6 +31,8 @@ func ConvertProjectLink(gi *model.Project) *ProjectLinkRspDto { Name: gi.Name, Code: gi.Code, PublishedGiLinks: []*PublishedGiLinkDto{}, + // TODO:前端修改完成后删除 + TrainSizeLinks: []*TrainSizeDto{}, } } diff --git a/service/projectLink.go b/service/projectLink.go index f9b7d55..e3eaa23 100644 --- a/service/projectLink.go +++ b/service/projectLink.go @@ -15,6 +15,9 @@ func QueryProjectLinkInfo(id int32) *dto.ProjectLinkRspDto { projectLink := dto.ConvertProjectLink(pro) // 关联地图列表 projectLink.PublishedGiLinks = dto.ConvertFromPublishedGiLink(QueryProjectPublished(id)) + // TODO:前端修改完成后删除 + // 关联列车尺寸列表 + projectLink.TrainSizeLinks = dto.ConvertFromTrainSizeDto(QueryProjectTrainSize(id)) return projectLink } @@ -22,6 +25,11 @@ func QueryProjectLinkInfo(id int32) *dto.ProjectLinkRspDto { func UpdateProjectLink(req *dto.ProjectLinkReqDto) { delProjectMapLink(req.Pid) saveProjectMapLink(req.Pid, req.Mids) + + // TODO:前端修改完成后删除 + // 保存新关联关系 + delProjectSizeLink(req.Pid) + saveProjectSize(req.Pid, req.Sids) } // 删除项目地图关联关系 @@ -40,3 +48,30 @@ func saveProjectMapLink(pid int32, mids []*int32) { } 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() +}