83 lines
1.7 KiB
Go
83 lines
1.7 KiB
Go
package dto
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type TokenRespDto struct {
|
|
Code int `json:"code"`
|
|
Token string `json:"token"`
|
|
Expire string `json:"expire"`
|
|
}
|
|
|
|
type ErrorDto struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type OrderItem struct {
|
|
Column string `form:"column" json:"column"`
|
|
Asc bool `form:"asc" json:"asc"`
|
|
}
|
|
|
|
type PageQueryDto struct {
|
|
// 页码
|
|
Page int `form:"current" json:"page" binding:"required" example:"1"`
|
|
// 页面行数
|
|
Size int `form:"size" json:"size" binding:"required" example:"10"`
|
|
// 排序项
|
|
Orders []OrderItem `form:"orders" json:"orders"`
|
|
}
|
|
|
|
type PageDto struct {
|
|
Total int `form:"total" json:"total"`
|
|
PageQueryDto
|
|
Records any `form:"records" json:"records"`
|
|
}
|
|
|
|
type JsonTime time.Time
|
|
|
|
func (jt *JsonTime) MarshalJSON() ([]byte, error) {
|
|
format := time.Time(*jt).Format(time.DateTime)
|
|
return json.Marshal(format)
|
|
}
|
|
|
|
func (jt *JsonTime) UnmarshalJSON(data []byte) error {
|
|
if data[0] == '"' {
|
|
data = data[1 : len(data)-1]
|
|
}
|
|
str := string(data)
|
|
parse, err := time.Parse(time.DateTime, str)
|
|
if err != nil {
|
|
panic(ErrorDto{ArgumentParseError, fmt.Sprintf("时间参数格式化出错:\n%s", err.Error())})
|
|
}
|
|
*jt = JsonTime(parse)
|
|
return nil
|
|
}
|
|
|
|
func (jt *JsonTime) String() string {
|
|
return time.Time(*jt).Format(time.DateTime)
|
|
}
|
|
|
|
// 数据库分页偏移
|
|
func (p *PageQueryDto) Offset() int {
|
|
if p.Page > 0 {
|
|
return (p.Page - 1) * p.Size
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (p *PageQueryDto) Default() {
|
|
p.Page = 1
|
|
p.Size = 10
|
|
}
|
|
|
|
type LoginDto struct {
|
|
// 账号
|
|
Account string `form:"account" json:"account" binding:"required" example:"17791995809"`
|
|
// 加密密码
|
|
Password string `form:"password" json:"password" binding:"required" example:"95129dbaace576e46f41a629e6f35d5c"`
|
|
}
|