feat:完善项目信息
This commit is contained in:
@ -12,36 +12,6 @@ import (
|
||||
|
||||
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"`
|
||||
@ -50,7 +20,7 @@ func (a *Account) Login(c *gin.Context) {
|
||||
Captcha string `json:"captcha" form:"captcha"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewAccount()(nil, api.GetTenantID()(c).(uint64)).Login(form.Mode, &controller.AccountLoginParams{
|
||||
@ -59,25 +29,6 @@ func (a *Account) Login(c *gin.Context) {
|
||||
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)
|
||||
|
@ -2,57 +2,15 @@ package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/auth"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"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)
|
||||
func (*Auth) Index(c *gin.Context) {
|
||||
data, err := auth.NewInstance()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -11,7 +11,7 @@ type Config struct{}
|
||||
func (a *Config) Index(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
pageForm
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
|
@ -2,7 +2,8 @@ package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -12,12 +13,12 @@ type Log struct{}
|
||||
func (a *Log) Login(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
pageForm
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewLog()(getSession()(c).(*service.Session)).Login(form.Name, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := controller.NewLog()(api.GetSession()(c).(*session.Admin)).Login(form.Name, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -20,8 +21,8 @@ type (
|
||||
)
|
||||
|
||||
// handle 审核处理
|
||||
func (a *manageExamineForm) handle(session *service.Session, local string) error {
|
||||
return manage.NewExamine()(session, local).Launch(a.Convert(), a.Identity, a.Status)
|
||||
func (a *manageExamineForm) handle(session *session.Admin) error {
|
||||
return manage.NewExamine()(session).Launch(a.Convert(), a.Identity, a.Status)
|
||||
}
|
||||
|
||||
func (*Manage) Company(c *gin.Context) {
|
||||
@ -36,7 +37,7 @@ func (*Manage) CompanyExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForCompany
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForExpert
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -79,7 +80,7 @@ func (*Manage) LaboratoryExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForLaboratory
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -95,7 +96,7 @@ func (*Manage) ResearchExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForResearch
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
@ -111,6 +112,6 @@ func (*Manage) AgentExamine(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForAgent
|
||||
err := form.handle(api.GetSession()(c).(*service.Session), api.GetTenantID()(c).(string))
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin))
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func (a *Menu) Status(c *gin.Context) {
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(api.GetSession()(c).(*session.Admin)).Status(form.Convert(), form.Status)
|
||||
|
@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/role"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -85,50 +84,60 @@ func (*Role) Delete(c *gin.Context) {
|
||||
|
||||
func (*Role) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewMenu()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := role.NewMenu()(api.GetSession()(c).(*session.Admin)).Index((&api.IDStringForm{ID: form.RoleID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*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"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
MenuIDs []string `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewMenu()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
menuIDs := make([]uint64, 0)
|
||||
|
||||
for _, v := range form.MenuIDs {
|
||||
menuIDs = append(menuIDs, (&api.IDStringForm{ID: v}).Convert())
|
||||
}
|
||||
err := role.NewMenu()(api.GetSession()(c).(*session.Admin)).Bind((&api.IDStringForm{ID: form.RoleID}).Convert(), menuIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Role) Auth(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := role.NewAuth()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
data, err := role.NewAuth()(api.GetSession()(c).(*session.Admin)).Index((&api.IDStringForm{ID: form.RoleID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*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"`
|
||||
RoleID string `json:"role_id" form:"role_id" binding:"required"`
|
||||
AuthIDs []string `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := role.NewAuth()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
authIDs := make([]uint64, 0)
|
||||
|
||||
for _, v := range form.AuthIDs {
|
||||
authIDs = append(authIDs, (&api.IDStringForm{ID: v}).Convert())
|
||||
}
|
||||
err := role.NewAuth()(api.GetSession()(c).(*session.Admin)).Bind((&api.IDStringForm{ID: form.RoleID}).Convert(), authIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
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"`
|
||||
}
|
@ -4,7 +4,6 @@ import (
|
||||
"SciencesServer/app/api/admin/controller/tenant"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -20,7 +19,7 @@ type (
|
||||
Contact string `json:"contact" form:"contact" binding:"required"` // 联系人
|
||||
ContactMobile string `json:"contact_mobile" form:"contact_mobile" binding:"required"` // 联系方式
|
||||
Province string `json:"province" form:"province" binding:"required"` // 省
|
||||
City string `json:"city" form:"city" binding:"city"` // 市区
|
||||
City string `json:"city" form:"city" binding:"required"` // 市区
|
||||
Remark string `json:"remark" form:"remark"` // 备注
|
||||
}
|
||||
)
|
||||
@ -87,8 +86,7 @@ func (a *Tenant) Member(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).
|
||||
Instance((&api.IDStringForm{ID: form.TenantID}).Convert())
|
||||
data, err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Instance((&api.IDStringForm{ID: form.TenantID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -115,7 +113,7 @@ func (a *Tenant) Menu(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant.NewMenu()(getSession()(c).(*service.Session)).List(form.TenantID)
|
||||
data, err := tenant.NewMenu()(api.GetSession()(c).(*session.Admin)).List(form.TenantID)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -128,7 +126,7 @@ func (a *Tenant) MenuBind(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewMenu()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
|
||||
err := tenant.NewMenu()(api.GetSession()(c).(*session.Admin)).Bind(form.TenantID, form.MenuIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
@ -141,6 +139,6 @@ func (a *Tenant) AuthBind(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewAuth()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
|
||||
err := tenant.NewAuth()(api.GetSession()(c).(*session.Admin)).Bind(form.TenantID, form.AuthIDs)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package api
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller/user"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -39,27 +38,37 @@ func (this *userForm) RoleInfo() []uint64 {
|
||||
|
||||
func (*User) Info(c *gin.Context) {
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Info()
|
||||
APIResponse(err, data)(c)
|
||||
api.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"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
Status int `json:"status" form:"status"`
|
||||
DepartmentIDs []string `json:"department_ids" form:"department_ids"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
|
||||
departmentIDs := make([]uint64, 0)
|
||||
|
||||
obj := new(api.IDStringForm)
|
||||
|
||||
for _, v := range form.DepartmentIDs {
|
||||
obj.ID = v
|
||||
departmentIDs = append(departmentIDs, obj.Convert())
|
||||
}
|
||||
data, err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Index(form.Name, form.Mobile, departmentIDs,
|
||||
form.Status, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Menu(c *gin.Context) {
|
||||
data, err := user.NewMenu()(api.GetSession()(c).(*session.Admin)).Index()
|
||||
APIResponse(err, data)(c)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *User) Add(c *gin.Context) {
|
||||
@ -80,18 +89,18 @@ func (a *User) Add(c *gin.Context) {
|
||||
|
||||
func (a *User) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
userForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Edit(&user.InstanceForm{
|
||||
ID: form.ID, Account: form.Account, Name: form.Name, Mobile: form.Mobile,
|
||||
ID: form.Convert(), Account: form.Account, Name: form.Name, Mobile: form.Mobile,
|
||||
Remark: form.Remark, Gender: form.Gender, DepartmentID: form.departmentInfo(), RoleIDs: form.RoleInfo(),
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Password(c *gin.Context) {
|
||||
@ -114,46 +123,21 @@ func (a *User) PasswordEdit(c *gin.Context) {
|
||||
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)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewPerson()(getSession()(c).(*service.Session)).EditPassword(form.OldPwd, form.Password, form.RepeatPwd)
|
||||
APIResponse(err)(c)
|
||||
err := user.NewPerson()(api.GetSession()(c).(*session.Admin)).PasswordEdit(form.OldPwd, form.Password, form.RepeatPwd)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *User) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).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 := user.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 := user.NewRole()(getSession()(c).(*service.Session)).Bind(form.Convert(), form.RoleIDs)
|
||||
APIResponse(err)(c)
|
||||
err := user.NewInstance()(api.GetSession()(c).(*session.Admin)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
type Instance struct{ *session.Admin }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
type InstanceHandle func(session *session.Admin) *Instance
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List() ([]*Tree, error) {
|
||||
// Index 列表信息
|
||||
func (c *Instance) Index() ([]*Tree, error) {
|
||||
mSysAuth := model.NewSysAuth()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
@ -28,7 +27,7 @@ func (c *Instance) List() ([]*Tree, error) {
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
return func(session *session.Admin) *Instance {
|
||||
return &Instance{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,11 @@
|
||||
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 生成秘钥
|
||||
|
@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
@ -16,7 +17,7 @@ type Config struct{}
|
||||
|
||||
type ConfigHandle func() *Config
|
||||
|
||||
func (c *Config) Config(kind, page, pageSize int) (*ReturnPages, error) {
|
||||
func (c *Config) Config(kind, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysConfig := model.NewSysConfig()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
@ -32,7 +33,7 @@ func (c *Config) Config(kind, page, pageSize int) (*ReturnPages, error) {
|
||||
if err := model2.Pages(mSysConfig.SysConfig, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ReturnPages{Data: out, Count: count}, nil
|
||||
return &controller.ReturnPages{Data: out, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Config) Add(kind int, name, key string, value interface{}) error {
|
||||
|
@ -56,7 +56,9 @@ func (c *Instance) Index() ([]*InstanceTreeInfo, error) {
|
||||
|
||||
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 {
|
||||
Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)},
|
||||
&model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
@ -67,9 +69,11 @@ func (c *Instance) Select() ([]*InstanceTreeInfo, error) {
|
||||
|
||||
out := make([]*model2.SysDepartment, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysDepartment.SysDepartment, &out, []string{"id", "name"}, &model2.ModelWhereOrder{
|
||||
if err := model2.ScanFields(mSysDepartment.SysDepartment, &out, []string{"id", "parent_id", "name"}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)}); err != nil {
|
||||
Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("status", 1),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
|
@ -2,14 +2,15 @@ package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/tools/ip"
|
||||
)
|
||||
|
||||
type Log struct{ *Platform }
|
||||
type Log struct{ *session.Admin }
|
||||
|
||||
type LogHandle func(session *service.Session) *Log
|
||||
type LogHandle func(session *session.Admin) *Log
|
||||
|
||||
type (
|
||||
// LogForLogin 登录日志
|
||||
@ -20,7 +21,7 @@ type (
|
||||
)
|
||||
|
||||
// Login 登录日志
|
||||
func (c *Log) Login(name string, page, pageSize int) (*ReturnPages, error) {
|
||||
func (c *Log) Login(name string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysUserLoginLogs := model.NewSysUserLoginLog()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
@ -47,11 +48,11 @@ func (c *Log) Login(name string, page, pageSize int) (*ReturnPages, error) {
|
||||
SysUserLoginLogInfo: v, IPAddress: string(ipAddress),
|
||||
})
|
||||
}
|
||||
return &ReturnPages{Data: list, Count: count}, nil
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func NewLog() LogHandle {
|
||||
return func(session *service.Session) *Log {
|
||||
return &Log{Platform: &Platform{Session: session}}
|
||||
return func(session *session.Admin) *Log {
|
||||
return &Log{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
@ -13,11 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type Examine struct {
|
||||
*service.Session
|
||||
local string
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type ExamineHandle func(session *service.Session, local string) *Examine
|
||||
type ExamineHandle func(session *session.Admin) *Examine
|
||||
|
||||
type ExamineManageInfo struct {
|
||||
IModel model2.IModel
|
||||
@ -219,10 +218,9 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
}
|
||||
|
||||
func NewExamine() ExamineHandle {
|
||||
return func(session *service.Session, local string) *Examine {
|
||||
return func(session *session.Admin) *Examine {
|
||||
return &Examine{
|
||||
Session: session,
|
||||
local: local,
|
||||
Admin: session,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"gorm.io/gorm"
|
||||
|
@ -1,23 +1,23 @@
|
||||
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/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Auth struct{ *controller.Platform }
|
||||
type Auth struct{ *session.Admin }
|
||||
|
||||
type AuthHandle func(session *service.Session) *Auth
|
||||
type AuthHandle func(session *session.Admin) *Auth
|
||||
|
||||
// List 角色权限列表
|
||||
func (c *Auth) List(roleID uint64) ([]*auth2.TreeChecked, error) {
|
||||
// Index 角色权限列表
|
||||
func (c *Auth) Index(roleID uint64) ([]*auth2.TreeChecked, error) {
|
||||
mSysAuth := model3.NewSysAuth()
|
||||
|
||||
out, err := mSysAuth.RoleAuth(c.TenantID, roleID)
|
||||
@ -81,7 +81,7 @@ func (c *Auth) Bind(roleID uint64, authIDs []uint64) error {
|
||||
}
|
||||
|
||||
func NewAuth() AuthHandle {
|
||||
return func(session *service.Session) *Auth {
|
||||
return &Auth{Platform: &controller.Platform{Session: session}}
|
||||
return func(session *session.Admin) *Auth {
|
||||
return &Auth{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
|
@ -1,24 +1,23 @@
|
||||
package role
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Menu struct{ *controller.Platform }
|
||||
type Menu struct{ *session.Admin }
|
||||
|
||||
type MenuHandle func(session *service.Session) *Menu
|
||||
type MenuHandle func(session *session.Admin) *Menu
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List(roleID uint64) ([]*menu2.TreeChecked, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
// Index 菜单列表
|
||||
func (c *Menu) Index(roleID uint64) ([]*menu2.TreeChecked, error) {
|
||||
mSysMenu := model.NewSysMenu()
|
||||
return menu2.MenuForRoleChecked(mSysMenu, c.TenantID, roleID)
|
||||
}
|
||||
|
||||
@ -27,7 +26,7 @@ func (c *Menu) Bind(roleID uint64, menuIDs []uint64) error {
|
||||
if len(menuIDs) > 0 {
|
||||
var count int64
|
||||
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
mSysMenu := model.NewSysMenu()
|
||||
|
||||
if err := model2.Count(mSysMenu.SysMenu, &count, model2.NewWhereIn("id", menuIDs),
|
||||
model2.NewWhere("auth", model2.SysMenuAuthForSystem)); err != nil {
|
||||
@ -36,7 +35,7 @@ func (c *Menu) Bind(roleID uint64, menuIDs []uint64) error {
|
||||
return errors.New("不可设置超管菜单")
|
||||
}
|
||||
}
|
||||
mSysRoleMenu := model3.NewSysRoleMenu()
|
||||
mSysRoleMenu := model.NewSysRoleMenu()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
err := model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{model2.NewWhere("role_id", roleID)}, tx)
|
||||
@ -68,7 +67,7 @@ func (c *Menu) Bind(roleID uint64, menuIDs []uint64) error {
|
||||
}
|
||||
|
||||
func NewMenu() MenuHandle {
|
||||
return func(session *service.Session) *Menu {
|
||||
return &Menu{Platform: &controller.Platform{Session: session}}
|
||||
return func(session *session.Admin) *Menu {
|
||||
return &Menu{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
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,10 +1,10 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/logger"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
@ -13,9 +13,9 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Auth struct{ *controller.Platform }
|
||||
type Auth struct{ *session.Admin }
|
||||
|
||||
type AuthHandle func(session *service.Session) *Auth
|
||||
type AuthHandle func(session *session.Admin) *Auth
|
||||
|
||||
// delete 删除所有权限
|
||||
func (c *Auth) delete(tenantID uint64, tenantKey string, tx *gorm.DB) error {
|
||||
@ -101,7 +101,7 @@ func (c *Auth) Bind(tenantID uint64, authIDs []uint64) error {
|
||||
}
|
||||
|
||||
func NewAuth() AuthHandle {
|
||||
return func(session *service.Session) *Auth {
|
||||
return &Auth{Platform: &controller.Platform{Session: session}}
|
||||
return func(session *session.Admin) *Auth {
|
||||
return &Auth{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -67,9 +67,11 @@ func (c *Member) Form(tenantID uint64, params *MemberParams) error {
|
||||
}
|
||||
mSysUser.TenantID = tenantID
|
||||
mSysUser.Account = params.Mobile
|
||||
mSysUser.Name = params.Mobile
|
||||
mSysUser.Mobile = params.Mobile
|
||||
mSysUser.Password = params.Password
|
||||
mSysUser.IsAdmin = model2.SysUserAdministratorForAdmin
|
||||
mSysUser.Remark = "子平台管理员"
|
||||
|
||||
return model2.Create(mSysUser.SysUser)
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/api/admin/controller/menu"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model3 "SciencesServer/app/api/enterprise/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Menu struct{ *controller.Platform }
|
||||
type Menu struct{ *session.Admin }
|
||||
|
||||
type MenuHandle func(session *service.Session) *Menu
|
||||
type MenuHandle func(session *session.Admin) *Menu
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List(tenantID uint64) ([]*menu2.TreeChecked, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
return menu2.MenuForTenantChecked(mSysMenu, tenantID)
|
||||
func (c *Menu) List(tenantID uint64) ([]*menu.TreeChecked, error) {
|
||||
mSysMenu := model.NewSysMenu()
|
||||
return menu.MenuForTenantChecked(mSysMenu, tenantID)
|
||||
}
|
||||
|
||||
// Bind 绑定菜单
|
||||
@ -36,7 +36,7 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
return errors.New("不可设置超管菜单")
|
||||
}
|
||||
}
|
||||
mSysTenantMenu := model3.NewSysTenantMenu()
|
||||
mSysTenantMenu := model.NewSysTenantMenu()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// TODO:先全部删除,后期考虑局部删除
|
||||
@ -46,7 +46,7 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
return err
|
||||
}
|
||||
// 租户角色的菜单
|
||||
mSysRoleMenu := model3.NewSysRoleMenu()
|
||||
mSysRoleMenu := model.NewSysRoleMenu()
|
||||
|
||||
if len(menuIDs) <= 0 {
|
||||
if err = model2.DeleteWhere(mSysRoleMenu.SysRoleMenu, []*model2.ModelWhere{model2.NewWhere("tenant_id", tenantID)}, tx); err != nil {
|
||||
@ -82,7 +82,7 @@ func (c *Menu) Bind(tenantID uint64, menuIDs []uint64) error {
|
||||
}
|
||||
|
||||
func NewMenu() MenuHandle {
|
||||
return func(session *service.Session) *Menu {
|
||||
return &Menu{Platform: &controller.Platform{Session: session}}
|
||||
return func(session *session.Admin) *Menu {
|
||||
return &Menu{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
@ -138,7 +138,7 @@ func (c *Instance) Info() (*InstanceUserInfo, error) {
|
||||
}
|
||||
|
||||
// Index 列表信息
|
||||
func (c *Instance) Index(name, mobile string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
func (c *Instance) Index(name, mobile string, departmentIDs []uint64, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u.tenant_id", c.TenantID)}
|
||||
|
||||
if name != "" {
|
||||
@ -147,6 +147,9 @@ func (c *Instance) Index(name, mobile string, status, page, pageSize int) (*cont
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("u.mobile", mobile))
|
||||
}
|
||||
if len(departmentIDs) > 0 {
|
||||
where = append(where, model2.NewWhereIn("d.id", departmentIDs))
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("u.status", status))
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ package user
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Person struct{ *service.Session }
|
||||
type Person struct{ *session.Admin }
|
||||
|
||||
type PersonHandle func(session *service.Session) *Person
|
||||
type PersonHandle func(session *session.Admin) *Person
|
||||
|
||||
// EditPassword 修改密码
|
||||
func (c *Person) EditPassword(oldPassword, password, repeatPwd string) error {
|
||||
@ -41,7 +41,7 @@ func (c *Person) EditPassword(oldPassword, password, repeatPwd string) error {
|
||||
}
|
||||
|
||||
func NewPerson() PersonHandle {
|
||||
return func(session *service.Session) *Person {
|
||||
return &Person{Session: session}
|
||||
return func(session *session.Admin) *Person {
|
||||
return &Person{Admin: session}
|
||||
}
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
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}}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package model
|
||||
|
||||
// SysDepartment 部门数据模型
|
||||
type SysDepartment struct {
|
||||
Model
|
||||
ModelTenant
|
||||
@ -7,7 +8,7 @@ type SysDepartment struct {
|
||||
Name string `gorm:"column:name;type:varchar(20);default:'';comment:部门名称" json:"name"`
|
||||
Contact string `gorm:"column:contact_name;type:varchar(20);default:'';comment:联系人" json:"contact_name"`
|
||||
ContactMobile string `gorm:"column:contact_mobile;type:varchar(15);default:'';comment:联系方式" json:"contact_mobile"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:0;comment:状态(1:正常,2:禁用)" json:"status"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常,2:禁用)" json:"status"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:'';comment:备注信息" json:"remark"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
|
@ -169,8 +169,6 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
user.POST("/delete", _api.Delete)
|
||||
user.POST("/password", _api.Password)
|
||||
user.POST("/password/edit", _api.PasswordEdit)
|
||||
user.POST("/role", _api.Role)
|
||||
user.POST("/role/bind", _api.RoleBind)
|
||||
}
|
||||
// Tenant 租户管理
|
||||
tenant := v1.Group("/tenant")
|
||||
@ -205,13 +203,13 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
auth := v1.Group("/auth")
|
||||
{
|
||||
_api := new(api1.Auth)
|
||||
auth.POST("/list", _api.List)
|
||||
auth.GET("", _api.Index)
|
||||
}
|
||||
// Department 部门管理
|
||||
department := v1.Group("/department")
|
||||
{
|
||||
_api := new(api1.Department)
|
||||
department.GET("/", _api.Index)
|
||||
department.GET("", _api.Index)
|
||||
department.GET("/select", _api.Select)
|
||||
department.POST("/add", _api.Add)
|
||||
department.POST("/edit", _api.Edit)
|
||||
@ -221,7 +219,7 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
role := v1.Group("/role")
|
||||
{
|
||||
_api := new(api1.Role)
|
||||
role.POST("/", _api.Index)
|
||||
role.POST("", _api.Index)
|
||||
role.POST("/select", _api.Select)
|
||||
role.POST("/add", _api.Add)
|
||||
role.POST("/edit", _api.Edit)
|
||||
|
Reference in New Issue
Block a user