feat:完善项目信息
This commit is contained in:
91
app/api/admin/api/account.go
Normal file
91
app/api/admin/api/account.go
Normal file
@ -0,0 +1,91 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Account struct{}
|
||||
|
||||
/**
|
||||
* @apiDefine Account 账号管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {post} /api/account/login 账号登录
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName AccountLogin
|
||||
* @apiGroup Account
|
||||
*
|
||||
* @apiHeader {string} x-equipment 设备平台(Web,H5,App)
|
||||
*
|
||||
* @apiParam {String} account 登录账号
|
||||
* @apiParam {String} password 登录密码
|
||||
* @apiParam {Json} captcha 验证码信息
|
||||
* @apiParam {String} captcha.key 验证key
|
||||
* @apiParam {String} captcha.value 验证value
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {String} data token
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjE3NDU2OTMwIiwiaWF0IjoiMTYxNjg1MjEzMCIsInVpZCI6IjIwMTMxMTI4MTMwMTg0MTkyMDAifQ.D7oSD4OGdz8rJt0rFNVEl5Ea47_vtuC51IDrY9mUTPo"
|
||||
* }
|
||||
*/
|
||||
func (a *Account) Login(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mode int `json:"mode" form:"mode" binding:"required"`
|
||||
Account string `json:"account" form:"account" binding:"required"`
|
||||
Password string `json:"password" form:"password"`
|
||||
Captcha string `json:"captcha" form:"captcha"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewAccount()(nil, api.GetTenantID()(c).(uint64)).Login(form.Mode, &controller.AccountLoginParams{
|
||||
Account: form.Account, Password: form.Password, Captcha: form.Captcha,
|
||||
}, c.GetHeader("x-equipment"), c.ClientIP())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/account/logout 账号退出
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName AccountLogout
|
||||
* @apiGroup Account
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Account) Logout(c *gin.Context) {
|
||||
// 因跳过中间键,故只能自己去获取token用户信息
|
||||
token := c.GetHeader(config.APIRequestToken)
|
||||
|
||||
_session := session.NewAdmin()
|
||||
|
||||
_ = service.NewAuthToken(token).Auth(config.RedisKeyForAccountAdmin, _session)
|
||||
|
||||
err := controller.NewAccount()(_session, 0).Logout()
|
||||
api.APIResponse(err)(c)
|
||||
}
|
58
app/api/admin/api/auth.go
Normal file
58
app/api/admin/api/auth.go
Normal file
@ -0,0 +1,58 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/auth"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Auth struct{}
|
||||
|
||||
/**
|
||||
* @apiDefine Auth 权限管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} /api/auth/list 权限列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName AuthList
|
||||
* @apiGroup Auth
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind_title 权限类型名称
|
||||
* @apiSuccess (200) {String} data.kind 权限类型
|
||||
* @apiSuccess (200) {String} data.name 权限名称
|
||||
* @apiSuccess (200) {String} data.auth 权限信息
|
||||
* @apiSuccess (200) {String} data.remark 备注信息
|
||||
* @apiSuccess (200) {Array} data.children 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* {
|
||||
* "id": 1,
|
||||
* "kind": 1,
|
||||
* "name": "测试",
|
||||
* "auth": "",
|
||||
* "remark": "",
|
||||
* "created_at": "2021-09-15T13:59:35+08:00",
|
||||
* "updated_at": "2021-09-15T13:59:35+08:00",
|
||||
* "kind_title": "模块",
|
||||
* "children": []
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (a *Auth) List(c *gin.Context) {
|
||||
data, err := auth.NewInstance()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
108
app/api/admin/api/base.go
Normal file
108
app/api/admin/api/base.go
Normal file
@ -0,0 +1,108 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/logger"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
SuccessCode = 200 //成功的状态码
|
||||
FailureCode = 999 //失败的状态码
|
||||
)
|
||||
|
||||
type response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ApiHandle func(c *gin.Context, syslog ...bool) interface{}
|
||||
|
||||
func (c ApiHandle) SysLog() {
|
||||
fmt.Println(123)
|
||||
//service.Publish(config.EventForSysLogProduce, _session.Community, _session.UID, _session.Name, mode, event, content,
|
||||
// c.Get("params"), c.ClientIP())
|
||||
}
|
||||
|
||||
func getSession() ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
value, _ := c.Get(config.TokenForSession)
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
func bind(req interface{}) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
var err error
|
||||
|
||||
if c.Request.Method == "GET" {
|
||||
err = c.ShouldBindQuery(req)
|
||||
} else {
|
||||
err = c.ShouldBindBodyWith(req, binding.JSON)
|
||||
}
|
||||
if err != nil {
|
||||
logger.ErrorF("Request URL【%s】Params Bind Error:%v", c.Request.URL, err)
|
||||
return errors.New("参数异常/缺失")
|
||||
}
|
||||
c.Set("params", utils.AnyToJSON(req))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APISuccess(data ...interface{}) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
resp := &response{
|
||||
Code: SuccessCode,
|
||||
Message: "ok",
|
||||
}
|
||||
if len(data) > 0 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APIFailure(err error) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
resp := &response{
|
||||
Code: FailureCode,
|
||||
Message: "failure",
|
||||
}
|
||||
if err != nil {
|
||||
resp.Message = err.Error()
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APIResponse(err error, data ...interface{}) ApiHandle {
|
||||
return func(c *gin.Context, log ...bool) interface{} {
|
||||
resp := &response{
|
||||
Code: SuccessCode,
|
||||
Message: "ok",
|
||||
}
|
||||
if err != nil {
|
||||
resp.Code = FailureCode
|
||||
resp.Message = err.Error()
|
||||
c.JSON(http.StatusOK, resp)
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
if len(data) > 0 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return nil
|
||||
}
|
||||
}
|
42
app/api/admin/api/captcha.go
Normal file
42
app/api/admin/api/captcha.go
Normal file
File diff suppressed because one or more lines are too long
33
app/api/admin/api/config.go
Normal file
33
app/api/admin/api/config.go
Normal file
@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Config struct{}
|
||||
|
||||
func (a *Config) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewConfig()().Config(form.Kind, form.Page, form.PageSize)
|
||||
APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (a *Config) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
Params map[string]interface{} `json:"params" form:"params" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewConfig()().Form(form.Params)
|
||||
APIResponse(err)
|
||||
}
|
67
app/api/admin/api/department.go
Normal file
67
app/api/admin/api/department.go
Normal file
@ -0,0 +1,67 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Department struct{}
|
||||
|
||||
type departmentForm struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
func (a *Department) List(c *gin.Context) {
|
||||
data, err := controller.NewDepartment()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Select(c *gin.Context) {
|
||||
data, err := controller.NewDepartment()(getSession()(c).(*service.Session)).Select()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Add(c *gin.Context) {
|
||||
form := new(departmentForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Data(&controller.DepartmentParams{
|
||||
ParentID: form.ParentID, Title: form.Title, Name: form.Name, Mobile: form.Mobile, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
departmentForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Data(&controller.DepartmentParams{
|
||||
ID: form.ID, ParentID: form.ParentID, Title: form.Title, Name: form.Name, Mobile: form.Mobile, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Department) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewDepartment()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
23
app/api/admin/api/logs.go
Normal file
23
app/api/admin/api/logs.go
Normal file
@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Log struct{}
|
||||
|
||||
func (a *Log) Login(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewLog()(getSession()(c).(*service.Session)).Login(form.Name, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
116
app/api/admin/api/manage.go
Normal file
116
app/api/admin/api/manage.go
Normal file
@ -0,0 +1,116 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/manage"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Manage struct{}
|
||||
|
||||
type (
|
||||
// manageExamineForm 审核处理
|
||||
manageExamineForm struct {
|
||||
api.IDStringForm
|
||||
Identity int
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}
|
||||
)
|
||||
|
||||
// handle 审核处理
|
||||
func (a *manageExamineForm) handle(session *service.Session, local string) error {
|
||||
return manage.NewExamine()(session, local).Launch(a.Convert(), a.Identity, a.Status)
|
||||
}
|
||||
|
||||
func (*Manage) Company(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) CompanyExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForCompany
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Manage) Expert(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewInstance()(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string)).
|
||||
Expert(form.Name, form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)
|
||||
}
|
||||
|
||||
func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForExpert
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Manage) Laboratory(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) LaboratoryExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForLaboratory
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Manage) Research(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) ResearchExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForResearch
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (*Manage) Agent(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) AgentExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForAgent
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
api.APIResponse(err)
|
||||
}
|
236
app/api/admin/api/menu.go
Normal file
236
app/api/admin/api/menu.go
Normal file
@ -0,0 +1,236 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/menu"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Menu struct{}
|
||||
|
||||
type (
|
||||
// menuForm 菜单信息
|
||||
menuForm struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Link string `json:"link" form:"link"`
|
||||
Component string `json:"component" form:"component"`
|
||||
Icon string `json:"icon" form:"icon"`
|
||||
Auth int `json:"auth" form:"auth"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
Status int `json:"status" form:"status"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @apiDefine Menu 菜单管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} /api/menu/list 菜单列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuList
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) List(c *gin.Context) {
|
||||
data, err := menu.NewInstance()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/add 菜单添加
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuAdd
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} parent_id 父级ID
|
||||
* @apiParam {String} name 菜单名
|
||||
* @apiParam {Number} kind 菜单类型(1:目录,2:菜单)
|
||||
* @apiParam {String} link 访问地址
|
||||
* @apiParam {String} component 页面组件
|
||||
* @apiParam {String} icon 页面icon
|
||||
* @apiParam {Number} auth 菜单权限(0:普通权限,1:超管权限)
|
||||
* @apiParam {Number} sort 排序,从大到小
|
||||
* @apiParam {Number} status 忘了干嘛,没用
|
||||
* @apiParam {String} remark 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Add(c *gin.Context) {
|
||||
form := new(menuForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Form(&menu.InstanceParams{
|
||||
ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/edit 菜单修改
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuEdit
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Number} parent_id 父级ID
|
||||
* @apiParam {String} name 菜单名
|
||||
* @apiParam {Number} kind 菜单类型(1:目录,2:菜单)
|
||||
* @apiParam {String} link 访问地址
|
||||
* @apiParam {String} component 页面组件
|
||||
* @apiParam {String} icon 页面icon
|
||||
* @apiParam {Number} auth 菜单权限(0:普通权限,1:超管权限)
|
||||
* @apiParam {Number} sort 排序,从大到小
|
||||
* @apiParam {Number} status 禁用状态(1:启用,2:禁用)
|
||||
* @apiParam {String} remark 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
menuForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Form(&menu.InstanceParams{
|
||||
ID: form.ID, ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/status 菜单状态
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuStatus
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Number} status 状态(1:启动,2:禁用)
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Status(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/delete 删除菜单
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuDelete
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
264
app/api/admin/api/role.go
Normal file
264
app/api/admin/api/role.go
Normal file
@ -0,0 +1,264 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
role2 "SciencesServer/app/api/admin/controller/role"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Role struct{}
|
||||
|
||||
func (a *Role) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role2.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Select(c *gin.Context) {
|
||||
data, err := role2.NewInstance()(getSession()(c).(*service.Session)).Select()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Add(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark" binding:"required"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Data(0, form.Name, form.Remark, form.Sort)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark" binding:"required"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Data(form.ID, form.Name, form.Remark, form.Sort)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Status(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Role) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/menu 菜单信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleMenu
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Role) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role2.NewMenu()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/menu/bind 菜单绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleMenuBind
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
* @apiParam {Array.Number} menu_ids 菜单ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Role) MenuBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewMenu()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/auth 权限信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleAuth
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id ID
|
||||
* @apiSuccess (200) {Number} data.kind_title 权限类型名称
|
||||
* @apiSuccess (200) {String} data.kind 权限类型
|
||||
* @apiSuccess (200) {String} data.name 权限名称
|
||||
* @apiSuccess (200) {String} data.auth 权限信息
|
||||
* @apiSuccess (200) {Bool} data.checked 选中状态
|
||||
* @apiSuccess (200) {String} data.remark 备注信息
|
||||
* @apiSuccess (200) {Array} data.children 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* {
|
||||
* "id": 1,
|
||||
* "kind": 1,
|
||||
* "name": "测试",
|
||||
* "auth": "",
|
||||
* "checked": false,
|
||||
* "remark": "",
|
||||
* "created_at": "2021-09-15T13:59:35+08:00",
|
||||
* "updated_at": "2021-09-15T13:59:35+08:00",
|
||||
* "kind_title": "模块",
|
||||
* "children": []
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
func (a *Role) Auth(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role2.NewAuth()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/auth/bind 权限绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName RoleAuthBind
|
||||
* @apiGroup Role
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
* @apiParam {Array.Number} auth_ids 权限ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Role) AuthBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role2.NewAuth()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
37
app/api/admin/api/struct.go
Normal file
37
app/api/admin/api/struct.go
Normal file
@ -0,0 +1,37 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type idForm struct {
|
||||
ID uint64 `json:"id" form:"id" binding:"required"`
|
||||
}
|
||||
|
||||
type uidForm struct {
|
||||
UID string `json:"uid" form:"uid" binding:"required"`
|
||||
}
|
||||
|
||||
func (this *uidForm) Convert() uint64 {
|
||||
return utils.StringToUnit64(this.UID)
|
||||
}
|
||||
|
||||
type imageForm struct {
|
||||
Image string `json:"image" form:"image"`
|
||||
}
|
||||
|
||||
func (this *imageForm) FilterImageURL() string {
|
||||
return strings.Replace(this.Image, config.SettingInfo.Domain, "", -1)
|
||||
}
|
||||
|
||||
type positionForm struct {
|
||||
Longitude float64 `json:"longitude" form:"longitude" binding:"required"`
|
||||
Latitude float64 `json:"latitude" form:"latitude" binding:"required"`
|
||||
}
|
||||
|
||||
type pageForm struct {
|
||||
Page int `json:"current" form:"current" binding:"required"`
|
||||
PageSize int `json:"pageSize" form:"pageSize" binding:"required"`
|
||||
}
|
530
app/api/admin/api/tenant.go
Normal file
530
app/api/admin/api/tenant.go
Normal file
@ -0,0 +1,530 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
tenant2 "SciencesServer/app/api/admin/controller/tenant"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Tenant struct{}
|
||||
|
||||
type (
|
||||
// tenantForm 基本信息
|
||||
tenantForm struct {
|
||||
Name string `json:"name" form:"name" binding:"required"` // 名称
|
||||
imageForm // 图片
|
||||
Account string `json:"account" form:"account" binding:"required"` // 登录帐号
|
||||
Password string `json:"password" form:"password" binding:"required"` // 登录密码
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"` // 重复登录密码
|
||||
Deadline string `json:"deadline" form:"deadline" binding:"required"` // 协约终止时间
|
||||
Remark string `json:"remark" form:"remark"` // 备注
|
||||
}
|
||||
// tenantSettingForm 配置信息
|
||||
tenantSettingForm struct {
|
||||
Protocol []uint `json:"protocol" form:"protocol" binding:"required"` // 消息协议
|
||||
MaxDevices int `json:"max_devices" form:"max_devices" binding:"required"` // 允许最多的设备数
|
||||
MaxCustomer int `json:"max_customer" form:"max_customer"` // 允许最多的客户数
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @apiDefine Tenant 租户管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/list 租户列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantList
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} [name='""'] 租户名称
|
||||
* @apiParam {Number} [status=0] 租户状态
|
||||
* @apiParam {Number} current 当前页
|
||||
* @apiParam {Number} page_size 页展示数
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id ID
|
||||
* @apiSuccess (200) {String} data.key 标识key
|
||||
* @apiSuccess (200) {String} data.name 公司名称
|
||||
* @apiSuccess (200) {Time} data.deadline 协议到期时间
|
||||
* @apiSuccess (200) {Number} data.device_count 设备数量
|
||||
* @apiSuccess (200) {Json} data.config 配置信息
|
||||
* @apiSuccess (200) {Number} data.config.max_devices 最大设备数
|
||||
* @apiSuccess (200) {Number} data.config.max_customer 最大客户数
|
||||
* @apiSuccess (200) {Number} data.config.protocol 支持协议(&)
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* {
|
||||
* "id": 1,
|
||||
* "key": "3xPdWH",
|
||||
* "image": "",
|
||||
* "name": "商挈智能",
|
||||
* "deadline": "2021-12-31T23:59:59+08:00",
|
||||
* "remark": "测试",
|
||||
* "created_at": "2021-07-27T10:45:18+08:00",
|
||||
* "updated_at": "2021-07-27T10:45:18+08:00",
|
||||
* "device_count": 0,
|
||||
* "config": {
|
||||
* "max_devices": 1,
|
||||
* "max_customer": 1,
|
||||
* "protocol": 3
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant2.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/add 租户添加
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantAdd
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} name 租户名称
|
||||
* @apiParam {String} image 租户图片
|
||||
* @apiParam {String} account 租户管理员登录帐号
|
||||
* @apiParam {String} password 租户管理员登录密码
|
||||
* @apiParam {String} repeat_pwd 重复密码
|
||||
* @apiParam {Number} max_devices 最大设备数
|
||||
* @apiParam {Number} [max_customer=0] 租户可拥有的最大客户数
|
||||
* @apiParam {Array.Number} protocol 消息协议
|
||||
* @apiParam {Time} deadline 协议有效期:2021-12-31
|
||||
* @apiParam {String} [remark="''"] 备注信息
|
||||
* @apiParam {Number} current 当前页
|
||||
* @apiParam {Number} page_size 页展示数
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) Add(c *gin.Context) {
|
||||
form := new(tenantForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).Add(&tenant2.InstanceParams{Name: form.Name,
|
||||
Image: form.FilterImageURL(), Account: form.Account, Password: form.Password, RepeatPwd: form.RepeatPwd,
|
||||
Deadline: form.Deadline, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/edit 租户修改
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantEdit
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {String} name 租户名称
|
||||
* @apiParam {String} image 租户图片
|
||||
* @apiParam {String} [remark="''"] 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
imageForm
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).Edit(&tenant2.InstanceParams{ID: form.ID, Name: form.Name,
|
||||
Image: form.FilterImageURL(), Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/edit/password 租户修改密码
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantEditPassword
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {String} name 租户名称
|
||||
* @apiParam {String} image 租户图片
|
||||
* @apiParam {String} [remark="''"] 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) EditPassword(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Password string `json:"password" form:"password" binding:"required"` // 登录密码
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"` // 重复登录密码
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).Edit(&tenant2.InstanceParams{ID: form.ID, Password: form.Password,
|
||||
RepeatPwd: form.RepeatPwd,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/detail 租户详细信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantDetail
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Number} type 详细信息(1:基本信息,2:资产设备信息,3:成员信息,4:权限信息)
|
||||
* @apiParam {Number} [current=0] 当前页
|
||||
* @apiParam {Number} [page_size=0] 页展示数
|
||||
* @apiParam {String} [name="''"] 成员名称
|
||||
* @apiParam {Number} [status=0] 成员状态
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": Any
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) Detail(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Type tenant2.InstanceDetailType `json:"type" form:"type" binding:"required"`
|
||||
Page int `json:"current" form:"current"`
|
||||
PageSize int `json:"pageSize" form:"pageSize"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Status int `json:"status" form:"status"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant2.NewInstance()(getSession()(c).(*service.Session)).Detail(form.ID, form.Type, form.Page,
|
||||
form.PageSize, form.Name, form.Status)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/renewal 租户续期
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantRenewal
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Time} deadline 协议有效期:2021-12-31
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) Renewal(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Deadline string `json:"deadline" form:"deadline" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).Renewal(form.ID, form.Deadline)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/start_up 租户启用
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantStartUp
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) StartUp(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).StartUp(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/disable 租户禁用
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantDisable
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) Disable(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).Disable(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/member/bind 租户用户绑定状态
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantMemberBind
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Number} status 状态(1:启用,2:禁用)
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) MemberBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
uidForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewInstance()(getSession()(c).(*service.Session)).MemberBind(form.Convert(), form.Status)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/tenant/menu 菜单信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantMenu
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant2.NewMenu()(getSession()(c).(*service.Session)).List(form.TenantID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/menu/bind 菜单绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantMenuBind
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} tenant_id 租户ID
|
||||
* @apiParam {Array.Number} menu_ids 菜单ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) MenuBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewMenu()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/auth/bind 权限绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantAuthBind
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} tenant_id 租户ID
|
||||
* @apiParam {Array.Number} auth_ids 权限ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Tenant) AuthBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant2.NewAuth()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
258
app/api/admin/api/user.go
Normal file
258
app/api/admin/api/user.go
Normal file
@ -0,0 +1,258 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
user2 "SciencesServer/app/api/admin/controller/user"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
|
||||
type userForm struct {
|
||||
Account string `json:"account" form:"account" binding:"required"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Gender int `json:"gender" form:"gender" binding:"required"`
|
||||
Departments []uint64 `json:"departments" form:"departments"`
|
||||
Roles []uint64 `json:"roles" form:"roles"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @apiDefine User 用户管理
|
||||
*/
|
||||
|
||||
func (a *User) Info(c *gin.Context) {
|
||||
data, err := user2.NewInstance()(getSession()(c).(*service.Session)).Info()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) List(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Status int `json:"status" form:"status"`
|
||||
pageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user2.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/user/menu 菜单信息
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserMenu
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *User) Menu(c *gin.Context) {
|
||||
data, err := user2.NewMenu()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Add(c *gin.Context) {
|
||||
form := &struct {
|
||||
userForm
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewInstance()(getSession()(c).(*service.Session)).Add(&user2.InstanceForm{
|
||||
Account: form.Account, Name: form.Name, Mobile: form.Mobile, Password: form.Password,
|
||||
Remark: form.Remark, Gender: form.Gender, Departments: form.Departments, Roles: form.Roles,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
userForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewInstance()(getSession()(c).(*service.Session)).Edit(&user2.InstanceForm{
|
||||
ID: form.ID, Account: form.Account, Name: form.Name, Mobile: form.Mobile,
|
||||
Remark: form.Remark, Gender: form.Gender, Departments: form.Departments, Roles: form.Roles,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/user/password/quick 快速设置新密码
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordQuick
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {String} password 登录密码
|
||||
* @apiParam {String} repeat_pwd 重复密码
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *User) QuickPassword(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewInstance()(getSession()(c).(*service.Session)).Password(form.ID, form.Password, form.RepeatPwd)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/user/password/edit 修改新密码
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordEdit
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {String} original_pwd 原始密码
|
||||
* @apiParam {String} password 登录密码
|
||||
* @apiParam {String} repeat_pwd 重复密码
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *User) EditPassword(c *gin.Context) {
|
||||
form := &struct {
|
||||
OldPwd string `json:"original_pwd" form:"original_pwd" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewPerson()(getSession()(c).(*service.Session)).EditPassword(form.OldPwd, form.Password, form.RepeatPwd)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/user/delete 用户删除
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserDelete
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *User) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Role(c *gin.Context) {
|
||||
form := &struct {
|
||||
uidForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user2.NewRole()(getSession()(c).(*service.Session)).List(form.Convert())
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) RoleBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
uidForm
|
||||
RoleIDs []uint64 `json:"role_ids" form:"role_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewRole()(getSession()(c).(*service.Session)).Bind(form.Convert(), form.RoleIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
@ -1 +1,125 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
session *session.Admin
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type AccountHandle func(session *session.Admin, tenantID uint64) *Account
|
||||
|
||||
type (
|
||||
// AccountLoginParams 登陆参数
|
||||
AccountLoginParams struct {
|
||||
Account, Password, Captcha string
|
||||
}
|
||||
// AccountLoginResponse 登陆响应
|
||||
AccountLoginResponse struct {
|
||||
Token string `json:"token"`
|
||||
EffectTime int `json:"effect_time"`
|
||||
}
|
||||
)
|
||||
|
||||
// loginHandle 登陆操作,1:账户密码登陆,2:短信验证登陆
|
||||
var loginHandle = map[int]func(params *AccountLoginParams, tenantID uint64) (*model.SysUser, error){
|
||||
1: loginForPassword, 2: loginForSmsCaptcha,
|
||||
}
|
||||
|
||||
// loginForPassword 密码登陆
|
||||
func loginForPassword(params *AccountLoginParams, tenantID uint64) (*model.SysUser, error) {
|
||||
if params.Password == "" {
|
||||
return nil, errors.New("操作错误,密码不可为空")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := mSysUser.GetByAccountOrMobile(params.Account, tenantID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,当前帐号信息不存在或已被删除")
|
||||
}
|
||||
if !mSysUser.ValidatePassword(params.Password) {
|
||||
return nil, errors.New("操作错误,用户名或密码错误")
|
||||
}
|
||||
return mSysUser, nil
|
||||
}
|
||||
|
||||
// loginForSmsCaptcha 短信验证码登陆
|
||||
func loginForSmsCaptcha(params *AccountLoginParams, tenantID uint64) (*model.SysUser, error) {
|
||||
if params.Password == "" {
|
||||
return nil, errors.New("操作错误,验证码不可为空")
|
||||
}
|
||||
// 验证验证码
|
||||
if pass, _ := handle.NewCaptcha().Validate(&handle.CaptchaSms{Mobile: params.Account, Captcha: params.Captcha}); !pass {
|
||||
return nil, errors.New("操作错误,验证码错误")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{
|
||||
"id", "tenant_id", "name", "mobile", "is_admin", "status",
|
||||
}, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("mobile", params.Account))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,当前帐号信息不存在或已被删除")
|
||||
}
|
||||
return mSysUser, nil
|
||||
}
|
||||
|
||||
// Login 登录请求
|
||||
func (c *Account) Login(mode int, params *AccountLoginParams, equipment, ip string) (*AccountLoginResponse, error) {
|
||||
_handle, has := loginHandle[mode]
|
||||
|
||||
if !has {
|
||||
return nil, errors.New("操作错误,未知的登陆模式")
|
||||
}
|
||||
data, err := _handle(params, c.tenantID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if data.Status != model2.SysUserStatusForNormal {
|
||||
return nil, errors.New(fmt.Sprintf("操作错误,当前账号【%s】状态异常,已禁止登陆,请联系管理员", data.Name))
|
||||
}
|
||||
_session := session.NewAdmin()
|
||||
_session.UID = data.UUID
|
||||
_session.TenantID = data.TenantID
|
||||
_session.Name = data.Name
|
||||
_session.Mobile = data.Mobile
|
||||
_session.IsAdmin = data.IsAdminUser()
|
||||
|
||||
_uid := data.UUIDString()
|
||||
|
||||
_session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: _uid})
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountAdmin, _uid, _session)
|
||||
service.Publish(config.EventForAccountLoginProduce, data.TenantID, _session.UID, equipment, ip)
|
||||
|
||||
return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
||||
}
|
||||
|
||||
// Logout 退出请求
|
||||
func (c *Account) Logout() error {
|
||||
if c.session != nil && c.session.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccountAdmin, utils.UintToString(c.session.UID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewAccount() AccountHandle {
|
||||
return func(session *session.Admin, tenantID uint64) *Account {
|
||||
return &Account{session: session, tenantID: tenantID}
|
||||
}
|
||||
}
|
||||
|
60
app/api/admin/controller/auth/base.go
Normal file
60
app/api/admin/controller/auth/base.go
Normal file
@ -0,0 +1,60 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type (
|
||||
// Tree 权限信息
|
||||
Tree struct {
|
||||
*model2.SysAuth
|
||||
KindTitle string `json:"kind_title"`
|
||||
Children []*Tree `json:"children"`
|
||||
}
|
||||
// TreeRole 角色权限信息
|
||||
TreeRole struct {
|
||||
*model2.SysAuth
|
||||
KindTitle string `json:"kind_title"`
|
||||
Checked bool `json:"checked"`
|
||||
Children []*TreeRole `json:"children"`
|
||||
}
|
||||
// TreeChecked 角色选中状态
|
||||
TreeChecked struct {
|
||||
*model2.SysAuth
|
||||
Checked bool `json:"checked"`
|
||||
Children []*TreeChecked `json:"children"`
|
||||
}
|
||||
)
|
||||
|
||||
// tree 树状筛选
|
||||
func tree(src []*model2.SysAuth, parentID uint64) []*Tree {
|
||||
out := make([]*Tree, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &Tree{
|
||||
SysAuth: v,
|
||||
KindTitle: v.KindTitle(),
|
||||
Children: tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TreeCheckedFunc 树状筛选
|
||||
func TreeCheckedFunc(src []*model.SysAuthScene, parentID uint64) []*TreeChecked {
|
||||
out := make([]*TreeChecked, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &TreeChecked{
|
||||
SysAuth: v.SysAuth,
|
||||
Checked: v.SceneID > 0,
|
||||
Children: TreeCheckedFunc(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
34
app/api/admin/controller/auth/instance.go
Normal file
34
app/api/admin/controller/auth/instance.go
Normal file
@ -0,0 +1,34 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List() ([]*Tree, error) {
|
||||
mSysAuth := model.NewSysAuth()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)},
|
||||
&model2.ModelWhereOrder{Order: model2.NewOrder("sort", model2.OrderModeToDesc)},
|
||||
}
|
||||
out := make([]*model2.SysAuth, 0)
|
||||
|
||||
if err := model2.Scan(mSysAuth, &out, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tree(out, 0), nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
37
app/api/admin/controller/base.go
Normal file
37
app/api/admin/controller/base.go
Normal file
@ -0,0 +1,37 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/cache"
|
||||
"SciencesServer/utils"
|
||||
)
|
||||
|
||||
// Platform
|
||||
type Platform struct{ *service.Session }
|
||||
|
||||
func (c *Platform) Format() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ReturnPages 分页数据
|
||||
type ReturnPages struct {
|
||||
Data interface{} `json:"data"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
type Key struct{}
|
||||
|
||||
// Generate 生成秘钥
|
||||
func (*Key) Generate(len int) string {
|
||||
key := utils.GetRandomString(len)
|
||||
for {
|
||||
isExist, _ := cache.Cache.SIsMember(config.RedisKeyForTenantKeys, key)
|
||||
|
||||
if !isExist {
|
||||
_ = cache.Cache.SAdd(config.RedisKeyForTenantKeys, key)
|
||||
return key
|
||||
}
|
||||
key = utils.GetRandomString(len)
|
||||
}
|
||||
}
|
64
app/api/admin/controller/config.go
Normal file
64
app/api/admin/controller/config.go
Normal file
@ -0,0 +1,64 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Config struct{}
|
||||
|
||||
type ConfigHandle func() *Config
|
||||
|
||||
func (c *Config) Config(kind, page, pageSize int) (*ReturnPages, error) {
|
||||
mSysConfig := model.NewSysConfig()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{Order: model2.NewOrder("kind", model2.OrderModeToAsc)},
|
||||
}
|
||||
if kind > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)})
|
||||
}
|
||||
out := make([]*model2.SysConfig, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mSysConfig.SysConfig, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ReturnPages{Data: out, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Config) Form(params map[string]interface{}) error {
|
||||
if len(params) <= 0 {
|
||||
return nil
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysConfig := model.NewSysConfig()
|
||||
now := time.Now()
|
||||
|
||||
for k, v := range params {
|
||||
if _, has := config.SystemConfig[k]; !has {
|
||||
return errors.New("UnKnown Config Key :" + k)
|
||||
}
|
||||
if err := model2.UpdatesWhere(mSysConfig.SysConfig, map[string]interface{}{
|
||||
"value": v, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("key", k)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
config.SystemConfig[k] = v
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewConfig() ConfigHandle {
|
||||
return func() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
}
|
98
app/api/admin/controller/department.go
Normal file
98
app/api/admin/controller/department.go
Normal file
@ -0,0 +1,98 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Department struct{ *Platform }
|
||||
|
||||
type DepartmentHandle func(session *service.Session) *Department
|
||||
|
||||
type DepartmentParams struct {
|
||||
ID, ParentID uint64
|
||||
Title, Name, Mobile, Remark string
|
||||
}
|
||||
|
||||
type DepartmentTree struct {
|
||||
*model2.SysDepartment
|
||||
Children []*DepartmentTree `json:"children"`
|
||||
}
|
||||
|
||||
func (c *Department) tree(src []*model2.SysDepartment, parentID uint64) []*DepartmentTree {
|
||||
out := make([]*DepartmentTree, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &DepartmentTree{
|
||||
SysDepartment: v,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *Department) List() ([]*DepartmentTree, error) {
|
||||
mSysDepartment := model.NewSysDepartment()
|
||||
|
||||
out := make([]*model2.SysDepartment, 0)
|
||||
|
||||
if err := model2.Scan(mSysDepartment.SysDepartment, &out, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func (c *Department) Select() ([]*DepartmentTree, error) {
|
||||
mSysDepartment := model.NewSysDepartment()
|
||||
|
||||
out := make([]*model2.SysDepartment, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysDepartment.SysDepartment, &out, []string{"id", "name"}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
}
|
||||
|
||||
func (c *Department) Data(params *DepartmentParams) error {
|
||||
mSysDepartment := model.NewSysDepartment()
|
||||
|
||||
if params.ID <= 0 {
|
||||
mSysDepartment.ParentID = params.ParentID
|
||||
mSysDepartment.Title = params.Title
|
||||
mSysDepartment.Name = params.Name
|
||||
mSysDepartment.Mobile = params.Mobile
|
||||
mSysDepartment.Remark = params.Remark
|
||||
|
||||
return model2.Create(mSysDepartment.SysDepartment)
|
||||
}
|
||||
mSysDepartment.ID = params.ID
|
||||
|
||||
return model2.Updates(mSysDepartment.SysDepartment, map[string]interface{}{
|
||||
"parent_id": params.ParentID, "title": params.Title, "name": params.Name,
|
||||
"mobile": params.Mobile, "remark": params.Remark, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Department) Delete(id uint64) error {
|
||||
mSysDepartment := model.NewSysDepartment()
|
||||
mSysDepartment.ID = id
|
||||
|
||||
if err := model2.Delete(mSysDepartment.SysDepartment); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewDepartment() DepartmentHandle {
|
||||
return func(session *service.Session) *Department {
|
||||
return &Department{Platform: &Platform{Session: session}}
|
||||
}
|
||||
}
|
57
app/api/admin/controller/logs.go
Normal file
57
app/api/admin/controller/logs.go
Normal file
@ -0,0 +1,57 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/tools/ip"
|
||||
)
|
||||
|
||||
type Log struct{ *Platform }
|
||||
|
||||
type LogHandle func(session *service.Session) *Log
|
||||
|
||||
type (
|
||||
// LogForLogin 登录日志
|
||||
LogForLogin struct {
|
||||
*model.SysUserLoginLogInfo
|
||||
IPAddress string `json:"ip_address"`
|
||||
}
|
||||
)
|
||||
|
||||
// Login 登录日志
|
||||
func (c *Log) Login(name string, page, pageSize int) (*ReturnPages, error) {
|
||||
mSysUserLoginLogs := model.NewSysUserLoginLog()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("l.tenant_id", c.TenantID))
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mSysUserLoginLogs.Logs(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*LogForLogin, 0)
|
||||
|
||||
for _, v := range out {
|
||||
ipAddress, _ := ip.Find(v.IP)
|
||||
|
||||
list = append(list, &LogForLogin{
|
||||
SysUserLoginLogInfo: v, IPAddress: string(ipAddress),
|
||||
})
|
||||
}
|
||||
return &ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewLog() LogHandle {
|
||||
return func(session *service.Session) *Log {
|
||||
return &Log{Platform: &Platform{Session: session}}
|
||||
}
|
||||
}
|
228
app/api/admin/controller/manage/examine.go
Normal file
228
app/api/admin/controller/manage/examine.go
Normal file
@ -0,0 +1,228 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Examine struct {
|
||||
*service.Session
|
||||
local string
|
||||
}
|
||||
|
||||
type ExamineHandle func(session *service.Session, local string) *Examine
|
||||
|
||||
type ExamineManageInfo struct {
|
||||
IModel model2.IModel
|
||||
UIDs []uint64 // 用户表UUID
|
||||
}
|
||||
|
||||
// examineHandle 审核处理
|
||||
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
||||
config.TenantUserIdentityForCompany: examineCompany,
|
||||
config.TenantUserIdentityForExpert: examineExpert,
|
||||
config.TenantUserIdentityForResearch: examineResearch,
|
||||
config.TenantUserIdentityForLaboratory: examineLaboratory,
|
||||
}
|
||||
|
||||
func checkManage(IModel model2.IModel, id uint64) error {
|
||||
IModel.SetID(id)
|
||||
|
||||
if isExist, err := model2.FirstField(IModel, []string{"id", "examine_status"}); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("数据信息不存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func examineCompany(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
err := checkManage(mManageCompany.ManageCompany, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageCompany.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
mUserCompany := model.NewUserCompany()
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
if err = model2.Pluck(mUserCompany.UserCompany, "uid", &uids, model2.NewWhere("company_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ExamineManageInfo{IModel: mManageCompany.ManageCompany, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineExpert(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
err := checkManage(mManageExpert.ManageExpert, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageExpert.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
mUserExpert := model.NewUserExpert()
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
if err = model2.Pluck(mUserExpert.UserExpert, "uid", &uids, model2.NewWhere("expert_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ExamineManageInfo{IModel: mManageExpert.ManageExpert, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineResearch(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageResearch := model.NewManageResearch()
|
||||
|
||||
err := checkManage(mManageResearch.ManageResearch, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageResearch.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
|
||||
mUserResearch := model.NewUserResearch()
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
if err = model2.Pluck(mUserResearch.UserResearch, "uid", &uids, model2.NewWhere("research_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ExamineManageInfo{IModel: mManageResearch.ManageResearch, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineLaboratory(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
err := checkManage(mManageLaboratory.ManageLaboratory, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageLaboratory.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
|
||||
mUserLaboratory := model.NewUserLaboratory()
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
if err = model2.Pluck(mUserLaboratory.UserLaboratory, "uid", &uids, model2.NewWhere("laboratory_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ExamineManageInfo{IModel: mManageLaboratory.ManageLaboratory, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
func examineAgent(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageAgent := model.NewManageAgent()
|
||||
|
||||
err := checkManage(mManageAgent.ManageAgent, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageAgent.Examine.ExamineStatus != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("操作错误,当前入驻信息已审核")
|
||||
}
|
||||
|
||||
mUserAgent := model.NewUserAgent()
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
if err = model2.Pluck(mUserAgent.UserAgent, "uid", &uids, model2.NewWhere("laboratory_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ExamineManageInfo{IModel: mManageAgent.ManageAgent, UIDs: uids}, nil
|
||||
}
|
||||
|
||||
// Launch 发起审核
|
||||
func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
_status := model2.ExamineStatusKind(status)
|
||||
|
||||
if _status != model2.ExamineStatusForRefuse && _status != model2.ExamineStatusForAgree {
|
||||
return errors.New("未知的审核模式")
|
||||
}
|
||||
handle, has := examineHandle[identity]
|
||||
|
||||
if !has {
|
||||
return errors.New("未知的身份信息")
|
||||
}
|
||||
data, err := handle(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(data.IModel, map[string]interface{}{
|
||||
"examine_status": status, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 拒绝后,不执行以下数据
|
||||
if _status == model2.ExamineStatusForRefuse {
|
||||
return nil
|
||||
}
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
users := make([]*model2.UserInstance, 0)
|
||||
|
||||
if err = model2.ScanFields(mUserInstance.UserInstance, &users, []string{"id", "uuid", "identity"},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereIn("uuid", data.UIDs),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
|
||||
identitys := make([]*model2.UserIdentity, 0)
|
||||
|
||||
now := time.Now()
|
||||
|
||||
snowflake, _ := utils.NewSnowflake(1)
|
||||
|
||||
for _, v := range users {
|
||||
identitys = append(identitys, &model2.UserIdentity{
|
||||
UUID: uint64(snowflake.GetID()),
|
||||
UID: v.UUID,
|
||||
Identity: identity,
|
||||
ModelAt: model2.ModelAt{
|
||||
CreatedAt: now, UpdatedAt: now,
|
||||
},
|
||||
})
|
||||
if err = model2.UpdatesWhere(mUserInstance.UserInstance, map[string]interface{}{
|
||||
"identity": mUserInstance.Identity | identity, "updated_at": now,
|
||||
}, []*model2.ModelWhere{
|
||||
model2.NewWhere("id", v.ID),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(identitys) > 0 {
|
||||
if err = model2.Creates(mUserIdentity.UserIdentity, identity, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewExamine() ExamineHandle {
|
||||
return func(session *service.Session, local string) *Examine {
|
||||
return &Examine{
|
||||
Session: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
96
app/api/admin/controller/manage/instance.go
Normal file
96
app/api/admin/controller/manage/instance.go
Normal file
@ -0,0 +1,96 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
*service.Session
|
||||
gorm.Model
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *service.Session, local string) *Instance
|
||||
|
||||
type (
|
||||
// InstanceForExpert 专家信息
|
||||
InstanceForExpert struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Industry []string `json:"industry"`
|
||||
ResearchName string `json:"research_name"`
|
||||
LaboratoryName string `json:"laboratory_name"`
|
||||
Address string `json:"address"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) Company(name string, status int, page, pageSize int) {
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("name", name))
|
||||
}
|
||||
|
||||
var count int64
|
||||
|
||||
mManageCompany.Companys(page, pageSize, &count)
|
||||
}
|
||||
|
||||
// Expert 专家信息
|
||||
func (c *Instance) Expert(name string, status int, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("name", name))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceForExpert, 0)
|
||||
|
||||
for _, v := range out {
|
||||
industry := make([]string, 0)
|
||||
|
||||
for _, v := range strings.Split(v.Industry, ";") {
|
||||
industry = append(industry, config.GetIndustryInfo(v, "-"))
|
||||
}
|
||||
// 研究机构,实验室
|
||||
researchName := v.LaboratoryName
|
||||
laboratoryName := ""
|
||||
|
||||
if v.LaboratoryName != "" {
|
||||
researchName = v.ResearchName
|
||||
laboratoryName = v.LaboratoryName
|
||||
}
|
||||
list = append(list, &InstanceForExpert{ID: v.GetEncodeID(), Name: v.Name, Industry: industry,
|
||||
ResearchName: researchName, LaboratoryName: laboratoryName,
|
||||
Address: v.FormatBasic(), CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session, local string) *Instance {
|
||||
return &Instance{
|
||||
Session: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
97
app/api/admin/controller/menu/base.go
Normal file
97
app/api/admin/controller/menu/base.go
Normal file
@ -0,0 +1,97 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type (
|
||||
Tree struct {
|
||||
*model2.SysMenu
|
||||
Children []*Tree `json:"children"`
|
||||
}
|
||||
TreeChecked struct {
|
||||
*model2.SysMenuBasic
|
||||
Checked bool `json:"checked"`
|
||||
Children []*TreeChecked `json:"children"`
|
||||
}
|
||||
)
|
||||
|
||||
// tree 树状筛选
|
||||
func tree(src []*model2.SysMenu, parentID uint64) []*Tree {
|
||||
out := make([]*Tree, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &Tree{
|
||||
SysMenu: v,
|
||||
Children: tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TreeCheckedFunc 树状筛选
|
||||
func TreeCheckedFunc(src []*model.SysMenuScene, parentID uint64) []*TreeChecked {
|
||||
out := make([]*TreeChecked, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &TreeChecked{
|
||||
SysMenuBasic: v.SysMenuBasic,
|
||||
Checked: v.SceneID > 0,
|
||||
Children: TreeCheckedFunc(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// menuForSystem 系统管理员菜单
|
||||
func menuForSystem(iModel model2.IModel, where ...*model2.ModelWhere) ([]*Tree, error) {
|
||||
out, err := iModel.(*model.SysMenu).SystemMenu(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tree(out, 0), nil
|
||||
}
|
||||
|
||||
// MenuForSystem 系统管理员菜单
|
||||
func MenuForSystem(iModel model2.IModel, where ...*model2.ModelWhere) ([]*Tree, error) {
|
||||
out, err := iModel.(*model.SysMenu).SystemMenu(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tree(out, 0), nil
|
||||
}
|
||||
|
||||
// MenuForTenant 租户人员菜单
|
||||
func MenuForTenant(iModel model2.IModel, tenantID uint64) ([]*TreeChecked, error) {
|
||||
out, err := iModel.(*model.SysMenu).TenantMenu(tenantID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return TreeCheckedFunc(out, 0), nil
|
||||
}
|
||||
|
||||
func MenuForRole(iModel model2.IModel, tenantID uint64, roleID uint64) ([]*TreeChecked, error) {
|
||||
out, err := iModel.(*model.SysMenu).RoleMenu(tenantID, roleID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return TreeCheckedFunc(out, 0), nil
|
||||
}
|
||||
|
||||
// MenuForUser 当前用户菜单
|
||||
func MenuForUser(iModel model2.IModel, tenantID uint64, uid uint64) ([]*TreeChecked, error) {
|
||||
out, err := iModel.(*model.SysMenu).UserMenu(tenantID, uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return TreeCheckedFunc(out, 0), nil
|
||||
}
|
113
app/api/admin/controller/menu/menu.go
Normal file
113
app/api/admin/controller/menu/menu.go
Normal file
@ -0,0 +1,113 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Instance 菜单管理
|
||||
type Instance struct{ *controller.Platform }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
type (
|
||||
// InstanceParams 菜单参数
|
||||
InstanceParams struct {
|
||||
ID, ParentID uint64
|
||||
Kind, Auth int
|
||||
Name, Link, Component, Icon string
|
||||
Sort, Status int
|
||||
Remark string
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List() ([]*Tree, error) {
|
||||
mSysMenu := model.NewSysMenu()
|
||||
|
||||
auth := []model2.SysMenuAuth{model2.SysMenuAuthForOrdinary}
|
||||
|
||||
if c.IsAdmin {
|
||||
auth = append(auth, model2.SysMenuAuthForSystem)
|
||||
}
|
||||
return menuForSystem(mSysMenu, model2.NewWhereIn("auth", auth))
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Instance) Form(params *InstanceParams) error {
|
||||
if params.ID <= 0 {
|
||||
return model2.Create(&model2.SysMenu{
|
||||
SysMenuBasic: model2.SysMenuBasic{
|
||||
ParentID: params.ParentID,
|
||||
Name: params.Name,
|
||||
Kind: model2.SysMenuKind(params.Kind),
|
||||
Link: params.Link,
|
||||
Component: params.Component,
|
||||
Icon: params.Icon,
|
||||
},
|
||||
Auth: model2.SysMenuAuth(params.Auth),
|
||||
Sort: params.Sort,
|
||||
Status: model2.SysMenuStatusForNormal,
|
||||
Remark: params.Remark,
|
||||
})
|
||||
}
|
||||
out := model.NewSysMenu()
|
||||
out.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstWhere(out.SysMenu)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("菜单信息不存在")
|
||||
}
|
||||
out.ParentID = params.ParentID
|
||||
out.Name = params.Name
|
||||
out.Kind = model2.SysMenuKind(params.Kind)
|
||||
out.Link = params.Link
|
||||
out.Component = params.Component
|
||||
out.Icon = params.Icon
|
||||
out.Auth = model2.SysMenuAuth(params.Auth)
|
||||
out.Sort = params.Sort
|
||||
out.Status = model2.SysMenuStatus(params.Status)
|
||||
out.Remark = params.Remark
|
||||
|
||||
if err = model2.Save(out); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status 状态操作
|
||||
func (c *Instance) Status(id uint64, status int) error {
|
||||
mSysMenu := model.NewSysMenu()
|
||||
mSysMenu.ID = id
|
||||
|
||||
if err := model2.Updates(mSysMenu.SysMenu, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysMenu := model.NewSysMenu()
|
||||
mSysMenu.ID = id
|
||||
|
||||
if err := model2.Delete(mSysMenu.SysMenu); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
87
app/api/admin/controller/role/auth.go
Normal file
87
app/api/admin/controller/role/auth.go
Normal file
@ -0,0 +1,87 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
auth2 "SciencesServer/app/api/admin/controller/auth"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Auth struct{ *controller.Platform }
|
||||
|
||||
type AuthHandle func(session *service.Session) *Auth
|
||||
|
||||
// List 角色权限列表
|
||||
func (c *Auth) List(roleID uint64) ([]*auth2.TreeChecked, error) {
|
||||
mSysAuth := model3.NewSysAuth()
|
||||
|
||||
out, err := mSysAuth.RoleAuth(c.TenantID, roleID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auth2.TreeCheckedFunc(out, 0), nil
|
||||
}
|
||||
|
||||
// Bind 角色权限绑定
|
||||
func (c *Auth) Bind(roleID uint64, authIDs []uint64) error {
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysRoleAuth := model3.NewSysRoleAuth()
|
||||
|
||||
err := model2.DeleteWhere(mSysRoleAuth.SysRoleAuth, []*model2.ModelWhere{model2.NewWhere("role_id", roleID)}, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 查询权限信息
|
||||
mSysAuth := model3.NewSysAuth()
|
||||
|
||||
auths := make([]*model2.SysAuth, 0)
|
||||
|
||||
if err = model2.Find(mSysAuth.SysAuth, &auths, &model2.ModelWhereOrder{Where: model2.NewWhereIn("id", authIDs)}); err != nil {
|
||||
return err
|
||||
}
|
||||
authRequests := make([]*service.AuthRequest, 0)
|
||||
|
||||
roles := make([]*model2.SysRoleAuth, 0)
|
||||
|
||||
for _, v := range auths {
|
||||
roles = append(roles, &model2.SysRoleAuth{
|
||||
ModelTenant: model2.ModelTenant{TenantID: c.TenantID}, RoleID: roleID, AuthID: v.ID,
|
||||
})
|
||||
if v.Auth == "" {
|
||||
continue
|
||||
}
|
||||
authRequests = append(authRequests, &service.AuthRequest{Url: v.Auth, Method: "*"})
|
||||
}
|
||||
if err = model2.Creates(mSysRoleAuth.SysRoleAuth, roles, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
//permission := service.NewPermission([]string{utils.UintToString(roleID)}, authRequests...)(c.TenantKey, "")
|
||||
//// 删除角色权限
|
||||
//if _, err = permission.RemoveRolePolicy(); err != nil {
|
||||
// logger.ErrorF("删除角色【%d】规则信息错误:%v", roleID, err)
|
||||
// return
|
||||
//}
|
||||
//if len(authRequests) > 0 {
|
||||
// if _, err = permission.AddPolicies(); err != nil {
|
||||
// logger.ErrorF("创建角色【%d】规则信息错误:%v", roleID, err)
|
||||
// return
|
||||
// }
|
||||
//}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewAuth() AuthHandle {
|
||||
return func(session *service.Session) *Auth {
|
||||
return &Auth{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
173
app/api/admin/controller/role/instance.go
Normal file
173
app/api/admin/controller/role/instance.go
Normal file
@ -0,0 +1,173 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 角色信息
|
||||
InstanceInfo struct {
|
||||
*model2.SysRole
|
||||
StatusTitle string `json:"status_title"`
|
||||
}
|
||||
// InstanceBasicInfo 角色基本信息
|
||||
InstanceBasicInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List(name string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysRole := model.NewSysRole()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
||||
},
|
||||
&model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
})
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("status", status),
|
||||
})
|
||||
}
|
||||
var count int64
|
||||
|
||||
out := make([]*model2.SysRole, 0)
|
||||
|
||||
if err := model2.Pages(mSysRole.SysRole, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InstanceInfo{SysRole: v, StatusTitle: v.StatusTitle()})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
|
||||
}
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *Instance) Select() ([]*InstanceBasicInfo, error) {
|
||||
mSysRole := model.NewSysRole()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
||||
},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("status", model2.SysRoleStatusForNormal),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
}
|
||||
out := make([]*InstanceBasicInfo, 0)
|
||||
|
||||
if err := model2.Scan(mSysRole.SysRole, &out, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Data 数据操作
|
||||
func (c *Instance) Data(id uint64, name, remark string, sort int) error {
|
||||
mSysRole := model.NewSysRole()
|
||||
|
||||
if id <= 0 {
|
||||
mSysRole.TenantID = c.TenantID
|
||||
mSysRole.Name = name
|
||||
mSysRole.Remark = remark
|
||||
mSysRole.Sort = sort
|
||||
mSysRole.Status = model2.SysRoleStatusForNormal
|
||||
|
||||
if err := model2.Create(mSysRole.SysRole); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
mSysRole.ID = id
|
||||
|
||||
if err := model2.Updates(mSysRole.SysRole, map[string]interface{}{
|
||||
"name": name, "remark": remark, "sort": sort,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status 状态操作
|
||||
func (c *Instance) Status(id uint64, status int) error {
|
||||
mSysRole := model.NewSysRole()
|
||||
mSysRole.ID = id
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysRole.SysRole)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("角色不存在")
|
||||
}
|
||||
if c.TenantID > 0 && c.TenantID != mSysRole.TenantID {
|
||||
return errors.New("不可操作其他租户角色")
|
||||
}
|
||||
if err = model2.Updates(mSysRole.SysRole, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysRole := model.NewSysRole()
|
||||
mSysRole.ID = id
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysRole.SysRole)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("角色不存在")
|
||||
}
|
||||
if c.TenantID > 0 && c.TenantID != mSysRole.TenantID {
|
||||
return errors.New("不可删除其他租户角色")
|
||||
}
|
||||
if err = model2.Delete(mSysRole.SysRole); err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
//permission := service.NewPermission([]string{utils.UintToString(id)})(c.TenantKey, "")
|
||||
//// 删除角色权限
|
||||
//if _, err = permission.RemoveRolePolicy(); err != nil {
|
||||
// logger.ErrorF("删除租户【%s】下角色【%d】权限信息错误:%v", c.TenantKey, id, err)
|
||||
// return
|
||||
//}
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
74
app/api/admin/controller/role/menu.go
Normal file
74
app/api/admin/controller/role/menu.go
Normal file
@ -0,0 +1,74 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Menu struct{ *controller.Platform }
|
||||
|
||||
type MenuHandle func(session *service.Session) *Menu
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List(roleID uint64) ([]*menu2.TreeChecked, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
return menu2.MenuForRole(mSysMenu, c.TenantID, roleID)
|
||||
}
|
||||
|
||||
// Bind 绑定菜单
|
||||
func (c *Menu) Bind(roleID uint64, menuIDs []uint64) error {
|
||||
if len(menuIDs) > 0 {
|
||||
var count int64
|
||||
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
|
||||
if err := model2.Count(mSysMenu.SysMenu, &count, model2.NewWhereIn("id", menuIDs),
|
||||
model2.NewWhere("auth", model2.SysMenuAuthForSystem)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("不可设置超管菜单")
|
||||
}
|
||||
}
|
||||
mSysRoleMenu := model3.NewSysRoleMenu()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
err := model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{model2.NewWhere("role_id", roleID)}, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(menuIDs) <= 0 {
|
||||
return nil
|
||||
}
|
||||
menus := make([]*model2.SysRoleMenu, 0)
|
||||
|
||||
mark := make(map[uint64]uint64, 0)
|
||||
|
||||
for _, v := range menuIDs {
|
||||
if _, has := mark[v]; has {
|
||||
continue
|
||||
}
|
||||
menus = append(menus, &model2.SysRoleMenu{
|
||||
ModelTenant: model2.ModelTenant{TenantID: c.TenantID}, RoleID: roleID, MenuID: v,
|
||||
})
|
||||
mark[v] = v
|
||||
}
|
||||
if err = model2.Creates(mSysRoleMenu.SysRoleMenu, menus, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewMenu() MenuHandle {
|
||||
return func(session *service.Session) *Menu {
|
||||
return &Menu{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
79
app/api/admin/controller/role/user.go
Normal file
79
app/api/admin/controller/role/user.go
Normal file
@ -0,0 +1,79 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct{ *controller.Platform }
|
||||
|
||||
type UserHandle func(session *service.Session) *User
|
||||
|
||||
// List 列表信息
|
||||
func (c *User) List(uid uint64) ([]*model3.SysRoleUserInfo, error) {
|
||||
mSysRole := model3.NewSysRole()
|
||||
|
||||
out, err := mSysRole.UserRole(uid)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Bind 绑定角色
|
||||
func (c *User) Bind(uid uint64, roleIDs []uint64) error {
|
||||
mSysUserRole := model3.NewSysUserRole()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
err := model2.DeleteWhere(mSysUserRole.SysUserRole, []*model2.ModelWhere{model2.NewWhere("uid", uid)}, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roles := make([]*model2.SysUserRole, 0)
|
||||
obj := make([]string, 0)
|
||||
|
||||
mark := make(map[uint64]uint64, 0)
|
||||
|
||||
for _, v := range roleIDs {
|
||||
if _, has := mark[v]; has {
|
||||
continue
|
||||
}
|
||||
obj = append(obj, utils.UintToString(v))
|
||||
|
||||
roles = append(roles, &model2.SysUserRole{
|
||||
UID: uid, RoleID: v,
|
||||
})
|
||||
mark[v] = v
|
||||
}
|
||||
if err = model2.Creates(mSysUserRole.SysUserRole, roles, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
//permission := service.NewPermission(obj)(c.TenantKey, utils.UintToString(uid))
|
||||
//
|
||||
//if _, err = permission.DeleteRolesForUser(false); err != nil {
|
||||
// logger.ErrorF("删除用户【%d】角色权限错误:%v", uid, err)
|
||||
// return
|
||||
//}
|
||||
//if _, err = permission.AddRoleForUser(); err != nil {
|
||||
// logger.ErrorF("添加用户【%d】角色权限错误:%v", uid, err)
|
||||
// return
|
||||
//}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewUser() UserHandle {
|
||||
return func(session *service.Session) *User {
|
||||
return &User{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
package controller
|
107
app/api/admin/controller/tenant/auth.go
Normal file
107
app/api/admin/controller/tenant/auth.go
Normal file
@ -0,0 +1,107 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/logger"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Auth struct{ *controller.Platform }
|
||||
|
||||
type AuthHandle func(session *service.Session) *Auth
|
||||
|
||||
// delete 删除所有权限
|
||||
func (c *Auth) delete(tenantID uint64, tenantKey string, tx *gorm.DB) error {
|
||||
mSysRoleAuth := model3.NewSysRoleAuth()
|
||||
|
||||
err := model2.DeleteWhere(mSysRoleAuth.SysRoleAuth, []*model2.ModelWhere{model2.NewWhere("tenant_id", tenantID)}, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
permission := service.NewPermission(nil)(tenantKey, "")
|
||||
|
||||
if succ, err := permission.RemoveFilteredGroupingPolicy(); err != nil {
|
||||
logger.ErrorF("删除租户【%s】权限信息错误:%v", tenantKey, err)
|
||||
} else if !succ {
|
||||
logger.ErrorF("删除租户【%s】权限信息失败", tenantKey)
|
||||
}
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// revoke 撤销某些权限
|
||||
func (c *Auth) revoke(tenantID uint64, tenantKey string, authIDs []uint64, tx *gorm.DB) error {
|
||||
// 查询该租户下不含有的权限信息
|
||||
mSysRuleAuth := model3.NewSysRoleAuth()
|
||||
|
||||
out, err := mSysRuleAuth.Auths(model2.NewWhere("r.tenant_id", tenantID), model2.NewWhereNotIn("r_a.auth_id", authIDs))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(out) <= 0 {
|
||||
return nil
|
||||
}
|
||||
roleAuthIDs := make([]uint64, 0)
|
||||
roleIDs := make([]string, 0)
|
||||
auths := make([]*service.AuthRequest, 0)
|
||||
|
||||
for _, v := range out {
|
||||
roleAuthIDs = append(roleAuthIDs, v.ID)
|
||||
roleIDs = append(roleIDs, utils.UintToString(v.RoleID))
|
||||
auths = append(auths, &service.AuthRequest{Url: v.Auth, Method: "*"})
|
||||
}
|
||||
if err = model2.DeleteWhere(mSysRuleAuth.SysRoleAuth, []*model2.ModelWhere{model2.NewWhereIn("id", roleAuthIDs)}); err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
//permission := service.NewPermission(roleIDs, auths...)(c.TenantKey, "")
|
||||
//// 删除角色权限
|
||||
//if _, err = permission.RemoveNamedGroupingPolicies(); err != nil {
|
||||
// logger.ErrorF("删除租户【%s】下角色权限错误:%v", tenantKey, err)
|
||||
// return
|
||||
//}
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Bind 绑定权限
|
||||
func (c *Auth) Bind(tenantID uint64, authIDs []uint64) error {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = tenantID
|
||||
|
||||
isExist, err := model2.FirstField(mSysTenant.SysTenant, []string{"id", "key"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司信息不存在或已被删除")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysTenantAuth := model3.NewSysTenantAuth()
|
||||
|
||||
if err = model2.DeleteWhere(mSysTenantAuth.SysTenantAuth, []*model2.ModelWhere{model2.NewWhere("tenant_id", mSysTenant.ID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(authIDs) <= 0 {
|
||||
// 删除租户下所有角色的权限
|
||||
return c.delete(mSysTenant.ID, mSysTenant.Key, tx)
|
||||
}
|
||||
return c.revoke(mSysTenant.ID, mSysTenant.Key, authIDs, tx)
|
||||
})
|
||||
}
|
||||
|
||||
func NewAuth() AuthHandle {
|
||||
return func(session *service.Session) *Auth {
|
||||
return &Auth{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
421
app/api/admin/controller/tenant/instance.go
Normal file
421
app/api/admin/controller/tenant/instance.go
Normal file
@ -0,0 +1,421 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
auth2 "SciencesServer/app/api/admin/controller/auth"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 租户信息
|
||||
InstanceInfo struct {
|
||||
*model3.SysTenantInfo
|
||||
}
|
||||
// InstanceParams 租户参数信息
|
||||
InstanceParams struct {
|
||||
ID uint64
|
||||
Image, Name, Account, Password, RepeatPwd string
|
||||
Deadline, Remark string
|
||||
}
|
||||
// InstanceBasicInfo 租户基本信息
|
||||
InstanceBasicInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
// InstanceDetailType 租户信息类型
|
||||
InstanceDetailType int
|
||||
)
|
||||
|
||||
const (
|
||||
// InstanceDetailTypeForBasic 基本信息
|
||||
InstanceDetailTypeForBasic InstanceDetailType = iota + 1
|
||||
// InstanceDetailTypeForMember 成员信息
|
||||
InstanceDetailTypeForMember
|
||||
// InstanceDetailTypeForAuth 权限信息
|
||||
InstanceDetailTypeForAuth
|
||||
)
|
||||
|
||||
// instanceDetailGetHandle 详细信息获取操作
|
||||
var instanceDetailGetHandle = map[InstanceDetailType]func(id uint64) func(args ...interface{}) (interface{}, error){
|
||||
InstanceDetailTypeForBasic: basic,
|
||||
InstanceDetailTypeForMember: member,
|
||||
InstanceDetailTypeForAuth: auth,
|
||||
}
|
||||
|
||||
// basic 基本信息
|
||||
func basic(id uint64) func(args ...interface{}) (interface{}, error) {
|
||||
return func(args ...interface{}) (interface{}, error) {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = id
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("信息不存在")
|
||||
}
|
||||
return &InstanceInfo{SysTenantInfo: &model3.SysTenantInfo{
|
||||
SysTenant: mSysTenant.SysTenant,
|
||||
}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// member 人员信息
|
||||
func member(id uint64) func(args ...interface{}) (interface{}, error) {
|
||||
return func(args ...interface{}) (interface{}, error) {
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
page := args[0].(int)
|
||||
pageSize := args[1].(int)
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u_t.tenant_id", id)}
|
||||
|
||||
if args[2] != nil && args[2] != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", args[2]))
|
||||
}
|
||||
if args[3] != nil && args[3].(int) > 0 {
|
||||
where = append(where, model2.NewWhere("u_t.status", args[3]))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mSysUserTenant.Member(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &controller.ReturnPages{Data: out, Count: count}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// auth 权限信息
|
||||
func auth(id uint64) func(args ...interface{}) (interface{}, error) {
|
||||
return func(args ...interface{}) (interface{}, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
|
||||
_menu, err := mSysMenu.TenantMenu(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mSysAuth := model3.NewSysAuth()
|
||||
|
||||
_auth := make([]*model3.SysAuthScene, 0)
|
||||
|
||||
if _auth, err = mSysAuth.TenantAuth(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"menu": menu2.TreeCheckedFunc(_menu, 0), "auth": auth2.TreeCheckedFunc(_auth, 0),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// validateForCustomerCount 验证最大客户数
|
||||
func (c *Instance) validateForCustomerCount(tenantID uint64, sysValue, srcValue int) (bool, error) {
|
||||
if srcValue > sysValue {
|
||||
return true, nil
|
||||
}
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Count(mSysTenant.SysTenant, &count, model2.NewWhere("parent_id", tenantID)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return int(count) <= srcValue, nil
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List(name string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
|
||||
var count int64
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("t.parent_id", 0)}
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("t.name", name))
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("t.status", status))
|
||||
}
|
||||
out, err := mSysTenant.Tenants(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis(config.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &InstanceInfo{SysTenantInfo: v})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Add 数据处理
|
||||
func (c *Instance) Add(params *InstanceParams) error {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
|
||||
if params.Password != params.RepeatPwd {
|
||||
return errors.New("密码不一致")
|
||||
}
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant, model2.NewWhere("name", params.Name))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("该租户/公司名称已存在")
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
|
||||
if isExist, err = model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("account", params.Account)); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("登录用户名已存在")
|
||||
}
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysTenant.Image.Image = params.Image
|
||||
mSysTenant.Name = params.Name
|
||||
mSysTenant.Remark = params.Remark
|
||||
|
||||
if err = model2.Create(mSysTenant.SysTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUser.Name = mSysTenant.Name
|
||||
mSysUser.Account = params.Account
|
||||
mSysUser.Password = params.Password
|
||||
|
||||
if err = model2.Create(mSysUser.SysUser, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.TenantID = mSysTenant.ID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
mSysUserTenant.Identity = model2.SysUserTenantIdentityForSystemAdmin
|
||||
|
||||
if err = model2.Create(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edit 修改信息
|
||||
func (c *Instance) Edit(params *InstanceParams) error {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司信息不存在")
|
||||
} else if c.TenantID > 0 {
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
return errors.New("不可修改其他租户/公司的信息")
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可修改其他租户/公司的客户信息")
|
||||
}
|
||||
}
|
||||
if mSysTenant.Name != params.Name {
|
||||
if isExist, err = model2.FirstWhere(mSysTenant.SysTenant, model2.NewWhere("name", params.Name)); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("该租户/公司名称已存在")
|
||||
}
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
"name": params.Name, "image": params.Image, "remark": params.Remark, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditPassword 修改信息
|
||||
func (c *Instance) EditPassword(params *InstanceParams) error {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司信息不存在")
|
||||
} else if c.TenantID > 0 {
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
return errors.New("不可修改其他租户/公司的用户密码信息")
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可修改其他租户/公司的用户密码信息")
|
||||
}
|
||||
}
|
||||
if params.Password != params.RepeatPwd {
|
||||
return errors.New("密码不一致")
|
||||
}
|
||||
// 查询该租户下管理员信息
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
if isExist, err = model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "uid", "identity"},
|
||||
model2.NewWhere("tenant_id", params.ID), model2.NewWhere("identity", model2.SysUserTenantIdentityForSystemAdmin)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("该租户/公司下管理员信息不存在或已被删除")
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
mSysUser.Password = params.Password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err = model2.UpdatesWhere(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uuid", mSysUserTenant.UID)}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Instance) Detail(id uint64, tType InstanceDetailType, page, pageSize int, name string, status int) (interface{}, error) {
|
||||
handle, has := instanceDetailGetHandle[tType]
|
||||
|
||||
if !has {
|
||||
return nil, errors.New(fmt.Sprintf("Unknown Tenant Detail Type:%d", tType))
|
||||
}
|
||||
out, err := handle(id)(page, pageSize, name, status)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Renewal 续期操作
|
||||
func (c *Instance) Renewal(id uint64, deadline string) error {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司信息不存在")
|
||||
} else if c.TenantID > 0 {
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
return errors.New("非超级管理员,不可操作")
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("非法操作,不可续期他人客户使用期限")
|
||||
}
|
||||
}
|
||||
now := time.Now()
|
||||
|
||||
updates := make(map[string]interface{}, 0)
|
||||
updates["updated_at"] = now
|
||||
|
||||
if err = model2.Updates(mSysTenant.SysTenant, updates); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// StartUp 启用处理
|
||||
func (c *Instance) StartUp(id uint64) error {
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司/客户信息不存在")
|
||||
} else if c.TenantID > 0 {
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
return errors.New("非超级管理员,不可操作")
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可启用其他租户/公司客户")
|
||||
}
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable 禁用处理
|
||||
func (c *Instance) Disable(id uint64) error {
|
||||
//mSysTenant := model.NewSysTenant()
|
||||
//mSysTenant.ID = id
|
||||
//
|
||||
//isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
//if err != nil {
|
||||
// return err
|
||||
//} else if !isExist {
|
||||
// return errors.New("租户/公司/客户信息不存在")
|
||||
//} else if c.TenantID > 0 {
|
||||
// if mSysTenant.ParentID <= 0 {
|
||||
// return errors.New("非超级管理员,不可操作")
|
||||
// } else if c.TenantID != mSysTenant.ParentID {
|
||||
// return errors.New("不可启用其他租户/公司/客户")
|
||||
// }
|
||||
//} else if mSysTenant.Status == model2.SysTenantStatusForDisable {
|
||||
// return errors.New("该租户/公司/客户已是禁用状态")
|
||||
//}
|
||||
//if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
// "status": model2.SysTenantStatusForDisable, "updated_at": time.Now(),
|
||||
//}); err != nil {
|
||||
// return err
|
||||
//}
|
||||
//// TODO:推送用户强制退出,并强行删除所有产品数据
|
||||
//service.Publish(config.EventForRedisListDestroy, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MemberBind 人员绑定/解绑
|
||||
func (c *Instance) MemberBind(id uint64, status int) error {
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
}
|
||||
|
||||
if err := model2.Updates(mSysUserTenant.SysUserTenant, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
88
app/api/admin/controller/tenant/menu.go
Normal file
88
app/api/admin/controller/tenant/menu.go
Normal file
@ -0,0 +1,88 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Menu struct{ *controller.Platform }
|
||||
|
||||
type MenuHandle func(session *service.Session) *Menu
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List(tenantID uint64) ([]*menu2.TreeChecked, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
return menu2.MenuForTenant(mSysMenu, tenantID)
|
||||
}
|
||||
|
||||
// Bind 绑定菜单
|
||||
func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
if len(menuIDs) > 0 {
|
||||
var count int64
|
||||
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
|
||||
if err := model2.Count(mSysMenu.SysMenu, &count, model2.NewWhereIn("id", menuIDs),
|
||||
model2.NewWhere("auth", model2.SysMenuAuthForSystem)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("不可设置超管菜单")
|
||||
}
|
||||
}
|
||||
mSysTenantMenu := model3.NewSysTenantMenu()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// TODO:先全部删除,后期考虑局部删除
|
||||
err := model2.DeleteWhere(mSysTenantMenu.SysTenantMenu, []*model2.ModelWhere{model2.NewWhere("tenant_id", tenantID)}, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 租户角色的菜单
|
||||
mSysRoleMenu := model3.NewSysRoleMenu()
|
||||
|
||||
if len(menuIDs) <= 0 {
|
||||
if err = model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{model2.NewWhere("tenant_id", tenantID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
menus := make([]*model2.SysTenantMenu, 0)
|
||||
|
||||
mark := make(map[uint64]uint64, 0)
|
||||
|
||||
for _, v := range menuIDs {
|
||||
if _, has := mark[v]; has {
|
||||
continue
|
||||
}
|
||||
menus = append(menus, &model2.SysTenantMenu{
|
||||
ModelTenant: model2.ModelTenant{TenantID: tenantID}, MenuID: v,
|
||||
})
|
||||
mark[v] = v
|
||||
}
|
||||
if err = model2.Creates(mSysTenantMenu.SysTenantMenu, menus, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 删除租户下角色不存在的菜单
|
||||
if err = model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{
|
||||
model2.NewWhere("tenant_id", tenantID),
|
||||
model2.NewWhereNotIn("menu_id", menuIDs),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewMenu() MenuHandle {
|
||||
return func(session *service.Session) *Menu {
|
||||
return &Menu{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
20
app/api/admin/controller/tenant/struct.go
Normal file
20
app/api/admin/controller/tenant/struct.go
Normal file
@ -0,0 +1,20 @@
|
||||
package tenant
|
||||
|
||||
// InstanceParamsForProtocol 协议参数
|
||||
type InstanceParamsForSetting struct {
|
||||
Protocol []uint
|
||||
MaxDevices, MaxCustomer int
|
||||
}
|
||||
|
||||
// NewProtocol 消息协议
|
||||
func (c *InstanceParamsForSetting) NewProtocol() uint {
|
||||
// &(与):0&0=0 0&1=0 1&0=0 1&1=1
|
||||
// |(或):0&0=0 0&1=1 1&0=1 1&1=1
|
||||
// ^(非):0^0=0 0&1=1 1^0=1 1^1=0
|
||||
var protocol uint
|
||||
|
||||
for i := 0; i < len(c.Protocol); i++ {
|
||||
|
||||
}
|
||||
return protocol
|
||||
}
|
44
app/api/admin/controller/tenant/sub.go
Normal file
44
app/api/admin/controller/tenant/sub.go
Normal file
@ -0,0 +1,44 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
|
||||
"SciencesServer/config"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Sub struct{}
|
||||
|
||||
type SubHandle func() *Sub
|
||||
|
||||
// database 数据表
|
||||
func (c *Sub) database(key string) string {
|
||||
return model2.SubDatabase + "_" + key
|
||||
}
|
||||
|
||||
// sync 同步数据
|
||||
func (c *Sub) sync(tx *gorm.DB, database string) error {
|
||||
// TODO:生成租户对应数据库,并生成对应数据表
|
||||
err := tx.Exec(fmt.Sprintf("CREATE DATABASE %s;", database)).Error
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 使用生成后的数据库
|
||||
if err = tx.Exec(fmt.Sprintf("use %s;", database)).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
iModels := []model2.IModel{}
|
||||
|
||||
for _, v := range iModels {
|
||||
if err = tx.Migrator().CreateTable(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 重新使用默认的数据库
|
||||
tx.Exec(fmt.Sprintf("use %s;", config.EngineInfo.Engines.Mysql.Database))
|
||||
|
||||
return nil
|
||||
}
|
249
app/api/admin/controller/user/instance.go
Normal file
249
app/api/admin/controller/user/instance.go
Normal file
@ -0,0 +1,249 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 基本信息
|
||||
InstanceInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Mobile string `json:"mobile"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
// InstanceUserInfo 用户信息
|
||||
InstanceUserInfo struct {
|
||||
*model3.SysUserTenantUser
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
)
|
||||
|
||||
// InstanceForm 表单信息
|
||||
type InstanceForm struct {
|
||||
ID uint64 // 租户用户主键ID
|
||||
Account, Name, Mobile, Password, Remark string
|
||||
Gender int
|
||||
Departments, Roles []uint64
|
||||
}
|
||||
|
||||
// Info 用户信息
|
||||
func (c *Instance) Info() (*InstanceInfo, error) {
|
||||
mSysUser := model3.NewSysUser()
|
||||
|
||||
_, err := model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &InstanceInfo{
|
||||
UID: mSysUser.UUIDString(), Name: mSysUser.Name, Email: mSysUser.Email, Mobile: mSysUser.Mobile, Remark: mSysUser.Remark,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List(name, mobile string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u_t.tenant_id", c.TenantID)}
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("u.mobile", mobile))
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("u_t.status", status))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mSysUserTenant.User(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceUserInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InstanceUserInfo{SysUserTenantUser: v, UID: utils.UintToString(v.UID)})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Add 添加用户
|
||||
func (c *Instance) Add(params *InstanceForm) error {
|
||||
if utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("手机号码格式错误")
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
// 查询登录账户或手机号码是否注册
|
||||
var count int64
|
||||
|
||||
err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("account", params.Account))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUser.Account = params.Account
|
||||
mSysUser.Name = params.Name
|
||||
mSysUser.Mobile = params.Mobile
|
||||
mSysUser.Gender.Gender = model2.GenderKind(params.Gender)
|
||||
mSysUser.Password = params.Password
|
||||
mSysUser.Remark = params.Remark
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Create(mSysUser.SysUser, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.TenantID = c.TenantID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
if len(params.Departments) > 0 {
|
||||
mSysUserTenant.Department = strings.Join(utils.ArrayStrings(params.Departments), ",")
|
||||
}
|
||||
if len(params.Roles) > 0 {
|
||||
mSysUserTenant.Role = strings.Join(utils.ArrayStrings(params.Roles), ",")
|
||||
}
|
||||
mSysUserTenant.Identity = model2.SysUserTenantIdentityForSystemUser
|
||||
|
||||
if err = model2.Create(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Edit 修改用户信息
|
||||
func (c *Instance) Edit(params *InstanceForm) error {
|
||||
if utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("手机号码格式错误")
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
} else if mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("不可修改他人用户信息")
|
||||
}
|
||||
// 查询用户信息
|
||||
mSysUser := model3.NewSysUser()
|
||||
|
||||
if isExist, err = model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", mSysUserTenant.UID)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
}
|
||||
if params.Mobile != mSysUser.Mobile {
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("该手机号码已注册")
|
||||
}
|
||||
}
|
||||
now := time.Now()
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mSysUserTenant.SysUserTenant, map[string]interface{}{
|
||||
"department": strings.Join(utils.ArrayStrings(params.Departments), ","),
|
||||
"role": strings.Join(utils.ArrayStrings(params.Roles), ","),
|
||||
"updated_at": now,
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"name": params.Name, "mobile": params.Mobile, "gender": params.Gender, "remark": params.Remark, "updated_at": now,
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Instance) Password(id uint64, password, repeatPwd string) error {
|
||||
if password != repeatPwd {
|
||||
return errors.New("两次密码不一致")
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
} else if mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("不可修改他人用户密码")
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err = model2.UpdatesWhere(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}, []*model2.ModelWhere{
|
||||
model2.NewWhere("uuid", mSysUserTenant.UID),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
} else if mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("不可删除他人用户信息")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Delete(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
|
||||
if err = model2.DeleteWhere(mSysUser.SysUser, []*model2.ModelWhere{
|
||||
model2.NewWhere("uuid", mSysUserTenant.UID),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
40
app/api/admin/controller/user/menu.go
Normal file
40
app/api/admin/controller/user/menu.go
Normal file
@ -0,0 +1,40 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
)
|
||||
|
||||
type Menu struct{ *controller.Platform }
|
||||
|
||||
type MenuHandle func(session *service.Session) *Menu
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List() (interface{}, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
|
||||
if c.IsAdmin {
|
||||
return menu2.MenuForSystem(mSysMenu)
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
if isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "identity"},
|
||||
model2.NewWhere("tenant_id", c.TenantID), model2.NewWhere("uid", c.UID)); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
if mSysUserTenant.Identity == model2.SysUserTenantIdentityForSystemAdmin {
|
||||
return menu2.MenuForTenant(mSysMenu, c.TenantID)
|
||||
}
|
||||
return menu2.MenuForUser(mSysMenu, c.TenantID, c.UID)
|
||||
}
|
||||
|
||||
func NewMenu() MenuHandle {
|
||||
return func(session *service.Session) *Menu {
|
||||
return &Menu{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
47
app/api/admin/controller/user/person.go
Normal file
47
app/api/admin/controller/user/person.go
Normal file
@ -0,0 +1,47 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Person struct{ *service.Session }
|
||||
|
||||
type PersonHandle func(session *service.Session) *Person
|
||||
|
||||
// EditPassword 修改密码
|
||||
func (c *Person) EditPassword(oldPassword, password, repeatPwd string) error {
|
||||
if password != repeatPwd {
|
||||
return errors.New("两次密码不一致")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在或已被删除")
|
||||
}
|
||||
if !mSysUser.ValidatePassword(oldPassword) {
|
||||
return errors.New("旧密码错误")
|
||||
}
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err = model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewPerson() PersonHandle {
|
||||
return func(session *service.Session) *Person {
|
||||
return &Person{Session: session}
|
||||
}
|
||||
}
|
79
app/api/admin/controller/user/role.go
Normal file
79
app/api/admin/controller/user/role.go
Normal file
@ -0,0 +1,79 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Role struct{ *controller.Platform }
|
||||
|
||||
type RoleHandle func(session *service.Session) *Role
|
||||
|
||||
// List 列表信息
|
||||
func (c *Role) List(uid uint64) ([]*model3.SysRoleUserInfo, error) {
|
||||
mSysRole := model3.NewSysRole()
|
||||
|
||||
out, err := mSysRole.UserRole(uid)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Bind 绑定角色
|
||||
func (c *Role) Bind(uid uint64, roleIDs []uint64) error {
|
||||
mSysUserRole := model3.NewSysUserRole()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
err := model2.DeleteWhere(mSysUserRole.SysUserRole, []*model2.ModelWhere{model2.NewWhere("uid", uid)}, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
roles := make([]*model2.SysUserRole, 0)
|
||||
obj := make([]string, 0)
|
||||
|
||||
mark := make(map[uint64]uint64, 0)
|
||||
|
||||
for _, v := range roleIDs {
|
||||
if _, has := mark[v]; has {
|
||||
continue
|
||||
}
|
||||
obj = append(obj, utils.UintToString(v))
|
||||
|
||||
roles = append(roles, &model2.SysUserRole{
|
||||
UID: uid, RoleID: v,
|
||||
})
|
||||
mark[v] = v
|
||||
}
|
||||
if err = model2.Creates(mSysUserRole.SysUserRole, roles, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
go utils.TryCatch(func() {
|
||||
//permission := service.NewPermission(obj)(c.TenantKey, utils.UintToString(uid))
|
||||
//
|
||||
//if _, err = permission.DeleteRolesForUser(false); err != nil {
|
||||
// logger.ErrorF("删除用户【%d】角色权限错误:%v", uid, err)
|
||||
// return
|
||||
//}
|
||||
//if _, err = permission.AddRoleForUser(); err != nil {
|
||||
// logger.ErrorF("添加用户【%d】角色权限错误:%v", uid, err)
|
||||
// return
|
||||
//}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewRole() RoleHandle {
|
||||
return func(session *service.Session) *Role {
|
||||
return &Role{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
11
app/api/admin/model/manage_agent.go
Normal file
11
app/api/admin/model/manage_agent.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ManageAgent struct {
|
||||
*model.ManageAgent
|
||||
}
|
||||
|
||||
func NewManageAgent() *ManageAgent {
|
||||
return &ManageAgent{model.NewManageAgent()}
|
||||
}
|
17
app/api/admin/model/manage_company.go
Normal file
17
app/api/admin/model/manage_company.go
Normal file
@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type ManageCompany struct {
|
||||
*model.ManageCompany
|
||||
}
|
||||
|
||||
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) {
|
||||
|
||||
}
|
||||
|
||||
func NewManageCompany() *ManageCompany {
|
||||
return &ManageCompany{}
|
||||
}
|
50
app/api/admin/model/manage_expert.go
Normal file
50
app/api/admin/model/manage_expert.go
Normal file
@ -0,0 +1,50 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageExpert struct {
|
||||
*model.ManageExpert
|
||||
}
|
||||
|
||||
type ManageExpertInfo struct {
|
||||
*model.ManageExpert
|
||||
Name string `json:"name"`
|
||||
ResearchName string `json:"research_name"`
|
||||
LaboratoryName string `json:"laboratory_name"`
|
||||
}
|
||||
|
||||
// Experts 专家信息
|
||||
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
|
||||
mUserInstance := model.NewUserInstance()
|
||||
mSysTenant := model.NewSysTenant()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.*", "u.name", "l.name AS laboratory_name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON e.uid = u.uuid", mUserInstance.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.tenant_id = l.id", mSysTenant.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.parent_id = r.id", mSysTenant.TableName())).
|
||||
Where("")
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageExpertInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("e.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageExpert() *ManageExpert {
|
||||
return &ManageExpert{model.NewManageExpert()}
|
||||
}
|
11
app/api/admin/model/manage_laboratory.go
Normal file
11
app/api/admin/model/manage_laboratory.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ManageLaboratory struct {
|
||||
*model.ManageLaboratory
|
||||
}
|
||||
|
||||
func NewManageLaboratory() *ManageLaboratory {
|
||||
return &ManageLaboratory{model.NewManageLaboratory()}
|
||||
}
|
11
app/api/admin/model/manage_research.go
Normal file
11
app/api/admin/model/manage_research.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ManageResearch struct {
|
||||
*model.ManageResearch
|
||||
}
|
||||
|
||||
func NewManageResearch() *ManageResearch {
|
||||
return &ManageResearch{model.NewManageResearch()}
|
||||
}
|
62
app/api/admin/model/sys_auth.go
Normal file
62
app/api/admin/model/sys_auth.go
Normal file
@ -0,0 +1,62 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysAuth struct {
|
||||
*model.SysAuth
|
||||
}
|
||||
|
||||
// SysAuthScene 信息
|
||||
type SysAuthScene struct {
|
||||
*model.SysAuth
|
||||
SceneID uint64 `json:"scene_id"`
|
||||
}
|
||||
|
||||
// TenantAuth 租户权限
|
||||
func (m *SysAuth) TenantAuth(tenantID uint64) ([]*SysAuthScene, error) {
|
||||
mSysTenantAuth := NewSysTenantAuth()
|
||||
|
||||
out := make([]*SysAuthScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.*, r_a.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t_a ON t_a.auth_id = a.id AND t_a.tenant_id = %d AND t_a.is_deleted = %d",
|
||||
mSysTenantAuth.TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RoleAuth 角色权限
|
||||
func (m *SysAuth) RoleAuth(tenantID, roleID uint64) ([]*SysAuthScene, error) {
|
||||
mSysTenantAuth := NewSysTenantAuth()
|
||||
|
||||
mSysRoleAuth := NewSysRoleAuth()
|
||||
|
||||
out := make([]*SysAuthScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.*, r_a.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t_a ON t_a.auth_id = a.id AND t_a.tenant_id = %d AND t_a.is_deleted = %d",
|
||||
mSysTenantAuth.TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r_a ON r_a.auth_id = a.id AND r_a.role_id = %d AND r_a.is_deleted = %d",
|
||||
mSysRoleAuth.TableName(), roleID, model.DeleteStatusForNot)).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where("t_a.id > ?", 0)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysAuth() *SysAuth {
|
||||
return &SysAuth{SysAuth: model.NewSysAuth()}
|
||||
}
|
11
app/api/admin/model/sys_config.go
Normal file
11
app/api/admin/model/sys_config.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysConfig struct {
|
||||
*model.SysConfig
|
||||
}
|
||||
|
||||
func NewSysConfig() *SysConfig {
|
||||
return &SysConfig{}
|
||||
}
|
11
app/api/admin/model/sys_deparement.go
Normal file
11
app/api/admin/model/sys_deparement.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysDepartment struct {
|
||||
*model.SysDepartment
|
||||
}
|
||||
|
||||
func NewSysDepartment() *SysDepartment {
|
||||
return &SysDepartment{SysDepartment: model.NewSysDepartment()}
|
||||
}
|
13
app/api/admin/model/sys_industry.go
Normal file
13
app/api/admin/model/sys_industry.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
)
|
||||
|
||||
type SysIndustry struct {
|
||||
*model.SysIndustry
|
||||
}
|
||||
|
||||
func NewSysIndustry() *SysIndustry {
|
||||
return &SysIndustry{model.NewSysIndustry()}
|
||||
}
|
13
app/api/admin/model/sys_log.go
Normal file
13
app/api/admin/model/sys_log.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type SysLog struct {
|
||||
*model2.SysLog
|
||||
}
|
||||
|
||||
func NewSysLog() *SysLog {
|
||||
return &SysLog{}
|
||||
}
|
117
app/api/admin/model/sys_menu.go
Normal file
117
app/api/admin/model/sys_menu.go
Normal file
@ -0,0 +1,117 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysMenu struct {
|
||||
*model.SysMenu
|
||||
}
|
||||
|
||||
type SysMenuScene struct {
|
||||
ID uint64 `json:"id"`
|
||||
*model.SysMenuBasic
|
||||
SceneID uint64 `json:"scene_id"` // 场景(租户,角色)
|
||||
}
|
||||
|
||||
// Recursion 递归查询子菜单
|
||||
func (m *SysMenu) Recursion(id uint64) {
|
||||
//SELECT
|
||||
//t3.id, t3.parent_id, t3.`name`, t3.kind
|
||||
//FROM
|
||||
//(SELECT
|
||||
//t1.id, t1.parent_id, t1.name, t1.kind,
|
||||
// IF(FIND_IN_SET( parent_id, @pids ) > 0, @pids := concat( @pids, ',', id ), 0 ) AS is_child
|
||||
//FROM
|
||||
//(SELECT id, parent_id, `name`, kind FROM sys_menu WHERE is_deleted = 0 ORDER BY parent_id ASC, sort DESC) AS t1,
|
||||
// (SELECT @pids := 1) AS t2
|
||||
//) AS t3
|
||||
//WHERE is_child != 0
|
||||
}
|
||||
|
||||
// SystemMenu 系统菜单
|
||||
func (m *SysMenu) SystemMenu(where ...*model.ModelWhere) ([]*model.SysMenu, error) {
|
||||
out := make([]*model.SysMenu, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Where("status = ? AND is_deleted = ?", model.SysMenuStatusForNormal, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
if err := db.Order("parent_id " + model.OrderModeToAsc).Order("sort " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TenantMenu 租户菜单
|
||||
func (m *SysMenu) TenantMenu(tenantID uint64) ([]*SysMenuScene, error) {
|
||||
mSysTenantMenu := NewSysTenantMenu()
|
||||
|
||||
out := make([]*SysMenuScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" m").
|
||||
Select("m.id, m.parent_id, m.name, m.kind, m.link, m.component, m.icon, t_m.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t_m ON m.id = t_m.menu_id AND t_m.tenant_id = %d AND t_m.is_deleted = %d",
|
||||
mSysTenantMenu.TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
Where("m.status = ? AND m.is_deleted = ?", model.SysMenuStatusForNormal, model.DeleteStatusForNot)
|
||||
|
||||
if err := db.Order("m.parent_id " + model.OrderModeToAsc).Order("m.sort " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RoleMenu 角色菜单
|
||||
func (m *SysMenu) RoleMenu(tenantID uint64, roleID uint64) ([]*SysMenuScene, error) {
|
||||
mSysTenantMenu := NewSysTenantMenu()
|
||||
|
||||
mSysRoleMenu := NewSysRoleMenu()
|
||||
|
||||
out := make([]*SysMenuScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS m").
|
||||
Select("m.id, m.parent_id, m.name, m.kind, m.link, m.component, m.icon, r_m.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t_m ON m.id = t_m.menu_id AND t_m.tenant_id = %d AND t_m.is_deleted = %d",
|
||||
mSysTenantMenu.TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r_m ON m.id = r_m.menu_id AND r_m.role_id = %d AND r_m.is_deleted = %d",
|
||||
mSysRoleMenu.TableName(), roleID, model.DeleteStatusForNot)).
|
||||
Where("m.status = ? AND m.is_deleted = ?", model.SysMenuStatusForNormal, model.DeleteStatusForNot).
|
||||
Where("t_m.id > ?", 0)
|
||||
|
||||
if err := db.Order("m.parent_id " + model.OrderModeToAsc).Order("m.sort " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserMenu 用户菜单
|
||||
func (m *SysMenu) UserMenu(tenantID, uid uint64) ([]*SysMenuScene, error) {
|
||||
mSysUserRole := NewSysUserRole()
|
||||
|
||||
mSysRoleMenu := NewSysRoleMenu()
|
||||
|
||||
out := make([]*SysMenuScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(mSysUserRole.TableName()+" AS u_r").
|
||||
Select("m.id, m.parent_id, m.name, m.kind, m.link, m.component, m.icon").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r_m ON u_r.role_id = r_m.id AND r_m.is_deletd = %d",
|
||||
mSysRoleMenu.TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON r_m.menu_id = m.id AND m.status = %d AND m.is_deleted = %d",
|
||||
m.TableName(), model.SysMenuStatusForNormal, model.DeleteStatusForNot)).
|
||||
Where("u_r.tenant_id = ? AND u_r.uid = ? AND u_r.is_deleted = ?", tenantID, uid, model.DeleteStatusForNot)
|
||||
|
||||
if err := db.Order("m.parent_id " + model.OrderModeToAsc).Order("m.sort " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysMenu() *SysMenu {
|
||||
return &SysMenu{SysMenu: model.NewSysMenu()}
|
||||
}
|
45
app/api/admin/model/sys_role.go
Normal file
45
app/api/admin/model/sys_role.go
Normal file
@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysRole struct {
|
||||
*model.SysRole
|
||||
}
|
||||
|
||||
// SysRoleBasic 基本信息
|
||||
type SysRoleBasic struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// SysRoleUserInfo 用户角色信息
|
||||
type SysRoleUserInfo struct {
|
||||
*SysRoleBasic
|
||||
UserRoleID uint64 `json:"user_role_id"`
|
||||
}
|
||||
|
||||
// UserRole 用户角色信息
|
||||
func (m *SysRole) UserRole(uid uint64) ([]*SysRoleUserInfo, error) {
|
||||
mSysUserRole := NewSysUserRole()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS r").
|
||||
Select("r.is, r.name, u_r.id AS user_role_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u_r ON r.id = u_r.role_id AND u_r.uid = %d AND u_r.is_deleted = %d",
|
||||
mSysUserRole.TableName(), uid, model.DeleteStatusForNot)).
|
||||
Where("r.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
out := make([]*SysRoleUserInfo, 0)
|
||||
|
||||
if err := db.Order("r.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysRole() *SysRole {
|
||||
return &SysRole{SysRole: model.NewSysRole()}
|
||||
}
|
47
app/api/admin/model/sys_role_auth.go
Normal file
47
app/api/admin/model/sys_role_auth.go
Normal file
@ -0,0 +1,47 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysRoleAuth struct {
|
||||
*model.SysRoleAuth
|
||||
}
|
||||
|
||||
// SysRoleAuths 权限信息
|
||||
type SysRoleAuths struct {
|
||||
ID uint64 `json:"id"`
|
||||
RoleID uint64 `json:"role_id"`
|
||||
Auth string `json:"auth"`
|
||||
}
|
||||
|
||||
// Auths 权限信息
|
||||
func (m *SysRoleAuth) Auths(where ...*model.ModelWhere) ([]*SysRoleAuths, error) {
|
||||
mSysRole := NewSysRole()
|
||||
|
||||
mSysAuth := NewSysAuth()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS r_a").
|
||||
Select("r_a.id, r_a.role_id, a.auth").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON r_a.role_id = r.id", mSysRole.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS a ON r_a.auth_id = a.id", mSysAuth.TableName())).
|
||||
Where("r_a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
out := make([]*SysRoleAuths, 0)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
if err := db.Order("r_a.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysRoleAuth() *SysRoleAuth {
|
||||
return &SysRoleAuth{SysRoleAuth: model.NewSysRoleAuth()}
|
||||
}
|
13
app/api/admin/model/sys_role_menu.go
Normal file
13
app/api/admin/model/sys_role_menu.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type SysRoleMenu struct {
|
||||
*model2.SysRoleMenu
|
||||
}
|
||||
|
||||
func NewSysRoleMenu() *SysRoleMenu {
|
||||
return &SysRoleMenu{SysRoleMenu: model2.NewSysRoleMenu()}
|
||||
}
|
84
app/api/admin/model/sys_tenant.go
Normal file
84
app/api/admin/model/sys_tenant.go
Normal file
@ -0,0 +1,84 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysTenant struct {
|
||||
*model.SysTenant
|
||||
}
|
||||
|
||||
type (
|
||||
// SysTenantBasic 租户基本信息
|
||||
SysTenantBasic struct {
|
||||
}
|
||||
// SysTenantInfo 租户信息
|
||||
SysTenantInfo struct {
|
||||
*model.SysTenant
|
||||
DeviceCount int `json:"device_count"`
|
||||
CustomerDeviceCount int `json:"customer_device_count"`
|
||||
}
|
||||
// SysTenantSubsetInfo 租户子集信息
|
||||
SysTenantSubsetInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
DeviceCount int `json:"device_count"`
|
||||
}
|
||||
// SysTenantDeviceCount 设备数量
|
||||
SysTenantDeviceCount struct {
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
Count int `json:"count"`
|
||||
CustomerCount int `json:"customer_count"`
|
||||
}
|
||||
)
|
||||
|
||||
// IsInvalid 判断是否有效
|
||||
func (m *SysTenant) IsInvalid() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Tenants 租户信息
|
||||
func (m *SysTenant) Tenants(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysTenantInfo, error) {
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()).Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysTenantInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TenantSubset 租户子集信息
|
||||
func (m *SysTenant) TenantSubset(tenantID uint64) ([]*SysTenantSubsetInfo, error) {
|
||||
|
||||
sql := fmt.Sprintf(`SELECT t3.id, t3.parent_id, t3.name, d.count AS device_count FROM
|
||||
(SELECT t1.id, t1.parent_id, t1.name, IF(FIND_IN_SET( parent_id, @pids ) > 0, @pids := concat( @pids, ',', id ), 0 ) AS is_child
|
||||
FROM (SELECT id, parent_id, name FROM %s WHERE is_deleted = 0 ORDER BY id DESC) AS t1,
|
||||
(SELECT @pids := %d) AS t2) AS t3
|
||||
LEFT JOIN (SELECT tenant_id, COUNT(id) AS count FROM %s WHERE is_deleted = 0 GROUP BY tenant_id) AS d ON t3.id = d.tenant_id
|
||||
WHERE is_child != 0`, m.TableName(), tenantID, "数据表")
|
||||
|
||||
out := make([]*SysTenantSubsetInfo, 0)
|
||||
|
||||
if err := orm.GetDB().Raw(sql).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysTenant() *SysTenant {
|
||||
return &SysTenant{SysTenant: model.NewSysTenant()}
|
||||
}
|
11
app/api/admin/model/sys_tenant_auth.go
Normal file
11
app/api/admin/model/sys_tenant_auth.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysTenantAuth struct {
|
||||
*model.SysTenantAuth
|
||||
}
|
||||
|
||||
func NewSysTenantAuth() *SysTenantAuth {
|
||||
return &SysTenantAuth{SysTenantAuth: model.NewSysTenantAuth()}
|
||||
}
|
11
app/api/admin/model/sys_tenant_menu.go
Normal file
11
app/api/admin/model/sys_tenant_menu.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysTenantMenu struct {
|
||||
*model.SysTenantMenu
|
||||
}
|
||||
|
||||
func NewSysTenantMenu() *SysTenantMenu {
|
||||
return &SysTenantMenu{SysTenantMenu: model.NewSysTenantMenu()}
|
||||
}
|
43
app/api/admin/model/sys_user.go
Normal file
43
app/api/admin/model/sys_user.go
Normal file
@ -0,0 +1,43 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SysUser 用户信息
|
||||
type SysUser struct {
|
||||
*model.SysUser
|
||||
}
|
||||
|
||||
func (m *SysUser) ValidatePassword(password string) bool {
|
||||
return utils.HashCompare([]byte(m.Password), []byte(utils.Md5String(password, m.Salt)))
|
||||
}
|
||||
|
||||
func (m *SysUser) IsAdminUser() bool {
|
||||
return m.IsAdmin == model.SysUserAdministratorForAdmin
|
||||
}
|
||||
|
||||
func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
|
||||
Where("tenant_id = ?", tenantID).
|
||||
Where("(account = ? OR mobile = ?)", account, account).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if err := db.First(m.SysUser).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func NewSysUser() *SysUser {
|
||||
return &SysUser{SysUser: model.NewSysUser()}
|
||||
}
|
45
app/api/admin/model/sys_user_login_log.go
Normal file
45
app/api/admin/model/sys_user_login_log.go
Normal file
@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysUserLoginLog struct {
|
||||
*model.SysUserLoginLog
|
||||
}
|
||||
|
||||
type SysUserLoginLogInfo struct {
|
||||
*model.SysUserLoginLog
|
||||
TenantName string `json:"tenant_name"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
// Logs 日志信息
|
||||
func (m *SysUserLoginLog) Logs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserLoginLogInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS l").
|
||||
Select("l.*, t.name AS tenant_name, u.name AS username").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON l.tenant_id = t.id", NewSysTenant().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON l.uid = u.uuid", NewSysUser().TableName())).
|
||||
Where("l.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysUserLoginLogInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("l.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysUserLoginLog() *SysUserLoginLog {
|
||||
return &SysUserLoginLog{SysUserLoginLog: model.NewSysUserLoginLog()}
|
||||
}
|
13
app/api/admin/model/sys_user_role.go
Normal file
13
app/api/admin/model/sys_user_role.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type SysUserRole struct {
|
||||
*model2.SysUserRole
|
||||
}
|
||||
|
||||
func NewSysUserRole() *SysUserRole {
|
||||
return &SysUserRole{SysUserRole: model2.NewSysUserRole()}
|
||||
}
|
83
app/api/admin/model/sys_user_tenant.go
Normal file
83
app/api/admin/model/sys_user_tenant.go
Normal file
@ -0,0 +1,83 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysUserTenant struct {
|
||||
*model.SysUserTenant
|
||||
}
|
||||
|
||||
type (
|
||||
// SysUserTenantBasic 基本信息
|
||||
SysUserTenantBasic struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
Status model.AccountStatus `json:"status"`
|
||||
}
|
||||
// SysUserTenantUser 用户信息
|
||||
SysUserTenantUser struct {
|
||||
*SysUserTenantBasic
|
||||
UID uint64 `json:"uid"`
|
||||
Email string `json:"email"`
|
||||
Identity model.SysUserTenantIdentity `json:"identity"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
// Member 成员信息
|
||||
func (m *SysUserTenant) Member(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantBasic, error) {
|
||||
mSysUser := NewSysUser()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_t").
|
||||
Select("u_t.id, u.name, u.mobile, u_t.status").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", mSysUser.TableName())).
|
||||
Where("u_t.is_deleted = ? AND u.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysUserTenantBasic, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// User 用户信息
|
||||
func (m *SysUserTenant) User(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantUser, error) {
|
||||
mSysUser := NewSysUser()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_t").
|
||||
Select("u_t.id, u_t.uid, u.name, u.mobile, u.email, u_t.identity, u_t.status, u.remark, u_t.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", mSysUser.TableName())).
|
||||
Where("u_t.is_deleted = ? AND u.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysUserTenantUser, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysUserTenant() *SysUserTenant {
|
||||
return &SysUserTenant{SysUserTenant: model.NewSysUserTenant()}
|
||||
}
|
11
app/api/admin/model/user_agent.go
Normal file
11
app/api/admin/model/user_agent.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserAgent struct {
|
||||
*model.UserAgent
|
||||
}
|
||||
|
||||
func NewUserAgent() *UserAgent {
|
||||
return &UserAgent{model.NewUserAgent()}
|
||||
}
|
11
app/api/admin/model/user_company.go
Normal file
11
app/api/admin/model/user_company.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserCompany struct {
|
||||
*model.UserCompany
|
||||
}
|
||||
|
||||
func NewUserCompany() *UserCompany {
|
||||
return &UserCompany{model.NewUserCompany()}
|
||||
}
|
11
app/api/admin/model/user_expert.go
Normal file
11
app/api/admin/model/user_expert.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserExpert struct {
|
||||
*model.UserExpert
|
||||
}
|
||||
|
||||
func NewUserExpert() *UserExpert {
|
||||
return &UserExpert{model.NewUserExpert()}
|
||||
}
|
11
app/api/admin/model/user_identity.go
Normal file
11
app/api/admin/model/user_identity.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserIdentity struct {
|
||||
*model.UserIdentity
|
||||
}
|
||||
|
||||
func NewUserIdentity() *UserIdentity {
|
||||
return &UserIdentity{model.NewUserIdentity()}
|
||||
}
|
11
app/api/admin/model/user_instance.go
Normal file
11
app/api/admin/model/user_instance.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserInstance struct {
|
||||
*model.UserInstance
|
||||
}
|
||||
|
||||
func NewUserInstance() *UserInstance {
|
||||
return &UserInstance{model.NewUserInstance()}
|
||||
}
|
11
app/api/admin/model/user_laboratory.go
Normal file
11
app/api/admin/model/user_laboratory.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserLaboratory struct {
|
||||
*model.UserLaboratory
|
||||
}
|
||||
|
||||
func NewUserLaboratory() *UserLaboratory {
|
||||
return &UserLaboratory{model.NewUserLaboratory()}
|
||||
}
|
11
app/api/admin/model/user_research.go
Normal file
11
app/api/admin/model/user_research.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserResearch struct {
|
||||
*model.UserResearch
|
||||
}
|
||||
|
||||
func NewUserResearch() *UserResearch {
|
||||
return &UserResearch{model.NewUserResearch()}
|
||||
}
|
Reference in New Issue
Block a user