初始化提交
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package model
|
||||
|
||||
// AdminApi 后台-接口表
|
||||
type AdminAPI struct {
|
||||
Model
|
||||
APIID int64 `gorm:"column:api_id;type:bigint(19);primary_key;AUTO_INCREMENT;comment:主键id" json:"api_id"`
|
||||
APIName string `gorm:"column:api_name;type:varchar(100);comment:api名称;NOT NULL" json:"api_name"`
|
||||
APIPath string `gorm:"column:api_path;type:varchar(255);comment:接口路径(全路径 id为:id);NOT NULL" json:"api_path"`
|
||||
APIMethod string `gorm:"column:api_method;type:varchar(10);comment:请求类型(put:修改 post:新增 get:获取 );NOT NULL" json:"api_method"`
|
||||
}
|
||||
|
||||
func (m *AdminAPI) TableName() string {
|
||||
return "gdxz_admin_api"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// AdminDept 后台-部门表
|
||||
type AdminDept struct {
|
||||
DeptId int64 `gorm:"column:dept_id;type:bigint(19);primary_key;comment:主键id" json:"dept_id"`
|
||||
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:本表父级id" json:"parent_id"`
|
||||
DeptName string `gorm:"column:dept_name;type:varchar(255);comment:部门名称" json:"dept_name"`
|
||||
DeptStatus int `gorm:"column:dept_status;type:tinyint(1);default:1;comment:部门状态(1:正常 2:删除)" json:"dept_status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (m *AdminDept) TableName() string {
|
||||
return "gdxz_admin_dept"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package model
|
||||
|
||||
// AdminMenu 后台-菜单表
|
||||
type AdminMenu struct {
|
||||
Model
|
||||
MenuId int64 `gorm:"column:menu_id;type:bigint(19);primary_key;comment:主键id" json:"menu_id"`
|
||||
MenuName string `gorm:"column:menu_name;type:varchar(30);comment:菜单名称" json:"menu_name"`
|
||||
ParentId int `gorm:"column:parent_id;type:int(10);default:0;comment:父菜单ID(0表示一级)" json:"parent_id"`
|
||||
MenuStatus int `gorm:"column:menu_status;type:tinyint(1);default:1;comment:菜单状态(0:隐藏 1:正常)此优先级最高" json:"menu_status"`
|
||||
MenuType int `gorm:"column:menu_type;type:tinyint(1);comment:菜单类型(1:模块 2:菜单 2:按钮)" json:"menu_type"`
|
||||
Permission string `gorm:"column:permission;type:varchar(255);comment:标识" json:"permission"`
|
||||
OrderNum int `gorm:"column:order_num;type:int(4);default:0;comment:显示顺序" json:"order_num"`
|
||||
Icon string `gorm:"column:icon;type:varchar(255);comment:图标地址" json:"icon"`
|
||||
Path string `gorm:"column:path;type:varchar(255);comment:页面地址(#表示当前页)" json:"path"`
|
||||
}
|
||||
|
||||
func (m *AdminMenu) TableName() string {
|
||||
return "gdxz_admin_menu"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
// AdminMenuApi 后台-菜单-接口表
|
||||
type AdminMenuApi struct {
|
||||
MenuId int64 `gorm:"column:menu_id;type:bigint(19);primary_key;comment:菜单id" json:"menu_id"`
|
||||
ApiId int64 `gorm:"column:api_id;type:bigint(19);primary_key;comment:接口id" json:"api_id"`
|
||||
Menu AdminMenu `gorm:"foreignkey:MenuId;association_foreignkey:MenuID"`
|
||||
API AdminAPI `gorm:"foreignkey:ApiId;association_foreignkey:APIID"`
|
||||
}
|
||||
|
||||
func (m *AdminMenuApi) TableName() string {
|
||||
return "gdxz_admin_menu_api"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// AdminPost 后台-岗位表
|
||||
type AdminPost struct {
|
||||
PostId int64 `gorm:"column:post_id;type:bigint(19);primary_key;comment:主键id" json:"post_id"`
|
||||
PostName string `gorm:"column:post_name;type:varchar(255);comment:部门名称" json:"post_name"`
|
||||
PostStatus int `gorm:"column:post_status;type:tinyint(1);default:1;comment:状态(1:正常 2:删除)" json:"post_status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (m *AdminPost) TableName() string {
|
||||
return "gdxz_admin_post"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package model
|
||||
|
||||
// AdminRole 后台-角色表
|
||||
type AdminRole struct {
|
||||
Model
|
||||
RoleId int64 `gorm:"column:role_id;type:bigint(19);primary_key;comment:主键id" json:"role_id"`
|
||||
RoleName string `gorm:"column:role_name;type:varchar(100);comment:角色名称" json:"role_name"`
|
||||
RoleStatus int `gorm:"column:role_status;type:tinyint(1);default:1;comment:角色状态(1:正常 2:禁用)" json:"role_status"`
|
||||
IsAdmin int `gorm:"column:is_admin;type:tinyint(1);default:0;comment:是否管理员(0:否 1:是)" json:"is_admin"`
|
||||
}
|
||||
|
||||
func (m *AdminRole) TableName() string {
|
||||
return "gdxz_admin_role"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
// AdminRoleMenu 后台-角色-菜单表
|
||||
type AdminRoleMenu struct {
|
||||
RoleID int64 `gorm:"column:role_id;type:bigint(19);primary_key;comment:权限id" json:"role_id"`
|
||||
MenuID int64 `gorm:"column:menu_id;type:bigint(19);primary_key;comment:菜单id" json:"menu_id"`
|
||||
Menu AdminMenu `gorm:"foreignKey:MenuID"`
|
||||
Role AdminRole `gorm:"foreignKey:RoleID"`
|
||||
}
|
||||
|
||||
func (m *AdminRoleMenu) TableName() string {
|
||||
return "gdxz_admin_role_menu"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// AdminUser 后台-用户表
|
||||
type AdminUser struct {
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
|
||||
UserName string `gorm:"column:user_name;type:varchar(64);comment:用户名" json:"user_name"`
|
||||
Password string `gorm:"column:password;type:varchar(128);comment:密码" json:"password"`
|
||||
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码" json:"salt"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态(1:正常 2:审核中 3:删除)" json:"status"`
|
||||
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
|
||||
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||||
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别(1:男 2:女)" json:"sex"`
|
||||
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
|
||||
RoleId int64 `gorm:"column:role_id;type:bigint(19);comment:角色表" json:"role_id"`
|
||||
DeptId int64 `gorm:"column:dept_id;type:bigint(19);comment:部门id" json:"dept_id"`
|
||||
PostId int64 `gorm:"column:post_id;type:bigint(19);comment:岗位id" json:"post_id"`
|
||||
CreateBy int64 `gorm:"column:create_by;type:bigint(19);comment:创建者id(用户表id)" json:"create_by"`
|
||||
UpdateBy int64 `gorm:"column:update_by;type:bigint(19);comment:更新者id(用户表id)" json:"update_by"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (m *AdminUser) TableName() string {
|
||||
return "gdxz_admin_user"
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
CreatedAt LocalTime `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt LocalTime `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// LocalTime 自定义数据类型
|
||||
type LocalTime time.Time
|
||||
|
||||
func (t *LocalTime) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
// 前端接收的时间字符串
|
||||
str := string(data)
|
||||
// 去除接收的str收尾多余的"
|
||||
timeStr := strings.Trim(str, "\"")
|
||||
t1, err := time.Parse("2006-01-02 15:04:05", timeStr)
|
||||
*t = LocalTime(t1)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t LocalTime) MarshalJSON() ([]byte, error) {
|
||||
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format("2006-01-02 15:04:05"))
|
||||
return []byte(formatted), nil
|
||||
}
|
||||
|
||||
func (t LocalTime) Value() (driver.Value, error) {
|
||||
// MyTime 转换成 time.Time 类型
|
||||
tTime := time.Time(t)
|
||||
return tTime.Format("2006-01-02 15:04:05"), nil
|
||||
}
|
||||
|
||||
func (t *LocalTime) Scan(v interface{}) error {
|
||||
switch vt := v.(type) {
|
||||
case time.Time:
|
||||
// 字符串转成 time.Time 类型
|
||||
*t = LocalTime(vt)
|
||||
default:
|
||||
return errors.New("类型处理错误")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *LocalTime) String() string {
|
||||
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
|
||||
}
|
||||
|
||||
// BeforeCreate 注册 BeforeCreate 回调函数
|
||||
func (m *Model) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
// 动态访问 YourModel 结构体本身
|
||||
model := tx.Statement.Dest
|
||||
|
||||
// 设置创建时间
|
||||
layout := "2006-01-02 15:04:05"
|
||||
strTime := "2019-08-09 11:35:52"
|
||||
parsedTime, err := time.Parse(layout, strTime)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 使用反射设置创建时间字段
|
||||
createdAtField := reflect.ValueOf(model).Elem().FieldByName("CreatedAt")
|
||||
if createdAtField.CanSet() {
|
||||
createdAtField.Set(reflect.ValueOf(parsedTime))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user