mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 05:12:32 +08:00
模块化上传驱动,使用泛型优化工具库降低冗余
This commit is contained in:
@@ -223,8 +223,8 @@ func (s *sAdminDept) List(ctx context.Context, in adminin.DeptListInp) (res *adm
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
ids = convert.UniqueSliceInt64(ids)
|
||||
pids = convert.UniqueSliceInt64(pids)
|
||||
ids = convert.UniqueSlice(ids)
|
||||
pids = convert.UniqueSlice(pids)
|
||||
mod = mod.Wheref(`id in (?) or pid in (?)`, ids, pids)
|
||||
}
|
||||
|
||||
|
@@ -307,6 +307,6 @@ func (s *sAdminMenu) LoginPermissions(ctx context.Context, memberId int64) (list
|
||||
}
|
||||
}
|
||||
|
||||
lists = convert.UniqueSliceString(lists)
|
||||
lists = convert.UniqueSlice(lists)
|
||||
return
|
||||
}
|
||||
|
@@ -124,7 +124,7 @@ func (s *sAdminNotice) Status(ctx context.Context, in adminin.NoticeStatusInp) (
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
|
||||
if !validate.InSlice(consts.StatusSlice, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
@@ -322,16 +322,14 @@ func (s *sAdminNotice) UnreadCount(ctx context.Context, in adminin.NoticeUnreadC
|
||||
|
||||
// messageIds 获取我的消息所有的消息ID
|
||||
func (s *sAdminNotice) messageIds(ctx context.Context, memberId int64) (ids []int64, err error) {
|
||||
mod := s.Model(ctx, &handler.Option{FilterAuth: false}).
|
||||
array, err := s.Model(ctx, &handler.Option{FilterAuth: false}).
|
||||
Fields("id").
|
||||
Where("status", consts.StatusEnabled).
|
||||
Where("(`type` IN(?) OR (`type` = ? and JSON_CONTAINS(`receiver`,'"+gconv.String(memberId)+"')))",
|
||||
[]int{consts.NoticeTypeNotify, consts.NoticeTypeNotice}, consts.NoticeTypeLetter,
|
||||
)
|
||||
|
||||
array, err := mod.Array()
|
||||
).Array()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range array {
|
||||
@@ -351,14 +349,15 @@ func (s *sAdminNotice) UpRead(ctx context.Context, in adminin.NoticeUpReadInp) (
|
||||
err = gerror.New("获取用户信息失败!")
|
||||
return
|
||||
}
|
||||
|
||||
if err = dao.AdminNotice.Ctx(ctx).Where("id", in.Id).Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return gerror.New("公告不存在")
|
||||
}
|
||||
|
||||
return s.updatedReadClicks(ctx, in.Id, memberId)
|
||||
}
|
||||
|
||||
@@ -408,13 +407,12 @@ func (s *sAdminNotice) ReadAll(ctx context.Context, in adminin.NoticeReadAllInp)
|
||||
}
|
||||
|
||||
for _, messageId := range messageIds {
|
||||
if !validate.InSliceInt64(readIds, messageId) {
|
||||
if !validate.InSlice(readIds, messageId) {
|
||||
if err = s.updatedReadClicks(ctx, messageId, memberId); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -435,7 +433,7 @@ func (s *sAdminNotice) updatedReadClicks(ctx context.Context, noticeId, memberId
|
||||
_, err = dao.AdminNoticeRead.Ctx(ctx).Data(entity.AdminNoticeRead{NoticeId: noticeId, MemberId: memberId}).Insert()
|
||||
return
|
||||
}
|
||||
_, err = dao.AdminNoticeRead.Ctx(ctx).Where(dao.AdminNoticeRead.Columns().Id, models.Id).Increment("clicks", 1)
|
||||
_, err = dao.AdminNoticeRead.Ctx(ctx).Where(dao.AdminNoticeRead.Columns().Id, models.Id).Increment(dao.AdminNoticeRead.Columns().Clicks, 1)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -382,7 +382,7 @@ func (s *sAdminOrder) Status(ctx context.Context, in adminin.OrderStatusInp) (er
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
|
||||
if !validate.InSlice(consts.StatusSlice, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
|
@@ -203,7 +203,7 @@ func (s *sAdminPost) Status(ctx context.Context, in adminin.PostStatusInp) (err
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusSlice, in.Status) {
|
||||
if !validate.InSlice(consts.StatusSlice, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
|
@@ -57,7 +57,6 @@ func (s *sAdminRole) Verify(ctx context.Context, path, method string) bool {
|
||||
g.Log().Infof(ctx, "admin Verify Enforce err:%+v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -102,7 +101,6 @@ func (s *sAdminRole) GetName(ctx context.Context, id int64) (name string, err er
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
|
||||
return r.String(), nil
|
||||
}
|
||||
|
||||
@@ -148,7 +146,7 @@ func (s *sAdminRole) UpdatePermissions(ctx context.Context, in adminin.UpdatePer
|
||||
}
|
||||
|
||||
// 去重
|
||||
in.MenuIds = convert.UniqueSliceInt64(in.MenuIds)
|
||||
in.MenuIds = convert.UniqueSlice(in.MenuIds)
|
||||
|
||||
list := make(g.List, 0, len(in.MenuIds))
|
||||
for _, v := range in.MenuIds {
|
||||
@@ -169,7 +167,6 @@ func (s *sAdminRole) UpdatePermissions(ctx context.Context, in adminin.UpdatePer
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return casbin.Refresh(ctx)
|
||||
}
|
||||
|
||||
@@ -296,19 +293,18 @@ func (s *sAdminRole) DataScopeEdit(ctx context.Context, in *adminin.DataScopeEdi
|
||||
return gerror.New("超管角色拥有全部权限,无需修改!")
|
||||
}
|
||||
|
||||
if in.DataScope == consts.RoleDataDeptCustom && len(convert.UniqueSliceInt64(in.CustomDept)) == 0 {
|
||||
if in.DataScope == consts.RoleDataDeptCustom && len(convert.UniqueSlice(in.CustomDept)) == 0 {
|
||||
return gerror.New("自定义权限必须配置自定义部门!")
|
||||
}
|
||||
|
||||
models.DataScope = in.DataScope
|
||||
models.CustomDept = gjson.New(convert.UniqueSliceInt64(in.CustomDept))
|
||||
models.CustomDept = gjson.New(convert.UniqueSlice(in.CustomDept))
|
||||
|
||||
_, err = dao.AdminRole.Ctx(ctx).
|
||||
Fields(dao.AdminRole.Columns().DataScope, dao.AdminRole.Columns().CustomDept).
|
||||
Where("id", in.Id).
|
||||
Data(models).
|
||||
Update()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user