模块标准化
This commit is contained in:
@@ -2,7 +2,7 @@ package dao
|
||||
|
||||
import (
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/constant"
|
||||
"cutego/pkg/page"
|
||||
@@ -19,8 +19,8 @@ func (d ConfigDao) sql(session *xorm.Session) *xorm.Session {
|
||||
}
|
||||
|
||||
// SelectByConfigKey 根据键名查询参数配置信息
|
||||
func (d ConfigDao) SelectByConfigKey(configKey string) *entity.SysConfig {
|
||||
config := entity.SysConfig{}
|
||||
func (d ConfigDao) SelectByConfigKey(configKey string) *dataobject.SysConfig {
|
||||
config := dataobject.SysConfig{}
|
||||
_, err := d.sql(refs.SqlDB.NewSession()).Where("config_key = ?", configKey).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
@@ -30,8 +30,8 @@ func (d ConfigDao) SelectByConfigKey(configKey string) *entity.SysConfig {
|
||||
}
|
||||
|
||||
// SelectPage 分页查询数据
|
||||
func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]entity.SysConfig, int64) {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]dataobject.SysConfig, int64) {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
if gotool.StrUtils.HasNotEmpty(query.ConfigName) {
|
||||
session.And("config_name like concat('%', ?, '%')", query.ConfigName)
|
||||
@@ -58,7 +58,7 @@ func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]entity.SysConfig, i
|
||||
}
|
||||
|
||||
// CheckConfigKeyUnique 校验是否存在
|
||||
func (d ConfigDao) CheckConfigKeyUnique(config entity.SysConfig) int64 {
|
||||
func (d ConfigDao) CheckConfigKeyUnique(config dataobject.SysConfig) int64 {
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
if config.ConfigId > 0 {
|
||||
session.Where("config_id != ?", config.ConfigId)
|
||||
@@ -72,7 +72,7 @@ func (d ConfigDao) CheckConfigKeyUnique(config entity.SysConfig) int64 {
|
||||
}
|
||||
|
||||
// Insert 添加数据
|
||||
func (d ConfigDao) Insert(config entity.SysConfig) int64 {
|
||||
func (d ConfigDao) Insert(config dataobject.SysConfig) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&config)
|
||||
@@ -86,8 +86,8 @@ func (d ConfigDao) Insert(config entity.SysConfig) int64 {
|
||||
}
|
||||
|
||||
// SelectById 查询数据
|
||||
func (d ConfigDao) SelectById(id int64) *entity.SysConfig {
|
||||
config := entity.SysConfig{}
|
||||
func (d ConfigDao) SelectById(id int64) *dataobject.SysConfig {
|
||||
config := dataobject.SysConfig{}
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
_, err := session.Where("config_id = ?", id).Get(&config)
|
||||
if err != nil {
|
||||
@@ -98,7 +98,7 @@ func (d ConfigDao) SelectById(id int64) *entity.SysConfig {
|
||||
}
|
||||
|
||||
// Update 修改数据
|
||||
func (d ConfigDao) Update(config entity.SysConfig) int64 {
|
||||
func (d ConfigDao) Update(config dataobject.SysConfig) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("config_id = ?", config.ConfigId).Update(&config)
|
||||
@@ -112,8 +112,8 @@ func (d ConfigDao) Update(config entity.SysConfig) int64 {
|
||||
}
|
||||
|
||||
// CheckConfigByIds 根据id集合查询
|
||||
func (d ConfigDao) CheckConfigByIds(list []int64) *[]entity.SysConfig {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
func (d ConfigDao) CheckConfigByIds(list []int64) *[]dataobject.SysConfig {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
err := d.sql(refs.SqlDB.NewSession()).In("config_id", list).Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
@@ -126,7 +126,7 @@ func (d ConfigDao) CheckConfigByIds(list []int64) *[]entity.SysConfig {
|
||||
func (d ConfigDao) Delete(list []int64) bool {
|
||||
session := refs.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()
|
||||
@@ -137,8 +137,8 @@ func (d ConfigDao) Delete(list []int64) bool {
|
||||
}
|
||||
|
||||
// SelectAll 查询所有数据
|
||||
func (d ConfigDao) SelectAll() *[]entity.SysConfig {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
func (d ConfigDao) SelectAll() *[]dataobject.SysConfig {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
session := refs.SqlDB.NewSession()
|
||||
err := session.Find(&configs)
|
||||
if err != nil {
|
||||
@@ -152,7 +152,7 @@ func init() {
|
||||
// 查询配置数据存入到缓存中
|
||||
configDao := new(ConfigDao)
|
||||
configSession := configDao.sql(refs.SqlDB.NewSession())
|
||||
configs := make([]*entity.SysConfig, 0)
|
||||
configs := make([]*dataobject.SysConfig, 0)
|
||||
err := configSession.Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
||||
Reference in New Issue
Block a user