优化全局变量
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/page"
|
||||
"cutego/refs"
|
||||
"github.com/druidcaesa/gotool"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
@@ -20,9 +20,9 @@ func (d PostDao) sqlSelectJoin(session *xorm.Session) *xorm.Session {
|
||||
}
|
||||
|
||||
// SelectAll 查询所有岗位数据, 数据库操作
|
||||
func (d PostDao) SelectAll() []*dataobject.SysPost {
|
||||
session := modules.SqlDB.NewSession()
|
||||
posts := make([]*dataobject.SysPost, 0)
|
||||
func (d PostDao) SelectAll() []*entity.SysPost {
|
||||
session := refs.SqlDB.NewSession()
|
||||
posts := make([]*entity.SysPost, 0)
|
||||
err := session.Find(&posts)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
@@ -34,7 +34,7 @@ func (d PostDao) SelectAll() []*dataobject.SysPost {
|
||||
// SelectPostListByUserId 根据用户id查询岗位id集合
|
||||
func (d PostDao) SelectPostListByUserId(userId int64) *[]int64 {
|
||||
var ids []int64
|
||||
selectSql := d.sqlSelectJoin(modules.SqlDB.NewSession())
|
||||
selectSql := d.sqlSelectJoin(refs.SqlDB.NewSession())
|
||||
err := selectSql.Where("u.user_id = ?", userId).Cols("p.post_id").Find(&ids)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
@@ -44,9 +44,9 @@ func (d PostDao) SelectPostListByUserId(userId int64) *[]int64 {
|
||||
}
|
||||
|
||||
// SelectPage 查询岗位分页数据
|
||||
func (d PostDao) SelectPage(query request.PostQuery) (*[]dataobject.SysPost, int64) {
|
||||
posts := make([]dataobject.SysPost, 0)
|
||||
session := modules.SqlDB.NewSession().Table(dataobject.SysPost{}.TableName())
|
||||
func (d PostDao) SelectPage(query request.PostQuery) (*[]entity.SysPost, int64) {
|
||||
posts := make([]entity.SysPost, 0)
|
||||
session := refs.SqlDB.NewSession().Table(entity.SysPost{}.TableName())
|
||||
if gotool.StrUtils.HasNotEmpty(query.PostCode) {
|
||||
session.And("post_code like concat('%', ?, '%')", query.PostCode)
|
||||
}
|
||||
@@ -66,8 +66,8 @@ func (d PostDao) SelectPage(query request.PostQuery) (*[]dataobject.SysPost, int
|
||||
}
|
||||
|
||||
// CheckPostNameUnique 校验岗位名称是否存在
|
||||
func (d PostDao) CheckPostNameUnique(post dataobject.SysPost) int64 {
|
||||
session := modules.SqlDB.NewSession().Table("sys_post").Cols("post_id").
|
||||
func (d PostDao) CheckPostNameUnique(post entity.SysPost) int64 {
|
||||
session := refs.SqlDB.NewSession().Table("sys_post").Cols("post_id").
|
||||
Where("post_name = ?", post.PostName)
|
||||
if post.PostId > 0 {
|
||||
session.And("post_id != ?", post.PostId)
|
||||
@@ -77,8 +77,8 @@ func (d PostDao) CheckPostNameUnique(post dataobject.SysPost) int64 {
|
||||
}
|
||||
|
||||
// CheckPostCodeUnique 校验岗位编码是否存在
|
||||
func (d PostDao) CheckPostCodeUnique(post dataobject.SysPost) int64 {
|
||||
session := modules.SqlDB.NewSession().Table("sys_post").Cols("post_id").
|
||||
func (d PostDao) CheckPostCodeUnique(post entity.SysPost) int64 {
|
||||
session := refs.SqlDB.NewSession().Table("sys_post").Cols("post_id").
|
||||
Where("post_code = ?", post.PostCode)
|
||||
if post.PostId > 0 {
|
||||
session.And("post_id != ?", post.PostId)
|
||||
@@ -88,8 +88,8 @@ func (d PostDao) CheckPostCodeUnique(post dataobject.SysPost) int64 {
|
||||
}
|
||||
|
||||
// Insert 添加岗位数据
|
||||
func (d PostDao) Insert(post dataobject.SysPost) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d PostDao) Insert(post entity.SysPost) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&post)
|
||||
if err != nil {
|
||||
@@ -102,8 +102,8 @@ func (d PostDao) Insert(post dataobject.SysPost) int64 {
|
||||
}
|
||||
|
||||
// GetPostById 根据id查询岗位数据
|
||||
func (d PostDao) GetPostById(post dataobject.SysPost) *dataobject.SysPost {
|
||||
_, err := modules.SqlDB.NewSession().Where("post_id = ?", post.PostId).Get(&post)
|
||||
func (d PostDao) GetPostById(post entity.SysPost) *entity.SysPost {
|
||||
_, err := refs.SqlDB.NewSession().Where("post_id = ?", post.PostId).Get(&post)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
@@ -114,9 +114,9 @@ func (d PostDao) GetPostById(post dataobject.SysPost) *dataobject.SysPost {
|
||||
// Delete 批量删除岗位
|
||||
func (d PostDao) Delete(posts []int64) int64 {
|
||||
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
i, err := session.In("post_id", posts).Delete(&dataobject.SysPost{})
|
||||
i, err := session.In("post_id", posts).Delete(&entity.SysPost{})
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
common.ErrorLog(err)
|
||||
@@ -127,8 +127,8 @@ func (d PostDao) Delete(posts []int64) int64 {
|
||||
}
|
||||
|
||||
// Update 修改岗位数据
|
||||
func (d PostDao) Update(post dataobject.SysPost) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d PostDao) Update(post entity.SysPost) bool {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Where("post_id = ?", post.PostId).Update(&post)
|
||||
if err != nil {
|
||||
@@ -140,9 +140,9 @@ func (d PostDao) Update(post dataobject.SysPost) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (d PostDao) SelectPostByUserName(name string) *[]dataobject.SysPost {
|
||||
posts := make([]dataobject.SysPost, 0)
|
||||
session := modules.SqlDB.NewSession().Table([]string{dataobject.SysPost{}.TableName(), "p"})
|
||||
func (d PostDao) SelectPostByUserName(name string) *[]entity.SysPost {
|
||||
posts := make([]entity.SysPost, 0)
|
||||
session := refs.SqlDB.NewSession().Table([]string{entity.SysPost{}.TableName(), "p"})
|
||||
err := session.Cols("p.post_id", "p.post_name", "p.post_code").
|
||||
Join("LEFT", []string{"sys_user_post", "up"}, "up.post_id = p.post_id").
|
||||
Join("LEFT", []string{"sys_user", "u"}, "u.user_id = up.user_id").Where("u.user_name = ?", name).Find(&posts)
|
||||
|
||||
Reference in New Issue
Block a user