2ed5dfa6a1
iotlcm-app:小程序端 + 用户端服务。 - app/:uni-app 小程序前端(基于 unibest,MIT) - 微信 AppID → YOUR_WX_APPID,uni-app AppID → __UNI__YOURAPPID - 内网后端地址 → admin.iotlcm.example.com - 应用标题与 unibest 模板 README 重写(保留上游致谢与 MIT 声明) - server/:GoFrame 用户端服务(基于 XiuAdmin,Apache-2.0) - module xiuadmin → git.5iot.com/iotlcm-public/iotlcm-app(360 文件) - 支付回调地址 → app.iotlcm.example.com,商户名与应用名泛化 - 真实手机号 → 合法 11 位编造号(保留号段前 3 位 + 后 4 位) - 依赖号码尾部的断言同步更新 - 补 server/LICENSE(Apache-2.0) - 移除内部资产:CI 触发器 - 补根 README,LF 行尾 + .gitattributes 已知:TestSysDept_RefreshDeptAncestors 在源仓同一提交上同样失败,属既有缺陷。
219 lines
5.9 KiB
Go
219 lines
5.9 KiB
Go
// 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-app/internal/dao"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/contexts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/xgen"
|
|
genconsts "git.5iot.com/iotlcm-public/iotlcm-app/internal/library/xgen/gen_consts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/xgorm/handler"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model/do"
|
|
"git.5iot.com/iotlcm-public/iotlcm-app/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
|
|
}
|