|
|
package BaseRolePersonService
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"dsBaseRpc/Const"
|
|
|
"dsBaseRpc/Const/ErrorConst"
|
|
|
"dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonDao"
|
|
|
"dsBaseRpc/RpcService/BaseRolePerson/BaseRolePersonProto"
|
|
|
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonDao"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/LogUtil"
|
|
|
"dsBaseRpc/Utils/SqlKit"
|
|
|
"dsBaseRpc/models"
|
|
|
)
|
|
|
|
|
|
type Rpc struct{} //服务对象
|
|
|
|
|
|
//选择单条
|
|
|
func (s *Rpc) GetBaseRolePerson(ctx context.Context, in *BaseRolePersonProto.ModelArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
//通用获取单条
|
|
|
list := SqlKit.QueryListMapByIds([]string{in.Id}, "t_base_role_person")
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = 1
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//增加
|
|
|
func (s *Rpc) AddBaseRolePerson(ctx context.Context, in *BaseRolePersonProto.ModelArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
//调用dao
|
|
|
model := new(models.TBaseRolePerson)
|
|
|
//实体填充
|
|
|
//
|
|
|
model.Id = CommonUtil.GetUUID()
|
|
|
//角色ID
|
|
|
model.RoleId = in.RoleId
|
|
|
//身份ID
|
|
|
model.IdentityId = in.IdentityId
|
|
|
//人员ID
|
|
|
model.PersonId = in.PersonId
|
|
|
//具体管辖是哪个省、市、区或大学区ID,单位ID
|
|
|
model.RuleId = in.RuleId
|
|
|
//是否启用 0:未启用 1:启用
|
|
|
model.BUse = in.BUse
|
|
|
|
|
|
_, err := BaseRolePersonDao.AddBaseRolePerson(*model)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddBaseRolePerson时发生严重错误:"+err.Error())
|
|
|
} else {
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
}
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//删除
|
|
|
func (s *Rpc) DeleteBaseRolePerson(ctx context.Context, in *BaseRolePersonProto.DeleteIdsArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
//调用通用删除命令进行删除
|
|
|
err := SqlKit.DeleteIds("t_base_role_person", in.Ids)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行DeleteBaseRolePerson时发生严重错误:"+err.Error())
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//修改
|
|
|
func (s *Rpc) UpdateBaseRolePerson(ctx context.Context, in *BaseRolePersonProto.ModelArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
//3、修改
|
|
|
model := new(models.TBaseRolePerson)
|
|
|
//实体填充
|
|
|
//
|
|
|
model.Id = CommonUtil.GetUUID()
|
|
|
//角色ID
|
|
|
model.RoleId = in.RoleId
|
|
|
//身份ID
|
|
|
model.IdentityId = in.IdentityId
|
|
|
//人员ID
|
|
|
model.PersonId = in.PersonId
|
|
|
//具体管辖是哪个省、市、区或大学区ID,单位ID
|
|
|
model.RuleId = in.RuleId
|
|
|
//是否启用 0:未启用 1:启用
|
|
|
model.BUse = in.BUse
|
|
|
|
|
|
_, err := BaseRolePersonDao.UpdateBaseRolePerson(*model, in.ForceUpdateFields)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseRolePerson时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
reply.Success = true
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
return &reply, nil
|
|
|
}
|
|
|
|
|
|
//分页查询
|
|
|
func (s *Rpc) PageBaseRolePerson(ctx context.Context, in *BaseRolePersonProto.QueryArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
//rpc响应
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
list, count, err := BaseRolePersonDao.PageBaseRolePerson(in)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行PageBaseRolePerson时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//返回结果
|
|
|
if list != nil && len(list) > 0 {
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = count
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
} else {
|
|
|
reply.Success = false
|
|
|
reply.Count = 0
|
|
|
reply.Message = Const.DataBaseBlankResult
|
|
|
reply.List = Const.BlankArrayString
|
|
|
return &reply, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据人员ID获取所管辖的地区信息
|
|
|
func (s *Rpc) GetManageArea(ctx context.Context, in *BaseRolePersonProto.GetManageAreaArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
|
|
|
//1、判断这个人员是不是超级管理员
|
|
|
isAdmin, err := BaseRolePersonDao.IsAdmin(in.PersonId)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行IsAdmin时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//如果是超级管理员,那么返回所有开通的城市及下属的县区
|
|
|
if isAdmin {
|
|
|
list, count, err := BaseRolePersonDao.HaveActiveCityList()
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行HaveActiveCityList时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//返回结果
|
|
|
if list != nil && len(list) > 0 {
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = count
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
} else {
|
|
|
reply.Success = false
|
|
|
reply.Count = 0
|
|
|
reply.Message = Const.DataBaseBlankResult
|
|
|
reply.List = Const.BlankArrayString
|
|
|
return &reply, nil
|
|
|
}
|
|
|
} else {
|
|
|
//如果不是超级管理员,那么返回此人员对应的城市或县区
|
|
|
list, count, err := BaseRolePersonDao.GetManageArea(in.PersonId)
|
|
|
//错误处理
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行GetManageArea时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
//将结果序列化
|
|
|
reply.Success = true
|
|
|
reply.Count = count
|
|
|
reply.Message = Const.SuccessDataBaseAction
|
|
|
reply.List = CommonUtil.SerializeToString(list)
|
|
|
return &reply, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//检查指定人员是否有预操作数据对象的控制权
|
|
|
func (s *Rpc) CheckDataPrivilege(ctx context.Context, in *BaseRolePersonProto.CheckDataPrivilegeArg) (*BaseRolePersonProto.Reply, error) {
|
|
|
var reply BaseRolePersonProto.Reply
|
|
|
//操作人员ID
|
|
|
actionPersonId := in.ActionPersonId
|
|
|
//哪些角色下
|
|
|
roleIds, err := BaseRolePersonDao.ConvertRoleIntIdsToGuidIds(in.RoleId)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
return &reply, err
|
|
|
}
|
|
|
//人员有哪些角色
|
|
|
list, count, err := BaseRolePersonDao.GetPersonRoleList(actionPersonId)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = Const.DataBaseActionError
|
|
|
LogUtil.Error(ErrorConst.SqlQueryError, "执行GetPersonRoleList时发生严重错误:"+err.Error())
|
|
|
return &reply, err
|
|
|
}
|
|
|
if count == 0 {
|
|
|
reply.Success = false
|
|
|
reply.Message = "操作者不在限定的角色范围内。"
|
|
|
return &reply, err
|
|
|
}
|
|
|
|
|
|
//看看是不是有超级管理员角色?
|
|
|
for i := range list {
|
|
|
if list[i]["role_id"].(string) == Const.SuperManager {
|
|
|
reply.Success = true
|
|
|
reply.Message = "恭迎超级管理员驾临指导工作!!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
found := false
|
|
|
for i := range list {
|
|
|
for j := range roleIds {
|
|
|
if list[i]["role_id"].(string) == roleIds[j] {
|
|
|
found = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !found {
|
|
|
reply.Success = false
|
|
|
reply.Message = "操作者不在限定的角色范围内。"
|
|
|
return &reply, err
|
|
|
}
|
|
|
//***检查区域*****************************
|
|
|
//哪些区域下
|
|
|
areaCodes := in.AreaCode
|
|
|
if len(areaCodes) > 0 {
|
|
|
found = false
|
|
|
for i := range list {
|
|
|
for j := range areaCodes {
|
|
|
if list[i]["rule_id"].(string) == areaCodes[j] {
|
|
|
found = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !found {
|
|
|
reply.Success = false
|
|
|
reply.Message = "操作者没有指定的区域管理权!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
}
|
|
|
//***检查单位+学校+部门*****************************
|
|
|
orgIds := in.OrgId
|
|
|
if len(orgIds) > 0 {
|
|
|
found = true
|
|
|
l2 := SqlKit.QueryListMapByIds(orgIds, "t_base_organization")
|
|
|
if l2 == nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = "传入的单位或部门ID没有找到!!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
for i := range list {
|
|
|
for j := range l2 {
|
|
|
//6位是市或县区
|
|
|
if l2[j]["city_code"].(string) != list[i]["rule_id"].(string) &&
|
|
|
l2[j]["district_code"].(string) != list[i]["rule_id"].(string) &&
|
|
|
l2[j]["bureau_id"].(string) != list[i]["rule_id"].(string) {
|
|
|
found = false
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !found {
|
|
|
reply.Success = false
|
|
|
reply.Message = "操作者没有指定的单位、部门管理权!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
}
|
|
|
//***检查班级*****************************
|
|
|
classIds := in.ClassId
|
|
|
if len(classIds) > 0 {
|
|
|
found = true
|
|
|
listClass := SqlKit.QueryListMapByIds(classIds, "t_base_class")
|
|
|
if listClass == nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = "传入的班级ID没有找到!!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
for i := range list {
|
|
|
for j := range listClass {
|
|
|
if listClass[j]["city_code"].(string) != list[i]["rule_id"].(string) &&
|
|
|
listClass[j]["district_code"].(string) != list[i]["rule_id"].(string) &&
|
|
|
listClass[j]["bureau_id"].(string) != list[i]["rule_id"].(string) {
|
|
|
found = false
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !found {
|
|
|
reply.Success = false
|
|
|
reply.Message = "操作者没有指定的单位、部门管理权!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
}
|
|
|
//***检查人员*****************************
|
|
|
//通过人员换算出对应的单位IDS
|
|
|
personIds := in.PersonId
|
|
|
if len(personIds) > 0 {
|
|
|
l2, message, err := SysLoginpersonDao.GetBureauIdsByPersonIds(personIds)
|
|
|
if err != nil {
|
|
|
reply.Success = false
|
|
|
reply.Message = message
|
|
|
return &reply, err
|
|
|
}
|
|
|
if l2 == nil || len(l2) != len(personIds) {
|
|
|
reply.Success = false
|
|
|
reply.Message = "传入的人员ID没有找到!!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
found = true
|
|
|
for i := range list {
|
|
|
for j := range l2 {
|
|
|
if l2[j]["city_code"].(string) != list[i]["rule_id"].(string) &&
|
|
|
l2[j]["district_code"].(string) != list[i]["rule_id"].(string) &&
|
|
|
l2[j]["bureau_ud"].(string) != list[i]["rule_id"].(string) {
|
|
|
found = false
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !found {
|
|
|
reply.Success = false
|
|
|
reply.Message = "操作者没有指定的人员所在单位管理权!"
|
|
|
return &reply, err
|
|
|
}
|
|
|
}
|
|
|
reply.Success = true
|
|
|
reply.Message = "检查通过!"
|
|
|
return &reply, nil
|
|
|
}
|