22 changed files with 1110 additions and 57 deletions
@ -0,0 +1,233 @@ |
|||
package jurisdictionpc |
|||
|
|||
import ( |
|||
"fmt" |
|||
"key_performance_indicators/models/modelshr" |
|||
"key_performance_indicators/models/modelssystempermission" |
|||
"key_performance_indicators/overall" |
|||
"key_performance_indicators/overall/publicmethod" |
|||
"strconv" |
|||
"strings" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-29 13:06:32 |
|||
@ 功能: 给指定岗位授权 |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) GrantPostSystemPowers(c *gin.Context) { |
|||
var receivedValue editPowerStructNew |
|||
err := c.ShouldBindJSON(&receivedValue) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if receivedValue.OrdId == "" || receivedValue.OrdId == "0" { |
|||
publicmethod.Result(1, receivedValue, c, "未知行政组织!不可进行配权") |
|||
return |
|||
} |
|||
if receivedValue.PostId == "" || receivedValue.PostId == "0" { |
|||
publicmethod.Result(1, receivedValue, c, "未知岗位!不可进行配权") |
|||
return |
|||
} |
|||
if receivedValue.SystemName == "" { |
|||
publicmethod.Result(1, receivedValue, c, "未知配权系统!不可进行配权") |
|||
return |
|||
} |
|||
if receivedValue.Level == 0 { |
|||
receivedValue.Level = 2 |
|||
} |
|||
var orgIdList []int64 |
|||
switch receivedValue.Level { |
|||
case 2: //本部门
|
|||
orgIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) |
|||
_, _, departmentId, _, _ := publicmethod.GetOrgStructure(orgIdInt) |
|||
// orgIdList = publicmethod.GetDepartmentSun(departmentId, orgIdList)
|
|||
|
|||
var getSunOrg publicmethod.GetOrgAllSun |
|||
getSunOrg.GetOrgSun(departmentId) |
|||
orgIdList = getSunOrg.Id |
|||
orgIdList = append(orgIdList, departmentId) |
|||
case 3: //本分部
|
|||
orgIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) |
|||
_, companyId, _, _, _ := publicmethod.GetOrgStructure(orgIdInt) |
|||
// orgIdList = publicmethod.GetDepartmentSun(companyId, orgIdList)
|
|||
var getSunOrg publicmethod.GetOrgAllSun |
|||
getSunOrg.GetOrgSun(companyId) |
|||
orgIdList = getSunOrg.Id |
|||
orgIdList = append(orgIdList, companyId) |
|||
case 4: //指定行政组织
|
|||
case 5: //所有
|
|||
overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1").Find(&orgIdList) |
|||
default: //本岗位
|
|||
orgIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) |
|||
orgIdList = append(orgIdList, orgIdInt) |
|||
} |
|||
var orgIdListAry []string //行政组织
|
|||
for _, v := range orgIdList { |
|||
orgIdListAry = append(orgIdListAry, strconv.FormatInt(v, 10)) |
|||
} |
|||
orgIdListStr := strings.Join(orgIdListAry, ",") |
|||
addTime := time.Now().Unix() |
|||
var empowerCont modelssystempermission.Empower |
|||
err = empowerCont.GetCont(map[string]interface{}{"`ordid`": receivedValue.OrdId, "`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName}, "`id`") |
|||
|
|||
if len(receivedValue.PowerList) > 0 { |
|||
var menuList []string //权限点位
|
|||
var menuOperationList []string //操作点位
|
|||
for _, v := range receivedValue.PowerList { |
|||
switch receivedValue.SystemName { |
|||
case "kpi": |
|||
if v.Attribute != 4 { |
|||
menuList = append(menuList, v.Key) |
|||
} |
|||
if v.Attribute == 4 { |
|||
menuOperationList = append(menuOperationList, v.Key) |
|||
} |
|||
case "cangchu": |
|||
menuList = append(menuList, v.Key) |
|||
default: |
|||
menuList = append(menuList, v.Key) |
|||
} |
|||
} |
|||
menuListStr := strings.Join(menuList, ",") |
|||
menuOperationListStr := strings.Join(menuOperationList, ",") |
|||
fmt.Printf("操作点位-------->%v-------->%v\n", menuOperationListStr, menuOperationList) |
|||
if err != nil { |
|||
ordIdInt64, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) |
|||
empowerCont.OrdId = ordIdInt64 //行政组织"`
|
|||
postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64) |
|||
empowerCont.PostId = postIdInt64 //岗位ID"`
|
|||
empowerCont.System = receivedValue.SystemName //系统"`
|
|||
empowerCont.PointId = menuListStr //权限点位"`
|
|||
empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|||
empowerCont.Time = time.Now().Unix() //创建时间"`
|
|||
empowerCont.Level = receivedValue.Level |
|||
empowerCont.Operation = menuOperationListStr |
|||
empowerCont.Organization = orgIdListStr |
|||
err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error |
|||
} else { |
|||
err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": menuListStr, "`operation`": menuOperationListStr, "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1, "`organization`": orgIdListStr}) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "权限配置失败") |
|||
return |
|||
} |
|||
} |
|||
} else { |
|||
if err == nil { |
|||
err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": "", "`operation`": "", "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1, "`organization`": orgIdListStr}) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "权限配置失败") |
|||
return |
|||
} |
|||
} |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2023-05-30 14:59:12 |
|||
@ 功能: |
|||
@ 参数 |
|||
|
|||
# |
|||
|
|||
@ 返回值 |
|||
|
|||
# |
|||
|
|||
@ 方法原型 |
|||
|
|||
# |
|||
*/ |
|||
func (a *ApiMethod) GrantRoleSystemPowers(c *gin.Context) { |
|||
var receivedValue editRolePowerStructNew |
|||
err := c.ShouldBindJSON(&receivedValue) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if receivedValue.RoleId == "" || receivedValue.RoleId == "0" { |
|||
publicmethod.Result(1, receivedValue, c, "未知角色!不可进行配权") |
|||
return |
|||
} |
|||
|
|||
if receivedValue.SystemName == "" { |
|||
publicmethod.Result(1, receivedValue, c, "未知配权系统!不可进行配权") |
|||
return |
|||
} |
|||
if receivedValue.Level == 0 { |
|||
receivedValue.Level = 2 |
|||
} |
|||
addTime := time.Now().Unix() |
|||
var empowerCont modelssystempermission.RoleEmpower |
|||
err = empowerCont.GetCont(map[string]interface{}{"`role_id`": receivedValue.RoleId, "`system`": receivedValue.SystemName}, "`id`") |
|||
if len(receivedValue.PowerList) < 1 { |
|||
if err == nil { |
|||
err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": "", "`operation`": "", "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1}) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "权限配置失败") |
|||
return |
|||
} |
|||
} |
|||
} else { |
|||
var menuList []string //权限点位
|
|||
var menuOperationList []string //操作点位
|
|||
for _, v := range receivedValue.PowerList { |
|||
switch receivedValue.SystemName { |
|||
case "kpi": |
|||
if v.Attribute != 4 { |
|||
menuList = append(menuList, v.Key) |
|||
} |
|||
if v.Attribute == 4 { |
|||
menuOperationList = append(menuOperationList, v.Key) |
|||
} |
|||
case "cangchu": |
|||
menuList = append(menuList, v.Key) |
|||
default: |
|||
menuList = append(menuList, v.Key) |
|||
} |
|||
} |
|||
menuListStr := strings.Join(menuList, ",") |
|||
menuOperationListStr := strings.Join(menuOperationList, ",") |
|||
if err == nil { |
|||
err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": menuListStr, "`operation`": menuOperationListStr, "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1}) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "权限配置失败") |
|||
return |
|||
} |
|||
} else { |
|||
roleIdInt, _ := strconv.ParseInt(receivedValue.RoleId, 10, 64) |
|||
empowerCont.RoleId = roleIdInt //行政组织"`
|
|||
empowerCont.System = receivedValue.SystemName //系统"`
|
|||
empowerCont.PointId = menuListStr //权限点位"`
|
|||
empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|||
empowerCont.Time = addTime //创建时间"`
|
|||
empowerCont.Level = receivedValue.Level //授权范围等级(1:本部门;2:本分部;3:所有)"`
|
|||
empowerCont.Operation = menuOperationListStr //操作点位
|
|||
err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "权限配置失败") |
|||
return |
|||
} |
|||
} |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
package modelAppPlatform |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 字典类型
|
|||
type DictType struct { |
|||
Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` |
|||
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:字典类型名称"` |
|||
Code int64 `json:"code" gorm:"column:code;type:bigint(20) unsigned;default:0;not null;comment:字典类型编码"` |
|||
Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:显示状态(1:显示;2:隐藏,3:删除)"` |
|||
Remark string `json:"remark" gorm:"column:remark;type:mediumtext;default:'';comment:字典类型描述"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (DictType *DictType) TableName() string { |
|||
return "dict_type" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *DictType) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *DictType) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *DictType) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *DictType) ContMap(whereMap interface{}, field ...string) (countAry []DictType, err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *DictType) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
package modelAppPlatform |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 字典内容
|
|||
type Dictionary struct { |
|||
Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` |
|||
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:字典内容名称"` |
|||
TypeCode int64 `json:"typeCode" gorm:"column:typeCode;type:bigint(20) unsigned;default:0;not null;comment:字典类型编码"` |
|||
Code int64 `json:"code" gorm:"column:code;type:bigint(20) unsigned;default:0;not null;comment:字典内编码"` |
|||
Sort int `json:"sort" gorm:"column:sort;type:int(1) unsigned;default:50;not null;comment:排序(数字越小排名越靠前))"` |
|||
Status int `json:"status" gorm:"column:status;type:int(1) unsigned;default:1;not null;comment:显示状态(1:显示;2:隐藏,3:删除)"` |
|||
Remark string `json:"remark" gorm:"column:remark;type:mediumtext;default:'';comment:字典内描述"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (Dictionary *Dictionary) TableName() string { |
|||
return "dictionary" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Dictionary) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Dictionary) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *Dictionary) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Dictionary) ContMap(whereMap interface{}, field ...string) (countAry []Dictionary, err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *Dictionary) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
package modelAppPlatform |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 行政组织类型
|
|||
type Menus struct { |
|||
Id int `json:"id" gorm:"primaryKey;column:id;type:int(5) unsigned;not null;comment:Id;index"` |
|||
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:菜单名称"` |
|||
Types int `json:"type" gorm:"column:type;type:int(1) unsigned;default:1;not null;comment:菜单类型(1-菜单;2-目录;3-外链;4-按钮权限"` |
|||
Path string `json:"path" gorm:"column:path;type:varchar(255) ;default:'';comment:路由路径"` |
|||
Component string `json:"component" gorm:"column:component;type:varchar(255) ;default:'';comment:组件路径(vue页面完整路径,省略.vue后缀)"` |
|||
Perm int64 `json:"perm" gorm:"column:perm;type:bigint(20) unsigned;default:0;not null;comment:权限标识"` |
|||
Visible int `json:"visible" gorm:"column:visible;type:int(1) unsigned;default:1;not null;comment:显示状态(1:显示;2:隐藏,3:删除)"` |
|||
Sort int `json:"sort" gorm:"column:sort;type:int(1) unsigned;default:50;not null;comment:排序(数字越小排名越靠前))"` |
|||
Icon string `json:"icon" gorm:"column:icon;type:varchar(255) ;default:'';comment:菜单图标"` |
|||
Redirect string `json:"redirect" gorm:"column:redirect;type:varchar(255) ;default:'';comment:跳转路径"` |
|||
ParentId int `json:"parentId" gorm:"column:parentId;type:int(5) unsigned;default:0;not null;comment:父菜单ID"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (menus *Menus) TableName() string { |
|||
return "menus" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Menus) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Menus) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *Menus) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_AppPlatform.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Menus) ContMap(whereMap interface{}, field ...string) (countAry []Menus, err error) { |
|||
gormDb := overall.CONSTANT_DB_AppPlatform.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *Menus) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_AppPlatform.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue