调整xorm层级
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/page"
|
||||
"github.com/druidcaesa/gotool"
|
||||
@@ -17,9 +18,9 @@ func (d ConfigDao) sql(session *xorm.Session) *xorm.Session {
|
||||
}
|
||||
|
||||
// SelectByConfigKey 根据键名查询参数配置信息
|
||||
func (d ConfigDao) SelectByConfigKey(configKey string) *entity.SysConfig {
|
||||
config := entity.SysConfig{}
|
||||
_, err := d.sql(SqlDB.NewSession()).Where("config_key = ?", configKey).Get(&config)
|
||||
func (d ConfigDao) SelectByConfigKey(configKey string) *dataobject.SysConfig {
|
||||
config := dataobject.SysConfig{}
|
||||
_, err := d.sql(modules.SqlDB.NewSession()).Where("config_key = ?", configKey).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
@@ -28,9 +29,9 @@ func (d ConfigDao) SelectByConfigKey(configKey string) *entity.SysConfig {
|
||||
}
|
||||
|
||||
// SelectPage 分页查询数据
|
||||
func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]entity.SysConfig, int64) {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
session := d.sql(SqlDB.NewSession())
|
||||
func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]dataobject.SysConfig, int64) {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
if gotool.StrUtils.HasNotEmpty(query.ConfigName) {
|
||||
session.And("config_name like concat('%', ?, '%')", query.ConfigName)
|
||||
}
|
||||
@@ -56,8 +57,8 @@ func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]entity.SysConfig, i
|
||||
}
|
||||
|
||||
// CheckConfigKeyUnique 校验是否存在
|
||||
func (d ConfigDao) CheckConfigKeyUnique(config entity.SysConfig) int64 {
|
||||
session := d.sql(SqlDB.NewSession())
|
||||
func (d ConfigDao) CheckConfigKeyUnique(config dataobject.SysConfig) int64 {
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
if config.ConfigId > 0 {
|
||||
session.Where("config_id != ?", config.ConfigId)
|
||||
}
|
||||
@@ -70,8 +71,8 @@ func (d ConfigDao) CheckConfigKeyUnique(config entity.SysConfig) int64 {
|
||||
}
|
||||
|
||||
// Insert 添加数据
|
||||
func (d ConfigDao) Insert(config entity.SysConfig) int64 {
|
||||
session := SqlDB.NewSession()
|
||||
func (d ConfigDao) Insert(config dataobject.SysConfig) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&config)
|
||||
if err != nil {
|
||||
@@ -84,9 +85,9 @@ func (d ConfigDao) Insert(config entity.SysConfig) int64 {
|
||||
}
|
||||
|
||||
// SelectById 查询数据
|
||||
func (d ConfigDao) SelectById(id int64) *entity.SysConfig {
|
||||
config := entity.SysConfig{}
|
||||
session := d.sql(SqlDB.NewSession())
|
||||
func (d ConfigDao) SelectById(id int64) *dataobject.SysConfig {
|
||||
config := dataobject.SysConfig{}
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
_, err := session.Where("config_id = ?", id).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
@@ -96,8 +97,8 @@ func (d ConfigDao) SelectById(id int64) *entity.SysConfig {
|
||||
}
|
||||
|
||||
// Update 修改数据
|
||||
func (d ConfigDao) Update(config entity.SysConfig) int64 {
|
||||
session := SqlDB.NewSession()
|
||||
func (d ConfigDao) Update(config dataobject.SysConfig) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("config_id = ?", config.ConfigId).Update(&config)
|
||||
if err != nil {
|
||||
@@ -110,9 +111,9 @@ func (d ConfigDao) Update(config entity.SysConfig) int64 {
|
||||
}
|
||||
|
||||
// CheckConfigByIds 根据id集合查询
|
||||
func (d ConfigDao) CheckConfigByIds(list []int64) *[]entity.SysConfig {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
err := d.sql(SqlDB.NewSession()).In("config_id", list).Find(&configs)
|
||||
func (d ConfigDao) CheckConfigByIds(list []int64) *[]dataobject.SysConfig {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
err := d.sql(modules.SqlDB.NewSession()).In("config_id", list).Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
@@ -122,9 +123,9 @@ func (d ConfigDao) CheckConfigByIds(list []int64) *[]entity.SysConfig {
|
||||
|
||||
// Remove 删除数据
|
||||
func (d ConfigDao) Delete(list []int64) bool {
|
||||
session := SqlDB.NewSession()
|
||||
session := modules.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.In("config_id", list).Delete(&entity.SysConfig{})
|
||||
_, err := session.In("config_id", list).Delete(&dataobject.SysConfig{})
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
session.Rollback()
|
||||
@@ -135,9 +136,9 @@ func (d ConfigDao) Delete(list []int64) bool {
|
||||
}
|
||||
|
||||
// SelectAll 查询所有数据
|
||||
func (d ConfigDao) SelectAll() *[]entity.SysConfig {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
session := SqlDB.NewSession()
|
||||
func (d ConfigDao) SelectAll() *[]dataobject.SysConfig {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
session := modules.SqlDB.NewSession()
|
||||
err := session.Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
||||
Reference in New Issue
Block a user