2023-07-14 10:16:58 +08:00
|
|
|
package dto
|
|
|
|
|
2023-07-31 10:15:02 +08:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-07-14 16:28:47 +08:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2023-07-14 10:16:58 +08:00
|
|
|
type OrderItem struct {
|
|
|
|
Column string `form:"column" json:"column"`
|
|
|
|
Asc bool `form:"asc" json:"asc"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PageQueryDto struct {
|
2023-07-14 16:28:47 +08:00
|
|
|
// 页码
|
|
|
|
Page int `form:"page" json:"page" binding:"required" example:"1"`
|
|
|
|
// 页面行数
|
|
|
|
Size int `form:"size" json:"size" binding:"required" example:"10"`
|
|
|
|
// 排序项
|
2023-07-14 10:16:58 +08:00
|
|
|
Orders []OrderItem `form:"orders" json:"orders"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PageDto struct {
|
|
|
|
Total int `form:"total" json:"total"`
|
|
|
|
PageQueryDto
|
|
|
|
Records any `form:"records" json:"records"`
|
|
|
|
}
|
|
|
|
|
2023-07-31 10:15:02 +08:00
|
|
|
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 {
|
|
|
|
var str string
|
|
|
|
err := json.Unmarshal(data, &str)
|
|
|
|
if err != nil {
|
|
|
|
panic(ErrorDto{ArgumentParseError, fmt.Sprintf("时间参数解析出错:\n%s", err.Error())})
|
|
|
|
}
|
|
|
|
parse, err := time.Parse(time.DateTime, str)
|
|
|
|
if err != nil {
|
|
|
|
panic(ErrorDto{ArgumentParseError, fmt.Sprintf("时间参数格式化出错:\n%s", err.Error())})
|
|
|
|
}
|
|
|
|
*jt = JsonTime(parse)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-14 10:16:58 +08:00
|
|
|
// 数据库分页偏移
|
|
|
|
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 {
|
2023-07-14 16:28:47 +08:00
|
|
|
// 账号
|
|
|
|
Account string `form:"account" json:"account" binding:"required" example:"17791995809"`
|
|
|
|
// 加密密码
|
|
|
|
Password string `form:"password" json:"password" binding:"required" example:"95129dbaace576e46f41a629e6f35d5c"`
|
2023-07-14 10:16:58 +08:00
|
|
|
}
|