mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: 代码重构、分页数据组件支持多选
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils"
|
||||
@@ -40,7 +41,7 @@ func (d *Db) Dbs(rc *req.Ctx) {
|
||||
// 不存在可访问标签id,即没有可操作数据
|
||||
tagIds := d.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||
if len(tagIds) == 0 {
|
||||
rc.ResData = model.EmptyPageResult()
|
||||
rc.ResData = model.EmptyPageResult[any]()
|
||||
return
|
||||
}
|
||||
condition.TagIds = tagIds
|
||||
@@ -96,10 +97,18 @@ func (d *Db) GetDatabaseNames(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (d *Db) DeleteDb(rc *req.Ctx) {
|
||||
dbId := GetDbId(rc.GinCtx)
|
||||
d.DbApp.Delete(dbId)
|
||||
// 删除该库的sql执行记录
|
||||
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "dbId")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
dbId := uint64(value)
|
||||
d.DbApp.Delete(dbId)
|
||||
// 删除该库的sql执行记录
|
||||
d.DbSqlExecApp.DeleteBy(&entity.DbSqlExec{DbId: dbId})
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Db) TableInfos(rc *req.Ctx) {
|
||||
@@ -381,21 +390,21 @@ func (d *Db) SaveSql(rc *req.Ctx) {
|
||||
|
||||
dbId := GetDbId(g)
|
||||
// 判断dbId是否存在
|
||||
err := model.GetById(new(entity.Db), dbId)
|
||||
err := gormx.GetById(new(entity.Db), dbId)
|
||||
biz.ErrIsNil(err, "该数据库信息不存在")
|
||||
|
||||
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
||||
dbSql := &entity.DbSql{Type: dbSqlForm.Type, DbId: dbId, Name: dbSqlForm.Name, Db: dbSqlForm.Db}
|
||||
dbSql.CreatorId = account.Id
|
||||
e := model.GetBy(dbSql)
|
||||
e := gormx.GetBy(dbSql)
|
||||
|
||||
dbSql.SetBaseInfo(account)
|
||||
// 更新sql信息
|
||||
dbSql.Sql = dbSqlForm.Sql
|
||||
if e == nil {
|
||||
model.UpdateById(dbSql)
|
||||
gormx.UpdateById(dbSql)
|
||||
} else {
|
||||
model.Insert(dbSql)
|
||||
gormx.Insert(dbSql)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +415,7 @@ func (d *Db) GetSqlNames(rc *req.Ctx) {
|
||||
dbSql := &entity.DbSql{Type: 1, DbId: id, Db: db}
|
||||
dbSql.CreatorId = rc.LoginAccount.Id
|
||||
var sqls []entity.DbSql
|
||||
model.ListBy(dbSql, &sqls, "id", "name")
|
||||
gormx.ListBy(dbSql, &sqls, "id", "name")
|
||||
|
||||
rc.ResData = sqls
|
||||
}
|
||||
@@ -418,7 +427,7 @@ func (d *Db) DeleteSql(rc *req.Ctx) {
|
||||
dbSql.Name = rc.GinCtx.Query("name")
|
||||
dbSql.Db = rc.GinCtx.Query("db")
|
||||
|
||||
model.DeleteByCondition(dbSql)
|
||||
gormx.DeleteByCondition(dbSql)
|
||||
|
||||
}
|
||||
|
||||
@@ -430,7 +439,7 @@ func (d *Db) GetSql(rc *req.Ctx) {
|
||||
dbSql.CreatorId = rc.LoginAccount.Id
|
||||
dbSql.Name = rc.GinCtx.Query("name")
|
||||
|
||||
e := model.GetBy(dbSql)
|
||||
e := gormx.GetBy(dbSql)
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
type Db interface {
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Count(condition *entity.DbQuery) int64
|
||||
|
||||
@@ -58,7 +58,7 @@ type dbAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ type DbSqlExec interface {
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
}
|
||||
|
||||
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
|
||||
@@ -151,7 +151,7 @@ func (d *dbSqlExecAppImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
d.dbSqlExecRepo.DeleteBy(condition)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Db interface {
|
||||
// 分页获取机器信息列表
|
||||
GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Count(condition *entity.DbQuery) int64
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@ type DbSqlExec interface {
|
||||
DeleteBy(condition *entity.DbSqlExec)
|
||||
|
||||
// 分页获取
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type dbRepoImpl struct{}
|
||||
@@ -17,27 +15,14 @@ func newDbRepo() repository.Db {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_db d WHERE 1 = 1 "
|
||||
|
||||
values := make([]any, 0)
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE ?"
|
||||
values = append(values, "%"+condition.Host+"%")
|
||||
}
|
||||
if condition.Database != "" {
|
||||
sql = sql + " AND d.database LIKE ?"
|
||||
values = append(values, "%"+condition.Database+"%")
|
||||
}
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
|
||||
}
|
||||
if condition.TagPathLike != "" {
|
||||
sql = sql + " AND d.tag_path LIKE ?"
|
||||
values = append(values, "%"+condition.TagPathLike+"%")
|
||||
}
|
||||
sql = sql + " ORDER BY d.tag_path"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(new(entity.Db)).
|
||||
Like("host", condition.Host).
|
||||
Like("database", condition.Database).
|
||||
In("tag_id", condition.TagIds).
|
||||
RLike("tag_path", condition.TagPathLike).
|
||||
OrderByAsc("tag_path")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
||||
@@ -48,18 +33,18 @@ func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
||||
if condition.TagId != 0 {
|
||||
where["tag_id"] = condition.TagId
|
||||
}
|
||||
return model.CountByMap(new(entity.Db), where)
|
||||
return gormx.CountByCond(new(entity.Db), where)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (d *dbRepoImpl) GetDb(condition *entity.Db, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
||||
db := new(entity.Db)
|
||||
if err := model.GetById(db, id, cols...); err != nil {
|
||||
if err := gormx.GetById(db, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -67,13 +52,13 @@ func (d *dbRepoImpl) GetById(id uint64, cols ...string) *entity.Db {
|
||||
}
|
||||
|
||||
func (d *dbRepoImpl) Insert(db *entity.Db) {
|
||||
biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
|
||||
biz.ErrIsNil(gormx.Insert(db), "新增数据库信息失败")
|
||||
}
|
||||
|
||||
func (d *dbRepoImpl) Update(db *entity.Db) {
|
||||
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(db), "更新数据库信息失败")
|
||||
}
|
||||
|
||||
func (d *dbRepoImpl) Delete(id uint64) {
|
||||
model.DeleteById(new(entity.Db), id)
|
||||
gormx.DeleteById(new(entity.Db), id)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/gormx"
|
||||
)
|
||||
|
||||
type dbSqlRepoImpl struct{}
|
||||
@@ -15,5 +15,5 @@ func newDbSqlRepo() repository.DbSql {
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbSqlRepoImpl) DeleteBy(condition *entity.DbSql) {
|
||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql失败")
|
||||
biz.ErrIsNil(gormx.DeleteByCondition(condition), "删除sql失败")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -14,14 +15,15 @@ func newDbSqlExecRepo() repository.DbSqlExec {
|
||||
}
|
||||
|
||||
func (d *dbSqlExecRepoImpl) Insert(dse *entity.DbSqlExec) {
|
||||
model.Insert(dse)
|
||||
gormx.Insert(dse)
|
||||
}
|
||||
|
||||
func (d *dbSqlExecRepoImpl) DeleteBy(condition *entity.DbSqlExec) {
|
||||
biz.ErrIsNil(model.DeleteByCondition(condition), "删除sql执行记录失败")
|
||||
biz.ErrIsNil(gormx.DeleteByCondition(condition), "删除sql执行记录失败")
|
||||
}
|
||||
|
||||
// 分页获取
|
||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import (
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AuthCert struct {
|
||||
@@ -58,5 +61,13 @@ func (c *AuthCert) SaveAuthCert(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (c *AuthCert) Delete(rc *req.Ctx) {
|
||||
c.AuthCertApp.DeleteById(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
c.AuthCertApp.DeleteById(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -40,19 +41,18 @@ func (m *Machine) Machines(rc *req.Ctx) {
|
||||
// 不存在可访问标签id,即没有可操作数据
|
||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||
if len(tagIds) == 0 {
|
||||
rc.ResData = model.EmptyPageResult()
|
||||
rc.ResData = model.EmptyPageResult[any]()
|
||||
return
|
||||
}
|
||||
condition.TagIds = tagIds
|
||||
|
||||
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
|
||||
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]vo.MachineVO))
|
||||
if res.Total == 0 {
|
||||
rc.ResData = res
|
||||
return
|
||||
}
|
||||
|
||||
list := res.List.(*[]*vo.MachineVO)
|
||||
for _, mv := range *list {
|
||||
for _, mv := range *res.List {
|
||||
mv.HasCli = machine.HasCli(mv.Id)
|
||||
}
|
||||
rc.ResData = res
|
||||
@@ -99,9 +99,15 @@ func (m *Machine) ChangeStatus(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *Machine) DeleteMachine(rc *req.Ctx) {
|
||||
id := uint64(ginx.PathParamInt(rc.GinCtx, "machineId"))
|
||||
rc.ReqParam = id
|
||||
m.MachineApp.Delete(id)
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "machineId")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
m.MachineApp.Delete(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭机器客户端
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type AuthCert interface {
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Save(ac *entity.AuthCert)
|
||||
|
||||
@@ -29,7 +29,7 @@ type authCertAppImpl struct {
|
||||
authCertRepo repository.AuthCert
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return a.authCertRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -30,7 +32,7 @@ type Machine interface {
|
||||
GetById(id uint64, cols ...string) *entity.Machine
|
||||
|
||||
// 分页获取机器信息列表
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO]
|
||||
|
||||
// 获取机器连接
|
||||
GetCli(id uint64) *machine.Cli
|
||||
@@ -52,7 +54,7 @@ type machineAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO] {
|
||||
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -109,7 +111,7 @@ func (m *machineAppImpl) ChangeStatus(id uint64, status int8) {
|
||||
func (m *machineAppImpl) Delete(id uint64) {
|
||||
// 关闭连接
|
||||
machine.DeleteCli(id)
|
||||
model.Tx(
|
||||
gormx.Tx(
|
||||
func(db *gorm.DB) error {
|
||||
// 删除machine表信息
|
||||
return db.Delete(new(entity.Machine), "id = ?", id).Error
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/internal/machine/infrastructure/machine"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
|
||||
type MachineFile interface {
|
||||
// 分页获取机器文件信息列表
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineFile(condition *entity.MachineFile, cols ...string) error
|
||||
@@ -67,7 +68,7 @@ type machineFileAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return m.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -86,9 +87,9 @@ func (m *machineFileAppImpl) Save(entity *entity.MachineFile) {
|
||||
biz.NotNil(m.machineRepo.GetById(entity.MachineId, "Name"), "该机器不存在")
|
||||
|
||||
if entity.Id != 0 {
|
||||
model.UpdateById(entity)
|
||||
gormx.UpdateById(entity)
|
||||
} else {
|
||||
model.Insert(entity)
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type MachineScript interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
||||
@@ -40,7 +41,7 @@ const Common_Script_Machine_Id = 9999999
|
||||
// machineScriptRepo: persistence.MachineScriptDao}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return m.machineScriptRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -62,9 +63,9 @@ func (m *machineScriptAppImpl) Save(entity *entity.MachineScript) {
|
||||
}
|
||||
|
||||
if entity.Id != 0 {
|
||||
model.UpdateById(entity)
|
||||
gormx.UpdateById(entity)
|
||||
} else {
|
||||
model.Insert(entity)
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type AuthCert interface {
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Insert(ac *entity.AuthCert)
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type Machine interface {
|
||||
// 分页获取机器信息列表
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO]
|
||||
|
||||
Count(condition *entity.MachineQuery) int64
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type MachineFile interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineFile(condition *entity.MachineFile, cols ...string) error
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type MachineScript interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
// 根据条件获取
|
||||
GetMachineScript(condition *entity.MachineScript, cols ...string) error
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type MachineTaskConfig interface {
|
||||
GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MachineTaskConfig, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
// 根据条件获取
|
||||
GetBy(condition *entity.MachineTaskConfig, cols ...string) error
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -13,21 +14,22 @@ func newAuthCertRepo() repository.AuthCert {
|
||||
return new(authCertRepoImpl)
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCert, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) Insert(ac *entity.AuthCert) {
|
||||
biz.ErrIsNil(model.Insert(ac), "新增授权凭证失败")
|
||||
biz.ErrIsNil(gormx.Insert(ac), "新增授权凭证失败")
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) Update(ac *entity.AuthCert) {
|
||||
biz.ErrIsNil(model.UpdateById(ac), "更新授权凭证失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(ac), "更新授权凭证失败")
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
|
||||
ac := new(entity.AuthCert)
|
||||
err := model.GetById(ac, id)
|
||||
err := gormx.GetById(ac, id)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -36,14 +38,14 @@ func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
|
||||
|
||||
func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
||||
acs := new([]*entity.AuthCert)
|
||||
model.GetByIdIn(new(entity.AuthCert), acs, ids)
|
||||
gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
|
||||
return *acs
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetByCondition(condition *entity.AuthCert, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) DeleteById(id uint64) {
|
||||
model.DeleteById(new(entity.AuthCert), id)
|
||||
gormx.DeleteById(new(entity.AuthCert), id)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -15,28 +16,14 @@ func newMachineRepo() repository.Machine {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT m.* FROM t_machine m WHERE 1 = 1 "
|
||||
|
||||
values := make([]any, 0)
|
||||
if condition.Ip != "" {
|
||||
sql = sql + " AND m.ip LIKE ?"
|
||||
values = append(values, "%"+condition.Ip+"%")
|
||||
}
|
||||
if condition.Name != "" {
|
||||
sql = sql + " AND m.name LIKE ?"
|
||||
values = append(values, "%"+condition.Name+"%")
|
||||
}
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = fmt.Sprintf("%s AND m.tag_id IN ? ", sql)
|
||||
values = append(values, condition.TagIds)
|
||||
}
|
||||
if condition.TagPathLike != "" {
|
||||
sql = sql + " AND m.tag_path LIKE ?"
|
||||
values = append(values, condition.TagPathLike+"%")
|
||||
}
|
||||
sql = sql + " ORDER BY m.tag_path"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO] {
|
||||
qd := gormx.NewQuery(new(entity.Machine)).
|
||||
Like("ip", condition.Ip).
|
||||
Like("name", condition.Name).
|
||||
In("tag_id", condition.TagIds).
|
||||
RLike("tag_path", condition.TagPathLike).
|
||||
OrderByAsc("tag_path")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
||||
@@ -48,18 +35,18 @@ func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
||||
where["tag_id"] = condition.TagId
|
||||
}
|
||||
|
||||
return model.CountByMap(new(entity.Machine), where)
|
||||
return gormx.CountByCond(new(entity.Machine), where)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
machine := new(entity.Machine)
|
||||
if err := model.GetById(machine, id, cols...); err != nil {
|
||||
if err := gormx.GetById(machine, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -67,9 +54,9 @@ func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) Create(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(entity), "创建机器信息失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(entity), "创建机器信息失败: %s")
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.UpdateById(entity), "更新机器信息失败: %s")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -14,19 +15,20 @@ func newMachineFileRepo() repository.MachineFile {
|
||||
}
|
||||
|
||||
// 分页获取机器文件信息列表
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineFileRepoImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.MachineFile {
|
||||
ms := new(entity.MachineFile)
|
||||
if err := model.GetById(ms, id, cols...); err != nil {
|
||||
if err := gormx.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -35,13 +37,13 @@ func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.Machine
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineFile), id), "删除失败")
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineFile), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) {
|
||||
model.Insert(entity)
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
|
||||
model.UpdateById(entity)
|
||||
gormx.UpdateById(entity)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -14,19 +15,20 @@ func newMachineScriptRepo() repository.MachineScript {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
||||
ms := new(entity.MachineScript)
|
||||
if err := model.GetById(ms, id, cols...); err != nil {
|
||||
if err := gormx.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -35,13 +37,13 @@ func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.Machi
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.MachineScript), id), "删除失败")
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineScript), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineScriptRepoImpl) Create(entity *entity.MachineScript) {
|
||||
model.Insert(entity)
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
|
||||
model.UpdateById(entity)
|
||||
gormx.UpdateById(entity)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"mayfly-go/pkg/utils"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@@ -32,7 +33,7 @@ func (m *Mongo) Mongos(rc *req.Ctx) {
|
||||
// 不存在可访问标签id,即没有可操作数据
|
||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||
if len(tagIds) == 0 {
|
||||
rc.ResData = model.EmptyPageResult()
|
||||
rc.ResData = model.EmptyPageResult[any]()
|
||||
return
|
||||
}
|
||||
condition.TagIds = tagIds
|
||||
@@ -58,7 +59,15 @@ func (m *Mongo) Save(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *Mongo) DeleteMongo(rc *req.Ctx) {
|
||||
m.MongoApp.Delete(m.GetMongoId(rc.GinCtx))
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
m.MongoApp.Delete(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mongo) Databases(rc *req.Ctx) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
type Mongo interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Count(condition *entity.MongoQuery) int64
|
||||
|
||||
@@ -54,7 +54,7 @@ type mongoAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return d.mongoRepo.GetList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Mongo interface {
|
||||
// 分页获取列表
|
||||
GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Count(condition *entity.MongoQuery) int64
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/mongo/domain/entity"
|
||||
"mayfly-go/internal/mongo/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type mongoRepoImpl struct{}
|
||||
@@ -17,20 +15,13 @@ func newMongoRepo() repository.Mongo {
|
||||
}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_mongo d WHERE 1=1 "
|
||||
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
|
||||
}
|
||||
|
||||
values := make([]any, 0)
|
||||
if condition.TagPathLike != "" {
|
||||
values = append(values, condition.TagPathLike+"%")
|
||||
sql = sql + " AND d.tag_path LIKE ?"
|
||||
}
|
||||
sql = sql + " ORDER BY d.tag_path"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(new(entity.Mongo)).
|
||||
Like("name", condition.Name).
|
||||
In("tag_id", condition.TagIds).
|
||||
RLike("tag_path", condition.TagPathLike).
|
||||
OrderByAsc("tag_path")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
||||
@@ -41,18 +32,18 @@ func (d *mongoRepoImpl) Count(condition *entity.MongoQuery) int64 {
|
||||
if condition.TagId != 0 {
|
||||
where["tag_id"] = condition.TagId
|
||||
}
|
||||
return model.CountByMap(new(entity.Mongo), where)
|
||||
return gormx.CountByCond(new(entity.Mongo), where)
|
||||
}
|
||||
|
||||
// 根据条件获取
|
||||
func (d *mongoRepoImpl) Get(condition *entity.Mongo, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
||||
db := new(entity.Mongo)
|
||||
if err := model.GetById(db, id, cols...); err != nil {
|
||||
if err := gormx.GetById(db, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -60,13 +51,13 @@ func (d *mongoRepoImpl) GetById(id uint64, cols ...string) *entity.Mongo {
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Insert(db *entity.Mongo) {
|
||||
biz.ErrIsNil(model.Insert(db), "新增mongo信息失败")
|
||||
biz.ErrIsNil(gormx.Insert(db), "新增mongo信息失败")
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Update(db *entity.Mongo) {
|
||||
biz.ErrIsNil(model.UpdateById(db), "更新mongo信息失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(db), "更新mongo信息失败")
|
||||
}
|
||||
|
||||
func (d *mongoRepoImpl) Delete(id uint64) {
|
||||
model.DeleteById(new(entity.Mongo), id)
|
||||
gormx.DeleteById(new(entity.Mongo), id)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -30,7 +31,7 @@ func (r *Redis) RedisList(rc *req.Ctx) {
|
||||
// 不存在可访问标签id,即没有可操作数据
|
||||
tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||
if len(tagIds) == 0 {
|
||||
rc.ResData = model.EmptyPageResult()
|
||||
rc.ResData = model.EmptyPageResult[any]()
|
||||
return
|
||||
}
|
||||
condition.TagIds = tagIds
|
||||
@@ -66,7 +67,15 @@ func (r *Redis) GetRedisPwd(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (r *Redis) DeleteRedis(rc *req.Ctx) {
|
||||
r.RedisApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
r.RedisApp.Delete(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Redis) RedisInfo(rc *req.Ctx) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
type Redis interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Count(condition *entity.RedisQuery) int64
|
||||
|
||||
@@ -55,7 +55,7 @@ type redisAppImpl struct {
|
||||
}
|
||||
|
||||
// 分页获取机器脚本信息列表
|
||||
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Redis interface {
|
||||
// 分页获取机器信息列表
|
||||
GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Count(condition *entity.RedisQuery) int64
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/redis/domain/entity"
|
||||
"mayfly-go/internal/redis/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type redisRepoImpl struct{}
|
||||
@@ -17,22 +15,13 @@ func newRedisRepo() repository.Redis {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_redis d WHERE 1=1 "
|
||||
values := make([]any, 0)
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE ?"
|
||||
values = append(values, "%"+condition.Host+"%")
|
||||
}
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
|
||||
}
|
||||
if condition.TagPathLike != "" {
|
||||
sql = sql + " AND d.tag_path LIKE ?"
|
||||
values = append(values, condition.TagPathLike+"%")
|
||||
}
|
||||
sql = sql + " ORDER BY d.tag_path"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(new(entity.Redis)).
|
||||
Like("host", condition.Host).
|
||||
In("tag_id", condition.TagIds).
|
||||
RLike("tag_path", condition.TagPathLike).
|
||||
OrderByAsc("tag_path")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
||||
@@ -44,30 +33,30 @@ func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
||||
where["tag_id"] = condition.TagId
|
||||
}
|
||||
|
||||
return model.CountByMap(new(entity.Redis), where)
|
||||
return gormx.CountByCond(new(entity.Redis), where)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
|
||||
rd := new(entity.Redis)
|
||||
if err := model.GetById(rd, id, cols...); err != nil {
|
||||
if err := gormx.GetById(rd, id, cols...); err != nil {
|
||||
return nil
|
||||
}
|
||||
return rd
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) GetRedis(condition *entity.Redis, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Insert(redis *entity.Redis) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(redis), "新增失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(redis), "新增失败: %s")
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Update(redis *entity.Redis) {
|
||||
biz.ErrIsNilAppendErr(model.UpdateById(redis), "更新失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.UpdateById(redis), "更新失败: %s")
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNilAppendErr(model.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
||||
}
|
||||
|
||||
@@ -345,9 +345,15 @@ func (a *Account) ChangeStatus(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (a *Account) DeleteAccount(rc *req.Ctx) {
|
||||
id := uint64(ginx.PathParamInt(rc.GinCtx, "id"))
|
||||
rc.ReqParam = id
|
||||
a.AccountApp.Delete(id)
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
a.AccountApp.Delete(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
// 获取账号角色id列表,用户回显角色分配
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"mayfly-go/internal/sys/api/vo"
|
||||
"mayfly-go/internal/sys/application"
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils"
|
||||
@@ -40,7 +41,15 @@ func (r *Role) SaveRole(rc *req.Ctx) {
|
||||
|
||||
// 删除角色及其资源关联关系
|
||||
func (r *Role) DelRole(rc *req.Ctx) {
|
||||
r.RoleApp.DeleteRole(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
r.RoleApp.DeleteRole(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
// 获取角色关联的资源id数组,用于分配资源时回显已拥有的资源
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
type Account interface {
|
||||
GetAccount(condition *entity.Account, cols ...string) error
|
||||
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Create(account *entity.Account)
|
||||
|
||||
@@ -37,7 +38,7 @@ func (a *accountAppImpl) GetAccount(condition *entity.Account, cols ...string) e
|
||||
return a.accountRepo.GetAccount(condition, cols...)
|
||||
}
|
||||
|
||||
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return a.accountRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ func (a *accountAppImpl) Update(account *entity.Account) {
|
||||
}
|
||||
|
||||
func (a *accountAppImpl) Delete(id uint64) {
|
||||
err := model.Tx(
|
||||
err := gormx.Tx(
|
||||
func(db *gorm.DB) error {
|
||||
// 删除account表信息
|
||||
return db.Delete(new(entity.Account), "id = ?", id).Error
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
const SysConfigKeyPrefix = "sys:config:"
|
||||
|
||||
type Config interface {
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Save(config *entity.Config)
|
||||
|
||||
@@ -31,7 +31,7 @@ type configAppImpl struct {
|
||||
configRepo repository.Config
|
||||
}
|
||||
|
||||
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return a.configRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Create(msg *entity.Msg)
|
||||
|
||||
@@ -27,7 +27,7 @@ type msgAppImpl struct {
|
||||
msgRepo repository.Msg
|
||||
}
|
||||
|
||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -16,8 +16,6 @@ type Resource interface {
|
||||
|
||||
GetById(id uint64, cols ...string) *entity.Resource
|
||||
|
||||
GetByIdIn(ids []uint64, toEntity any, cols ...string)
|
||||
|
||||
Save(entity *entity.Resource)
|
||||
|
||||
ChangeStatus(resourceId uint64, status int8)
|
||||
@@ -47,10 +45,6 @@ func (r *resourceAppImpl) GetById(id uint64, cols ...string) *entity.Resource {
|
||||
return r.resourceRepo.GetById(id, cols...)
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) GetByIdIn(ids []uint64, toEntity any, orderBy ...string) {
|
||||
r.resourceRepo.GetByIdIn(ids, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) Save(resource *entity.Resource) {
|
||||
// 更新操作
|
||||
if resource.Id != 0 {
|
||||
@@ -61,7 +55,7 @@ func (r *resourceAppImpl) Save(resource *entity.Resource) {
|
||||
r.checkCode(resource.Code)
|
||||
}
|
||||
}
|
||||
model.UpdateById(resource)
|
||||
gormx.UpdateById(resource)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -80,7 +74,7 @@ func (r *resourceAppImpl) Save(resource *entity.Resource) {
|
||||
}
|
||||
r.checkCode(resource.Code)
|
||||
resource.Weight = int(time.Now().Unix())
|
||||
model.Insert(resource)
|
||||
gormx.Insert(resource)
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) ChangeStatus(resourceId uint64, status int8) {
|
||||
@@ -148,7 +142,7 @@ func (r *resourceAppImpl) Sort(sortResource *entity.Resource) {
|
||||
|
||||
func (r *resourceAppImpl) checkCode(code string) {
|
||||
biz.IsTrue(!strings.Contains(code, ","), "code不能包含','")
|
||||
biz.IsEquals(model.CountBy(&entity.Resource{Code: code}), int64(0), "该code已存在")
|
||||
biz.IsEquals(gormx.CountBy(&entity.Resource{Code: code}), int64(0), "该code已存在")
|
||||
}
|
||||
|
||||
func (r *resourceAppImpl) Delete(id uint64) {
|
||||
@@ -160,7 +154,7 @@ func (r *resourceAppImpl) Delete(id uint64) {
|
||||
for _, v := range children {
|
||||
r.resourceRepo.Delete(v.Id)
|
||||
// 删除角色关联的资源信息
|
||||
model.DeleteByCondition(&entity.RoleResource{ResourceId: v.Id})
|
||||
gormx.DeleteByCondition(&entity.RoleResource{ResourceId: v.Id})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@ package application
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Role interface {
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
SaveRole(role *entity.Role)
|
||||
|
||||
@@ -45,7 +46,7 @@ type roleAppImpl struct {
|
||||
roleRepo repository.Role
|
||||
}
|
||||
|
||||
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return m.roleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -54,17 +55,17 @@ func (m *roleAppImpl) SaveRole(role *entity.Role) {
|
||||
if role.Id != 0 {
|
||||
// code不可更改,防止误传
|
||||
role.Code = ""
|
||||
model.UpdateById(role)
|
||||
gormx.UpdateById(role)
|
||||
} else {
|
||||
role.Status = 1
|
||||
model.Insert(role)
|
||||
gormx.Insert(role)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *roleAppImpl) DeleteRole(id uint64) {
|
||||
m.roleRepo.Delete(id)
|
||||
// 删除角色与资源的关联关系
|
||||
model.DeleteByCondition(&entity.RoleResource{RoleId: id})
|
||||
gormx.DeleteByCondition(&entity.RoleResource{RoleId: id})
|
||||
}
|
||||
|
||||
func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type Syslog interface {
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
// 从请求上下文的参数保存系统日志
|
||||
SaveFromReq(req *req.Ctx)
|
||||
@@ -29,7 +29,7 @@ type syslogAppImpl struct {
|
||||
syslogRepo repository.Syslog
|
||||
}
|
||||
|
||||
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ type Account interface {
|
||||
// 根据条件获取账号信息
|
||||
GetAccount(condition *entity.Account, cols ...string) error
|
||||
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Insert(account *entity.Account)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Insert(config *entity.Config)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Insert(msg *entity.Msg)
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ type Resource interface {
|
||||
|
||||
GetById(id uint64, cols ...string) *entity.Resource
|
||||
|
||||
GetByIdIn(ids []uint64, toEntity any, orderBy ...string)
|
||||
|
||||
Delete(id uint64)
|
||||
|
||||
GetByCondition(condition *entity.Resource, cols ...string) error
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Role interface {
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Delete(id uint64)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Syslog interface {
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Insert(log *entity.Syslog)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -14,24 +15,20 @@ func newAccountRepo() repository.Account {
|
||||
}
|
||||
|
||||
func (a *accountRepoImpl) GetAccount(condition *entity.Account, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT * FROM t_sys_account "
|
||||
username := condition.Username
|
||||
values := make([]any, 0)
|
||||
if username != "" {
|
||||
sql = sql + " WHERE username LIKE ?"
|
||||
values = append(values, "%"+username+"%")
|
||||
}
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(new(entity.Account)).
|
||||
Like("name", condition.Name).
|
||||
Like("username", condition.Username)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *accountRepoImpl) Insert(account *entity.Account) {
|
||||
biz.ErrIsNil(model.Insert(account), "新增账号信息失败")
|
||||
biz.ErrIsNil(gormx.Insert(account), "新增账号信息失败")
|
||||
}
|
||||
|
||||
func (m *accountRepoImpl) Update(account *entity.Account) {
|
||||
biz.ErrIsNil(model.UpdateById(account), "更新账号信息失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(account), "更新账号信息失败")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -13,22 +14,23 @@ func newConfigRepo() repository.Config {
|
||||
return new(configRepoImpl)
|
||||
}
|
||||
|
||||
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
||||
func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *configRepoImpl) Insert(config *entity.Config) {
|
||||
biz.ErrIsNil(model.Insert(config), "新增系统配置失败")
|
||||
biz.ErrIsNil(gormx.Insert(config), "新增系统配置失败")
|
||||
}
|
||||
|
||||
func (m *configRepoImpl) Update(config *entity.Config) {
|
||||
biz.ErrIsNil(model.UpdateById(config), "更新系统配置失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(config), "更新系统配置失败")
|
||||
}
|
||||
|
||||
func (m *configRepoImpl) GetConfig(condition *entity.Config, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (r *configRepoImpl) GetByCondition(condition *entity.Config, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -13,10 +14,11 @@ func newMsgRepo() repository.Msg {
|
||||
return new(msgRepoImpl)
|
||||
}
|
||||
|
||||
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity)
|
||||
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *msgRepoImpl) Insert(account *entity.Msg) {
|
||||
biz.ErrIsNil(model.Insert(account), "新增消息记录失败")
|
||||
biz.ErrIsNil(gormx.Insert(account), "新增消息记录失败")
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/gormx"
|
||||
)
|
||||
|
||||
type resourceRepoImpl struct{}
|
||||
@@ -14,40 +14,36 @@ func newResourceRepo() repository.Resource {
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetResourceList(condition *entity.Resource, toEntity any, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
gormx.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetById(id uint64, cols ...string) *entity.Resource {
|
||||
res := new(entity.Resource)
|
||||
if err := model.GetById(res, id, cols...); err != nil {
|
||||
if err := gormx.GetById(res, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetByIdIn(ids []uint64, toEntity any, orderBy ...string) {
|
||||
model.GetByIdIn(new(entity.Resource), toEntity, ids, orderBy...)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.Resource), id), "删除失败")
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.Resource), id), "删除失败")
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetByCondition(condition *entity.Resource, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetChildren(uiPath string) []entity.Resource {
|
||||
sql := "SELECT id, ui_path FROM t_sys_resource WHERE ui_path LIKE ?"
|
||||
var rs []entity.Resource
|
||||
model.GetListBySql2Model(sql, &rs, uiPath+"%")
|
||||
gormx.GetListBySql2Model(sql, &rs, uiPath+"%")
|
||||
return rs
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) UpdateByUiPathLike(resource *entity.Resource) {
|
||||
sql := "UPDATE t_sys_resource SET status=? WHERE (ui_path LIKE ?)"
|
||||
model.ExecSql(sql, resource.Status, resource.UiPath+"%")
|
||||
gormx.ExecSql(sql, resource.Status, resource.UiPath+"%")
|
||||
}
|
||||
|
||||
func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||
@@ -84,5 +80,5 @@ func (r *resourceRepoImpl) GetAccountResources(accountId uint64, toEntity any) {
|
||||
ORDER BY
|
||||
m.pid ASC,
|
||||
m.weight ASC`
|
||||
biz.ErrIsNilAppendErr(model.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.GetListBySql2Model(sql, toEntity, accountId), "查询账号资源失败: %s")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -13,12 +14,13 @@ func newRoleRepo() repository.Role {
|
||||
return new(roleRepoImpl)
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
func (m *roleRepoImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(model.DeleteById(new(entity.Role), id), "删除角色失败")
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.Role), id), "删除角色失败")
|
||||
}
|
||||
|
||||
// 获取角色拥有的资源id数组,从role_resource表获取
|
||||
@@ -26,7 +28,7 @@ func (m *roleRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
||||
var rrs []entity.RoleResource
|
||||
|
||||
condtion := &entity.RoleResource{RoleId: roleId}
|
||||
model.ListBy(condtion, &rrs, "ResourceId")
|
||||
gormx.ListBy(condtion, &rrs, "ResourceId")
|
||||
|
||||
var rids []uint64
|
||||
for _, v := range rrs {
|
||||
@@ -41,22 +43,22 @@ func (m *roleRepoImpl) GetRoleResources(roleId uint64, toEntity any) {
|
||||
"FROM t_sys_role_resource rr JOIN t_sys_resource r ON rr.resource_id = r.id " +
|
||||
"WHERE rr.role_id = ? " +
|
||||
"ORDER BY r.pid ASC, r.weight ASC"
|
||||
model.GetListBySql2Model(sql, toEntity, roleId)
|
||||
gormx.GetListBySql2Model(sql, toEntity, roleId)
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) SaveRoleResource(rr *entity.RoleResource) {
|
||||
model.Insert(rr)
|
||||
gormx.Insert(rr)
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) DeleteRoleResource(roleId uint64, resourceId uint64) {
|
||||
model.DeleteByCondition(&entity.RoleResource{RoleId: roleId, ResourceId: resourceId})
|
||||
gormx.DeleteByCondition(&entity.RoleResource{RoleId: roleId, ResourceId: resourceId})
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
|
||||
var rrs []entity.AccountRole
|
||||
|
||||
condtion := &entity.AccountRole{AccountId: accountId}
|
||||
model.ListBy(condtion, &rrs, "RoleId")
|
||||
gormx.ListBy(condtion, &rrs, "RoleId")
|
||||
|
||||
var rids []uint64
|
||||
for _, v := range rrs {
|
||||
@@ -66,11 +68,11 @@ func (m *roleRepoImpl) GetAccountRoleIds(accountId uint64) []uint64 {
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) SaveAccountRole(ar *entity.AccountRole) {
|
||||
model.Insert(ar)
|
||||
gormx.Insert(ar)
|
||||
}
|
||||
|
||||
func (m *roleRepoImpl) DeleteAccountRole(accountId, roleId uint64) {
|
||||
model.DeleteByCondition(&entity.AccountRole{RoleId: roleId, AccountId: accountId})
|
||||
gormx.DeleteByCondition(&entity.AccountRole{RoleId: roleId, AccountId: accountId})
|
||||
}
|
||||
|
||||
// 获取账号角色信息列表
|
||||
@@ -78,5 +80,5 @@ func (m *roleRepoImpl) GetAccountRoles(accountId uint64, toEntity any) {
|
||||
sql := "SELECT r.status, r.name, ar.create_time AS CreateTime, ar.creator AS creator " +
|
||||
"FROM t_sys_role r JOIN t_sys_account_role ar ON r.id = ar.role_id AND ar.account_id = ? " +
|
||||
"ORDER BY ar.create_time DESC"
|
||||
model.GetListBySql2Model(sql, toEntity, accountId)
|
||||
gormx.GetListBySql2Model(sql, toEntity, accountId)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -12,10 +13,11 @@ func newSyslogRepo() repository.Syslog {
|
||||
return new(syslogRepoImpl)
|
||||
}
|
||||
|
||||
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
func (m *syslogRepoImpl) GetPageList(condition *entity.Syslog, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *syslogRepoImpl) Insert(syslog *entity.Syslog) {
|
||||
model.Insert(syslog)
|
||||
gormx.Insert(syslog)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Team struct {
|
||||
@@ -48,7 +50,15 @@ func (p *Team) SaveTeam(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (p *Team) DelTeam(rc *req.Ctx) {
|
||||
p.TeamApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
||||
idsStr := ginx.PathParam(rc.GinCtx, "id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
p.TeamApp.Delete(uint64(value))
|
||||
}
|
||||
}
|
||||
|
||||
// 获取团队的成员信息
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
type Team interface {
|
||||
// 分页获取项目团队信息列表
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Save(team *entity.Team)
|
||||
|
||||
@@ -17,7 +17,7 @@ type Team interface {
|
||||
|
||||
//--------------- 团队成员相关接口 ---------------
|
||||
|
||||
GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult
|
||||
GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any]
|
||||
|
||||
SaveMember(tagTeamMember *entity.TeamMember)
|
||||
|
||||
@@ -51,7 +51,7 @@ type teamAppImpl struct {
|
||||
tagTreeTeamRepo repository.TagTreeTeam
|
||||
}
|
||||
|
||||
func (p *teamAppImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
func (p *teamAppImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
return p.teamRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -66,11 +66,12 @@ func (p *teamAppImpl) Save(team *entity.Team) {
|
||||
func (p *teamAppImpl) Delete(id uint64) {
|
||||
p.teamRepo.Delete(id)
|
||||
p.teamMemberRepo.DeleteBy(&entity.TeamMember{TeamId: id})
|
||||
p.tagTreeTeamRepo.DeleteBy(&entity.TagTreeTeam{TeamId: id})
|
||||
}
|
||||
|
||||
// --------------- 团队成员相关接口 ---------------
|
||||
|
||||
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult {
|
||||
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any] {
|
||||
return p.teamMemberRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Team interface {
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
||||
GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Insert(p *entity.Team)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ type TeamMember interface {
|
||||
|
||||
Save(mp *entity.TeamMember)
|
||||
|
||||
GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult
|
||||
GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any]
|
||||
|
||||
DeleteBy(condition *entity.TeamMember)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -49,29 +49,29 @@ func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEn
|
||||
sql = sql + ")"
|
||||
}
|
||||
sql = sql + " ORDER BY p.code_path"
|
||||
model.GetListBySql2Model(sql, toEntity)
|
||||
gormx.GetListBySql2Model(sql, toEntity)
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) SelectById(id uint64) *entity.TagTree {
|
||||
pt := new(entity.TagTree)
|
||||
if err := model.GetById(pt, id); err != nil {
|
||||
if err := gormx.GetById(pt, id); err != nil {
|
||||
return nil
|
||||
}
|
||||
return pt
|
||||
}
|
||||
|
||||
func (a *tagTreeRepoImpl) GetBy(condition *entity.TagTree, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) Insert(tagTree *entity.TagTree) {
|
||||
biz.ErrIsNil(model.Insert(tagTree), "新增标签失败")
|
||||
biz.ErrIsNil(gormx.Insert(tagTree), "新增标签失败")
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) UpdateById(tagTree *entity.TagTree) {
|
||||
biz.ErrIsNil(model.UpdateById(tagTree), "更新标签失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(tagTree), "更新标签失败")
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) Delete(id uint64) {
|
||||
model.DeleteById(new(entity.TagTree), id)
|
||||
gormx.DeleteById(new(entity.TagTree), id)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/gormx"
|
||||
)
|
||||
|
||||
type tagTreeTeamRepoImpl struct{}
|
||||
@@ -14,19 +14,19 @@ func newTagTreeTeamRepo() repository.TagTreeTeam {
|
||||
}
|
||||
|
||||
func (p *tagTreeTeamRepoImpl) ListTag(condition *entity.TagTreeTeam, toEntity any, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
gormx.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *tagTreeTeamRepoImpl) Save(pm *entity.TagTreeTeam) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(pm), "保存团队项目信息失败:%s")
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(pm), "保存团队项目信息失败:%s")
|
||||
}
|
||||
|
||||
func (p *tagTreeTeamRepoImpl) DeleteBy(condition *entity.TagTreeTeam) {
|
||||
model.DeleteByCondition(condition)
|
||||
gormx.DeleteByCondition(condition)
|
||||
}
|
||||
|
||||
func (p *tagTreeTeamRepoImpl) SelectTagPathsByAccountId(accountId uint64) []string {
|
||||
var res []string
|
||||
model.GetListBySql2Model("SELECT DISTINCT(t1.tag_path) FROM t_tag_tree_team t1 JOIN t_team_member t2 ON t1.team_id = t2.team_id WHERE t2.account_id = ? ORDER BY t1.tag_path", &res, accountId)
|
||||
gormx.GetListBySql2Model("SELECT DISTINCT(t1.tag_path) FROM t_tag_tree_team t1 JOIN t_team_member t2 ON t1.team_id = t2.team_id WHERE t2.account_id = ? ORDER BY t1.tag_path", &res, accountId)
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -13,22 +14,23 @@ func newTeamRepo() repository.Team {
|
||||
return new(teamRepoImpl)
|
||||
}
|
||||
|
||||
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, condition, toEntity, orderBy...)
|
||||
func (p *teamRepoImpl) GetPageList(condition *entity.Team, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (p *teamRepoImpl) Insert(team *entity.Team) {
|
||||
biz.ErrIsNil(model.Insert(team), "新增团队失败")
|
||||
biz.ErrIsNil(gormx.Insert(team), "新增团队失败")
|
||||
}
|
||||
|
||||
func (p *teamRepoImpl) UpdateById(team *entity.Team) {
|
||||
biz.ErrIsNil(model.UpdateById(team), "更新团队失败")
|
||||
biz.ErrIsNil(gormx.UpdateById(team), "更新团队失败")
|
||||
}
|
||||
|
||||
func (p *teamRepoImpl) Delete(id uint64) {
|
||||
model.DeleteById(new(entity.Team), id)
|
||||
gormx.DeleteById(new(entity.Team), id)
|
||||
}
|
||||
|
||||
func (p *teamRepoImpl) DeleteBy(team *entity.Team) {
|
||||
model.DeleteByCondition(team)
|
||||
gormx.DeleteByCondition(team)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -15,36 +15,28 @@ func newTeamMemberRepo() repository.TeamMember {
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string) {
|
||||
model.ListByOrder(condition, toEntity, orderBy...)
|
||||
gormx.ListByOrder(condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) Save(pm *entity.TeamMember) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(pm), "保存团队成员失败:%s")
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(pm), "保存团队成员失败:%s")
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult {
|
||||
sql := "SELECT d.*, a.name FROM t_team_member d JOIN t_sys_account a ON d.account_id = a.id WHERE a.status = 1 "
|
||||
|
||||
if condition.AccountId != 0 {
|
||||
sql = fmt.Sprintf("%s AND d.account_id = %d", sql, condition.AccountId)
|
||||
}
|
||||
if condition.TeamId != 0 {
|
||||
sql = fmt.Sprintf("%s AND d.team_id = %d", sql, condition.TeamId)
|
||||
}
|
||||
|
||||
values := make([]any, 0)
|
||||
if condition.Username != "" {
|
||||
sql = sql + " AND d.Username LIKE ?"
|
||||
values = append(values, "%"+condition.Username+"%")
|
||||
}
|
||||
sql = sql + " ORDER BY d.id DESC"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(new(entity.TeamMember)).
|
||||
Select("t_team_member.*, a.name").
|
||||
Joins("JOIN t_sys_account a ON t_team_member.account_id = a.id AND a.status = 1").
|
||||
Eq("account_id", condition.AccountId).
|
||||
Eq("team_id", condition.TeamId).
|
||||
Like("a.username", condition.Username).
|
||||
OrderByDesc("t_team_member.id")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) DeleteBy(condition *entity.TeamMember) {
|
||||
model.DeleteByCondition(condition)
|
||||
gormx.DeleteByCondition(condition)
|
||||
}
|
||||
|
||||
func (p *teamMemberRepoImpl) IsExist(teamId, accountId uint64) bool {
|
||||
return model.CountBy(&entity.TeamMember{TeamId: teamId, AccountId: accountId}) > 0
|
||||
return gormx.CountBy(&entity.TeamMember{TeamId: teamId, AccountId: accountId}) > 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user