Commit 2b472dcf authored by 黄智's avatar 黄智

新增组织管理模块

parent d75d0acb
......@@ -2,7 +2,7 @@ package entity
import "time"
//系统组织表
// 系统组织表
type SystemOrganization struct {
Id int64 `json:"id" xorm:"pk autoincr"` //id
OrganizationId string `json:"organization_id"` //组织id
......@@ -10,13 +10,12 @@ type SystemOrganization struct {
POrganizationId string `json:"p_organization_id"` //父级组织id
Description string `json:"description"` //组织介绍
OrganizationCode string `json:"organization_code"` //组织机构代码
Attachment string `json:"attachment"` //组织附件
Sort int64 `json:"sort"` //排序
DataType int64 `json:"data_type"` //数据类型(0目录 1组织)
CreatedTime time.Time `json:"created_time" xorm:"created"` //创建时间
UpdatedTime time.Time `json:"updated_time" xorm:"updated"` //更新时间
IsDeleted int64 `json:"is_deleted"` //是否删除0未删除 1已删除
CreatedBy string `json:"created_by"` //创建者
UpdatedBy string `json:"updated_by"` //更新者
CreatedBy int `json:"created_by"` //创建者
UpdatedBy int `json:"updated_by"` //更新者
Level int64 `json:"level"` //组织节点层级
}
package request
//添加组织入参
// 添加组织入参
type OrgInput struct {
POrganizationId string `json:"p_organization_id"` //父级组织id或者目录id
Name string `json:"name"` //组织名称or目录名称
OrganizationCode string `json:"organization_code"` //组织机构代码
Description string `json:"description"` //组织介绍
Attachment string `json:"attachment"` //组织附件
DataType int64 `json:"data_type"` //数据类型(0目录 1组织)
}
//组织排序参数
// 组织排序参数
type OrgSortInput struct {
Id int64 `json:"id" xorm:"pk autoincr"` //id
Sort int64 `json:"sort"` //排序
}
//查询组织详情参数
// 查询组织详情参数
type QueryOrgDetailInput struct {
OrganizationId string `form:"organization_id"` // 组织id
State string `form:"state" xorm:"state"` // 状态0禁用 1启用
......@@ -26,14 +25,14 @@ type QueryOrgDetailInput struct {
DataType string `form:"data_type"` // 数据类型(0目录 1组织 2平台用户组织)
}
//查询业务系统信息
// 查询业务系统信息
type GetBusinessMsgInput struct {
Limit int `form:"limit"` // 页条
Page int `form:"page"` // 页码
OrganizationId string `form:"organization_id"` // 所属组织
}
//新增用户
// 新增用户
type OrgUserInput struct {
Logo string `json:"logo"` // 头像logo
SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号
......@@ -50,7 +49,7 @@ type OrgUserInput struct {
IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
}
//编辑用户
// 编辑用户
type UpdateOrgUserInput struct {
Logo string `json:"logo"` // 头像logo
SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号
......@@ -64,12 +63,12 @@ type UpdateOrgUserInput struct {
DocumentNumber string `json:"document_number"` //证件号
}
//删除用户
// 删除用户
type DelOrgUser struct {
Ids []int `json:"ids" xorm:"pk autoincr"` //id
}
//去重校验
// 去重校验
type CheckRepetition struct {
Id int `form:"id" json:"id"`
ContactPhone string `form:"contact_phone" json:"contact_phone"`
......
package response
import (
"time"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
)
......@@ -14,11 +12,10 @@ type SystemOrganizationTree struct {
POrganizationId string `json:"p_organization_id"` //父级组织id
Description string `json:"description"` //组织介绍
OrganizationCode string `json:"organization_code"` //组织机构代码
Attachment string `json:"attachment"` //组织附件
Sort int64 `json:"sort"` //排序
DataType int64 `json:"data_type"` //数据类型(0目录 1组织)
CreatedTime time.Time `json:"created_time" xorm:"created"` //创建时间
UpdatedTime time.Time `json:"updated_time" xorm:"updated"` //更新时间
CreatedTime jsontime.Time `json:"created_time" xorm:"created"` //创建时间
UpdatedTime jsontime.Time `json:"updated_time" xorm:"updated"` //更新时间
CreatedBy string `json:"created_by"` //创建者
UpdatedBy string `json:"updated_by"` //更新者
Level int64 `json:"level"` //组织节点层级
......@@ -27,13 +24,12 @@ type SystemOrganizationTree struct {
// 组织管理员列表
type OrgAdminUser struct {
Id int32 `json:"id" xorm:"pk autoincr" ` // id
Id int `json:"id" xorm:"pk autoincr" ` // id
SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号
ContactPhone string `json:"contact_phone" xorm:"contact_phone"` // 联系人电话
SystemRole []string `json:"system_role" xorm:"-"` // 系统角色
CreatedTime jsontime.Time `json:"created_time" xorm:"created" ` // 创建时间
State int `json:"state" xorm:"state"` // 状态0禁用1启用
SystemId string `json:"system_id" xorm:"system_id"` // 系统账号id
Phone string `json:"phone" xorm:"phone"` // 手机号
}
// 账号详情
......@@ -74,15 +70,15 @@ type UpdateOrgUser struct {
// 机构详情
type OrgDetail struct {
OrganizationType string `json:"organization_type"` //机构类型
OrganizationCode string `json:"organization_code"` //组织机构代码
Name string `json:"name"` //机构名称
CreatedTime jsontime.Time `json:"created_time" xorm:"created"` //创建时间
OrgAdminNumber int64 `json:"org_admin_number"` //组织管理员数
BusinessSystemNumber int64 `json:"business_system_number"` //业务系统数
Attachment string `json:"attachment"` //组织附件
Description string `json:"description"` //组织介绍
PlatformUsersNumber int64 `json:"platform_users_number"` //平台用户数
//OrganizationType string `json:"organization_type"` //机构类型
OrganizationCode string `json:"organization_code"` //组织机构代码
Name string `json:"name"` //机构名称
CreatedTime jsontime.Time `json:"created_time" xorm:"created"` //创建时间
//OrgAdminNumber int64 `json:"org_admin_number"` //组织管理员数
//BusinessSystemNumber int64 `json:"business_system_number"` //业务系统数
//Attachment string `json:"attachment"` //组织附件
Description string `json:"description"` //组织介绍
PlatformUsersNumber int64 `json:"platform_users_number"` //平台用户数
}
type BusinessSystem struct {
......
package response
import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"time"
)
// 系统用户角色关联查询
type SystemUserRole struct {
SystemId string `json:"system_id" xorm:"system_id"` // 系统账号id
RoleName string `json:"role_name"` // 角色名称
}
type SystemRoleList struct {
Id int64 `json:"id"` // id
RoleName string `json:"role_name"` // 角色名称
RoleDesc string `json:"role_desc"` // 角色描述
State int `json:"state"` // 状态0禁用1启用
CreatedBy string `json:"created_by"` // 角色创建人
CreatedTime time.Time `json:"created_time"` // 角色创建时间
RoleType int `json:"role_type"` // 角色类型(0 普通角色 1 内置角色类型 不能删除和编辑 )
RoleId string `json:"role_id"` // 角色id(uuid)
DataPurview int `json:"data_purview"` // 数据权限:1-仅自己,2-本组织所有,3-全平台所有
UserCount int `json:"user_count"` // 用户数
CantAllot int `json:"cant_allot"` // 是否可分配用户
SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号
}
// SystemRoleDetailRes 系统角色详情
type SystemRoleDetailRes struct {
Id int64 `json:"id"` // id
RoleName string `json:"role_name"` // 角色名称
RoleDesc string `json:"role_desc"` // 角色描述
State int `json:"state"` // 状态0禁用1启用
DataPurview int `json:"data_purview"` // 数据权限:1-仅自己,2-本组织所有,3-全平台所有
RoleId string `json:"role_id"` // 角色id(uuid)
CreatedTime jsontime.Time `json:"created_time"` // 角色创建时间
UpdatedTime jsontime.Time `json:"updated_time"` // 角色更新时间
RoleType int `json:"role_type"` // 角色类型(0 普通角色 1 内置角色类型 不能删除和编辑 )
Menus []SystemMenus `json:"menus"` // 菜单
}
type SystemRoleListRes struct {
Id int64 `json:"id"` // id
RoleName string `json:"role_name"` // 角色名称
RoleDesc string `json:"role_desc"` // 角色描述
State int `json:"state"` // 状态0禁用1启用
CreatedBy string `json:"created_by"` // 角色创建人
CreatedTime jsontime.Time `json:"created_time"` // 角色创建时间
RoleType int `json:"role_type"` // 角色类型(0 普通角色 1 内置角色类型 不能删除和编辑 )
RoleId string `json:"role_id"` // 角色id(uuid)
DataPurview int `json:"data_purview"` // 数据权限:1-仅自己,2-本组织所有,3-全平台所有
UserCount int `json:"user_count"` // 用户数
CantAllot int `json:"cant_allot"` // 是否可分配用户
}
type SystemAllotUserList struct {
Id int32 `json:"id" ` // id
SystemAccount string `json:"system_account"` // 系统账号
IsAdmin int `json:"is_admin"` // 用户类型
ContactPhone string `json:"contact_phone"` // 联系人电话
OrganizationId string `json:"organization_id"` // 所属组织
OrganizationName string `json:"organization_name" xorm:"name"` // 所属组织
State int `json:"state"` // 状态0禁用1启用
CreatedTime time.Time `json:"created_time"` // 创建时间
SystemId string `json:"system_id" xorm:"system_id"` // 系统账号id
UrSystemId string `json:"ur_system_id" xorm:"ur_system_id"` // 系统账号id
IsBind int `json:"is_bind"` // 是否绑定 0否1是
}
type SystemAllotUserListRes struct {
Id int32 `json:"id" ` // id
SystemAccount string `json:"system_account"` // 系统账号
IsAdmin int `json:"is_admin"` // 用户类型
ContactPhone string `json:"contact_phone"` // 联系人电话
OrganizationId string `json:"organization_id"` // 所属组织
OrganizationName string `json:"organization_name"` // 所属组织
State int `json:"state"` // 状态0禁用1启用
CreatedTime jsontime.Time `json:"created_time"` // 创建时间
SystemId string `json:"system_id"` // 系统账号id
IsBind int `json:"is_bind"` // 是否绑定 0否1是
}
package response
import "time"
type SystemRoleMenu struct {
Id int64 `json:"id" xorm:"pk autoincr" ` // 主键自增id
RoleId string `json:"role_id" xorm:"role_id"` // 角色id(uuid)
MenuId string `json:"menu_id" xorm:"menu_id" ` // 菜单id(uuid)
CreatedTime time.Time `json:"created_time" xorm:"created" ` // 创建时间
}
type SystemMenus struct {
Id int32 `json:"id"` // id
MenuId string `json:"menu_id"` // 菜单id
}
package controller
import (
"errors"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
)
// 新增组织
func AddOrg(c *gin.Context) {
var input request.OrgInput
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
//参数检测 DataType 0 目录 1组织
if input.DataType == 0 && input.Name == "" {
SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入目录名称"), nil)
return
}
if input.DataType == 1 {
if input.Name == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("请输入机构名称")), nil)
return
}
if input.OrganizationCode == "" {
SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入组织机构代码"), nil)
return
}
}
orgService := service.Organization{User: header.GetUser(c)}
result, err := orgService.AddOrg(input)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
// 更新组织或目录
func UpdateOrg(c *gin.Context) {
var input request.OrgInput
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
//参数检测 DataType 0 目录 1组织
if input.DataType == 0 && input.Name == "" {
SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入目录名称"), nil)
return
}
if input.DataType == 1 {
if input.Name == "" {
SendJsonResponse(c, resp.FAIL.WithMsg("请输入机构名称"), nil)
return
}
if input.OrganizationCode == "" {
SendJsonResponse(c, resp.FAIL.WithMsg("请输入组织机构代码"), nil)
return
}
}
orgService := service.Organization{User: header.GetUser(c)}
if err := orgService.UpdateOrg(cast.ToInt64(c.Param("id")), input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 删除组织或者目录
func DeleteOrg(c *gin.Context) {
orgService := service.Organization{User: header.GetUser(c)}
if err := orgService.DeleteOrg(cast.ToInt64(c.Param("id"))); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 组织排序
func SortOrg(c *gin.Context) {
var input []request.OrgSortInput
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
orgService := service.Organization{User: header.GetUser(c)}
if err := orgService.SortOrg(input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 查询组织树
func GetOrgTree(c *gin.Context) {
orgService := service.Organization{}
result, err := orgService.GetOrgTree()
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
// 查询组织详情
func OrgDetail(c *gin.Context) {
var input request.QueryOrgDetailInput
if err := c.ShouldBind(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
if input.OrganizationId == "" {
SendJsonResponse(c, resp.InvalidParam.WithMsg("组织id必填"), nil)
return
}
//if input.DataType == "" {
// SendJsonResponse(c, resp.InvalidParam.WithMsg("DataType必填"), nil)
// return
//}
if input.Limit == 0 {
input.Limit = 10
}
orgService := service.Organization{}
result, err := orgService.OrgDetail(input)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
//
//// 查询业务系统信息
//func GetBusinessMsg(c *gin.Context) {
// var input request.GetBusinessMsgInput
// if err := c.ShouldBind(&input); err != nil {
// SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), nil)
// return
// }
// if input.OrganizationId == "" {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("组织id必填")), nil)
// return
// }
// if input.Limit == 0 {
// input.Limit = 10
// }
// orgService := service.Organization{}
// respult, count, err := orgService.GetBusinessMsg(input)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonPageResponse(c, resp.GET_OK, respult, count)
//}
//
//// 查询组织用户详情
//func OrgUserDetail(c *gin.Context) {
// id := cast.ToInt(c.Param("id"))
// if id <= 0 {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil)
// return
// }
// orgService := service.Organization{}
// respult, err := orgService.OrgUserDetail(id)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.GET_OK, respult)
//}
//
//// 组织添加用户时查询的角色列表
//func OrgUserRoles(c *gin.Context) {
// isadmin := c.Query("is_admin")
// if isadmin == "" {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("用户类型必填")), nil)
// return
// }
// orgService := service.Organization{}
// respult, err := orgService.OrgUserRoles(cast.ToInt(isadmin))
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.GET_OK, respult)
//}
//
//// 添加组织用户
//func OrgAddUser(c *gin.Context) {
// var input request.OrgUserInput
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// if err := vd.Validate(input); err != nil {
// SendJsonResponse(c, err, "")
// return
// }
// if input.IsAdmin != 2 && input.IsAdmin != 3 {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(errors.New("超出类型可选范围")), nil)
// return
// }
//
// orgService := service.Organization{User: util.GetContextUser(c)}
// if err := orgService.OrgAddUser(input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.ADD_OK, nil)
//}
//
//// 编辑用户
//func OrgUpdateUser(c *gin.Context) {
// id := cast.ToInt(c.Param("id"))
// if id <= 0 {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil)
// return
// }
// var input request.UpdateOrgUserInput
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// if err := vd.Validate(input); err != nil {
// SendJsonResponse(c, err, "")
// return
// }
// orgService := service.Organization{User: util.GetContextUser(c)}
// if err := orgService.OrgUpdateUser(id, input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.UPDATE_OK, nil)
//}
//
//// 删除组织用户
//func DelOrgUser(c *gin.Context) {
// var input request.DelOrgUser
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// if len(input.Ids) <= 0 {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil)
// return
// }
// orgService := service.Organization{User: util.GetContextUser(c)}
// if err := orgService.DelOrgUser(input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.DELETE_OK, nil)
//}
//
//// 去重校验
//func CheckRepetition(c *gin.Context) {
// var input request.CheckRepetition
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// orgService := service.Organization{}
// if err := orgService.CheckRepetition(input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.GET_OK, nil)
//}
package header
import (
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
func SetContext(c *gin.Context) {
bgToken, _ := c.Cookie(conf.CookieName)
if bgToken == "" {
c.String(401, "用户未登录!")
c.Abort()
return
}
svc := service.UserSvc{}
m, err := svc.GetCurUser(bgToken)
if err != nil {
c.String(500, "用户未登录!")
c.Abort()
return
}
c.Set("user_info", m)
c.Next()
}
func GetUser(c *gin.Context) entity.SystemUserInfo {
val, ok := c.Get("user_info")
if !ok {
return entity.SystemUserInfo{}
}
user, ok := val.(entity.SystemUserInfo)
if !ok {
return entity.SystemUserInfo{}
}
return user
}
package router
import (
"fmt"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"github.com/gin-gonic/gin"
)
// 初始化组织相关路由
func InitOrganizationRouter(e *gin.Engine) {
base := e.Group(fmt.Sprintf("%s/org", conf.Options.Prefix), header.SetContext)
{
base.POST("/add", controller.AddOrg) //新增组织or目录
base.PUT("/:id", controller.UpdateOrg) //更新组织或目录
base.DELETE("/:id", controller.DeleteOrg) //删除组织或者目录
base.PUT("/sort", controller.SortOrg) //组织排序
base.GET("/tree", controller.GetOrgTree) //查询组织树
base.GET("/detail", controller.OrgDetail) //查询组织详情
//base.GET("/business/msg", controller.GetBusinessMsg) //查询业务系统信息
//base.GET("/user/:id", controller.OrgUserDetail) //查询组织用户详情
//base.GET("/select/role", controller.OrgUserRoles) //注册平台用户使用的查询角色列表
//base.POST("/add/user", controller.OrgAddUser) //添加组织用户
//base.PUT("/update/user/:id", controller.OrgUpdateUser) //组织编辑用户
//base.DELETE("/del/user", controller.DelOrgUser) //删除组织用户
//base.POST("/check", controller.CheckRepetition) //去重校验
}
}
......@@ -34,4 +34,6 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitAutomatedMaintenRouter(r)
// 初始化登录路由
InitSystemLoginRouter(r)
// 初始化组织相关路由
InitOrganizationRouter(r)
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment