diff --git a/src/bean/entity/system_organization.go b/src/bean/entity/system_organization.go index 110ea1fa07cb8458c3c92a9cdc3fe9b2c3ae309a..2e419ef68b14d00fe7297326c6a5fd83d4fe873b 100644 --- a/src/bean/entity/system_organization.go +++ b/src/bean/entity/system_organization.go @@ -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"` //组织节点层级 } diff --git a/src/bean/vo/request/system_organization.go b/src/bean/vo/request/system_organization.go index 336ff26f7a04a31b0a0d214db36b5255b540c119..3ccb0926862ced51b565285d9105c2cfecad6cce 100644 --- a/src/bean/vo/request/system_organization.go +++ b/src/bean/vo/request/system_organization.go @@ -1,22 +1,21 @@ 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"` diff --git a/src/bean/vo/response/system_organization.go b/src/bean/vo/response/system_organization.go index f62271d31f961458b6933453d6906022452722d5..54bfeb8ecd2c168fd6a57b1b2a0d41b94e015a73 100644 --- a/src/bean/vo/response/system_organization.go +++ b/src/bean/vo/response/system_organization.go @@ -1,8 +1,6 @@ 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 { diff --git a/src/bean/vo/response/system_role.go b/src/bean/vo/response/system_role.go new file mode 100644 index 0000000000000000000000000000000000000000..3495d7169b7bc2f62bb69c31b899b8ea38790275 --- /dev/null +++ b/src/bean/vo/response/system_role.go @@ -0,0 +1,80 @@ +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是 +} diff --git a/src/bean/vo/response/system_role_menu.go b/src/bean/vo/response/system_role_menu.go new file mode 100644 index 0000000000000000000000000000000000000000..fe5f2a3a44b372abeee2cf013d455af604405781 --- /dev/null +++ b/src/bean/vo/response/system_role_menu.go @@ -0,0 +1,15 @@ +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 +} diff --git a/src/controller/organization.go b/src/controller/organization.go new file mode 100644 index 0000000000000000000000000000000000000000..14014495f8970a4609424f1bf0b4cc712a6e5a2a --- /dev/null +++ b/src/controller/organization.go @@ -0,0 +1,274 @@ +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) +//} diff --git a/src/router/middleware/header/user.go b/src/router/middleware/header/user.go new file mode 100644 index 0000000000000000000000000000000000000000..3b22afde250f0bf5fabe060b78cc1bd5e3ddf3ff --- /dev/null +++ b/src/router/middleware/header/user.go @@ -0,0 +1,42 @@ +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 +} diff --git a/src/router/organizationrouter.go b/src/router/organizationrouter.go new file mode 100644 index 0000000000000000000000000000000000000000..e86579e4d6f2b0251aa39d0683da4ccdf7c1ac35 --- /dev/null +++ b/src/router/organizationrouter.go @@ -0,0 +1,30 @@ +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) //去重校验 + } +} diff --git a/src/router/router.go b/src/router/router.go index 2cd6b1d7bb32c61df8bac3b1b900960a8229bac2..396dd72511508209d36aa09253bd793da16d517c 100644 --- a/src/router/router.go +++ b/src/router/router.go @@ -34,4 +34,6 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) { InitAutomatedMaintenRouter(r) // 初始化登录路由 InitSystemLoginRouter(r) + // 初始化组织相关路由 + InitOrganizationRouter(r) } diff --git a/src/service/organization.go b/src/service/organization.go new file mode 100644 index 0000000000000000000000000000000000000000..c865141ed6ed48f501dcf00b1583e88a76084762 --- /dev/null +++ b/src/service/organization.go @@ -0,0 +1,603 @@ +package service + +import ( + "errors" + "fmt" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" + "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" + "xorm.io/xorm" + + "go.uber.org/zap" +) + +type Organization struct { + User entity.SystemUserInfo +} + +// 新增目录或组织 +func (o *Organization) AddOrg(input request.OrgInput) (interface{}, error) { + db, err := client.GetDbClient() + if err != nil { + return nil, resp.DbConnectError.WithError(err) + } + + //数据校验 + if input.DataType == 1 { + has, err := db.Table("system_organization").Select("id").Where("organization_code = ? and is_deleted = 0", input.OrganizationCode).Exist(&entity.SystemOrganization{}) + if err != nil { + conf.Logger.Error("组织机构代码获取组织信息失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + if has { + return nil, resp.DbInsertError.WithError(errors.New("组织机构代码已存在")) + } + } + + orgModel := entity.SystemOrganization{ + Id: 0, + OrganizationId: util.GetUUID(), + Name: input.Name, + POrganizationId: input.POrganizationId, + Description: input.Description, + OrganizationCode: input.OrganizationCode, + + DataType: input.DataType, + CreatedBy: o.User.Id, + } + var samelevelOrg, parentOrg entity.SystemOrganization + if orgModel.POrganizationId != "" { + has, err := db.Table("system_organization").Where("p_organization_id = ? and is_deleted = 0", orgModel.POrganizationId).Limit(1, 0).OrderBy("sort desc").Get(&samelevelOrg) + if err != nil { + conf.Logger.Error("获取同级组织信息失败", zap.Error(err)) + return nil, resp.DbConnectError.WithError(err) + } + + if !has { + _, err := db.Table("system_organization").Where("organization_id = ? and is_deleted = 0", orgModel.POrganizationId).Limit(1, 0).OrderBy("sort desc").Get(&parentOrg) + if err != nil { + conf.Logger.Error("获取父级组织信息失败", zap.Error(err)) + return nil, resp.DbConnectError.WithError(err) + } + orgModel.Level = parentOrg.Level + 1 + orgModel.Sort = 1 + } else { + orgModel.Level = samelevelOrg.Level + orgModel.Sort = samelevelOrg.Sort + 1 + } + } else { + //查询跟目录sort + has, err := db.Table("system_organization").Where("is_deleted = 0 and level = 1").Limit(1, 0).OrderBy("sort desc").Get(&parentOrg) + if err != nil { + conf.Logger.Error("获取同级组织信息失败", zap.Error(err)) + return nil, resp.DbConnectError.WithError(err) + } + if has { + orgModel.Sort = parentOrg.Sort + 1 + } else { + orgModel.Sort = 1 + } + orgModel.Level = 1 + } + if _, err := db.Table("system_organization").Omit("id").Insert(&orgModel); err != nil { + conf.Logger.Error("插入 system_organization", zap.String("error", err.Error())) + return nil, resp.DbInsertError.WithError(err) + } + result := map[string]interface{}{"id": orgModel.Id, "organization_id": orgModel.OrganizationId} + return result, nil +} + +// 更新组织或目录 +func (o *Organization) UpdateOrg(id int64, input request.OrgInput) error { + db, err := client.GetDbClient() + if err != nil { + return resp.DbConnectError.WithError(err) + } + + var org entity.SystemOrganization + has, err := db.Table("system_organization").ID(id).Where("is_deleted = 0").Get(&org) + if err != nil { + conf.Logger.Error("获取组织信息失败", zap.Error(err)) + return resp.DbSelectError.WithError(err) + } + if !has { + if input.DataType == 0 { + return resp.FAIL.WithMsg("该目录不存在") + } + if input.DataType == 1 { + return resp.FAIL.WithMsg("该组织不存在") + } + } + + //数据校验 + if input.DataType == 1 && org.OrganizationCode != input.OrganizationCode { + has, err := db.Table("system_organization").Select("id").Where("organization_code = ? and is_deleted = 0", input.OrganizationCode).Exist(&entity.SystemOrganization{}) + if err != nil { + conf.Logger.Error("组织机构代码获取组织信息失败", zap.Error(err)) + return resp.DbSelectError.WithError(err) + } + if has { + return resp.DbUpdateError.WithError(errors.New("组织机构代码已存在")) + } + } + + if _, err := db.Table("system_organization").Cols("name, description, organization_code, updated_time, updated_by"). + Where("id = ?", id).Update(&entity.SystemOrganization{ + Name: input.Name, + Description: input.Description, + OrganizationCode: input.OrganizationCode, + UpdatedBy: o.User.Id, + }); err != nil { + conf.Logger.Error("更新组织信息失败", zap.Error(err)) + return resp.DbUpdateError.WithError(err) + } + return nil +} + +// 删除组织或者目录 +func (o *Organization) DeleteOrg(id int64) error { + db, err := client.GetDbClient() + if err != nil { + return resp.DbConnectError.WithError(err) + } + _, err = db.Transaction(func(session *xorm.Session) (interface{}, error) { + var org entity.SystemOrganization + basehas, err := session.Table("system_organization").ID(id).Where("is_deleted = 0").Get(&org) + if err != nil { + conf.Logger.Error("查询基础组织信息失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + + //目录 目录没有下级可删除 + if org.DataType == 0 { + if !basehas { + return nil, resp.FAIL.WithMsg("该目录不存在") + } + + //验证目录是否有下级 + has, err := session.Table("system_organization").Select("id").Where("is_deleted = 0 and p_organization_id = ?", org.OrganizationId).Exist(&entity.SystemOrganization{}) + if err != nil { + conf.Logger.Error("验证目录是否有下级查询基础组织信息失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + if has { + return nil, resp.FAIL.WithMsg("该目录下有数据,不可删除!") + } + } + + //组织 组织没有组织管理员且没有绑定业务系统 + if org.DataType == 1 { + if !basehas { + return nil, resp.FAIL.WithMsg("该组织不存在") + } + + //验证组织下是否有组织管理员且是否绑定业务系统 + has, err := session.Table("system_user").Select("id").Where("is_deleted = 0 and organization_id = ?", org.OrganizationId).Exist(&entity.SystemUser{}) + if err != nil { + conf.Logger.Error("验证组织下是否有组织管理员查询基础组织信息失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + if has { + return nil, resp.FAIL.WithMsg("该组织下有业务数据,不可删除!") + } + } + + //删除 + _, err = session.Table("system_organization").Cols("is_deleted, updated_time, updated_by").ID(id).Update(&entity.SystemOrganization{IsDeleted: 1, UpdatedBy: o.User.Id}) + return nil, err + }) + return err +} + +// 组织排序 +func (o *Organization) SortOrg(input []request.OrgSortInput) error { + db, err := client.GetDbClient() + if err != nil { + return resp.DbConnectError.WithError(err) + } + _, err = db.Transaction(func(s *xorm.Session) (interface{}, error) { + for _, v := range input { + _, err := s.Table("system_organization").Cols("sort, updated_time, updated_by").Where("id = ? and is_deleted = 0", v.Id).Update(&entity.SystemOrganization{Sort: v.Sort, UpdatedBy: o.User.Id}) + if err != nil { + conf.Logger.Error("排序失败", zap.Error(err)) + return nil, resp.DbUpdateError.WithError(err) + } + } + return nil, nil + }) + return err +} + +// 查询组织树 +func (o *Organization) GetOrgTree() (interface{}, error) { + db, err := client.GetDbClient() + if err != nil { + return nil, resp.DbConnectError.WithError(err) + } + var orgs []response.SystemOrganizationTree + if err := db.Table("system_organization").Where("is_deleted = 0").OrderBy("level").OrderBy("sort").Find(&orgs); err != nil { + conf.Logger.Error("查询组织树失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + + var result []response.SystemOrganizationTree + // 组装树形 + for i, v := range orgs { + if v.Level == 1 { + changeTree(&orgs[i], orgs) + result = append(result, orgs[i]) + } + } + return result, nil +} + +func changeTree(parent *response.SystemOrganizationTree, all []response.SystemOrganizationTree) { + for i, v := range all { + if v.POrganizationId == parent.OrganizationId { + changeTree(&all[i], all) + parent.Child = append(parent.Child, all[i]) + } + } +} + +// 查询组织详情 +func (o *Organization) OrgDetail(input request.QueryOrgDetailInput) (interface{}, error) { + db, err := client.GetDbClient() + if err != nil { + return nil, resp.DbConnectError.WithError(err) + } + + //查询用户 区分组织管理员和平台用户 + var orgAdminUsers []response.OrgAdminUser + querySystemUser := db.Table("system_user").Alias("su").Select("su.id, su.system_account, su.created_time, su.state, su.phone"). + Where("organization_id = ? and su.is_deleted = 0", input.OrganizationId) + + //DataType 2平台用户组织 + //if input.DataType == "2" { + // querySystemUser.Where("su.is_admin = 3") + //} else { + // //组织管理员用户 + // querySystemUser.Where("su.is_admin = 2") + //} + + if input.KeyWord != "" { + querySystemUser.Where("su.system_account like ? or su.phone like ?", fmt.Sprintf("%%%s%%", input.KeyWord), fmt.Sprintf("%%%s%%", input.KeyWord)) + } + if input.State != "" { + querySystemUser.Where("su.state = ?", input.State) + } + count, err := querySystemUser.Limit(input.Limit, (input.Page-1)*input.Limit).Asc("su.created_time").FindAndCount(&orgAdminUsers) + if err != nil { + conf.Logger.Error("查询用户失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + + //查询用户角色 + var ids []int + for _, v := range orgAdminUsers { + ids = append(ids, v.Id) + } + //var systemUserRoles []response.SystemUserRole + //if err := db.Table("system_user_role").Alias("sur").Select("sur.system_id, sr.role_name"). + // Join("left", "system_role sr", "sr.role_id = sur.role_id").In("sur.system_id", system_ids).Find(&systemUserRoles); err != nil { + // conf.Logger.Error("查询用户角色信息失败", zap.Error(err)) + // return nil, res.DbSelectError.ErrorDetail(err) + //} + //for i, v := range orgAdminUsers { + // for _, s := range systemUserRoles { + // if v.SystemId == s.SystemId { + // orgAdminUsers[i].SystemRole = append(orgAdminUsers[i].SystemRole, s.RoleName) + // } + // } + //} + + var orgInfo response.OrgDetail + if _, err = db.Table("system_organization").Alias("so"). + Select("so.organization_code, so.name, so.created_time, t3.count as platform_users_number, so.description, (case when so.name <> '平台用户组织' then '政务机构' else '平台用户组织' end) as organization_type"). + Join("LEFT", "(SELECT count(id),su.organization_id from system_user as su where su.is_deleted = 0 and su.state = 1 GROUP BY su.organization_id) t3", "t3.organization_id = so.organization_id"). + Where("so.organization_id = ? and is_deleted = 0", input.OrganizationId).Get(&orgInfo); err != nil { + conf.Logger.Error("查询组织基本信息失败", zap.Error(err)) + return nil, resp.DbSelectError.WithError(err) + } + + result := map[string]interface{}{ + "org_info": orgInfo, + "org_users": map[string]interface{}{"data": orgAdminUsers, "total": count}, + } + if orgInfo.OrganizationCode == "" { + result = nil + } + return result, nil +} + +//// 查询组织业务系统信息 +//func (o *Organization) GetBusinessMsg(input request.GetBusinessMsgInput) (interface{}, int64, error) { +// db, err := client.GetDbClient() +// if err != nil { +// return nil, 0, res.DbConnectError.ErrorDetail(err) +// } +// +// //查询业务系统信息 +// var result []response.BusinessSystem +// count, err := db.Table("system_user").Select("business_name, system_account, state"). +// Where("organization_id = ? and is_admin = 1 and is_deleted = 0", input.OrganizationId).Limit(input.Limit, (input.Page-1)*input.Limit).Asc("system_user.created_time").FindAndCount(&result) +// if err != nil { +// conf.Logger.Error("查询业务系统信息失败", zap.Error(err)) +// return nil, 0, res.DbSelectError.ErrorDetail(err) +// } +// return result, count, nil +//} +// +//// 查询组织用户详情 +//func (o *Organization) OrgUserDetail(id int) (interface{}, error) { +// db, err := client.GetDbClient() +// if err != nil { +// return nil, res.DbConnectError.ErrorDetail(err) +// } +// selectSql := "su.id, su.organization_id, su.contact_phone, su.system_account, so.name as organization, createduser.contact_name as created_by, createduser.system_account as created_by_account, " + +// "su.updated_time, su.created_time, su.contact_name, su.contact_email, su.document_type, su.document_number, su.remark, su.logo, su.state, su.system_id, su.is_admin" +// var result response.OrgUserDetail +// has, err := db.Table("system_user").Alias("su"). +// Select(selectSql). +// Join("left", "system_organization so", "so.organization_id = su.organization_id"). +// Join("left", "system_user createduser", "createduser.system_id::varchar = su.created_by"). +// Where("su.id = ? and su.is_deleted = 0", id).Get(&result) +// if err != nil { +// conf.Logger.Error("查询组织用户详情失败", zap.Error(err)) +// return nil, res.DbSelectError.ErrorDetail(err) +// } +// if !has { +// return nil, res.DbSelectError.ErrorDetail(errors.New("用户不存在")) +// } +// +// //查询用户角色 +// var systemUserRoles []response.SystemUserRole +// if err := db.Table("system_user_role").Alias("sur").Select("sur.system_id::varchar, sr.role_name"). +// Join("left", "system_role sr", "sr.role_id = sur.role_id").Where("sur.system_id::varchar = ?", result.SystemId).Find(&systemUserRoles); err != nil { +// conf.Logger.Error("查询用户角色信息失败", zap.Error(err)) +// return nil, res.DbSelectError.ErrorDetail(err) +// } +// for _, v := range systemUserRoles { +// result.SystemRole = append(result.SystemRole, v.RoleName) +// } +// return result, nil +//} +// +//// 组织添加用户时查询角色列表 查询非内置角色 + 平台运营者 +//func (o *Organization) OrgUserRoles(is_admin int) (interface{}, error) { +// db, err := client.GetDbClient() +// if err != nil { +// return nil, res.DbConnectError.ErrorDetail(err) +// } +// var rols []entity.SystemRole +// if is_admin == 3 { +// if err := db.Table("system_role").Where("(role_type = 0 and is_deleted = 0 and state = 1) or role_id = ?", util.PINGTAIYUNYINGZHE).Find(&rols); err != nil { +// conf.Logger.Error("查询用户角色信息失败", zap.Error(err)) +// return nil, res.DbSelectError.ErrorDetail(err) +// } +// } else if is_admin == 2 { +// if err := db.Table("system_role").Where("role_id = ?", util.ZUZHIGUANLIYUAN).Find(&rols); err != nil { +// conf.Logger.Error("查询用户角色信息失败", zap.Error(err)) +// return nil, res.DbSelectError.ErrorDetail(err) +// } +// } else if is_admin == 1 { +// if err := db.Table("system_role").Where("role_id = ?", util.YEWUXITONGJUESE).Find(&rols); err != nil { +// conf.Logger.Error("查询用户角色信息失败", zap.Error(err)) +// return nil, res.DbSelectError.ErrorDetail(err) +// } +// } +// return rols, nil +//} +// +//// 添加组织用户 +//func (o *Organization) OrgAddUser(input request.OrgUserInput) error { +// db, err := client.GetDbClient() +// if err != nil { +// return res.DbConnectError.ErrorDetail(err) +// } +// +// //验证账号是否存在 +// has, err := db.Table("system_user").Select("id").Where("system_account = ? and is_deleted = 0", input.SystemAccount).Exist(&entity.SystemUser{}) +// if err != nil { +// conf.Logger.Error("查询账号信息验证失败", zap.Error(err)) +// return res.DbInsertError.ErrorDetail(err) +// } +// if has { +// return res.DbInsertError.ErrorDetail(errors.New("账号已存在")) +// } +// +// //验证手机号是否存在 +// has, err = db.Table("system_user").Select("id").Where("contact_phone = ? and is_deleted = 0", input.ContactPhone).Exist(&entity.SystemUser{}) +// if err != nil { +// conf.Logger.Error("查询账号信息验证失败", zap.Error(err)) +// return res.DbInsertError.ErrorDetail(err) +// } +// if has { +// return res.DbInsertError.ErrorDetail(errors.New("手机号已存在")) +// } +// +// systemId := util.GetUUID() +// upperMd5Pass, err := SolvePassword(systemId, input.Password) +// if err != nil { +// conf.Logger.Error("密码处理出错", zap.Error(err)) +// return res.DbInsertError.ErrorDetail(err) +// } +// userModel := entity.SystemUser{ +// SystemId: systemId, +// Logo: input.Logo, +// SystemAccount: input.SystemAccount, +// ContactPhone: input.ContactPhone, +// Password: upperMd5Pass, +// State: input.State, +// ContactName: input.ContactName, +// ContactEmail: input.ContactEmail, +// Remark: input.Remark, +// OrganizationId: input.OrganizationId, +// DocumentType: input.DocumentType, +// DocumentNumber: input.DocumentNumber, +// CreatedBy: o.User.SystemId, +// IsAdmin: cast.ToInt(input.IsAdmin), +// } +// +// _, err = db.Transaction(func(s *xorm.Session) (interface{}, error) { +// if _, err := s.Table("system_user").Insert(&userModel); err != nil { +// conf.Logger.Error("创建系统账户失败", zap.Error(err)) +// return nil, res.DbInsertError.ErrorDetail(err) +// } +// +// var systemUserRoles []entity.SystemUserRole +// for _, v := range input.SelectRole { +// systemUserRoles = append(systemUserRoles, entity.SystemUserRole{SystemId: systemId, RoleId: v}) +// } +// if _, err := s.Table("system_user_role").Insert(&systemUserRoles); err != nil { +// conf.Logger.Error("创建用户角色失败", zap.Error(err)) +// return nil, res.DbInsertError.ErrorDetail(err) +// } +// return nil, nil +// }) +// return err +//} +// +//// 更新组织用户 +//func (o *Organization) OrgUpdateUser(id int, input request.UpdateOrgUserInput) error { +// db, err := client.GetDbClient() +// if err != nil { +// return res.DbConnectError.ErrorDetail(err) +// } +// var baseUser entity.SystemUser +// has, err := db.Table("system_user").ID(id).Where("is_deleted = 0").Get(&baseUser) +// if err != nil { +// conf.Logger.Error("查询账号信息失败", zap.Error(err)) +// return res.DbUpdateError.ErrorDetail(err) +// } +// if !has { +// return res.DbUpdateError.ErrorDetail(errors.New("该用户不存在")) +// } +// +// if baseUser.SystemAccount != input.SystemAccount { +// //验证账号是否存在 +// has, err = db.Table("system_user").Select("id").Where("system_account = ? and is_deleted = 0", input.SystemAccount).Exist(&entity.SystemUser{}) +// if err != nil { +// conf.Logger.Error("查询账号信息验证失败", zap.Error(err)) +// return res.DbUpdateError.ErrorDetail(err) +// } +// if has { +// return res.DbUpdateError.ErrorDetail(errors.New("账号已存在")) +// } +// } +// +// if baseUser.ContactPhone != input.ContactPhone { +// //验证手机号是否存在 +// has, err = db.Table("system_user").Select("id").Where("contact_phone = ? and is_deleted = 0", input.ContactPhone).Exist(&entity.SystemUser{}) +// if err != nil { +// conf.Logger.Error("查询账号信息验证失败", zap.Error(err)) +// return res.DbUpdateError.ErrorDetail(err) +// } +// if has { +// return res.DbUpdateError.ErrorDetail(errors.New("手机号已存在")) +// } +// } +// +// userModel := entity.SystemUser{ +// Logo: input.Logo, +// SystemAccount: input.SystemAccount, +// ContactPhone: input.ContactPhone, +// State: input.State, +// ContactName: input.ContactName, +// ContactEmail: input.ContactEmail, +// Remark: input.Remark, +// DocumentType: input.DocumentType, +// DocumentNumber: input.DocumentNumber, +// UpdatedBy: o.User.SystemId, +// } +// +// if _, err := db.Table("system_user").ID(id).Update(&userModel); err != nil { +// conf.Logger.Error("账号信息更新失败", zap.Error(err)) +// return res.DbUpdateError.ErrorDetail(err) +// } +// return nil +//} +// +//// 删除组织用户 +//func (o *Organization) DelOrgUser(input request.DelOrgUser) error { +// db, err := client.GetDbClient() +// if err != nil { +// return res.DbConnectError.ErrorDetail(err) +// } +// +// _, err = db.Transaction(func(s *xorm.Session) (interface{}, error) { +// var baseUsers []entity.SystemUser +// if err := s.Table("system_user").In("id", input.Ids).Where("is_deleted = 0").Find(&baseUsers); err != nil { +// conf.Logger.Error("查询账号信息失败", zap.Error(err)) +// return nil, res.DbDeleteError.ErrorDetail(err) +// } +// if len(baseUsers) == 0 { +// return nil, res.DbDeleteError.ErrorDetail(errors.New("用户数据不存在,删除失败")) +// } +// for _, v := range baseUsers { +// if v.State == 1 { +// return nil, res.DbDeleteError.ErrorDetail(errors.New("删除内容中有启用状态的数据,不可删除!")) +// } +// } +// +// //是组织管理员 验证是否为最后一个组织管理员账号 组织管理员人数不能为0,不可删除! +// if len(baseUsers) > 0 && baseUsers[0].IsAdmin == 2 { +// count, err := s.Table("system_user").Where("organization_id = ? and is_deleted = 0 and is_admin = 2", baseUsers[0].OrganizationId).Count(&entity.SystemUser{}) +// if err != nil { +// conf.Logger.Error("查询账号验证统计失败", zap.Error(err)) +// return nil, res.DbDeleteError.ErrorDetail(err) +// } +// if int(count)-len(baseUsers) <= 0 { +// return nil, res.DbDeleteError.ErrorDetail(errors.New("组织管理员人数不能为0,不可删除!")) +// } +// } +// +// if _, err := db.Table("system_user").In("id", input.Ids).Update(&entity.SystemUser{IsDeleted: 1, UpdatedBy: o.User.SystemId}); err != nil { +// conf.Logger.Error("用户删除失败", zap.Error(err)) +// return nil, res.DbDeleteError.ErrorDetail(err) +// } +// +// //删除用户关联角色 +// var system_ids []string +// for _, v := range baseUsers { +// system_ids = append(system_ids, v.SystemId) +// } +// if _, err := db.Table("system_user_role").In("system_id", system_ids).Delete(&entity.SystemUserRole{}); err != nil { +// conf.Logger.Error("删除用户关联角色失败", zap.Error(err)) +// return nil, res.DbDeleteError.ErrorDetail(err) +// } +// return nil, nil +// }) +// return err +//} +// +//// 去重校验 +//func (o *Organization) CheckRepetition(input request.CheckRepetition) error { +// db, err := client.GetDbClient() +// if err != nil { +// return res.DbConnectError.ErrorDetail(err) +// } +// +// var system_user entity.SystemUser +// if input.Id != 0 { +// if _, err := db.Table("system_user").Select("id, contact_phone").ID(input.Id).Where("is_deleted = 0").Get(&system_user); err != nil { +// conf.Logger.Error("查询用户失败", zap.Error(err)) +// return res.DbDataCheckError.ErrorDetail(err) +// } +// } +// if input.ContactPhone != system_user.ContactPhone { +// has, err := db.Table("system_user").Select("id").Where("contact_phone = ? and is_deleted = 0", input.ContactPhone).Exist(&entity.SystemUser{}) +// if err != nil { +// conf.Logger.Error("手机号去重查询失败", zap.Error(err)) +// return res.DbDataCheckError.ErrorDetail(err) +// } +// if has { +// return res.DbDataCheckError.ErrorDetail(errors.New("该手机号已注册")) +// } +// } +// return nil +//}