【修改API报错信息】

This commit is contained in:
weizhihong 2023-10-20 18:08:06 +08:00
parent a7b7caa9d1
commit ec7738c4f6
13 changed files with 179 additions and 298 deletions

View File

@ -10,6 +10,7 @@ import (
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
"joylink.club/bj-rtsts-server/sys_error"
)
func InitAuthRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -49,13 +50,9 @@ func InitAuthRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware)
func pageQueryRole(c *gin.Context) {
req := dto.PageQueryDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,请求参数异常", err))
}
page, err := service.PageAuthRoleQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageAuthRoleQuery(&req))
}
// 查询角色列表
@ -74,8 +71,7 @@ func pageQueryRole(c *gin.Context) {
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/role/list [get]
func listQueryRole(c *gin.Context) {
page := service.ListAuthRoleQuery()
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.ListAuthRoleQuery())
}
// 创建角色
@ -97,7 +93,7 @@ func listQueryRole(c *gin.Context) {
func createRole(c *gin.Context) {
req := dto.AuthRoleReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("创建失败,请求参数异常", err))
}
slog.Debug("保存数据", req)
c.JSON(http.StatusOK, service.CreateAuthRole(&req))
@ -122,7 +118,7 @@ func createRole(c *gin.Context) {
func queryRoleInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
@ -149,12 +145,12 @@ func queryRoleInfo(c *gin.Context) {
func updateRoleInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
req := dto.AuthRoleReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新角色信息出错,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
rid := int32(int64Id)
@ -184,9 +180,8 @@ func updateRoleInfo(c *gin.Context) {
func deleteRoleInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("删除失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
rid := int32(int64Id)
result := service.DeleteAuthRole(rid)
@ -215,13 +210,9 @@ func deleteRoleInfo(c *gin.Context) {
func pageQueryApiPath(c *gin.Context) {
req := dto.AuthApiPathPageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
page, err := service.PageAuthApiPathQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageAuthApiPathQuery(&req))
}
// 查询接口路径列表
@ -262,7 +253,7 @@ func listQueryApiPath(c *gin.Context) {
func createApiPath(c *gin.Context) {
req := dto.AuthApiPathReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("创建失败,参数格式错误", err))
}
slog.Debug("保存数据", req)
c.JSON(http.StatusOK, service.CreateAuthApiPath(&req))
@ -287,7 +278,7 @@ func createApiPath(c *gin.Context) {
func queryApiPathInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
@ -314,11 +305,11 @@ func queryApiPathInfo(c *gin.Context) {
func updateApiPathInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少id"))
}
req := dto.AuthApiPathReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.UpdateAuthApiPath(int32(int64Id), &req))
@ -343,7 +334,7 @@ func updateApiPathInfo(c *gin.Context) {
func deleteApiPathInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("删除失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
@ -369,7 +360,7 @@ func deleteApiPathInfo(c *gin.Context) {
func assignRoleToUser(c *gin.Context) {
req := dto.AuthRoleUserReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("关联失败,参数格式错误", err))
}
result := service.UserLinkRole(&req)
if result {

View File

@ -10,6 +10,7 @@ import (
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
"joylink.club/bj-rtsts-server/sys_error"
)
func InitCategoryRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -39,18 +40,12 @@ func InitCategoryRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewa
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/category/paging [get]
func pageQueryCategory(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("分页查询厂家", user)
req := dto.PageCategoryReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
slog.Debug("分页查厂家参数", req)
page, err := service.PageCategoryQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageCategoryQuery(&req))
}
// 查询厂家信息列表
@ -72,14 +67,10 @@ func pageQueryCategory(c *gin.Context) {
func listQueryCategory(c *gin.Context) {
req := dto.CategoryReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
slog.Debug("查厂家参数", req)
page, err := service.ListCategoryQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.ListCategoryQuery(&req))
}
// 创建厂家信息
@ -101,14 +92,10 @@ func listQueryCategory(c *gin.Context) {
func createCategory(c *gin.Context) {
req := dto.CategoryDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "传入参数错误"})
panic(sys_error.New("保存失败,参数格式错误", err))
}
slog.Debug("保存数据", req)
data, err := service.CreateCategory(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, data)
c.JSON(http.StatusOK, service.CreateCategory(&req))
}
// 查询厂家信息
@ -130,9 +117,8 @@ func createCategory(c *gin.Context) {
func queryCategoryInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryCategory(int32(int64Id)))
}
@ -157,19 +143,15 @@ func queryCategoryInfo(c *gin.Context) {
func updateCategoryInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
req := dto.CategoryDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
result := service.UpdateCategory(int32(int64Id), &req)
if !result {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存参数出错"})
}
c.JSON(http.StatusOK, result)
c.JSON(http.StatusOK, service.UpdateCategory(int32(int64Id), &req))
}
// 删除厂家信息
@ -189,14 +171,11 @@ func updateCategoryInfo(c *gin.Context) {
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/category/{id} [delete]
func deleteCategory(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("id删除草稿的图形数据", user)
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("删除失败,主键格式错误", err))
}
slog.Debug("id查询草稿的图形数据", id)
service.DeleteCategoryById(id)
c.JSON(http.StatusOK, true)
}

View File

@ -1,7 +1,6 @@
package api
import (
"log/slog"
"net/http"
"strconv"
@ -14,6 +13,7 @@ import (
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
"joylink.club/bj-rtsts-server/sys_error"
)
func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -45,18 +45,11 @@ func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewa
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/drafting/paging [get]
func pageQueryDrafting(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("分页查询草稿", user)
req := dto.PageDraftingReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
slog.Debug("分页查草稿参数", req)
page, err := service.PageDraftingQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageDraftingQuery(&req))
}
// 列表查询草稿
@ -76,18 +69,11 @@ func pageQueryDrafting(c *gin.Context) {
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/drafting/list [get]
func listQueryDrafting(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("列表查询草稿", user)
req := dto.ListDraftingReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
slog.Debug("列表查草稿参数", req)
list, err := service.ListDraftingQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, list)
c.JSON(http.StatusOK, service.ListDraftingQuery(&req))
}
// 创建草稿
@ -111,14 +97,9 @@ func createDrafting(c *gin.Context) {
createId := user.(*model.User).ID
req := dto.DraftingDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("创建失败,参数格式错误", err))
}
slog.Debug("保存数据", req)
data, err := service.CreateDrafting(createId, &req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, data)
c.JSON(http.StatusOK, service.CreateDrafting(createId, &req))
}
// 草稿另存为
@ -141,21 +122,16 @@ func createDrafting(c *gin.Context) {
func saveAsDrafting(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("另存为失败,缺少主键"))
}
slog.Debug("传入参数id为" + id)
user, _ := c.Get(middleware.IdentityKey)
createrId := user.(*model.User).ID
req := dto.DraftingDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("另存为失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
newData, err := service.SaveAsDrafting(createrId, int32(int64Id), &req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, newData)
c.JSON(http.StatusOK, service.SaveAsDrafting(createrId, int32(int64Id), &req))
}
// 查询草稿详情
@ -177,9 +153,8 @@ func saveAsDrafting(c *gin.Context) {
func queryDraftingInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少主键"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryDrafting(int32(int64Id)))
}
@ -204,19 +179,14 @@ func queryDraftingInfo(c *gin.Context) {
func updateDraftingInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少主键"))
}
slog.Debug("传入参数id为" + id)
req := dto.DraftingDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
result := service.UpdateDrafting(int32(int64Id), &req)
if !result {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存出错"})
}
c.JSON(http.StatusOK, result)
c.JSON(http.StatusOK, service.UpdateDrafting(int32(int64Id), &req))
}
// 删除草稿数据
@ -236,14 +206,11 @@ func updateDraftingInfo(c *gin.Context) {
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/drafting/{id} [delete]
func deleteDrafting(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
slog.Debug("id删除草稿的图形数据", user)
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("删除失败,主键格式错误", err))
}
slog.Debug("id查询草稿的图形数据", id)
service.DeleteDraftingById(id)
c.JSON(http.StatusOK, true)
}
@ -267,7 +234,7 @@ func deleteDrafting(c *gin.Context) {
func generateCalculateLinkData(c *gin.Context) {
req := dto.DraftingMapDataDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("link生成失败参数格式错误", err))
}
gd := &graphicData.RtssGraphicStorage{}
proto.Unmarshal(req.Proto, gd)

View File

@ -1,7 +1,6 @@
package api
import (
"log/slog"
"net/http"
"strconv"
@ -10,6 +9,7 @@ import (
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
"joylink.club/bj-rtsts-server/sys_error"
)
func InitProjectRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -41,14 +41,9 @@ func InitProjectRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
func pageQueryProject(c *gin.Context) {
req := dto.PageProjectReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
slog.Debug("分页查项目参数", req)
page, err := service.PageProjectQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageProjectQuery(&req))
}
// 查询项目信息列表
@ -70,14 +65,9 @@ func pageQueryProject(c *gin.Context) {
func listQueryProject(c *gin.Context) {
req := dto.ProjectReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
slog.Debug("查项目参数", req)
page, err := service.ListProjectQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.ListProjectQuery(&req))
}
// 创建项目信息
@ -99,14 +89,9 @@ func listQueryProject(c *gin.Context) {
func createProject(c *gin.Context) {
req := dto.ProjectDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("创建失败,参数格式错误", err))
}
slog.Debug("保存数据", req)
data, err := service.CreateProject(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, data)
c.JSON(http.StatusOK, service.CreateProject(&req))
}
// 查询项目信息
@ -128,9 +113,8 @@ func createProject(c *gin.Context) {
func queryProjectInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少主键"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryProject(int32(int64Id)))
}
@ -155,18 +139,14 @@ func queryProjectInfo(c *gin.Context) {
func updateProjectInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少主键"))
}
req := dto.ProjectDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
result := service.UpdateProject(int32(int64Id), &req)
if !result {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存出错"})
}
c.JSON(http.StatusOK, result)
c.JSON(http.StatusOK, service.UpdateProject(int32(int64Id), &req))
}
// 删除项目信息
@ -189,9 +169,8 @@ func deleteProject(c *gin.Context) {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("删除失败,缺少主键"))
}
slog.Debug("id查询草稿的图形数据", id)
service.DeleteProjectById(id)
c.JSON(http.StatusOK, true)
}

View File

@ -10,6 +10,7 @@ import (
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
"joylink.club/bj-rtsts-server/sys_error"
)
func InitProjectLinkRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -39,7 +40,7 @@ func InitProjectLinkRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
func queryProjectLinkInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
@ -65,7 +66,7 @@ func queryProjectLinkInfo(c *gin.Context) {
func queryTrainSizeByMapId(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
@ -91,7 +92,7 @@ func queryTrainSizeByMapId(c *gin.Context) {
func queryTrainSizeByPId(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少id"))
}
slog.Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
@ -118,7 +119,7 @@ func queryTrainSizeByPId(c *gin.Context) {
func saveProjectLinkInfo(c *gin.Context) {
req := dto.ProjectLinkReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("保持失败,参数格式化错误", err))
}
service.UpdateProjectLink(&req)
c.JSON(http.StatusOK, true)

View File

@ -79,12 +79,10 @@ func initPublishMapInfo() {
func createByProjectId(c *gin.Context) {
req := dto.SimulationCreateReqDto{}
if err := c.ShouldBind(&req); nil != err {
// panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("测试启动失败,请求参数异常", err))
}
mapInfos := service.QueryProjectPublishedGi(req.ProjectId)
if len(mapInfos) == 0 {
// panic(dto.ErrorDto{Code: dto.DataNotExist, Message: "项目未关联地图"})
panic(sys_error.New("测试启动失败,项目未关联发布图"))
}
mapIds := make([]int32, len(mapInfos))
@ -159,12 +157,11 @@ func findAllSimulations(c *gin.Context) {
func checkSimMapData(c *gin.Context) {
rt := &dto.CheckMapDataReqDto{}
if err := c.ShouldBind(&rt); nil != err {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("请求参数异常", err))
}
err := proto.Unmarshal(rt.Data, &graphicData.RtssGraphicStorage{})
if err != nil {
c.JSON(http.StatusInternalServerError, "参数错误")
return
panic(sys_error.New("非平面布置图数据"))
}
c.JSON(http.StatusOK, &dto.CheckMapDataRspDto{Success: true})
}
@ -187,13 +184,12 @@ func checkSimMapData(c *gin.Context) {
func addTrain(c *gin.Context) {
req := dto.AddTrainReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("添加列车失败,请求参数异常", err))
}
simulation := checkDeviceDataAndReturn(req.SimulationId)
id := getAddTrainPrimaryKey(simulation)
if id == -1 {
c.JSON(http.StatusBadRequest, "已存在在线列车")
return
panic(sys_error.New("添加列车失败,已有列车在运行"))
}
rsp := &state.TrainState{
Id: strconv.Itoa(id),
@ -226,7 +222,7 @@ func addTrain(c *gin.Context) {
func removeTrain(c *gin.Context) {
rt := &dto.RemoveTrainDto{}
if err := c.ShouldBind(&rt); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("移除列车失败,请求参数异常", err))
}
slog.Debug("ATS测试仿真-移除列车,请求:", rt)
simulation := checkDeviceDataAndReturn(rt.SimulationId)
@ -254,7 +250,7 @@ func removeTrain(c *gin.Context) {
func switchOperation(c *gin.Context) {
req := &request_proto.TurnoutOperationReq{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("道岔操作失败,请求参数异常", err))
}
simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", "request", req)
@ -308,7 +304,7 @@ func signalOperation(c *gin.Context) {
func esbBtnOperation(c *gin.Context) {
req := &dto.EsbButtonOperationReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("紧急关闭按钮操作失败,请求参数异常", err))
}
simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req)
@ -335,7 +331,7 @@ func esbBtnOperation(c *gin.Context) {
func ibpBtnOperation(c *gin.Context) {
req := &dto.IBPButtonOperationReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("IBP按钮操作失败请求参数异常", err))
}
simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req)
@ -362,7 +358,7 @@ func ibpBtnOperation(c *gin.Context) {
func ibpKeyOperation(c *gin.Context) {
req := &dto.KeyOperationReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("IBP开关操作失败请求参数异常", err))
}
simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req)
@ -434,7 +430,7 @@ func getDataChannelName(c *gin.Context) {
func getMapKilometerRange(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("缺少仿真编号"))
}
simulation := checkDeviceDataAndReturn(id)
c.JSON(http.StatusOK, simulation.Repo.GetCoordinateInfo())
@ -459,7 +455,7 @@ func getMapKilometerRange(c *gin.Context) {
func relayOperation(c *gin.Context) {
req := &dto.RelayOperationReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("继电器操作失败,请求参数异常", err))
}
simulation := checkDeviceDataAndReturn(req.SimulationId)
slog.Info("传入状态参数", req)
@ -471,7 +467,7 @@ func relayOperation(c *gin.Context) {
func checkDeviceDataAndReturn(simId string) *memory.VerifySimulation {
deviceMemory := simulation.FindSimulation(simId)
if deviceMemory == nil {
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("仿真[%s]不存在", simId)})
panic(sys_error.New(fmt.Sprintf("仿真[%s]不存在", simId)))
}
return deviceMemory
}

View File

@ -10,6 +10,7 @@ import (
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
"joylink.club/bj-rtsts-server/sys_error"
)
func InitTrainManageRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -53,13 +54,9 @@ func InitTrainManageRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
func pageQueryTrainModel(c *gin.Context) {
req := dto.PageTrainManageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
page, err := service.PageTrainModelQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageTrainModelQuery(&req))
}
// 创建列车型号
@ -81,13 +78,9 @@ func pageQueryTrainModel(c *gin.Context) {
func createTrainModel(c *gin.Context) {
req := dto.TrainModelDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("保存失败,参数格式错误", err))
}
data, err := service.CreateTrainModel(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, data)
c.JSON(http.StatusOK, service.CreateTrainModel(&req))
}
// 查询列车型号详情
@ -109,7 +102,7 @@ func createTrainModel(c *gin.Context) {
func queryTrainModel(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少主键"))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryTrainModel(int32(int64Id)))
@ -135,18 +128,14 @@ func queryTrainModel(c *gin.Context) {
func updateTrainModel(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少主键"))
}
req := dto.TrainModelDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
result := service.UpdateTrainModel(int32(int64Id), &req)
if !result {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存参数出错"})
}
c.JSON(http.StatusOK, result)
c.JSON(http.StatusOK, service.UpdateTrainModel(int32(int64Id), &req))
}
// 删除列车型号数据
@ -169,7 +158,7 @@ func deleteTrainModel(c *gin.Context) {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("删除失败,缺少主键"))
}
service.DeleteTrainModelById(id)
c.JSON(http.StatusOK, true)
@ -194,13 +183,9 @@ func deleteTrainModel(c *gin.Context) {
func queryTrainModelList(c *gin.Context) {
req := dto.TrainManageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
models, err := service.ListTrainModelQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, models)
c.JSON(http.StatusOK, service.ListTrainModelQuery(&req))
}
// 分页查询列车尺寸列表
@ -222,13 +207,9 @@ func queryTrainModelList(c *gin.Context) {
func pageQueryTrainSize(c *gin.Context) {
req := dto.PageTrainManageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
page, err := service.PageTrainSizeQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageTrainSizeQuery(&req))
}
// 查询列车尺寸列表
@ -250,13 +231,9 @@ func pageQueryTrainSize(c *gin.Context) {
func queryTrainSizeList(c *gin.Context) {
req := dto.TrainManageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
sizeList, err := service.ListTrainSizeQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, sizeList)
c.JSON(http.StatusOK, service.ListTrainSizeQuery(&req))
}
// 创建列车尺寸
@ -278,13 +255,9 @@ func queryTrainSizeList(c *gin.Context) {
func createTrainSize(c *gin.Context) {
req := dto.TrainSizeDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("创建失败,参数格式错误", err))
}
data, err := service.CreateTrainSize(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, data)
c.JSON(http.StatusOK, service.CreateTrainSize(&req))
}
// 查询列车尺寸详情
@ -306,7 +279,7 @@ func createTrainSize(c *gin.Context) {
func queryTrainSize(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少查询主键"))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryTrainSize(int32(int64Id)))
@ -332,18 +305,14 @@ func queryTrainSize(c *gin.Context) {
func updateTrainSize(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少查询主键"))
}
req := dto.TrainSizeDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("更新失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
result := service.UpdateTrainSize(int32(int64Id), &req)
if !result {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存出错"})
}
c.JSON(http.StatusOK, result)
c.JSON(http.StatusOK, service.UpdateTrainSize(int32(int64Id), &req))
}
// 删除列车尺寸数据
@ -366,7 +335,7 @@ func deleteTrainSize(c *gin.Context) {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("删除失败,主键格式错误", err))
}
service.DeleteTrainSizeById(id)
c.JSON(http.StatusOK, true)
@ -391,13 +360,9 @@ func deleteTrainSize(c *gin.Context) {
func pageQueryTrainWheelDiameter(c *gin.Context) {
req := dto.PageTrainManageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
page, err := service.PageTrainWheelDiameterQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, page)
c.JSON(http.StatusOK, service.PageTrainWheelDiameterQuery(&req))
}
// 查询列车轮径列表
@ -419,13 +384,9 @@ func pageQueryTrainWheelDiameter(c *gin.Context) {
func queryTrainWheelDiameterList(c *gin.Context) {
req := dto.TrainManageReqDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
wheels, err := service.ListTrainWheelDiameterQuery(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, wheels)
c.JSON(http.StatusOK, service.ListTrainWheelDiameterQuery(&req))
}
// 创建列车轮径
@ -447,13 +408,9 @@ func queryTrainWheelDiameterList(c *gin.Context) {
func createTrainWheelDiameter(c *gin.Context) {
req := dto.TrainWheelDiameterDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("创建失败,参数格式错误", err))
}
data, err := service.CreateTrainWheelDiameter(&req)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
c.JSON(http.StatusOK, data)
c.JSON(http.StatusOK, service.CreateTrainWheelDiameter(&req))
}
// 查询列车轮径详情
@ -475,7 +432,7 @@ func createTrainWheelDiameter(c *gin.Context) {
func queryTrainWheelDiameter(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("查询失败,缺少查询主键"))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryTrainWheelDiameter(int32(int64Id)))
@ -501,18 +458,14 @@ func queryTrainWheelDiameter(c *gin.Context) {
func updateTrainWheelDiameter(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("更新失败,缺少查询主键"))
}
req := dto.TrainWheelDiameterDto{}
if err := c.ShouldBind(&req); err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
panic(sys_error.New("查询失败,参数格式错误", err))
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
result := service.UpdateTrainWheelDiameter(int32(int64Id), &req)
if !result {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "保存出错"})
}
c.JSON(http.StatusOK, result)
c.JSON(http.StatusOK, service.UpdateTrainWheelDiameter(int32(int64Id), &req))
}
// 删除列车轮径数据
@ -535,7 +488,7 @@ func deleteTrainWheelDiameter(c *gin.Context) {
idStr := c.Param("id")
id, err := strconv.Atoi(idStr)
if err != nil {
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: "必要参数id不存在"})
panic(sys_error.New("删除失败,缺少主键"))
}
service.DeleteTrainWheelDiameterById(id)
c.JSON(http.StatusOK, true)

13
init.go
View File

@ -60,19 +60,6 @@ func InitServer() *gin.Engine {
Tip: be.UserMsg,
Message: be.Error(),
})
// switch e := e.(type) {
// case error:
// c.JSON(http.StatusInternalServerError, &dto.ErrorDto{
// Code: dto.LogicError,
// Tip: dto.ErrorTipMap[dto.LogicError],
// Message: e.Error(),
// })
// case dto.ErrorDto:
// e.Tip = dto.ErrorTipMap[e.Code]
// c.JSON(http.StatusInternalServerError, e)
// default:
// c.JSON(http.StatusInternalServerError, e)
// }
c.Writer.WriteHeaderNow()
c.Abort()
}))

View File

@ -10,13 +10,13 @@ import (
)
// 查询权限角色信息列表
func PageAuthRoleQuery(query *dto.PageQueryDto) (*dto.PageDto, error) {
func PageAuthRoleQuery(query *dto.PageQueryDto) *dto.PageDto {
d := dbquery.AuthRole
records, total, err := d.Debug().Select(d.ID, d.Name).Order(d.CreateTime).FindByPage(query.Offset(), query.Size)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: *query, Records: dto.ConvertFromAuthRole(records)}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: *query, Records: dto.ConvertFromAuthRole(records)}
}
// 获取角色列表
@ -142,7 +142,7 @@ func DeleteAuthRole(rid int32) bool {
}
// 查询接口路径信息列表
func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) (*dto.PageDto, error) {
func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) *dto.PageDto {
d := dbquery.AuthAPIPath
dq := d.Where()
if query.Name != "" {
@ -152,7 +152,7 @@ func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) (*dto.PageDto, error
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询接口路径信息列表

View File

@ -10,7 +10,7 @@ import (
)
// 查询草稿列表
func PageCategoryQuery(query *dto.PageCategoryReqDto) (*dto.PageDto, error) {
func PageCategoryQuery(query *dto.PageCategoryReqDto) *dto.PageDto {
d := dbquery.Category
dq := d.Where()
if query.Name != "" {
@ -20,11 +20,11 @@ func PageCategoryQuery(query *dto.PageCategoryReqDto) (*dto.PageDto, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询草稿列表
func ListCategoryQuery(query *dto.CategoryReqDto) ([]*model.Category, error) {
func ListCategoryQuery(query *dto.CategoryReqDto) []*model.Category {
d := dbquery.Category
dq := d.Where()
if query.Name != "" {
@ -34,11 +34,11 @@ func ListCategoryQuery(query *dto.CategoryReqDto) ([]*model.Category, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return records, nil
return records
}
// 创建草稿
func CreateCategory(cd *dto.CategoryDto) (*model.Category, error) {
func CreateCategory(cd *dto.CategoryDto) *model.Category {
if err := checkCategoryInfo(cd.Name, cd.Code, 0); err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
@ -53,7 +53,11 @@ func CreateCategory(cd *dto.CategoryDto) (*model.Category, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dbquery.Category.Where(dbquery.Category.Name.Eq(cd.Name)).Order(dbquery.Category.CreatedAt).Debug().First()
data, err := dbquery.Category.Where(dbquery.Category.Name.Eq(cd.Name)).Order(dbquery.Category.CreatedAt).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return data
}
func QueryCategory(id int32) *model.Category {

View File

@ -10,7 +10,7 @@ import (
)
// 查询草稿列表
func PageDraftingQuery(query *dto.PageDraftingReqDto) (*dto.PageDto, error) {
func PageDraftingQuery(query *dto.PageDraftingReqDto) *dto.PageDto {
d := dbquery.Drafting
dq := d.Where()
if query.Name != "" {
@ -20,10 +20,10 @@ func PageDraftingQuery(query *dto.PageDraftingReqDto) (*dto.PageDto, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
func ListDraftingQuery(query *dto.ListDraftingReqDto) ([]*model.Drafting, error) {
func ListDraftingQuery(query *dto.ListDraftingReqDto) []*model.Drafting {
d := dbquery.Drafting
dq := d.Where()
if query.Type != 0 {
@ -33,11 +33,11 @@ func ListDraftingQuery(query *dto.ListDraftingReqDto) ([]*model.Drafting, error)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return records, nil
return records
}
// 创建草稿
func CreateDrafting(createId int32, dd *dto.DraftingDto) (*model.Drafting, error) {
func CreateDrafting(createId int32, dd *dto.DraftingDto) *model.Drafting {
if err := checkDraftingInfo(dd.Name); err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
@ -54,16 +54,20 @@ func CreateDrafting(createId int32, dd *dto.DraftingDto) (*model.Drafting, error
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dbquery.Drafting.Where(
data, err := dbquery.Drafting.Where(
dbquery.Drafting.Name.Eq(dd.Name),
dbquery.Drafting.CreatorID.Eq(createId),
).Order(dbquery.Drafting.CreatedAt).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return data
}
// 另存为
func SaveAsDrafting(createId int32, oldId int32, dd *dto.DraftingDto) (*model.Drafting, error) {
func SaveAsDrafting(createId int32, oldId int32, dd *dto.DraftingDto) *model.Drafting {
if err := checkDraftingInfo(dd.Name); err != nil {
return nil, err
return nil
}
oldD, err := dbquery.Drafting.Where(dbquery.Drafting.ID.Eq(oldId)).Debug().First()
if oldD == nil || err != nil {
@ -81,10 +85,14 @@ func SaveAsDrafting(createId int32, oldId int32, dd *dto.DraftingDto) (*model.Dr
if err = dbquery.Drafting.Save(&newD); err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dbquery.Drafting.Where(
data, err := dbquery.Drafting.Where(
dbquery.Drafting.Name.Eq(dd.Name),
dbquery.Drafting.CreatorID.Eq(createId),
).Order(dbquery.Drafting.CreatedAt).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return data
}
func QueryDrafting(id int32) *model.Drafting {

View File

@ -10,7 +10,7 @@ import (
)
// 查询项目列表
func PageProjectQuery(query *dto.PageProjectReqDto) (*dto.PageDto, error) {
func PageProjectQuery(query *dto.PageProjectReqDto) *dto.PageDto {
d := dbquery.Project
dq := d.Where()
if query.Name != "" {
@ -23,11 +23,11 @@ func PageProjectQuery(query *dto.PageProjectReqDto) (*dto.PageDto, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询项目列表
func ListProjectQuery(query *dto.ProjectReqDto) ([]*model.Project, error) {
func ListProjectQuery(query *dto.ProjectReqDto) []*model.Project {
d := dbquery.Project
dq := d.Where()
if query.Name != "" {
@ -40,11 +40,11 @@ func ListProjectQuery(query *dto.ProjectReqDto) ([]*model.Project, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return records, nil
return records
}
// 创建草稿
func CreateProject(pd *dto.ProjectDto) (*model.Project, error) {
func CreateProject(pd *dto.ProjectDto) *model.Project {
if err := checkProjectInfo(pd.Code, 0); err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
@ -59,7 +59,11 @@ func CreateProject(pd *dto.ProjectDto) (*model.Project, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return p.Where(p.Name.Eq(pd.Name)).Order(p.CreatedAt).Debug().First()
data, err := p.Where(p.Name.Eq(pd.Name)).Order(p.CreatedAt).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return data
}
func QueryProject(id int32) *model.Project {

View File

@ -10,7 +10,7 @@ import (
)
// 查询列车型号信息列表
func PageTrainModelQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error) {
func PageTrainModelQuery(query *dto.PageTrainManageReqDto) *dto.PageDto {
d := dbquery.TrainModel
dq := d.Where()
if query.Name != "" {
@ -20,11 +20,11 @@ func PageTrainModelQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询列车型号信息列表
func ListTrainModelQuery(query *dto.TrainManageReqDto) ([]*model.TrainModel, error) {
func ListTrainModelQuery(query *dto.TrainManageReqDto) []*model.TrainModel {
d := dbquery.TrainModel
dq := d.Where()
if query.Name != "" {
@ -34,11 +34,11 @@ func ListTrainModelQuery(query *dto.TrainManageReqDto) ([]*model.TrainModel, err
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return records, nil
return records
}
// 创建列车型号信息
func CreateTrainModel(td *dto.TrainModelDto) (*model.TrainModel, error) {
func CreateTrainModel(td *dto.TrainModelDto) *model.TrainModel {
if err := checkTrainModel(td.Name, 0); err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
@ -52,7 +52,11 @@ func CreateTrainModel(td *dto.TrainModelDto) (*model.TrainModel, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dt.Where(dt.Name.Eq(td.Name)).Order(dt.CreatedAt).Debug().First()
data, err2 := dt.Where(dt.Name.Eq(td.Name)).Order(dt.CreatedAt).Debug().First()
if err2 != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err2.Error()})
}
return data
}
// 查询列车型号信息
@ -90,7 +94,7 @@ func DeleteTrainModelById(id int) {
}
// 查询列车尺寸信息列表
func PageTrainSizeQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error) {
func PageTrainSizeQuery(query *dto.PageTrainManageReqDto) *dto.PageDto {
d := dbquery.TrainSize
dq := d.Where()
if query.Name != "" {
@ -100,11 +104,11 @@ func PageTrainSizeQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error)
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询列车尺寸信息列表
func ListTrainSizeQuery(query *dto.TrainManageReqDto) ([]*model.TrainSize, error) {
func ListTrainSizeQuery(query *dto.TrainManageReqDto) []*model.TrainSize {
d := dbquery.TrainSize
dq := d.Where()
if query.Name != "" {
@ -114,11 +118,11 @@ func ListTrainSizeQuery(query *dto.TrainManageReqDto) ([]*model.TrainSize, error
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return records, nil
return records
}
// 创建列车尺寸信息
func CreateTrainSize(td *dto.TrainSizeDto) (*model.TrainSize, error) {
func CreateTrainSize(td *dto.TrainSizeDto) *model.TrainSize {
d := model.TrainSize{
Name: td.Name,
CarriageLength: td.CarriageLength,
@ -130,7 +134,11 @@ func CreateTrainSize(td *dto.TrainSizeDto) (*model.TrainSize, error) {
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dt.Where(dt.Name.Eq(td.Name)).Order(dt.Name).Debug().First()
data, err := dt.Where(dt.Name.Eq(td.Name)).Order(dt.Name).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return data
}
// 查询列车尺寸信息
@ -185,7 +193,7 @@ func QueryProjectTrainSize(id int32) []*model.TrainSize {
}
// 查询列车轮径信息列表
func PageTrainWheelDiameterQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto, error) {
func PageTrainWheelDiameterQuery(query *dto.PageTrainManageReqDto) *dto.PageDto {
d := dbquery.TrainWheelDiameter
dq := d.Where()
if query.Name != "" {
@ -195,11 +203,11 @@ func PageTrainWheelDiameterQuery(query *dto.PageTrainManageReqDto) (*dto.PageDto
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}
}
// 查询列车轮径信息列表
func ListTrainWheelDiameterQuery(query *dto.TrainManageReqDto) ([]*model.TrainWheelDiameter, error) {
func ListTrainWheelDiameterQuery(query *dto.TrainManageReqDto) []*model.TrainWheelDiameter {
d := dbquery.TrainWheelDiameter
dq := d.Where()
if query.Name != "" {
@ -209,11 +217,11 @@ func ListTrainWheelDiameterQuery(query *dto.TrainManageReqDto) ([]*model.TrainWh
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return records, nil
return records
}
// 创建列车轮径信息
func CreateTrainWheelDiameter(twd *dto.TrainWheelDiameterDto) (*model.TrainWheelDiameter, error) {
func CreateTrainWheelDiameter(twd *dto.TrainWheelDiameterDto) *model.TrainWheelDiameter {
d := model.TrainWheelDiameter{
Name: twd.Name,
Diameter: twd.Diameter,
@ -227,7 +235,11 @@ func CreateTrainWheelDiameter(twd *dto.TrainWheelDiameterDto) (*model.TrainWheel
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return dt.Where(dt.Name.Eq(twd.Name)).Order(dt.Name).Debug().First()
data, err := dt.Where(dt.Name.Eq(twd.Name)).Order(dt.Name).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()})
}
return data
}
// 查询列车轮径信息