Simplify all the context link.
This commit is contained in:
@ -21,41 +21,41 @@ type AlienController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *AlienController) Init(context *Context) {
|
func (this *AlienController) Init() {
|
||||||
this.BaseController.Init(context)
|
this.BaseController.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean.
|
//手动装填本实例的Bean.
|
||||||
b := context.GetBean(this.uploadTokenDao)
|
b := CONTEXT.GetBean(this.uploadTokenDao)
|
||||||
if c, ok := b.(*UploadTokenDao); ok {
|
if c, ok := b.(*UploadTokenDao); ok {
|
||||||
this.uploadTokenDao = c
|
this.uploadTokenDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.downloadTokenDao)
|
b = CONTEXT.GetBean(this.downloadTokenDao)
|
||||||
if c, ok := b.(*DownloadTokenDao); ok {
|
if c, ok := b.(*DownloadTokenDao); ok {
|
||||||
this.downloadTokenDao = c
|
this.downloadTokenDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.matterDao)
|
b = CONTEXT.GetBean(this.matterDao)
|
||||||
if c, ok := b.(*MatterDao); ok {
|
if c, ok := b.(*MatterDao); ok {
|
||||||
this.matterDao = c
|
this.matterDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.matterService)
|
b = CONTEXT.GetBean(this.matterService)
|
||||||
if c, ok := b.(*MatterService); ok {
|
if c, ok := b.(*MatterService); ok {
|
||||||
this.matterService = c
|
this.matterService = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.imageCacheDao)
|
b = CONTEXT.GetBean(this.imageCacheDao)
|
||||||
if c, ok := b.(*ImageCacheDao); ok {
|
if c, ok := b.(*ImageCacheDao); ok {
|
||||||
this.imageCacheDao = c
|
this.imageCacheDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.imageCacheService)
|
b = CONTEXT.GetBean(this.imageCacheService)
|
||||||
if c, ok := b.(*ImageCacheService); ok {
|
if c, ok := b.(*ImageCacheService); ok {
|
||||||
this.imageCacheService = c
|
this.imageCacheService = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.alienService)
|
b = CONTEXT.GetBean(this.alienService)
|
||||||
if c, ok := b.(*AlienService); ok {
|
if c, ok := b.(*AlienService); ok {
|
||||||
this.alienService = c
|
this.alienService = c
|
||||||
}
|
}
|
||||||
|
@ -19,40 +19,40 @@ type AlienService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *AlienService) Init(context *Context) {
|
func (this *AlienService) Init() {
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.matterDao)
|
b := CONTEXT.GetBean(this.matterDao)
|
||||||
if b, ok := b.(*MatterDao); ok {
|
if b, ok := b.(*MatterDao); ok {
|
||||||
this.matterDao = b
|
this.matterDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.matterService)
|
b = CONTEXT.GetBean(this.matterService)
|
||||||
if b, ok := b.(*MatterService); ok {
|
if b, ok := b.(*MatterService); ok {
|
||||||
this.matterService = b
|
this.matterService = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.userDao)
|
b = CONTEXT.GetBean(this.userDao)
|
||||||
if b, ok := b.(*UserDao); ok {
|
if b, ok := b.(*UserDao); ok {
|
||||||
this.userDao = b
|
this.userDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.uploadTokenDao)
|
b = CONTEXT.GetBean(this.uploadTokenDao)
|
||||||
if c, ok := b.(*UploadTokenDao); ok {
|
if c, ok := b.(*UploadTokenDao); ok {
|
||||||
this.uploadTokenDao = c
|
this.uploadTokenDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.downloadTokenDao)
|
b = CONTEXT.GetBean(this.downloadTokenDao)
|
||||||
if c, ok := b.(*DownloadTokenDao); ok {
|
if c, ok := b.(*DownloadTokenDao); ok {
|
||||||
this.downloadTokenDao = c
|
this.downloadTokenDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.imageCacheDao)
|
b = CONTEXT.GetBean(this.imageCacheDao)
|
||||||
if c, ok := b.(*ImageCacheDao); ok {
|
if c, ok := b.(*ImageCacheDao); ok {
|
||||||
this.imageCacheDao = c
|
this.imageCacheDao = c
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.imageCacheService)
|
b = CONTEXT.GetBean(this.imageCacheService)
|
||||||
if c, ok := b.(*ImageCacheService); ok {
|
if c, ok := b.(*ImageCacheService); ok {
|
||||||
this.imageCacheService = c
|
this.imageCacheService = c
|
||||||
}
|
}
|
||||||
|
@ -21,17 +21,17 @@ type BaseController struct {
|
|||||||
sessionDao *SessionDao
|
sessionDao *SessionDao
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *BaseController) Init(context *Context) {
|
func (this *BaseController) Init() {
|
||||||
|
|
||||||
this.Bean.Init(context)
|
this.Bean.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean.
|
//手动装填本实例的Bean.
|
||||||
b := context.GetBean(this.userDao)
|
b := CONTEXT.GetBean(this.userDao)
|
||||||
if b, ok := b.(*UserDao); ok {
|
if b, ok := b.(*UserDao); ok {
|
||||||
this.userDao = b
|
this.userDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.sessionDao)
|
b = CONTEXT.GetBean(this.sessionDao)
|
||||||
if b, ok := b.(*SessionDao); ok {
|
if b, ok := b.(*SessionDao); ok {
|
||||||
this.sessionDao = b
|
this.sessionDao = b
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,17 @@ package rest
|
|||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
type IBean interface {
|
type IBean interface {
|
||||||
Init(context *Context)
|
Init()
|
||||||
PanicError(err error);
|
PanicError(err error);
|
||||||
PanicWebError(msg string, code int);
|
PanicWebError(msg string, code int);
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bean struct {
|
type Bean struct {
|
||||||
context *Context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Bean) Init(context *Context) {
|
func (this *Bean) Init() {
|
||||||
this.context = context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理错误的统一方法
|
//处理错误的统一方法
|
||||||
|
@ -67,7 +67,7 @@ func (this *Context) Init() {
|
|||||||
this.initBeans()
|
this.initBeans()
|
||||||
|
|
||||||
//初始化Router. 这个方法要在Bean注册好了之后才能。
|
//初始化Router. 这个方法要在Bean注册好了之后才能。
|
||||||
this.Router = NewRouter(this)
|
this.Router = NewRouter()
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册一个Bean
|
//注册一个Bean
|
||||||
@ -159,7 +159,7 @@ func (this *Context) GetBean(bean IBean) IBean {
|
|||||||
func (this *Context) initBeans() {
|
func (this *Context) initBeans() {
|
||||||
|
|
||||||
for _, bean := range this.BeanMap {
|
for _, bean := range this.BeanMap {
|
||||||
bean.Init(this)
|
bean.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ func (this *DownloadTokenDao) FindByUuid(uuid string) *DownloadToken {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var downloadToken = &DownloadToken{}
|
var downloadToken = &DownloadToken{}
|
||||||
db := this.context.DB.Where(&DownloadToken{Base: Base{Uuid: uuid}}).First(downloadToken)
|
db := CONTEXT.DB.Where(&DownloadToken{Base: Base{Uuid: uuid}}).First(downloadToken)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func (this *DownloadTokenDao) CheckByUuid(uuid string) *DownloadToken {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var downloadToken = &DownloadToken{}
|
var downloadToken = &DownloadToken{}
|
||||||
db := this.context.DB.Where(&DownloadToken{Base: Base{Uuid: uuid}}).First(downloadToken)
|
db := CONTEXT.DB.Where(&DownloadToken{Base: Base{Uuid: uuid}}).First(downloadToken)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
return downloadToken
|
return downloadToken
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func (this *DownloadTokenDao) Create(downloadToken *DownloadToken) *DownloadToke
|
|||||||
downloadToken.CreateTime = time.Now()
|
downloadToken.CreateTime = time.Now()
|
||||||
downloadToken.UpdateTime = time.Now()
|
downloadToken.UpdateTime = time.Now()
|
||||||
|
|
||||||
db := this.context.DB.Create(downloadToken)
|
db := CONTEXT.DB.Create(downloadToken)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return downloadToken
|
return downloadToken
|
||||||
@ -53,7 +53,7 @@ func (this *DownloadTokenDao) Create(downloadToken *DownloadToken) *DownloadToke
|
|||||||
func (this *DownloadTokenDao) Save(downloadToken *DownloadToken) *DownloadToken {
|
func (this *DownloadTokenDao) Save(downloadToken *DownloadToken) *DownloadToken {
|
||||||
|
|
||||||
downloadToken.UpdateTime = time.Now()
|
downloadToken.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Save(downloadToken)
|
db := CONTEXT.DB.Save(downloadToken)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return downloadToken
|
return downloadToken
|
||||||
|
@ -13,16 +13,16 @@ type ImageCacheController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *ImageCacheController) Init(context *Context) {
|
func (this *ImageCacheController) Init() {
|
||||||
this.BaseController.Init(context)
|
this.BaseController.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.imageCacheDao)
|
b := CONTEXT.GetBean(this.imageCacheDao)
|
||||||
if b, ok := b.(*ImageCacheDao); ok {
|
if b, ok := b.(*ImageCacheDao); ok {
|
||||||
this.imageCacheDao = b
|
this.imageCacheDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.imageCacheService)
|
b = CONTEXT.GetBean(this.imageCacheService)
|
||||||
if b, ok := b.(*ImageCacheService); ok {
|
if b, ok := b.(*ImageCacheService); ok {
|
||||||
this.imageCacheService = b
|
this.imageCacheService = b
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func (this *ImageCacheDao) FindByUuid(uuid string) *ImageCache {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var imageCache ImageCache
|
var imageCache ImageCache
|
||||||
db := this.context.DB.Where(&ImageCache{Base: Base{Uuid: uuid}}).First(&imageCache)
|
db := CONTEXT.DB.Where(&ImageCache{Base: Base{Uuid: uuid}}).First(&imageCache)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ func (this *ImageCacheDao) CheckByUuid(uuid string) *ImageCache {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var imageCache ImageCache
|
var imageCache ImageCache
|
||||||
db := this.context.DB.Where(&ImageCache{Base: Base{Uuid: uuid}}).First(&imageCache)
|
db := CONTEXT.DB.Where(&ImageCache{Base: Base{Uuid: uuid}}).First(&imageCache)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return &imageCache
|
return &imageCache
|
||||||
@ -52,7 +52,7 @@ func (this *ImageCacheDao) FindByMatterUuidAndMode(matterUuid string, mode strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
var imageCache = &ImageCache{}
|
var imageCache = &ImageCache{}
|
||||||
db := this.context.DB.Model(&ImageCache{}).Where(wp.Query, wp.Args...).First(imageCache)
|
db := CONTEXT.DB.Model(&ImageCache{}).Where(wp.Query, wp.Args...).First(imageCache)
|
||||||
|
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -66,7 +66,7 @@ func (this *ImageCacheDao) CheckByUuidAndUserUuid(uuid string, userUuid string)
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var imageCache = &ImageCache{}
|
var imageCache = &ImageCache{}
|
||||||
db := this.context.DB.Where(&ImageCache{Base: Base{Uuid: uuid}, UserUuid: userUuid}).First(imageCache)
|
db := CONTEXT.DB.Where(&ImageCache{Base: Base{Uuid: uuid}, UserUuid: userUuid}).First(imageCache)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return imageCache
|
return imageCache
|
||||||
@ -78,7 +78,7 @@ func (this *ImageCacheDao) ListByUserUuidAndPuuidAndDirAndName(userUuid string)
|
|||||||
|
|
||||||
var imageCaches []*ImageCache
|
var imageCaches []*ImageCache
|
||||||
|
|
||||||
db := this.context.DB.
|
db := CONTEXT.DB.
|
||||||
Where(ImageCache{UserUuid: userUuid}).
|
Where(ImageCache{UserUuid: userUuid}).
|
||||||
Find(&imageCaches)
|
Find(&imageCaches)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
@ -100,7 +100,7 @@ func (this *ImageCacheDao) Page(page int, pageSize int, userUuid string, matterU
|
|||||||
}
|
}
|
||||||
|
|
||||||
var conditionDB *gorm.DB
|
var conditionDB *gorm.DB
|
||||||
conditionDB = this.context.DB.Model(&ImageCache{}).Where(wp.Query, wp.Args...)
|
conditionDB = CONTEXT.DB.Model(&ImageCache{}).Where(wp.Query, wp.Args...)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
db := conditionDB.Count(&count)
|
db := conditionDB.Count(&count)
|
||||||
@ -122,7 +122,7 @@ func (this *ImageCacheDao) Create(imageCache *ImageCache) *ImageCache {
|
|||||||
imageCache.Uuid = string(timeUUID.String())
|
imageCache.Uuid = string(timeUUID.String())
|
||||||
imageCache.CreateTime = time.Now()
|
imageCache.CreateTime = time.Now()
|
||||||
imageCache.UpdateTime = time.Now()
|
imageCache.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Create(imageCache)
|
db := CONTEXT.DB.Create(imageCache)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return imageCache
|
return imageCache
|
||||||
@ -132,7 +132,7 @@ func (this *ImageCacheDao) Create(imageCache *ImageCache) *ImageCache {
|
|||||||
func (this *ImageCacheDao) Save(imageCache *ImageCache) *ImageCache {
|
func (this *ImageCacheDao) Save(imageCache *ImageCache) *ImageCache {
|
||||||
|
|
||||||
imageCache.UpdateTime = time.Now()
|
imageCache.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Save(imageCache)
|
db := CONTEXT.DB.Save(imageCache)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return imageCache
|
return imageCache
|
||||||
@ -163,7 +163,7 @@ func (this *ImageCacheDao) deleteFileAndDir(imageCache *ImageCache) {
|
|||||||
//删除一个文件,数据库中删除,物理磁盘上删除。
|
//删除一个文件,数据库中删除,物理磁盘上删除。
|
||||||
func (this *ImageCacheDao) Delete(imageCache *ImageCache) {
|
func (this *ImageCacheDao) Delete(imageCache *ImageCache) {
|
||||||
|
|
||||||
db := this.context.DB.Delete(&imageCache)
|
db := CONTEXT.DB.Delete(&imageCache)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
this.deleteFileAndDir(imageCache)
|
this.deleteFileAndDir(imageCache)
|
||||||
@ -179,11 +179,11 @@ func (this *ImageCacheDao) DeleteByMatterUuid(matterUuid string) {
|
|||||||
|
|
||||||
//查询出即将删除的图片缓存
|
//查询出即将删除的图片缓存
|
||||||
var imageCaches []*ImageCache
|
var imageCaches []*ImageCache
|
||||||
db := this.context.DB.Where(wp.Query, wp.Args).Find(&imageCaches)
|
db := CONTEXT.DB.Where(wp.Query, wp.Args).Find(&imageCaches)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
//删除文件记录
|
//删除文件记录
|
||||||
db = this.context.DB.Where(wp.Query, wp.Args).Delete(ImageCache{})
|
db = CONTEXT.DB.Where(wp.Query, wp.Args).Delete(ImageCache{})
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
//删除文件实体
|
//删除文件实体
|
||||||
|
@ -18,15 +18,15 @@ type ImageCacheService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *ImageCacheService) Init(context *Context) {
|
func (this *ImageCacheService) Init() {
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.imageCacheDao)
|
b := CONTEXT.GetBean(this.imageCacheDao)
|
||||||
if b, ok := b.(*ImageCacheDao); ok {
|
if b, ok := b.(*ImageCacheDao); ok {
|
||||||
this.imageCacheDao = b
|
this.imageCacheDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.userDao)
|
b = CONTEXT.GetBean(this.userDao)
|
||||||
if b, ok := b.(*UserDao); ok {
|
if b, ok := b.(*UserDao); ok {
|
||||||
this.userDao = b
|
this.userDao = b
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,21 @@ type MatterController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *MatterController) Init(context *Context) {
|
func (this *MatterController) Init() {
|
||||||
this.BaseController.Init(context)
|
this.BaseController.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.matterDao)
|
b := CONTEXT.GetBean(this.matterDao)
|
||||||
if b, ok := b.(*MatterDao); ok {
|
if b, ok := b.(*MatterDao); ok {
|
||||||
this.matterDao = b
|
this.matterDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.matterService)
|
b = CONTEXT.GetBean(this.matterService)
|
||||||
if b, ok := b.(*MatterService); ok {
|
if b, ok := b.(*MatterService); ok {
|
||||||
this.matterService = b
|
this.matterService = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.downloadTokenDao)
|
b = CONTEXT.GetBean(this.downloadTokenDao)
|
||||||
if b, ok := b.(*DownloadTokenDao); ok {
|
if b, ok := b.(*DownloadTokenDao); ok {
|
||||||
this.downloadTokenDao = b
|
this.downloadTokenDao = b
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ type MatterDao struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *MatterDao) Init(context *Context) {
|
func (this *MatterDao) Init() {
|
||||||
this.BaseDao.Init(context)
|
this.BaseDao.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.imageCacheDao)
|
b := CONTEXT.GetBean(this.imageCacheDao)
|
||||||
if b, ok := b.(*ImageCacheDao); ok {
|
if b, ok := b.(*ImageCacheDao); ok {
|
||||||
this.imageCacheDao = b
|
this.imageCacheDao = b
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ func (this *MatterDao) FindByUuid(uuid string) *Matter {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var matter Matter
|
var matter Matter
|
||||||
db := this.context.DB.Where(&Matter{Base: Base{Uuid: uuid}}).First(&matter)
|
db := CONTEXT.DB.Where(&Matter{Base: Base{Uuid: uuid}}).First(&matter)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ func (this *MatterDao) CheckByUuid(uuid string) *Matter {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var matter Matter
|
var matter Matter
|
||||||
db := this.context.DB.Where(&Matter{Base: Base{Uuid: uuid}}).First(&matter)
|
db := CONTEXT.DB.Where(&Matter{Base: Base{Uuid: uuid}}).First(&matter)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return &matter
|
return &matter
|
||||||
@ -70,7 +70,7 @@ func (this *MatterDao) FindByUserUuidAndPuuidAndNameAndDirTrue(userUuid string,
|
|||||||
wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{1}})
|
wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{1}})
|
||||||
|
|
||||||
var matter = &Matter{}
|
var matter = &Matter{}
|
||||||
db := this.context.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
|
db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
|
||||||
|
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -84,7 +84,7 @@ func (this *MatterDao) CheckByUuidAndUserUuid(uuid string, userUuid string) *Mat
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var matter = &Matter{}
|
var matter = &Matter{}
|
||||||
db := this.context.DB.Where(&Matter{Base: Base{Uuid: uuid}, UserUuid: userUuid}).First(matter)
|
db := CONTEXT.DB.Where(&Matter{Base: Base{Uuid: uuid}, UserUuid: userUuid}).First(matter)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return matter
|
return matter
|
||||||
@ -113,7 +113,7 @@ func (this *MatterDao) CountByUserUuidAndPuuidAndDirAndName(userUuid string, puu
|
|||||||
|
|
||||||
wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{dir}})
|
wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{dir}})
|
||||||
|
|
||||||
db := this.context.DB.
|
db := CONTEXT.DB.
|
||||||
Model(&matter).
|
Model(&matter).
|
||||||
Where(wp.Query, wp.Args...).
|
Where(wp.Query, wp.Args...).
|
||||||
Count(&count)
|
Count(&count)
|
||||||
@ -127,7 +127,7 @@ func (this *MatterDao) ListByUserUuidAndPuuidAndDirAndName(userUuid string, puui
|
|||||||
|
|
||||||
var matters []*Matter
|
var matters []*Matter
|
||||||
|
|
||||||
db := this.context.DB.
|
db := CONTEXT.DB.
|
||||||
Where(Matter{UserUuid: userUuid, Puuid: puuid, Dir: dir, Name: name}).
|
Where(Matter{UserUuid: userUuid, Puuid: puuid, Dir: dir, Name: name}).
|
||||||
Find(&matters)
|
Find(&matters)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
@ -139,7 +139,7 @@ func (this *MatterDao) ListByUserUuidAndPuuidAndDirAndName(userUuid string, puui
|
|||||||
func (this *MatterDao) List(puuid string, userUuid string, sortArray []OrderPair) []*Matter {
|
func (this *MatterDao) List(puuid string, userUuid string, sortArray []OrderPair) []*Matter {
|
||||||
var matters []*Matter
|
var matters []*Matter
|
||||||
|
|
||||||
db := this.context.DB.Where(Matter{UserUuid: userUuid, Puuid: puuid}).Order(this.GetSortString(sortArray)).Find(&matters)
|
db := CONTEXT.DB.Where(Matter{UserUuid: userUuid, Puuid: puuid}).Order(this.GetSortString(sortArray)).Find(&matters)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return matters
|
return matters
|
||||||
@ -176,9 +176,9 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin
|
|||||||
orWp = orWp.Or(&WherePair{Query: "name LIKE ?", Args: []interface{}{"%." + v}})
|
orWp = orWp.Or(&WherePair{Query: "name LIKE ?", Args: []interface{}{"%." + v}})
|
||||||
}
|
}
|
||||||
|
|
||||||
conditionDB = this.context.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).Where(orWp.Query, orWp.Args...)
|
conditionDB = CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).Where(orWp.Query, orWp.Args...)
|
||||||
} else {
|
} else {
|
||||||
conditionDB = this.context.DB.Model(&Matter{}).Where(wp.Query, wp.Args...)
|
conditionDB = CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
@ -200,7 +200,7 @@ func (this *MatterDao) Create(matter *Matter) *Matter {
|
|||||||
matter.Uuid = string(timeUUID.String())
|
matter.Uuid = string(timeUUID.String())
|
||||||
matter.CreateTime = time.Now()
|
matter.CreateTime = time.Now()
|
||||||
matter.UpdateTime = time.Now()
|
matter.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Create(matter)
|
db := CONTEXT.DB.Create(matter)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return matter
|
return matter
|
||||||
@ -210,7 +210,7 @@ func (this *MatterDao) Create(matter *Matter) *Matter {
|
|||||||
func (this *MatterDao) Save(matter *Matter) *Matter {
|
func (this *MatterDao) Save(matter *Matter) *Matter {
|
||||||
|
|
||||||
matter.UpdateTime = time.Now()
|
matter.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Save(matter)
|
db := CONTEXT.DB.Save(matter)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return matter
|
return matter
|
||||||
@ -228,12 +228,12 @@ func (this *MatterDao) Delete(matter *Matter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//删除文件夹本身
|
//删除文件夹本身
|
||||||
db := this.context.DB.Delete(&matter)
|
db := CONTEXT.DB.Delete(&matter)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//删除数据库中文件记录
|
//删除数据库中文件记录
|
||||||
db := this.context.DB.Delete(&matter)
|
db := CONTEXT.DB.Delete(&matter)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
//删除对应的缓存图片。
|
//删除对应的缓存图片。
|
||||||
|
@ -23,15 +23,15 @@ type MatterService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *MatterService) Init(context *Context) {
|
func (this *MatterService) Init() {
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.matterDao)
|
b := CONTEXT.GetBean(this.matterDao)
|
||||||
if b, ok := b.(*MatterDao); ok {
|
if b, ok := b.(*MatterDao); ok {
|
||||||
this.matterDao = b
|
this.matterDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.userDao)
|
b = CONTEXT.GetBean(this.userDao)
|
||||||
if b, ok := b.(*UserDao); ok {
|
if b, ok := b.(*UserDao); ok {
|
||||||
this.userDao = b
|
this.userDao = b
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,16 @@ type PreferenceController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *PreferenceController) Init(context *Context) {
|
func (this *PreferenceController) Init() {
|
||||||
this.BaseController.Init(context)
|
this.BaseController.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.preferenceDao)
|
b := CONTEXT.GetBean(this.preferenceDao)
|
||||||
if b, ok := b.(*PreferenceDao); ok {
|
if b, ok := b.(*PreferenceDao); ok {
|
||||||
this.preferenceDao = b
|
this.preferenceDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.preferenceService)
|
b = CONTEXT.GetBean(this.preferenceService)
|
||||||
if b, ok := b.(*PreferenceService); ok {
|
if b, ok := b.(*PreferenceService); ok {
|
||||||
this.preferenceService = b
|
this.preferenceService = b
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ func (this *PreferenceDao) Fetch() *Preference {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var preference = &Preference{}
|
var preference = &Preference{}
|
||||||
db := this.context.DB.First(preference)
|
db := CONTEXT.DB.First(preference)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
|
|
||||||
if db.Error.Error() == "record not found" {
|
if db.Error.Error() == "record not found" {
|
||||||
@ -39,7 +39,7 @@ func (this *PreferenceDao) Create(preference *Preference) *Preference {
|
|||||||
preference.Uuid = string(timeUUID.String())
|
preference.Uuid = string(timeUUID.String())
|
||||||
preference.CreateTime = time.Now()
|
preference.CreateTime = time.Now()
|
||||||
preference.UpdateTime = time.Now()
|
preference.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Create(preference)
|
db := CONTEXT.DB.Create(preference)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return preference
|
return preference
|
||||||
@ -49,7 +49,7 @@ func (this *PreferenceDao) Create(preference *Preference) *Preference {
|
|||||||
func (this *PreferenceDao) Save(preference *Preference) *Preference {
|
func (this *PreferenceDao) Save(preference *Preference) *Preference {
|
||||||
|
|
||||||
preference.UpdateTime = time.Now()
|
preference.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Save(preference)
|
db := CONTEXT.DB.Save(preference)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return preference
|
return preference
|
||||||
|
@ -7,10 +7,10 @@ type PreferenceService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *PreferenceService) Init(context *Context) {
|
func (this *PreferenceService) Init() {
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.preferenceDao)
|
b := CONTEXT.GetBean(this.preferenceDao)
|
||||||
if b, ok := b.(*PreferenceDao); ok {
|
if b, ok := b.(*PreferenceDao); ok {
|
||||||
this.preferenceDao = b
|
this.preferenceDao = b
|
||||||
}
|
}
|
||||||
|
@ -12,27 +12,25 @@ import (
|
|||||||
|
|
||||||
//用于处理所有前来的请求
|
//用于处理所有前来的请求
|
||||||
type Router struct {
|
type Router struct {
|
||||||
context *Context
|
|
||||||
userService *UserService
|
userService *UserService
|
||||||
routeMap map[string]func(writer http.ResponseWriter, request *http.Request)
|
routeMap map[string]func(writer http.ResponseWriter, request *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
//构造方法
|
//构造方法
|
||||||
func NewRouter(context *Context) *Router {
|
func NewRouter() *Router {
|
||||||
router := &Router{
|
router := &Router{
|
||||||
context: context,
|
|
||||||
routeMap: make(map[string]func(writer http.ResponseWriter, request *http.Request)),
|
routeMap: make(map[string]func(writer http.ResponseWriter, request *http.Request)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//装载userService.
|
//装载userService.
|
||||||
b := context.GetBean(router.userService)
|
b := CONTEXT.GetBean(router.userService)
|
||||||
if b, ok := b.(*UserService); ok {
|
if b, ok := b.(*UserService); ok {
|
||||||
router.userService = b
|
router.userService = b
|
||||||
}
|
}
|
||||||
|
|
||||||
//将Controller中的路由规则装载机进来
|
//将Controller中的路由规则装载机进来
|
||||||
for _, controller := range context.ControllerMap {
|
for _, controller := range CONTEXT.ControllerMap {
|
||||||
routes := controller.RegisterRoutes()
|
routes := controller.RegisterRoutes()
|
||||||
for k, v := range routes {
|
for k, v := range routes {
|
||||||
router.routeMap[k] = v
|
router.routeMap[k] = v
|
||||||
@ -90,7 +88,7 @@ func (this *Router) GlobalPanicHandler(writer http.ResponseWriter, request *http
|
|||||||
func (this *Router) logSecurityVisit(writer http.ResponseWriter, request *http.Request) {
|
func (this *Router) logSecurityVisit(writer http.ResponseWriter, request *http.Request) {
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
var securityVisitDao *SecurityVisitDao
|
var securityVisitDao *SecurityVisitDao
|
||||||
b := this.context.GetBean(securityVisitDao)
|
b := CONTEXT.GetBean(securityVisitDao)
|
||||||
if b, ok := b.(*SecurityVisitDao); ok {
|
if b, ok := b.(*SecurityVisitDao); ok {
|
||||||
securityVisitDao = b
|
securityVisitDao = b
|
||||||
}
|
}
|
||||||
@ -158,7 +156,7 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
|
|||||||
} else {
|
} else {
|
||||||
//直接将请求扔给每个controller,看看他们能不能处理,如果都不能处理,那就算了。
|
//直接将请求扔给每个controller,看看他们能不能处理,如果都不能处理,那就算了。
|
||||||
canHandle := false
|
canHandle := false
|
||||||
for _, controller := range this.context.ControllerMap {
|
for _, controller := range CONTEXT.ControllerMap {
|
||||||
if handler, exist := controller.HandleRoutes(writer, request); exist {
|
if handler, exist := controller.HandleRoutes(writer, request); exist {
|
||||||
canHandle = true
|
canHandle = true
|
||||||
|
|
||||||
|
@ -12,16 +12,16 @@ type SecurityVisitController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *SecurityVisitController) Init(context *Context) {
|
func (this *SecurityVisitController) Init() {
|
||||||
this.BaseController.Init(context)
|
this.BaseController.Init()
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.securityVisitDao)
|
b := CONTEXT.GetBean(this.securityVisitDao)
|
||||||
if b, ok := b.(*SecurityVisitDao); ok {
|
if b, ok := b.(*SecurityVisitDao); ok {
|
||||||
this.securityVisitDao = b
|
this.securityVisitDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.securityVisitService)
|
b = CONTEXT.GetBean(this.securityVisitService)
|
||||||
if b, ok := b.(*SecurityVisitService); ok {
|
if b, ok := b.(*SecurityVisitService); ok {
|
||||||
this.securityVisitService = b
|
this.securityVisitService = b
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ func (this *SecurityVisitDao) FindByUuid(uuid string) *SecurityVisit {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var securityVisit SecurityVisit
|
var securityVisit SecurityVisit
|
||||||
db := this.context.DB.Where(&SecurityVisit{Base: Base{Uuid: uuid}}).First(&securityVisit)
|
db := CONTEXT.DB.Where(&SecurityVisit{Base: Base{Uuid: uuid}}).First(&securityVisit)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func (this *SecurityVisitDao) CheckByUuid(uuid string) *SecurityVisit {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var securityVisit SecurityVisit
|
var securityVisit SecurityVisit
|
||||||
db := this.context.DB.Where(&SecurityVisit{Base: Base{Uuid: uuid}}).First(&securityVisit)
|
db := CONTEXT.DB.Where(&SecurityVisit{Base: Base{Uuid: uuid}}).First(&securityVisit)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return &securityVisit
|
return &securityVisit
|
||||||
@ -45,7 +45,7 @@ func (this *SecurityVisitDao) Page(page int, pageSize int, userUuid string, sort
|
|||||||
}
|
}
|
||||||
|
|
||||||
var conditionDB *gorm.DB
|
var conditionDB *gorm.DB
|
||||||
conditionDB = this.context.DB.Model(&SecurityVisit{}).Where(wp.Query, wp.Args...)
|
conditionDB = CONTEXT.DB.Model(&SecurityVisit{}).Where(wp.Query, wp.Args...)
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
db := conditionDB.Count(&count)
|
db := conditionDB.Count(&count)
|
||||||
@ -66,7 +66,7 @@ func (this *SecurityVisitDao) Create(securityVisit *SecurityVisit) *SecurityVisi
|
|||||||
securityVisit.Uuid = string(timeUUID.String())
|
securityVisit.Uuid = string(timeUUID.String())
|
||||||
securityVisit.CreateTime = time.Now()
|
securityVisit.CreateTime = time.Now()
|
||||||
securityVisit.UpdateTime = time.Now()
|
securityVisit.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Create(securityVisit)
|
db := CONTEXT.DB.Create(securityVisit)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return securityVisit
|
return securityVisit
|
||||||
@ -76,7 +76,7 @@ func (this *SecurityVisitDao) Create(securityVisit *SecurityVisit) *SecurityVisi
|
|||||||
func (this *SecurityVisitDao) Save(securityVisit *SecurityVisit) *SecurityVisit {
|
func (this *SecurityVisitDao) Save(securityVisit *SecurityVisit) *SecurityVisit {
|
||||||
|
|
||||||
securityVisit.UpdateTime = time.Now()
|
securityVisit.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Save(securityVisit)
|
db := CONTEXT.DB.Save(securityVisit)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return securityVisit
|
return securityVisit
|
||||||
@ -85,6 +85,6 @@ func (this *SecurityVisitDao) Save(securityVisit *SecurityVisit) *SecurityVisit
|
|||||||
//删除一条记录
|
//删除一条记录
|
||||||
func (this *SecurityVisitDao) Delete(securityVisit *SecurityVisit) {
|
func (this *SecurityVisitDao) Delete(securityVisit *SecurityVisit) {
|
||||||
|
|
||||||
db := this.context.DB.Delete(&securityVisit)
|
db := CONTEXT.DB.Delete(&securityVisit)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,15 @@ type SecurityVisitService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *SecurityVisitService) Init(context *Context) {
|
func (this *SecurityVisitService) Init() {
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.securityVisitDao)
|
b := CONTEXT.GetBean(this.securityVisitDao)
|
||||||
if b, ok := b.(*SecurityVisitDao); ok {
|
if b, ok := b.(*SecurityVisitDao); ok {
|
||||||
this.securityVisitDao = b
|
this.securityVisitDao = b
|
||||||
}
|
}
|
||||||
|
|
||||||
b = context.GetBean(this.userDao)
|
b = CONTEXT.GetBean(this.userDao)
|
||||||
if b, ok := b.(*UserDao); ok {
|
if b, ok := b.(*UserDao); ok {
|
||||||
this.userDao = b
|
this.userDao = b
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ type SessionDao struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构造函数
|
//构造函数
|
||||||
func NewSessionDao(context *Context) *SessionDao {
|
func NewSessionDao() *SessionDao {
|
||||||
|
|
||||||
var sessionDao = &SessionDao{}
|
var sessionDao = &SessionDao{}
|
||||||
sessionDao.Init(context)
|
sessionDao.Init()
|
||||||
return sessionDao
|
return sessionDao
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ func (this *SessionDao) FindByUuid(uuid string) *Session {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var session = &Session{}
|
var session = &Session{}
|
||||||
db := this.context.DB.Where(&Session{Base: Base{Uuid: uuid}}).First(session)
|
db := CONTEXT.DB.Where(&Session{Base: Base{Uuid: uuid}}).First(session)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func (this *SessionDao) CheckByUuid(uuid string) *Session {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var session = &Session{}
|
var session = &Session{}
|
||||||
db := this.context.DB.Where(&Session{Base: Base{Uuid: uuid}}).First(session)
|
db := CONTEXT.DB.Where(&Session{Base: Base{Uuid: uuid}}).First(session)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ func (this *SessionDao) CheckByUuid(uuid string) *Session {
|
|||||||
func (this *SessionDao) FindByAuthentication(authentication string) *Session {
|
func (this *SessionDao) FindByAuthentication(authentication string) *Session {
|
||||||
|
|
||||||
var session = &Session{}
|
var session = &Session{}
|
||||||
db := this.context.DB.Where(&Session{Authentication: authentication}).First(session)
|
db := CONTEXT.DB.Where(&Session{Authentication: authentication}).First(session)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ func (this *SessionDao) Create(session *Session) *Session {
|
|||||||
|
|
||||||
timeUUID, _ := uuid.NewV4()
|
timeUUID, _ := uuid.NewV4()
|
||||||
session.Uuid = string(timeUUID.String())
|
session.Uuid = string(timeUUID.String())
|
||||||
db := this.context.DB.Create(session)
|
db := CONTEXT.DB.Create(session)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return session
|
return session
|
||||||
@ -68,7 +68,7 @@ func (this *SessionDao) Delete(uuid string) {
|
|||||||
session := this.CheckByUuid(uuid)
|
session := this.CheckByUuid(uuid)
|
||||||
|
|
||||||
session.ExpireTime = time.Now()
|
session.ExpireTime = time.Now()
|
||||||
db := this.context.DB.Delete(session)
|
db := CONTEXT.DB.Delete(session)
|
||||||
|
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ func (this *UploadTokenDao) FindByUuid(uuid string) *UploadToken {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var uploadToken = &UploadToken{}
|
var uploadToken = &UploadToken{}
|
||||||
db := this.context.DB.Where(&UploadToken{Base: Base{Uuid: uuid}}).First(uploadToken)
|
db := CONTEXT.DB.Where(&UploadToken{Base: Base{Uuid: uuid}}).First(uploadToken)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ func (this *UploadTokenDao) Create(uploadToken *UploadToken) *UploadToken {
|
|||||||
uploadToken.CreateTime = time.Now()
|
uploadToken.CreateTime = time.Now()
|
||||||
uploadToken.UpdateTime = time.Now()
|
uploadToken.UpdateTime = time.Now()
|
||||||
|
|
||||||
db := this.context.DB.Create(uploadToken)
|
db := CONTEXT.DB.Create(uploadToken)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return uploadToken
|
return uploadToken
|
||||||
@ -43,7 +43,7 @@ func (this *UploadTokenDao) Create(uploadToken *UploadToken) *UploadToken {
|
|||||||
func (this *UploadTokenDao) Save(uploadToken *UploadToken) *UploadToken {
|
func (this *UploadTokenDao) Save(uploadToken *UploadToken) *UploadToken {
|
||||||
|
|
||||||
uploadToken.UpdateTime = time.Now()
|
uploadToken.UpdateTime = time.Now()
|
||||||
db := this.context.DB.Save(uploadToken)
|
db := CONTEXT.DB.Save(uploadToken)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return uploadToken
|
return uploadToken
|
||||||
|
@ -13,8 +13,8 @@ type UserController struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *UserController) Init(context *Context) {
|
func (this *UserController) Init() {
|
||||||
this.BaseController.Init(context)
|
this.BaseController.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册自己的路由。
|
//注册自己的路由。
|
||||||
|
@ -24,7 +24,7 @@ func (this *UserDao) Create(user *User) *User {
|
|||||||
user.LastTime = time.Now()
|
user.LastTime = time.Now()
|
||||||
user.Sort = time.Now().UnixNano() / 1e6
|
user.Sort = time.Now().UnixNano() / 1e6
|
||||||
|
|
||||||
db := this.context.DB.Create(user)
|
db := CONTEXT.DB.Create(user)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
return user
|
return user
|
||||||
@ -35,7 +35,7 @@ func (this *UserDao) FindByUuid(uuid string) *User {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var user *User = &User{}
|
var user *User = &User{}
|
||||||
db := this.context.DB.Where(&User{Base: Base{Uuid: uuid}}).First(user)
|
db := CONTEXT.DB.Where(&User{Base: Base{Uuid: uuid}}).First(user)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func (this *UserDao) CheckByUuid(uuid string) *User {
|
|||||||
|
|
||||||
// Read
|
// Read
|
||||||
var user *User = &User{}
|
var user *User = &User{}
|
||||||
db := this.context.DB.Where(&User{Base: Base{Uuid: uuid}}).First(user)
|
db := CONTEXT.DB.Where(&User{Base: Base{Uuid: uuid}}).First(user)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func (this *UserDao) CheckByUuid(uuid string) *User {
|
|||||||
func (this *UserDao) FindByEmail(email string) *User {
|
func (this *UserDao) FindByEmail(email string) *User {
|
||||||
|
|
||||||
var user *User = &User{}
|
var user *User = &User{}
|
||||||
db := this.context.DB.Where(&User{Email: email}).First(user)
|
db := CONTEXT.DB.Where(&User{Email: email}).First(user)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -89,15 +89,15 @@ func (this *UserDao) Page(page int, pageSize int, username string, email string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
db := this.context.DB.Model(&User{}).Where(wp.Query, wp.Args...).Count(&count)
|
db := CONTEXT.DB.Model(&User{}).Where(wp.Query, wp.Args...).Count(&count)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
|
|
||||||
var users []*User
|
var users []*User
|
||||||
orderStr := this.GetSortString(sortArray)
|
orderStr := this.GetSortString(sortArray)
|
||||||
if orderStr == "" {
|
if orderStr == "" {
|
||||||
db = this.context.DB.Where(wp.Query, wp.Args...).Offset(page * pageSize).Limit(pageSize).Find(&users)
|
db = CONTEXT.DB.Where(wp.Query, wp.Args...).Offset(page * pageSize).Limit(pageSize).Find(&users)
|
||||||
} else {
|
} else {
|
||||||
db = this.context.DB.Where(wp.Query, wp.Args...).Order(orderStr).Offset(page * pageSize).Limit(pageSize).Find(&users)
|
db = CONTEXT.DB.Where(wp.Query, wp.Args...).Order(orderStr).Offset(page * pageSize).Limit(pageSize).Find(&users)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
@ -110,7 +110,7 @@ func (this *UserDao) Page(page int, pageSize int, username string, email string,
|
|||||||
//查询某个用户名是否已经有用户了
|
//查询某个用户名是否已经有用户了
|
||||||
func (this *UserDao) CountByUsername(username string) int {
|
func (this *UserDao) CountByUsername(username string) int {
|
||||||
var count int
|
var count int
|
||||||
db := this.context.DB.
|
db := CONTEXT.DB.
|
||||||
Model(&User{}).
|
Model(&User{}).
|
||||||
Where("username = ?", username).
|
Where("username = ?", username).
|
||||||
Count(&count)
|
Count(&count)
|
||||||
@ -121,7 +121,7 @@ func (this *UserDao) CountByUsername(username string) int {
|
|||||||
//查询某个邮箱是否已经有用户了
|
//查询某个邮箱是否已经有用户了
|
||||||
func (this *UserDao) CountByEmail(email string) int {
|
func (this *UserDao) CountByEmail(email string) int {
|
||||||
var count int
|
var count int
|
||||||
db := this.context.DB.
|
db := CONTEXT.DB.
|
||||||
Model(&User{}).
|
Model(&User{}).
|
||||||
Where("email = ?", email).
|
Where("email = ?", email).
|
||||||
Count(&count)
|
Count(&count)
|
||||||
@ -133,7 +133,7 @@ func (this *UserDao) CountByEmail(email string) int {
|
|||||||
func (this *UserDao) Save(user *User) *User {
|
func (this *UserDao) Save(user *User) *User {
|
||||||
|
|
||||||
user.UpdateTime = time.Now()
|
user.UpdateTime = time.Now()
|
||||||
db := this.context.DB.
|
db := CONTEXT.DB.
|
||||||
Save(user)
|
Save(user)
|
||||||
this.PanicError(db.Error)
|
this.PanicError(db.Error)
|
||||||
return user
|
return user
|
||||||
|
@ -11,10 +11,10 @@ type UserService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//初始化方法
|
//初始化方法
|
||||||
func (this *UserService) Init(context *Context) {
|
func (this *UserService) Init() {
|
||||||
|
|
||||||
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
//手动装填本实例的Bean. 这里必须要用中间变量方可。
|
||||||
b := context.GetBean(this.userDao)
|
b := CONTEXT.GetBean(this.userDao)
|
||||||
if b, ok := b.(*UserDao); ok {
|
if b, ok := b.(*UserDao); ok {
|
||||||
this.userDao = b
|
this.userDao = b
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user