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,6 @@
|
||||
// package gen_codes
|
||||
// @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 gen_codes
|
||||
@@ -0,0 +1,218 @@
|
||||
// package gen_codes
|
||||
// @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 gen_codes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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/xgen"
|
||||
genconsts "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/xgen/gen_consts"
|
||||
"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"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type sSysGenTable struct {
|
||||
}
|
||||
|
||||
func SysGenTableNew() *sSysGenTable {
|
||||
return &sSysGenTable{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysGenTable(SysGenTableNew())
|
||||
}
|
||||
func (l *sSysGenTable) Model(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
if len(option) == 0 {
|
||||
option = append(option, &handler.Option{
|
||||
FilterTenant: false,
|
||||
FilterAuth: true,
|
||||
})
|
||||
}
|
||||
return handler.Model(dao.SysGenTable.Ctx(ctx), option...)
|
||||
}
|
||||
|
||||
// 列表
|
||||
func (s *sSysGenTable) List(ctx context.Context, param *model.SysGenTableListParam) (output []*model.SysGenTableListModel, total int, err error) {
|
||||
m := s.Model(ctx)
|
||||
if param.GenType != 0 {
|
||||
m = m.Where(dao.SysGenTable.Columns().GenType, param.GenType)
|
||||
}
|
||||
if param.VarName != "" {
|
||||
m = m.Where(dao.SysGenTable.Columns().VarName, param.VarName)
|
||||
}
|
||||
if param.Status != "" {
|
||||
m = m.Where(dao.SysGenTable.Columns().Status, param.Status)
|
||||
}
|
||||
total, err = m.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
output = make([]*model.SysGenTableListModel, 0)
|
||||
err = m.Page(param.Page, param.PageSize).OrderDesc(dao.SysGenTable.Columns().TableId).Scan(&output)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 详情
|
||||
func (s *sSysGenTable) View(ctx context.Context, param *model.SysGenTableViewParam) (output *model.SysGenTableViewModel, err error) {
|
||||
if param.TableId == 0 {
|
||||
err = gerror.New("参数错误")
|
||||
return
|
||||
}
|
||||
m := s.Model(ctx)
|
||||
err = m.Where(dao.SysGenTable.Columns().TableId, param.TableId).Scan(&output)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 新增
|
||||
func (s *sSysGenTable) Add(ctx context.Context, param *model.SysGenTableAddParam) (output *model.SysGenTableAddModel, err error) {
|
||||
data := do.SysGenTable{}
|
||||
gconv.Struct(param, &data)
|
||||
data.Options = "{}"
|
||||
data.MasterColumns = "[]"
|
||||
data.Status = "1"
|
||||
data.CreatedDept = contexts.GetDeptId(ctx)
|
||||
data.CreatedBy = contexts.GetUserId(ctx)
|
||||
data.CreatedAt = gtime.Now()
|
||||
m := s.Model(ctx)
|
||||
id, err := m.Data(data).OmitNil().InsertAndGetId()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
output = &model.SysGenTableAddModel{
|
||||
TableId: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 修改
|
||||
func (s *sSysGenTable) Edit(ctx context.Context, param *model.SysGenTableEditParam) (output *model.SysGenTableEditModel, err error) {
|
||||
if param == nil || param.TableId == 0 {
|
||||
err = gerror.New("参数错误")
|
||||
return
|
||||
}
|
||||
data := do.SysGenTable{}
|
||||
gconv.Struct(param, &data)
|
||||
if param.Options != nil {
|
||||
data.Options = gjson.New(*param.Options).MustToJsonString()
|
||||
}
|
||||
if param.MasterColumns != nil {
|
||||
data.MasterColumns = gjson.New(*param.MasterColumns).MustToJsonString()
|
||||
}
|
||||
|
||||
data.UpdatedBy = contexts.GetUserId(ctx)
|
||||
data.UpdatedAt = gtime.Now()
|
||||
m := s.Model(ctx)
|
||||
_, err = m.Data(data).OmitNil().Where(dao.SysGenTable.Columns().TableId, param.TableId).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
output = &model.SysGenTableEditModel{
|
||||
TableId: param.TableId,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysGenTable) Delete(ctx context.Context, param *model.SysGenTableDeleteParam) (output *model.SysGenTableDeleteModel, err error) {
|
||||
if len(param.TableIds) == 0 {
|
||||
err = gerror.New("参数错误")
|
||||
return
|
||||
}
|
||||
m := s.Model(ctx)
|
||||
_, err = m.WhereIn(dao.SysGenTable.Columns().TableId, param.TableIds).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
output = &model.SysGenTableDeleteModel{
|
||||
TableIds: param.TableIds,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取选择项
|
||||
func (s *sSysGenTable) Selects(ctx context.Context) (output *model.SelectsModel, err error) {
|
||||
output, err = xgen.GenCodesSelects(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取表选择项
|
||||
func (s *sSysGenTable) TableSelect(ctx context.Context, param *model.GenCodesTableSelectParam) (output []*model.GenCodesTableSelectModel, err error) {
|
||||
output, err = xgen.GenCodesTableSelect(ctx, param)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取字段选择项
|
||||
func (s *sSysGenTable) ColumnSelect(ctx context.Context, param *model.GenCodesColumnSelectParam) (output []*model.GenCodesColumnSelectModel, err error) {
|
||||
output, err = xgen.GenCodesColumnSelect(ctx, param)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取字段列表
|
||||
func (s *sSysGenTable) ColumnList(ctx context.Context, param *model.GenCodesColumnListParam) (output []*model.GenCodesColumnListModel, err error) {
|
||||
output, err = xgen.GenCodesColumnList(ctx, param)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 预览
|
||||
func (s *sSysGenTable) Preview(ctx context.Context, param *model.GenCodesPreviewParam) (output *model.GenCodesPreviewModel, err error) {
|
||||
output, err = xgen.GenCodesPreview(ctx, param)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 构建
|
||||
func (s *sSysGenTable) Build(ctx context.Context, param *model.GenCodesBuildParam) (output *model.GenCodesBuildModel, err error) {
|
||||
editParam := &model.SysGenTableEditParam{}
|
||||
gconv.Struct(param, editParam)
|
||||
status := genconsts.GenCodesStatusOk
|
||||
editParam.Status = &status
|
||||
_, err = s.Edit(ctx, editParam)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
output, err = xgen.GenCodesBuild(ctx, param)
|
||||
if err != nil {
|
||||
status = genconsts.GenCodesStatusFail
|
||||
editParam.Status = &status
|
||||
_, err = s.Edit(ctx, &model.SysGenTableEditParam{
|
||||
TableId: editParam.TableId,
|
||||
Status: &status,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user