chore: 初始开源发布
iotlcm-admin-svr:管理后台服务。 - Go module:iotlcm → git.5iot.com/iotlcm-public/iotlcm-admin-svr(729 文件) - 凭据与地址脱敏:JWT signingKey(含代码里的 MustGet 默认值)、 MySQL DSN、Redis 口令、告警邮件发件人邮箱全部改为占位; 私网 IP → 文档地址段;库名 xiujie_admin → iotlcm - 真实手机号/邮箱 → 合法 11 位编造号 / example.com - 移除内部资产:CI 触发器、过时 DDL(sql/db_iotlcm.sql)、 私有依赖 go get 行、明文 registry 登录口令 - 启动 banner 统一 IOTLCM 方块字 + 社区惯例署名 - Dockerfile 改用公共基础镜像 - 拼错的 RADEME.md → README.md,README 重写 - 需要真实数据库的用例改为可用 IOTLCM_TEST_WITH_DB=1 显式启用 - 补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 数据库 schema 不随本仓发布(生产 DDL 已过时),README 已说明。
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
// package system
|
||||
// @Link https://github.com/xiujiecn/xiu-admin
|
||||
// @Copyright Copyright (c) 2025 LiXiujie
|
||||
// @Author Lxj <li@xiujie.cn>
|
||||
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/dao"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/contexts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/event"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/xgorm/handler"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/do"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/utility/convert"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/utility/excel"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type sSysPost struct {
|
||||
}
|
||||
|
||||
func NewSysPost() *sSysPost {
|
||||
return &sSysPost{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysPost(NewSysPost())
|
||||
}
|
||||
|
||||
func (l *sSysPost) Model(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
if len(option) == 0 {
|
||||
option = append(option, &handler.Option{
|
||||
FilterTenant: true,
|
||||
FilterAuth: true,
|
||||
})
|
||||
}
|
||||
return handler.Model(dao.SysPost.Ctx(ctx), option...)
|
||||
}
|
||||
|
||||
func (l *sSysPost) ModelQuery(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
if len(option) == 0 {
|
||||
option = append(option, &handler.Option{
|
||||
FilterTenant: true,
|
||||
FilterAuth: true,
|
||||
})
|
||||
}
|
||||
return handler.Model(service.MemoryDB().DB(ctx).Ctx(ctx).Model(dao.SysPost.Table()), option...)
|
||||
}
|
||||
|
||||
func (l *sSysPost) List(ctx context.Context, query *model.SysPostListParam) (items []*model.SysPostListModel, total int, err error) {
|
||||
m := l.ModelQuery(ctx)
|
||||
deptIds := make([]int64, 0)
|
||||
if query.DeptId != 0 {
|
||||
deptIds = append(deptIds, query.DeptId)
|
||||
} else if query.BelongDeptId != 0 {
|
||||
deptIds = append(deptIds, query.BelongDeptId)
|
||||
subDeptIds, err := service.SysDept().GetDeptIdsByParentId(ctx, query.BelongDeptId)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
deptIds = append(deptIds, subDeptIds...)
|
||||
}
|
||||
if query.PostCode != "" {
|
||||
m = m.WhereLike(dao.SysPost.Columns().PostCode, "%"+query.PostCode+"%")
|
||||
}
|
||||
if query.PostName != "" {
|
||||
m = m.WhereLike(dao.SysPost.Columns().PostName, "%"+query.PostName+"%")
|
||||
}
|
||||
if len(deptIds) > 0 {
|
||||
m = m.WhereIn(dao.SysPost.Columns().DeptId, deptIds)
|
||||
}
|
||||
if query.Status != "" {
|
||||
m = m.Where(dao.SysPost.Columns().Status, query.Status)
|
||||
}
|
||||
if len(query.CreatedAt) == 2 {
|
||||
startTime := gtime.NewFromStr(query.CreatedAt[0])
|
||||
endTime := gtime.NewFromStr(query.CreatedAt[1])
|
||||
m = m.WhereBetween(dao.SysPost.Columns().CreatedAt, startTime, endTime.EndOfDay())
|
||||
}
|
||||
total, err = m.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
err = m.WithAll().Page(query.Page, query.PageSize).OrderAsc(dao.SysPost.Columns().PostSort).Scan(&items)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (l *sSysPost) View(ctx context.Context, param *model.SysPostViewParam) (post *model.SysPostViewModel, err error) {
|
||||
err = l.ModelQuery(ctx).WithAll().Where(dao.SysPost.Columns().PostId, param.PostId).Scan(&post)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (l *sSysPost) Add(ctx context.Context, param *model.SysPostAddParam) (post *model.SysPostAddModel, err error) {
|
||||
user := contexts.GetUser(ctx)
|
||||
if user == nil {
|
||||
return nil, gerror.NewCode(consts.CodeLoginExpired, "登录已过期")
|
||||
}
|
||||
data := do.SysPost{}
|
||||
gconv.Struct(param, &data)
|
||||
data.TenantId = user.TenantId
|
||||
data.CreatedDept = user.DeptId
|
||||
data.CreatedBy = user.ID
|
||||
data.CreatedAt = gtime.Now()
|
||||
data.UpdatedBy = user.ID
|
||||
data.UpdatedAt = gtime.Now()
|
||||
postId, err := l.Model(ctx).Data(data).OmitNil().InsertAndGetId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
post = &model.SysPostAddModel{
|
||||
PostId: postId,
|
||||
}
|
||||
event.EventsInstance().Emit(ctx, consts.EventKeyDBSysPostCreate, postId)
|
||||
return
|
||||
}
|
||||
|
||||
func (l *sSysPost) Edit(ctx context.Context, param *model.SysPostEditParam) (post *model.SysPostEditModel, err error) {
|
||||
user := contexts.GetUser(ctx)
|
||||
if user == nil {
|
||||
return nil, gerror.NewCode(consts.CodeLoginExpired, "登录已过期")
|
||||
}
|
||||
data := do.SysPost{}
|
||||
gconv.Struct(param, &data)
|
||||
data.UpdatedBy = user.ID
|
||||
data.UpdatedAt = gtime.Now()
|
||||
_, err = l.Model(ctx).Data(data).OmitNil().Where(dao.SysPost.Columns().PostId, param.PostId).Update()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
post = &model.SysPostEditModel{
|
||||
PostId: param.PostId,
|
||||
}
|
||||
event.EventsInstance().Emit(ctx, consts.EventKeyDBSysPostUpdate, param.PostId)
|
||||
return
|
||||
}
|
||||
|
||||
func (l *sSysPost) Delete(ctx context.Context, param *model.SysPostDeleteParam) (post *model.SysPostDeleteModel, err error) {
|
||||
user := contexts.GetUser(ctx)
|
||||
if user == nil {
|
||||
return nil, gerror.NewCode(consts.CodeLoginExpired, "登录已过期")
|
||||
}
|
||||
ids := make([]int64, 0)
|
||||
if param.PostId != 0 {
|
||||
ids = append(ids, param.PostId)
|
||||
}
|
||||
if len(param.PostIds) > 0 {
|
||||
ids = append(ids, param.PostIds...)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil, gerror.New("请选择要删除的岗位")
|
||||
}
|
||||
data := do.SysPost{}
|
||||
data.DeletedBy = user.ID
|
||||
data.DeletedAt = gtime.Now()
|
||||
_, err = l.Model(ctx).Data(data).OmitNil().WhereIn(dao.SysPost.Columns().PostId, ids).Update()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
post = &model.SysPostDeleteModel{
|
||||
PostId: param.PostId,
|
||||
}
|
||||
event.EventsInstance().Emit(ctx, consts.EventKeyDBSysPostDelete, ids)
|
||||
return
|
||||
}
|
||||
|
||||
func (l *sSysPost) Export(ctx context.Context, param *model.SysPostExportParam) (post *model.SysPostExportModel, err error) {
|
||||
if param.Page == 0 {
|
||||
param.Page = 1
|
||||
}
|
||||
if param.PageSize == 0 {
|
||||
param.PageSize = 1000
|
||||
}
|
||||
items, total, err := l.List(ctx, param.SysPostListParam)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...}
|
||||
tags, err := convert.GetEntityDescTags(model.SysPostExportModel{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
fileName = "导出CURD列表-" + gctx.CtxId(ctx)
|
||||
sheetName = fmt.Sprintf("索引条件共%v行,共%v页,当前导出是第%v页,本页共%v行", total, total+param.PageSize-1/param.PageSize, param.Page, len(items))
|
||||
exports []model.SysPostExportModel
|
||||
)
|
||||
g.Log().Info(ctx, " sSysPost.Export total", total)
|
||||
if err = gconv.Scan(items, &exports); err != nil {
|
||||
return
|
||||
}
|
||||
g.Log().Info(ctx, " sSysPost.Export exports", len(exports))
|
||||
err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName)
|
||||
g.Log().Info(ctx, " sSysPost.Export err", err)
|
||||
post = &model.SysPostExportModel{}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user