优化全局变量
This commit is contained in:
parent
6dbdeb7145
commit
c44203b176
10
main.go
10
main.go
|
@ -2,14 +2,12 @@ package main
|
|||
|
||||
// init函数执行顺序自上而下, 最后执行main包里面的init函数
|
||||
import (
|
||||
"cutego/modules"
|
||||
_ "cutego/modules/core/dao"
|
||||
_ "cutego/modules/core/job"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/config"
|
||||
_ "cutego/pkg/cronjob"
|
||||
"cutego/pkg/middleware/logger"
|
||||
_ "cutego/pkg/gin"
|
||||
"cutego/pkg/util"
|
||||
"cutego/refs"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
@ -17,9 +15,7 @@ import (
|
|||
func main() {
|
||||
//go testChangeJob()
|
||||
gin.SetMode(util.IF(config.AppEnvConfig.Server.RunMode == "", "debug", config.AppEnvConfig.Server.RunMode).(string))
|
||||
r := modules.Init()
|
||||
r.Use(logger.LoggerToFile())
|
||||
err := r.Run(fmt.Sprintf(":%d", config.AppEnvConfig.Server.Port))
|
||||
err := refs.CoolGin.Run(fmt.Sprintf(":%d", config.AppEnvConfig.Server.Port))
|
||||
if err != nil {
|
||||
common.FatalfLog("Start server: %+v", err)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/constant"
|
||||
"cutego/pkg/page"
|
||||
"cutego/refs"
|
||||
"github.com/druidcaesa/gotool"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
@ -18,9 +19,9 @@ func (d ConfigDao) sql(session *xorm.Session) *xorm.Session {
|
|||
}
|
||||
|
||||
// SelectByConfigKey 根据键名查询参数配置信息
|
||||
func (d ConfigDao) SelectByConfigKey(configKey string) *dataobject.SysConfig {
|
||||
config := dataobject.SysConfig{}
|
||||
_, err := d.sql(modules.SqlDB.NewSession()).Where("config_key = ?", configKey).Get(&config)
|
||||
func (d ConfigDao) SelectByConfigKey(configKey string) *entity.SysConfig {
|
||||
config := entity.SysConfig{}
|
||||
_, err := d.sql(refs.SqlDB.NewSession()).Where("config_key = ?", configKey).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -29,9 +30,9 @@ func (d ConfigDao) SelectByConfigKey(configKey string) *dataobject.SysConfig {
|
|||
}
|
||||
|
||||
// SelectPage 分页查询数据
|
||||
func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]dataobject.SysConfig, int64) {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]entity.SysConfig, int64) {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
if gotool.StrUtils.HasNotEmpty(query.ConfigName) {
|
||||
session.And("config_name like concat('%', ?, '%')", query.ConfigName)
|
||||
}
|
||||
|
@ -57,8 +58,8 @@ func (d ConfigDao) SelectPage(query request.ConfigQuery) (*[]dataobject.SysConfi
|
|||
}
|
||||
|
||||
// CheckConfigKeyUnique 校验是否存在
|
||||
func (d ConfigDao) CheckConfigKeyUnique(config dataobject.SysConfig) int64 {
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d ConfigDao) CheckConfigKeyUnique(config entity.SysConfig) int64 {
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
if config.ConfigId > 0 {
|
||||
session.Where("config_id != ?", config.ConfigId)
|
||||
}
|
||||
|
@ -71,8 +72,8 @@ func (d ConfigDao) CheckConfigKeyUnique(config dataobject.SysConfig) int64 {
|
|||
}
|
||||
|
||||
// Insert 添加数据
|
||||
func (d ConfigDao) Insert(config dataobject.SysConfig) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d ConfigDao) Insert(config entity.SysConfig) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&config)
|
||||
if err != nil {
|
||||
|
@ -85,9 +86,9 @@ func (d ConfigDao) Insert(config dataobject.SysConfig) int64 {
|
|||
}
|
||||
|
||||
// SelectById 查询数据
|
||||
func (d ConfigDao) SelectById(id int64) *dataobject.SysConfig {
|
||||
config := dataobject.SysConfig{}
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d ConfigDao) SelectById(id int64) *entity.SysConfig {
|
||||
config := entity.SysConfig{}
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
_, err := session.Where("config_id = ?", id).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -97,8 +98,8 @@ func (d ConfigDao) SelectById(id int64) *dataobject.SysConfig {
|
|||
}
|
||||
|
||||
// Update 修改数据
|
||||
func (d ConfigDao) Update(config dataobject.SysConfig) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d ConfigDao) Update(config entity.SysConfig) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("config_id = ?", config.ConfigId).Update(&config)
|
||||
if err != nil {
|
||||
|
@ -111,9 +112,9 @@ func (d ConfigDao) Update(config dataobject.SysConfig) int64 {
|
|||
}
|
||||
|
||||
// CheckConfigByIds 根据id集合查询
|
||||
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)
|
||||
func (d ConfigDao) CheckConfigByIds(list []int64) *[]entity.SysConfig {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
err := d.sql(refs.SqlDB.NewSession()).In("config_id", list).Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -123,9 +124,9 @@ func (d ConfigDao) CheckConfigByIds(list []int64) *[]dataobject.SysConfig {
|
|||
|
||||
// Remove 删除数据
|
||||
func (d ConfigDao) Delete(list []int64) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.In("config_id", list).Delete(&dataobject.SysConfig{})
|
||||
_, err := session.In("config_id", list).Delete(&entity.SysConfig{})
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
session.Rollback()
|
||||
|
@ -136,9 +137,9 @@ func (d ConfigDao) Delete(list []int64) bool {
|
|||
}
|
||||
|
||||
// SelectAll 查询所有数据
|
||||
func (d ConfigDao) SelectAll() *[]dataobject.SysConfig {
|
||||
configs := make([]dataobject.SysConfig, 0)
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d ConfigDao) SelectAll() *[]entity.SysConfig {
|
||||
configs := make([]entity.SysConfig, 0)
|
||||
session := refs.SqlDB.NewSession()
|
||||
err := session.Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -146,3 +147,25 @@ func (d ConfigDao) SelectAll() *[]dataobject.SysConfig {
|
|||
}
|
||||
return &configs
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 查询配置数据存入到缓存中
|
||||
configDao := new(ConfigDao)
|
||||
configSession := configDao.sql(refs.SqlDB.NewSession())
|
||||
configs := make([]*entity.SysConfig, 0)
|
||||
err := configSession.Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return
|
||||
}
|
||||
for _, sysConfig := range configs {
|
||||
refs.RedisDB.SET(constant.RedisConst{}.GetRedisConfigKey()+sysConfig.ConfigKey, common.StructToJson(map[string]interface{}{
|
||||
"configId": sysConfig.ConfigId,
|
||||
"configName": sysConfig.ConfigName,
|
||||
"configKey": sysConfig.ConfigKey,
|
||||
"configValue": sysConfig.ConfigValue,
|
||||
"configType": sysConfig.ConfigType,
|
||||
"remark": sysConfig.Remark,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
@ -18,9 +18,9 @@ func (d CronJobDao) sql(session *xorm.Session) *xorm.Session {
|
|||
}
|
||||
|
||||
// SelectPage 分页查询数据
|
||||
func (d CronJobDao) SelectPage(query request.CronJobQuery) ([]dataobject.SysCronJob, int64) {
|
||||
configs := make([]dataobject.SysCronJob, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d CronJobDao) SelectPage(query request.CronJobQuery) ([]entity.SysCronJob, int64) {
|
||||
configs := make([]entity.SysCronJob, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
if gotool.StrUtils.HasNotEmpty(query.JobName) {
|
||||
session.And("job_name like concat('%', ?, '%')", query.JobName)
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ func (d CronJobDao) SelectPage(query request.CronJobQuery) ([]dataobject.SysCron
|
|||
}
|
||||
|
||||
// Insert 添加数据
|
||||
func (d CronJobDao) Insert(config dataobject.SysCronJob) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d CronJobDao) Insert(config entity.SysCronJob) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&config)
|
||||
if err != nil {
|
||||
|
@ -51,9 +51,9 @@ func (d CronJobDao) Insert(config dataobject.SysCronJob) int64 {
|
|||
}
|
||||
|
||||
// SelectById 查询数据
|
||||
func (d CronJobDao) SelectById(id int64) *dataobject.SysCronJob {
|
||||
config := dataobject.SysCronJob{}
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d CronJobDao) SelectById(id int64) *entity.SysCronJob {
|
||||
config := entity.SysCronJob{}
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
_, err := session.Where("job_id = ?", id).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -63,8 +63,8 @@ func (d CronJobDao) SelectById(id int64) *dataobject.SysCronJob {
|
|||
}
|
||||
|
||||
// Update 修改数据
|
||||
func (d CronJobDao) Update(config dataobject.SysCronJob) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d CronJobDao) Update(config entity.SysCronJob) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("job_id = ?", config.JobId).Update(&config)
|
||||
if err != nil {
|
||||
|
@ -78,9 +78,9 @@ func (d CronJobDao) Update(config dataobject.SysCronJob) int64 {
|
|||
|
||||
// Delete 删除数据
|
||||
func (d CronJobDao) Delete(list []int64) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.In("job_id", list).Delete(&dataobject.SysCronJob{})
|
||||
_, err := session.In("job_id", list).Delete(&entity.SysCronJob{})
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
session.Rollback()
|
||||
|
@ -91,9 +91,9 @@ func (d CronJobDao) Delete(list []int64) bool {
|
|||
}
|
||||
|
||||
// SelectByFuncAlias 通过方法别名获取任务详情
|
||||
func (d CronJobDao) SelectByFuncAlias(funcAlias string) *dataobject.SysCronJob {
|
||||
config := dataobject.SysCronJob{}
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d CronJobDao) SelectByFuncAlias(funcAlias string) *entity.SysCronJob {
|
||||
config := entity.SysCronJob{}
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
_, err := session.Where("func_alias = ?", funcAlias).Get(&config)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -103,9 +103,9 @@ func (d CronJobDao) SelectByFuncAlias(funcAlias string) *dataobject.SysCronJob {
|
|||
}
|
||||
|
||||
// SelectAll 查找所有启用状态的任务
|
||||
func (d CronJobDao) SelectAll() ([]dataobject.SysCronJob, int) {
|
||||
configs := make([]dataobject.SysCronJob, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d CronJobDao) SelectAll() ([]entity.SysCronJob, int) {
|
||||
configs := make([]entity.SysCronJob, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
err := session.Where("status = ?", 1).Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/refs"
|
||||
"github.com/druidcaesa/gotool"
|
||||
)
|
||||
|
||||
|
@ -12,9 +12,9 @@ type DeptDao struct {
|
|||
}
|
||||
|
||||
// SelectTree 根据条件查询部门集合
|
||||
func (d DeptDao) SelectTree(query request.DeptQuery) *[]dataobject.SysDept {
|
||||
depts := make([]dataobject.SysDept, 0)
|
||||
session := modules.SqlDB.NewSession().Where("del_flag = '0'")
|
||||
func (d DeptDao) SelectTree(query request.DeptQuery) *[]entity.SysDept {
|
||||
depts := make([]entity.SysDept, 0)
|
||||
session := refs.SqlDB.NewSession().Where("del_flag = '0'")
|
||||
if query.ParentId > 0 {
|
||||
session.And("parent_id = ?", query.ParentId)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func (d DeptDao) SelectTree(query request.DeptQuery) *[]dataobject.SysDept {
|
|||
// SelectDeptListByRoleId 根据角色ID查询部门树信息
|
||||
func (d DeptDao) SelectDeptListByRoleId(id int64, strictly bool) *[]int64 {
|
||||
list := make([]int64, 0)
|
||||
session := modules.SqlDB.NewSession().Table([]string{"sys_dept", "d"}).Cols("d.dept_id")
|
||||
session := refs.SqlDB.NewSession().Table([]string{"sys_dept", "d"}).Cols("d.dept_id")
|
||||
session.Join("LEFT", []string{"sys_role_dept", "rd"}, "d.dept_id = rd.dept_id").
|
||||
Where("rd.role_id = ?", id)
|
||||
if strictly {
|
||||
|
@ -50,9 +50,9 @@ func (d DeptDao) SelectDeptListByRoleId(id int64, strictly bool) *[]int64 {
|
|||
}
|
||||
|
||||
// GetList 查询部门列表
|
||||
func (d DeptDao) GetList(query request.DeptQuery) *[]dataobject.SysDept {
|
||||
list := make([]dataobject.SysDept, 0)
|
||||
session := modules.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
|
||||
func (d DeptDao) GetList(query request.DeptQuery) *[]entity.SysDept {
|
||||
list := make([]entity.SysDept, 0)
|
||||
session := refs.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
|
||||
session.Where("del_flag = '0'")
|
||||
if query.ParentId > 0 {
|
||||
session.And("parent_id = ?", query.ParentId)
|
||||
|
@ -72,9 +72,9 @@ func (d DeptDao) GetList(query request.DeptQuery) *[]dataobject.SysDept {
|
|||
}
|
||||
|
||||
// SelectDeptById 根据部门编号获取详细信息
|
||||
func (d DeptDao) SelectDeptById(id int) *dataobject.SysDept {
|
||||
dept := dataobject.SysDept{}
|
||||
_, err := modules.SqlDB.NewSession().Where("dept_id = ?", id).Get(&dept)
|
||||
func (d DeptDao) SelectDeptById(id int) *entity.SysDept {
|
||||
dept := entity.SysDept{}
|
||||
_, err := refs.SqlDB.NewSession().Where("dept_id = ?", id).Get(&dept)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -83,8 +83,8 @@ func (d DeptDao) SelectDeptById(id int) *dataobject.SysDept {
|
|||
}
|
||||
|
||||
// Insert 添加部门数据
|
||||
func (d DeptDao) Insert(dept dataobject.SysDept) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d DeptDao) Insert(dept entity.SysDept) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&dept)
|
||||
if err != nil {
|
||||
|
@ -97,8 +97,8 @@ func (d DeptDao) Insert(dept dataobject.SysDept) int64 {
|
|||
}
|
||||
|
||||
// CheckDeptNameUnique 校验部门名称是否唯一
|
||||
func (d DeptDao) CheckDeptNameUnique(dept dataobject.SysDept) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d DeptDao) CheckDeptNameUnique(dept entity.SysDept) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
count, err := session.Table("sys_dept").Cols("dept_id").Where("dept_name=?", dept.DeptName).And("parent_id = ?", dept.ParentId).Limit(1).Count()
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -110,24 +110,24 @@ func (d DeptDao) CheckDeptNameUnique(dept dataobject.SysDept) int64 {
|
|||
|
||||
// HasChildByDeptId 是否存在部门子节点
|
||||
func (d DeptDao) HasChildByDeptId(id int) int64 {
|
||||
count, _ := modules.SqlDB.NewSession().Table("sys_dept").Cols("dept_id").Where("parent_id = ?", id).
|
||||
count, _ := refs.SqlDB.NewSession().Table("sys_dept").Cols("dept_id").Where("parent_id = ?", id).
|
||||
And("del_flag = '0'").Limit(1).Count()
|
||||
return count
|
||||
}
|
||||
|
||||
// CheckDeptExistUser 查询部门是否存在用户
|
||||
func (d DeptDao) CheckDeptExistUser(id int) int64 {
|
||||
count, _ := modules.SqlDB.NewSession().Table("sys_user").Cols("user_id").Where("dept_id = ?", id).
|
||||
count, _ := refs.SqlDB.NewSession().Table("sys_user").Cols("user_id").Where("dept_id = ?", id).
|
||||
And("del_flag = '0'").Count()
|
||||
return count
|
||||
}
|
||||
|
||||
// Delete 删除部门
|
||||
func (d DeptDao) Delete(id int) int64 {
|
||||
dept := dataobject.SysDept{
|
||||
dept := entity.SysDept{
|
||||
DeptId: id,
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
i, err := session.Where("dept_id = ?", id).Delete(&dept)
|
||||
if err != nil {
|
||||
|
@ -140,8 +140,8 @@ func (d DeptDao) Delete(id int) int64 {
|
|||
}
|
||||
|
||||
// Update 更新部门
|
||||
func (d DeptDao) Update(dept dataobject.SysDept) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d DeptDao) Update(dept entity.SysDept) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("dept_id = ?", dept.DeptId).Update(&dept)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/constant"
|
||||
"cutego/pkg/page"
|
||||
"cutego/refs"
|
||||
"github.com/druidcaesa/gotool"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
@ -19,10 +20,10 @@ func (d *DictDataDao) sql(session *xorm.Session) *xorm.Session {
|
|||
|
||||
// SelectByDictType 根据字典类型查询字典数据
|
||||
// @Param dictType string 字典类型
|
||||
// @Return []dataobject.SysDictData
|
||||
func (d *DictDataDao) SelectByDictType(dictType string) []dataobject.SysDictData {
|
||||
data := make([]dataobject.SysDictData, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
// @Return []entity.SysDictData
|
||||
func (d *DictDataDao) SelectByDictType(dictType string) []entity.SysDictData {
|
||||
data := make([]entity.SysDictData, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
err := session.Where("status = '0' ").And("dict_type = ?", dictType).OrderBy("dict_sort").Asc("dict_sort").
|
||||
Find(&data)
|
||||
if err != nil {
|
||||
|
@ -33,10 +34,10 @@ func (d *DictDataDao) SelectByDictType(dictType string) []dataobject.SysDictData
|
|||
}
|
||||
|
||||
// GetDiceDataAll 查询所有字典数据
|
||||
// @Return *[]dataobject.SysDictData
|
||||
func (d DictDataDao) GetDiceDataAll() *[]dataobject.SysDictData {
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
data := make([]dataobject.SysDictData, 0)
|
||||
// @Return *[]entity.SysDictData
|
||||
func (d DictDataDao) GetDiceDataAll() *[]entity.SysDictData {
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
data := make([]entity.SysDictData, 0)
|
||||
err := session.Where("status = '0' ").OrderBy("dict_sort").Asc("dict_sort").
|
||||
Find(&data)
|
||||
if err != nil {
|
||||
|
@ -48,11 +49,11 @@ func (d DictDataDao) GetDiceDataAll() *[]dataobject.SysDictData {
|
|||
|
||||
// SelectPage 查询集合数据
|
||||
// @Param query request.DiceDataQuery
|
||||
// @Return *[]dataobject.SysDictData
|
||||
// @Return *[]entity.SysDictData
|
||||
// @Return 总行数
|
||||
func (d *DictDataDao) SelectPage(query request.DiceDataQuery) (*[]dataobject.SysDictData, int64) {
|
||||
list := make([]dataobject.SysDictData, 0)
|
||||
session := modules.SqlDB.NewSession().Table("sys_dict_data").OrderBy("dict_sort").Asc("dict_sort")
|
||||
func (d *DictDataDao) SelectPage(query request.DiceDataQuery) (*[]entity.SysDictData, int64) {
|
||||
list := make([]entity.SysDictData, 0)
|
||||
session := refs.SqlDB.NewSession().Table("sys_dict_data").OrderBy("dict_sort").Asc("dict_sort")
|
||||
if gotool.StrUtils.HasNotEmpty(query.DictType) {
|
||||
session.And("dict_type = ?", query.DictType)
|
||||
}
|
||||
|
@ -73,10 +74,10 @@ func (d *DictDataDao) SelectPage(query request.DiceDataQuery) (*[]dataobject.Sys
|
|||
|
||||
// SelectByDictCode 根据dictCode查询字典数据
|
||||
// @Param dictCode int64
|
||||
// @Return *dataobject.SysDictData
|
||||
func (d *DictDataDao) SelectByDictCode(dictCode int64) *dataobject.SysDictData {
|
||||
data := dataobject.SysDictData{}
|
||||
session := modules.SqlDB.NewSession()
|
||||
// @Return *entity.SysDictData
|
||||
func (d *DictDataDao) SelectByDictCode(dictCode int64) *entity.SysDictData {
|
||||
data := entity.SysDictData{}
|
||||
session := refs.SqlDB.NewSession()
|
||||
_, err := session.Where("dict_code = ?", dictCode).Get(&data)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -86,10 +87,10 @@ func (d *DictDataDao) SelectByDictCode(dictCode int64) *dataobject.SysDictData {
|
|||
}
|
||||
|
||||
// Insert 添加字典数据
|
||||
// @Param data dataobject.SysDictData
|
||||
// @Param data entity.SysDictData
|
||||
// @Return 新增的行数
|
||||
func (d *DictDataDao) Insert(data dataobject.SysDictData) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d *DictDataDao) Insert(data entity.SysDictData) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&data)
|
||||
if err != nil {
|
||||
|
@ -103,9 +104,9 @@ func (d *DictDataDao) Insert(data dataobject.SysDictData) int64 {
|
|||
|
||||
// Delete 删除字典数据
|
||||
func (d *DictDataDao) Delete(codes []int64) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.In("dict_code", codes).Delete(&dataobject.SysDictData{})
|
||||
_, err := session.In("dict_code", codes).Delete(&entity.SysDictData{})
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
session.Rollback()
|
||||
|
@ -116,8 +117,8 @@ func (d *DictDataDao) Delete(codes []int64) bool {
|
|||
}
|
||||
|
||||
// 修改字典数据
|
||||
func (d *DictDataDao) Update(data dataobject.SysDictData) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d *DictDataDao) Update(data entity.SysDictData) bool {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Where("dict_code = ?", data.DictCode).Update(&data)
|
||||
if err != nil {
|
||||
|
@ -128,3 +129,28 @@ func (d *DictDataDao) Update(data dataobject.SysDictData) bool {
|
|||
session.Commit()
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 查询字典类型数据
|
||||
dictTypeDao := new(DictTypeDao)
|
||||
typeAll := dictTypeDao.SelectAll()
|
||||
// 所有字典数据
|
||||
d := new(DictDataDao)
|
||||
listData := d.GetDiceDataAll()
|
||||
for _, dictType := range typeAll {
|
||||
dictData := make([]map[string]interface{}, 0)
|
||||
for _, data := range *listData {
|
||||
if dictType.DictType == data.DictType {
|
||||
dictData = append(dictData, map[string]interface{}{
|
||||
"dictCode": data.DictCode,
|
||||
"dictSort": data.DictSort,
|
||||
"dictLabel": data.DictLabel,
|
||||
"dictValue": data.DictValue,
|
||||
"isDefault": data.IsDefault,
|
||||
"remark": data.Remark,
|
||||
})
|
||||
}
|
||||
}
|
||||
refs.RedisDB.SET(constant.RedisConst{}.GetRedisDictKey()+dictType.DictType, common.StructToJson(dictData))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
@ -18,9 +18,9 @@ func (d DictTypeDao) sql(session *xorm.Session) *xorm.Session {
|
|||
}
|
||||
|
||||
// SelectAll 查询所有字典类型数据
|
||||
func (d DictTypeDao) SelectAll() []*dataobject.SysDictType {
|
||||
types := make([]*dataobject.SysDictType, 0)
|
||||
err := d.sql(modules.SqlDB.NewSession()).Where("status = '0'").Find(&types)
|
||||
func (d DictTypeDao) SelectAll() []*entity.SysDictType {
|
||||
types := make([]*entity.SysDictType, 0)
|
||||
err := d.sql(refs.SqlDB.NewSession()).Where("status = '0'").Find(&types)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -29,9 +29,9 @@ func (d DictTypeDao) SelectAll() []*dataobject.SysDictType {
|
|||
}
|
||||
|
||||
// SelectPage 分页查询字典类型数据
|
||||
func (d DictTypeDao) SelectPage(query request.DictTypeQuery) (*[]dataobject.SysDictType, int64) {
|
||||
list := make([]dataobject.SysDictType, 0)
|
||||
session := modules.SqlDB.NewSession().Table("sys_dict_type")
|
||||
func (d DictTypeDao) SelectPage(query request.DictTypeQuery) (*[]entity.SysDictType, int64) {
|
||||
list := make([]entity.SysDictType, 0)
|
||||
session := refs.SqlDB.NewSession().Table("sys_dict_type")
|
||||
if gotool.StrUtils.HasNotEmpty(query.DictName) {
|
||||
session.And("dict_name like concat('%', ?, '%')", query.DictName)
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ func (d DictTypeDao) SelectPage(query request.DictTypeQuery) (*[]dataobject.SysD
|
|||
}
|
||||
|
||||
// SelectById 根据id查询字典类型数据
|
||||
func (d DictTypeDao) SelectById(id int64) *dataobject.SysDictType {
|
||||
dictType := dataobject.SysDictType{}
|
||||
_, err := modules.SqlDB.NewSession().Where("dict_id = ?", id).Get(&dictType)
|
||||
func (d DictTypeDao) SelectById(id int64) *entity.SysDictType {
|
||||
dictType := entity.SysDictType{}
|
||||
_, err := refs.SqlDB.NewSession().Where("dict_id = ?", id).Get(&dictType)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -68,8 +68,8 @@ func (d DictTypeDao) SelectById(id int64) *dataobject.SysDictType {
|
|||
}
|
||||
|
||||
// CheckDictTypeUnique 检验字典类型是否存在
|
||||
func (d DictTypeDao) CheckDictTypeUnique(dictType dataobject.SysDictType) int64 {
|
||||
session := modules.SqlDB.NewSession().Table("sys_dict_type")
|
||||
func (d DictTypeDao) CheckDictTypeUnique(dictType entity.SysDictType) int64 {
|
||||
session := refs.SqlDB.NewSession().Table("sys_dict_type")
|
||||
if dictType.DictId > 0 {
|
||||
session.And("dict_id != ?", dictType.DictId)
|
||||
}
|
||||
|
@ -82,8 +82,8 @@ func (d DictTypeDao) CheckDictTypeUnique(dictType dataobject.SysDictType) int64
|
|||
}
|
||||
|
||||
// Update 修改字典
|
||||
func (d DictTypeDao) Update(dictType dataobject.SysDictType) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d DictTypeDao) Update(dictType entity.SysDictType) bool {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Where("dict_id = ?", dictType.DictId).Update(&dictType)
|
||||
if err != nil {
|
||||
|
@ -96,8 +96,8 @@ func (d DictTypeDao) Update(dictType dataobject.SysDictType) bool {
|
|||
}
|
||||
|
||||
// Insert 新增字典类型
|
||||
func (d DictTypeDao) Insert(dictType dataobject.SysDictType) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d DictTypeDao) Insert(dictType entity.SysDictType) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&dictType)
|
||||
if err != nil {
|
||||
|
@ -111,9 +111,9 @@ func (d DictTypeDao) Insert(dictType dataobject.SysDictType) int64 {
|
|||
|
||||
// Delete 批量删除
|
||||
func (d DictTypeDao) Delete(ids []int64) bool {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.In("dict_id", ids).Delete(dataobject.SysDictType{})
|
||||
_, err := session.In("dict_id", ids).Delete(entity.SysDictType{})
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
common.ErrorLog(err)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
@ -18,9 +18,9 @@ func (d LogDao) sql(session *xorm.Session) *xorm.Session {
|
|||
}
|
||||
|
||||
// SelectPage 分页查询数据
|
||||
func (d LogDao) SelectPage(query request.LogQuery) ([]dataobject.SysLog, int64) {
|
||||
configs := make([]dataobject.SysLog, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d LogDao) SelectPage(query request.LogQuery) ([]entity.SysLog, int64) {
|
||||
configs := make([]entity.SysLog, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
if gotool.StrUtils.HasNotEmpty(query.Content) {
|
||||
session.And("content like concat('%', ?, '%')", query.Content)
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ func (d LogDao) SelectPage(query request.LogQuery) ([]dataobject.SysLog, int64)
|
|||
}
|
||||
|
||||
// Insert 添加数据
|
||||
func (d LogDao) Insert(config dataobject.SysLog) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d LogDao) Insert(config entity.SysLog) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&config)
|
||||
if err != nil {
|
||||
|
|
|
@ -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/go-xorm/xorm"
|
||||
)
|
||||
|
||||
|
@ -18,9 +18,9 @@ func (d LoginInfoDao) sql(session *xorm.Session) *xorm.Session {
|
|||
}
|
||||
|
||||
// SelectPage 分页查询数据
|
||||
func (d LoginInfoDao) SelectPage(query request.LoginInfoQuery) (*[]dataobject.SysLoginInfo, int64) {
|
||||
loginInfos := make([]dataobject.SysLoginInfo, 0)
|
||||
session := d.sql(modules.SqlDB.NewSession())
|
||||
func (d LoginInfoDao) SelectPage(query request.LoginInfoQuery) (*[]entity.SysLoginInfo, int64) {
|
||||
loginInfos := make([]entity.SysLoginInfo, 0)
|
||||
session := d.sql(refs.SqlDB.NewSession())
|
||||
session.And("user_name = ?", query.UserName)
|
||||
total, _ := page.GetTotal(session.Clone())
|
||||
err := session.Limit(query.PageSize, page.StartSize(query.PageNum, query.PageSize)).Find(&loginInfos)
|
||||
|
@ -32,8 +32,8 @@ func (d LoginInfoDao) SelectPage(query request.LoginInfoQuery) (*[]dataobject.Sy
|
|||
}
|
||||
|
||||
// Insert 添加登录记录
|
||||
func (d LoginInfoDao) Insert(body dataobject.SysLoginInfo) *dataobject.SysLoginInfo {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d LoginInfoDao) Insert(body entity.SysLoginInfo) *entity.SysLoginInfo {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Table("sys_login_info").Insert(&body)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/refs"
|
||||
"github.com/druidcaesa/gotool"
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,7 @@ type MenuDao struct {
|
|||
// GetMenuPermission 根据用户ID查询权限
|
||||
func (d MenuDao) GetMenuPermission(id int64) *[]string {
|
||||
var perms []string
|
||||
session := modules.SqlDB.Table([]string{"sys_menu", "m"})
|
||||
session := refs.SqlDB.Table([]string{"sys_menu", "m"})
|
||||
err := session.Distinct("m.perms").
|
||||
Join("LEFT", []string{"sys_role_menu", "rm"}, "m.menu_id = rm.menu_id").
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "rm.role_id = ur.role_id").
|
||||
|
@ -28,9 +28,9 @@ func (d MenuDao) GetMenuPermission(id int64) *[]string {
|
|||
}
|
||||
|
||||
// GetMenuAll 查询所有菜单数据
|
||||
func (d MenuDao) GetMenuAll() *[]dataobject.SysMenu {
|
||||
menus := make([]dataobject.SysMenu, 0)
|
||||
session := modules.SqlDB.Table([]string{dataobject.SysMenu{}.TableName(), "m"})
|
||||
func (d MenuDao) GetMenuAll() *[]entity.SysMenu {
|
||||
menus := make([]entity.SysMenu, 0)
|
||||
session := refs.SqlDB.Table([]string{entity.SysMenu{}.TableName(), "m"})
|
||||
err := session.Distinct("m.menu_id").Cols("m.parent_id", "m.menu_name", "m.path", "m.component", "m.visible", "m.status", "m.perms", "m.is_frame", "m.is_cache", "m.menu_type", "m.icon", "m.order_num", "m.create_time").
|
||||
Where("m.menu_type in ('M', 'C')").And("m.status = 0").OrderBy("m.parent_id").OrderBy("m.order_num").Find(&menus)
|
||||
if err != nil {
|
||||
|
@ -41,9 +41,9 @@ func (d MenuDao) GetMenuAll() *[]dataobject.SysMenu {
|
|||
}
|
||||
|
||||
// GetMenuByUserId 根据用户ID查询菜单
|
||||
func (d MenuDao) GetMenuByUserId(id int64) *[]dataobject.SysMenu {
|
||||
menus := make([]dataobject.SysMenu, 0)
|
||||
session := modules.SqlDB.Table([]string{dataobject.SysMenu{}.TableName(), "m"})
|
||||
func (d MenuDao) GetMenuByUserId(id int64) *[]entity.SysMenu {
|
||||
menus := make([]entity.SysMenu, 0)
|
||||
session := refs.SqlDB.Table([]string{entity.SysMenu{}.TableName(), "m"})
|
||||
err := session.Distinct("m.menu_id").Cols("m.parent_id", "m.menu_name", "m.path", "m.component", "m.visible", "m.status", "m.perms", "m.is_frame", "m.is_cache", "m.menu_type", "m.icon", "m.order_num", "m.create_time").
|
||||
Join("LEFT", []string{"sys_role_menu", "rm"}, "m.menu_id = rm.menu_id").
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "rm.role_id = ur.role_id").
|
||||
|
@ -60,7 +60,7 @@ func (d MenuDao) GetMenuByUserId(id int64) *[]dataobject.SysMenu {
|
|||
// SelectMenuByRoleId 根据角色ID查询菜单树信息
|
||||
func (d MenuDao) SelectMenuByRoleId(id int64, strictly bool) *[]int64 {
|
||||
list := make([]int64, 0)
|
||||
session := modules.SqlDB.NewSession().Table([]string{"sys_menu", "m"})
|
||||
session := refs.SqlDB.NewSession().Table([]string{"sys_menu", "m"})
|
||||
session.Join("LEFT", []string{"sys_role_menu", "rm"}, "m.menu_id = rm.menu_id")
|
||||
session.Where("rm.role_id = ?", id)
|
||||
if strictly {
|
||||
|
@ -75,9 +75,9 @@ func (d MenuDao) SelectMenuByRoleId(id int64, strictly bool) *[]int64 {
|
|||
}
|
||||
|
||||
// SelectMenuList 查询系统菜单列表
|
||||
func (d MenuDao) SelectMenuList(query request.MenuQuery) *[]dataobject.SysMenu {
|
||||
list := make([]dataobject.SysMenu, 0)
|
||||
session := modules.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
|
||||
func (d MenuDao) SelectMenuList(query request.MenuQuery) *[]entity.SysMenu {
|
||||
list := make([]entity.SysMenu, 0)
|
||||
session := refs.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
|
||||
if gotool.StrUtils.HasNotEmpty(query.MenuName) {
|
||||
session.And("menu_name like concat('%', ?, '%')", query.MenuName)
|
||||
}
|
||||
|
@ -96,9 +96,9 @@ func (d MenuDao) SelectMenuList(query request.MenuQuery) *[]dataobject.SysMenu {
|
|||
}
|
||||
|
||||
// SelectMenuListByUserId 根据用户查询系统菜单列表
|
||||
func (d MenuDao) SelectMenuListByUserId(query request.MenuQuery) *[]dataobject.SysMenu {
|
||||
session := modules.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
|
||||
list := make([]dataobject.SysMenu, 0)
|
||||
func (d MenuDao) SelectMenuListByUserId(query request.MenuQuery) *[]entity.SysMenu {
|
||||
session := refs.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
|
||||
list := make([]entity.SysMenu, 0)
|
||||
session.Distinct("m.menu_id", "m.parent_id", "m.menu_name", "m.path", "m.component", "m.visible", "m.status", "ifnull(m.perms,'') as perms", "m.is_frame", "m.is_cache", "m.menu_type", "m.icon", "m.order_num", "m.create_time")
|
||||
session.Join("LEFT", []string{"sys_role_menu", "rm"}, "m.menu_id = rm.menu_id").
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "rm.role_id = ur.role_id").
|
||||
|
@ -122,11 +122,11 @@ func (d MenuDao) SelectMenuListByUserId(query request.MenuQuery) *[]dataobject.S
|
|||
}
|
||||
|
||||
// SelectMenuByMenuId 根据菜单ID查询信息
|
||||
func (d MenuDao) SelectMenuByMenuId(id int) *dataobject.SysMenu {
|
||||
menu := dataobject.SysMenu{
|
||||
func (d MenuDao) SelectMenuByMenuId(id int) *entity.SysMenu {
|
||||
menu := entity.SysMenu{
|
||||
MenuId: id,
|
||||
}
|
||||
_, err := modules.SqlDB.NewSession().Where("menu_id = ?", menu.MenuId).Get(&menu)
|
||||
_, err := refs.SqlDB.NewSession().Where("menu_id = ?", menu.MenuId).Get(&menu)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -135,8 +135,8 @@ func (d MenuDao) SelectMenuByMenuId(id int) *dataobject.SysMenu {
|
|||
}
|
||||
|
||||
// Insert 添加菜单数据
|
||||
func (d MenuDao) Insert(menu dataobject.SysMenu) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d MenuDao) Insert(menu entity.SysMenu) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&menu)
|
||||
if err != nil {
|
||||
|
@ -149,8 +149,8 @@ func (d MenuDao) Insert(menu dataobject.SysMenu) int64 {
|
|||
}
|
||||
|
||||
// Update 修改菜单数据
|
||||
func (d MenuDao) Update(menu dataobject.SysMenu) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d MenuDao) Update(menu entity.SysMenu) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("menu_id = ?", menu.MenuId).Update(&menu)
|
||||
if err != nil {
|
||||
|
@ -164,10 +164,10 @@ func (d MenuDao) Update(menu dataobject.SysMenu) int64 {
|
|||
|
||||
// Delete 删除菜单操作
|
||||
func (d MenuDao) Delete(id int) int64 {
|
||||
menu := dataobject.SysMenu{
|
||||
menu := entity.SysMenu{
|
||||
MenuId: id,
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
i, err := session.Delete(&menu)
|
||||
if err != nil {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -13,9 +13,9 @@ type NoticeDao struct {
|
|||
}
|
||||
|
||||
// SelectPage 查询集合
|
||||
func (d NoticeDao) SelectPage(query request.NoticeQuery) (*[]dataobject.SysNotice, int64) {
|
||||
notices := make([]dataobject.SysNotice, 0)
|
||||
session := modules.SqlDB.NewSession().Table(dataobject.SysNotice{}.TableName())
|
||||
func (d NoticeDao) SelectPage(query request.NoticeQuery) (*[]entity.SysNotice, int64) {
|
||||
notices := make([]entity.SysNotice, 0)
|
||||
session := refs.SqlDB.NewSession().Table(entity.SysNotice{}.TableName())
|
||||
if gotool.StrUtils.HasNotEmpty(query.NoticeTitle) {
|
||||
session.And("notice_title like concat('%', ?, '%')", query.NoticeTitle)
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ func (d NoticeDao) SelectPage(query request.NoticeQuery) (*[]dataobject.SysNotic
|
|||
}
|
||||
|
||||
// Insert 添加数据
|
||||
func (d NoticeDao) Insert(notice dataobject.SysNotice) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d NoticeDao) Insert(notice entity.SysNotice) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(¬ice)
|
||||
if err != nil {
|
||||
|
@ -50,9 +50,9 @@ func (d NoticeDao) Insert(notice dataobject.SysNotice) int64 {
|
|||
|
||||
// Delete 批量删除
|
||||
func (d NoticeDao) Delete(list []int64) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
i, err := session.In("notice_id", list).Delete(&dataobject.SysNotice{})
|
||||
i, err := session.In("notice_id", list).Delete(&entity.SysNotice{})
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
common.ErrorLog(err)
|
||||
|
@ -63,9 +63,9 @@ func (d NoticeDao) Delete(list []int64) int64 {
|
|||
}
|
||||
|
||||
// SelectById 查询
|
||||
func (d NoticeDao) SelectById(id int64) *dataobject.SysNotice {
|
||||
notice := dataobject.SysNotice{}
|
||||
_, err := modules.SqlDB.NewSession().Where("notice_id = ?", id).Get(¬ice)
|
||||
func (d NoticeDao) SelectById(id int64) *entity.SysNotice {
|
||||
notice := entity.SysNotice{}
|
||||
_, err := refs.SqlDB.NewSession().Where("notice_id = ?", id).Get(¬ice)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -74,8 +74,8 @@ func (d NoticeDao) SelectById(id int64) *dataobject.SysNotice {
|
|||
}
|
||||
|
||||
// Update 修改数据
|
||||
func (d NoticeDao) Update(notice dataobject.SysNotice) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d NoticeDao) Update(notice entity.SysNotice) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("notice_id = ?", notice.NoticeId).Update(¬ice)
|
||||
if err != nil {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
@ -15,7 +15,7 @@ type RoleDao struct {
|
|||
|
||||
// 角色公用sql
|
||||
func (d RoleDao) sqlSelectJoin() *xorm.Session {
|
||||
return modules.SqlDB.Table([]string{dataobject.SysRole{}.TableName(), "r"}).
|
||||
return refs.SqlDB.Table([]string{entity.SysRole{}.TableName(), "r"}).
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "ur.role_id = r.role_id").
|
||||
Join("LEFT", []string{"sys_user", "u"}, "u.user_id = ur.user_id").
|
||||
Join("LEFT", []string{"sys_dept", "d"}, "u.dept_id = d.dept_id")
|
||||
|
@ -23,14 +23,14 @@ func (d RoleDao) sqlSelectJoin() *xorm.Session {
|
|||
|
||||
// 用户角色关系查询sql
|
||||
func (d RoleDao) sqlSelectRoleAndUser() *xorm.Session {
|
||||
return modules.SqlDB.Table([]string{dataobject.SysRole{}.TableName(), "r"}).
|
||||
return refs.SqlDB.Table([]string{entity.SysRole{}.TableName(), "r"}).
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "ur.role_id = r.role_id").
|
||||
Join("LEFT", []string{"sys_user", "u"}, "u.user_id = ur.user_id")
|
||||
}
|
||||
|
||||
// SelectPage 根据条件查询角色数据
|
||||
func (d RoleDao) SelectPage(q *request.RoleQuery) ([]*dataobject.SysRole, int64) {
|
||||
roles := make([]*dataobject.SysRole, 0)
|
||||
func (d RoleDao) SelectPage(q *request.RoleQuery) ([]*entity.SysRole, int64) {
|
||||
roles := make([]*entity.SysRole, 0)
|
||||
session := d.sqlSelectJoin()
|
||||
if !gotool.StrUtils.HasEmpty(q.RoleName) {
|
||||
session.And("r.role_name like concat('%', ?, '%')", q.RoleName)
|
||||
|
@ -56,9 +56,9 @@ func (d RoleDao) SelectPage(q *request.RoleQuery) ([]*dataobject.SysRole, int64)
|
|||
}
|
||||
|
||||
// SelectAll 查询所有角色
|
||||
func (d RoleDao) SelectAll() []*dataobject.SysRole {
|
||||
func (d RoleDao) SelectAll() []*entity.SysRole {
|
||||
sql := d.sqlSelectJoin()
|
||||
roles := make([]*dataobject.SysRole, 0)
|
||||
roles := make([]*entity.SysRole, 0)
|
||||
err := sql.Find(&roles)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -91,8 +91,8 @@ func (d RoleDao) SelectRolePermissionByUserId(id int64) *[]string {
|
|||
}
|
||||
|
||||
// GetRoleListByUserId 根据用户ID查询角色
|
||||
func (d RoleDao) GetRoleListByUserId(id int64) *[]dataobject.SysRole {
|
||||
roles := make([]dataobject.SysRole, 0)
|
||||
func (d RoleDao) GetRoleListByUserId(id int64) *[]entity.SysRole {
|
||||
roles := make([]entity.SysRole, 0)
|
||||
err := d.sqlSelectJoin().Where("r.del_flag = '0'").And("ur.user_id = ?", id).Find(&roles)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -102,8 +102,8 @@ func (d RoleDao) GetRoleListByUserId(id int64) *[]dataobject.SysRole {
|
|||
}
|
||||
|
||||
// SelectRoleByRoleId 根据角色id查询角色数据
|
||||
func (d RoleDao) SelectRoleByRoleId(id int64) *dataobject.SysRole {
|
||||
role := dataobject.SysRole{}
|
||||
func (d RoleDao) SelectRoleByRoleId(id int64) *entity.SysRole {
|
||||
role := entity.SysRole{}
|
||||
_, err := d.sqlSelectJoin().Where("r.role_id = ?", id).Get(&role)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
|
@ -113,8 +113,8 @@ func (d RoleDao) SelectRoleByRoleId(id int64) *dataobject.SysRole {
|
|||
}
|
||||
|
||||
// CheckRoleNameUnique 校验角色名称是否唯一
|
||||
func (d RoleDao) CheckRoleNameUnique(role dataobject.SysRole) int64 {
|
||||
session := modules.SqlDB.Table(role.TableName()).Where("role_name = ?", role.RoleName)
|
||||
func (d RoleDao) CheckRoleNameUnique(role entity.SysRole) int64 {
|
||||
session := refs.SqlDB.Table(role.TableName()).Where("role_name = ?", role.RoleName)
|
||||
if role.RoleId > 0 {
|
||||
session.And("role_id != ?", role.RoleId)
|
||||
}
|
||||
|
@ -126,8 +126,8 @@ func (d RoleDao) CheckRoleNameUnique(role dataobject.SysRole) int64 {
|
|||
}
|
||||
|
||||
// CheckRoleKeyUnique 校验角色权限是否唯一
|
||||
func (d RoleDao) CheckRoleKeyUnique(role dataobject.SysRole) int64 {
|
||||
session := modules.SqlDB.Table(role.TableName()).Where("role_key = ?", role.RoleKey)
|
||||
func (d RoleDao) CheckRoleKeyUnique(role entity.SysRole) int64 {
|
||||
session := refs.SqlDB.Table(role.TableName()).Where("role_key = ?", role.RoleKey)
|
||||
if role.RoleId > 0 {
|
||||
session.And("role_id != ?", role.RoleId)
|
||||
}
|
||||
|
@ -139,8 +139,8 @@ func (d RoleDao) CheckRoleKeyUnique(role dataobject.SysRole) int64 {
|
|||
}
|
||||
|
||||
// Add 添加角色进入数据库操作
|
||||
func (d RoleDao) Insert(role dataobject.SysRole) dataobject.SysRole {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d RoleDao) Insert(role entity.SysRole) entity.SysRole {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Insert(&role)
|
||||
if err != nil {
|
||||
|
@ -152,8 +152,8 @@ func (d RoleDao) Insert(role dataobject.SysRole) dataobject.SysRole {
|
|||
}
|
||||
|
||||
// Update 修改数据
|
||||
func (d RoleDao) Update(role dataobject.SysRole) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d RoleDao) Update(role entity.SysRole) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("role_id = ?", role.RoleId).Update(&role)
|
||||
if err != nil {
|
||||
|
@ -166,8 +166,8 @@ func (d RoleDao) Update(role dataobject.SysRole) int64 {
|
|||
}
|
||||
|
||||
// Delete 删除角色
|
||||
func (d RoleDao) Delete(role dataobject.SysRole) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d RoleDao) Delete(role entity.SysRole) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
i, err := session.Delete(&role)
|
||||
if err != nil {
|
||||
|
@ -180,8 +180,8 @@ func (d RoleDao) Delete(role dataobject.SysRole) int64 {
|
|||
}
|
||||
|
||||
// UpdateRoleStatus 修改角色状态
|
||||
func (d RoleDao) UpdateRoleStatus(role *dataobject.SysRole) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d RoleDao) UpdateRoleStatus(role *entity.SysRole) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Where("role_id = ?", role.RoleId).Cols("status", "update_by", "update_time").Update(role)
|
||||
if err != nil {
|
||||
|
@ -194,8 +194,8 @@ func (d RoleDao) UpdateRoleStatus(role *dataobject.SysRole) int64 {
|
|||
}
|
||||
|
||||
// SelectRolesByUserName 查询角色组
|
||||
func (d RoleDao) SelectRolesByUserName(name string) *[]dataobject.SysRole {
|
||||
roles := make([]dataobject.SysRole, 0)
|
||||
func (d RoleDao) SelectRolesByUserName(name string) *[]entity.SysRole {
|
||||
roles := make([]entity.SysRole, 0)
|
||||
session := d.sqlSelectJoin()
|
||||
err := session.Where("r.del_flag = '0'").And("u.user_name = ?", name).Find(&roles)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/refs"
|
||||
)
|
||||
|
||||
type RoleMenuDao struct {
|
||||
}
|
||||
|
||||
// Insert 添加角色菜单关系
|
||||
func (d RoleMenuDao) Insert(list []dataobject.SysRoleMenu) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d RoleMenuDao) Insert(list []entity.SysRoleMenu) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&list)
|
||||
if err != nil {
|
||||
|
@ -23,11 +23,11 @@ func (d RoleMenuDao) Insert(list []dataobject.SysRoleMenu) int64 {
|
|||
}
|
||||
|
||||
// Delete 删除角色和菜单关系
|
||||
func (d RoleMenuDao) Delete(role dataobject.SysRole) {
|
||||
menu := dataobject.SysRoleMenu{
|
||||
func (d RoleMenuDao) Delete(role entity.SysRole) {
|
||||
menu := entity.SysRoleMenu{
|
||||
RoleId: role.RoleId,
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Delete(&menu)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/api/v1/response"
|
||||
"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"
|
||||
"time"
|
||||
|
@ -17,7 +17,7 @@ type UserDao struct {
|
|||
|
||||
// 查询公共sql
|
||||
func (d UserDao) sqlSelectJoin() *xorm.Session {
|
||||
return modules.SqlDB.NewSession().Table([]string{"sys_user", "u"}).
|
||||
return refs.SqlDB.NewSession().Table([]string{"sys_user", "u"}).
|
||||
Join("LEFT", []string{"sys_dept", "d"}, "u.dept_id = d.dept_id").
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "u.user_id = ur.user_id").
|
||||
Join("LEFT", []string{"sys_role", "r"}, "r.role_id = ur.role_id")
|
||||
|
@ -68,8 +68,8 @@ func (d UserDao) GetUserById(userId int64) *response.UserResponse {
|
|||
}
|
||||
|
||||
// GetUserByUserName 根据用户名查询用户数据
|
||||
func (d UserDao) GetUserByUserName(user dataobject.SysUser) *dataobject.SysUser {
|
||||
i, err := modules.SqlDB.Get(&user)
|
||||
func (d UserDao) GetUserByUserName(user entity.SysUser) *entity.SysUser {
|
||||
i, err := refs.SqlDB.Get(&user)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil
|
||||
|
@ -81,9 +81,9 @@ func (d UserDao) GetUserByUserName(user dataobject.SysUser) *dataobject.SysUser
|
|||
}
|
||||
|
||||
// CheckEmailUnique 校验邮箱是否存在
|
||||
func (d UserDao) CheckEmailUnique(user request.UserBody) *dataobject.SysUser {
|
||||
sysUser := dataobject.SysUser{}
|
||||
session := modules.SqlDB.NewSession().Table("sys_user")
|
||||
func (d UserDao) CheckEmailUnique(user request.UserBody) *entity.SysUser {
|
||||
sysUser := entity.SysUser{}
|
||||
session := refs.SqlDB.NewSession().Table("sys_user")
|
||||
session.Cols("user_id", "email")
|
||||
session.Where("email = ?", user.Email)
|
||||
if user.UserId > 0 {
|
||||
|
@ -97,9 +97,9 @@ func (d UserDao) CheckEmailUnique(user request.UserBody) *dataobject.SysUser {
|
|||
}
|
||||
|
||||
// CheckPhoneNumUnique 校验手机号是否存在
|
||||
func (d UserDao) CheckPhoneNumUnique(body request.UserBody) *dataobject.SysUser {
|
||||
sysUser := dataobject.SysUser{}
|
||||
session := modules.SqlDB.NewSession().Table("sys_user")
|
||||
func (d UserDao) CheckPhoneNumUnique(body request.UserBody) *entity.SysUser {
|
||||
sysUser := entity.SysUser{}
|
||||
session := refs.SqlDB.NewSession().Table("sys_user")
|
||||
session.Cols("user_id", "phone_num")
|
||||
session.Where("phone_num = ?", body.PhoneNumber)
|
||||
if body.UserId > 0 {
|
||||
|
@ -114,7 +114,7 @@ func (d UserDao) CheckPhoneNumUnique(body request.UserBody) *dataobject.SysUser
|
|||
|
||||
// Insert 添加用户
|
||||
func (d UserDao) Insert(body request.UserBody) *request.UserBody {
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Table("sys_user").Insert(&body)
|
||||
if err != nil {
|
||||
|
@ -127,7 +127,7 @@ func (d UserDao) Insert(body request.UserBody) *request.UserBody {
|
|||
|
||||
// Update 修改用户数据
|
||||
func (d UserDao) Update(body request.UserBody) int64 {
|
||||
session := modules.SqlDB.NewSession().Table("sys_user")
|
||||
session := refs.SqlDB.NewSession().Table("sys_user")
|
||||
session.Begin()
|
||||
_, err := session.Where("user_id = ?", body.UserId).Update(&body)
|
||||
if err != nil {
|
||||
|
@ -141,10 +141,10 @@ func (d UserDao) Update(body request.UserBody) int64 {
|
|||
|
||||
// Delete 根据id删除用户数据
|
||||
func (d UserDao) Delete(id int64) int64 {
|
||||
user := dataobject.SysUser{
|
||||
user := entity.SysUser{
|
||||
UserId: id,
|
||||
}
|
||||
session := modules.SqlDB.NewSession().Table("sys_user")
|
||||
session := refs.SqlDB.NewSession().Table("sys_user")
|
||||
session.Begin()
|
||||
i, err := session.Delete(&user)
|
||||
if err != nil {
|
||||
|
@ -157,11 +157,11 @@ func (d UserDao) Delete(id int64) int64 {
|
|||
|
||||
// ResetPwd 修改用户密码数据库操作
|
||||
func (d UserDao) ResetPwd(body request.UserBody) int64 {
|
||||
user := dataobject.SysUser{
|
||||
user := entity.SysUser{
|
||||
UserId: body.UserId,
|
||||
Password: body.Password,
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Where("user_id = ?", user.UserId).Cols("password").Update(&user)
|
||||
if err != nil {
|
||||
|
@ -176,7 +176,7 @@ func (d UserDao) ResetPwd(body request.UserBody) int64 {
|
|||
// GetAllocatedList 查询未分配用户角色列表
|
||||
func (d UserDao) GetAllocatedList(query request.UserQuery) ([]*response.UserResponse, int64) {
|
||||
resp := make([]*response.UserResponse, 0)
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Table([]string{"sys_user", "u"}).Distinct("u.user_id", "u.dept_id", "u.user_name", "u.nick_name", "u.email", "u.phone_number", "u.status", "u.create_time").
|
||||
Join("LEFT", []string{"sys_dept", "d"}, "u.dept_id = d.dept_id").
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "u.user_id = ur.user_id").
|
||||
|
@ -199,7 +199,7 @@ func (d UserDao) GetAllocatedList(query request.UserQuery) ([]*response.UserResp
|
|||
// GetUnallocatedList 查询未分配用户角色列表
|
||||
func (d UserDao) GetUnallocatedList(query request.UserQuery) ([]*response.UserResponse, int64) {
|
||||
resp := make([]*response.UserResponse, 0)
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Table([]string{"sys_user", "u"}).Distinct("u.user_id", "u.dept_id", "u.user_name", "u.nick_name", "u.email", "u.phone_number", "u.status", "u.create_time").
|
||||
Join("LEFT", []string{"sys_dept", "d"}, "u.dept_id = d.dept_id").
|
||||
Join("LEFT", []string{"sys_user_role", "ur"}, "u.user_id = ur.user_id").
|
||||
|
@ -222,10 +222,10 @@ func (d UserDao) GetUnallocatedList(query request.UserQuery) ([]*response.UserRe
|
|||
|
||||
// UpdatePwd 修改密码
|
||||
func (d UserDao) UpdatePwd(id int64, hash string) int64 {
|
||||
user := dataobject.SysUser{}
|
||||
user := entity.SysUser{}
|
||||
user.UserId = id
|
||||
user.Password = hash
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Cols("password").Where("user_id = ?", id).Update(&user)
|
||||
if err != nil {
|
||||
|
@ -239,13 +239,13 @@ func (d UserDao) UpdatePwd(id int64, hash string) int64 {
|
|||
|
||||
// UpdateAvatar 修改头像
|
||||
func (d UserDao) UpdateAvatar(info *response.UserResponse) int64 {
|
||||
user := dataobject.SysUser{
|
||||
user := entity.SysUser{
|
||||
Avatar: info.Avatar,
|
||||
UserId: info.UserId,
|
||||
UpdateBy: info.UserName,
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Cols("avatar", "update_by", "update_time").Where("user_id = ?", user.UserId).Update(&user)
|
||||
if err != nil {
|
||||
|
@ -258,13 +258,13 @@ func (d UserDao) UpdateAvatar(info *response.UserResponse) int64 {
|
|||
}
|
||||
|
||||
func (d UserDao) UpdateStatus(info request.UserBody) int64 {
|
||||
user := dataobject.SysUser{
|
||||
user := entity.SysUser{
|
||||
UserId: info.UserId,
|
||||
Status: info.Status,
|
||||
UpdateBy: info.UserName,
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
update, err := session.Cols("status", "update_by", "update_time").Where("user_id = ?", user.UserId).Update(&user)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/refs"
|
||||
)
|
||||
|
||||
type UserPostDao struct {
|
||||
}
|
||||
|
||||
// BatchInsert 批量新增用户岗位信息
|
||||
func (d UserPostDao) BatchInsert(posts []dataobject.SysUserPost) {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d UserPostDao) BatchInsert(posts []entity.SysUserPost) {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Table(dataobject.SysUserPost{}.TableName()).Insert(&posts)
|
||||
_, err := session.Table(entity.SysUserPost{}.TableName()).Insert(&posts)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
session.Rollback()
|
||||
|
@ -24,10 +24,10 @@ func (d UserPostDao) BatchInsert(posts []dataobject.SysUserPost) {
|
|||
|
||||
// Delete 删除用户和岗位关系
|
||||
func (d UserPostDao) Delete(id int64) {
|
||||
post := dataobject.SysUserPost{
|
||||
post := entity.SysUserPost{
|
||||
UserId: id,
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Delete(&post)
|
||||
if err != nil {
|
||||
|
@ -39,7 +39,7 @@ func (d UserPostDao) Delete(id int64) {
|
|||
|
||||
// CountById 通过岗位ID查询岗位使用数量
|
||||
func (d UserPostDao) CountById(id int64) int64 {
|
||||
count, err := modules.SqlDB.NewSession().Table("sys_user_post").Cols("post_id").Where("post_id = ?", id).Count()
|
||||
count, err := refs.SqlDB.NewSession().Table("sys_user_post").Cols("post_id").Where("post_id = ?", id).Count()
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return 0
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/request"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/refs"
|
||||
)
|
||||
|
||||
type UserRoleDao struct {
|
||||
}
|
||||
|
||||
// BatchInsert 批量新增用户角色信息
|
||||
func (d UserRoleDao) BatchInsert(roles []dataobject.SysUserRole) {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d UserRoleDao) BatchInsert(roles []entity.SysUserRole) {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Table(dataobject.SysUserRole{}.TableName()).Insert(&roles)
|
||||
_, err := session.Table(entity.SysUserRole{}.TableName()).Insert(&roles)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
session.Rollback()
|
||||
|
@ -25,10 +25,10 @@ func (d UserRoleDao) BatchInsert(roles []dataobject.SysUserRole) {
|
|||
|
||||
// Delete 删除用户和角色关系
|
||||
func (d UserRoleDao) Delete(id int64) {
|
||||
role := dataobject.SysUserRole{
|
||||
role := entity.SysUserRole{
|
||||
UserId: id,
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
_, err := session.Delete(&role)
|
||||
if err != nil {
|
||||
|
@ -40,8 +40,8 @@ func (d UserRoleDao) Delete(id int64) {
|
|||
}
|
||||
|
||||
// DeleteAuthUser 取消用户授权
|
||||
func (d UserRoleDao) DeleteAuthUser(role dataobject.SysUserRole) int64 {
|
||||
session := modules.SqlDB.NewSession()
|
||||
func (d UserRoleDao) DeleteAuthUser(role entity.SysUserRole) int64 {
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
i, err := session.Delete(&role)
|
||||
if err != nil {
|
||||
|
@ -56,15 +56,15 @@ func (d UserRoleDao) DeleteAuthUser(role dataobject.SysUserRole) int64 {
|
|||
// InsertAuthUsers 批量选择用户授权
|
||||
func (d UserRoleDao) InsertAuthUsers(body request.UserRoleBody) int64 {
|
||||
ids := body.UserIds
|
||||
roles := make([]dataobject.SysUserRole, 0)
|
||||
roles := make([]entity.SysUserRole, 0)
|
||||
for i := 0; i < len(ids); i++ {
|
||||
role := dataobject.SysUserRole{
|
||||
role := entity.SysUserRole{
|
||||
RoleId: body.RoleId,
|
||||
UserId: ids[i],
|
||||
}
|
||||
roles = append(roles, role)
|
||||
}
|
||||
session := modules.SqlDB.NewSession()
|
||||
session := refs.SqlDB.NewSession()
|
||||
session.Begin()
|
||||
insert, err := session.Insert(&roles)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
router "cutego/modules/core/router"
|
||||
"cutego/pkg/filter"
|
||||
"cutego/pkg/jwt"
|
||||
"cutego/pkg/middleware"
|
||||
"cutego/pkg/middleware/logger"
|
||||
"cutego/pkg/websocket"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Init() *gin.Engine {
|
||||
ginInstance := gin.New()
|
||||
ginInstance.Use(gin.Logger())
|
||||
ginInstance.Use(gin.Recovery())
|
||||
ginInstance.Use(logger.LoggerToFile())
|
||||
ginInstance.Use(middleware.Recover)
|
||||
ginInstance.Use(jwt.JWTAuth())
|
||||
ginInstance.Use(filter.DemoHandler())
|
||||
// websocket
|
||||
ginInstance.GET("/websocket", websocket.HandleWebSocketMessage)
|
||||
// v1版本api
|
||||
v1Router := ginInstance.Group("/api/v1")
|
||||
// 加载: 模块路由
|
||||
router.LoadCoreRouter(v1Router)
|
||||
return ginInstance
|
||||
}
|
116
modules/xorm.go
116
modules/xorm.go
|
@ -1,116 +0,0 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"cutego/modules/core/dao"
|
||||
models2 "cutego/modules/core/dataobject"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/config"
|
||||
"cutego/pkg/constant"
|
||||
redisTool "cutego/pkg/redispool"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-xorm/xorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// X 全局DB
|
||||
var (
|
||||
SqlDB *xorm.Engine
|
||||
RedisDB *redisTool.RedisClient
|
||||
)
|
||||
|
||||
func initDatabase() {
|
||||
var err error
|
||||
// 配置mysql数据库
|
||||
ds := config.AppEnvConfig.DataSource
|
||||
jdbc := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",
|
||||
ds.Username,
|
||||
ds.Password,
|
||||
ds.Host,
|
||||
ds.Port,
|
||||
ds.Database,
|
||||
ds.Charset)
|
||||
SqlDB, _ = xorm.NewEngine(ds.DbType, jdbc)
|
||||
if err != nil {
|
||||
common.FatalfLog("db error: %#v\n", err.Error())
|
||||
}
|
||||
err = SqlDB.Ping()
|
||||
if err != nil {
|
||||
common.FatalfLog("db connect error: %#v\n", err.Error())
|
||||
}
|
||||
SqlDB.SetMaxIdleConns(ds.MaxIdleSize)
|
||||
SqlDB.SetMaxOpenConns(ds.MaxOpenSize)
|
||||
timer := time.NewTicker(time.Minute * 30)
|
||||
go func(x *xorm.Engine) {
|
||||
for _ = range timer.C {
|
||||
err = x.Ping()
|
||||
if err != nil {
|
||||
common.FatalfLog("db connect error: %#v\n", err.Error())
|
||||
}
|
||||
}
|
||||
}(SqlDB)
|
||||
SqlDB.ShowSQL(true)
|
||||
// 开启缓存
|
||||
SqlDB.SetDefaultCacher(xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000))
|
||||
}
|
||||
func initRedis() {
|
||||
// 配置redis数据库
|
||||
RedisDB = redisTool.NewRedis()
|
||||
}
|
||||
func init() {
|
||||
initDatabase()
|
||||
initRedis()
|
||||
cacheInitDataToRedis()
|
||||
}
|
||||
|
||||
// 初始化缓存数据
|
||||
func cacheInitDataToRedis() {
|
||||
initDict()
|
||||
initConfig()
|
||||
}
|
||||
|
||||
func initDict() {
|
||||
// 查询字典类型数据
|
||||
dictTypeDao := new(dao.DictTypeDao)
|
||||
typeAll := dictTypeDao.SelectAll()
|
||||
// 所有字典数据
|
||||
d := new(dao.DictDataDao)
|
||||
listData := d.GetDiceDataAll()
|
||||
for _, dictType := range typeAll {
|
||||
dictData := make([]map[string]interface{}, 0)
|
||||
for _, data := range *listData {
|
||||
if dictType.DictType == data.DictType {
|
||||
dictData = append(dictData, map[string]interface{}{
|
||||
"dictCode": data.DictCode,
|
||||
"dictSort": data.DictSort,
|
||||
"dictLabel": data.DictLabel,
|
||||
"dictValue": data.DictValue,
|
||||
"isDefault": data.IsDefault,
|
||||
"remark": data.Remark,
|
||||
})
|
||||
}
|
||||
}
|
||||
RedisDB.SET(constant.RedisConst{}.GetRedisDictKey()+dictType.DictType, common.StructToJson(dictData))
|
||||
}
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
// 查询配置数据存入到缓存中
|
||||
configSession := SqlDB.NewSession().Table("sys_config")
|
||||
configs := make([]*models2.SysConfig, 0)
|
||||
err := configSession.Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return
|
||||
}
|
||||
for _, sysConfig := range configs {
|
||||
RedisDB.SET(constant.RedisConst{}.GetRedisConfigKey()+sysConfig.ConfigKey, common.StructToJson(map[string]interface{}{
|
||||
"configId": sysConfig.ConfigId,
|
||||
"configName": sysConfig.ConfigName,
|
||||
"configKey": sysConfig.ConfigKey,
|
||||
"configValue": sysConfig.ConfigValue,
|
||||
"configType": sysConfig.ConfigType,
|
||||
"remark": sysConfig.Remark,
|
||||
}))
|
||||
}
|
||||
}
|
|
@ -1,22 +1,22 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/constant"
|
||||
"cutego/refs"
|
||||
)
|
||||
|
||||
// RemoveList 批量根据Key删除数据
|
||||
// @Param list []string 键合集
|
||||
func RemoveList(list []string) {
|
||||
modules.RedisDB.DELALL(list)
|
||||
refs.RedisDB.DELALL(list)
|
||||
}
|
||||
|
||||
// RemoveKey 根据key删除
|
||||
// @Param key 键
|
||||
// @Return int 删除的数量
|
||||
func RemoveCache(key string) int {
|
||||
del, err := modules.RedisDB.DEL(key)
|
||||
del, err := refs.RedisDB.DEL(key)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func RemoveCache(key string) int {
|
|||
// @Param key 键
|
||||
// @Return string 值
|
||||
func GetCache(key string) string {
|
||||
val, err := modules.RedisDB.GET(key)
|
||||
val, err := refs.RedisDB.GET(key)
|
||||
if err != nil {
|
||||
common.ErrorLog(constant.RedisConst{}.GetRedisError(), err.Error())
|
||||
return ""
|
||||
|
@ -40,7 +40,7 @@ func GetCache(key string) string {
|
|||
// @Param value 值
|
||||
// @Return 新增的行数
|
||||
func SetCache(key string, value interface{}) int {
|
||||
n, err := modules.RedisDB.SET(key, common.StructToJson(value))
|
||||
n, err := refs.RedisDB.SET(key, common.StructToJson(value))
|
||||
if err != nil {
|
||||
common.ErrorLog(constant.RedisConst{}.GetRedisError(), err.Error())
|
||||
return 0
|
||||
|
@ -54,5 +54,5 @@ func SetCache(key string, value interface{}) int {
|
|||
// @Param sec 过期时间(单位: 秒)
|
||||
// @Return 新增的行数
|
||||
func SetCacheTTL(key string, value interface{}, sec int) {
|
||||
modules.RedisDB.SETEX(key, sec, common.StructToJson(value))
|
||||
refs.RedisDB.SETEX(key, sec, common.StructToJson(value))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package gin
|
||||
|
||||
import (
|
||||
"cutego/modules/core/router"
|
||||
"cutego/pkg/filter"
|
||||
"cutego/pkg/jwt"
|
||||
"cutego/pkg/middleware"
|
||||
"cutego/pkg/middleware/logger"
|
||||
"cutego/pkg/websocket"
|
||||
"cutego/refs"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Println("CoolGin init...")
|
||||
refs.CoolGin = gin.New()
|
||||
refs.CoolGin.Use(gin.Logger())
|
||||
refs.CoolGin.Use(gin.Recovery())
|
||||
refs.CoolGin.Use(logger.LoggerToFile())
|
||||
refs.CoolGin.Use(middleware.Recover)
|
||||
refs.CoolGin.Use(jwt.JWTAuth())
|
||||
refs.CoolGin.Use(filter.DemoHandler())
|
||||
// websocket
|
||||
refs.CoolGin.GET("/websocket", websocket.HandleWebSocketMessage)
|
||||
// v1版本api
|
||||
v1Router := refs.CoolGin.Group("/api/v1")
|
||||
// 加载: 模块路由
|
||||
router.LoadCoreRouter(v1Router)
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/response"
|
||||
"cutego/pkg/cache"
|
||||
"cutego/pkg/config"
|
||||
"cutego/refs"
|
||||
"errors"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -52,7 +52,7 @@ func JWTAuth() gin.HandlerFunc {
|
|||
}
|
||||
singleTag := config.AppEnvConfig.Login.Single
|
||||
if singleTag {
|
||||
token, err := modules.RedisDB.GET(claims.UserInfo.UserName)
|
||||
token, err := refs.RedisDB.GET(claims.UserInfo.UserName)
|
||||
if err == nil {
|
||||
if !(token == currentTokenStr) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"cutego/modules"
|
||||
"cutego/modules/core/api/v1/response"
|
||||
"cutego/modules/core/dataobject"
|
||||
"cutego/modules/core/entity"
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/config"
|
||||
"cutego/pkg/jwt"
|
||||
"cutego/refs"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ func CheckLockToken(c *gin.Context) bool {
|
|||
if config.AppEnvConfig.Login.Single {
|
||||
// 获取redis中的token数据
|
||||
info := GetUserInfo(c)
|
||||
get, err := modules.RedisDB.GET(info.UserName)
|
||||
get, err := refs.RedisDB.GET(info.UserName)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return false
|
||||
|
@ -49,7 +49,7 @@ func CheckLockToken(c *gin.Context) bool {
|
|||
}
|
||||
|
||||
// CheckIsAdmin 判断是否是超级管理员
|
||||
func CheckIsAdmin(user *dataobject.SysUser) bool {
|
||||
func CheckIsAdmin(user *entity.SysUser) bool {
|
||||
if user.UserId == 1 {
|
||||
return true
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package refs
|
||||
|
||||
import (
|
||||
"cutego/pkg/common"
|
||||
"cutego/pkg/config"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-xorm/xorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 配置数据库
|
||||
func init() {
|
||||
var err error
|
||||
// 配置mysql数据库
|
||||
ds := config.AppEnvConfig.DataSource
|
||||
jdbc := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",
|
||||
ds.Username,
|
||||
ds.Password,
|
||||
ds.Host,
|
||||
ds.Port,
|
||||
ds.Database,
|
||||
ds.Charset)
|
||||
SqlDB, err = xorm.NewEngine(ds.DbType, jdbc)
|
||||
if err != nil {
|
||||
common.FatalfLog("db error: %#v\n", err.Error())
|
||||
}
|
||||
err = SqlDB.Ping()
|
||||
if err != nil {
|
||||
common.FatalfLog("db connect error: %#v\n", err.Error())
|
||||
}
|
||||
SqlDB.SetMaxIdleConns(ds.MaxIdleSize)
|
||||
SqlDB.SetMaxOpenConns(ds.MaxOpenSize)
|
||||
timer := time.NewTicker(time.Minute * 30)
|
||||
go func(x *xorm.Engine) {
|
||||
for _ = range timer.C {
|
||||
err = x.Ping()
|
||||
if err != nil {
|
||||
common.FatalfLog("db connect error: %#v\n", err.Error())
|
||||
}
|
||||
}
|
||||
}(SqlDB)
|
||||
SqlDB.ShowSQL(true)
|
||||
// 开启缓存
|
||||
SqlDB.SetDefaultCacher(xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000))
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package refs
|
||||
|
||||
import (
|
||||
redisTool "cutego/pkg/redispool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// X 全局DB
|
||||
var (
|
||||
SqlDB *xorm.Engine
|
||||
RedisDB *redisTool.RedisClient
|
||||
CoolGin *gin.Engine
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
package refs
|
||||
|
||||
import redisTool "cutego/pkg/redispool"
|
||||
|
||||
// 配置redis数据库
|
||||
func init() {
|
||||
RedisDB = redisTool.NewRedis()
|
||||
}
|
Loading…
Reference in New Issue