✨ Init
This commit is contained in:
18
model/app/favorite.go
Normal file
18
model/app/favorite.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package app
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type Favorite struct {
|
||||
global.GVA_MODEL
|
||||
UserId int `json:"userId" gorm:"not null;column:user_id;comment:'用户id'"` // 用户id
|
||||
FavoriteId int `json:"favoriteId" gorm:"not null;comment:收藏id"` // 收藏id
|
||||
Cover string `json:"cover" gorm:"size:50;comment:封面"`
|
||||
Titte string `json:"title" comment:"收藏商品名称"` // 收藏商品名称
|
||||
Introduction string `json:"introduction" comment:"简介"` // 简介
|
||||
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (Favorite) TableName() string {
|
||||
return "sys_favorite"
|
||||
}
|
18
model/app/oauth2_client.go
Normal file
18
model/app/oauth2_client.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// OAuth2Client OAuth2客户端信息
|
||||
type OAuth2Client struct {
|
||||
global.GVA_MODEL
|
||||
ClientId string `gorm:"type:varchar(255) not null"`
|
||||
ClientSecret string `gorm:"type:varchar(255) not null"`
|
||||
Grant string `gorm:"type:varchar(255) not null"` // 允许的授权范围,支持类型: oauth2.GrantType
|
||||
Domain string `gorm:"type:varchar(255)"`
|
||||
}
|
||||
|
||||
func (OAuth2Client) TableName() string {
|
||||
return "t_oauth2_client"
|
||||
}
|
8
model/app/request/favorite.go
Normal file
8
model/app/request/favorite.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package request
|
||||
|
||||
import "miniapp/model/common/request"
|
||||
|
||||
type GetFavoriteList struct {
|
||||
request.PageInfo
|
||||
UserId int `json:"userId" form:"userId" binding:"required"`
|
||||
}
|
25
model/app/request/login.go
Normal file
25
model/app/request/login.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package request
|
||||
|
||||
import "miniapp/model/common/constant"
|
||||
|
||||
type Login struct {
|
||||
Username string `json:"username" form:"username" binding:"required"` // 邮箱或手机号
|
||||
Password string `json:"password" form:"password"` // 密码
|
||||
TypeCode constant.LoginType `json:"type" form:"type" binding:"required"` // 登录方式,默认为空,可选值参见自定义类型
|
||||
UserIdentity constant.UserIdentity `json:"identity" form:"identity" binding:"required"` // 用户身份,默认为空,可选值参见自定义类型
|
||||
NickName string `json:"nickName" form:"nickName"` // 微信昵称
|
||||
AvatarUrl string `json:"avatarUrl" form:"avatarUrl"` // 微信头像
|
||||
}
|
||||
|
||||
// RefreshToken 刷新Token入参
|
||||
type RefreshToken struct {
|
||||
RefreshToken string `json:"refresh_token" form:"refresh_token" binding:"required"` // 刷新Token
|
||||
GrantType string `json:"grant_type" form:"grant_type" binding:"required"` // 授权类型,写refresh_token
|
||||
}
|
||||
|
||||
// DecryptMobile 解密用户手机号入参
|
||||
type DecryptMobile struct {
|
||||
SessionKey string `json:"sessionKey" form:"sessionKey"` // sessionKey
|
||||
EncryptedData string `json:"encryptedData" form:"encryptedData" binding:"required"` // 加密数据
|
||||
Iv string `json:"iv" form:"iv" binding:"required"` // 加密算法的初始向量
|
||||
}
|
54
model/app/request/user.go
Normal file
54
model/app/request/user.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/common/constant"
|
||||
"miniapp/model/common/request"
|
||||
"miniapp/model/types"
|
||||
)
|
||||
|
||||
type BindingWeChat struct {
|
||||
Code string `json:"code" form:"code" binding:"required"` // 微信code
|
||||
}
|
||||
|
||||
// GetUserList 获取普通用户
|
||||
type GetUserList struct {
|
||||
request.PageInfo
|
||||
Phone string `json:"phone" form:"phone"` // 手机号
|
||||
Status string `json:"status" form:"status" binding:"oneof='' NORMAL DISABLE"` // 用户状态
|
||||
StartAt string `json:"startAt" form:"startAt"` // 开始时间
|
||||
EndAt string `json:"endAt" form:"endAt"` // 结束时间
|
||||
Name string `json:"name" form:"name"` //用户名
|
||||
}
|
||||
|
||||
// ChangeUserInfo 修改普通用户信息
|
||||
type ChangeUserInfo struct {
|
||||
Nickname string `json:"nickname" form:"nickname"` // 昵称
|
||||
Avatar string `json:"avatar" form:"avatar"` // 头像
|
||||
Phone string `json:"phone" form:"phone"` // 手机号
|
||||
}
|
||||
|
||||
// ChangePassword 修改密码
|
||||
type ChangePassword struct {
|
||||
OldPassword string `json:"oldPassword" form:"oldPassword" binding:"required"` // 旧密码
|
||||
NewPassword string `json:"newPassword" form:"oldPassword" binding:"required"` // 新密码
|
||||
ConfirmPassword string `json:"confirmPassword" form:"oldPassword" binding:"required,eqcsfield=NewPassword"` // 确认新密码
|
||||
}
|
||||
|
||||
// SaveUser 保存用户信息
|
||||
type SaveUser struct {
|
||||
Id int `json:"id" form:"id"` // 用户ID
|
||||
Username string `json:"username" form:"username"` // 用户名
|
||||
Nickname string `json:"nickname" form:"nickname"` // 昵称
|
||||
Password string `json:"password" form:"password"` // 密码
|
||||
Email string `json:"email" form:"email"` // 邮箱
|
||||
Phone string `json:"phone" form:"phone"`
|
||||
Status constant.UserStatus `json:"status" form:"status" binding:"oneof=NORMAL DISABLE"` // 用户状态
|
||||
RoleId string `json:"role_id" form:"role_id"` //角色id
|
||||
}
|
||||
|
||||
type ChangeUserHospital struct {
|
||||
UserId int `json:"userId" form:"userId" binding:"required"` // 用户ID
|
||||
HospitalId int `json:"hospitalId" form:"hospitalId" binding:"required"` // 医院ID
|
||||
IsSurgery int `json:"isSurgery" form:"isSurgery"` // 是否已经手术 0未手术 1已手术
|
||||
SurgeryTime *types.DateTime `json:"surgeryTime" form:"surgeryTime"` // 手术时间
|
||||
}
|
8
model/app/request/vision.go
Normal file
8
model/app/request/vision.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package request
|
||||
|
||||
import "miniapp/model/common/request"
|
||||
|
||||
type VisionListRequest struct {
|
||||
request.PageInfo
|
||||
UserId int `json:"userId" form:"userId"`
|
||||
}
|
50
model/app/response/user.go
Normal file
50
model/app/response/user.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"miniapp/model/app"
|
||||
"miniapp/model/common/constant"
|
||||
"miniapp/model/types"
|
||||
"miniapp/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type UserItem struct {
|
||||
Id string `json:"id"`
|
||||
Phone string `json:"phone"` // 手机号
|
||||
Nickname string `json:"nickname"` // 用户名
|
||||
CreateAt string `json:"createAt"` // 创建时间
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
LastLoginAt string `json:"lastLoginAt"` // 最后登录时间
|
||||
Status constant.UserStatus `json:"status"` // 状态:1-正常,2-禁用
|
||||
}
|
||||
|
||||
type UserVO struct {
|
||||
Id string `json:"id"`
|
||||
Nickname string `json:"nickname"`
|
||||
Email string `json:"email"`
|
||||
Username string `json:"username"`
|
||||
Phone string `json:"phone"`
|
||||
Status constant.UserStatus `json:"status"`
|
||||
Birthday string `json:"birthday"`
|
||||
Avatar string `json:"avatar"`
|
||||
LastLoginAt *types.DateTime `json:"lastLoginAt"`
|
||||
LastLoginIp *string `json:"lastLoginIp"`
|
||||
CreatedAt types.DateTime `json:"createdAt"`
|
||||
TimeNote string `json:"timeNote"`
|
||||
}
|
||||
|
||||
func (auv *UserVO) ParseOrdinary(u app.User) {
|
||||
auv.Id = strconv.Itoa(int(u.ID))
|
||||
auv.Phone = utils.Desensitization().Phone(u.Phone)
|
||||
auv.Nickname = u.Nickname
|
||||
auv.Status = u.Status
|
||||
auv.LastLoginAt = u.LastLoginAt
|
||||
auv.Avatar = u.Avatar
|
||||
auv.CreatedAt = types.DateTime(u.CreatedAt)
|
||||
|
||||
if u.IsSurgery == 1 {
|
||||
auv.TimeNote = "距离下次复查时间还剩:"
|
||||
} else {
|
||||
auv.TimeNote = "距离手术时间还剩:"
|
||||
}
|
||||
}
|
26
model/app/user.go
Normal file
26
model/app/user.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
"miniapp/model/common/constant"
|
||||
"miniapp/model/types"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
global.GVA_MODEL
|
||||
Phone string `json:"phone" gorm:"index:deleted;type:varchar(255) not null comment '手机号'"`
|
||||
WechatUnionId *string `json:"wechat_union_id" gorm:"type:varchar(255) comment '微信UnionId'"`
|
||||
WechatOpenId *string `json:"wechat_open_id" gorm:"type:varchar(255) comment '微信OpenId'"`
|
||||
Nickname string `json:"nickname" gorm:"type:varchar(255) comment '昵称'"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(255) comment '头像'"`
|
||||
Status constant.UserStatus `json:"status" gorm:"type:enum('NORMAL','DISABLE'); default:'NORMAL'; not null; comment:'状态 NORMAL-正常;DISABLE-禁用'"`
|
||||
IsSurgery int `json:"isSurgery" gorm:"default:0;comment:是否已经手术 0未手术 1已手术"`
|
||||
IsInfo int `json:"isInfo" gorm:"default:0;comment:是否已经填写信息 0未填写 1已填写"`
|
||||
HospitalId int `json:"hospital_id" gorm:"comment:手术医院"`
|
||||
SurgeryTime *types.DateTime `json:"surgery_time" gorm:"comment:手术时间"`
|
||||
LastLoginAt *types.DateTime `json:"last_login_at" gorm:"comment:'最后登录时间'"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "t_user"
|
||||
}
|
16
model/app/vision.go
Normal file
16
model/app/vision.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package app
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type Vision struct {
|
||||
global.GVA_MODEL
|
||||
UserId int `json:"userId" form:"userId" gorm:"not null;column:user_id;comment:'用户id'"` // 用户id
|
||||
//左眼视力
|
||||
LeftEyeVision string `json:"leftEyeVision" from:"leftEyeVision" gorm:"not null;comment:左眼视力"` // 左眼视力
|
||||
//右眼视力
|
||||
RightEyeVision string `json:"rightEyeVision" from:"rightEyeVision" gorm:"not null;comment:右眼视力"` // 右眼视力
|
||||
}
|
||||
|
||||
func (v Vision) TableName() string {
|
||||
return "t_vision"
|
||||
}
|
19
model/cache/user.go
vendored
Normal file
19
model/cache/user.go
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package cache
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// UserInfo 登录用的用户信息结构体
|
||||
type UserInfo struct {
|
||||
UserType string `json:"userType"` // 用户类型
|
||||
RoleCodes string `json:"roleCodes"` // 角色代码
|
||||
UserId string `json:"userId"` // 用户Id
|
||||
}
|
||||
|
||||
// String 实现Stringer接口
|
||||
func (i UserInfo) String() (string, error) {
|
||||
b, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
15
model/common/article.go
Normal file
15
model/common/article.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package common
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type Article struct {
|
||||
global.GVA_MODEL
|
||||
Title string `json:"title" form:"title" gorm:"column:title;comment:标题;type:varchar(255);size:255;"`
|
||||
Content string `json:"content" form:"content" gorm:"column:content;comment:内容;type:longtext;"`
|
||||
CoverImg string `json:"cover_img" form:"coverImg" gorm:"column:cover_img;comment:封面图;type:varchar(255);size:255;"`
|
||||
ReadingNum int `json:"reading_num" form:"reading_num" gorm:"column:reading_num;comment:阅读量;type:int;size:10;"`
|
||||
}
|
||||
|
||||
func (Article) TableName() string {
|
||||
return "articles"
|
||||
}
|
12
model/common/banner.go
Normal file
12
model/common/banner.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type Banner struct {
|
||||
global.GVA_MODEL
|
||||
ImgUrl string `json:"imgUrl" gorm:"type:varchar(255) comment '图片地址'"`
|
||||
Link string `json:"link" gorm:"type:varchar(255) comment '跳转链接'"`
|
||||
Status int `json:"status" gorm:"type:tinyint(1) comment '是否显示 0-不显示 1-显示'"`
|
||||
}
|
16
model/common/constant/login.go
Normal file
16
model/common/constant/login.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package constant
|
||||
|
||||
// LoginType 自定义登录类型
|
||||
type LoginType string
|
||||
|
||||
// 登录类型
|
||||
const (
|
||||
LoginTypeWeChatMiniApp LoginType = "wechat_mini_app" // 微信小程序登录
|
||||
LoginTypeSms LoginType = "sms" // 短信验证码登录
|
||||
LoginTypePassword LoginType = "password" // 密码登录
|
||||
)
|
||||
|
||||
// String 转换为字符串
|
||||
func (t LoginType) String() string {
|
||||
return string(t)
|
||||
}
|
133
model/common/constant/order.go
Normal file
133
model/common/constant/order.go
Normal file
@@ -0,0 +1,133 @@
|
||||
package constant
|
||||
|
||||
import "fmt"
|
||||
|
||||
// PaymentType 支付方式
|
||||
type PaymentType int
|
||||
|
||||
const (
|
||||
PaymentTypeNone PaymentType = iota // 未知 0
|
||||
PaymentTypeWeChatMiniApp // 微信小程序 1
|
||||
PaymentTypeWeChatH5 // 微信H5 2
|
||||
PaymentTypeWeChatAPP // 微信APP 3
|
||||
PaymentTypeExchangeCode // 兑换码白嫖 4
|
||||
)
|
||||
|
||||
// 支付渠道描述
|
||||
var paymentTypeMap = map[PaymentType]string{
|
||||
PaymentTypeNone: "未知",
|
||||
PaymentTypeWeChatMiniApp: "微信小程序",
|
||||
PaymentTypeWeChatH5: "微信H5",
|
||||
PaymentTypeWeChatAPP: "微信APP",
|
||||
PaymentTypeExchangeCode: "兑换码",
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (pt PaymentType) String() string {
|
||||
if str, ok := paymentTypeMap[pt]; ok {
|
||||
return str
|
||||
}
|
||||
return fmt.Sprintf("未知状态(%d)", pt)
|
||||
}
|
||||
|
||||
// MarshalJSON JSON序列化的时候转换为中文
|
||||
func (pt PaymentType) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + pt.String() + `"`), nil
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
type PayStatus int
|
||||
|
||||
const (
|
||||
PayStatusNot PayStatus = iota // 未支付
|
||||
PayStatusSuccess // 支付成功
|
||||
PayStatusFail // 支付失败
|
||||
PayStatusRefunded // 已退款
|
||||
)
|
||||
|
||||
var payStatusMap = map[PayStatus]string{
|
||||
PayStatusNot: "未支付",
|
||||
PayStatusSuccess: "支付成功",
|
||||
PayStatusFail: "支付失败",
|
||||
PayStatusRefunded: "已退款",
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (ps PayStatus) String() string {
|
||||
if str, ok := payStatusMap[ps]; ok {
|
||||
return str
|
||||
}
|
||||
return fmt.Sprintf("未知状态(%d)", ps)
|
||||
}
|
||||
|
||||
// MarshalJSON JSON序列化的时候转换为中文
|
||||
func (ps PayStatus) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, ps.String())), nil
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
type OrderStatus int
|
||||
|
||||
const (
|
||||
OrderStatusWait OrderStatus = iota // 待支付 0
|
||||
OrderStatusUsing // 生效中 1
|
||||
OrderStatusFailure // 已失效 2
|
||||
OrderStatusApplicationRefund // 已申请退款 3
|
||||
OrderStatusRefunding // 退款中 4
|
||||
OrderStatusRefunded // 已退款 5
|
||||
OrderStatusCanceled // 已取消 6
|
||||
OrderStatusEnd // 已完成 7
|
||||
)
|
||||
|
||||
var orderStatusMap = map[OrderStatus]string{
|
||||
OrderStatusWait: "待支付",
|
||||
OrderStatusUsing: "生效中",
|
||||
OrderStatusFailure: "已失效",
|
||||
OrderStatusApplicationRefund: "已申请退款",
|
||||
OrderStatusRefunding: "退款中",
|
||||
OrderStatusRefunded: "已退款",
|
||||
OrderStatusCanceled: "已取消",
|
||||
OrderStatusEnd: "已完成",
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (os OrderStatus) String() string {
|
||||
if str, ok := orderStatusMap[os]; ok {
|
||||
return str
|
||||
}
|
||||
return fmt.Sprintf("未知状态(%d)", os)
|
||||
}
|
||||
|
||||
// MarshalJSON JSON序列化的时候转换为中文
|
||||
func (os OrderStatus) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, os.String())), nil
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
type OrderServiceType int
|
||||
|
||||
const (
|
||||
OrderServiceTypeProduct OrderServiceType = iota + 1 // 普通商品
|
||||
OrderServiceTypeActivity // 活动
|
||||
)
|
||||
|
||||
var orderServiceTypeMap = map[OrderServiceType]string{
|
||||
OrderServiceTypeProduct: "服务",
|
||||
OrderServiceTypeActivity: "活动",
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (os OrderServiceType) String() string {
|
||||
if str, ok := orderServiceTypeMap[os]; ok {
|
||||
return str
|
||||
}
|
||||
return fmt.Sprintf("未知状态(%d)", os)
|
||||
}
|
||||
|
||||
// MarshalJSON JSON序列化的时候转换为中文
|
||||
func (os OrderServiceType) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"%s"`, os.String())), nil
|
||||
}
|
8
model/common/constant/rds_key.go
Normal file
8
model/common/constant/rds_key.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
OAuth2RedisKey = "oauth:token:" // Token缓存前缀
|
||||
OAuth2UserCacheKey = "oauth:user:" // 用户缓存前缀
|
||||
ApiAntiShakeKey = "api:antishake:" // 防抖锁
|
||||
WeChatSessionKey = "wechat:session:" // 小程序用户SessionKey前缀
|
||||
)
|
88
model/common/constant/user.go
Normal file
88
model/common/constant/user.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// UserStatus 用户状态
|
||||
type UserStatus string
|
||||
|
||||
const (
|
||||
UserStatusActive UserStatus = "NORMAL" // 用户状态正常
|
||||
UserStatusDisabled UserStatus = "DISABLE" // 已禁用用户
|
||||
)
|
||||
|
||||
// 状态对应的描述
|
||||
var userStatusMap = map[UserStatus]string{
|
||||
UserStatusActive: "正常",
|
||||
UserStatusDisabled: "已禁用",
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (s UserStatus) String() string {
|
||||
if str, ok := userStatusMap[s]; ok {
|
||||
return str
|
||||
}
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
// UserSex 性别
|
||||
type UserSex int
|
||||
|
||||
const (
|
||||
UserSexNone UserSex = iota // 不知道是啥
|
||||
UserSexMale // 男
|
||||
UserSexFemale // 女
|
||||
UserSexOther // 其他性别
|
||||
)
|
||||
|
||||
// 状态对应的描述
|
||||
var userSexMap = map[UserSex]string{
|
||||
UserSexNone: "无性别",
|
||||
UserSexMale: "男",
|
||||
UserSexFemale: "女",
|
||||
UserSexOther: "其他",
|
||||
}
|
||||
|
||||
// FromString 中文取性别
|
||||
func (s UserSex) FromString(sex string) UserSex {
|
||||
result := UserSexNone
|
||||
for key, value := range userSexMap {
|
||||
if sex == value {
|
||||
result = key
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (s UserSex) String() string {
|
||||
if str, ok := userSexMap[s]; ok {
|
||||
return str
|
||||
}
|
||||
//return strconv.Itoa(int(s))
|
||||
return fmt.Sprintf("UserSex(%d)", int(s))
|
||||
}
|
||||
|
||||
// MarshalJSON JSON序列化的时候转换为中文
|
||||
func (s UserSex) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + s.String() + `"`), nil
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
// UserIdentity 用户身份
|
||||
type UserIdentity string
|
||||
|
||||
const (
|
||||
UserIdentityAdmin UserIdentity = "admin" // 管理员
|
||||
UserIdentityUser UserIdentity = "user" // 普通用户
|
||||
)
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (t UserIdentity) String() string {
|
||||
return string(t)
|
||||
}
|
16
model/common/hospital.go
Normal file
16
model/common/hospital.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package common
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type Hospital struct {
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" form:"name" gorm:"comment:医院名称;"`
|
||||
Addr string `json:"addr" form:"addr" gorm:"comment:医院地址;"`
|
||||
Phone string `json:"phone" form:"phone" gorm:"comment:医院电话;"`
|
||||
Notes []Notes `json:"notes" form:"notes" gorm:"many2many:hospital_notes;comment:注意事项;"`
|
||||
Todos []Todos `json:"todos" form:"todos" gorm:"many2many:hospital_todos;comment:任务列表;"`
|
||||
}
|
||||
|
||||
func (h Hospital) TableName() string {
|
||||
return "sys_hospital"
|
||||
}
|
13
model/common/notes.go
Normal file
13
model/common/notes.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package common
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type Notes struct {
|
||||
global.GVA_MODEL
|
||||
Content string `json:"content" form:"content" gorm:"comment:注意事项内容;"`
|
||||
NotesTime string `json:"notes_time" form:"notes_time" gorm:"comment:注意事项时间;"` //手术前、手术后、术中
|
||||
}
|
||||
|
||||
func (n Notes) TableName() string {
|
||||
return "sys_notes"
|
||||
}
|
28
model/common/request/common.go
Normal file
28
model/common/request/common.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package request
|
||||
|
||||
// PageInfo Paging common input parameter structure
|
||||
type PageInfo struct {
|
||||
Page int `json:"page" form:"page"` // 页码
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
Keyword string `json:"keyword" form:"keyword"` //关键字
|
||||
}
|
||||
|
||||
// GetById Find by id structure
|
||||
type GetById struct {
|
||||
ID int `json:"id" form:"id"` // 主键ID
|
||||
}
|
||||
|
||||
func (r *GetById) Uint() uint {
|
||||
return uint(r.ID)
|
||||
}
|
||||
|
||||
type IdsReq struct {
|
||||
Ids []int `json:"ids" form:"ids"`
|
||||
}
|
||||
|
||||
// GetAuthorityId Get role by id structure
|
||||
type GetAuthorityId struct {
|
||||
AuthorityId int `json:"authorityId" form:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
type Empty struct{}
|
8
model/common/response/common.go
Normal file
8
model/common/response/common.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package response
|
||||
|
||||
type PageResult struct {
|
||||
List interface{} `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
55
model/common/response/response.go
Normal file
55
model/common/response/response.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
const (
|
||||
ERROR = 7
|
||||
SUCCESS = 0
|
||||
)
|
||||
|
||||
func Result(code int, data interface{}, msg string, c *gin.Context) {
|
||||
// 开始时间
|
||||
c.JSON(http.StatusOK, Response{
|
||||
code,
|
||||
data,
|
||||
msg,
|
||||
})
|
||||
}
|
||||
|
||||
func Ok(c *gin.Context) {
|
||||
Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
|
||||
}
|
||||
|
||||
func OkWithMessage(message string, c *gin.Context) {
|
||||
Result(SUCCESS, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func OkWithData(data interface{}, c *gin.Context) {
|
||||
Result(SUCCESS, data, "查询成功", c)
|
||||
}
|
||||
|
||||
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
Result(SUCCESS, data, message, c)
|
||||
}
|
||||
|
||||
func Fail(c *gin.Context) {
|
||||
Result(ERROR, map[string]interface{}{}, "操作失败", c)
|
||||
}
|
||||
|
||||
func FailWithMessage(message string, c *gin.Context) {
|
||||
Result(ERROR, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
Result(ERROR, data, message, c)
|
||||
}
|
13
model/common/todos.go
Normal file
13
model/common/todos.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package common
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type Todos struct {
|
||||
// 任务列表
|
||||
global.GVA_MODEL
|
||||
Content string `json:"content" form:"content" gorm:"comment:任务内容;"`
|
||||
}
|
||||
|
||||
func (t Todos) TableName() string {
|
||||
return "sys_todos"
|
||||
}
|
14
model/common/user_todo.go
Normal file
14
model/common/user_todo.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package common
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type UserTodo struct {
|
||||
global.GVA_MODEL
|
||||
UserId int `json:"userId" form:"userId" gorm:"comment:用户id;"`
|
||||
Content string `json:"content" form:"content" gorm:"comment:任务内容;"`
|
||||
IsFinish int `json:"isFinish" form:"isFinish" gorm:"comment:是否完成;"`
|
||||
}
|
||||
|
||||
func (u UserTodo) TableName() string {
|
||||
return "t_user_todo"
|
||||
}
|
24
model/example/exa_breakpoint_continue.go
Normal file
24
model/example/exa_breakpoint_continue.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// file struct, 文件结构体
|
||||
type ExaFile struct {
|
||||
global.GVA_MODEL
|
||||
FileName string
|
||||
FileMd5 string
|
||||
FilePath string
|
||||
ExaFileChunk []ExaFileChunk
|
||||
ChunkTotal int
|
||||
IsFinish bool
|
||||
}
|
||||
|
||||
// file chunk struct, 切片结构体
|
||||
type ExaFileChunk struct {
|
||||
global.GVA_MODEL
|
||||
ExaFileID uint
|
||||
FileChunkNumber int
|
||||
FileChunkPath string
|
||||
}
|
15
model/example/exa_customer.go
Normal file
15
model/example/exa_customer.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
type ExaCustomer struct {
|
||||
global.GVA_MODEL
|
||||
CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名
|
||||
CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号
|
||||
SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID
|
||||
SysUserAuthorityID uint `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID
|
||||
SysUser system.SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情
|
||||
}
|
17
model/example/exa_file_upload_download.go
Normal file
17
model/example/exa_file_upload_download.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type ExaFileUploadAndDownload struct {
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" gorm:"comment:文件名"` // 文件名
|
||||
Url string `json:"url" gorm:"comment:文件地址"` // 文件地址
|
||||
Tag string `json:"tag" gorm:"comment:文件标签"` // 文件标签
|
||||
Key string `json:"key" gorm:"comment:编号"` // 编号
|
||||
}
|
||||
|
||||
func (ExaFileUploadAndDownload) TableName() string {
|
||||
return "exa_file_upload_and_downloads"
|
||||
}
|
11
model/example/response/exa_breakpoint_continue.go
Normal file
11
model/example/response/exa_breakpoint_continue.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package response
|
||||
|
||||
import "miniapp/model/example"
|
||||
|
||||
type FilePathResponse struct {
|
||||
FilePath string `json:"filePath"`
|
||||
}
|
||||
|
||||
type FileResponse struct {
|
||||
File example.ExaFile `json:"file"`
|
||||
}
|
7
model/example/response/exa_customer.go
Normal file
7
model/example/response/exa_customer.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package response
|
||||
|
||||
import "miniapp/model/example"
|
||||
|
||||
type ExaCustomerResponse struct {
|
||||
Customer example.ExaCustomer `json:"customer"`
|
||||
}
|
7
model/example/response/exa_file_upload_download.go
Normal file
7
model/example/response/exa_file_upload_download.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package response
|
||||
|
||||
import "miniapp/model/example"
|
||||
|
||||
type ExaFileResponse struct {
|
||||
File example.ExaFileUploadAndDownload `json:"file"`
|
||||
}
|
21
model/system/request/jwt.go
Normal file
21
model/system/request/jwt.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"github.com/gofrs/uuid/v5"
|
||||
jwt "github.com/golang-jwt/jwt/v4"
|
||||
)
|
||||
|
||||
// Custom claims structure
|
||||
type CustomClaims struct {
|
||||
BaseClaims
|
||||
BufferTime int64
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
type BaseClaims struct {
|
||||
UUID uuid.UUID
|
||||
ID uint
|
||||
Username string
|
||||
NickName string
|
||||
AuthorityId uint
|
||||
}
|
14
model/system/request/sys_api.go
Normal file
14
model/system/request/sys_api.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/common/request"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
// api分页条件查询及排序结构体
|
||||
type SearchApiParams struct {
|
||||
system.SysApi
|
||||
request.PageInfo
|
||||
OrderKey string `json:"orderKey"` // 排序
|
||||
Desc bool `json:"desc"` // 排序方式:升序false(默认)|降序true
|
||||
}
|
7
model/system/request/sys_authority_btn.go
Normal file
7
model/system/request/sys_authority_btn.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package request
|
||||
|
||||
type SysAuthorityBtnReq struct {
|
||||
MenuID uint `json:"menuID"`
|
||||
AuthorityId uint `json:"authorityId"`
|
||||
Selected []uint `json:"selected"`
|
||||
}
|
13
model/system/request/sys_auto_history.go
Normal file
13
model/system/request/sys_auto_history.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package request
|
||||
|
||||
import "miniapp/model/common/request"
|
||||
|
||||
type SysAutoHistory struct {
|
||||
request.PageInfo
|
||||
}
|
||||
|
||||
// GetById Find by id structure
|
||||
type RollBack struct {
|
||||
ID int `json:"id" form:"id"` // 主键ID
|
||||
DeleteTable bool `json:"deleteTable" form:"deleteTable"` // 是否删除表
|
||||
}
|
26
model/system/request/sys_casbin.go
Normal file
26
model/system/request/sys_casbin.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package request
|
||||
|
||||
// Casbin info structure
|
||||
type CasbinInfo struct {
|
||||
Path string `json:"path"` // 路径
|
||||
Method string `json:"method"` // 方法
|
||||
}
|
||||
|
||||
// Casbin structure for input parameters
|
||||
type CasbinInReceive struct {
|
||||
AuthorityId uint `json:"authorityId"` // 权限id
|
||||
CasbinInfos []CasbinInfo `json:"casbinInfos"`
|
||||
}
|
||||
|
||||
func DefaultCasbin() []CasbinInfo {
|
||||
return []CasbinInfo{
|
||||
{Path: "/menu/getMenu", Method: "POST"},
|
||||
{Path: "/jwt/jsonInBlacklist", Method: "POST"},
|
||||
{Path: "/base/login", Method: "POST"},
|
||||
{Path: "/user/admin_register", Method: "POST"},
|
||||
{Path: "/user/changePassword", Method: "POST"},
|
||||
{Path: "/user/setUserAuthority", Method: "POST"},
|
||||
{Path: "/user/setUserInfo", Method: "PUT"},
|
||||
{Path: "/user/getUserInfo", Method: "GET"},
|
||||
}
|
||||
}
|
11
model/system/request/sys_chatgpt.go
Normal file
11
model/system/request/sys_chatgpt.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/common/request"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
type ChatGptRequest struct {
|
||||
system.ChatGpt
|
||||
request.PageInfo
|
||||
}
|
11
model/system/request/sys_dictionary.go
Normal file
11
model/system/request/sys_dictionary.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/common/request"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
type SysDictionarySearch struct {
|
||||
system.SysDictionary
|
||||
request.PageInfo
|
||||
}
|
11
model/system/request/sys_dictionary_detail.go
Normal file
11
model/system/request/sys_dictionary_detail.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/common/request"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
type SysDictionaryDetailSearch struct {
|
||||
system.SysDictionaryDetail
|
||||
request.PageInfo
|
||||
}
|
102
model/system/request/sys_init.go
Normal file
102
model/system/request/sys_init.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"miniapp/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
type InitDB struct {
|
||||
DBType string `json:"dbType"` // 数据库类型
|
||||
Host string `json:"host"` // 服务器地址
|
||||
Port string `json:"port"` // 数据库连接端口
|
||||
UserName string `json:"userName"` // 数据库用户名
|
||||
Password string `json:"password"` // 数据库密码
|
||||
DBName string `json:"dbName" binding:"required"` // 数据库名
|
||||
DBPath string `json:"dbPath"` // sqlite数据库文件路径
|
||||
}
|
||||
|
||||
// MysqlEmptyDsn msyql 空数据库 建库链接
|
||||
// Author SliverHorn
|
||||
func (i *InitDB) MysqlEmptyDsn() string {
|
||||
if i.Host == "" {
|
||||
i.Host = "127.0.0.1"
|
||||
}
|
||||
if i.Port == "" {
|
||||
i.Port = "3306"
|
||||
}
|
||||
return fmt.Sprintf("%s:%s@tcp(%s:%s)/", i.UserName, i.Password, i.Host, i.Port)
|
||||
}
|
||||
|
||||
// PgsqlEmptyDsn pgsql 空数据库 建库链接
|
||||
// Author SliverHorn
|
||||
func (i *InitDB) PgsqlEmptyDsn() string {
|
||||
if i.Host == "" {
|
||||
i.Host = "127.0.0.1"
|
||||
}
|
||||
if i.Port == "" {
|
||||
i.Port = "5432"
|
||||
}
|
||||
return "host=" + i.Host + " user=" + i.UserName + " password=" + i.Password + " port=" + i.Port + " dbname=" + "postgres" + " " + "sslmode=disable TimeZone=Asia/Shanghai"
|
||||
}
|
||||
|
||||
// SqliteEmptyDsn sqlite 空数据库 建库链接
|
||||
// Author Kafumio
|
||||
func (i *InitDB) SqliteEmptyDsn() string {
|
||||
separator := string(os.PathSeparator)
|
||||
return i.DBPath + separator + i.DBName + ".db"
|
||||
}
|
||||
|
||||
// ToMysqlConfig 转换 config.Mysql
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (i *InitDB) ToMysqlConfig() config.Mysql {
|
||||
return config.Mysql{
|
||||
GeneralDB: config.GeneralDB{
|
||||
Path: i.Host,
|
||||
Port: i.Port,
|
||||
Dbname: i.DBName,
|
||||
Username: i.UserName,
|
||||
Password: i.Password,
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
LogMode: "error",
|
||||
Config: "charset=utf8mb4&parseTime=True&loc=Local",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ToPgsqlConfig 转换 config.Pgsql
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (i *InitDB) ToPgsqlConfig() config.Pgsql {
|
||||
return config.Pgsql{
|
||||
GeneralDB: config.GeneralDB{
|
||||
Path: i.Host,
|
||||
Port: i.Port,
|
||||
Dbname: i.DBName,
|
||||
Username: i.UserName,
|
||||
Password: i.Password,
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
LogMode: "error",
|
||||
Config: "sslmode=disable TimeZone=Asia/Shanghai",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ToSqliteConfig 转换 config.Sqlite
|
||||
// Author [Kafumio](https://github.com/Kafumio)
|
||||
func (i *InitDB) ToSqliteConfig() config.Sqlite {
|
||||
return config.Sqlite{
|
||||
GeneralDB: config.GeneralDB{
|
||||
Path: i.DBPath,
|
||||
Port: i.Port,
|
||||
Dbname: i.DBName,
|
||||
Username: i.UserName,
|
||||
Password: i.Password,
|
||||
MaxIdleConns: 10,
|
||||
MaxOpenConns: 100,
|
||||
LogMode: "error",
|
||||
Config: "",
|
||||
},
|
||||
}
|
||||
}
|
27
model/system/request/sys_menu.go
Normal file
27
model/system/request/sys_menu.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
// Add menu authority info structure
|
||||
type AddMenuAuthorityInfo struct {
|
||||
Menus []system.SysBaseMenu `json:"menus"`
|
||||
AuthorityId uint `json:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
func DefaultMenu() []system.SysBaseMenu {
|
||||
return []system.SysBaseMenu{{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: 1},
|
||||
ParentId: "0",
|
||||
Path: "dashboard",
|
||||
Name: "dashboard",
|
||||
Component: "view/dashboard/index.vue",
|
||||
Sort: 1,
|
||||
Meta: system.Meta{
|
||||
Title: "仪表盘",
|
||||
Icon: "setting",
|
||||
},
|
||||
}}
|
||||
}
|
11
model/system/request/sys_operation_record.go
Normal file
11
model/system/request/sys_operation_record.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/common/request"
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
type SysOperationRecordSearch struct {
|
||||
system.SysOperationRecord
|
||||
request.PageInfo
|
||||
}
|
56
model/system/request/sys_user.go
Normal file
56
model/system/request/sys_user.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
// Register User register structure
|
||||
type Register struct {
|
||||
Username string `json:"userName" example:"用户名"`
|
||||
Password string `json:"passWord" example:"密码"`
|
||||
NickName string `json:"nickName" example:"昵称"`
|
||||
HeaderImg string `json:"headerImg" example:"头像链接"`
|
||||
AuthorityId uint `json:"authorityId" swaggertype:"string" example:"int 角色id"`
|
||||
Enable int `json:"enable" swaggertype:"string" example:"int 是否启用"`
|
||||
AuthorityIds []uint `json:"authorityIds" swaggertype:"string" example:"[]uint 角色id"`
|
||||
Phone string `json:"phone" example:"电话号码"`
|
||||
Email string `json:"email" example:"电子邮箱"`
|
||||
}
|
||||
|
||||
// User login structure
|
||||
type Login struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码
|
||||
Captcha string `json:"captcha"` // 验证码
|
||||
CaptchaId string `json:"captchaId"` // 验证码ID
|
||||
}
|
||||
|
||||
// Modify password structure
|
||||
type ChangePasswordReq struct {
|
||||
ID uint `json:"-"` // 从 JWT 中提取 user id,避免越权
|
||||
Password string `json:"password"` // 密码
|
||||
NewPassword string `json:"newPassword"` // 新密码
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
type SetUserAuth struct {
|
||||
AuthorityId uint `json:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
// Modify user's auth structure
|
||||
type SetUserAuthorities struct {
|
||||
ID uint
|
||||
AuthorityIds []uint `json:"authorityIds"` // 角色ID
|
||||
}
|
||||
|
||||
type ChangeUserInfo struct {
|
||||
ID uint `gorm:"primarykey"` // 主键ID
|
||||
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
|
||||
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
|
||||
AuthorityIds []uint `json:"authorityIds" gorm:"-"` // 角色ID
|
||||
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
|
||||
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
|
||||
SideMode string `json:"sideMode" gorm:"comment:用户侧边主题"` // 用户侧边主题
|
||||
Enable int `json:"enable" gorm:"comment:冻结用户"` //冻结用户
|
||||
Authorities []system.SysAuthority `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
}
|
11
model/system/response/sys_api.go
Normal file
11
model/system/response/sys_api.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package response
|
||||
|
||||
import "miniapp/model/system"
|
||||
|
||||
type SysAPIResponse struct {
|
||||
Api system.SysApi `json:"api"`
|
||||
}
|
||||
|
||||
type SysAPIListResponse struct {
|
||||
Apis []system.SysApi `json:"apis"`
|
||||
}
|
12
model/system/response/sys_authority.go
Normal file
12
model/system/response/sys_authority.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package response
|
||||
|
||||
import "miniapp/model/system"
|
||||
|
||||
type SysAuthorityResponse struct {
|
||||
Authority system.SysAuthority `json:"authority"`
|
||||
}
|
||||
|
||||
type SysAuthorityCopyResponse struct {
|
||||
Authority system.SysAuthority `json:"authority"`
|
||||
OldAuthorityId uint `json:"oldAuthorityId"` // 旧角色ID
|
||||
}
|
5
model/system/response/sys_authority_btn.go
Normal file
5
model/system/response/sys_authority_btn.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package response
|
||||
|
||||
type SysAuthorityBtnRes struct {
|
||||
Selected []uint `json:"selected"`
|
||||
}
|
16
model/system/response/sys_auto_code.go
Normal file
16
model/system/response/sys_auto_code.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package response
|
||||
|
||||
type Db struct {
|
||||
Database string `json:"database" gorm:"column:database"`
|
||||
}
|
||||
|
||||
type Table struct {
|
||||
TableName string `json:"tableName" gorm:"column:table_name"`
|
||||
}
|
||||
|
||||
type Column struct {
|
||||
DataType string `json:"dataType" gorm:"column:data_type"`
|
||||
ColumnName string `json:"columnName" gorm:"column:column_name"`
|
||||
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
|
||||
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
|
||||
}
|
14
model/system/response/sys_auto_code_history.go
Normal file
14
model/system/response/sys_auto_code_history.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type AutoCodeHistory struct {
|
||||
ID uint `json:"ID" gorm:"column:id"`
|
||||
CreatedAt time.Time `json:"CreatedAt" gorm:"column:created_at"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt" gorm:"column:updated_at"`
|
||||
BusinessDB string `json:"businessDB" gorm:"column:business_db"`
|
||||
TableName string `json:"tableName" gorm:"column:table_name"`
|
||||
StructName string `json:"structName" gorm:"column:struct_name"`
|
||||
StructCNName string `json:"structCNName" gorm:"column:struct_cn_name"`
|
||||
Flag int `json:"flag" gorm:"column:flag"`
|
||||
}
|
8
model/system/response/sys_captcha.go
Normal file
8
model/system/response/sys_captcha.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package response
|
||||
|
||||
type SysCaptchaResponse struct {
|
||||
CaptchaId string `json:"captchaId"`
|
||||
PicPath string `json:"picPath"`
|
||||
CaptchaLength int `json:"captchaLength"`
|
||||
OpenCaptcha bool `json:"openCaptcha"`
|
||||
}
|
9
model/system/response/sys_casbin.go
Normal file
9
model/system/response/sys_casbin.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"miniapp/model/system/request"
|
||||
)
|
||||
|
||||
type PolicyPathResponse struct {
|
||||
Paths []request.CasbinInfo `json:"paths"`
|
||||
}
|
4
model/system/response/sys_chatgpt.go
Normal file
4
model/system/response/sys_chatgpt.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package response
|
||||
|
||||
type ChatGptResponse struct {
|
||||
}
|
15
model/system/response/sys_menu.go
Normal file
15
model/system/response/sys_menu.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package response
|
||||
|
||||
import "miniapp/model/system"
|
||||
|
||||
type SysMenusResponse struct {
|
||||
Menus []system.SysMenu `json:"menus"`
|
||||
}
|
||||
|
||||
type SysBaseMenusResponse struct {
|
||||
Menus []system.SysBaseMenu `json:"menus"`
|
||||
}
|
||||
|
||||
type SysBaseMenuResponse struct {
|
||||
Menu system.SysBaseMenu `json:"menu"`
|
||||
}
|
7
model/system/response/sys_system.go
Normal file
7
model/system/response/sys_system.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package response
|
||||
|
||||
import "miniapp/config"
|
||||
|
||||
type SysConfigResponse struct {
|
||||
Config config.Server `json:"config"`
|
||||
}
|
15
model/system/response/sys_user.go
Normal file
15
model/system/response/sys_user.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"miniapp/model/system"
|
||||
)
|
||||
|
||||
type SysUserResponse struct {
|
||||
User system.SysUser `json:"user"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
User system.SysUser `json:"user"`
|
||||
Token string `json:"token"`
|
||||
ExpiresAt int64 `json:"expiresAt"`
|
||||
}
|
17
model/system/sys_api.go
Normal file
17
model/system/sys_api.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type SysApi struct {
|
||||
global.GVA_MODEL
|
||||
Path string `json:"path" gorm:"comment:api路径"` // api路径
|
||||
Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述
|
||||
ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组
|
||||
Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
|
||||
}
|
||||
|
||||
func (SysApi) TableName() string {
|
||||
return "sys_apis"
|
||||
}
|
23
model/system/sys_authority.go
Normal file
23
model/system/sys_authority.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type SysAuthority struct {
|
||||
CreatedAt time.Time // 创建时间
|
||||
UpdatedAt time.Time // 更新时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
AuthorityId uint `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
||||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
||||
ParentId *uint `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
||||
DataAuthorityId []*SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;"`
|
||||
Children []SysAuthority `json:"children" gorm:"-"`
|
||||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
|
||||
Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"`
|
||||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
||||
}
|
||||
|
||||
func (SysAuthority) TableName() string {
|
||||
return "sys_authorities"
|
||||
}
|
8
model/system/sys_authority_btn.go
Normal file
8
model/system/sys_authority_btn.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package system
|
||||
|
||||
type SysAuthorityBtn struct {
|
||||
AuthorityId uint `gorm:"comment:角色ID"`
|
||||
SysMenuID uint `gorm:"comment:菜单ID"`
|
||||
SysBaseMenuBtnID uint `gorm:"comment:菜单按钮ID"`
|
||||
SysBaseMenuBtn SysBaseMenuBtn ` gorm:"comment:按钮详情"`
|
||||
}
|
19
model/system/sys_authority_menu.go
Normal file
19
model/system/sys_authority_menu.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package system
|
||||
|
||||
type SysMenu struct {
|
||||
SysBaseMenu
|
||||
MenuId string `json:"menuId" gorm:"comment:菜单ID"`
|
||||
AuthorityId uint `json:"-" gorm:"comment:角色ID"`
|
||||
Children []SysMenu `json:"children" gorm:"-"`
|
||||
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"foreignKey:SysBaseMenuID;references:MenuId"`
|
||||
Btns map[string]uint `json:"btns" gorm:"-"`
|
||||
}
|
||||
|
||||
type SysAuthorityMenu struct {
|
||||
MenuId string `json:"menuId" gorm:"comment:菜单ID;column:sys_base_menu_id"`
|
||||
AuthorityId string `json:"-" gorm:"comment:角色ID;column:sys_authority_authority_id"`
|
||||
}
|
||||
|
||||
func (s SysAuthorityMenu) TableName() string {
|
||||
return "sys_authority_menus"
|
||||
}
|
119
model/system/sys_auto_code.go
Normal file
119
model/system/sys_auto_code.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go/token"
|
||||
"strings"
|
||||
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// AutoCodeStruct 初始版本自动化代码工具
|
||||
type AutoCodeStruct struct {
|
||||
StructName string `json:"structName"` // Struct名称
|
||||
TableName string `json:"tableName"` // 表名
|
||||
PackageName string `json:"packageName"` // 文件名称
|
||||
HumpPackageName string `json:"humpPackageName"` // go文件名称
|
||||
Abbreviation string `json:"abbreviation"` // Struct简称
|
||||
Description string `json:"description"` // Struct中文名称
|
||||
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
|
||||
AutoCreateResource bool `json:"autoCreateResource"` // 是否自动创建资源标识
|
||||
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
|
||||
BusinessDB string `json:"businessDB"` // 业务数据库
|
||||
Fields []*Field `json:"fields,omitempty"`
|
||||
HasTimer bool
|
||||
DictTypes []string `json:"-"`
|
||||
Package string `json:"package"`
|
||||
PackageT string `json:"-"`
|
||||
NeedValid bool `json:"-"`
|
||||
NeedSort bool `json:"-"`
|
||||
HasPic bool `json:"-"`
|
||||
HasRichText bool `json:"-"`
|
||||
HasFile bool `json:"-"`
|
||||
NeedJSON bool `json:"-"`
|
||||
}
|
||||
|
||||
func (a *AutoCodeStruct) Pretreatment() {
|
||||
a.KeyWord()
|
||||
a.SuffixTest()
|
||||
}
|
||||
|
||||
// KeyWord 是go关键字的处理加上 _ ,防止编译报错
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (a *AutoCodeStruct) KeyWord() {
|
||||
if token.IsKeyword(a.Abbreviation) {
|
||||
a.Abbreviation = a.Abbreviation + "_"
|
||||
}
|
||||
}
|
||||
|
||||
// SuffixTest 处理_test 后缀
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (a *AutoCodeStruct) SuffixTest() {
|
||||
if strings.HasSuffix(a.HumpPackageName, "test") {
|
||||
a.HumpPackageName = a.HumpPackageName + "_"
|
||||
}
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
FieldName string `json:"fieldName"` // Field名
|
||||
FieldDesc string `json:"fieldDesc"` // 中文名
|
||||
FieldType string `json:"fieldType"` // Field数据类型
|
||||
FieldJson string `json:"fieldJson"` // FieldJson
|
||||
DataTypeLong string `json:"dataTypeLong"` // 数据库字段长度
|
||||
Comment string `json:"comment"` // 数据库字段描述
|
||||
ColumnName string `json:"columnName"` // 数据库字段
|
||||
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
|
||||
DictType string `json:"dictType"` // 字典
|
||||
Require bool `json:"require"` // 是否必填
|
||||
ErrorText string `json:"errorText"` // 校验失败文字
|
||||
Clearable bool `json:"clearable"` // 是否可清空
|
||||
Sort bool `json:"sort"` // 是否增加排序
|
||||
}
|
||||
|
||||
var ErrAutoMove error = errors.New("创建代码成功并移动文件成功")
|
||||
|
||||
type SysAutoCode struct {
|
||||
global.GVA_MODEL
|
||||
PackageName string `json:"packageName" gorm:"comment:包名"`
|
||||
Label string `json:"label" gorm:"comment:展示名"`
|
||||
Desc string `json:"desc" gorm:"comment:描述"`
|
||||
}
|
||||
|
||||
type AutoPlugReq struct {
|
||||
PlugName string `json:"plugName"` // 必然大写开头
|
||||
Snake string `json:"snake"` // 后端自动转为 snake
|
||||
RouterGroup string `json:"routerGroup"`
|
||||
HasGlobal bool `json:"hasGlobal"`
|
||||
HasRequest bool `json:"hasRequest"`
|
||||
HasResponse bool `json:"hasResponse"`
|
||||
NeedModel bool `json:"needModel"`
|
||||
Global []AutoPlugInfo `json:"global,omitempty"`
|
||||
Request []AutoPlugInfo `json:"request,omitempty"`
|
||||
Response []AutoPlugInfo `json:"response,omitempty"`
|
||||
}
|
||||
|
||||
func (a *AutoPlugReq) CheckList() {
|
||||
a.Global = bind(a.Global)
|
||||
a.Request = bind(a.Request)
|
||||
a.Response = bind(a.Response)
|
||||
|
||||
}
|
||||
func bind(req []AutoPlugInfo) []AutoPlugInfo {
|
||||
var r []AutoPlugInfo
|
||||
for _, info := range req {
|
||||
if info.Effective() {
|
||||
r = append(r, info)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
type AutoPlugInfo struct {
|
||||
Key string `json:"key"`
|
||||
Type string `json:"type"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
func (a AutoPlugInfo) Effective() bool {
|
||||
return a.Key != "" && a.Type != "" && a.Desc != ""
|
||||
}
|
40
model/system/sys_autocode_history.go
Normal file
40
model/system/sys_autocode_history.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"miniapp/global"
|
||||
"miniapp/model/common/request"
|
||||
)
|
||||
|
||||
// SysAutoCodeHistory 自动迁移代码记录,用于回滚,重放使用
|
||||
type SysAutoCodeHistory struct {
|
||||
global.GVA_MODEL
|
||||
Package string `json:"package"`
|
||||
BusinessDB string `json:"businessDB"`
|
||||
TableName string `json:"tableName"`
|
||||
RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息
|
||||
AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path
|
||||
InjectionMeta string `gorm:"type:text" json:"injectionMeta,omitempty"` // 注入的内容 RouterPath@functionName@RouterString;
|
||||
StructName string `json:"structName"`
|
||||
StructCNName string `json:"structCNName"`
|
||||
ApiIDs string `json:"apiIDs,omitempty"` // api表注册内容
|
||||
Flag int `json:"flag"` // 表示对应状态 0 代表创建, 1 代表回滚 ...
|
||||
}
|
||||
|
||||
// ToRequestIds ApiIDs 转换 request.IdsReq
|
||||
// Author [SliverHorn](https://github.com/SliverHorn)
|
||||
func (m *SysAutoCodeHistory) ToRequestIds() request.IdsReq {
|
||||
if m.ApiIDs == "" {
|
||||
return request.IdsReq{}
|
||||
}
|
||||
slice := strings.Split(m.ApiIDs, ";")
|
||||
ids := make([]int, 0, len(slice))
|
||||
length := len(slice)
|
||||
for i := 0; i < length; i++ {
|
||||
id, _ := strconv.ParseInt(slice[i], 10, 32)
|
||||
ids = append(ids, int(id))
|
||||
}
|
||||
return request.IdsReq{Ids: ids}
|
||||
}
|
42
model/system/sys_base_menu.go
Normal file
42
model/system/sys_base_menu.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type SysBaseMenu struct {
|
||||
global.GVA_MODEL
|
||||
MenuLevel uint `json:"-"`
|
||||
ParentId string `json:"parentId" gorm:"comment:父菜单ID"` // 父菜单ID
|
||||
Path string `json:"path" gorm:"comment:路由path"` // 路由path
|
||||
Name string `json:"name" gorm:"comment:路由name"` // 路由name
|
||||
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏
|
||||
Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径
|
||||
Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记
|
||||
Meta `json:"meta" gorm:"embedded;comment:附加属性"` // 附加属性
|
||||
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
|
||||
Children []SysBaseMenu `json:"children" gorm:"-"`
|
||||
Parameters []SysBaseMenuParameter `json:"parameters"`
|
||||
MenuBtn []SysBaseMenuBtn `json:"menuBtn"`
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
ActiveName string `json:"activeName" gorm:"comment:高亮菜单"`
|
||||
KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"` // 是否缓存
|
||||
DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"` // 是否是基础路由(开发中)
|
||||
Title string `json:"title" gorm:"comment:菜单名"` // 菜单名
|
||||
Icon string `json:"icon" gorm:"comment:菜单图标"` // 菜单图标
|
||||
CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"` // 自动关闭tab
|
||||
}
|
||||
|
||||
type SysBaseMenuParameter struct {
|
||||
global.GVA_MODEL
|
||||
SysBaseMenuID uint
|
||||
Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"` // 地址栏携带参数为params还是query
|
||||
Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key
|
||||
Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值
|
||||
}
|
||||
|
||||
func (SysBaseMenu) TableName() string {
|
||||
return "sys_base_menus"
|
||||
}
|
22
model/system/sys_chatgpt.go
Normal file
22
model/system/sys_chatgpt.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package system
|
||||
|
||||
type ChatGpt struct {
|
||||
DBName string `json:"dbname,omitempty"`
|
||||
Chat string `json:"chat,omitempty"`
|
||||
ChatID string `json:"chatID,omitempty"`
|
||||
}
|
||||
|
||||
type SysChatGptOption struct {
|
||||
SK string `json:"sk"`
|
||||
}
|
||||
|
||||
type ChatField struct {
|
||||
TABLE_NAME string
|
||||
COLUMN_NAME string
|
||||
COLUMN_COMMENT string
|
||||
}
|
||||
|
||||
type ChatFieldNoTable struct {
|
||||
COLUMN_NAME string
|
||||
COLUMN_COMMENT string
|
||||
}
|
20
model/system/sys_dictionary.go
Normal file
20
model/system/sys_dictionary.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// 自动生成模板SysDictionary
|
||||
package system
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type SysDictionary struct {
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` // 字典名(中)
|
||||
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"` // 字典名(英)
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"` // 状态
|
||||
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"` // 描述
|
||||
SysDictionaryDetails []SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
|
||||
}
|
||||
|
||||
func (SysDictionary) TableName() string {
|
||||
return "sys_dictionaries"
|
||||
}
|
21
model/system/sys_dictionary_detail.go
Normal file
21
model/system/sys_dictionary_detail.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// 自动生成模板SysDictionaryDetail
|
||||
package system
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type SysDictionaryDetail struct {
|
||||
global.GVA_MODEL
|
||||
Label string `json:"label" form:"label" gorm:"column:label;comment:展示值"` // 展示值
|
||||
Value int `json:"value" form:"value" gorm:"column:value;comment:字典值"` // 字典值
|
||||
Extend string `json:"extend" form:"extend" gorm:"column:extend;comment:扩展值"` // 扩展值
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:启用状态"` // 启用状态
|
||||
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"` // 排序标记
|
||||
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
|
||||
}
|
||||
|
||||
func (SysDictionaryDetail) TableName() string {
|
||||
return "sys_dictionary_details"
|
||||
}
|
10
model/system/sys_jwt_blacklist.go
Normal file
10
model/system/sys_jwt_blacklist.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type JwtBlacklist struct {
|
||||
global.GVA_MODEL
|
||||
Jwt string `gorm:"type:text;comment:jwt"`
|
||||
}
|
10
model/system/sys_menu_btn.go
Normal file
10
model/system/sys_menu_btn.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package system
|
||||
|
||||
import "miniapp/global"
|
||||
|
||||
type SysBaseMenuBtn struct {
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" gorm:"comment:按钮关键key"`
|
||||
Desc string `json:"desc" gorm:"按钮备注"`
|
||||
SysBaseMenuID uint `json:"sysBaseMenuID" gorm:"comment:菜单ID"`
|
||||
}
|
24
model/system/sys_operation_record.go
Normal file
24
model/system/sys_operation_record.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// 自动生成模板SysOperationRecord
|
||||
package system
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
// 如果含有time.Time 请自行import time包
|
||||
type SysOperationRecord struct {
|
||||
global.GVA_MODEL
|
||||
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"` // 请求ip
|
||||
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"` // 请求方法
|
||||
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"` // 请求路径
|
||||
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"` // 请求状态
|
||||
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
|
||||
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"` // 代理
|
||||
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` // 错误信息
|
||||
Body string `json:"body" form:"body" gorm:"type:text;column:body;comment:请求Body"` // 请求Body
|
||||
Resp string `json:"resp" form:"resp" gorm:"type:text;column:resp;comment:响应Body"` // 响应Body
|
||||
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` // 用户id
|
||||
User SysUser `json:"user"`
|
||||
}
|
10
model/system/sys_system.go
Normal file
10
model/system/sys_system.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"miniapp/config"
|
||||
)
|
||||
|
||||
// 配置文件结构体
|
||||
type System struct {
|
||||
Config config.Server `json:"config"`
|
||||
}
|
28
model/system/sys_user.go
Normal file
28
model/system/sys_user.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gofrs/uuid/v5"
|
||||
"miniapp/global"
|
||||
)
|
||||
|
||||
type SysUser struct {
|
||||
global.GVA_MODEL
|
||||
UUID uuid.UUID `json:"uuid" gorm:"index;comment:用户UUID"` // 用户UUID
|
||||
Username string `json:"userName" gorm:"index;comment:用户登录名"` // 用户登录名
|
||||
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
|
||||
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
|
||||
SideMode string `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"` // 用户侧边主题
|
||||
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
|
||||
BaseColor string `json:"baseColor" gorm:"default:#fff;comment:基础颜色"` // 基础颜色
|
||||
ActiveColor string `json:"activeColor" gorm:"default:#1890ff;comment:活跃颜色"` // 活跃颜色
|
||||
AuthorityId uint `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
|
||||
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"`
|
||||
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`
|
||||
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
|
||||
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
|
||||
Enable int `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"` //用户是否被冻结 1正常 2冻结
|
||||
}
|
||||
|
||||
func (SysUser) TableName() string {
|
||||
return "sys_users"
|
||||
}
|
11
model/system/sys_user_authority.go
Normal file
11
model/system/sys_user_authority.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package system
|
||||
|
||||
// SysUserAuthority 是 sysUser 和 sysAuthority 的连接表
|
||||
type SysUserAuthority struct {
|
||||
SysUserId uint `gorm:"column:sys_user_id"`
|
||||
SysAuthorityAuthorityId uint `gorm:"column:sys_authority_authority_id"`
|
||||
}
|
||||
|
||||
func (s *SysUserAuthority) TableName() string {
|
||||
return "sys_user_authority"
|
||||
}
|
111
model/types/date.go
Normal file
111
model/types/date.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 默认时间格式
|
||||
const dateFormat = "2006-01-02 15:04:05.000"
|
||||
|
||||
// DateTime 自定义时间类型
|
||||
type DateTime time.Time
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (dt *DateTime) Scan(value any) error {
|
||||
// mysql 内部日期的格式可能是 2006-01-02 15:04:05 +0800 CST 格式,所以检出的时候还需要进行一次格式化
|
||||
tTime, _ := time.ParseInLocation("2006-01-02 15:04:05 +0800 CST", value.(time.Time).String(), time.Local)
|
||||
*dt = DateTime(tTime)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (dt DateTime) Value() (driver.Value, error) {
|
||||
// 0001-01-01 00:00:00 属于空值,遇到空值解析成 null 即可
|
||||
if dt.String() == "0001-01-01 00:00:00.000" {
|
||||
return nil, nil
|
||||
}
|
||||
return []byte(dt.Format(dateFormat)), nil
|
||||
}
|
||||
|
||||
// 用于 fmt.Println 和后续验证场景
|
||||
func (dt DateTime) String() string {
|
||||
return dt.Format(dateFormat)
|
||||
}
|
||||
|
||||
// Format 格式化
|
||||
func (dt DateTime) Format(fm string) string {
|
||||
return time.Time(dt).Format(fm)
|
||||
}
|
||||
|
||||
// After 时间比较
|
||||
func (dt *DateTime) After(now time.Time) bool {
|
||||
return time.Time(*dt).After(now)
|
||||
}
|
||||
|
||||
// Before 时间比较
|
||||
func (dt *DateTime) Before(now time.Time) bool {
|
||||
return time.Time(*dt).Before(now)
|
||||
}
|
||||
|
||||
// IBefore 时间比较
|
||||
func (dt *DateTime) IBefore(now DateTime) bool {
|
||||
return dt.Before(time.Time(now))
|
||||
}
|
||||
|
||||
// SubTime 对比
|
||||
func (dt DateTime) SubTime(t time.Time) time.Duration {
|
||||
return dt.ToTime().Sub(t)
|
||||
}
|
||||
|
||||
// Sub 对比
|
||||
func (dt DateTime) Sub(t DateTime) time.Duration {
|
||||
return dt.ToTime().Sub(t.ToTime())
|
||||
}
|
||||
|
||||
// ToTime 转换为golang的时间类型
|
||||
func (dt DateTime) ToTime() time.Time {
|
||||
return time.Time(dt).Local()
|
||||
}
|
||||
|
||||
// IsNil 是否为空值
|
||||
func (dt DateTime) IsNil() bool {
|
||||
return dt.Format(dateFormat) == "0001-01-01 00:00:00.000"
|
||||
}
|
||||
|
||||
// Unix 实现Unix函数
|
||||
func (dt DateTime) Unix() int64 {
|
||||
return dt.ToTime().Unix()
|
||||
}
|
||||
|
||||
// EndOfCentury 获取本世纪最后时间
|
||||
func (dt DateTime) EndOfCentury() DateTime {
|
||||
yearEnd := time.Now().Local().Year()/100*100 + 99
|
||||
return DateTime(time.Date(yearEnd, 12, 31, 23, 59, 59, 999999999, time.Local))
|
||||
}
|
||||
|
||||
// ======== 序列化 ========
|
||||
|
||||
// MarshalJSON 时间到字符串
|
||||
func (dt DateTime) MarshalJSON() ([]byte, error) {
|
||||
// 过滤掉空数据
|
||||
if dt.IsNil() {
|
||||
return []byte("\"\""), nil
|
||||
}
|
||||
output := fmt.Sprintf(`"%s"`, dt.Format("2006-01-02 15:04:05"))
|
||||
return []byte(output), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON 字符串到时间
|
||||
func (dt *DateTime) UnmarshalJSON(b []byte) error {
|
||||
if len(b) == 2 {
|
||||
*dt = DateTime{}
|
||||
return nil
|
||||
}
|
||||
// 解析指定的格式
|
||||
//now, err := time.ParseInLocation(`"`+dateFormat+`"`, string(b), time.Local)
|
||||
now, err := time.ParseInLocation(dateFormat, string(b), time.Local)
|
||||
*dt = DateTime(now)
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user