【发布数据管理逻辑修改】

This commit is contained in:
weizhihong 2023-11-22 17:05:38 +08:00
parent f355453f54
commit 1434fb0f01
14 changed files with 1893 additions and 1737 deletions

View File

@ -24,6 +24,9 @@ func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
authed.DELETE("/:id", deletePublishedGiById)
authed.POST("/saveAsDrafting/:id", saveAsDraftingFromPublish)
authed.GET("/name", getPublishedGiByName)
authed.POST("/release", releasePublishedGiById)
authed.POST("/rename", renamePublishedGiById)
authed.GET("/:id/history", historyPublishedGiById)
}
// 分页查询发布的图形数据
@ -61,7 +64,7 @@ func pageQueryPublishedGi(c *gin.Context) {
// @Accept json
// @Produce json
// @Param publishedListReqDto query dto.PublishedListReqDto true "查询参数"
// @Success 200 {object} []model.PublishedGi
// @Success 200 {object} []model.Published
// @Failure 401 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/list [get]
@ -192,7 +195,7 @@ func saveAsDraftingFromPublish(c *gin.Context) {
// @Accept json
// @Produce json
// @Param publishedSingleQueryDto query dto.PublishedSingleQueryDto true "查询参数"
// @Success 200 {object} []model.PublishedGi
// @Success 200 {object} dto.PublishedDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/name [get]
@ -205,3 +208,76 @@ func getPublishedGiByName(c *gin.Context) {
entity := service.GetPublishedGiByName(param)
c.JSON(http.StatusOK, entity)
}
// 上下架发布数据
//
// @Summary 上下架发布数据
//
// @Security JwtAuth
//
// @Description 上下架发布数据
// @Tags 发布的图形数据Api
// @Accept json
// @Produce json
// @Param PublishChangeReqDto query dto.PublishChangeReqDto true "查询参数"
// @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/release [post]
func releasePublishedGiById(c *gin.Context) {
param := &dto.PublishChangeReqDto{}
if err := c.ShouldBind(param); err != nil {
panic(sys_error.New("操作失败,查询参数格式错误", err))
}
service.ChangePublishStatus(param.Id, param.Release)
c.JSON(http.StatusOK, true)
}
// 修改发布数据名称
//
// @Summary 修改发布数据名称
//
// @Security JwtAuth
//
// @Description 修改发布数据名称
// @Tags 发布的图形数据Api
// @Accept json
// @Produce json
// @Param PublishChangeReqDto query dto.PublishChangeReqDto true "查询参数"
// @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/rename [post]
func renamePublishedGiById(c *gin.Context) {
param := &dto.PublishChangeReqDto{}
if err := c.ShouldBind(param); err != nil {
panic(sys_error.New("操作失败,查询参数格式错误", err))
}
service.ChangePublishCode(param.Id, param.Name)
c.JSON(http.StatusOK, true)
}
// 查询发布历史版本信息
//
// @Summary 查询发布历史版本信息
//
// @Security JwtAuth
//
// @Description 查询发布历史版本信息
// @Tags 发布的图形数据Api
// @Accept json
// @Produce json
// @Param id path int true "id"
// @Success 200 {object} dto.PublishHistoryDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/:id/history [get]
func historyPublishedGiById(c *gin.Context) {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(sys_error.New("查询发布历史失败,查询参数格式错误", err))
}
mid := int32(id)
c.JSON(http.StatusOK, service.GetPublishHistory(mid))
}

View File

@ -2,11 +2,13 @@ package api
// 列车相关的关系管理
import (
"log/slog"
"net/http"
"strconv"
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/middleware"
"joylink.club/bj-rtsts-server/service"
@ -44,7 +46,7 @@ func pageQueryTrainInfo(c *gin.Context) {
if err := c.ShouldBind(&req); err != nil {
panic(sys_error.New("查询失败,参数格式错误", err))
}
c.JSON(http.StatusOK, service.PageTrainInfoQuery(&req))
c.JSON(http.StatusOK, service.PageTrainInfoByPublished(&req))
}
// 查询列车列表
@ -58,7 +60,7 @@ func pageQueryTrainInfo(c *gin.Context) {
// @Accept json
// @Produce json
// @Param trainInfoReqDto query dto.TrainInfoReqDto true "列车查询条件"
// @Success 200 {object} model.TrainInfo
// @Success 200 {object} dto.TrainInfoDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
@ -68,7 +70,7 @@ func queryTrainInfoList(c *gin.Context) {
if err := c.ShouldBind(&req); err != nil {
panic(sys_error.New("查询失败,参数格式错误", err))
}
c.JSON(http.StatusOK, service.ListTrainInfoQuery(&req))
c.JSON(http.StatusOK, service.ListTrainByProject(&req))
}
// 创建列车
@ -92,8 +94,9 @@ func createTrainInfo(c *gin.Context) {
if err := c.ShouldBind(&req); err != nil {
panic(sys_error.New("保存失败,参数格式错误", err))
}
c.JSON(http.StatusOK, service.CreateTrainInfo(&req))
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("发布图形数据", user)
c.JSON(http.StatusOK, service.CreateTrain(&req, user.(*model.User)))
}
// 查询列车详情
@ -107,7 +110,7 @@ func createTrainInfo(c *gin.Context) {
// @Accept json
// @Produce json
// @Param id path int true "列车ID"
// @Success 200 {object} model.TrainModel
// @Success 200 {object} dto.TrainInfoDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
@ -118,7 +121,7 @@ func queryTrainInfo(c *gin.Context) {
panic(sys_error.New("查询失败,缺少主键"))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryTrainInfo(int32(int64Id)))
c.JSON(http.StatusOK, service.QueryTrain(int32(int64Id)))
}
// 修改列车信息
@ -148,7 +151,9 @@ func updateTrainInfo(c *gin.Context) {
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.UpdateTrainInfo(int32(int64Id), &req))
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("发布图形数据", user)
c.JSON(http.StatusOK, service.UpdateTrain(int32(int64Id), &req, user.(*model.User)))
}
// 删除列车数据
@ -173,6 +178,6 @@ func deleteTrainInfo(c *gin.Context) {
if err != nil {
panic(sys_error.New("删除失败,缺少主键"))
}
service.DeleteTrainInfoById(id)
service.DeletePublishedById(int32(id))
c.JSON(http.StatusOK, true)
}

View File

@ -34,6 +34,9 @@ func newPublishedVersion(db *gorm.DB, opts ...gen.DOOption) publishedVersion {
_publishedVersion.Note = field.NewString(tableName, "note")
_publishedVersion.Version = field.NewInt32(tableName, "version")
_publishedVersion.Code = field.NewString(tableName, "code")
_publishedVersion.PublishID = field.NewInt32(tableName, "publish_id")
_publishedVersion.Type = field.NewInt32(tableName, "type")
_publishedVersion.Category = field.NewString(tableName, "category")
_publishedVersion.fillFieldMap()
@ -50,7 +53,10 @@ type publishedVersion struct {
PublishAt field.Time // 发布时间
Note field.String // 发布描述
Version field.Int32 // 版本
Code field.String // 数据名称
Code field.String // 发布草稿数据名称
PublishID field.Int32 // 对应发布图的ID
Type field.Int32
Category field.String
fieldMap map[string]field.Expr
}
@ -74,6 +80,9 @@ func (p *publishedVersion) updateTableName(table string) *publishedVersion {
p.Note = field.NewString(table, "note")
p.Version = field.NewInt32(table, "version")
p.Code = field.NewString(table, "code")
p.PublishID = field.NewInt32(table, "publish_id")
p.Type = field.NewInt32(table, "type")
p.Category = field.NewString(table, "category")
p.fillFieldMap()
@ -90,7 +99,7 @@ func (p *publishedVersion) GetFieldByName(fieldName string) (field.OrderExpr, bo
}
func (p *publishedVersion) fillFieldMap() {
p.fieldMap = make(map[string]field.Expr, 7)
p.fieldMap = make(map[string]field.Expr, 10)
p.fieldMap["id"] = p.ID
p.fieldMap["proto"] = p.Proto
p.fieldMap["user_id"] = p.UserID
@ -98,6 +107,9 @@ func (p *publishedVersion) fillFieldMap() {
p.fieldMap["note"] = p.Note
p.fieldMap["version"] = p.Version
p.fieldMap["code"] = p.Code
p.fieldMap["publish_id"] = p.PublishID
p.fieldMap["type"] = p.Type
p.fieldMap["category"] = p.Category
}
func (p publishedVersion) clone(db *gorm.DB) publishedVersion {

View File

@ -18,7 +18,10 @@ type PublishedVersion struct {
PublishAt time.Time `gorm:"column:publish_at;not null;comment:发布时间" json:"publish_at"` // 发布时间
Note string `gorm:"column:note;comment:发布描述" json:"note"` // 发布描述
Version int32 `gorm:"column:version;comment:版本" json:"version"` // 版本
Code string `gorm:"column:code;comment:数据名称" json:"code"` // 数据名称
Code string `gorm:"column:code;comment:发布草稿数据名称" json:"code"` // 发布草稿数据名称
PublishID int32 `gorm:"column:publish_id;comment:对应发布图的ID" json:"publish_id"` // 对应发布图的ID
Type int32 `gorm:"column:type" json:"type"`
Category string `gorm:"column:category" json:"category"`
}
// TableName PublishedVersion's table name

View File

@ -1236,14 +1236,16 @@ const docTemplate = `{
0,
1,
2,
3
3,
4
],
"type": "integer",
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
],
"name": "type",
"in": "query"
@ -1504,14 +1506,16 @@ const docTemplate = `{
0,
1,
2,
3
3,
4
],
"type": "integer",
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
],
"name": "type",
"in": "query"
@ -1647,14 +1651,16 @@ const docTemplate = `{
0,
1,
2,
3
3,
4
],
"type": "integer",
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
],
"name": "type",
"in": "query"
@ -2079,16 +2085,6 @@ const docTemplate = `{
"type": "integer",
"name": "pid",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"description": "TODO:前端修改完成后删除",
"name": "sids",
"in": "query"
}
],
"responses": {
@ -2174,14 +2170,14 @@ const docTemplate = `{
}
}
},
"/api/v1/projectLink/mapInfo/trainSize/{id}": {
"/api/v1/publishedGi/:id/history": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "通过地图ID查询项目的关联列车尺寸信息",
"description": "查询发布历史版本信息",
"consumes": [
"application/json"
],
@ -2189,13 +2185,13 @@ const docTemplate = `{
"application/json"
],
"tags": [
"项目关联信息Api"
"发布的图形数据Api"
],
"summary": "通过地图ID查询项目的关联列车尺寸信息",
"summary": "查询发布历史版本信息",
"parameters": [
{
"type": "integer",
"description": "地图ID",
"description": "id",
"name": "id",
"in": "path",
"required": true
@ -2205,7 +2201,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.TrainSizeDto"
"$ref": "#/definitions/dto.PublishHistoryDto"
}
},
"401": {
@ -2214,67 +2210,6 @@ const docTemplate = `{
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/projectLink/project/trainSize/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "通过项目ID查询项目的关联列车尺寸信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"项目关联信息Api"
],
"summary": "通过项目ID查询项目的关联列车尺寸信息",
"parameters": [
{
"type": "integer",
"description": "地图ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.TrainSizeDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
@ -2303,10 +2238,20 @@ const docTemplate = `{
],
"summary": "列表查询发布的图形数据",
"parameters": [
{
"type": "string",
"name": "category",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "integer",
"name": "type",
"in": "query"
}
],
"responses": {
@ -2315,7 +2260,7 @@ const docTemplate = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.PublishedGi"
"$ref": "#/definitions/model.Published"
}
}
},
@ -2368,10 +2313,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.PublishedGi"
}
"$ref": "#/definitions/dto.PublishedDto"
}
},
"401": {
@ -2476,6 +2418,12 @@ const docTemplate = `{
"name": "draftId",
"in": "query"
},
{
"type": "boolean",
"description": "强制覆盖",
"name": "force",
"in": "query"
},
{
"type": "string",
"description": "发布后的名称",
@ -2507,6 +2455,114 @@ const docTemplate = `{
}
}
},
"/api/v1/publishedGi/release": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "上下架发布数据",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"发布的图形数据Api"
],
"summary": "上下架发布数据",
"parameters": [
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "boolean",
"name": "release",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/publishedGi/rename": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "修改发布数据名称",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"发布的图形数据Api"
],
"summary": "修改发布数据名称",
"parameters": [
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "boolean",
"name": "release",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/publishedGi/saveAsDrafting/{id}": {
"post": {
"security": [
@ -2539,6 +2595,12 @@ const docTemplate = `{
"name": "draftId",
"in": "query"
},
{
"type": "boolean",
"description": "强制覆盖",
"name": "force",
"in": "query"
},
{
"type": "string",
"description": "发布后的名称",
@ -4044,7 +4106,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.TrainInfo"
"$ref": "#/definitions/dto.TrainInfoDto"
}
},
"401": {
@ -4168,7 +4230,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.TrainModel"
"$ref": "#/definitions/dto.TrainInfoDto"
}
},
"401": {
@ -4843,13 +4905,6 @@ const docTemplate = `{
},
"pid": {
"type": "integer"
},
"trainSizeLinks": {
"description": "TODO:前端修改完成后删除",
"type": "array",
"items": {
"$ref": "#/definitions/dto.TrainSizeDto"
}
}
}
},
@ -4901,6 +4956,26 @@ const docTemplate = `{
}
}
},
"dto.PublishHistoryDto": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"note": {
"type": "string"
},
"publishAt": {
"type": "string"
},
"publisher": {
"type": "string"
},
"version": {
"type": "integer"
}
}
},
"dto.PublishedDto": {
"type": "object",
"properties": {
@ -5133,7 +5208,7 @@ const docTemplate = `{
}
}
},
"dto.TrainSizeDto": {
"dto.TrainInfoDto": {
"type": "object",
"properties": {
"carriage_length": {
@ -5145,11 +5220,23 @@ const docTemplate = `{
"id": {
"type": "integer"
},
"max_diameter": {
"type": "integer"
},
"min_diameter": {
"type": "integer"
},
"name": {
"type": "string"
},
"total_length": {
"type": "integer"
},
"train_model": {
"type": "integer"
},
"train_sets": {
"type": "string"
}
}
},
@ -5214,13 +5301,15 @@ const docTemplate = `{
0,
1,
2,
3
3,
4
],
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
]
},
"model.AuthAPIPath": {
@ -5338,36 +5427,25 @@ const docTemplate = `{
}
}
},
"model.PublishedGi": {
"model.Published": {
"type": "object",
"properties": {
"category": {
"description": "厂家信息",
"type": "string"
},
"code": {
"description": "发布名称",
"type": "string"
},
"data_id": {
"description": "版本Id",
"type": "integer"
},
"id": {
"description": "id",
"type": "integer"
},
"name": {
"description": "发布图形界面名称",
"type": "string"
},
"note": {
"description": "发布描述",
"type": "string"
},
"proto": {
"description": "图形界面数据",
"type": "array",
"items": {
"type": "integer"
}
},
"publish_at": {
"description": "发布时间",
"type": "string"
},
"status": {
"description": "显示状态",
"type": "integer"
@ -5375,54 +5453,6 @@ const docTemplate = `{
"type": {
"description": "数据类型",
"type": "integer"
},
"user_id": {
"description": "发布用户id",
"type": "integer"
}
}
},
"model.TrainInfo": {
"type": "object",
"properties": {
"description": {
"description": "其他描述内容",
"type": "string"
},
"id": {
"description": "id",
"type": "integer"
},
"name": {
"description": "列车信息",
"type": "string"
},
"proto": {
"description": "列车参数信息",
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"model.TrainModel": {
"type": "object",
"properties": {
"created_at": {
"description": "创建时间",
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"description": "组次名称",
"type": "string"
},
"update_at": {
"description": "更新时间",
"type": "string"
}
}
},

View File

@ -1229,14 +1229,16 @@
0,
1,
2,
3
3,
4
],
"type": "integer",
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
],
"name": "type",
"in": "query"
@ -1497,14 +1499,16 @@
0,
1,
2,
3
3,
4
],
"type": "integer",
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
],
"name": "type",
"in": "query"
@ -1640,14 +1644,16 @@
0,
1,
2,
3
3,
4
],
"type": "integer",
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
],
"name": "type",
"in": "query"
@ -2072,16 +2078,6 @@
"type": "integer",
"name": "pid",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"description": "TODO:前端修改完成后删除",
"name": "sids",
"in": "query"
}
],
"responses": {
@ -2167,14 +2163,14 @@
}
}
},
"/api/v1/projectLink/mapInfo/trainSize/{id}": {
"/api/v1/publishedGi/:id/history": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "通过地图ID查询项目的关联列车尺寸信息",
"description": "查询发布历史版本信息",
"consumes": [
"application/json"
],
@ -2182,13 +2178,13 @@
"application/json"
],
"tags": [
"项目关联信息Api"
"发布的图形数据Api"
],
"summary": "通过地图ID查询项目的关联列车尺寸信息",
"summary": "查询发布历史版本信息",
"parameters": [
{
"type": "integer",
"description": "地图ID",
"description": "id",
"name": "id",
"in": "path",
"required": true
@ -2198,7 +2194,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.TrainSizeDto"
"$ref": "#/definitions/dto.PublishHistoryDto"
}
},
"401": {
@ -2207,67 +2203,6 @@
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/projectLink/project/trainSize/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "通过项目ID查询项目的关联列车尺寸信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"项目关联信息Api"
],
"summary": "通过项目ID查询项目的关联列车尺寸信息",
"parameters": [
{
"type": "integer",
"description": "地图ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.TrainSizeDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
@ -2296,10 +2231,20 @@
],
"summary": "列表查询发布的图形数据",
"parameters": [
{
"type": "string",
"name": "category",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "integer",
"name": "type",
"in": "query"
}
],
"responses": {
@ -2308,7 +2253,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.PublishedGi"
"$ref": "#/definitions/model.Published"
}
}
},
@ -2361,10 +2306,7 @@
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.PublishedGi"
}
"$ref": "#/definitions/dto.PublishedDto"
}
},
"401": {
@ -2469,6 +2411,12 @@
"name": "draftId",
"in": "query"
},
{
"type": "boolean",
"description": "强制覆盖",
"name": "force",
"in": "query"
},
{
"type": "string",
"description": "发布后的名称",
@ -2500,6 +2448,114 @@
}
}
},
"/api/v1/publishedGi/release": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "上下架发布数据",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"发布的图形数据Api"
],
"summary": "上下架发布数据",
"parameters": [
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "boolean",
"name": "release",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/publishedGi/rename": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "修改发布数据名称",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"发布的图形数据Api"
],
"summary": "修改发布数据名称",
"parameters": [
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "boolean",
"name": "release",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/publishedGi/saveAsDrafting/{id}": {
"post": {
"security": [
@ -2532,6 +2588,12 @@
"name": "draftId",
"in": "query"
},
{
"type": "boolean",
"description": "强制覆盖",
"name": "force",
"in": "query"
},
{
"type": "string",
"description": "发布后的名称",
@ -4037,7 +4099,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.TrainInfo"
"$ref": "#/definitions/dto.TrainInfoDto"
}
},
"401": {
@ -4161,7 +4223,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.TrainModel"
"$ref": "#/definitions/dto.TrainInfoDto"
}
},
"401": {
@ -4836,13 +4898,6 @@
},
"pid": {
"type": "integer"
},
"trainSizeLinks": {
"description": "TODO:前端修改完成后删除",
"type": "array",
"items": {
"$ref": "#/definitions/dto.TrainSizeDto"
}
}
}
},
@ -4894,6 +4949,26 @@
}
}
},
"dto.PublishHistoryDto": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"note": {
"type": "string"
},
"publishAt": {
"type": "string"
},
"publisher": {
"type": "string"
},
"version": {
"type": "integer"
}
}
},
"dto.PublishedDto": {
"type": "object",
"properties": {
@ -5126,7 +5201,7 @@
}
}
},
"dto.TrainSizeDto": {
"dto.TrainInfoDto": {
"type": "object",
"properties": {
"carriage_length": {
@ -5138,11 +5213,23 @@
"id": {
"type": "integer"
},
"max_diameter": {
"type": "integer"
},
"min_diameter": {
"type": "integer"
},
"name": {
"type": "string"
},
"total_length": {
"type": "integer"
},
"train_model": {
"type": "integer"
},
"train_sets": {
"type": "string"
}
}
},
@ -5207,13 +5294,15 @@
0,
1,
2,
3
3,
4
],
"x-enum-varnames": [
"PictureType_StationLayout",
"PictureType_Psl",
"PictureType_RelayCabinetLayout",
"PictureType_IBP"
"PictureType_IBP",
"PictureType_TrainData"
]
},
"model.AuthAPIPath": {
@ -5331,36 +5420,25 @@
}
}
},
"model.PublishedGi": {
"model.Published": {
"type": "object",
"properties": {
"category": {
"description": "厂家信息",
"type": "string"
},
"code": {
"description": "发布名称",
"type": "string"
},
"data_id": {
"description": "版本Id",
"type": "integer"
},
"id": {
"description": "id",
"type": "integer"
},
"name": {
"description": "发布图形界面名称",
"type": "string"
},
"note": {
"description": "发布描述",
"type": "string"
},
"proto": {
"description": "图形界面数据",
"type": "array",
"items": {
"type": "integer"
}
},
"publish_at": {
"description": "发布时间",
"type": "string"
},
"status": {
"description": "显示状态",
"type": "integer"
@ -5368,54 +5446,6 @@
"type": {
"description": "数据类型",
"type": "integer"
},
"user_id": {
"description": "发布用户id",
"type": "integer"
}
}
},
"model.TrainInfo": {
"type": "object",
"properties": {
"description": {
"description": "其他描述内容",
"type": "string"
},
"id": {
"description": "id",
"type": "integer"
},
"name": {
"description": "列车信息",
"type": "string"
},
"proto": {
"description": "列车参数信息",
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"model.TrainModel": {
"type": "object",
"properties": {
"created_at": {
"description": "创建时间",
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"description": "组次名称",
"type": "string"
},
"update_at": {
"description": "更新时间",
"type": "string"
}
}
},

View File

@ -214,11 +214,6 @@ definitions:
type: string
pid:
type: integer
trainSizeLinks:
description: TODO:前端修改完成后删除
items:
$ref: '#/definitions/dto.TrainSizeDto'
type: array
type: object
dto.ProjectRunConfigDto:
properties:
@ -252,6 +247,19 @@ definitions:
- mapId
- simulationId
type: object
dto.PublishHistoryDto:
properties:
id:
type: integer
note:
type: string
publishAt:
type: string
publisher:
type: string
version:
type: integer
type: object
dto.PublishedDto:
properties:
category:
@ -408,7 +416,7 @@ definitions:
token:
type: string
type: object
dto.TrainSizeDto:
dto.TrainInfoDto:
properties:
carriage_length:
type: integer
@ -416,10 +424,18 @@ definitions:
type: string
id:
type: integer
max_diameter:
type: integer
min_diameter:
type: integer
name:
type: string
total_length:
type: integer
train_model:
type: integer
train_sets:
type: string
type: object
dto.UpdateTrainReqDto:
properties:
@ -466,12 +482,14 @@ definitions:
- 1
- 2
- 3
- 4
type: integer
x-enum-varnames:
- PictureType_StationLayout
- PictureType_Psl
- PictureType_RelayCabinetLayout
- PictureType_IBP
- PictureType_TrainData
model.AuthAPIPath:
properties:
id:
@ -555,68 +573,26 @@ definitions:
description: 更新时间
type: string
type: object
model.PublishedGi:
model.Published:
properties:
category:
description: 厂家信息
type: string
code:
description: 发布名称
type: string
data_id:
description: 版本Id
type: integer
id:
description: id
type: integer
name:
description: 发布图形界面名称
type: string
note:
description: 发布描述
type: string
proto:
description: 图形界面数据
items:
type: integer
type: array
publish_at:
description: 发布时间
type: string
status:
description: 显示状态
type: integer
type:
description: 数据类型
type: integer
user_id:
description: 发布用户id
type: integer
type: object
model.TrainInfo:
properties:
description:
description: 其他描述内容
type: string
id:
description: id
type: integer
name:
description: 列车信息
type: string
proto:
description: 列车参数信息
items:
type: integer
type: array
type: object
model.TrainModel:
properties:
created_at:
description: 创建时间
type: string
id:
type: integer
name:
description: 组次名称
type: string
update_at:
description: 更新时间
type: string
type: object
request_proto.Psd_Operation:
enum:
@ -1619,6 +1595,7 @@ paths:
- 1
- 2
- 3
- 4
in: query
name: type
type: integer
@ -1627,6 +1604,7 @@ paths:
- PictureType_Psl
- PictureType_RelayCabinetLayout
- PictureType_IBP
- PictureType_TrainData
produces:
- application/json
responses:
@ -1746,6 +1724,7 @@ paths:
- 1
- 2
- 3
- 4
in: query
name: type
type: integer
@ -1754,6 +1733,7 @@ paths:
- PictureType_Psl
- PictureType_RelayCabinetLayout
- PictureType_IBP
- PictureType_TrainData
produces:
- application/json
responses:
@ -1807,6 +1787,7 @@ paths:
- 1
- 2
- 3
- 4
in: query
name: type
type: integer
@ -1815,6 +1796,7 @@ paths:
- PictureType_Psl
- PictureType_RelayCabinetLayout
- PictureType_IBP
- PictureType_TrainData
produces:
- application/json
responses:
@ -2159,13 +2141,6 @@ paths:
- in: query
name: pid
type: integer
- collectionFormat: csv
description: TODO:前端修改完成后删除
in: query
items:
type: integer
name: sids
type: array
produces:
- application/json
responses:
@ -2225,13 +2200,13 @@ paths:
summary: 查询项目的所有关联信息
tags:
- 项目关联信息Api
/api/v1/projectLink/mapInfo/trainSize/{id}:
/api/v1/publishedGi/:id/history:
get:
consumes:
- application/json
description: 通过地图ID查询项目的关联列车尺寸信息
description: 查询发布历史版本信息
parameters:
- description: 地图ID
- description: id
in: path
name: id
required: true
@ -2242,59 +2217,20 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/dto.TrainSizeDto'
$ref: '#/definitions/dto.PublishHistoryDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 通过地图ID查询项目的关联列车尺寸信息
summary: 查询发布历史版本信息
tags:
- 项目关联信息Api
/api/v1/projectLink/project/trainSize/{id}:
get:
consumes:
- application/json
description: 通过项目ID查询项目的关联列车尺寸信息
parameters:
- description: 地图ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.TrainSizeDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 通过项目ID查询项目的关联列车尺寸信息
tags:
- 项目关联信息Api
- 发布的图形数据Api
/api/v1/publishedGi/{id}:
delete:
consumes:
@ -2360,9 +2296,15 @@ paths:
- application/json
description: 可以通过名称过滤
parameters:
- in: query
name: category
type: string
- in: query
name: name
type: string
- in: query
name: type
type: integer
produces:
- application/json
responses:
@ -2370,7 +2312,7 @@ paths:
description: OK
schema:
items:
$ref: '#/definitions/model.PublishedGi'
$ref: '#/definitions/model.Published'
type: array
"401":
description: Unauthorized
@ -2403,9 +2345,7 @@ paths:
"200":
description: OK
schema:
items:
$ref: '#/definitions/model.PublishedGi'
type: array
$ref: '#/definitions/dto.PublishedDto'
"401":
description: Unauthorized
schema:
@ -2469,6 +2409,10 @@ paths:
in: query
name: draftId
type: integer
- description: 强制覆盖
in: query
name: force
type: boolean
- description: 发布后的名称
in: query
name: name
@ -2494,6 +2438,72 @@ paths:
summary: 从草稿发布数据
tags:
- 发布的图形数据Api
/api/v1/publishedGi/release:
post:
consumes:
- application/json
description: 上下架发布数据
parameters:
- in: query
name: id
type: integer
- in: query
name: name
type: string
- in: query
name: release
type: boolean
produces:
- application/json
responses:
"200":
description: OK
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 上下架发布数据
tags:
- 发布的图形数据Api
/api/v1/publishedGi/rename:
post:
consumes:
- application/json
description: 修改发布数据名称
parameters:
- in: query
name: id
type: integer
- in: query
name: name
type: string
- in: query
name: release
type: boolean
produces:
- application/json
responses:
"200":
description: OK
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 修改发布数据名称
tags:
- 发布的图形数据Api
/api/v1/publishedGi/saveAsDrafting/{id}:
post:
consumes:
@ -2509,6 +2519,10 @@ paths:
in: query
name: draftId
type: integer
- description: 强制覆盖
in: query
name: force
type: boolean
- description: 发布后的名称
in: query
name: name
@ -3439,7 +3453,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/model.TrainModel'
$ref: '#/definitions/dto.TrainInfoDto'
"401":
description: Unauthorized
schema:
@ -3531,7 +3545,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/model.TrainInfo'
$ref: '#/definitions/dto.TrainInfoDto'
"401":
description: Unauthorized
schema:

View File

@ -1,50 +1,27 @@
package dto
import "joylink.club/bj-rtsts-server/db/model"
type PagePublishedReqDto struct {
PageQueryDto
Name string `json:"name" form:"name"`
Release bool `json:"release" form:"release"` // 是否只要上架数据
}
type PublishedListReqDto struct {
Name string `json:"name" form:"name"`
Type int32 `json:"type" form:"type"`
Category string `json:"category" form:"category"`
}
type PublishedDto struct {
ID int32 `json:"id"`
Name string `json:"name"`
Proto []byte `json:"proto"`
UserID int32 `json:"userID"`
Note string `json:"note"`
Type int32 `json:"type"`
ID int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
Proto []byte `json:"proto" form:"proto"`
UserID int32 `json:"userID" form:"userID"`
Note string `json:"note" form:"note"`
Type int32 `json:"type" form:"type"`
Category string `json:"category" form:"category"`
PublishAt JsonTime `json:"publishAt" time_format:"2006-01-02 15:04:05"`
}
func ConvertFromPublisheds(ps []*model.Published, ds []*model.PublishedVersion) []*PublishedDto {
vm := make(map[int32]*model.PublishedVersion)
for _, m := range ds {
vm[m.ID] = m
}
var result []*PublishedDto
for _, p := range ps {
result = append(result, ConvertFromPublished(p, vm[p.DataID]))
}
return result
}
func ConvertFromPublished(gi *model.Published, d *model.PublishedVersion) *PublishedDto {
return &PublishedDto{
ID: gi.ID,
Name: gi.Code,
Category: gi.Category,
Type: gi.Type,
Proto: d.Proto,
UserID: d.UserID,
Note: d.Note,
PublishAt: JsonTime(d.PublishAt),
}
PublishAt JsonTime `json:"publishAt" form:"publishAt" time_format:"2006-01-02 15:04:05"`
Status int32 `json:"status" form:"status"`
}
type PublishReqDto struct {
@ -53,6 +30,14 @@ type PublishReqDto struct {
//草稿数据的id
DraftId int32 `json:"draftId" form:"draftId"`
Note string `json:"note" form:"note"`
// 强制覆盖
Force bool `json:"force" form:"force"`
}
type PublishChangeReqDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
Release bool `json:"release" form:"release"`
}
// PublishedGiSingleQueryDto 单个查询发布地图数据
@ -60,3 +45,11 @@ type PublishedSingleQueryDto struct {
Name string `json:"name" form:"name"`
Detail bool `json:"detail" form:"detail"`
}
type PublishHistoryDto struct {
Id int32 `json:"id" form:"id"`
Publisher string `json:"publisher" form:"publisher"`
PublishAt JsonTime `json:"publishAt" time_format:"2006-01-02 15:04:05"`
Version int32 `json:"version" form:"version"`
Note string `json:"note" form:"note"`
}

View File

@ -2,7 +2,6 @@ package dto
import (
"google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
)
@ -13,6 +12,7 @@ type PageTrainInfoReqDto struct {
type TrainInfoReqDto struct {
Name string `json:"name" form:"name"`
Pid int32 `json:"pid" form:"pid"`
}
type TrainInfoDto struct {
@ -27,21 +27,21 @@ type TrainInfoDto struct {
Description string `json:"description" form:"description"`
}
func ConvertToTrainInfoDto(trailInfos []*model.TrainInfo) []*TrainInfoDto {
func ConvertToTrainDto(trailInfos []*PublishedDto) []*TrainInfoDto {
var result []*TrainInfoDto
for _, t := range trailInfos {
result = append(result, ConvertDtoFromTrainInfo(t))
result = append(result, ConvertDtoFromTrain(t))
}
return result
}
func ConvertDtoFromTrainInfo(t *model.TrainInfo) *TrainInfoDto {
func ConvertDtoFromTrain(t *PublishedDto) *TrainInfoDto {
message := &graphicData.Train{}
proto.Unmarshal(t.Proto, message)
return &TrainInfoDto{
Id: t.ID,
Name: t.Name,
Description: t.Description,
Description: t.Note,
TrainModel: int32(message.TrainModel),
CarriageLength: message.CarriageLength,
TotalLength: message.TotalLength,
@ -50,18 +50,3 @@ func ConvertDtoFromTrainInfo(t *model.TrainInfo) *TrainInfoDto {
TrainSets: message.TrainSets,
}
}
func ConvertTrainInfoFromDto(t *TrainInfoDto) *model.TrainInfo {
info := &model.TrainInfo{Name: t.Name, Description: t.Description}
message := &graphicData.Train{
TrainModel: graphicData.Train_TrainModel(t.TrainModel),
CarriageLength: t.CarriageLength,
TotalLength: t.TotalLength,
MinDiameter: t.MinDiameter,
MaxDiameter: t.MaxDiameter,
TrainSets: t.TrainSets,
}
b, _ := proto.Marshal(message)
info.Proto = b
return info
}

View File

@ -5,7 +5,6 @@ import (
"sync"
"time"
"gorm.io/gorm/clause"
"joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
@ -16,128 +15,157 @@ var publishMapMutex sync.Mutex
// 查找发布地图分页信息
func PageQueryPublished(req *dto.PagePublishedReqDto) *dto.PageDto {
dp := dbquery.Published
where := dp.Where(dp.Status.Eq(1))
p, pv := dbquery.Published, dbquery.PublishedVersion
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, p.Status, pv.Note, pv.PublishAt).
LeftJoin(pv, p.DataID.EqCol(pv.ID)).Order(pv.PublishAt.Desc())
if req.Name != "" {
where = where.Where(dp.Code.Like(fmt.Sprintf("%%%s%%", req.Name)))
where = where.Where(p.Code.Like(fmt.Sprintf("%%%s%%", req.Name)))
}
result, count, err := where.Debug().FindByPage(req.Offset(), req.Size)
if req.Release {
where = where.Where(p.Status.Eq(1))
}
var records []*dto.PublishedDto
count, err := where.Debug().ScanByPage(&records, req.Offset(), req.Size)
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
var dataIds []int32 // 数据列表
for _, r := range result {
dataIds = append(dataIds, r.DataID)
}
pv := dbquery.PublishedVersion
protoDatas, err := pv.Select(pv.ID, pv.Note, pv.PublishAt).Where(pv.ID.In(dataIds...)).Find()
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
return &dto.PageDto{
Total: int(count),
PageQueryDto: req.PageQueryDto,
Records: dto.ConvertFromPublisheds(result, protoDatas),
}
return &dto.PageDto{Total: int(count), PageQueryDto: req.PageQueryDto, Records: records}
}
// 地图信息列表信息
func ListQueryPublished(req *dto.PublishedListReqDto) []*dto.PublishedDto {
where := dbquery.Published.Where(dbquery.Published.Status.Eq(1))
p := dbquery.Published
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category).Where(p.Status.Eq(1))
if req.Name != "" {
where = where.Where(dbquery.Published.Code.Like(fmt.Sprintf("%%%s%%", req.Name)))
}
result, err := where.Debug().Find()
if req.Type != 0 {
where = where.Where(dbquery.Published.Type.Eq(req.Type))
}
if req.Category != "" {
where = where.Where(dbquery.Published.Category.Eq(req.Category))
}
var records []*dto.PublishedDto
err := where.Debug().Scan(&records)
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
var dataIds []int32 // 数据列表
for _, r := range result {
dataIds = append(dataIds, r.DataID)
}
pv := dbquery.PublishedVersion
protoDatas, err := pv.Select(pv.ID, pv.Proto, pv.Note, pv.PublishAt).Where(pv.ID.In(dataIds...)).Find()
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
return dto.ConvertFromPublisheds(result, protoDatas)
return records
}
// 项目启动时查询发布地图信息
func ListAllPublished() []*dto.PublishedDto {
p := dbquery.Published
result, err := p.Select(p.ID, p.Code, p.Type, p.DataID).Where(dbquery.Published.Status.Eq(1)).Debug().Find()
p, pv := dbquery.Published, dbquery.PublishedVersion
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto).
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
Where(p.Status.Eq(1), p.Type.Neq(trainDataType)).Order(pv.PublishAt)
var records []*dto.PublishedDto
err := where.Debug().Scan(&records)
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
var dataIds []int32 // 数据列表
for _, r := range result {
dataIds = append(dataIds, r.DataID)
}
pv := dbquery.PublishedVersion
protoDatas, err := pv.Select(pv.ID, pv.Proto, pv.Note, pv.PublishAt).Where(pv.ID.In(dataIds...)).Find()
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
return dto.ConvertFromPublisheds(result, protoDatas)
return records
}
// 查询详细信息
func GetPublishedById(id int32) *dto.PublishedDto {
data, err := dbquery.Published.Where(dbquery.Published.ID.Eq(id)).Debug().First()
p, pv := dbquery.Published, dbquery.PublishedVersion
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto).
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
Where(p.ID.Eq(id), p.Status.Eq(1))
var record dto.PublishedDto
err := where.Debug().Scan(&record)
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
pv := dbquery.PublishedVersion
protoData, err := pv.Where(pv.ID.Eq(data.DataID)).Debug().First()
if err != nil {
panic(sys_error.New("查询发布地图信息失败", err))
}
return dto.ConvertFromPublished(data, protoData)
return &record
}
// 草稿发布
func PublishFormDraft(req *dto.PublishReqDto, user *model.User) {
publishMapMutex.Lock()
defer publishMapMutex.Unlock()
draft := QueryDrafting(req.DraftId)
if draft.Proto == nil || len(draft.Proto) == 0 {
panic(sys_error.New(fmt.Sprintf("草稿[%v]绘图数据信息为空", req.DraftId)))
}
// 查询版本信息
vds, _ := dbquery.PublishedVersion.Select(dbquery.PublishedVersion.Version).
Where(dbquery.PublishedVersion.Code.Eq(req.Name)).Order(dbquery.PublishedVersion.Version.Desc()).Find()
var version int32 = 1
if len(vds) > 0 {
version = version + vds[len(vds)-1].Version
}
// 存入新版本数据
err := dbquery.PublishedVersion.Save(&model.PublishedVersion{
Code: req.Name,
publishData(&dto.PublishedDto{
Name: req.Name,
Proto: draft.Proto,
Type: draft.Type,
Category: draft.Category,
UserID: user.ID,
PublishAt: time.Now(),
Note: req.Note,
Version: version,
})
if err != nil {
panic(sys_error.New("发布草稿数据失败", err))
}
versionData, err := dbquery.PublishedVersion.Select(dbquery.PublishedVersion.ID).
Where(dbquery.PublishedVersion.Code.Eq(req.Name), dbquery.PublishedVersion.Version.Eq(version)).First()
if err != nil {
panic(sys_error.New("发布草稿数据失败", err))
}
// 更新发布数据
dbquery.Published.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: dbquery.Published.Code.ColumnName().String()}},
DoUpdates: clause.AssignmentColumns([]string{dbquery.Published.DataID.ColumnName().String()}),
}).Create(&model.Published{Code: req.Name, Type: draft.Type, Category: draft.Category, DataID: versionData.ID, Status: 1})
}, req.Force)
}
// 删除发布图
// 发布数据
func publishData(publishData *dto.PublishedDto, force bool) {
publishMapMutex.Lock()
defer publishMapMutex.Unlock()
p, pv := dbquery.Published, dbquery.PublishedVersion
// 查询发布图数据
oldPs, err1 := p.Where(p.Code.Eq(publishData.Name)).Find()
if err1 != nil {
panic(sys_error.New("发布草稿数据失败", err1))
}
var pid, version int32 = 0, 1
if len(oldPs) > 0 { // 发布图数据不为空
pid = oldPs[0].ID
if oldPs[0].Category != publishData.Category || publishData.Type != oldPs[0].Type {
if !force { // 非强制覆盖
panic(sys_error.New("草稿数据与在线数据类型不一致"))
} else {
p.
Where(p.ID.Eq(pid)).
UpdateColumns(&model.Published{ID: pid, Type: publishData.Type, Category: publishData.Category})
}
}
vds, _ := pv.Select(pv.Version).Where(pv.PublishID.Eq(pid)).Order(pv.Version.Desc()).Find()
if len(vds) > 0 { // 版本号 + 1
version = version + vds[0].Version
}
}
// 存入新版本数据
pvd := &model.PublishedVersion{
Code: publishData.Name,
Proto: publishData.Proto,
UserID: publishData.UserID,
Note: publishData.Note,
Type: publishData.Type,
Category: publishData.Category,
PublishAt: time.Now(),
Version: version,
PublishID: pid,
}
err2 := pv.Create(pvd)
if err2 != nil {
panic(sys_error.New("发布草稿数据失败", err2))
}
// 更新发布数据
if pid == 0 {
pd := &model.Published{
Code: publishData.Name,
Type: publishData.Type,
Category: publishData.Category,
DataID: pvd.ID,
Status: 1,
}
// 保存发布信息
err4 := p.Create(pd)
if err4 != nil {
panic(sys_error.New("发布草稿数据失败", err4))
}
// 更新发布版本信息
pv.Where(pv.ID.Eq(pvd.ID)).UpdateColumn(pv.PublishID, pd.ID)
} else {
// 更新发布信息
p.Where(p.ID.Eq(pid)).UpdateColumn(p.DataID, pvd.ID)
}
}
// 删除发布数据
func DeletePublishedById(id int32) {
dbquery.Published.Debug().Where(dbquery.Published.ID.Eq(id)).UpdateColumn(dbquery.Published.Status, 0)
dbquery.Published.Where(dbquery.Published.ID.Eq(id)).Delete()
dbquery.PublishedVersion.Where(dbquery.PublishedVersion.PublishID.Eq(id)).Delete()
dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Mid.In(id)).Delete()
}
@ -147,22 +175,21 @@ func SaveAsDraftingFromPublish(id int32, user *model.User, name string) {
if num > 0 { // 处理重名情况
panic(sys_error.New(fmt.Sprintf("草稿【%s】已存在", name)))
}
published, err := dbquery.Published.Where(dbquery.Published.ID.Eq(id)).Debug().First()
p, pv := dbquery.Published, dbquery.PublishedVersion
where := p.Select(p.Type, p.Category, pv.Proto).LeftJoin(pv, p.DataID.EqCol(pv.ID)).Where(p.ID.Eq(id), p.Status.Eq(1))
var record dto.PublishedDto
err := where.Debug().Scan(&record)
if err != nil {
panic(sys_error.New("查询发布数据出错", err))
}
versionData, err := dbquery.PublishedVersion.Where(dbquery.PublishedVersion.ID.Eq(published.DataID)).First()
if err != nil {
panic(sys_error.New("查询发布数据出错", err))
panic(sys_error.New("查询发布地图信息失败", err))
}
err1 := dbquery.Drafting.Save(&model.Drafting{
Name: name,
Category: published.Category,
Proto: versionData.Proto,
Category: record.Category,
Proto: record.Proto,
CreatorID: user.ID,
CreatedAt: time.Now(),
UpdateAt: time.Now(),
Type: published.Type,
Type: record.Type,
})
if err1 != nil {
panic(sys_error.New("保存草稿出错", err1))
@ -172,37 +199,66 @@ func SaveAsDraftingFromPublish(id int32, user *model.User, name string) {
// 查询项目关联的详细数据
func QueryProjectPublished(id int32) []*model.Published {
// 获取项目关联的发布地图
dppl := dbquery.ProjectPublishLink
links, _ := dppl.Select(dppl.Mid).Where(dppl.Pid.Eq(id)).Find()
if len(links) == 0 {
return nil
dppl, p := dbquery.ProjectPublishLink, dbquery.Published
var publisheds []*model.Published
err := dppl.Select(p.ID, p.Code, p.Category, p.Type).
LeftJoin(p, p.ID.EqCol(dppl.Mid)).
Where(dppl.Pid.Eq(id), p.Status.Eq(1)).Debug().Order(p.Type, p.Code).Scan(&publisheds)
if err != nil {
panic(sys_error.New("发布草稿数据失败", err))
}
mids := make([]int32, len(links))
for i, m := range links {
mids[i] = m.Mid
}
dp := dbquery.Published
publisheds, _ := dp.
Select(dp.ID, dp.Code, dp.Category, dp.Type).
Where(dp.ID.In(mids...), dp.Status.Eq(1)).
Order(dp.Type, dp.Code).
Find()
return publisheds
}
// 根据名称获取地图详细信息
func GetPublishedGiByName(param *dto.PublishedSingleQueryDto) *dto.PublishedDto {
published, err := dbquery.Published.Where(dbquery.Published.Code.Eq(param.Name), dbquery.Published.Status.Eq(1)).Debug().First()
p, pv := dbquery.Published, dbquery.PublishedVersion
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto).
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
Where(p.Code.Eq(param.Name), p.Status.Eq(1))
var record dto.PublishedDto
err := where.Debug().Scan(&record)
if err != nil {
panic(sys_error.New("查询发布数据出错", err))
panic(sys_error.New("查询发布地图信息失败", err))
}
detailData := &model.PublishedVersion{}
if param.Detail {
versionData, err := dbquery.PublishedVersion.Where(dbquery.PublishedVersion.ID.Eq(published.DataID)).First()
return &record
}
// 修改发布数据状态
func ChangePublishStatus(id int32, release bool) {
var status int
if release {
status = 1
}
dbquery.Published.Debug().Where(dbquery.Published.ID.Eq(id)).UpdateColumn(dbquery.Published.Status, status)
if !release { // 下架时,删除关联关系
dbquery.ProjectPublishLink.Where(dbquery.ProjectPublishLink.Mid.In(id)).Delete()
}
}
// 修改发布Code
func ChangePublishCode(id int32, code string) {
p := dbquery.Published
count, err := p.Where(p.ID.Neq(id), p.Code.Eq(code)).Count()
if err != nil {
panic(sys_error.New("查询发布数据出错", err))
panic(sys_error.New("修改发布名称失败", err))
}
detailData = versionData
if count > 0 {
panic(sys_error.New("修改名称失败:名称已存在"))
}
return dto.ConvertFromPublished(published, detailData)
p.Debug().Where(dbquery.Published.ID.Eq(id)).UpdateColumn(dbquery.Published.Code, code)
}
// 查询发布历史
func GetPublishHistory(id int32) []*dto.PublishHistoryDto {
u, pv := dbquery.User, dbquery.PublishedVersion
var records []*dto.PublishHistoryDto
err := pv.
Select(pv.ID, pv.PublishAt, pv.Note, pv.Version, u.Name.As("publisher")).
LeftJoin(u, u.ID.EqCol(pv.UserID)).
Where(pv.PublishID.Eq(id)).Order(pv.Version.Desc()).Scan(&records)
if err != nil {
panic(sys_error.New("查询发布历史信息失败", err))
}
return records
}

View File

@ -2,72 +2,127 @@ package service
import (
"fmt"
"time"
"google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
)
// 查询列车信息列表
func PageTrainInfoQuery(query *dto.PageTrainInfoReqDto) *dto.PageDto {
d := dbquery.TrainInfo
dq := d.Where()
if query.Name != "" {
dq = dq.Where(d.Name.Like(fmt.Sprintf("%%%s%%", query.Name)))
}
records, total, err := dq.Debug().Select(d.ID, d.Name, d.Proto, d.Description).FindByPage(query.Offset(), query.Size)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToTrainInfoDto(records)}
}
var trainDataType = int32(graphicData.PictureType_TrainData)
// 查询列车信息列表
func ListTrainInfoQuery(query *dto.TrainInfoReqDto) []*model.TrainInfo {
d := dbquery.TrainInfo
dq := d.Where()
func PageTrainInfoByPublished(query *dto.PageTrainInfoReqDto) *dto.PageDto {
d, dv := dbquery.Published, dbquery.PublishedVersion
dq := d.Select(d.ID, d.Code.As("name"), dv.Note, dv.Proto).
LeftJoin(dv, d.DataID.EqCol(dv.ID)).
Where(d.Type.Eq(trainDataType), d.Status.Eq(1)).
Order(dv.PublishAt)
if query.Name != "" {
dq = dq.Where(d.Name.Like(fmt.Sprintf("%%%s%%", query.Name)))
dq = dq.Where(d.Code.Like(fmt.Sprintf("%%%s%%", query.Name)))
}
records, err := dq.Debug().Select(d.ID, d.Name, d.Proto).Find()
var records []*dto.PublishedDto
total, err := dq.Debug().ScanByPage(&records, query.Offset(), query.Size)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
panic(sys_error.New("列车信息查询错误", err))
}
return records
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToTrainDto(records)}
}
// 创建列车信息
func CreateTrainInfo(td *dto.TrainInfoDto) bool {
d := dto.ConvertTrainInfoFromDto(td)
err := dbquery.TrainInfo.Save(d)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
// 根据项目Id查询列车信息
func ListTrainByProject(query *dto.TrainInfoReqDto) []*dto.TrainInfoDto {
ppl, p, pv := dbquery.ProjectPublishLink, dbquery.Published, dbquery.PublishedVersion
where := ppl.Select(p.ID, p.Code.As("name"), pv.Note, pv.Proto).
LeftJoin(p, ppl.Mid.EqCol(p.ID)).
LeftJoin(pv, p.DataID.EqCol(pv.ID))
if query.Name != "" {
where = where.Where(p.Code.Like(fmt.Sprintf("%%%s%%", query.Name)))
}
if query.Pid != 0 {
where = where.Where(ppl.Pid.Eq(query.Pid))
}
var records []*dto.PublishedDto
err := where.Where(p.Type.Eq(trainDataType), p.Status.Eq(1)).Order(pv.PublishAt).Scan(&records)
if err != nil {
panic(sys_error.New("列车信息查询错误", err))
}
return dto.ConvertToTrainDto(records)
}
// 发布列车信息
func CreateTrain(td *dto.TrainInfoDto, user *model.User) bool {
publishData(&dto.PublishedDto{
Name: td.Name,
Proto: convertTrainProto(td),
Type: trainDataType,
UserID: user.ID,
Note: td.Description,
}, true)
return true
}
// 转成列车proto
func convertTrainProto(t *dto.TrainInfoDto) []byte {
message := &graphicData.Train{
TrainModel: graphicData.Train_TrainModel(t.TrainModel),
CarriageLength: t.CarriageLength,
TotalLength: t.TotalLength,
MinDiameter: t.MinDiameter,
MaxDiameter: t.MaxDiameter,
TrainSets: t.TrainSets,
}
b, _ := proto.Marshal(message)
return b
}
// 查询列车信息
func QueryTrainInfo(id int32) *dto.TrainInfoDto {
dt := dbquery.TrainInfo
data, err := dt.Where(dt.ID.Eq(id)).Debug().First()
func QueryTrain(id int32) *dto.TrainInfoDto {
d, dv := dbquery.Published, dbquery.PublishedVersion
var record dto.PublishedDto
err := d.Select(d.ID, d.Code.As("name"), dv.Note, dv.Proto).
LeftJoin(dv, d.DataID.EqCol(dv.ID)).
Where(d.Type.Eq(trainDataType), d.ID.Eq(id)).
Scan(&record)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
panic(sys_error.New("列车信息查询错误", err))
}
return dto.ConvertDtoFromTrainInfo(data)
return dto.ConvertDtoFromTrain(&record)
}
// 更新列车信息
func UpdateTrainInfo(id int32, td *dto.TrainInfoDto) bool {
d := dto.ConvertTrainInfoFromDto(td)
d.ID = id
_, err2 := dbquery.TrainInfo.Updates(d)
func UpdateTrain(id int32, td *dto.TrainInfoDto, user *model.User) bool {
p, pv := dbquery.Published, dbquery.PublishedVersion
pd, err := p.Select(p.ID, p.Code, p.DataID).Where(p.ID.Eq(id)).First()
if err != nil {
panic(sys_error.New("更新列车信息错误", err))
}
if td.Name != pd.Code {
ChangePublishCode(id, td.Name)
}
pvd, err := pv.Select(pv.Version).Where(pv.ID.Eq(pd.DataID)).First()
if err != nil {
panic(sys_error.New("更新列车信息错误", err))
}
pvdn := &model.PublishedVersion{
Proto: convertTrainProto(td),
UserID: user.ID,
PublishAt: time.Now(),
Note: td.Description,
Version: pvd.Version + 1,
Code: td.Name,
PublishID: id,
Type: trainDataType,
}
err2 := pv.Create(pvdn)
if err2 != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err2.Error()})
panic(sys_error.New("更新列车信息错误", err2))
}
_, err3 := p.Where(p.ID.Eq(id)).UpdateColumn(p.DataID, pvdn.ID)
if err3 != nil {
panic(sys_error.New("更新列车信息错误", err3))
}
return true
}
// 删除列车信息
func DeleteTrainInfoById(id int) {
_, _ = dbquery.TrainInfo.Debug().Where(dbquery.TrainInfo.ID.Eq(int32(id))).Delete()
}

View File

@ -31,6 +31,8 @@ const (
PictureType_RelayCabinetLayout PictureType = 2
// * IBP盘
PictureType_IBP PictureType = 3
// * 列车数据
PictureType_TrainData PictureType = 4
)
// Enum value maps for PictureType.
@ -40,12 +42,14 @@ var (
1: "Psl",
2: "RelayCabinetLayout",
3: "IBP",
4: "TrainData",
}
PictureType_value = map[string]int32{
"StationLayout": 0,
"Psl": 1,
"RelayCabinetLayout": 2,
"IBP": 3,
"TrainData": 4,
}
)
@ -80,13 +84,14 @@ var File_picture_proto protoreflect.FileDescriptor
var file_picture_proto_rawDesc = []byte{
0x0a, 0x0d, 0x70, 0x69, 0x63, 0x74, 0x75, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a,
0x4a, 0x0a, 0x0b, 0x50, 0x69, 0x63, 0x74, 0x75, 0x72, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x11,
0x59, 0x0a, 0x0b, 0x50, 0x69, 0x63, 0x74, 0x75, 0x72, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x11,
0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x10,
0x00, 0x12, 0x07, 0x0a, 0x03, 0x50, 0x73, 0x6c, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, 0x52, 0x65,
0x6c, 0x61, 0x79, 0x43, 0x61, 0x62, 0x69, 0x6e, 0x65, 0x74, 0x4c, 0x61, 0x79, 0x6f, 0x75, 0x74,
0x10, 0x02, 0x12, 0x07, 0x0a, 0x03, 0x49, 0x42, 0x50, 0x10, 0x03, 0x42, 0x19, 0x5a, 0x17, 0x2e,
0x2f, 0x74, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x72, 0x61, 0x70, 0x68,
0x69, 0x63, 0x44, 0x61, 0x74, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x10, 0x02, 0x12, 0x07, 0x0a, 0x03, 0x49, 0x42, 0x50, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x54,
0x72, 0x61, 0x69, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x10, 0x04, 0x42, 0x19, 0x5a, 0x17, 0x2e, 0x2f,
0x74, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69,
0x63, 0x44, 0x61, 0x74, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

File diff suppressed because it is too large Load Diff