细节fix
This commit is contained in:
parent
26cbe18aed
commit
47ae9c1659
|
@ -6,16 +6,15 @@ import (
|
|||
|
||||
type LingYeDO struct {
|
||||
// 自增ID
|
||||
ID uint `gorm:"column:id;type:bigint(20);not null;primary_key;AUTO_INCREMENT" json:"id" form:"id"`
|
||||
ID uint64 `gorm:"column:id;type:bigint(20);not null;primary_key;AUTO_INCREMENT;comment:'自增ID'"`
|
||||
// 创建时间
|
||||
CreatedAt time.Time
|
||||
CreatedAt time.Time `gorm:"comment:'创建时间'"`
|
||||
// 更新时间
|
||||
UpdatedAt time.Time
|
||||
UpdatedAt time.Time `gorm:"comment:'更新时间'"`
|
||||
// 删除时间
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
// 扩展字段
|
||||
DeletedAt *time.Time `gorm:"comment:'删除时间'" sql:"index"`
|
||||
// 创建者
|
||||
CreatedBy string
|
||||
// 删除者
|
||||
UpdatedBy string
|
||||
CreatedBy string `gorm:"comment:'创建者'"`
|
||||
// 更新者
|
||||
UpdatedBy string `gorm:"comment:'更新者'"`
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package base
|
||||
|
||||
type LingYeDTO struct {
|
||||
ID uint `json:"id" form:"id"`
|
||||
ID uint64 `json:"id" form:"id"`
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
_ "github.com/jinzhu/gorm/dialects/mssql"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||
//_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
"lingye-gin/src/modules/system/entity"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -50,10 +50,25 @@ func (v DataSourcePool) Connect() DataSourcePool {
|
|||
return v
|
||||
}
|
||||
|
||||
// 统一在这里注册数据表
|
||||
// 注册数据表
|
||||
func (DataSourcePool) LoadEntity() {
|
||||
// 自动迁移模式
|
||||
if SqlExcutor != nil {
|
||||
SqlExcutor.AutoMigrate(&entity.User{})
|
||||
SqlExcutor.AutoMigrate(
|
||||
&entity.Dept{},
|
||||
&entity.DictData{},
|
||||
&entity.DictType{},
|
||||
&entity.Job{},
|
||||
&entity.Menu{},
|
||||
&entity.Notice{},
|
||||
&entity.OperateLog{},
|
||||
&entity.Position{},
|
||||
&entity.Role{},
|
||||
&entity.RoleDept{},
|
||||
&entity.RoleMenu{},
|
||||
&entity.User{},
|
||||
&entity.UserPosition{},
|
||||
&entity.UserRole{},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ func main() {
|
|||
new(config.ApplicationProperties).Init()
|
||||
// 初始化redis
|
||||
new(middleware.RedisPool).Init()
|
||||
// 初始化gorm
|
||||
// 初始化gorm, 注册表
|
||||
new(config.DataSourcePool).Connect().LoadEntity()
|
||||
// 延时调用函数
|
||||
defer config.SqlExcutor.Close()
|
||||
|
|
|
@ -3,7 +3,6 @@ package middleware
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"lingye-gin/src"
|
||||
"lingye-gin/src/config"
|
||||
"strings"
|
||||
)
|
||||
|
@ -19,11 +18,11 @@ func (v GinRouter) Init(r *gin.Engine) {
|
|||
// 一般路由映射关系
|
||||
groupMap := make(map[string]*gin.RouterGroup)
|
||||
// api路由映射关系
|
||||
apiUrls := make([]main.RequestApi, 0)
|
||||
apiUrls := make([]RequestApi, 0)
|
||||
// api组名称
|
||||
apiGroupName := "api"
|
||||
|
||||
for _, normalRa := range main.Urls {
|
||||
for _, normalRa := range Urls {
|
||||
// 判断是否在某一组下
|
||||
if strings.Compare(normalRa.GroupName, "") == 0 {
|
||||
// 批量处理
|
||||
|
@ -68,7 +67,7 @@ func (v GinRouter) Init(r *gin.Engine) {
|
|||
config.Logger.Info("GinRouter Ok")
|
||||
}
|
||||
|
||||
func handle(request main.RequestApi, engine *gin.Engine) bool {
|
||||
func handle(request RequestApi, engine *gin.Engine) bool {
|
||||
// get
|
||||
if strings.Compare(request.Mode, "get") == 0 {
|
||||
engine.GET(request.RelativePath, request.HandleFunction)
|
||||
|
@ -92,7 +91,7 @@ func handle(request main.RequestApi, engine *gin.Engine) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func handleGroup(request main.RequestApi, group *gin.RouterGroup) bool {
|
||||
func handleGroup(request RequestApi, group *gin.RouterGroup) bool {
|
||||
// get
|
||||
if strings.Compare(request.Mode, "get") == 0 {
|
||||
group.GET(request.RelativePath, request.HandleFunction)
|
||||
|
|
|
@ -22,7 +22,7 @@ const HeadLingYe = "LingYe"
|
|||
// 继承jwt提供给载荷,扩展自己所需字段
|
||||
type JwtClaims struct {
|
||||
jwt.StandardClaims
|
||||
UserId uint `json:"id"` // 用户ID
|
||||
UserId uint64 `json:"id"` // 用户ID
|
||||
UserName string `json:"username"` // 用户名
|
||||
NickName string `json:"nickname"` // 用户昵称
|
||||
Email string `json:"email"` // 邮箱账号
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
|
@ -15,7 +15,7 @@ func (dao UserDAO) Insert(resource *entity.User) {
|
|||
}
|
||||
|
||||
// ID查询
|
||||
func (dao UserDAO) SelectOne(id uint) entity.User {
|
||||
func (dao UserDAO) SelectOne(id uint64) entity.User {
|
||||
var user entity.User
|
||||
config.SqlExcutor.First(&user, id)
|
||||
return user
|
||||
|
@ -65,7 +65,7 @@ func (UserDAO) UpdateById(user *entity.User) {
|
|||
}
|
||||
|
||||
// 删除
|
||||
func (UserDAO) DeleteById(id uint) {
|
||||
func (UserDAO) DeleteById(id uint64) {
|
||||
user := entity.User{}
|
||||
user.ID = id
|
||||
config.SqlExcutor.Delete(&user)
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package entity
|
||||
|
||||
import (
|
||||
"lingye-gin/src/base"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
base.LingYeDO
|
||||
UserName string `gorm:"column:user_name;type:varchar(255);not null;index:idx_username"`
|
||||
NickName string `gorm:"column:nick_name;type:varchar(255)"`
|
||||
Email string `gorm:"column:email;type:varchar(255)"`
|
||||
PhoneNumber string `gorm:"column:phone_number;type:varchar(255)"`
|
||||
Sex string `gorm:"column:sex;type:varchar(255)"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255)"`
|
||||
Password string `gorm:"column:password;type:varchar(255);not null"`
|
||||
Status string `gorm:"column:status;type:varchar(255);not null"`
|
||||
Remark string `gorm:"column:remark;type:text(0)"`
|
||||
}
|
||||
|
||||
// 设置User的表名为`sys_user`
|
||||
func (User) TableName() string {
|
||||
return "sys_user"
|
||||
}
|
|
@ -26,7 +26,7 @@ func DescribeUsers(c *gin.Context) {
|
|||
|
||||
func DescribeUserById(c *gin.Context) {
|
||||
id := c.Params.ByName("id")
|
||||
user := userService.DescribeUserById(util.StringToUInt(id))
|
||||
user := userService.DescribeUserById(util.StringToUInt64(id))
|
||||
if user.ID == 0 {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"code": http.StatusNotFound,
|
||||
|
@ -54,7 +54,7 @@ func CreateUser(c *gin.Context) {
|
|||
|
||||
func ModifyUserById(c *gin.Context) {
|
||||
id := c.Params.ByName("id")
|
||||
localUser := userService.DescribeUserById(util.StringToUInt(id))
|
||||
localUser := userService.DescribeUserById(util.StringToUInt64(id))
|
||||
if localUser.ID == 0 {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"code": http.StatusNotFound,
|
||||
|
@ -74,7 +74,7 @@ func ModifyUserById(c *gin.Context) {
|
|||
|
||||
func DeleteUserById(c *gin.Context) {
|
||||
id := c.Params.ByName("id")
|
||||
uid := util.StringToUInt(id)
|
||||
uid := util.StringToUInt64(id)
|
||||
localUser := userService.DescribeUserById(uid)
|
||||
if localUser.ID == 0 {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
|
|
|
@ -21,7 +21,7 @@ func (service UserService) Save(resource *dto.UserDTO) {
|
|||
service.userDao.Insert(record)
|
||||
}
|
||||
|
||||
func (service UserService) RemoveById(id uint) {
|
||||
func (service UserService) RemoveById(id uint64) {
|
||||
if id == 0 {
|
||||
panic("id is zero")
|
||||
}
|
||||
|
@ -41,6 +41,6 @@ func (service UserService) DescribeUsers(condition query.UserQuery) ([]entity.Us
|
|||
return service.userDao.SelectPage(condition)
|
||||
}
|
||||
|
||||
func (service UserService) DescribeUserById(id uint) entity.User {
|
||||
func (service UserService) DescribeUserById(id uint64) entity.User {
|
||||
return service.userDao.SelectOne(id)
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ func StructCopy(source interface{}, target interface{}) {
|
|||
}
|
||||
|
||||
// 字符串转uint
|
||||
func StringToUInt(number string) uint {
|
||||
func StringToUInt64(number string) uint64 {
|
||||
result, _ := strconv.Atoi(number)
|
||||
return uint(result)
|
||||
return uint64(result)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue