From e84db3a9bf25d0eeb75312ff7719962575fb0c6c Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 23 Oct 2023 09:45:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9api=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=89=93=E5=8D=B0=EF=BC=8C=E5=88=A0=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E6=96=87=E4=BB=B6=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/publishedGi.go | 44 +++++++++++------------------------------- rtss_simulation | 2 +- service/publishedGi.go | 16 +++++++++++---- service/simulation.go | 18 ----------------- 4 files changed, 24 insertions(+), 56 deletions(-) delete mode 100644 service/simulation.go diff --git a/api/publishedGi.go b/api/publishedGi.go index b4a3423..37257b5 100644 --- a/api/publishedGi.go +++ b/api/publishedGi.go @@ -8,10 +8,10 @@ import ( jwt "github.com/appleboy/gin-jwt/v2" "github.com/gin-gonic/gin" "joylink.club/bj-rtsts-server/db/model" - "joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto/publishedGi" "joylink.club/bj-rtsts-server/middleware" "joylink.club/bj-rtsts-server/service" + "joylink.club/bj-rtsts-server/sys_error" ) func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { @@ -41,13 +41,10 @@ func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl // @Failure 500 {object} dto.ErrorDto // @Router /api/v1/publishedGi/paging [get] func pageQueryPublishedGi(c *gin.Context) { - user, _ := c.Get(middleware.IdentityKey) - slog.Debug("分页查询发布的图形数据", user) req := publishedGi.PublishedGiReqDto{} if err := c.ShouldBind(&req); err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("查询失败,查询参数格式错误", err)) } - slog.Debug("分页查询发布的图形数据", req) page := service.PageQueryPublishedGi(&req) c.JSON(http.StatusOK, page) } @@ -68,13 +65,10 @@ func pageQueryPublishedGi(c *gin.Context) { // @Failure 500 {object} dto.ErrorDto // @Router /api/v1/publishedGi/list [get] func listQueryPublishedGi(c *gin.Context) { - user, _ := c.Get(middleware.IdentityKey) - slog.Debug("列表查询发布的图形数据", user) req := publishedGi.PublishedGiListReqDto{} if err := c.ShouldBindQuery(&req); err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("查询失败,查询参数格式错误", err)) } - slog.Debug("列表查询发布的图形数据", req) list := service.ListQueryPublishedGi(&req) c.JSON(http.StatusOK, list) } @@ -95,18 +89,12 @@ func listQueryPublishedGi(c *gin.Context) { // @Failure 500 {object} dto.ErrorDto // @Router /api/v1/publishedGi/{id} [get] func getPublishedGiById(c *gin.Context) { - user, _ := c.Get(middleware.IdentityKey) - slog.Debug("id查询发布的图形数据", user) idStr := c.Param("id") id, err := strconv.Atoi(idStr) if err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) - } - slog.Debug("id查询发布的图形数据", id) - entity, err := service.GetPublishedGiById(id) - if err != nil { - panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) + panic(sys_error.New("查询失败,传入参数格式错误", err)) } + entity := service.GetPublishedGiById(id) c.JSON(http.StatusOK, entity) } @@ -130,10 +118,8 @@ func publishFromDraft(c *gin.Context) { slog.Debug("发布图形数据", user) req := publishedGi.PublishReqDto{} if err := c.ShouldBind(&req); err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("发布失败,参数格式错误", err)) } - //todo - slog.Debug("发布图形数据请求参数", req) service.PublishFormDraft(&req, user.(*model.User)) } @@ -153,14 +139,11 @@ func publishFromDraft(c *gin.Context) { // @Failure 500 {object} dto.ErrorDto // @Router /api/v1/publishedGi/{id} [delete] func deletePublishedGiById(c *gin.Context) { - user, _ := c.Get(middleware.IdentityKey) - slog.Debug("id删除发布的图形数据", user) idStr := c.Param("id") id, err := strconv.Atoi(idStr) if err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("删除失败,传入参数格式错误", err)) } - slog.Debug("id查询发布的图形数据", id) service.DeletePublishedGiById(id) } @@ -186,11 +169,11 @@ func saveAsDraftingFromPublish(c *gin.Context) { slog.Debug("用户拉取发布图形数据", "userId", user, "发布图数据id", idStr) id, err := strconv.Atoi(idStr) if err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("另存为草稿失败,传入参数格式错误", err)) } req := publishedGi.PublishReqDto{} if err := c.ShouldBind(&req); err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("另存为草稿失败,传入参数格式错误", err)) } service.SaveAsDraftingFromPublish(int32(id), user.(*model.User), req.Name) } @@ -211,16 +194,11 @@ func saveAsDraftingFromPublish(c *gin.Context) { // @Failure 500 {object} dto.ErrorDto // @Router /api/v1/publishedGi/name [get] func getPublishedGiByName(c *gin.Context) { - user, _ := c.Get(middleware.IdentityKey) - slog.Debug("name查询发布的图形数据", user) param := &publishedGi.PublishedGiSingleQueryDto{} if err := c.ShouldBind(param); err != nil { - panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + panic(sys_error.New("查询失败,查询参数格式错误", err)) } slog.Debug("name查询发布的图形数据", param.Name) - entity, err := service.GetPublishedGiByName(param) - if err != nil { - panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) - } + entity := service.GetPublishedGiByName(param) c.JSON(http.StatusOK, entity) } diff --git a/rtss_simulation b/rtss_simulation index 89dd583..365f5a5 160000 --- a/rtss_simulation +++ b/rtss_simulation @@ -1 +1 @@ -Subproject commit 89dd583d1990729e1925e31b7bb5da3c6aeb3a94 +Subproject commit 365f5a50d94b1ad1462d58d1e555d4fb1fd2bc7e diff --git a/service/publishedGi.go b/service/publishedGi.go index 389a63a..070f835 100644 --- a/service/publishedGi.go +++ b/service/publishedGi.go @@ -53,8 +53,12 @@ func ListAllPublishedGi() ([]*model.PublishedGi, error) { return dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Status.Eq(1)).Find() } -func GetPublishedGiById(id int) (*model.PublishedGi, error) { - return dbquery.PublishedGi.Where(dbquery.PublishedGi.ID.Eq(int32(id))).Debug().First() +func GetPublishedGiById(id int) *model.PublishedGi { + data, err := dbquery.PublishedGi.Where(dbquery.PublishedGi.ID.Eq(int32(id))).Debug().First() + if err != nil { + panic(err) + } + return data } func PublishFormDraft(req *publishedGi.PublishReqDto, user *model.User) { @@ -151,12 +155,16 @@ func QueryProjectPublishedGi(id int32) []*model.PublishedGi { return publishedGis } -func GetPublishedGiByName(param *publishedGi.PublishedGiSingleQueryDto) (*model.PublishedGi, error) { +func GetPublishedGiByName(param *publishedGi.PublishedGiSingleQueryDto) *model.PublishedGi { where := dbquery.PublishedGi. Where(dbquery.PublishedGi.Name.Eq(param.Name)). Where(dbquery.PublishedGi.Status.Eq(1)) if !param.Detail { where = where.Omit(dbquery.PublishedGi.Proto) } - return where.Debug().First() + data, err := where.Debug().First() + if err != nil { + panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) + } + return data } diff --git a/service/simulation.go b/service/simulation.go deleted file mode 100644 index 9c4ed95..0000000 --- a/service/simulation.go +++ /dev/null @@ -1,18 +0,0 @@ -package service - -import ( - "google.golang.org/protobuf/proto" - "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" - "joylink.club/bj-rtsts-server/dto" -) - -// 查询地图数据 -func QueryRtssGraphicStorage(mapId int32) *graphicData.RtssGraphicStorage { - publishdata, err := GetPublishedGiById(int(mapId)) - if err != nil { - panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) - } - graphicStorage := &graphicData.RtssGraphicStorage{} - proto.Unmarshal(publishdata.Proto, graphicStorage) - return graphicStorage -}