2023-07-14 16:47:59 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
jwt "github.com/appleboy/gin-jwt/v2"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go.uber.org/zap"
|
2023-09-01 17:26:04 +08:00
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
|
|
|
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
2023-07-27 16:59:55 +08:00
|
|
|
"joylink.club/bj-rtsts-server/db/model"
|
2023-07-14 16:47:59 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
|
|
"joylink.club/bj-rtsts-server/middleware"
|
|
|
|
"joylink.club/bj-rtsts-server/service"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
2023-08-30 09:28:21 +08:00
|
|
|
authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
|
2023-07-18 17:19:03 +08:00
|
|
|
authed.GET("/paging", pageQueryDrafting)
|
2023-07-14 16:47:59 +08:00
|
|
|
authed.POST("", createDrafting)
|
|
|
|
authed.POST("/:id/saveAs", saveAsDrafting)
|
2023-07-14 18:09:07 +08:00
|
|
|
authed.GET("/:id", queryDraftingInfo)
|
|
|
|
authed.PUT("/:id", updateDraftingInfo)
|
2023-07-25 17:18:37 +08:00
|
|
|
authed.DELETE("/:id", deleteDrafting)
|
2023-09-01 17:26:04 +08:00
|
|
|
authed.POST("/calculatelink", generateCalculateLinkData)
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:09:07 +08:00
|
|
|
// 分页查询草稿
|
|
|
|
//
|
|
|
|
// @Summary 分页查询草稿
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 可以通过草稿名称过滤,分页查询草稿
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param PageDraftingReqDto query dto.PageDraftingReqDto true "草稿查询条件带分页信息"
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Success 200 {object} dto.PageDto
|
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
|
|
|
// @Router /api/v1/drafting/paging [get]
|
2023-07-14 16:47:59 +08:00
|
|
|
func pageQueryDrafting(c *gin.Context) {
|
|
|
|
user, _ := c.Get(middleware.IdentityKey)
|
|
|
|
zap.S().Debug("分页查询草稿", user)
|
|
|
|
req := dto.PageDraftingReqDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
zap.S().Debug("分页查草稿参数", req)
|
2023-07-28 14:13:03 +08:00
|
|
|
page, err := service.PageDraftingQuery(&req)
|
|
|
|
if err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
2023-07-28 14:13:03 +08:00
|
|
|
}
|
2023-07-14 16:47:59 +08:00
|
|
|
c.JSON(http.StatusOK, page)
|
|
|
|
}
|
|
|
|
|
2023-07-14 18:09:07 +08:00
|
|
|
// 创建草稿
|
|
|
|
//
|
|
|
|
// @Summary 创建草稿
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 创建草稿数据
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param draftingDto query dto.DraftingDto true "创建的草稿信息"
|
2023-07-18 17:19:03 +08:00
|
|
|
// @Success 200 {object} nil
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
|
|
|
// @Router /api/v1/drafting [post]
|
2023-07-14 16:47:59 +08:00
|
|
|
func createDrafting(c *gin.Context) {
|
2023-07-27 16:59:55 +08:00
|
|
|
user, _ := c.Get(middleware.IdentityKey)
|
2023-07-28 14:13:03 +08:00
|
|
|
createId := user.(*model.User).ID
|
2023-07-14 16:47:59 +08:00
|
|
|
req := dto.DraftingDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
zap.S().Debug("保存数据", req)
|
2023-07-28 14:13:03 +08:00
|
|
|
data, err := service.CreateDrafting(createId, &req)
|
|
|
|
if err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
2023-07-28 14:13:03 +08:00
|
|
|
}
|
|
|
|
c.JSON(http.StatusOK, data)
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:09:07 +08:00
|
|
|
// 草稿另存为
|
|
|
|
//
|
|
|
|
// @Summary 草稿另存为
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 草稿另存为
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param id path int true "源草稿id"
|
|
|
|
// @Param draftingDto query dto.DraftingDto true "另存为草稿信息"
|
2023-07-18 17:19:03 +08:00
|
|
|
// @Success 200 {object} nil
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id}/saveAs [post]
|
2023-07-14 16:47:59 +08:00
|
|
|
func saveAsDrafting(c *gin.Context) {
|
|
|
|
id, exist := c.Params.Get("id")
|
|
|
|
if !exist {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
zap.S().Debug("传入参数id为" + id)
|
2023-07-27 16:59:55 +08:00
|
|
|
user, _ := c.Get(middleware.IdentityKey)
|
2023-07-28 14:13:03 +08:00
|
|
|
createrId := user.(*model.User).ID
|
2023-07-14 16:47:59 +08:00
|
|
|
req := dto.DraftingDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
int64Id, _ := strconv.ParseInt(id, 10, 64)
|
2023-07-28 14:13:03 +08:00
|
|
|
newData, err := service.SaveAsDrafting(createrId, int32(int64Id), &req)
|
|
|
|
if err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
|
2023-07-28 14:13:03 +08:00
|
|
|
}
|
|
|
|
c.JSON(http.StatusOK, newData)
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 查询草稿详情
|
|
|
|
//
|
|
|
|
// @Summary 查询草稿详情
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 查询草稿详情
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param id path int true "草稿ID"
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Success 200 {object} model.Drafting
|
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id} [get]
|
2023-07-14 18:09:07 +08:00
|
|
|
func queryDraftingInfo(c *gin.Context) {
|
|
|
|
id, exist := c.Params.Get("id")
|
|
|
|
if !exist {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
zap.S().Debug("传入参数id为" + id)
|
|
|
|
int64Id, _ := strconv.ParseInt(id, 10, 64)
|
|
|
|
c.JSON(http.StatusOK, service.QueryDrafting(int32(int64Id)))
|
|
|
|
}
|
|
|
|
|
2023-07-28 14:13:03 +08:00
|
|
|
// 修改草稿信息
|
2023-07-14 18:09:07 +08:00
|
|
|
//
|
2023-07-28 14:13:03 +08:00
|
|
|
// @Summary 修改草稿信息
|
2023-07-14 18:09:07 +08:00
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
2023-07-28 14:13:03 +08:00
|
|
|
// @Description 修改草稿信息
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param id path int true "草稿ID"
|
|
|
|
// @Param draftingDto query dto.DraftingDto true "修改的草稿信息"
|
2023-07-18 17:19:03 +08:00
|
|
|
// @Success 200 {object} nil
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id} [put]
|
2023-07-14 18:09:07 +08:00
|
|
|
func updateDraftingInfo(c *gin.Context) {
|
|
|
|
id, exist := c.Params.Get("id")
|
|
|
|
if !exist {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
zap.S().Debug("传入参数id为" + id)
|
|
|
|
req := dto.DraftingDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
int64Id, _ := strconv.ParseInt(id, 10, 64)
|
2023-07-28 14:13:03 +08:00
|
|
|
result := service.UpdateDrafting(int32(int64Id), &req)
|
|
|
|
if !result {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存出错"})
|
2023-07-28 14:13:03 +08:00
|
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
2023-07-25 17:18:37 +08:00
|
|
|
|
|
|
|
// 删除草稿数据
|
|
|
|
//
|
|
|
|
// @Summary 删除草稿数据
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 删除草稿数据
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param id path int true "草稿ID"
|
|
|
|
// @Success 200 {object} nil
|
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id} [delete]
|
2023-07-25 17:18:37 +08:00
|
|
|
func deleteDrafting(c *gin.Context) {
|
|
|
|
user, _ := c.Get(middleware.IdentityKey)
|
|
|
|
zap.S().Debug("id删除草稿的图形数据", user)
|
|
|
|
idStr := c.Param("id")
|
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
|
if err != nil {
|
2023-08-30 18:05:11 +08:00
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
2023-07-25 17:18:37 +08:00
|
|
|
}
|
|
|
|
zap.S().Debug("id查询草稿的图形数据", id)
|
|
|
|
service.DeleteDraftingById(id)
|
2023-07-28 14:13:03 +08:00
|
|
|
c.JSON(http.StatusOK, true)
|
2023-07-25 17:18:37 +08:00
|
|
|
}
|
2023-09-01 17:26:04 +08:00
|
|
|
|
|
|
|
// 根据地图数据新生成计算的link信息
|
|
|
|
//
|
|
|
|
// @Summary 根据地图数据新生成计算的link信息
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 根据地图数据新生成计算的link信息
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param DraftingMapDataDto query dto.DraftingMapDataDto true "地图信息"
|
|
|
|
// @Success 200 {object} nil
|
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
|
|
|
// @Router /api/v1/drafting/calculatelink [post]
|
|
|
|
func generateCalculateLinkData(c *gin.Context) {
|
|
|
|
req := dto.DraftingMapDataDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
|
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
|
|
|
}
|
|
|
|
gd := &graphicData.RtssGraphicStorage{}
|
|
|
|
proto.Unmarshal(req.Proto, gd)
|
|
|
|
c.JSON(http.StatusOK, memory.BuildCalculateLinkData(gd))
|
|
|
|
}
|