调整xorm层级

This commit is contained in:
骑着蜗牛追导弹 2023-01-18 16:00:50 +08:00
parent 0f8c1f989b
commit a89c86023e
67 changed files with 500 additions and 460 deletions

View File

@ -80,7 +80,7 @@ gitee地址: https://gitee.com/odboy/cutego-ui
eg.
cutego
school
student
dataobject
dao
service
@ -88,6 +88,12 @@ cutego
router
[模块名称] entity -> dao -> service -> api -> router
```
#### SQL转换器
```text
http://www.gotool.top/handlesql/sql2xorm
```
![img.png](docs/images/sql转xorm1.png)
#### 交叉编译, 产出可执行程序

BIN
docs/images/sql转xorm1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

View File

@ -3,7 +3,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
cache2 "cutego/modules/core/cache"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
service2 "cutego/modules/core/service"
"cutego/pkg/cache"
"cutego/pkg/excels"
@ -55,7 +55,7 @@ func (a ConfigApi) List(c *gin.Context) {
// Add 添加数据
func (a ConfigApi) Add(c *gin.Context) {
config := entity.SysConfig{}
config := dataobject.SysConfig{}
if c.Bind(&config) != nil {
resp.ParamError(c)
return
@ -83,7 +83,7 @@ func (a ConfigApi) Get(c *gin.Context) {
// Edit 修改数据
func (a ConfigApi) Edit(c *gin.Context) {
config := entity.SysConfig{}
config := dataobject.SysConfig{}
if c.Bind(&config) != nil {
resp.ParamError(c)
return

View File

@ -3,7 +3,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/common"
"cutego/pkg/cronjob"
@ -42,7 +42,7 @@ func (a CronJobApi) GetById(c *gin.Context) {
// Edit 修改定时任务
func (a CronJobApi) Edit(c *gin.Context) {
record := entity.SysCronJob{}
record := dataobject.SysCronJob{}
if c.Bind(&record) != nil {
resp.ParamError(c)
return
@ -56,7 +56,7 @@ func (a CronJobApi) Edit(c *gin.Context) {
// Add 新增定时任务
func (a CronJobApi) Add(c *gin.Context) {
dto := entity.SysCronJob{}
dto := dataobject.SysCronJob{}
if c.Bind(&dto) != nil {
resp.ParamError(c)
return
@ -88,7 +88,7 @@ func (a CronJobApi) Remove(c *gin.Context) {
// ChangeStatus 改变任务状态
func (a CronJobApi) ChangeStatus(c *gin.Context) {
record := entity.SysCronJob{}
record := dataobject.SysCronJob{}
if c.Bind(&record) != nil {
resp.ParamError(c)
return

View File

@ -2,7 +2,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/resp"
"cutego/pkg/tree/tree_dept"
@ -64,7 +64,7 @@ func (a DeptApi) ExcludeChild(c *gin.Context) {
}
list := a.deptService.FindDeptList(request.DeptQuery{})
var depts = *list
deptList := make([]entity.SysDept, 0)
deptList := make([]dataobject.SysDept, 0)
for _, dept := range depts {
if dept.DeptId == deptId || strings.Contains(dept.Ancestors, strconv.Itoa(deptId)) {
continue
@ -87,7 +87,7 @@ func (a DeptApi) GetInfo(c *gin.Context) {
// Add 添加部门
func (a DeptApi) Add(c *gin.Context) {
dept := entity.SysDept{}
dept := dataobject.SysDept{}
if c.Bind(&dept) != nil {
resp.ParamError(c)
return
@ -134,7 +134,7 @@ func (a DeptApi) Delete(c *gin.Context) {
// Edit 修改部门数据接口
func (a DeptApi) Edit(c *gin.Context) {
dept := entity.SysDept{}
dept := dataobject.SysDept{}
if c.Bind(&dept) != nil {
resp.ParamError(c)
return

View File

@ -3,7 +3,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/excels"
"cutego/pkg/file"
@ -66,7 +66,7 @@ func (a DictDataApi) Get(c *gin.Context) {
// Add 添加字典数据
func (a DictDataApi) Add(c *gin.Context) {
data := entity.SysDictData{}
data := dataobject.SysDictData{}
if c.Bind(&data) != nil {
resp.ParamError(c)
return
@ -81,7 +81,7 @@ func (a DictDataApi) Add(c *gin.Context) {
// Edit 编辑字典数据
func (a DictDataApi) Edit(c *gin.Context) {
data := entity.SysDictData{}
data := dataobject.SysDictData{}
if c.Bind(&data) != nil {
resp.ParamError(c)
return

View File

@ -2,7 +2,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/cache"
"cutego/pkg/excels"
@ -43,7 +43,7 @@ func (a DictTypeApi) Get(c *gin.Context) {
// Edit 修改字典类型
func (a DictTypeApi) Edit(c *gin.Context) {
dictType := entity.SysDictType{}
dictType := dataobject.SysDictType{}
if c.Bind(&dictType) != nil {
resp.ParamError(c)
return
@ -63,7 +63,7 @@ func (a DictTypeApi) Edit(c *gin.Context) {
// Add 新增字典类型
func (a DictTypeApi) Add(c *gin.Context) {
dictType := entity.SysDictType{}
dictType := dataobject.SysDictType{}
if c.Bind(&dictType) != nil {
resp.ParamError(c)
return

View File

@ -3,7 +3,7 @@ package v1
import (
request2 "cutego/modules/core/api/v1/request"
cache2 "cutego/modules/core/cache"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/common"
"cutego/pkg/page"
@ -56,7 +56,7 @@ func (a LoginApi) handleLoginInfo(c *gin.Context, body request2.LoginBody, login
location = a.loginInfoService.GetLocationByIp(clientIp).Country
}
a.loginInfoService.Save(entity.SysLoginInfo{
a.loginInfoService.Save(dataobject.SysLoginInfo{
UserName: body.UserName,
IpAddr: clientIp,
LoginLocation: location,

View File

@ -2,7 +2,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/resp"
"cutego/pkg/tree/tree_menu"
@ -68,7 +68,7 @@ func (a MenuApi) TreeSelect(c *gin.Context) {
// Add 添加菜单数据
func (a MenuApi) Add(c *gin.Context) {
menu := entity.SysMenu{}
menu := dataobject.SysMenu{}
if c.Bind(&menu) != nil {
resp.ParamError(c, "参数绑定异常")
return
@ -82,7 +82,7 @@ func (a MenuApi) Add(c *gin.Context) {
// Edit 修改菜单数据
func (a MenuApi) Edit(c *gin.Context) {
menu := entity.SysMenu{}
menu := dataobject.SysMenu{}
if c.Bind(&menu) != nil {
resp.ParamError(c)
return

View File

@ -2,7 +2,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/page"
"cutego/pkg/resp"
@ -34,7 +34,7 @@ func (a NoticeApi) List(c *gin.Context) {
// Add 添加公告
func (a NoticeApi) Add(c *gin.Context) {
notice := entity.SysNotice{}
notice := dataobject.SysNotice{}
if c.Bind(&notice) != nil {
resp.ParamError(c)
return
@ -71,7 +71,7 @@ func (a NoticeApi) Get(c *gin.Context) {
// Edit 修改
func (a NoticeApi) Edit(c *gin.Context) {
notice := entity.SysNotice{}
notice := dataobject.SysNotice{}
if c.Bind(&notice) != nil {
resp.ParamError(c)
return

View File

@ -2,7 +2,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/excels"
"cutego/pkg/file"
@ -38,7 +38,7 @@ func (a PostApi) List(c *gin.Context) {
// Add 新增岗位
func (a PostApi) Add(c *gin.Context) {
post := entity.SysPost{}
post := dataobject.SysPost{}
if c.Bind(&post) != nil {
resp.ParamError(c)
return
@ -96,7 +96,7 @@ func (a PostApi) Delete(c *gin.Context) {
// Edit 修改岗位数据接口
func (a PostApi) Edit(c *gin.Context) {
post := entity.SysPost{}
post := dataobject.SysPost{}
if c.Bind(&post) != nil {
resp.ParamError(c)
return

View File

@ -1,38 +1,38 @@
package response
import (
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"time"
)
// UserResponse 用户实体返回结构体
type UserResponse struct {
UserId int64 `json:"userId"` // 用户ID
DeptId int64 `excel:"name=部门" json:"deptId"` // 部门ID
UserName string `excel:"name=用户登录名" json:"userName"` // 登录用户名
NickName string `excel:"name=用户昵称" json:"nickName"` // 用户昵称
Email string `excel:"name=用户邮箱" json:"email"` // 邮箱
PhoneNumber string `excel:"name=手机号" json:"phoneNumber"` // 手机号
Sex string `excel:"name=性别,format=0=男,1=女,2=未知" json:"sex"` // 性别0男1女
Avatar string `json:"avatar"` // 头像路径
Status string `json:"status"` // 状态 0正常1停用
DelFlag string `json:"delFlag"` // 0正常1删除
LoginIp string `json:"loginIp"` // 登录ip
LoginDate time.Time `json:"loginDate"` // 登录时间
CreateTime time.Time `xorm:"created" json:"createTime"` // 创建时间
CreateBy string `json:"createBy"` // 创建人
UpdateTime time.Time `json:"updateTime"` // 更新时间
UpdateBy string `json:"updateBy"` // 更新人
SysDept entity.SysDept `xorm:"extends" json:"dept"` // 部门实体
UserId int64 `json:"userId"` // 用户ID
DeptId int64 `excel:"name=部门" json:"deptId"` // 部门ID
UserName string `excel:"name=用户登录名" json:"userName"` // 登录用户名
NickName string `excel:"name=用户昵称" json:"nickName"` // 用户昵称
Email string `excel:"name=用户邮箱" json:"email"` // 邮箱
PhoneNumber string `excel:"name=手机号" json:"phoneNumber"` // 手机号
Sex string `excel:"name=性别,format=0=男,1=女,2=未知" json:"sex"` // 性别0男1女
Avatar string `json:"avatar"` // 头像路径
Status string `json:"status"` // 状态 0正常1停用
DelFlag string `json:"delFlag"` // 0正常1删除
LoginIp string `json:"loginIp"` // 登录ip
LoginDate time.Time `json:"loginDate"` // 登录时间
CreateTime time.Time `xorm:"created" json:"createTime"` // 创建时间
CreateBy string `json:"createBy"` // 创建人
UpdateTime time.Time `json:"updateTime"` // 更新时间
UpdateBy string `json:"updateBy"` // 更新人
SysDept dataobject.SysDept `xorm:"extends" json:"dept"` // 部门实体
}
// UserInfo 用户整体数据
type UserInfo struct {
User *UserResponse `json:"user,omitempty"` // 用户数据
Roles []*entity.SysRole `json:"roles,omitempty"` // 角色集合
Posts []*entity.SysPost `json:"posts,omitempty"` // 部门集合
PostIds *[]int64 `json:"postIds,omitempty"` // 岗位id集合
RoleIds *[]int64 `json:"roleIds,omitempty"` // 觉得id集合
User *UserResponse `json:"user,omitempty"` // 用户数据
Roles []*dataobject.SysRole `json:"roles,omitempty"` // 角色集合
Posts []*dataobject.SysPost `json:"posts,omitempty"` // 部门集合
PostIds *[]int64 `json:"postIds,omitempty"` // 岗位id集合
RoleIds *[]int64 `json:"roleIds,omitempty"` // 觉得id集合
}
// IsAdmin 判断当前用户是否是管理员

View File

@ -2,7 +2,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/excels"
"cutego/pkg/page"
@ -50,7 +50,7 @@ func (a RoleApi) GetRoleId(c *gin.Context) {
// Add 添加角色业务操作
func (a RoleApi) Add(c *gin.Context) {
role := entity.SysRole{}
role := dataobject.SysRole{}
if c.BindJSON(&role) == nil {
if a.roleService.CheckRoleNameUnique(role) > 0 {
c.JSON(500, resp.ErrorResp(500, "新增角色'"+role.RoleName+"'失败, 角色名称已存在"))
@ -70,7 +70,7 @@ func (a RoleApi) Add(c *gin.Context) {
// Edit 修改角色
func (a RoleApi) Edit(c *gin.Context) {
role := entity.SysRole{}
role := dataobject.SysRole{}
if c.BindJSON(&role) == nil {
if a.roleService.CheckRoleNameUnique(role) > 0 {
c.JSON(500, resp.ErrorResp(500, "修改角色'"+role.RoleName+"'失败, 角色名称已存在"))
@ -106,7 +106,7 @@ func (a RoleApi) Delete(c *gin.Context) {
// ChangeStatus 状态修改
func (a RoleApi) ChangeStatus(c *gin.Context) {
body := entity.SysRole{}
body := dataobject.SysRole{}
if c.BindJSON(&body) != nil {
c.JSON(500, resp.ErrorResp("参数绑定异常"))
return
@ -155,7 +155,7 @@ func (a RoleApi) UnallocatedList(c *gin.Context) {
// CancelAuthUser 取消授权用户
func (a RoleApi) CancelAuthUser(c *gin.Context) {
roleUser := entity.SysUserRole{}
roleUser := dataobject.SysUserRole{}
if c.BindJSON(&roleUser) != nil {
resp.Error(c)
return

View File

@ -3,7 +3,7 @@ package v1
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/modules/core/service"
"cutego/pkg/common"
"cutego/pkg/excels"
@ -53,11 +53,11 @@ func (a UserApi) GetInfo(c *gin.Context) {
parseInt, err := strconv.ParseInt(param, 10, 64)
if err == nil {
// 判断当前登录用户是否是admin
m := new(entity.SysUser)
m := new(dataobject.SysUser)
if m.IsAdmin(parseInt) {
r.Roles = roleAll
} else {
roles := make([]*entity.SysRole, 0)
roles := make([]*dataobject.SysRole, 0)
for _, role := range roleAll {
if role.RoleId != 1 {
roles = append(roles, role)
@ -74,7 +74,7 @@ func (a UserApi) GetInfo(c *gin.Context) {
}
} else {
//id为空不取管理员角色
roles := make([]*entity.SysRole, 0)
roles := make([]*dataobject.SysRole, 0)
for _, role := range roleAll {
if role.RoleId != 1 {
roles = append(roles, role)
@ -98,11 +98,11 @@ func (a UserApi) AuthRole(c *gin.Context) {
user := a.userService.GetUserById(parseInt)
// 查询角色
roles := a.roleService.GetRoleListByUserId(parseInt)
flag := entity.SysUser{}.IsAdmin(parseInt)
flag := dataobject.SysUser{}.IsAdmin(parseInt)
if flag {
m["roles"] = roles
} else {
roleList := make([]entity.SysRole, 0)
roleList := make([]dataobject.SysRole, 0)
for _, role := range *roles {
if role.RoleId != 1 {
roleList = append(roleList, role)

View File

@ -1,7 +1,7 @@
package cache
import (
models2 "cutego/modules/core/entity"
models2 "cutego/modules/core/dataobject"
"cutego/pkg/cache"
"cutego/pkg/common"
"cutego/pkg/constant"

View File

@ -1,7 +1,7 @@
package cache
import (
models2 "cutego/modules/core/entity"
models2 "cutego/modules/core/dataobject"
"cutego/pkg/cache"
"cutego/pkg/common"
"cutego/pkg/constant"

View File

@ -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)

View File

@ -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 CronJobDao) sql(session *xorm.Session) *xorm.Session {
}
// SelectPage 分页查询数据
func (d CronJobDao) SelectPage(query request.CronJobQuery) ([]entity.SysCronJob, int64) {
configs := make([]entity.SysCronJob, 0)
session := d.sql(SqlDB.NewSession())
func (d CronJobDao) SelectPage(query request.CronJobQuery) ([]dataobject.SysCronJob, int64) {
configs := make([]dataobject.SysCronJob, 0)
session := d.sql(modules.SqlDB.NewSession())
if gotool.StrUtils.HasNotEmpty(query.JobName) {
session.And("job_name like concat('%', ?, '%')", query.JobName)
}
@ -36,8 +37,8 @@ func (d CronJobDao) SelectPage(query request.CronJobQuery) ([]entity.SysCronJob,
}
// Insert 添加数据
func (d CronJobDao) Insert(config entity.SysCronJob) int64 {
session := SqlDB.NewSession()
func (d CronJobDao) Insert(config dataobject.SysCronJob) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&config)
if err != nil {
@ -50,9 +51,9 @@ func (d CronJobDao) Insert(config entity.SysCronJob) int64 {
}
// SelectById 查询数据
func (d CronJobDao) SelectById(id int64) *entity.SysCronJob {
config := entity.SysCronJob{}
session := d.sql(SqlDB.NewSession())
func (d CronJobDao) SelectById(id int64) *dataobject.SysCronJob {
config := dataobject.SysCronJob{}
session := d.sql(modules.SqlDB.NewSession())
_, err := session.Where("job_id = ?", id).Get(&config)
if err != nil {
common.ErrorLog(err)
@ -62,8 +63,8 @@ func (d CronJobDao) SelectById(id int64) *entity.SysCronJob {
}
// Update 修改数据
func (d CronJobDao) Update(config entity.SysCronJob) int64 {
session := SqlDB.NewSession()
func (d CronJobDao) Update(config dataobject.SysCronJob) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Where("job_id = ?", config.JobId).Update(&config)
if err != nil {
@ -77,9 +78,9 @@ func (d CronJobDao) Update(config entity.SysCronJob) int64 {
// Delete 删除数据
func (d CronJobDao) Delete(list []int64) bool {
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.In("job_id", list).Delete(&entity.SysCronJob{})
_, err := session.In("job_id", list).Delete(&dataobject.SysCronJob{})
if err != nil {
common.ErrorLog(err)
session.Rollback()
@ -90,9 +91,9 @@ func (d CronJobDao) Delete(list []int64) bool {
}
// SelectByFuncAlias 通过方法别名获取任务详情
func (d CronJobDao) SelectByFuncAlias(funcAlias string) *entity.SysCronJob {
config := entity.SysCronJob{}
session := d.sql(SqlDB.NewSession())
func (d CronJobDao) SelectByFuncAlias(funcAlias string) *dataobject.SysCronJob {
config := dataobject.SysCronJob{}
session := d.sql(modules.SqlDB.NewSession())
_, err := session.Where("func_alias = ?", funcAlias).Get(&config)
if err != nil {
common.ErrorLog(err)
@ -102,9 +103,9 @@ func (d CronJobDao) SelectByFuncAlias(funcAlias string) *entity.SysCronJob {
}
// SelectAll 查找所有启用状态的任务
func (d CronJobDao) SelectAll() ([]entity.SysCronJob, int) {
configs := make([]entity.SysCronJob, 0)
session := d.sql(SqlDB.NewSession())
func (d CronJobDao) SelectAll() ([]dataobject.SysCronJob, int) {
configs := make([]dataobject.SysCronJob, 0)
session := d.sql(modules.SqlDB.NewSession())
err := session.Where("status = ?", 1).Find(&configs)
if err != nil {
common.ErrorLog(err)

View File

@ -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"
"github.com/druidcaesa/gotool"
)
@ -11,9 +12,9 @@ type DeptDao struct {
}
// SelectTree 根据条件查询部门集合
func (d DeptDao) SelectTree(query request.DeptQuery) *[]entity.SysDept {
depts := make([]entity.SysDept, 0)
session := SqlDB.NewSession().Where("del_flag = '0'")
func (d DeptDao) SelectTree(query request.DeptQuery) *[]dataobject.SysDept {
depts := make([]dataobject.SysDept, 0)
session := modules.SqlDB.NewSession().Where("del_flag = '0'")
if query.ParentId > 0 {
session.And("parent_id = ?", query.ParentId)
}
@ -34,7 +35,7 @@ func (d DeptDao) SelectTree(query request.DeptQuery) *[]entity.SysDept {
// SelectDeptListByRoleId 根据角色ID查询部门树信息
func (d DeptDao) SelectDeptListByRoleId(id int64, strictly bool) *[]int64 {
list := make([]int64, 0)
session := SqlDB.NewSession().Table([]string{"sys_dept", "d"}).Cols("d.dept_id")
session := modules.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 {
@ -49,9 +50,9 @@ func (d DeptDao) SelectDeptListByRoleId(id int64, strictly bool) *[]int64 {
}
// GetList 查询部门列表
func (d DeptDao) GetList(query request.DeptQuery) *[]entity.SysDept {
list := make([]entity.SysDept, 0)
session := SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
func (d DeptDao) GetList(query request.DeptQuery) *[]dataobject.SysDept {
list := make([]dataobject.SysDept, 0)
session := modules.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
session.Where("del_flag = '0'")
if query.ParentId > 0 {
session.And("parent_id = ?", query.ParentId)
@ -71,9 +72,9 @@ func (d DeptDao) GetList(query request.DeptQuery) *[]entity.SysDept {
}
// SelectDeptById 根据部门编号获取详细信息
func (d DeptDao) SelectDeptById(id int) *entity.SysDept {
dept := entity.SysDept{}
_, err := SqlDB.NewSession().Where("dept_id = ?", id).Get(&dept)
func (d DeptDao) SelectDeptById(id int) *dataobject.SysDept {
dept := dataobject.SysDept{}
_, err := modules.SqlDB.NewSession().Where("dept_id = ?", id).Get(&dept)
if err != nil {
common.ErrorLog(err)
return nil
@ -82,8 +83,8 @@ func (d DeptDao) SelectDeptById(id int) *entity.SysDept {
}
// Insert 添加部门数据
func (d DeptDao) Insert(dept entity.SysDept) int64 {
session := SqlDB.NewSession()
func (d DeptDao) Insert(dept dataobject.SysDept) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&dept)
if err != nil {
@ -96,8 +97,8 @@ func (d DeptDao) Insert(dept entity.SysDept) int64 {
}
// CheckDeptNameUnique 校验部门名称是否唯一
func (d DeptDao) CheckDeptNameUnique(dept entity.SysDept) int64 {
session := SqlDB.NewSession()
func (d DeptDao) CheckDeptNameUnique(dept dataobject.SysDept) int64 {
session := modules.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)
@ -109,24 +110,24 @@ func (d DeptDao) CheckDeptNameUnique(dept entity.SysDept) int64 {
// HasChildByDeptId 是否存在部门子节点
func (d DeptDao) HasChildByDeptId(id int) int64 {
count, _ := SqlDB.NewSession().Table("sys_dept").Cols("dept_id").Where("parent_id = ?", id).
count, _ := modules.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, _ := SqlDB.NewSession().Table("sys_user").Cols("user_id").Where("dept_id = ?", id).
count, _ := modules.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 := entity.SysDept{
dept := dataobject.SysDept{
DeptId: id,
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
i, err := session.Where("dept_id = ?", id).Delete(&dept)
if err != nil {
@ -139,8 +140,8 @@ func (d DeptDao) Delete(id int) int64 {
}
// Update 更新部门
func (d DeptDao) Update(dept entity.SysDept) int64 {
session := SqlDB.NewSession()
func (d DeptDao) Update(dept dataobject.SysDept) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Where("dept_id = ?", dept.DeptId).Update(&dept)
if err != nil {

View File

@ -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"
@ -18,10 +19,10 @@ func (d *DictDataDao) sql(session *xorm.Session) *xorm.Session {
// SelectByDictType 根据字典类型查询字典数据
// @Param dictType string 字典类型
// @Return []entity.SysDictData
func (d *DictDataDao) SelectByDictType(dictType string) []entity.SysDictData {
data := make([]entity.SysDictData, 0)
session := d.sql(SqlDB.NewSession())
// @Return []dataobject.SysDictData
func (d *DictDataDao) SelectByDictType(dictType string) []dataobject.SysDictData {
data := make([]dataobject.SysDictData, 0)
session := d.sql(modules.SqlDB.NewSession())
err := session.Where("status = '0' ").And("dict_type = ?", dictType).OrderBy("dict_sort").Asc("dict_sort").
Find(&data)
if err != nil {
@ -32,10 +33,10 @@ func (d *DictDataDao) SelectByDictType(dictType string) []entity.SysDictData {
}
// GetDiceDataAll 查询所有字典数据
// @Return *[]entity.SysDictData
func (d DictDataDao) GetDiceDataAll() *[]entity.SysDictData {
session := d.sql(SqlDB.NewSession())
data := make([]entity.SysDictData, 0)
// @Return *[]dataobject.SysDictData
func (d DictDataDao) GetDiceDataAll() *[]dataobject.SysDictData {
session := d.sql(modules.SqlDB.NewSession())
data := make([]dataobject.SysDictData, 0)
err := session.Where("status = '0' ").OrderBy("dict_sort").Asc("dict_sort").
Find(&data)
if err != nil {
@ -47,11 +48,11 @@ func (d DictDataDao) GetDiceDataAll() *[]entity.SysDictData {
// SelectPage 查询集合数据
// @Param query request.DiceDataQuery
// @Return *[]entity.SysDictData
// @Return *[]dataobject.SysDictData
// @Return 总行数
func (d *DictDataDao) SelectPage(query request.DiceDataQuery) (*[]entity.SysDictData, int64) {
list := make([]entity.SysDictData, 0)
session := SqlDB.NewSession().Table("sys_dict_data").OrderBy("dict_sort").Asc("dict_sort")
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")
if gotool.StrUtils.HasNotEmpty(query.DictType) {
session.And("dict_type = ?", query.DictType)
}
@ -72,10 +73,10 @@ func (d *DictDataDao) SelectPage(query request.DiceDataQuery) (*[]entity.SysDict
// SelectByDictCode 根据dictCode查询字典数据
// @Param dictCode int64
// @Return *entity.SysDictData
func (d *DictDataDao) SelectByDictCode(dictCode int64) *entity.SysDictData {
data := entity.SysDictData{}
session := SqlDB.NewSession()
// @Return *dataobject.SysDictData
func (d *DictDataDao) SelectByDictCode(dictCode int64) *dataobject.SysDictData {
data := dataobject.SysDictData{}
session := modules.SqlDB.NewSession()
_, err := session.Where("dict_code = ?", dictCode).Get(&data)
if err != nil {
common.ErrorLog(err)
@ -85,10 +86,10 @@ func (d *DictDataDao) SelectByDictCode(dictCode int64) *entity.SysDictData {
}
// Insert 添加字典数据
// @Param data entity.SysDictData
// @Param data dataobject.SysDictData
// @Return 新增的行数
func (d *DictDataDao) Insert(data entity.SysDictData) int64 {
session := SqlDB.NewSession()
func (d *DictDataDao) Insert(data dataobject.SysDictData) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&data)
if err != nil {
@ -102,9 +103,9 @@ func (d *DictDataDao) Insert(data entity.SysDictData) int64 {
// Delete 删除字典数据
func (d *DictDataDao) Delete(codes []int64) bool {
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.In("dict_code", codes).Delete(&entity.SysDictData{})
_, err := session.In("dict_code", codes).Delete(&dataobject.SysDictData{})
if err != nil {
common.ErrorLog(err)
session.Rollback()
@ -115,8 +116,8 @@ func (d *DictDataDao) Delete(codes []int64) bool {
}
// 修改字典数据
func (d *DictDataDao) Update(data entity.SysDictData) bool {
session := SqlDB.NewSession()
func (d *DictDataDao) Update(data dataobject.SysDictData) bool {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Where("dict_code = ?", data.DictCode).Update(&data)
if err != nil {

View File

@ -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 DictTypeDao) sql(session *xorm.Session) *xorm.Session {
}
// SelectAll 查询所有字典类型数据
func (d DictTypeDao) SelectAll() []*entity.SysDictType {
types := make([]*entity.SysDictType, 0)
err := d.sql(SqlDB.NewSession()).Where("status = '0'").Find(&types)
func (d DictTypeDao) SelectAll() []*dataobject.SysDictType {
types := make([]*dataobject.SysDictType, 0)
err := d.sql(modules.SqlDB.NewSession()).Where("status = '0'").Find(&types)
if err != nil {
common.ErrorLog(err)
return nil
@ -28,9 +29,9 @@ func (d DictTypeDao) SelectAll() []*entity.SysDictType {
}
// SelectPage 分页查询字典类型数据
func (d DictTypeDao) SelectPage(query request.DictTypeQuery) (*[]entity.SysDictType, int64) {
list := make([]entity.SysDictType, 0)
session := SqlDB.NewSession().Table("sys_dict_type")
func (d DictTypeDao) SelectPage(query request.DictTypeQuery) (*[]dataobject.SysDictType, int64) {
list := make([]dataobject.SysDictType, 0)
session := modules.SqlDB.NewSession().Table("sys_dict_type")
if gotool.StrUtils.HasNotEmpty(query.DictName) {
session.And("dict_name like concat('%', ?, '%')", query.DictName)
}
@ -56,9 +57,9 @@ func (d DictTypeDao) SelectPage(query request.DictTypeQuery) (*[]entity.SysDictT
}
// SelectById 根据id查询字典类型数据
func (d DictTypeDao) SelectById(id int64) *entity.SysDictType {
dictType := entity.SysDictType{}
_, err := SqlDB.NewSession().Where("dict_id = ?", id).Get(&dictType)
func (d DictTypeDao) SelectById(id int64) *dataobject.SysDictType {
dictType := dataobject.SysDictType{}
_, err := modules.SqlDB.NewSession().Where("dict_id = ?", id).Get(&dictType)
if err != nil {
common.ErrorLog(err)
return nil
@ -67,8 +68,8 @@ func (d DictTypeDao) SelectById(id int64) *entity.SysDictType {
}
// CheckDictTypeUnique 检验字典类型是否存在
func (d DictTypeDao) CheckDictTypeUnique(dictType entity.SysDictType) int64 {
session := SqlDB.NewSession().Table("sys_dict_type")
func (d DictTypeDao) CheckDictTypeUnique(dictType dataobject.SysDictType) int64 {
session := modules.SqlDB.NewSession().Table("sys_dict_type")
if dictType.DictId > 0 {
session.And("dict_id != ?", dictType.DictId)
}
@ -81,8 +82,8 @@ func (d DictTypeDao) CheckDictTypeUnique(dictType entity.SysDictType) int64 {
}
// Update 修改字典
func (d DictTypeDao) Update(dictType entity.SysDictType) bool {
session := SqlDB.NewSession()
func (d DictTypeDao) Update(dictType dataobject.SysDictType) bool {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Where("dict_id = ?", dictType.DictId).Update(&dictType)
if err != nil {
@ -95,8 +96,8 @@ func (d DictTypeDao) Update(dictType entity.SysDictType) bool {
}
// Insert 新增字典类型
func (d DictTypeDao) Insert(dictType entity.SysDictType) int64 {
session := SqlDB.NewSession()
func (d DictTypeDao) Insert(dictType dataobject.SysDictType) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&dictType)
if err != nil {
@ -110,9 +111,9 @@ func (d DictTypeDao) Insert(dictType entity.SysDictType) int64 {
// Delete 批量删除
func (d DictTypeDao) Delete(ids []int64) bool {
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.In("dict_id", ids).Delete(entity.SysDictType{})
_, err := session.In("dict_id", ids).Delete(dataobject.SysDictType{})
if err != nil {
session.Rollback()
common.ErrorLog(err)

View File

@ -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 LogDao) sql(session *xorm.Session) *xorm.Session {
}
// SelectPage 分页查询数据
func (d LogDao) SelectPage(query request.LogQuery) ([]entity.SysLog, int64) {
configs := make([]entity.SysLog, 0)
session := d.sql(SqlDB.NewSession())
func (d LogDao) SelectPage(query request.LogQuery) ([]dataobject.SysLog, int64) {
configs := make([]dataobject.SysLog, 0)
session := d.sql(modules.SqlDB.NewSession())
if gotool.StrUtils.HasNotEmpty(query.Content) {
session.And("content like concat('%', ?, '%')", query.Content)
}
@ -36,8 +37,8 @@ func (d LogDao) SelectPage(query request.LogQuery) ([]entity.SysLog, int64) {
}
// Insert 添加数据
func (d LogDao) Insert(config entity.SysLog) int64 {
session := SqlDB.NewSession()
func (d LogDao) Insert(config dataobject.SysLog) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&config)
if err != nil {

View File

@ -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/go-xorm/xorm"
@ -17,9 +18,9 @@ func (d LoginInfoDao) sql(session *xorm.Session) *xorm.Session {
}
// SelectPage 分页查询数据
func (d LoginInfoDao) SelectPage(query request.LoginInfoQuery) (*[]entity.SysLoginInfo, int64) {
loginInfos := make([]entity.SysLoginInfo, 0)
session := d.sql(SqlDB.NewSession())
func (d LoginInfoDao) SelectPage(query request.LoginInfoQuery) (*[]dataobject.SysLoginInfo, int64) {
loginInfos := make([]dataobject.SysLoginInfo, 0)
session := d.sql(modules.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)
@ -31,8 +32,8 @@ func (d LoginInfoDao) SelectPage(query request.LoginInfoQuery) (*[]entity.SysLog
}
// Insert 添加登录记录
func (d LoginInfoDao) Insert(body entity.SysLoginInfo) *entity.SysLoginInfo {
session := SqlDB.NewSession()
func (d LoginInfoDao) Insert(body dataobject.SysLoginInfo) *dataobject.SysLoginInfo {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Table("sys_login_info").Insert(&body)
if err != nil {

View File

@ -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"
"github.com/druidcaesa/gotool"
)
@ -13,7 +14,7 @@ type MenuDao struct {
// GetMenuPermission 根据用户ID查询权限
func (d MenuDao) GetMenuPermission(id int64) *[]string {
var perms []string
session := SqlDB.Table([]string{"sys_menu", "m"})
session := modules.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").
@ -27,9 +28,9 @@ func (d MenuDao) GetMenuPermission(id int64) *[]string {
}
// GetMenuAll 查询所有菜单数据
func (d MenuDao) GetMenuAll() *[]entity.SysMenu {
menus := make([]entity.SysMenu, 0)
session := SqlDB.Table([]string{entity.SysMenu{}.TableName(), "m"})
func (d MenuDao) GetMenuAll() *[]dataobject.SysMenu {
menus := make([]dataobject.SysMenu, 0)
session := modules.SqlDB.Table([]string{dataobject.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 {
@ -40,9 +41,9 @@ func (d MenuDao) GetMenuAll() *[]entity.SysMenu {
}
// GetMenuByUserId 根据用户ID查询菜单
func (d MenuDao) GetMenuByUserId(id int64) *[]entity.SysMenu {
menus := make([]entity.SysMenu, 0)
session := SqlDB.Table([]string{entity.SysMenu{}.TableName(), "m"})
func (d MenuDao) GetMenuByUserId(id int64) *[]dataobject.SysMenu {
menus := make([]dataobject.SysMenu, 0)
session := modules.SqlDB.Table([]string{dataobject.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").
@ -59,7 +60,7 @@ func (d MenuDao) GetMenuByUserId(id int64) *[]entity.SysMenu {
// SelectMenuByRoleId 根据角色ID查询菜单树信息
func (d MenuDao) SelectMenuByRoleId(id int64, strictly bool) *[]int64 {
list := make([]int64, 0)
session := SqlDB.NewSession().Table([]string{"sys_menu", "m"})
session := modules.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 {
@ -74,9 +75,9 @@ func (d MenuDao) SelectMenuByRoleId(id int64, strictly bool) *[]int64 {
}
// SelectMenuList 查询系统菜单列表
func (d MenuDao) SelectMenuList(query request.MenuQuery) *[]entity.SysMenu {
list := make([]entity.SysMenu, 0)
session := SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
func (d MenuDao) SelectMenuList(query request.MenuQuery) *[]dataobject.SysMenu {
list := make([]dataobject.SysMenu, 0)
session := modules.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
if gotool.StrUtils.HasNotEmpty(query.MenuName) {
session.And("menu_name like concat('%', ?, '%')", query.MenuName)
}
@ -95,9 +96,9 @@ func (d MenuDao) SelectMenuList(query request.MenuQuery) *[]entity.SysMenu {
}
// SelectMenuListByUserId 根据用户查询系统菜单列表
func (d MenuDao) SelectMenuListByUserId(query request.MenuQuery) *[]entity.SysMenu {
session := SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
list := make([]entity.SysMenu, 0)
func (d MenuDao) SelectMenuListByUserId(query request.MenuQuery) *[]dataobject.SysMenu {
session := modules.SqlDB.NewSession().OrderBy("parent_id").OrderBy("order_num")
list := make([]dataobject.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").
@ -121,11 +122,11 @@ func (d MenuDao) SelectMenuListByUserId(query request.MenuQuery) *[]entity.SysMe
}
// SelectMenuByMenuId 根据菜单ID查询信息
func (d MenuDao) SelectMenuByMenuId(id int) *entity.SysMenu {
menu := entity.SysMenu{
func (d MenuDao) SelectMenuByMenuId(id int) *dataobject.SysMenu {
menu := dataobject.SysMenu{
MenuId: id,
}
_, err := SqlDB.NewSession().Where("menu_id = ?", menu.MenuId).Get(&menu)
_, err := modules.SqlDB.NewSession().Where("menu_id = ?", menu.MenuId).Get(&menu)
if err != nil {
common.ErrorLog(err)
return nil
@ -134,8 +135,8 @@ func (d MenuDao) SelectMenuByMenuId(id int) *entity.SysMenu {
}
// Insert 添加菜单数据
func (d MenuDao) Insert(menu entity.SysMenu) int64 {
session := SqlDB.NewSession()
func (d MenuDao) Insert(menu dataobject.SysMenu) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&menu)
if err != nil {
@ -148,8 +149,8 @@ func (d MenuDao) Insert(menu entity.SysMenu) int64 {
}
// Update 修改菜单数据
func (d MenuDao) Update(menu entity.SysMenu) int64 {
session := SqlDB.NewSession()
func (d MenuDao) Update(menu dataobject.SysMenu) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Where("menu_id = ?", menu.MenuId).Update(&menu)
if err != nil {
@ -163,10 +164,10 @@ func (d MenuDao) Update(menu entity.SysMenu) int64 {
// Delete 删除菜单操作
func (d MenuDao) Delete(id int) int64 {
menu := entity.SysMenu{
menu := dataobject.SysMenu{
MenuId: id,
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
i, err := session.Delete(&menu)
if err != nil {

View File

@ -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"
@ -12,9 +13,9 @@ type NoticeDao struct {
}
// SelectPage 查询集合
func (d NoticeDao) SelectPage(query request.NoticeQuery) (*[]entity.SysNotice, int64) {
notices := make([]entity.SysNotice, 0)
session := SqlDB.NewSession().Table(entity.SysNotice{}.TableName())
func (d NoticeDao) SelectPage(query request.NoticeQuery) (*[]dataobject.SysNotice, int64) {
notices := make([]dataobject.SysNotice, 0)
session := modules.SqlDB.NewSession().Table(dataobject.SysNotice{}.TableName())
if gotool.StrUtils.HasNotEmpty(query.NoticeTitle) {
session.And("notice_title like concat('%', ?, '%')", query.NoticeTitle)
}
@ -34,8 +35,8 @@ func (d NoticeDao) SelectPage(query request.NoticeQuery) (*[]entity.SysNotice, i
}
// Insert 添加数据
func (d NoticeDao) Insert(notice entity.SysNotice) int64 {
session := SqlDB.NewSession()
func (d NoticeDao) Insert(notice dataobject.SysNotice) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&notice)
if err != nil {
@ -49,9 +50,9 @@ func (d NoticeDao) Insert(notice entity.SysNotice) int64 {
// Delete 批量删除
func (d NoticeDao) Delete(list []int64) int64 {
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
i, err := session.In("notice_id", list).Delete(&entity.SysNotice{})
i, err := session.In("notice_id", list).Delete(&dataobject.SysNotice{})
if err != nil {
session.Rollback()
common.ErrorLog(err)
@ -62,9 +63,9 @@ func (d NoticeDao) Delete(list []int64) int64 {
}
// SelectById 查询
func (d NoticeDao) SelectById(id int64) *entity.SysNotice {
notice := entity.SysNotice{}
_, err := SqlDB.NewSession().Where("notice_id = ?", id).Get(&notice)
func (d NoticeDao) SelectById(id int64) *dataobject.SysNotice {
notice := dataobject.SysNotice{}
_, err := modules.SqlDB.NewSession().Where("notice_id = ?", id).Get(&notice)
if err != nil {
common.ErrorLog(err)
return nil
@ -73,8 +74,8 @@ func (d NoticeDao) SelectById(id int64) *entity.SysNotice {
}
// Update 修改数据
func (d NoticeDao) Update(notice entity.SysNotice) int64 {
session := SqlDB.NewSession()
func (d NoticeDao) Update(notice dataobject.SysNotice) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Where("notice_id = ?", notice.NoticeId).Update(&notice)
if err != nil {

View File

@ -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"
@ -19,9 +20,9 @@ func (d PostDao) sqlSelectJoin(session *xorm.Session) *xorm.Session {
}
// SelectAll 查询所有岗位数据, 数据库操作
func (d PostDao) SelectAll() []*entity.SysPost {
session := SqlDB.NewSession()
posts := make([]*entity.SysPost, 0)
func (d PostDao) SelectAll() []*dataobject.SysPost {
session := modules.SqlDB.NewSession()
posts := make([]*dataobject.SysPost, 0)
err := session.Find(&posts)
if err != nil {
common.ErrorLog(err)
@ -33,7 +34,7 @@ func (d PostDao) SelectAll() []*entity.SysPost {
// SelectPostListByUserId 根据用户id查询岗位id集合
func (d PostDao) SelectPostListByUserId(userId int64) *[]int64 {
var ids []int64
selectSql := d.sqlSelectJoin(SqlDB.NewSession())
selectSql := d.sqlSelectJoin(modules.SqlDB.NewSession())
err := selectSql.Where("u.user_id = ?", userId).Cols("p.post_id").Find(&ids)
if err != nil {
common.ErrorLog(err)
@ -43,9 +44,9 @@ func (d PostDao) SelectPostListByUserId(userId int64) *[]int64 {
}
// SelectPage 查询岗位分页数据
func (d PostDao) SelectPage(query request.PostQuery) (*[]entity.SysPost, int64) {
posts := make([]entity.SysPost, 0)
session := SqlDB.NewSession().Table(entity.SysPost{}.TableName())
func (d PostDao) SelectPage(query request.PostQuery) (*[]dataobject.SysPost, int64) {
posts := make([]dataobject.SysPost, 0)
session := modules.SqlDB.NewSession().Table(dataobject.SysPost{}.TableName())
if gotool.StrUtils.HasNotEmpty(query.PostCode) {
session.And("post_code like concat('%', ?, '%')", query.PostCode)
}
@ -65,8 +66,8 @@ func (d PostDao) SelectPage(query request.PostQuery) (*[]entity.SysPost, int64)
}
// CheckPostNameUnique 校验岗位名称是否存在
func (d PostDao) CheckPostNameUnique(post entity.SysPost) int64 {
session := SqlDB.NewSession().Table("sys_post").Cols("post_id").
func (d PostDao) CheckPostNameUnique(post dataobject.SysPost) int64 {
session := modules.SqlDB.NewSession().Table("sys_post").Cols("post_id").
Where("post_name = ?", post.PostName)
if post.PostId > 0 {
session.And("post_id != ?", post.PostId)
@ -76,8 +77,8 @@ func (d PostDao) CheckPostNameUnique(post entity.SysPost) int64 {
}
// CheckPostCodeUnique 校验岗位编码是否存在
func (d PostDao) CheckPostCodeUnique(post entity.SysPost) int64 {
session := SqlDB.NewSession().Table("sys_post").Cols("post_id").
func (d PostDao) CheckPostCodeUnique(post dataobject.SysPost) int64 {
session := modules.SqlDB.NewSession().Table("sys_post").Cols("post_id").
Where("post_code = ?", post.PostCode)
if post.PostId > 0 {
session.And("post_id != ?", post.PostId)
@ -87,8 +88,8 @@ func (d PostDao) CheckPostCodeUnique(post entity.SysPost) int64 {
}
// Insert 添加岗位数据
func (d PostDao) Insert(post entity.SysPost) int64 {
session := SqlDB.NewSession()
func (d PostDao) Insert(post dataobject.SysPost) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&post)
if err != nil {
@ -101,8 +102,8 @@ func (d PostDao) Insert(post entity.SysPost) int64 {
}
// GetPostById 根据id查询岗位数据
func (d PostDao) GetPostById(post entity.SysPost) *entity.SysPost {
_, err := SqlDB.NewSession().Where("post_id = ?", post.PostId).Get(&post)
func (d PostDao) GetPostById(post dataobject.SysPost) *dataobject.SysPost {
_, err := modules.SqlDB.NewSession().Where("post_id = ?", post.PostId).Get(&post)
if err != nil {
common.ErrorLog(err)
return nil
@ -113,9 +114,9 @@ func (d PostDao) GetPostById(post entity.SysPost) *entity.SysPost {
// Delete 批量删除岗位
func (d PostDao) Delete(posts []int64) int64 {
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
i, err := session.In("post_id", posts).Delete(&entity.SysPost{})
i, err := session.In("post_id", posts).Delete(&dataobject.SysPost{})
if err != nil {
session.Rollback()
common.ErrorLog(err)
@ -126,8 +127,8 @@ func (d PostDao) Delete(posts []int64) int64 {
}
// Update 修改岗位数据
func (d PostDao) Update(post entity.SysPost) bool {
session := SqlDB.NewSession()
func (d PostDao) Update(post dataobject.SysPost) bool {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Where("post_id = ?", post.PostId).Update(&post)
if err != nil {
@ -139,9 +140,9 @@ func (d PostDao) Update(post entity.SysPost) bool {
return true
}
func (d PostDao) SelectPostByUserName(name string) *[]entity.SysPost {
posts := make([]entity.SysPost, 0)
session := SqlDB.NewSession().Table([]string{entity.SysPost{}.TableName(), "p"})
func (d PostDao) SelectPostByUserName(name string) *[]dataobject.SysPost {
posts := make([]dataobject.SysPost, 0)
session := modules.SqlDB.NewSession().Table([]string{dataobject.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)

View File

@ -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"
@ -14,7 +15,7 @@ type RoleDao struct {
// 角色公用sql
func (d RoleDao) sqlSelectJoin() *xorm.Session {
return SqlDB.Table([]string{entity.SysRole{}.TableName(), "r"}).
return modules.SqlDB.Table([]string{dataobject.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")
@ -22,14 +23,14 @@ func (d RoleDao) sqlSelectJoin() *xorm.Session {
// 用户角色关系查询sql
func (d RoleDao) sqlSelectRoleAndUser() *xorm.Session {
return SqlDB.Table([]string{entity.SysRole{}.TableName(), "r"}).
return modules.SqlDB.Table([]string{dataobject.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) ([]*entity.SysRole, int64) {
roles := make([]*entity.SysRole, 0)
func (d RoleDao) SelectPage(q *request.RoleQuery) ([]*dataobject.SysRole, int64) {
roles := make([]*dataobject.SysRole, 0)
session := d.sqlSelectJoin()
if !gotool.StrUtils.HasEmpty(q.RoleName) {
session.And("r.role_name like concat('%', ?, '%')", q.RoleName)
@ -55,9 +56,9 @@ func (d RoleDao) SelectPage(q *request.RoleQuery) ([]*entity.SysRole, int64) {
}
// SelectAll 查询所有角色
func (d RoleDao) SelectAll() []*entity.SysRole {
func (d RoleDao) SelectAll() []*dataobject.SysRole {
sql := d.sqlSelectJoin()
roles := make([]*entity.SysRole, 0)
roles := make([]*dataobject.SysRole, 0)
err := sql.Find(&roles)
if err != nil {
common.ErrorLog(err)
@ -90,8 +91,8 @@ func (d RoleDao) SelectRolePermissionByUserId(id int64) *[]string {
}
// GetRoleListByUserId 根据用户ID查询角色
func (d RoleDao) GetRoleListByUserId(id int64) *[]entity.SysRole {
roles := make([]entity.SysRole, 0)
func (d RoleDao) GetRoleListByUserId(id int64) *[]dataobject.SysRole {
roles := make([]dataobject.SysRole, 0)
err := d.sqlSelectJoin().Where("r.del_flag = '0'").And("ur.user_id = ?", id).Find(&roles)
if err != nil {
common.ErrorLog(err)
@ -101,8 +102,8 @@ func (d RoleDao) GetRoleListByUserId(id int64) *[]entity.SysRole {
}
// SelectRoleByRoleId 根据角色id查询角色数据
func (d RoleDao) SelectRoleByRoleId(id int64) *entity.SysRole {
role := entity.SysRole{}
func (d RoleDao) SelectRoleByRoleId(id int64) *dataobject.SysRole {
role := dataobject.SysRole{}
_, err := d.sqlSelectJoin().Where("r.role_id = ?", id).Get(&role)
if err != nil {
common.ErrorLog(err)
@ -112,8 +113,8 @@ func (d RoleDao) SelectRoleByRoleId(id int64) *entity.SysRole {
}
// CheckRoleNameUnique 校验角色名称是否唯一
func (d RoleDao) CheckRoleNameUnique(role entity.SysRole) int64 {
session := SqlDB.Table(role.TableName()).Where("role_name = ?", role.RoleName)
func (d RoleDao) CheckRoleNameUnique(role dataobject.SysRole) int64 {
session := modules.SqlDB.Table(role.TableName()).Where("role_name = ?", role.RoleName)
if role.RoleId > 0 {
session.And("role_id != ?", role.RoleId)
}
@ -125,8 +126,8 @@ func (d RoleDao) CheckRoleNameUnique(role entity.SysRole) int64 {
}
// CheckRoleKeyUnique 校验角色权限是否唯一
func (d RoleDao) CheckRoleKeyUnique(role entity.SysRole) int64 {
session := SqlDB.Table(role.TableName()).Where("role_key = ?", role.RoleKey)
func (d RoleDao) CheckRoleKeyUnique(role dataobject.SysRole) int64 {
session := modules.SqlDB.Table(role.TableName()).Where("role_key = ?", role.RoleKey)
if role.RoleId > 0 {
session.And("role_id != ?", role.RoleId)
}
@ -138,8 +139,8 @@ func (d RoleDao) CheckRoleKeyUnique(role entity.SysRole) int64 {
}
// Add 添加角色进入数据库操作
func (d RoleDao) Insert(role entity.SysRole) entity.SysRole {
session := SqlDB.NewSession()
func (d RoleDao) Insert(role dataobject.SysRole) dataobject.SysRole {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Insert(&role)
if err != nil {
@ -151,8 +152,8 @@ func (d RoleDao) Insert(role entity.SysRole) entity.SysRole {
}
// Update 修改数据
func (d RoleDao) Update(role entity.SysRole) int64 {
session := SqlDB.NewSession()
func (d RoleDao) Update(role dataobject.SysRole) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Where("role_id = ?", role.RoleId).Update(&role)
if err != nil {
@ -165,8 +166,8 @@ func (d RoleDao) Update(role entity.SysRole) int64 {
}
// Delete 删除角色
func (d RoleDao) Delete(role entity.SysRole) int64 {
session := SqlDB.NewSession()
func (d RoleDao) Delete(role dataobject.SysRole) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
i, err := session.Delete(&role)
if err != nil {
@ -179,8 +180,8 @@ func (d RoleDao) Delete(role entity.SysRole) int64 {
}
// UpdateRoleStatus 修改角色状态
func (d RoleDao) UpdateRoleStatus(role *entity.SysRole) int64 {
session := SqlDB.NewSession()
func (d RoleDao) UpdateRoleStatus(role *dataobject.SysRole) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Where("role_id = ?", role.RoleId).Cols("status", "update_by", "update_time").Update(role)
if err != nil {
@ -193,8 +194,8 @@ func (d RoleDao) UpdateRoleStatus(role *entity.SysRole) int64 {
}
// SelectRolesByUserName 查询角色组
func (d RoleDao) SelectRolesByUserName(name string) *[]entity.SysRole {
roles := make([]entity.SysRole, 0)
func (d RoleDao) SelectRolesByUserName(name string) *[]dataobject.SysRole {
roles := make([]dataobject.SysRole, 0)
session := d.sqlSelectJoin()
err := session.Where("r.del_flag = '0'").And("u.user_name = ?", name).Find(&roles)
if err != nil {

View File

@ -1,7 +1,8 @@
package dao
import (
"cutego/modules/core/entity"
"cutego/modules"
"cutego/modules/core/dataobject"
"cutego/pkg/common"
)
@ -9,8 +10,8 @@ type RoleMenuDao struct {
}
// Insert 添加角色菜单关系
func (d RoleMenuDao) Insert(list []entity.SysRoleMenu) int64 {
session := SqlDB.NewSession()
func (d RoleMenuDao) Insert(list []dataobject.SysRoleMenu) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&list)
if err != nil {
@ -22,11 +23,11 @@ func (d RoleMenuDao) Insert(list []entity.SysRoleMenu) int64 {
}
// Delete 删除角色和菜单关系
func (d RoleMenuDao) Delete(role entity.SysRole) {
menu := entity.SysRoleMenu{
func (d RoleMenuDao) Delete(role dataobject.SysRole) {
menu := dataobject.SysRoleMenu{
RoleId: role.RoleId,
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Delete(&menu)
if err != nil {

View File

@ -1,9 +1,10 @@
package dao
import (
"cutego/modules"
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/pkg/common"
"cutego/pkg/page"
"github.com/druidcaesa/gotool"
@ -16,7 +17,7 @@ type UserDao struct {
// 查询公共sql
func (d UserDao) sqlSelectJoin() *xorm.Session {
return SqlDB.NewSession().Table([]string{"sys_user", "u"}).
return modules.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")
@ -67,8 +68,8 @@ func (d UserDao) GetUserById(userId int64) *response.UserResponse {
}
// GetUserByUserName 根据用户名查询用户数据
func (d UserDao) GetUserByUserName(user entity.SysUser) *entity.SysUser {
i, err := SqlDB.Get(&user)
func (d UserDao) GetUserByUserName(user dataobject.SysUser) *dataobject.SysUser {
i, err := modules.SqlDB.Get(&user)
if err != nil {
common.ErrorLog(err)
return nil
@ -80,9 +81,9 @@ func (d UserDao) GetUserByUserName(user entity.SysUser) *entity.SysUser {
}
// CheckEmailUnique 校验邮箱是否存在
func (d UserDao) CheckEmailUnique(user request.UserBody) *entity.SysUser {
sysUser := entity.SysUser{}
session := SqlDB.NewSession().Table("sys_user")
func (d UserDao) CheckEmailUnique(user request.UserBody) *dataobject.SysUser {
sysUser := dataobject.SysUser{}
session := modules.SqlDB.NewSession().Table("sys_user")
session.Cols("user_id", "email")
session.Where("email = ?", user.Email)
if user.UserId > 0 {
@ -96,9 +97,9 @@ func (d UserDao) CheckEmailUnique(user request.UserBody) *entity.SysUser {
}
// CheckPhoneNumUnique 校验手机号是否存在
func (d UserDao) CheckPhoneNumUnique(body request.UserBody) *entity.SysUser {
sysUser := entity.SysUser{}
session := SqlDB.NewSession().Table("sys_user")
func (d UserDao) CheckPhoneNumUnique(body request.UserBody) *dataobject.SysUser {
sysUser := dataobject.SysUser{}
session := modules.SqlDB.NewSession().Table("sys_user")
session.Cols("user_id", "phone_num")
session.Where("phone_num = ?", body.PhoneNumber)
if body.UserId > 0 {
@ -113,7 +114,7 @@ func (d UserDao) CheckPhoneNumUnique(body request.UserBody) *entity.SysUser {
// Insert 添加用户
func (d UserDao) Insert(body request.UserBody) *request.UserBody {
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Table("sys_user").Insert(&body)
if err != nil {
@ -126,7 +127,7 @@ func (d UserDao) Insert(body request.UserBody) *request.UserBody {
// Update 修改用户数据
func (d UserDao) Update(body request.UserBody) int64 {
session := SqlDB.NewSession().Table("sys_user")
session := modules.SqlDB.NewSession().Table("sys_user")
session.Begin()
_, err := session.Where("user_id = ?", body.UserId).Update(&body)
if err != nil {
@ -140,10 +141,10 @@ func (d UserDao) Update(body request.UserBody) int64 {
// Delete 根据id删除用户数据
func (d UserDao) Delete(id int64) int64 {
user := entity.SysUser{
user := dataobject.SysUser{
UserId: id,
}
session := SqlDB.NewSession().Table("sys_user")
session := modules.SqlDB.NewSession().Table("sys_user")
session.Begin()
i, err := session.Delete(&user)
if err != nil {
@ -156,11 +157,11 @@ func (d UserDao) Delete(id int64) int64 {
// ResetPwd 修改用户密码数据库操作
func (d UserDao) ResetPwd(body request.UserBody) int64 {
user := entity.SysUser{
user := dataobject.SysUser{
UserId: body.UserId,
Password: body.Password,
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Where("user_id = ?", user.UserId).Cols("password").Update(&user)
if err != nil {
@ -175,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 := SqlDB.NewSession()
session := modules.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").
@ -198,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 := SqlDB.NewSession()
session := modules.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").
@ -221,10 +222,10 @@ func (d UserDao) GetUnallocatedList(query request.UserQuery) ([]*response.UserRe
// UpdatePwd 修改密码
func (d UserDao) UpdatePwd(id int64, hash string) int64 {
user := entity.SysUser{}
user := dataobject.SysUser{}
user.UserId = id
user.Password = hash
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Cols("password").Where("user_id = ?", id).Update(&user)
if err != nil {
@ -238,13 +239,13 @@ func (d UserDao) UpdatePwd(id int64, hash string) int64 {
// UpdateAvatar 修改头像
func (d UserDao) UpdateAvatar(info *response.UserResponse) int64 {
user := entity.SysUser{
user := dataobject.SysUser{
Avatar: info.Avatar,
UserId: info.UserId,
UpdateBy: info.UserName,
UpdateTime: time.Now(),
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Cols("avatar", "update_by", "update_time").Where("user_id = ?", user.UserId).Update(&user)
if err != nil {
@ -257,13 +258,13 @@ func (d UserDao) UpdateAvatar(info *response.UserResponse) int64 {
}
func (d UserDao) UpdateStatus(info request.UserBody) int64 {
user := entity.SysUser{
user := dataobject.SysUser{
UserId: info.UserId,
Status: info.Status,
UpdateBy: info.UserName,
UpdateTime: time.Now(),
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
update, err := session.Cols("status", "update_by", "update_time").Where("user_id = ?", user.UserId).Update(&user)
if err != nil {

View File

@ -1,7 +1,8 @@
package dao
import (
"cutego/modules/core/entity"
"cutego/modules"
"cutego/modules/core/dataobject"
"cutego/pkg/common"
)
@ -9,10 +10,10 @@ type UserPostDao struct {
}
// BatchInsert 批量新增用户岗位信息
func (d UserPostDao) BatchInsert(posts []entity.SysUserPost) {
session := SqlDB.NewSession()
func (d UserPostDao) BatchInsert(posts []dataobject.SysUserPost) {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Table(entity.SysUserPost{}.TableName()).Insert(&posts)
_, err := session.Table(dataobject.SysUserPost{}.TableName()).Insert(&posts)
if err != nil {
common.ErrorLog(err)
session.Rollback()
@ -23,10 +24,10 @@ func (d UserPostDao) BatchInsert(posts []entity.SysUserPost) {
// Delete 删除用户和岗位关系
func (d UserPostDao) Delete(id int64) {
post := entity.SysUserPost{
post := dataobject.SysUserPost{
UserId: id,
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Delete(&post)
if err != nil {
@ -38,7 +39,7 @@ func (d UserPostDao) Delete(id int64) {
// CountById 通过岗位ID查询岗位使用数量
func (d UserPostDao) CountById(id int64) int64 {
count, err := SqlDB.NewSession().Table("sys_user_post").Cols("post_id").Where("post_id = ?", id).Count()
count, err := modules.SqlDB.NewSession().Table("sys_user_post").Cols("post_id").Where("post_id = ?", id).Count()
if err != nil {
common.ErrorLog(err)
return 0

View File

@ -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"
)
@ -10,10 +11,10 @@ type UserRoleDao struct {
}
// BatchInsert 批量新增用户角色信息
func (d UserRoleDao) BatchInsert(roles []entity.SysUserRole) {
session := SqlDB.NewSession()
func (d UserRoleDao) BatchInsert(roles []dataobject.SysUserRole) {
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Table(entity.SysUserRole{}.TableName()).Insert(&roles)
_, err := session.Table(dataobject.SysUserRole{}.TableName()).Insert(&roles)
if err != nil {
common.ErrorLog(err)
session.Rollback()
@ -24,10 +25,10 @@ func (d UserRoleDao) BatchInsert(roles []entity.SysUserRole) {
// Delete 删除用户和角色关系
func (d UserRoleDao) Delete(id int64) {
role := entity.SysUserRole{
role := dataobject.SysUserRole{
UserId: id,
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
_, err := session.Delete(&role)
if err != nil {
@ -39,8 +40,8 @@ func (d UserRoleDao) Delete(id int64) {
}
// DeleteAuthUser 取消用户授权
func (d UserRoleDao) DeleteAuthUser(role entity.SysUserRole) int64 {
session := SqlDB.NewSession()
func (d UserRoleDao) DeleteAuthUser(role dataobject.SysUserRole) int64 {
session := modules.SqlDB.NewSession()
session.Begin()
i, err := session.Delete(&role)
if err != nil {
@ -55,15 +56,15 @@ func (d UserRoleDao) DeleteAuthUser(role entity.SysUserRole) int64 {
// InsertAuthUsers 批量选择用户授权
func (d UserRoleDao) InsertAuthUsers(body request.UserRoleBody) int64 {
ids := body.UserIds
roles := make([]entity.SysUserRole, 0)
roles := make([]dataobject.SysUserRole, 0)
for i := 0; i < len(ids); i++ {
role := entity.SysUserRole{
role := dataobject.SysUserRole{
RoleId: body.RoleId,
UserId: ids[i],
}
roles = append(roles, role)
}
session := SqlDB.NewSession()
session := modules.SqlDB.NewSession()
session.Begin()
insert, err := session.Insert(&roles)
if err != nil {

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import "time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"strings"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import "time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import "time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import "time"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
// SysRoleMenu 角色菜单数据结构
type SysRoleMenu struct {

View File

@ -1,4 +1,4 @@
package entity
package dataobject
import (
"reflect"

View File

@ -1,4 +1,4 @@
package entity
package dataobject
type SysUserPost struct {
UserId int64 `json:"userId"` // 用户id

View File

@ -1,4 +1,4 @@
package entity
package dataobject
type SysUserRole struct {
UserId int64 `xorm:"pk" json:"userId"` // 用户id

View File

@ -4,7 +4,7 @@ import (
"cutego/modules/core/api/v1/request"
cache2 "cutego/modules/core/cache"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
type ConfigService struct {
@ -12,7 +12,7 @@ type ConfigService struct {
}
// GetConfigKey 根据键名查询参数配置信息
func (s ConfigService) GetConfigKey(param string) *entity.SysConfig {
func (s ConfigService) GetConfigKey(param string) *dataobject.SysConfig {
// 从缓存中取出数据判断是否存在, 存在直接使用, 不存在就从数据库查询
val := cache2.GetRedisConfig(param)
if val != nil {
@ -24,27 +24,27 @@ func (s ConfigService) GetConfigKey(param string) *entity.SysConfig {
}
// FindPage 分页查询数据
func (s ConfigService) FindPage(query request.ConfigQuery) (*[]entity.SysConfig, int64) {
func (s ConfigService) FindPage(query request.ConfigQuery) (*[]dataobject.SysConfig, int64) {
return s.configDao.SelectPage(query)
}
// CheckConfigKeyUnique 校验是否存在
func (s ConfigService) CheckConfigKeyUnique(config entity.SysConfig) bool {
func (s ConfigService) CheckConfigKeyUnique(config dataobject.SysConfig) bool {
return s.configDao.CheckConfigKeyUnique(config) > 0
}
// Save 添加数据
func (s ConfigService) Save(config entity.SysConfig) int64 {
func (s ConfigService) Save(config dataobject.SysConfig) int64 {
return s.configDao.Insert(config)
}
// GetInfo 查询数据
func (s ConfigService) GetInfo(id int64) *entity.SysConfig {
func (s ConfigService) GetInfo(id int64) *dataobject.SysConfig {
return s.configDao.SelectById(id)
}
// Edit 修改数据
func (s ConfigService) Edit(config entity.SysConfig) int64 {
func (s ConfigService) Edit(config dataobject.SysConfig) int64 {
return s.configDao.Update(config)
}
@ -54,11 +54,11 @@ func (s ConfigService) Remove(list []int64) bool {
}
// CheckConfigByIds 根据id集合查询
func (s ConfigService) CheckConfigByIds(list []int64) *[]entity.SysConfig {
func (s ConfigService) CheckConfigByIds(list []int64) *[]dataobject.SysConfig {
return s.configDao.CheckConfigByIds(list)
}
// FindAll 查询所有数据
func (s ConfigService) FindAll() *[]entity.SysConfig {
func (s ConfigService) FindAll() *[]dataobject.SysConfig {
return s.configDao.SelectAll()
}

View File

@ -3,7 +3,7 @@ package service
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
type CronJobService struct {
@ -11,27 +11,27 @@ type CronJobService struct {
}
// FindPage 分页查询数据
func (s CronJobService) FindPage(query request.CronJobQuery) ([]entity.SysCronJob, int64) {
func (s CronJobService) FindPage(query request.CronJobQuery) ([]dataobject.SysCronJob, int64) {
return s.cronJobDao.SelectPage(query)
}
// Save 添加数据
func (s CronJobService) Save(config entity.SysCronJob) int64 {
func (s CronJobService) Save(config dataobject.SysCronJob) int64 {
return s.cronJobDao.Insert(config)
}
// GetInfo 查询数据
func (s CronJobService) GetInfo(id int64) *entity.SysCronJob {
func (s CronJobService) GetInfo(id int64) *dataobject.SysCronJob {
return s.cronJobDao.SelectById(id)
}
// GetInfoByAlias 查询数据
func (s CronJobService) GetInfoByAlias(funcAlias string) *entity.SysCronJob {
func (s CronJobService) GetInfoByAlias(funcAlias string) *dataobject.SysCronJob {
return s.cronJobDao.SelectByFuncAlias(funcAlias)
}
// Edit 修改数据
func (s CronJobService) Edit(config entity.SysCronJob) int64 {
func (s CronJobService) Edit(config dataobject.SysCronJob) int64 {
return s.cronJobDao.Update(config)
}
@ -41,6 +41,6 @@ func (s CronJobService) Remove(list []int64) bool {
}
// FindAll 查找所有
func (s CronJobService) FindAll() ([]entity.SysCronJob, int) {
func (s CronJobService) FindAll() ([]dataobject.SysCronJob, int) {
return s.cronJobDao.SelectAll()
}

View File

@ -3,7 +3,7 @@ package service
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
type DeptService struct {
@ -12,7 +12,7 @@ type DeptService struct {
}
// TreeSelect 根据条件查询部门树
func (s DeptService) FindTreeSelect(query request.DeptQuery) *[]entity.SysDept {
func (s DeptService) FindTreeSelect(query request.DeptQuery) *[]dataobject.SysDept {
treeSelect := s.deptDao.SelectTree(query)
return treeSelect
}
@ -24,22 +24,22 @@ func (s DeptService) FindDeptListByRoleId(id int64) *[]int64 {
}
// FindDeptList 查询部门列表
func (s DeptService) FindDeptList(query request.DeptQuery) *[]entity.SysDept {
func (s DeptService) FindDeptList(query request.DeptQuery) *[]dataobject.SysDept {
return s.deptDao.GetList(query)
}
// GetDeptById 根据部门编号获取详细信息
func (s DeptService) GetDeptById(id int) *entity.SysDept {
func (s DeptService) GetDeptById(id int) *dataobject.SysDept {
return s.deptDao.SelectDeptById(id)
}
// Save 添加部门数据
func (s DeptService) Save(dept entity.SysDept) int64 {
func (s DeptService) Save(dept dataobject.SysDept) int64 {
return s.deptDao.Insert(dept)
}
// CheckDeptNameUnique 校验部门名称是否唯一
func (s DeptService) CheckDeptNameUnique(dept entity.SysDept) bool {
func (s DeptService) CheckDeptNameUnique(dept dataobject.SysDept) bool {
if s.deptDao.CheckDeptNameUnique(dept) > 0 {
return true
}
@ -62,6 +62,6 @@ func (s DeptService) CheckDeptExistUser(id int) int64 {
}
// 修改部门
func (s DeptService) Edit(dept entity.SysDept) bool {
func (s DeptService) Edit(dept dataobject.SysDept) bool {
return s.deptDao.Update(dept) > 0
}

View File

@ -4,7 +4,7 @@ import (
"cutego/modules/core/api/v1/request"
cache2 "cutego/modules/core/cache"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/pkg/constant"
)
@ -13,11 +13,11 @@ type DictDataService struct {
}
// FindByDictType 根据字典类型查询字典数据
func (s DictDataService) FindByDictType(dictType string) []entity.SysDictData {
func (s DictDataService) FindByDictType(dictType string) []dataobject.SysDictData {
// 先从缓存中拉数据
key := cache2.GetRedisDict(dictType)
if key != nil {
return key.([]entity.SysDictData)
return key.([]dataobject.SysDictData)
} else {
// 缓存中为空, 从数据库中取数据
return s.dictDataDao.SelectByDictType(dictType)
@ -25,21 +25,21 @@ func (s DictDataService) FindByDictType(dictType string) []entity.SysDictData {
}
// FindPage 查询字段数据集合
func (s DictDataService) FindPage(query request.DiceDataQuery) (*[]entity.SysDictData, int64) {
func (s DictDataService) FindPage(query request.DiceDataQuery) (*[]dataobject.SysDictData, int64) {
return s.dictDataDao.SelectPage(query)
}
// GetByCode 根据code查询字典数据
// @Param code int64
// @Return *entity.SysDictData
func (s DictDataService) GetByCode(code int64) *entity.SysDictData {
// @Return *dataobject.SysDictData
func (s DictDataService) GetByCode(code int64) *dataobject.SysDictData {
return s.dictDataDao.SelectByDictCode(code)
}
// Save 新增字典数据
// @Param data entity.SysDictData
// @Param data dataobject.SysDictData
// @Return bool
func (s DictDataService) Save(data entity.SysDictData) bool {
func (s DictDataService) Save(data dataobject.SysDictData) bool {
insert := s.dictDataDao.Insert(data)
if insert > 0 {
// 刷新缓存数据
@ -65,12 +65,12 @@ func (s DictDataService) Remove(codes []int64) bool {
// GetNoCacheByType 根据字典类型查询字典数据
// @Param dictType 字典类型
// @Return []entity.SysDictData
func (s DictDataService) GetNoCacheByType(dictType string) []entity.SysDictData {
// @Return []dataobject.SysDictData
func (s DictDataService) GetNoCacheByType(dictType string) []dataobject.SysDictData {
return s.dictDataDao.SelectByDictType(constant.RedisConst{}.GetRedisDictKey() + dictType)
}
// 修改字典数据
func (s DictDataService) Edit(data entity.SysDictData) bool {
func (s DictDataService) Edit(data dataobject.SysDictData) bool {
return s.dictDataDao.Update(data)
}

View File

@ -4,7 +4,7 @@ import (
"cutego/modules/core/api/v1/request"
cache2 "cutego/modules/core/cache"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
type DictTypeService struct {
@ -13,27 +13,27 @@ type DictTypeService struct {
}
// FindPage 分页查询字典类型数据
func (s DictTypeService) FindPage(query request.DictTypeQuery) (*[]entity.SysDictType, int64) {
func (s DictTypeService) FindPage(query request.DictTypeQuery) (*[]dataobject.SysDictType, int64) {
return s.dictTypeDao.SelectPage(query)
}
// GetById 根据id查询字典类型数据
func (s DictTypeService) GetById(id int64) *entity.SysDictType {
func (s DictTypeService) GetById(id int64) *dataobject.SysDictType {
return s.dictTypeDao.SelectById(id)
}
// CheckDictTypeUnique 检验字典类型是否存在
func (s DictTypeService) CheckDictTypeUnique(dictType entity.SysDictType) bool {
func (s DictTypeService) CheckDictTypeUnique(dictType dataobject.SysDictType) bool {
return s.dictTypeDao.CheckDictTypeUnique(dictType) > 0
}
// Edit 修改字典数据
func (s DictTypeService) Edit(dictType entity.SysDictType) bool {
func (s DictTypeService) Edit(dictType dataobject.SysDictType) bool {
return s.dictTypeDao.Update(dictType)
}
// Save 新增字典类型
func (s DictTypeService) Save(dictType entity.SysDictType) bool {
func (s DictTypeService) Save(dictType dataobject.SysDictType) bool {
insert := s.dictTypeDao.Insert(dictType)
if insert > 0 {
cache2.SetRedisDict(dictType.DictType, nil)
@ -47,7 +47,7 @@ func (s DictTypeService) Remove(ids []int64) bool {
}
// FindAll 查询所有字典类型数据
func (s DictTypeService) FindAll() []*entity.SysDictType {
func (s DictTypeService) FindAll() []*dataobject.SysDictType {
return s.dictTypeDao.SelectAll()
}
@ -72,7 +72,7 @@ func (s DictTypeService) LoadDictCache() {
}
allData := s.dictDataDao.GetDiceDataAll()
for _, key := range typeList {
list := make([]entity.SysDictData, 0)
list := make([]dataobject.SysDictData, 0)
for _, data := range *allData {
if key == data.DictType {
list = append(list, data)
@ -87,7 +87,7 @@ func (s DictTypeService) RefreshCache() {
typeList := s.RemoveAllCache()
allData := s.dictDataDao.GetDiceDataAll()
for _, key := range typeList {
list := make([]entity.SysDictData, 0)
list := make([]dataobject.SysDictData, 0)
for _, data := range *allData {
if key == data.DictType {
list = append(list, data)

View File

@ -3,7 +3,7 @@ package service
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"github.com/gin-gonic/gin"
"github.com/go-basic/uuid"
)
@ -16,12 +16,12 @@ type LogService struct {
}
// FindPage 分页查询数据
func (s LogService) FindPage(query request.LogQuery) ([]entity.SysLog, int64) {
func (s LogService) FindPage(query request.LogQuery) ([]dataobject.SysLog, int64) {
return s.logDao.SelectPage(query)
}
// Save 添加数据
func (s LogService) save(config entity.SysLog) int64 {
func (s LogService) save(config dataobject.SysLog) int64 {
return s.logDao.Insert(config)
}
@ -32,7 +32,7 @@ func (s LogService) LogToDB(c *gin.Context, content string) {
uid = DEFAULT_UID_KEY
}
uidStr := uid.(string)
s.save(entity.SysLog{Uid: uidStr, Content: content})
s.save(dataobject.SysLog{Uid: uidStr, Content: content})
}
// 开始记录日志前调用(只调用一次)

View File

@ -3,7 +3,7 @@ package service
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/pkg/config"
"github.com/gin-gonic/gin"
"github.com/yinheli/qqwry"
@ -16,12 +16,12 @@ type LoginInfoService struct {
}
// FindPage 分页查询数据
func (s LoginInfoService) FindPage(query request.LoginInfoQuery) (*[]entity.SysLoginInfo, int64) {
func (s LoginInfoService) FindPage(query request.LoginInfoQuery) (*[]dataobject.SysLoginInfo, int64) {
return s.loginInfoDao.SelectPage(query)
}
// Save 添加登录记录业务逻辑
func (s LoginInfoService) Save(body entity.SysLoginInfo) bool {
func (s LoginInfoService) Save(body dataobject.SysLoginInfo) bool {
// 添加登录记录数据库操作
user := s.loginInfoDao.Insert(body)
if user != nil {

View File

@ -4,7 +4,7 @@ import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
type MenuService struct {
@ -13,10 +13,10 @@ type MenuService struct {
}
// GetMenuTreeByUserId 根据用户ID查询菜单
func (s MenuService) GetMenuTreeByUserId(user *response.UserResponse) *[]entity.SysMenu {
var menuList *[]entity.SysMenu
func (s MenuService) GetMenuTreeByUserId(user *response.UserResponse) *[]dataobject.SysMenu {
var menuList *[]dataobject.SysMenu
// 判断是否是管理员
flag := entity.SysUser{}.IsAdmin(user.UserId)
flag := dataobject.SysUser{}.IsAdmin(user.UserId)
if flag {
menuList = s.menuDao.GetMenuAll()
} else {
@ -32,7 +32,7 @@ func (s MenuService) FindMenuListByRoleId(id int64) *[]int64 {
}
// GetMenuList 获取菜单列表
func (s MenuService) FindMenuList(query request.MenuQuery, info *response.UserResponse) *[]entity.SysMenu {
func (s MenuService) FindMenuList(query request.MenuQuery, info *response.UserResponse) *[]dataobject.SysMenu {
if info.IsAdmin() {
return s.menuDao.SelectMenuList(query)
} else {
@ -42,17 +42,17 @@ func (s MenuService) FindMenuList(query request.MenuQuery, info *response.UserRe
}
// GetMenuByMenuId 根据菜单ID查询信息
func (s MenuService) GetMenuByMenuId(id int) *entity.SysMenu {
func (s MenuService) GetMenuByMenuId(id int) *dataobject.SysMenu {
return s.menuDao.SelectMenuByMenuId(id)
}
// Save 添加菜单数据
func (s MenuService) Save(menu entity.SysMenu) int64 {
func (s MenuService) Save(menu dataobject.SysMenu) int64 {
return s.menuDao.Insert(menu)
}
// Edit 修改菜单数据
func (s MenuService) Edit(menu entity.SysMenu) int64 {
func (s MenuService) Edit(menu dataobject.SysMenu) int64 {
return s.menuDao.Update(menu)
}

View File

@ -3,7 +3,7 @@ package service
import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
type NoticeService struct {
@ -11,12 +11,12 @@ type NoticeService struct {
}
// FindPage 查询集合数据
func (s NoticeService) FindPage(query request.NoticeQuery) (*[]entity.SysNotice, int64) {
func (s NoticeService) FindPage(query request.NoticeQuery) (*[]dataobject.SysNotice, int64) {
return s.noticeDao.SelectPage(query)
}
// Save 添加公告
func (s NoticeService) Save(notice entity.SysNotice) bool {
func (s NoticeService) Save(notice dataobject.SysNotice) bool {
return s.noticeDao.Insert(notice) > 0
}
@ -26,11 +26,11 @@ func (s NoticeService) Remove(list []int64) bool {
}
// GetById 查询
func (s NoticeService) GetById(id int64) *entity.SysNotice {
func (s NoticeService) GetById(id int64) *dataobject.SysNotice {
return s.noticeDao.SelectById(id)
}
// Edit 修改
func (s NoticeService) Edit(notice entity.SysNotice) bool {
func (s NoticeService) Edit(notice dataobject.SysNotice) bool {
return s.noticeDao.Update(notice) > 0
}

View File

@ -3,7 +3,7 @@ package service
import (
"cutego/modules/core/api/v1/response"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"github.com/druidcaesa/gotool"
)
@ -14,7 +14,7 @@ type PermissionService struct {
// GetRolePermissionByUserId 查询用户角色集合
func (s PermissionService) GetRolePermissionByUserId(user *response.UserResponse) *[]string {
admin := entity.SysUser{}.IsAdmin(user.UserId)
admin := dataobject.SysUser{}.IsAdmin(user.UserId)
roleKeys := s.roleDao.SelectRolePermissionByUserId(user.UserId)
if admin && roleKeys != nil {
*roleKeys = append(*roleKeys, "admin")
@ -25,7 +25,7 @@ func (s PermissionService) GetRolePermissionByUserId(user *response.UserResponse
// GetMenuPermission 获取菜单数据权限
func (s PermissionService) GetMenuPermission(user *response.UserResponse) *[]string {
flag := entity.SysUser{}.IsAdmin(user.UserId)
flag := dataobject.SysUser{}.IsAdmin(user.UserId)
// 查询菜单数据权限
permission := s.menuDao.GetMenuPermission(user.UserId)
if flag && permission != nil {

View File

@ -4,7 +4,7 @@ import (
"bytes"
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"github.com/druidcaesa/gotool"
)
@ -13,7 +13,7 @@ type PostService struct {
}
// FindAll 查询所有岗位业务方法
func (s PostService) FindAll() []*entity.SysPost {
func (s PostService) FindAll() []*dataobject.SysPost {
return s.postDao.SelectAll()
}
@ -23,28 +23,28 @@ func (s PostService) FindPostListByUserId(userId int64) *[]int64 {
}
// FindList 查询岗位分页列表
func (s PostService) FindPage(query request.PostQuery) (*[]entity.SysPost, int64) {
func (s PostService) FindPage(query request.PostQuery) (*[]dataobject.SysPost, int64) {
return s.postDao.SelectPage(query)
}
// CheckPostNameUnique 校验岗位名称是否存在
func (s PostService) CheckPostNameUnique(post entity.SysPost) bool {
func (s PostService) CheckPostNameUnique(post dataobject.SysPost) bool {
return s.postDao.CheckPostNameUnique(post) > 0
}
// CheckPostCodeUnique 校验岗位编码是否存在
func (s PostService) CheckPostCodeUnique(post entity.SysPost) bool {
func (s PostService) CheckPostCodeUnique(post dataobject.SysPost) bool {
return s.postDao.CheckPostCodeUnique(post) > 0
}
// Save 添加岗位数据
func (s PostService) Save(post entity.SysPost) bool {
func (s PostService) Save(post dataobject.SysPost) bool {
return s.postDao.Insert(post) > 0
}
// GetPostById 根据id查询岗位数据
func (s PostService) GetPostById(id int64) *entity.SysPost {
post := entity.SysPost{
func (s PostService) GetPostById(id int64) *dataobject.SysPost {
post := dataobject.SysPost{
PostId: id,
}
return s.postDao.GetPostById(post)
@ -56,7 +56,7 @@ func (s PostService) Remove(ids []int64) bool {
}
// Edit 修改岗位数据
func (s PostService) Edit(post entity.SysPost) bool {
func (s PostService) Edit(post dataobject.SysPost) bool {
return s.postDao.Update(post)
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"cutego/modules/core/api/v1/request"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"github.com/druidcaesa/gotool"
)
@ -15,7 +15,7 @@ type RoleService struct {
}
// FindAll 查询所有角色
func (s RoleService) FindAll(query *request.RoleQuery) ([]*entity.SysRole, int64) {
func (s RoleService) FindAll(query *request.RoleQuery) ([]*dataobject.SysRole, int64) {
if query == nil {
all := s.roleDao.SelectAll()
return all, 0
@ -29,42 +29,42 @@ func (s RoleService) FindRoleListByUserId(parseInt int64) *[]int64 {
}
// GetRoleListByUserId 根据用户ID查询角色
func (s RoleService) GetRoleListByUserId(id int64) *[]entity.SysRole {
func (s RoleService) GetRoleListByUserId(id int64) *[]dataobject.SysRole {
return s.roleDao.GetRoleListByUserId(id)
}
// FindPage 分页查询角色数据
func (s RoleService) FindPage(query request.RoleQuery) ([]*entity.SysRole, int64) {
func (s RoleService) FindPage(query request.RoleQuery) ([]*dataobject.SysRole, int64) {
return s.roleDao.SelectPage(&query)
}
// GetRoleByRoleId 根据角色id查询角色数据
func (s RoleService) GetRoleByRoleId(id int64) *entity.SysRole {
func (s RoleService) GetRoleByRoleId(id int64) *dataobject.SysRole {
return s.roleDao.SelectRoleByRoleId(id)
}
// CheckRoleNameUnique 判断角色名城是否存在
func (s RoleService) CheckRoleNameUnique(role entity.SysRole) int64 {
func (s RoleService) CheckRoleNameUnique(role dataobject.SysRole) int64 {
return s.roleDao.CheckRoleNameUnique(role)
}
// CheckRoleKeyUnique 校验角色权限是否唯一
func (s RoleService) CheckRoleKeyUnique(role entity.SysRole) int64 {
func (s RoleService) CheckRoleKeyUnique(role dataobject.SysRole) int64 {
return s.roleDao.CheckRoleKeyUnique(role)
}
// Save 添加角色数据
func (s RoleService) Save(role entity.SysRole) int64 {
func (s RoleService) Save(role dataobject.SysRole) int64 {
role = s.roleDao.Insert(role)
return s.BindRoleMenu(role)
}
// 添加角色菜单关系
func (s RoleService) BindRoleMenu(role entity.SysRole) int64 {
list := make([]entity.SysRoleMenu, 0)
func (s RoleService) BindRoleMenu(role dataobject.SysRole) int64 {
list := make([]dataobject.SysRoleMenu, 0)
for _, id := range role.MenuIds {
menu := entity.SysRoleMenu{
menu := dataobject.SysRoleMenu{
RoleId: role.RoleId,
MenuId: id,
}
@ -74,7 +74,7 @@ func (s RoleService) BindRoleMenu(role entity.SysRole) int64 {
}
// Edit 修改角色数据
func (s RoleService) Edit(role entity.SysRole) int64 {
func (s RoleService) Edit(role dataobject.SysRole) int64 {
// 删除菜单关联关系
s.roleMenuDao.Delete(role)
s.BindRoleMenu(role)
@ -84,7 +84,7 @@ func (s RoleService) Edit(role entity.SysRole) int64 {
// Remove 删除角色
func (s RoleService) Remove(id int64) int64 {
role := entity.SysRole{
role := dataobject.SysRole{
RoleId: id,
}
// 删除菜单角色关系
@ -102,12 +102,12 @@ func (s RoleService) CheckRoleAllowed(id int64) (bool, string) {
}
// EditRoleStatus 角色状态修改
func (s RoleService) EditRoleStatus(role *entity.SysRole) int64 {
func (s RoleService) EditRoleStatus(role *dataobject.SysRole) int64 {
return s.roleDao.UpdateRoleStatus(role)
}
// DeleteAuthUser 取消授权用户
func (s RoleService) DeleteAuthUser(userRole entity.SysUserRole) int64 {
func (s RoleService) DeleteAuthUser(userRole dataobject.SysUserRole) int64 {
return s.userRoleDao.DeleteAuthUser(userRole)
}

View File

@ -4,7 +4,7 @@ import (
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
)
// UserService 用户操作业务逻辑
@ -25,19 +25,19 @@ func (s UserService) GetUserById(parseInt int64) *response.UserResponse {
}
// GetUserByUserName 根据用户名查询用户
func (s UserService) GetUserByUserName(name string) *entity.SysUser {
user := entity.SysUser{}
func (s UserService) GetUserByUserName(name string) *dataobject.SysUser {
user := dataobject.SysUser{}
user.UserName = name
return s.userDao.GetUserByUserName(user)
}
// CheckEmailUnique 校验邮箱是否存在
func (s UserService) CheckEmailUnique(user request.UserBody) *entity.SysUser {
func (s UserService) CheckEmailUnique(user request.UserBody) *dataobject.SysUser {
return s.userDao.CheckEmailUnique(user)
}
// CheckPhoneNumUnique 校验手机号是否存在
func (s UserService) CheckPhoneNumUnique(body request.UserBody) *entity.SysUser {
func (s UserService) CheckPhoneNumUnique(body request.UserBody) *dataobject.SysUser {
return s.userDao.CheckPhoneNumUnique(body)
}
@ -57,9 +57,9 @@ func (s UserService) Save(body request.UserBody) bool {
func (s UserService) BindUserPost(user *request.UserBody) {
postIds := user.PostIds
if len(postIds) > 0 {
sysUserPosts := make([]entity.SysUserPost, 0)
sysUserPosts := make([]dataobject.SysUserPost, 0)
for i := 0; i < len(postIds); i++ {
m := entity.SysUserPost{
m := dataobject.SysUserPost{
UserId: user.UserId,
PostId: postIds[i],
}
@ -73,9 +73,9 @@ func (s UserService) BindUserPost(user *request.UserBody) {
func (s UserService) BindUserRole(user *request.UserBody) {
roleIds := user.RoleIds
if len(roleIds) > 0 {
roles := make([]entity.SysUserRole, 0)
roles := make([]dataobject.SysUserRole, 0)
for i := 0; i < len(roleIds); i++ {
role := entity.SysUserRole{
role := dataobject.SysUserRole{
RoleId: roleIds[i],
UserId: user.UserId,
}
@ -111,7 +111,7 @@ func (s UserService) Remove(id int64) int64 {
// CheckUserAllowed 校验是否可以修改用户密码
func (s UserService) CheckUserAllowed(body request.UserBody) bool {
user := entity.SysUser{}
user := dataobject.SysUser{}
return user.IsAdmin(body.UserId)
}

View File

@ -0,0 +1,19 @@
package dataobject
import (
"time"
)
type Student struct {
Id int64 `xorm:"pk autoincr not null bigint 'id'"`
CreateBy string `xorm:"default 'NULL' varchar(255) 'create_by'"`
CreateTime time.Time `xorm:"default 'NULL' datetime 'create_time'"`
UpdateBy string `xorm:"default 'NULL' varchar(255) 'update_by'"`
UpdateTime time.Time `xorm:"default 'NULL' datetime 'update_time'"`
Name string `xorm:"default 'NULL' varchar(255) 'name'"`
Sex string `xorm:"default 'NULL' varchar(255) 'sex'"`
}
func (s *Student) TableName() string {
return "student"
}

View File

@ -1,7 +1,8 @@
package dao
package modules
import (
models2 "cutego/modules/core/entity"
"cutego/modules/core/dao"
models2 "cutego/modules/core/dataobject"
"cutego/pkg/common"
"cutego/pkg/config"
"cutego/pkg/constant"
@ -70,10 +71,10 @@ func cacheInitDataToRedis() {
func initDict() {
// 查询字典类型数据
dictTypeDao := new(DictTypeDao)
dictTypeDao := new(dao.DictTypeDao)
typeAll := dictTypeDao.SelectAll()
// 所有字典数据
d := new(DictDataDao)
d := new(dao.DictDataDao)
listData := d.GetDiceDataAll()
for _, dictType := range typeAll {
dictData := make([]map[string]interface{}, 0)
@ -95,8 +96,7 @@ func initDict() {
func initConfig() {
// 查询配置数据存入到缓存中
configDao := new(ConfigDao)
configSession := configDao.sql(SqlDB.NewSession())
configSession := SqlDB.NewSession().Table("sys_config")
configs := make([]*models2.SysConfig, 0)
err := configSession.Find(&configs)
if err != nil {

12
pkg/cache/index.go vendored
View File

@ -1,7 +1,7 @@
package cache
import (
"cutego/modules/core/dao"
"cutego/modules"
"cutego/pkg/common"
"cutego/pkg/constant"
)
@ -9,14 +9,14 @@ import (
// RemoveList 批量根据Key删除数据
// @Param list []string 键合集
func RemoveList(list []string) {
dao.RedisDB.DELALL(list)
modules.RedisDB.DELALL(list)
}
// RemoveKey 根据key删除
// @Param key 键
// @Return int 删除的数量
func RemoveCache(key string) int {
del, err := dao.RedisDB.DEL(key)
del, err := modules.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 := dao.RedisDB.GET(key)
val, err := modules.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 := dao.RedisDB.SET(key, common.StructToJson(value))
n, err := modules.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) {
dao.RedisDB.SETEX(key, sec, common.StructToJson(value))
modules.RedisDB.SETEX(key, sec, common.StructToJson(value))
}

View File

@ -150,7 +150,7 @@ func StructToJson(v interface{}) string {
// 切片(interface{}.(期望类型))
// s := make([]interface {}, 0)
// target := common.JsonToStruct(get, s)
// target.([]entity.SysDictData)
// target.([]dataobject.SysDictData)
//
// @Param data Json字符串
// @Param s 容器(结构体、Map等)

View File

@ -1,8 +1,8 @@
package jwt
import (
"cutego/modules"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/dao"
"cutego/pkg/cache"
"cutego/pkg/config"
"errors"
@ -52,7 +52,7 @@ func JWTAuth() gin.HandlerFunc {
}
singleTag := config.AppEnvConfig.Login.Single
if singleTag {
token, err := dao.RedisDB.GET(claims.UserInfo.UserName)
token, err := modules.RedisDB.GET(claims.UserInfo.UserName)
if err == nil {
if !(token == currentTokenStr) {
c.JSON(http.StatusOK, gin.H{

View File

@ -1,7 +1,7 @@
package tree_dept
import (
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"sort"
)
@ -201,10 +201,10 @@ func nodePartialSelected(trees []Tree) bool {
return true
}
type DeptList []entity.SysDept
type DeptList []dataobject.SysDept
// ConvertToINodeArray 将当前数组转换成父类 INode 接口 数组
func (s DeptList) ConvertToINodeArray(*[]entity.SysDept) (nodes []INode) {
func (s DeptList) ConvertToINodeArray(*[]dataobject.SysDept) (nodes []INode) {
for _, v := range s {
nodes = append(nodes, v)
}
@ -212,7 +212,7 @@ func (s DeptList) ConvertToINodeArray(*[]entity.SysDept) (nodes []INode) {
}
// GetTree 获取树结构
func (s DeptList) GetTree(treeSelect *[]entity.SysDept) []Tree {
func (s DeptList) GetTree(treeSelect *[]dataobject.SysDept) []Tree {
s = *treeSelect
array := s.ConvertToINodeArray(treeSelect)
return GenerateTree(array, nil)

View File

@ -1,7 +1,7 @@
package tree_menu
import (
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"github.com/druidcaesa/gotool"
"sort"
)
@ -74,7 +74,7 @@ func GenerateTree(nodes, selectedNodes []INode) (trees []Tree) {
var component = "Layout"
m := make(map[string]interface{})
if v.GetData() != nil {
menu := v.GetData().(entity.SysMenu)
menu := v.GetData().(dataobject.SysMenu)
m["title"] = menu.MenuName
m["icon"] = menu.Icon
m["noCache"] = menu.IsCache == 1
@ -133,7 +133,7 @@ func recursiveTree(tree *Tree, nodes, selectedNodes []INode) {
var component = "Layout"
m := make(map[string]interface{})
if v.GetData() != nil {
menu := v.GetData().(entity.SysMenu)
menu := v.GetData().(dataobject.SysMenu)
flag = menu.Visible == "1"
m["title"] = menu.MenuName
m["icon"] = menu.Icon
@ -265,10 +265,10 @@ func nodePartialSelected(trees []Tree) bool {
return true
}
type SystemMenus []entity.SysMenu
type SystemMenus []dataobject.SysMenu
// ConvertToINodeArray 将当前数组转换成父类 INode 接口 数组
func (s SystemMenus) ConvertToINodeArray(*[]entity.SysMenu) (nodes []INode) {
func (s SystemMenus) ConvertToINodeArray(*[]dataobject.SysMenu) (nodes []INode) {
for _, v := range s {
nodes = append(nodes, v)
}
@ -276,7 +276,7 @@ func (s SystemMenus) ConvertToINodeArray(*[]entity.SysMenu) (nodes []INode) {
}
// GetTree 获取树结构数据
func (s SystemMenus) GetTree(m *[]entity.SysMenu) []Tree {
func (s SystemMenus) GetTree(m *[]dataobject.SysMenu) []Tree {
s = *m
array := s.ConvertToINodeArray(m)
return GenerateTree(array, nil)

View File

@ -1,9 +1,9 @@
package util
import (
"cutego/modules"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/dao"
"cutego/modules/core/entity"
"cutego/modules/core/dataobject"
"cutego/pkg/common"
"cutego/pkg/config"
"cutego/pkg/jwt"
@ -32,7 +32,7 @@ func CheckLockToken(c *gin.Context) bool {
if config.AppEnvConfig.Login.Single {
// 获取redis中的token数据
info := GetUserInfo(c)
get, err := dao.RedisDB.GET(info.UserName)
get, err := modules.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 *entity.SysUser) bool {
func CheckIsAdmin(user *dataobject.SysUser) bool {
if user.UserId == 1 {
return true
} else {