chore: 初始开源发布
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 在源仓同一提交上同样失败,属既有缺陷。
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/dao"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
type appRegisterSettings struct {
|
||||
DeptId int64
|
||||
RoleId int64
|
||||
}
|
||||
|
||||
func appUserDeptOrDefault(user *entity.SysUser) int64 {
|
||||
if user != nil && user.DeptId > 0 {
|
||||
return user.DeptId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func appRegisterDeptOrDefault(ctx context.Context, tenantId string) int64 {
|
||||
deptId, err := appLoadRegisterDept(ctx, tenantId)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return deptId
|
||||
}
|
||||
|
||||
func appLoadRegisterSettings(ctx context.Context, tenantId string) (*appRegisterSettings, error) {
|
||||
if tenantId == "" {
|
||||
tenantId = consts.DefaultSystemTenantCode
|
||||
}
|
||||
|
||||
deptId, err := appLoadRegisterDept(ctx, tenantId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = appValidateRegisterDept(ctx, tenantId, deptId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
roleValue, err := appTenantConfigValue(ctx, tenantId, consts.ConfigKeyAppRegisterRoleId)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "读取小程序默认角色失败")
|
||||
}
|
||||
roleId, err := appPositiveConfigInt64(roleValue, "小程序默认角色ID")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = appValidateRegisterRole(ctx, tenantId, roleId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &appRegisterSettings{
|
||||
DeptId: deptId,
|
||||
RoleId: roleId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func appLoadRegisterDept(ctx context.Context, tenantId string) (int64, error) {
|
||||
if tenantId == "" {
|
||||
tenantId = consts.DefaultSystemTenantCode
|
||||
}
|
||||
|
||||
deptValue, err := appTenantConfigValue(ctx, tenantId, consts.ConfigKeyAppRegisterDeptId)
|
||||
if err != nil {
|
||||
return 0, gerror.Wrap(err, "读取小程序默认部门失败")
|
||||
}
|
||||
return appPositiveConfigInt64(deptValue, "小程序默认部门ID")
|
||||
}
|
||||
|
||||
func appTenantConfigValue(ctx context.Context, tenantId string, key string) (string, error) {
|
||||
var config *entity.SysConfig
|
||||
if err := dao.SysConfig.Ctx(ctx).
|
||||
Where(dao.SysConfig.Columns().TenantId, tenantId).
|
||||
Where(dao.SysConfig.Columns().ConfigKey, key).
|
||||
OrderDesc(dao.SysConfig.Columns().ConfigId).
|
||||
Limit(1).
|
||||
Scan(&config); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if config == nil || config.ConfigId == 0 {
|
||||
return "", nil
|
||||
}
|
||||
return strings.TrimSpace(config.ConfigValue), nil
|
||||
}
|
||||
|
||||
func appPositiveConfigInt64(value string, label string) (int64, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return 0, gerror.Newf("%s未配置", label)
|
||||
}
|
||||
id, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, gerror.Newf("%s配置不正确", label)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func appValidateRegisterDept(ctx context.Context, tenantId string, deptId int64) error {
|
||||
var dept *entity.SysDept
|
||||
if err := dao.SysDept.Ctx(ctx).
|
||||
Where(dao.SysDept.Columns().TenantId, tenantId).
|
||||
Where(dao.SysDept.Columns().DeptId, deptId).
|
||||
WhereNull(dao.SysDept.Columns().DeletedAt).
|
||||
Limit(1).
|
||||
Scan(&dept); err != nil {
|
||||
return gerror.Wrap(err, "校验小程序默认部门失败")
|
||||
}
|
||||
if dept == nil || dept.DeptId == 0 {
|
||||
return gerror.New("小程序默认部门不存在")
|
||||
}
|
||||
if strings.TrimSpace(dept.Status) != consts.SysDeptStatusNormal {
|
||||
return gerror.New("小程序默认部门已停用")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func appValidateRegisterRole(ctx context.Context, tenantId string, roleId int64) error {
|
||||
var role *entity.SysRole
|
||||
if err := dao.SysRole.Ctx(ctx).
|
||||
Where(dao.SysRole.Columns().TenantId, tenantId).
|
||||
Where(dao.SysRole.Columns().RoleId, roleId).
|
||||
WhereNull(dao.SysRole.Columns().DeletedAt).
|
||||
Limit(1).
|
||||
Scan(&role); err != nil {
|
||||
return gerror.Wrap(err, "校验小程序默认角色失败")
|
||||
}
|
||||
if role == nil || role.RoleId == 0 {
|
||||
return gerror.New("小程序默认角色不存在")
|
||||
}
|
||||
if strings.TrimSpace(role.Status) != consts.SysDeptStatusNormal {
|
||||
return gerror.New("小程序默认角色已停用")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user