diff --git a/api/category.go b/api/category.go new file mode 100644 index 0000000..dd5dce2 --- /dev/null +++ b/api/category.go @@ -0,0 +1,213 @@ +package api + +import ( + "net/http" + "strconv" + + jwt "github.com/appleboy/gin-jwt/v2" + "github.com/gin-gonic/gin" + "go.uber.org/zap" + "joylink.club/bj-rtsts-server/dto" + "joylink.club/bj-rtsts-server/middleware" + "joylink.club/bj-rtsts-server/service" +) + +func InitCategoryRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + authed := api.Group("/v1/category").Use(authMiddleware.MiddlewareFunc()) + authed.GET("/paging", pageQueryCategory) + authed.GET("/list", listQueryCategory) + authed.POST("", createCategory) + authed.GET("/:id", queryCategoryInfo) + authed.PUT("/:id", updateCategoryInfo) + authed.DELETE("/:id", deleteCategory) +} + +// 分页查询厂家信息 +// +// @Summary 分页查询厂家信息 +// +// @Security JwtAuth +// +// @Description 可以通过厂家名称过滤,分页查询厂家信息 +// @Tags 厂家信息Api +// @Accept json +// @Produce json +// @Param PageCategoryReqDto query dto.PageCategoryReqDto true "厂家查询条件带分页信息" +// @Success 200 {object} dto.PageDto +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/category/paging [get] +func pageQueryCategory(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + zap.S().Debug("分页查询厂家", user) + req := dto.PageCategoryReqDto{} + if err := c.ShouldBind(&req); err != nil { + zap.S().Warn("分页查询参数绑定错误,使用默认参数", err) + req.Default() + } + zap.S().Debug("分页查厂家参数", req) + page, err := service.PageCategoryQuery(&req) + if err != nil { + c.JSON(http.StatusInternalServerError, err.Error()) + return + } + c.JSON(http.StatusOK, page) +} + +// 查询厂家信息列表 +// +// @Summary 查询厂家信息列表 +// +// @Security JwtAuth +// +// @Description 可以通过厂家名称过滤,查询厂家信息列表 +// @Tags 厂家信息Api +// @Accept json +// @Produce json +// @Param PageCategoryReqDto query dto.PageCategoryReqDto true "厂家查询条件" +// @Success 200 {object} dto.PageDto +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/category/list [get] +func listQueryCategory(c *gin.Context) { + req := dto.PageCategoryReqDto{} + if err := c.ShouldBind(&req); err != nil { + zap.S().Warn("查询参数绑定错误,使用默认参数", err) + req.Default() + } + zap.S().Debug("查厂家参数", req) + page, err := service.ListCategoryQuery(&req) + if err != nil { + c.JSON(http.StatusInternalServerError, err.Error()) + return + } + c.JSON(http.StatusOK, page) +} + +// 创建厂家信息 +// +// @Summary 创建厂家信息 +// +// @Security JwtAuth +// +// @Description 创建厂家数据 +// @Tags 厂家信息Api +// @Accept json +// @Produce json +// @Param CategoryDto query dto.CategoryDto true "创建的厂家信息" +// @Success 200 {object} nil +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/category [post] +func createCategory(c *gin.Context) { + req := dto.CategoryDto{} + if err := c.ShouldBind(&req); err != nil { + c.JSON(http.StatusBadRequest, "传入参数错误") + return + } + zap.S().Debug("保存数据", req) + data, err := service.CreateCategory(&req) + if err != nil { + c.JSON(http.StatusInternalServerError, err.Error()) + return + } + c.JSON(http.StatusOK, data) +} + +// 查询厂家信息 +// +// @Summary 查询厂家信息 +// +// @Security JwtAuth +// +// @Description 查询厂家信息 +// @Tags 厂家信息Api +// @Accept json +// @Produce json +// @Param id path int true "厂家ID" +// @Success 200 {object} model.Drafting +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/category/:id [get] +func queryCategoryInfo(c *gin.Context) { + id, exist := c.Params.Get("id") + if !exist { + c.JSON(http.StatusBadRequest, "必要参数id不存在") + return + } + zap.S().Debug("传入参数id为" + id) + int64Id, _ := strconv.ParseInt(id, 10, 64) + c.JSON(http.StatusOK, service.QueryCategory(int32(int64Id))) +} + +// 修改厂家信息 +// +// @Summary 修改厂家信息 +// +// @Security JwtAuth +// +// @Description 修改厂家信息 +// @Tags 厂家信息Api +// @Accept json +// @Produce json +// @Param id path int true "厂家信息ID" +// @Param CategoryDto query dto.CategoryDto true "修改的厂家信息" +// @Success 200 {object} nil +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/category/:id [put] +func updateCategoryInfo(c *gin.Context) { + id, exist := c.Params.Get("id") + if !exist { + c.JSON(http.StatusBadRequest, "必要参数id不存在") + return + } + zap.S().Debug("传入参数id为" + id) + req := dto.CategoryDto{} + if err := c.ShouldBind(&req); err != nil { + c.JSON(http.StatusBadRequest, "保存参数出错") + return + } + int64Id, _ := strconv.ParseInt(id, 10, 64) + result := service.UpdateCategory(int32(int64Id), &req) + if !result { + c.JSON(http.StatusInternalServerError, "保存参数出错") + return + } + c.JSON(http.StatusOK, result) +} + +// 删除厂家信息 +// +// @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 +// @Router /api/v1/category/:id [delete] +func deleteCategory(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 { + c.JSON(http.StatusBadRequest, "id参数解析错误") + panic("id参数解析错误") + } + zap.S().Debug("id查询草稿的图形数据", id) + service.DeleteCategoryById(id) + c.JSON(http.StatusOK, true) +} diff --git a/db/dbquery/category.gen.go b/db/dbquery/category.gen.go new file mode 100644 index 0000000..5cc890c --- /dev/null +++ b/db/dbquery/category.gen.go @@ -0,0 +1,396 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package dbquery + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "joylink.club/bj-rtsts-server/db/model" +) + +func newCategory(db *gorm.DB, opts ...gen.DOOption) category { + _category := category{} + + _category.categoryDo.UseDB(db, opts...) + _category.categoryDo.UseModel(&model.Category{}) + + tableName := _category.categoryDo.TableName() + _category.ALL = field.NewAsterisk(tableName) + _category.ID = field.NewInt32(tableName, "id") + _category.Name = field.NewString(tableName, "name") + _category.Config = field.NewString(tableName, "config") + _category.CreatedAt = field.NewTime(tableName, "created_at") + _category.UpdateAt = field.NewTime(tableName, "update_at") + + _category.fillFieldMap() + + return _category +} + +type category struct { + categoryDo + + ALL field.Asterisk + ID field.Int32 // id + Name field.String // 厂家名 + Config field.String // 厂家配置 + CreatedAt field.Time // 创建时间 + UpdateAt field.Time // 修改时间 + + fieldMap map[string]field.Expr +} + +func (c category) Table(newTableName string) *category { + c.categoryDo.UseTable(newTableName) + return c.updateTableName(newTableName) +} + +func (c category) As(alias string) *category { + c.categoryDo.DO = *(c.categoryDo.As(alias).(*gen.DO)) + return c.updateTableName(alias) +} + +func (c *category) updateTableName(table string) *category { + c.ALL = field.NewAsterisk(table) + c.ID = field.NewInt32(table, "id") + c.Name = field.NewString(table, "name") + c.Config = field.NewString(table, "config") + c.CreatedAt = field.NewTime(table, "created_at") + c.UpdateAt = field.NewTime(table, "update_at") + + c.fillFieldMap() + + return c +} + +func (c *category) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := c.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (c *category) fillFieldMap() { + c.fieldMap = make(map[string]field.Expr, 5) + c.fieldMap["id"] = c.ID + c.fieldMap["name"] = c.Name + c.fieldMap["config"] = c.Config + c.fieldMap["created_at"] = c.CreatedAt + c.fieldMap["update_at"] = c.UpdateAt +} + +func (c category) clone(db *gorm.DB) category { + c.categoryDo.ReplaceConnPool(db.Statement.ConnPool) + return c +} + +func (c category) replaceDB(db *gorm.DB) category { + c.categoryDo.ReplaceDB(db) + return c +} + +type categoryDo struct{ gen.DO } + +type ICategoryDo interface { + gen.SubQuery + Debug() ICategoryDo + WithContext(ctx context.Context) ICategoryDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() ICategoryDo + WriteDB() ICategoryDo + As(alias string) gen.Dao + Session(config *gorm.Session) ICategoryDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) ICategoryDo + Not(conds ...gen.Condition) ICategoryDo + Or(conds ...gen.Condition) ICategoryDo + Select(conds ...field.Expr) ICategoryDo + Where(conds ...gen.Condition) ICategoryDo + Order(conds ...field.Expr) ICategoryDo + Distinct(cols ...field.Expr) ICategoryDo + Omit(cols ...field.Expr) ICategoryDo + Join(table schema.Tabler, on ...field.Expr) ICategoryDo + LeftJoin(table schema.Tabler, on ...field.Expr) ICategoryDo + RightJoin(table schema.Tabler, on ...field.Expr) ICategoryDo + Group(cols ...field.Expr) ICategoryDo + Having(conds ...gen.Condition) ICategoryDo + Limit(limit int) ICategoryDo + Offset(offset int) ICategoryDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) ICategoryDo + Unscoped() ICategoryDo + Create(values ...*model.Category) error + CreateInBatches(values []*model.Category, batchSize int) error + Save(values ...*model.Category) error + First() (*model.Category, error) + Take() (*model.Category, error) + Last() (*model.Category, error) + Find() ([]*model.Category, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Category, err error) + FindInBatches(result *[]*model.Category, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.Category) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) ICategoryDo + Assign(attrs ...field.AssignExpr) ICategoryDo + Joins(fields ...field.RelationField) ICategoryDo + Preload(fields ...field.RelationField) ICategoryDo + FirstOrInit() (*model.Category, error) + FirstOrCreate() (*model.Category, error) + FindByPage(offset int, limit int) (result []*model.Category, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) ICategoryDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (c categoryDo) Debug() ICategoryDo { + return c.withDO(c.DO.Debug()) +} + +func (c categoryDo) WithContext(ctx context.Context) ICategoryDo { + return c.withDO(c.DO.WithContext(ctx)) +} + +func (c categoryDo) ReadDB() ICategoryDo { + return c.Clauses(dbresolver.Read) +} + +func (c categoryDo) WriteDB() ICategoryDo { + return c.Clauses(dbresolver.Write) +} + +func (c categoryDo) Session(config *gorm.Session) ICategoryDo { + return c.withDO(c.DO.Session(config)) +} + +func (c categoryDo) Clauses(conds ...clause.Expression) ICategoryDo { + return c.withDO(c.DO.Clauses(conds...)) +} + +func (c categoryDo) Returning(value interface{}, columns ...string) ICategoryDo { + return c.withDO(c.DO.Returning(value, columns...)) +} + +func (c categoryDo) Not(conds ...gen.Condition) ICategoryDo { + return c.withDO(c.DO.Not(conds...)) +} + +func (c categoryDo) Or(conds ...gen.Condition) ICategoryDo { + return c.withDO(c.DO.Or(conds...)) +} + +func (c categoryDo) Select(conds ...field.Expr) ICategoryDo { + return c.withDO(c.DO.Select(conds...)) +} + +func (c categoryDo) Where(conds ...gen.Condition) ICategoryDo { + return c.withDO(c.DO.Where(conds...)) +} + +func (c categoryDo) Order(conds ...field.Expr) ICategoryDo { + return c.withDO(c.DO.Order(conds...)) +} + +func (c categoryDo) Distinct(cols ...field.Expr) ICategoryDo { + return c.withDO(c.DO.Distinct(cols...)) +} + +func (c categoryDo) Omit(cols ...field.Expr) ICategoryDo { + return c.withDO(c.DO.Omit(cols...)) +} + +func (c categoryDo) Join(table schema.Tabler, on ...field.Expr) ICategoryDo { + return c.withDO(c.DO.Join(table, on...)) +} + +func (c categoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICategoryDo { + return c.withDO(c.DO.LeftJoin(table, on...)) +} + +func (c categoryDo) RightJoin(table schema.Tabler, on ...field.Expr) ICategoryDo { + return c.withDO(c.DO.RightJoin(table, on...)) +} + +func (c categoryDo) Group(cols ...field.Expr) ICategoryDo { + return c.withDO(c.DO.Group(cols...)) +} + +func (c categoryDo) Having(conds ...gen.Condition) ICategoryDo { + return c.withDO(c.DO.Having(conds...)) +} + +func (c categoryDo) Limit(limit int) ICategoryDo { + return c.withDO(c.DO.Limit(limit)) +} + +func (c categoryDo) Offset(offset int) ICategoryDo { + return c.withDO(c.DO.Offset(offset)) +} + +func (c categoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICategoryDo { + return c.withDO(c.DO.Scopes(funcs...)) +} + +func (c categoryDo) Unscoped() ICategoryDo { + return c.withDO(c.DO.Unscoped()) +} + +func (c categoryDo) Create(values ...*model.Category) error { + if len(values) == 0 { + return nil + } + return c.DO.Create(values) +} + +func (c categoryDo) CreateInBatches(values []*model.Category, batchSize int) error { + return c.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (c categoryDo) Save(values ...*model.Category) error { + if len(values) == 0 { + return nil + } + return c.DO.Save(values) +} + +func (c categoryDo) First() (*model.Category, error) { + if result, err := c.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.Category), nil + } +} + +func (c categoryDo) Take() (*model.Category, error) { + if result, err := c.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.Category), nil + } +} + +func (c categoryDo) Last() (*model.Category, error) { + if result, err := c.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.Category), nil + } +} + +func (c categoryDo) Find() ([]*model.Category, error) { + result, err := c.DO.Find() + return result.([]*model.Category), err +} + +func (c categoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Category, err error) { + buf := make([]*model.Category, 0, batchSize) + err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (c categoryDo) FindInBatches(result *[]*model.Category, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return c.DO.FindInBatches(result, batchSize, fc) +} + +func (c categoryDo) Attrs(attrs ...field.AssignExpr) ICategoryDo { + return c.withDO(c.DO.Attrs(attrs...)) +} + +func (c categoryDo) Assign(attrs ...field.AssignExpr) ICategoryDo { + return c.withDO(c.DO.Assign(attrs...)) +} + +func (c categoryDo) Joins(fields ...field.RelationField) ICategoryDo { + for _, _f := range fields { + c = *c.withDO(c.DO.Joins(_f)) + } + return &c +} + +func (c categoryDo) Preload(fields ...field.RelationField) ICategoryDo { + for _, _f := range fields { + c = *c.withDO(c.DO.Preload(_f)) + } + return &c +} + +func (c categoryDo) FirstOrInit() (*model.Category, error) { + if result, err := c.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.Category), nil + } +} + +func (c categoryDo) FirstOrCreate() (*model.Category, error) { + if result, err := c.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.Category), nil + } +} + +func (c categoryDo) FindByPage(offset int, limit int) (result []*model.Category, count int64, err error) { + result, err = c.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = c.Offset(-1).Limit(-1).Count() + return +} + +func (c categoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = c.Count() + if err != nil { + return + } + + err = c.Offset(offset).Limit(limit).Scan(result) + return +} + +func (c categoryDo) Scan(result interface{}) (err error) { + return c.DO.Scan(result) +} + +func (c categoryDo) Delete(models ...*model.Category) (result gen.ResultInfo, err error) { + return c.DO.Delete(models) +} + +func (c *categoryDo) withDO(do gen.Dao) *categoryDo { + c.DO = *do.(*gen.DO) + return c +} diff --git a/db/dbquery/drafting.gen.go b/db/dbquery/drafting.gen.go index ca0b856..8b9b4da 100644 --- a/db/dbquery/drafting.gen.go +++ b/db/dbquery/drafting.gen.go @@ -33,6 +33,7 @@ func newDrafting(db *gorm.DB, opts ...gen.DOOption) drafting { _drafting.CreatorID = field.NewInt32(tableName, "creator_id") _drafting.CreatedAt = field.NewTime(tableName, "created_at") _drafting.UpdateAt = field.NewTime(tableName, "update_at") + _drafting.Category = field.NewInt32(tableName, "category") _drafting.fillFieldMap() @@ -49,6 +50,7 @@ type drafting struct { CreatorID field.Int32 // 创建人id CreatedAt field.Time // 创建时间 UpdateAt field.Time // 修改时间 + Category field.Int32 // 厂家id fieldMap map[string]field.Expr } @@ -71,6 +73,7 @@ func (d *drafting) updateTableName(table string) *drafting { d.CreatorID = field.NewInt32(table, "creator_id") d.CreatedAt = field.NewTime(table, "created_at") d.UpdateAt = field.NewTime(table, "update_at") + d.Category = field.NewInt32(table, "category") d.fillFieldMap() @@ -87,13 +90,14 @@ func (d *drafting) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (d *drafting) fillFieldMap() { - d.fieldMap = make(map[string]field.Expr, 6) + d.fieldMap = make(map[string]field.Expr, 7) d.fieldMap["id"] = d.ID d.fieldMap["name"] = d.Name d.fieldMap["proto"] = d.Proto d.fieldMap["creator_id"] = d.CreatorID d.fieldMap["created_at"] = d.CreatedAt d.fieldMap["update_at"] = d.UpdateAt + d.fieldMap["category"] = d.Category } func (d drafting) clone(db *gorm.DB) drafting { diff --git a/db/dbquery/gen.go b/db/dbquery/gen.go index 80338a1..284f136 100644 --- a/db/dbquery/gen.go +++ b/db/dbquery/gen.go @@ -17,6 +17,7 @@ import ( var ( Q = new(Query) + Category *category Drafting *drafting PublishedGi *publishedGi User *user @@ -24,6 +25,7 @@ var ( func SetDefault(db *gorm.DB, opts ...gen.DOOption) { *Q = *Use(db, opts...) + Category = &Q.Category Drafting = &Q.Drafting PublishedGi = &Q.PublishedGi User = &Q.User @@ -32,6 +34,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) { func Use(db *gorm.DB, opts ...gen.DOOption) *Query { return &Query{ db: db, + Category: newCategory(db, opts...), Drafting: newDrafting(db, opts...), PublishedGi: newPublishedGi(db, opts...), User: newUser(db, opts...), @@ -41,6 +44,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query { type Query struct { db *gorm.DB + Category category Drafting drafting PublishedGi publishedGi User user @@ -51,6 +55,7 @@ func (q *Query) Available() bool { return q.db != nil } func (q *Query) clone(db *gorm.DB) *Query { return &Query{ db: db, + Category: q.Category.clone(db), Drafting: q.Drafting.clone(db), PublishedGi: q.PublishedGi.clone(db), User: q.User.clone(db), @@ -68,6 +73,7 @@ func (q *Query) WriteDB() *Query { func (q *Query) ReplaceDB(db *gorm.DB) *Query { return &Query{ db: db, + Category: q.Category.replaceDB(db), Drafting: q.Drafting.replaceDB(db), PublishedGi: q.PublishedGi.replaceDB(db), User: q.User.replaceDB(db), @@ -75,6 +81,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query { } type queryCtx struct { + Category ICategoryDo Drafting IDraftingDo PublishedGi IPublishedGiDo User IUserDo @@ -82,6 +89,7 @@ type queryCtx struct { func (q *Query) WithContext(ctx context.Context) *queryCtx { return &queryCtx{ + Category: q.Category.WithContext(ctx), Drafting: q.Drafting.WithContext(ctx), PublishedGi: q.PublishedGi.WithContext(ctx), User: q.User.WithContext(ctx), diff --git a/db/model/category.gen.go b/db/model/category.gen.go new file mode 100644 index 0000000..32d619e --- /dev/null +++ b/db/model/category.gen.go @@ -0,0 +1,25 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package model + +import ( + "time" +) + +const TableNameCategory = "category" + +// Category mapped from table +type Category struct { + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:id" json:"id"` // id + Name string `gorm:"column:name;not null;comment:厂家名" json:"name"` // 厂家名 + Config string `gorm:"column:config;comment:厂家配置" json:"config"` // 厂家配置 + CreatedAt time.Time `gorm:"column:created_at;not null;comment:创建时间" json:"created_at"` // 创建时间 + UpdateAt time.Time `gorm:"column:update_at;comment:修改时间" json:"update_at"` // 修改时间 +} + +// TableName Category's table name +func (*Category) TableName() string { + return TableNameCategory +} diff --git a/db/model/drafting.gen.go b/db/model/drafting.gen.go index 39a3387..a849186 100644 --- a/db/model/drafting.gen.go +++ b/db/model/drafting.gen.go @@ -18,6 +18,7 @@ type Drafting struct { CreatorID int32 `gorm:"column:creator_id;not null;comment:创建人id" json:"creator_id"` // 创建人id CreatedAt time.Time `gorm:"column:created_at;not null;comment:创建时间" json:"created_at"` // 创建时间 UpdateAt time.Time `gorm:"column:update_at;comment:修改时间" json:"update_at"` // 修改时间 + Category int32 `gorm:"column:category;comment:厂家id" json:"category"` // 厂家id } // TableName Drafting's table name diff --git a/docs/docs.go b/docs/docs.go index 9ebb75d..5741532 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,6 +16,374 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/api/v1/category": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "创建厂家数据", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "创建厂家信息", + "parameters": [ + { + "type": "string", + "name": "config", + "in": "query" + }, + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "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" + } + } + } + } + }, + "/api/v1/category/:id": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "查询厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "查询厂家信息", + "parameters": [ + { + "type": "integer", + "description": "厂家ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model.Drafting" + } + }, + "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" + } + } + } + }, + "put": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "修改厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "修改厂家信息", + "parameters": [ + { + "type": "integer", + "description": "厂家信息ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "config", + "in": "query" + }, + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "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" + } + } + } + }, + "delete": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "删除厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "删除厂家信息", + "parameters": [ + { + "type": "integer", + "description": "厂家信息ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "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" + } + } + } + } + }, + "/api/v1/category/list": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过厂家名称过滤,查询厂家信息列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "查询厂家信息列表", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "current", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageDto" + } + }, + "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" + } + } + } + } + }, + "/api/v1/category/paging": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过厂家名称过滤,分页查询厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "分页查询厂家信息", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "current", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageDto" + } + }, + "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" + } + } + } + } + }, "/api/v1/drafting": { "post": { "security": [ @@ -35,6 +403,11 @@ const docTemplate = `{ ], "summary": "创建草稿", "parameters": [ + { + "type": "integer", + "name": "category", + "in": "query" + }, { "type": "integer", "name": "id", @@ -159,6 +532,11 @@ const docTemplate = `{ "in": "path", "required": true }, + { + "type": "integer", + "name": "category", + "in": "query" + }, { "type": "integer", "name": "id", @@ -280,6 +658,11 @@ const docTemplate = `{ "in": "path", "required": true }, + { + "type": "integer", + "name": "category", + "in": "query" + }, { "type": "integer", "name": "id", @@ -735,7 +1118,7 @@ const docTemplate = `{ "JwtAuth": [] } ], - "description": "创建ATS测试仿真", + "description": "创建并进入仿真后获取仿真的设备信息", "consumes": [ "application/json" ], @@ -745,7 +1128,7 @@ const docTemplate = `{ "tags": [ "ATS测试仿真Api" ], - "summary": "创建ATS测试仿真", + "summary": "创建并进入仿真后获取仿真的设备信息", "parameters": [ { "type": "string", @@ -780,6 +1163,56 @@ const docTemplate = `{ } } }, + "/api/v1/simulation/destroy/{id}": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "ATS测试仿真-添加列车", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ATS测试仿真Api" + ], + "summary": "ATS仿真销毁", + "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "仿真id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, "/api/v1/simulation/list": { "get": { "security": [ @@ -930,56 +1363,6 @@ const docTemplate = `{ } } }, - "/api/v1/simulation/train/destroy/{id}": { - "get": { - "security": [ - { - "JwtAuth": [] - } - ], - "description": "ATS测试仿真-添加列车", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "ATS测试仿真Api" - ], - "summary": "ATS仿真销毁", - "parameters": [ - { - "type": "string", - "description": "JWT Token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "仿真id", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/dto.ErrorDto" - } - } - } - } - }, "/api/v1/simulation/train/remove": { "post": { "security": [ @@ -1435,9 +1818,7 @@ const docTemplate = `{ "type": "object", "required": [ "simulationId", - "switchIndex", - "turnNormal", - "turnReverse" + "switchIndex" ], "properties": { "simulationId": { @@ -1471,6 +1852,10 @@ const docTemplate = `{ "model.Drafting": { "type": "object", "properties": { + "category": { + "description": "厂家id", + "type": "integer" + }, "created_at": { "description": "创建时间", "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index b87c289..955ae49 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -9,6 +9,374 @@ "host": "localhost:9091", "basePath": "/", "paths": { + "/api/v1/category": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "创建厂家数据", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "创建厂家信息", + "parameters": [ + { + "type": "string", + "name": "config", + "in": "query" + }, + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "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" + } + } + } + } + }, + "/api/v1/category/:id": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "查询厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "查询厂家信息", + "parameters": [ + { + "type": "integer", + "description": "厂家ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model.Drafting" + } + }, + "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" + } + } + } + }, + "put": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "修改厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "修改厂家信息", + "parameters": [ + { + "type": "integer", + "description": "厂家信息ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "name": "config", + "in": "query" + }, + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "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" + } + } + } + }, + "delete": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "删除厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "删除厂家信息", + "parameters": [ + { + "type": "integer", + "description": "厂家信息ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "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" + } + } + } + } + }, + "/api/v1/category/list": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过厂家名称过滤,查询厂家信息列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "查询厂家信息列表", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "current", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageDto" + } + }, + "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" + } + } + } + } + }, + "/api/v1/category/paging": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过厂家名称过滤,分页查询厂家信息", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "厂家信息Api" + ], + "summary": "分页查询厂家信息", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "current", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageDto" + } + }, + "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" + } + } + } + } + }, "/api/v1/drafting": { "post": { "security": [ @@ -28,6 +396,11 @@ ], "summary": "创建草稿", "parameters": [ + { + "type": "integer", + "name": "category", + "in": "query" + }, { "type": "integer", "name": "id", @@ -152,6 +525,11 @@ "in": "path", "required": true }, + { + "type": "integer", + "name": "category", + "in": "query" + }, { "type": "integer", "name": "id", @@ -273,6 +651,11 @@ "in": "path", "required": true }, + { + "type": "integer", + "name": "category", + "in": "query" + }, { "type": "integer", "name": "id", @@ -728,7 +1111,7 @@ "JwtAuth": [] } ], - "description": "创建ATS测试仿真", + "description": "创建并进入仿真后获取仿真的设备信息", "consumes": [ "application/json" ], @@ -738,7 +1121,7 @@ "tags": [ "ATS测试仿真Api" ], - "summary": "创建ATS测试仿真", + "summary": "创建并进入仿真后获取仿真的设备信息", "parameters": [ { "type": "string", @@ -773,6 +1156,56 @@ } } }, + "/api/v1/simulation/destroy/{id}": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "ATS测试仿真-添加列车", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ATS测试仿真Api" + ], + "summary": "ATS仿真销毁", + "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "仿真id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, "/api/v1/simulation/list": { "get": { "security": [ @@ -923,56 +1356,6 @@ } } }, - "/api/v1/simulation/train/destroy/{id}": { - "get": { - "security": [ - { - "JwtAuth": [] - } - ], - "description": "ATS测试仿真-添加列车", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "ATS测试仿真Api" - ], - "summary": "ATS仿真销毁", - "parameters": [ - { - "type": "string", - "description": "JWT Token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "仿真id", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/dto.ErrorDto" - } - } - } - } - }, "/api/v1/simulation/train/remove": { "post": { "security": [ @@ -1428,9 +1811,7 @@ "type": "object", "required": [ "simulationId", - "switchIndex", - "turnNormal", - "turnReverse" + "switchIndex" ], "properties": { "simulationId": { @@ -1464,6 +1845,10 @@ "model.Drafting": { "type": "object", "properties": { + "category": { + "description": "厂家id", + "type": "integer" + }, "created_at": { "description": "创建时间", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index caa4980..cbc309f 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -153,8 +153,6 @@ definitions: required: - simulationId - switchIndex - - turnNormal - - turnReverse type: object dto.TokenRespDto: properties: @@ -167,6 +165,9 @@ definitions: type: object model.Drafting: properties: + category: + description: 厂家id + type: integer created_at: description: 创建时间 type: string @@ -215,12 +216,250 @@ info: title: CBTC测试系统API version: "1.0" paths: + /api/v1/category: + post: + consumes: + - application/json + description: 创建厂家数据 + parameters: + - in: query + name: config + type: string + - in: query + name: id + type: integer + - in: query + name: name + type: string + produces: + - application/json + responses: + "200": + description: OK + "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: 创建厂家信息 + tags: + - 厂家信息Api + /api/v1/category/:id: + delete: + consumes: + - application/json + description: 删除厂家信息 + parameters: + - description: 厂家信息ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + "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: 删除厂家信息 + tags: + - 厂家信息Api + get: + consumes: + - application/json + description: 查询厂家信息 + parameters: + - description: 厂家ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/model.Drafting' + "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: 查询厂家信息 + tags: + - 厂家信息Api + put: + consumes: + - application/json + description: 修改厂家信息 + parameters: + - description: 厂家信息ID + in: path + name: id + required: true + type: integer + - in: query + name: config + type: string + - in: query + name: id + type: integer + - in: query + name: name + type: string + produces: + - application/json + responses: + "200": + description: OK + "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: 修改厂家信息 + tags: + - 厂家信息Api + /api/v1/category/list: + get: + consumes: + - application/json + description: 可以通过厂家名称过滤,查询厂家信息列表 + parameters: + - in: query + name: name + type: string + - description: 页码 + example: 1 + in: query + name: current + required: true + type: integer + - description: 页面行数 + example: 10 + in: query + name: size + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.PageDto' + "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: 查询厂家信息列表 + tags: + - 厂家信息Api + /api/v1/category/paging: + get: + consumes: + - application/json + description: 可以通过厂家名称过滤,分页查询厂家信息 + parameters: + - in: query + name: name + type: string + - description: 页码 + example: 1 + in: query + name: current + required: true + type: integer + - description: 页面行数 + example: 10 + in: query + name: size + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.PageDto' + "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: 分页查询厂家信息 + tags: + - 厂家信息Api /api/v1/drafting: post: consumes: - application/json description: 创建草稿数据 parameters: + - in: query + name: category + type: integer - in: query name: id type: integer @@ -332,6 +571,9 @@ paths: name: id required: true type: integer + - in: query + name: category + type: integer - in: query name: id type: integer @@ -377,6 +619,9 @@ paths: name: id required: true type: integer + - in: query + name: category + type: integer - in: query name: id type: integer @@ -673,7 +918,7 @@ paths: post: consumes: - application/json - description: 创建ATS测试仿真 + description: 创建并进入仿真后获取仿真的设备信息 parameters: - description: JWT Token in: header @@ -699,7 +944,39 @@ paths: $ref: '#/definitions/dto.ErrorDto' security: - JwtAuth: [] - summary: 创建ATS测试仿真 + summary: 创建并进入仿真后获取仿真的设备信息 + tags: + - ATS测试仿真Api + /api/v1/simulation/destroy/{id}: + post: + consumes: + - application/json + description: ATS测试仿真-添加列车 + parameters: + - description: JWT Token + in: header + name: Authorization + required: true + type: string + - description: 仿真id + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + type: string + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: ATS仿真销毁 tags: - ATS测试仿真Api /api/v1/simulation/list: @@ -797,38 +1074,6 @@ paths: summary: ATS测试仿真-添加列车 tags: - ATS测试仿真Api - /api/v1/simulation/train/destroy/{id}: - get: - consumes: - - application/json - description: ATS测试仿真-添加列车 - parameters: - - description: JWT Token - in: header - name: Authorization - required: true - type: string - - description: 仿真id - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - type: string - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/dto.ErrorDto' - security: - - JwtAuth: [] - summary: ATS仿真销毁 - tags: - - ATS测试仿真Api /api/v1/simulation/train/remove: post: consumes: diff --git a/dto/category.go b/dto/category.go new file mode 100644 index 0000000..cd7cf97 --- /dev/null +++ b/dto/category.go @@ -0,0 +1,12 @@ +package dto + +type PageCategoryReqDto struct { + PageQueryDto + Name string `json:"name" form:"name"` +} + +type CategoryDto struct { + Id int `json:"id" form:"id"` + Name string `json:"name" form:"name"` + Config string `json:"config" form:"config"` +} diff --git a/dto/drafting.go b/dto/drafting.go index 7a6a1ad..908a799 100644 --- a/dto/drafting.go +++ b/dto/drafting.go @@ -6,7 +6,8 @@ type PageDraftingReqDto struct { } type DraftingDto struct { - Id int `json:"id" form:"id"` - Name string `json:"name" form:"name"` - Proto []byte `json:"proto" from:"proto"` + Id int `json:"id" form:"id"` + Name string `json:"name" form:"name"` + Category int32 `json:"category" form:"category"` + Proto []byte `json:"proto" from:"proto"` } diff --git a/service/category.go b/service/category.go new file mode 100644 index 0000000..5b9b161 --- /dev/null +++ b/service/category.go @@ -0,0 +1,100 @@ +package service + +import ( + "fmt" + "time" + + "joylink.club/bj-rtsts-server/db/dbquery" + "joylink.club/bj-rtsts-server/db/model" + "joylink.club/bj-rtsts-server/dto" +) + +// 查询草稿列表 +func PageCategoryQuery(query *dto.PageCategoryReqDto) (*dto.PageDto, error) { + d := dbquery.Category + 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.UpdateAt, d.CreatedAt).FindByPage(query.Offset(), query.Size) + if err != nil { + panic(err) + } + return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil +} + +// 查询草稿列表 +func ListCategoryQuery(query *dto.PageCategoryReqDto) ([]*model.Category, error) { + d := dbquery.Category + dq := d.Where() + if query.Name != "" { + dq = dq.Where(d.Name.Like(fmt.Sprintf("%%%s%%", query.Name))) + } + records, err := dq.Debug().Select(d.ID, d.Name, d.UpdateAt, d.CreatedAt).Find() + if err != nil { + panic(err) + } + return records, nil +} + +// 创建草稿 +func CreateCategory(dto *dto.CategoryDto) (*model.Category, error) { + if err := checkCategoryInfo(dto.Name); err != nil { + panic(err) + } + d := model.Category{ + Name: dto.Name, + Config: dto.Config, + CreatedAt: time.Now(), + UpdateAt: time.Now(), + } + err := dbquery.Category.Save(&d) + if err != nil { + panic(err) + } + return dbquery.Category.Where(dbquery.Category.Name.Eq(dto.Name)).Order(dbquery.Drafting.CreatedAt).Debug().First() +} + +func QueryCategory(id int32) *model.Category { + data, err := dbquery.Category.Where(dbquery.Category.ID.Eq(id)).Debug().First() + if err != nil { + panic(err) + } + return data +} + +func UpdateCategory(id int32, dto *dto.CategoryDto) bool { + findOldQuery := dbquery.Category + oldD, err := findOldQuery.Where(findOldQuery.ID.Eq(id)).Debug().First() + if oldD == nil || err != nil { + panic(err) + } + if dto.Config != "" { + oldD.Config = dto.Config + } + if len(dto.Name) > 0 { + oldD.Name = dto.Name + } + oldD.UpdateAt = time.Now() + _, error := dbquery.Category.Updates(oldD) + if error != nil { + panic(error) + } + return true +} + +func DeleteCategoryById(id int) { + _, _ = dbquery.Category.Debug().Where(dbquery.Category.ID.Eq(int32(id))).Delete() +} + +func checkCategoryInfo(name string) error { + findNameQuery := dbquery.Category + count, err := findNameQuery.Where(findNameQuery.Name.Eq(name)).Debug().Count() + if err != nil { + panic(err) + } + if count > 0 { + panic("名称已存在") + } + return err +} diff --git a/service/drafting.go b/service/drafting.go index 81d282e..2e09c52 100644 --- a/service/drafting.go +++ b/service/drafting.go @@ -34,6 +34,7 @@ func CreateDrafting(createId int32, dto *dto.DraftingDto) (*model.Drafting, erro CreatorID: createId, CreatedAt: time.Now(), UpdateAt: time.Now(), + Category: dto.Category, } err := dbquery.Drafting.Save(&d) if err != nil { @@ -60,6 +61,7 @@ func SaveAsDrafting(createId int32, oldId int32, dto *dto.DraftingDto) (*model.D CreatorID: createId, CreatedAt: time.Now(), UpdateAt: time.Now(), + Category: oldD.Category, } if err = dbquery.Drafting.Save(&newD); err != nil { panic(err)