Browse Source

修改获取授权的方式

master
超级管理员 3 years ago
parent
commit
c6a0013999
  1. 23
      README.md
  2. 26
      api/version1/empower/system_license.go
  3. 1
      config/configDatabase/database.go
  4. 15
      config/configDatabase/database.yaml
  5. 10
      identification/interceptor/identity.go
  6. 7
      initialization/databaseinit/mysql.go
  7. 35
      models/modelsschool/system_menu.go
  8. 65
      models/modelsstorage/accesstoaddress.go
  9. 1
      overall/appConfig.go
  10. 73
      overall/publicmethod/technique.go

23
README.md

@ -320,4 +320,27 @@ systemPermission:
} else { } else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.SystemPermission.Name) fmt.Printf("%v数据库开启成功!\n", sqlConfig.SystemPermission.Name)
} }
```
## 增加仓储系统参数
1、config\configDatabase\database.go
Storage MasterMysqlSetUp `mapstructure:"storage" json:"storage" yaml:"storage"` //仓储系统数据库
2、overall\appConfig.go
CONSTANT_DB_Storage *gorm.DB //仓储系统数据库
3、initialization\databaseinit\mysql.go
```
//仓储系统
overall.CONSTANT_DB_Storage = sqlConfig.Storage.OpenSql()
if overall.CONSTANT_DB_Storage == nil {
fmt.Printf("%v数据库开启失败!\n", sqlConfig.Storage.Name)
} else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.Storage.Name)
}
``` ```

26
api/version1/empower/system_license.go

@ -1,9 +1,7 @@
package empower package empower
import ( import (
"key_performance_indicators/models/modelssystempermission"
"key_performance_indicators/overall/publicmethod" "key_performance_indicators/overall/publicmethod"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -26,17 +24,23 @@ func (a *ApiMethod) ObtainAuthorization(c *gin.Context) {
publicmethod.Result(1, err, c, "未知身份!不可授权!") publicmethod.Result(1, err, c, "未知身份!不可授权!")
return return
} }
var systemPermission modelssystempermission.Empower
err = systemPermission.GetCont(map[string]interface{}{"`state`": 1, "`ordid`": context.AdminOrg, "`post_id`": context.Position, "`system`": receivedValue.System}, "`point_id`") menuIdAry, menuUrl, err := publicmethod.GetPostPower(context.AdminOrg, context.Position, receivedValue.System)
// var systemPermission modelssystempermission.Empower
// err = systemPermission.GetCont(map[string]interface{}{"`state`": 1, "`ordid`": context.AdminOrg, "`post_id`": context.Position, "`system`": receivedValue.System}, "`point_id`")
if err != nil { if err != nil {
publicmethod.Result(1, err, c, "没有可使用的授权信息!") publicmethod.Result(1, err, c, "没有可使用的授权信息!")
return return
} }
// var pointId []string // // var pointId []string
pointId := strings.Split(systemPermission.PointId, ",") // pointId := strings.Split(systemPermission.PointId, ",")
if len(pointId) < 1 { // if len(pointId) < 1 {
publicmethod.Result(1, err, c, "没有可使用的授23权信息!") // publicmethod.Result(1, err, c, "没有可使用的授23权信息!")
return // return
} // }
publicmethod.Result(0, pointId, c) sendData := publicmethod.MapOut[string]()
sendData["powerid"] = menuIdAry
sendData["powerurl"] = menuUrl
publicmethod.Result(0, sendData, c)
} }

1
config/configDatabase/database.go

@ -25,6 +25,7 @@ type MysqlSetUp struct {
WechatCallBackLogDate MasterMysqlSetUp `mapstructure:"wechatCallBackLogDate" json:"wechatCallBackLogDate" yaml:"wechatCallBackLogDate"` //企业微信回调记录 WechatCallBackLogDate MasterMysqlSetUp `mapstructure:"wechatCallBackLogDate" json:"wechatCallBackLogDate" yaml:"wechatCallBackLogDate"` //企业微信回调记录
Managearchives MasterMysqlSetUp `mapstructure:"managearchives" json:"managearchives" yaml:"managearchives"` //管理档案 Managearchives MasterMysqlSetUp `mapstructure:"managearchives" json:"managearchives" yaml:"managearchives"` //管理档案
SystemPermission MasterMysqlSetUp `mapstructure:"systempermission" json:"systempermission" yaml:"systempermission"` //系统权限配置数据库 SystemPermission MasterMysqlSetUp `mapstructure:"systempermission" json:"systempermission" yaml:"systempermission"` //系统权限配置数据库
Storage MasterMysqlSetUp `mapstructure:"storage" json:"storage" yaml:"storage"` //仓储系统数据库
} }
type MasterMysqlSetUp struct { type MasterMysqlSetUp struct {

15
config/configDatabase/database.yaml

@ -203,4 +203,19 @@ systemPermission:
password: 'root' #数据库密码 password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量 max_idle_conns: 100 #最大空闲数量
max_open_conns: 1500 #最大打开数量 max_open_conns: 1500 #最大打开数量
gorm_log: true #是否开启gorm日志
#仓库系统
storage:
url_path: '127.0.0.1' #数据库地址
port: 3306 #数据库端口
charset: 'utf8mb4' #数据库编码方式
parseTime: 'True' #是否自动转换时间
loc: 'Local' #时区
name: 'depository' #数据库名称
username: 'root' #数据库用户民
password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量
max_open_conns: 1500 #最大打开数量
gorm_log: true #是否开启gorm日志 gorm_log: true #是否开启gorm日志

10
identification/interceptor/identity.go

@ -3,7 +3,6 @@ package interceptor
import ( import (
"fmt" "fmt"
"key_performance_indicators/middleware/grocerystore" "key_performance_indicators/middleware/grocerystore"
"key_performance_indicators/models/modelssystempermission"
"key_performance_indicators/overall" "key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod" "key_performance_indicators/overall/publicmethod"
@ -131,15 +130,8 @@ func VerifyUrl() gin.HandlerFunc {
// 获取请求方法 // 获取请求方法
act := c.Request.Method act := c.Request.Method
// publicmethod.GetPostPower(context.AdminOrg, context.Position, "kpi")
fmt.Printf("obj------>%v-----------act------->%v---systemClass------------>%v------------------context-------->%v\n", obj, act, systemClass, context.Role) fmt.Printf("obj------>%v-----------act------->%v---systemClass------------>%v------------------context-------->%v\n", obj, act, systemClass, context.Role)
c.Next() c.Next()
} }
} }
// 获取岗位权限
func GetPostPower(postid int64, system string) {
var ponitId string
err := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Empower{}).Select("`point_id`").Where("`state` = 1 AND `post_id` = ? AND `system` = ?", postid, system).Find(&ponitId).Error
if err == nil {
}
}

7
initialization/databaseinit/mysql.go

@ -114,4 +114,11 @@ func LoadDatabase() {
} else { } else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.SystemPermission.Name) fmt.Printf("%v数据库开启成功!\n", sqlConfig.SystemPermission.Name)
} }
//仓储系统
overall.CONSTANT_DB_Storage = sqlConfig.Storage.OpenSql()
if overall.CONSTANT_DB_Storage == nil {
fmt.Printf("%v数据库开启失败!\n", sqlConfig.Storage.Name)
} else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.Storage.Name)
}
} }

35
models/modelsschool/system_nenu.go → models/modelsschool/system_menu.go

@ -28,15 +28,15 @@ type SystemMenuOperation struct {
MenuPermit []MenuOperation `json:"menupermit"` MenuPermit []MenuOperation `json:"menupermit"`
} }
// 根据条件获取总数 // 编辑内容
func (cont *SystemMenu) CountCont(whereMap map[string]interface{}) (countId int64) { func (cont *SystemMenu) EiteCont(whereMap interface{}, saveData interface{}) (err error) {
overall.CONSTANT_DB_Master.Model(&cont).Where(whereMap).Count(&countId) err = overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Updates(saveData).Error
return return
} }
// 获取行政组织内容 // 获取内容
func (cont *SystemMenu) GetCont(whereMap map[string]interface{}, field ...string) (err error) { func (cont *SystemMenu) GetCont(whereMap interface{}, field ...string) (err error) {
gormDb := overall.CONSTANT_DB_Master.Model(&cont) gormDb := overall.CONSTANT_DB_KPI.Model(&cont)
if len(field) > 0 { if len(field) > 0 {
fieldStr := strings.Join(field, ",") fieldStr := strings.Join(field, ",")
gormDb = gormDb.Select(fieldStr) gormDb = gormDb.Select(fieldStr)
@ -45,3 +45,26 @@ func (cont *SystemMenu) GetCont(whereMap map[string]interface{}, field ...string
err = gormDb.First(&cont).Error err = gormDb.First(&cont).Error
return return
} }
// 根据条件获取总数
func (cont *SystemMenu) CountCont(whereMap interface{}) (countId int64) {
overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Count(&countId)
return
}
// 读取全部信息
func (cont *SystemMenu) ContMap(whereMap interface{}, field ...string) (countAry []SystemMenu, err error) {
gormDb := overall.CONSTANT_DB_KPI.Model(&cont)
if len(field) > 0 {
fieldStr := strings.Join(field, ",")
gormDb = gormDb.Select(fieldStr)
}
err = gormDb.Where(whereMap).Find(&countAry).Error
return
}
// 删除内容
func (cont *SystemMenu) DelCont(whereMap interface{}) (err error) {
err = overall.CONSTANT_DB_KPI.Where(whereMap).Delete(&cont).Error
return
}

65
models/modelsstorage/accesstoaddress.go

@ -0,0 +1,65 @@
package modelsstorage
import (
"key_performance_indicators/overall"
"strings"
)
// 仓储系统菜单管理
type AccesstoAddress struct {
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;index"`
Name string `json:"name" gorm:"column:name;type:varchar(100);comment:名称"`
Url string `json:"url" gorm:"column:url;type:varchar(100);comment:路径"`
Type int `json:"type" gorm:"column:type;type:int(1) unsigned;default:1;not null;comment:访问方式(1get,2post,3delet,4put,5全部)"`
RoleId int `json:"roleid" gorm:"column:role_id;type:int(1) unsigned;default:1;not null;comment:菜单对应的角色"`
Menuparent int `json:"menuparent" gorm:"column:menuparent;type:int(1) unsigned;default:0;not null;comment:父菜单,0代表无父菜单"`
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"`
Icon string `json:"icon" gorm:"icon:name;type:varchar(100);comment:图标"`
Target string `json:"target" gorm:"column:target;type:varchar(100);comment:目标"`
IsChild int `json:"ischild" gorm:"column:ischild;type:int(1) unsigned;default:1;not null;comment:是否有子菜单\r\n(1有2无)"`
}
func (AccesstoAddress *AccesstoAddress) TableName() string {
return "accesstoaddress"
}
// 编辑内容
func (cont *AccesstoAddress) EiteCont(whereMap interface{}, saveData interface{}) (err error) {
err = overall.CONSTANT_DB_Storage.Model(&cont).Where(whereMap).Updates(saveData).Error
return
}
// 获取内容
func (cont *AccesstoAddress) GetCont(whereMap interface{}, field ...string) (err error) {
gormDb := overall.CONSTANT_DB_Storage.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 *AccesstoAddress) CountCont(whereMap interface{}) (countId int64) {
overall.CONSTANT_DB_Storage.Model(&cont).Where(whereMap).Count(&countId)
return
}
// 读取全部信息
func (cont *AccesstoAddress) ContMap(whereMap interface{}, field ...string) (countAry []AccesstoAddress, err error) {
gormDb := overall.CONSTANT_DB_Storage.Model(&cont)
if len(field) > 0 {
fieldStr := strings.Join(field, ",")
gormDb = gormDb.Select(fieldStr)
}
err = gormDb.Where(whereMap).Find(&countAry).Error
return
}
// 删除内容
func (cont *AccesstoAddress) DelCont(whereMap interface{}) (err error) {
err = overall.CONSTANT_DB_Storage.Where(whereMap).Delete(&cont).Error
return
}

1
overall/appConfig.go

@ -38,6 +38,7 @@ var (
CONSTANT_DB_WECHAT_LOG *gorm.DB //企业微信回调记录 CONSTANT_DB_WECHAT_LOG *gorm.DB //企业微信回调记录
CONSTANT_DB_MANAGE_ARCHIVES *gorm.DB //管理档案 CONSTANT_DB_MANAGE_ARCHIVES *gorm.DB //管理档案
CONSTANT_DB_System_Permission *gorm.DB //系统权限配置数据库 CONSTANT_DB_System_Permission *gorm.DB //系统权限配置数据库
CONSTANT_DB_Storage *gorm.DB //仓储系统数据库
//Redis //Redis
CONSTANT_REDIS0 *redis.Client CONSTANT_REDIS0 *redis.Client
CONSTANT_REDIS1 *redis.Client CONSTANT_REDIS1 *redis.Client

73
overall/publicmethod/technique.go

@ -11,11 +11,15 @@ import (
"key_performance_indicators/middleware/grocerystore" "key_performance_indicators/middleware/grocerystore"
"key_performance_indicators/middleware/snowflake" "key_performance_indicators/middleware/snowflake"
"key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelsschool"
"key_performance_indicators/models/modelsstorage"
"key_performance_indicators/models/modelssystempermission"
"key_performance_indicators/overall" "key_performance_indicators/overall"
"math" "math"
"math/big" "math/big"
"reflect" "reflect"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/mozillazg/go-pinyin" "github.com/mozillazg/go-pinyin"
@ -682,3 +686,72 @@ func ComputingTime(timeStamp int64, timeType int) (timeDataInt int64) {
} }
return return
} }
/*
获取岗位权限
@ordid 行政组织
@postid 岗位
@system 系统标识
*/
func GetPostPower(ordid, postid int64, system string) (menuIdAry, menuUrl []string, err error) {
var ponitId string
err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Empower{}).Select("`point_id`").Where("`state` = 1 AND `post_id` = ? AND `system` = ?", postid, system).Find(&ponitId).Error
if err != nil {
return
}
menuIdAry = strings.Split(ponitId, ",")
if len(menuIdAry) < 1 {
return
}
switch system {
case "cangchu":
menuUrl, err = getStorageSystemEmpower(menuIdAry)
default:
//绩效考核系统
menuUrl, err = getKpiSystemEmpower(menuIdAry)
}
return
}
/*
获取绩效考核系统授权菜单
@menuIdAry 菜单ID
*/
func getKpiSystemEmpower(menuIdAry []string) (menuUrl []string, err error) {
if len(menuIdAry) < 1 {
return
}
var empowerMenuUrl []string
err = overall.CONSTANT_DB_Master.Model(&modelsschool.SystemMenu{}).Distinct("`m_url`").Where("`m_steat` = 1 AND `m_id` IN ?", menuIdAry).Find(&empowerMenuUrl).Error
if err != nil || len(empowerMenuUrl) < 1 {
return
}
for i := 0; i < len(empowerMenuUrl); i++ {
if empowerMenuUrl[i] != "#" && IsInTrue[string](empowerMenuUrl[i], menuUrl) == false {
menuUrl = append(menuUrl, empowerMenuUrl[i])
}
}
return
}
/*
获取仓储考核系统授权菜单
@menuIdAry 菜单ID
*/
func getStorageSystemEmpower(menuIdAry []string) (menuUrl []string, err error) {
if len(menuIdAry) < 1 {
return
}
var empowerMenuUrl []string
err = overall.CONSTANT_DB_Storage.Model(&modelsstorage.AccesstoAddress{}).Distinct("`url`").Where("`state` = 1 AND `id` IN ?", menuIdAry).Find(&empowerMenuUrl).Error
if err != nil || len(empowerMenuUrl) < 1 {
return
}
// fmt.Printf("empowerMenuUrl---------->%v\n", empowerMenuUrl)
for i := 0; i < len(empowerMenuUrl); i++ {
if empowerMenuUrl[i] != "#" && empowerMenuUrl[i] != "" && IsInTrue[string](empowerMenuUrl[i], menuUrl) == false {
menuUrl = append(menuUrl, empowerMenuUrl[i])
}
}
return
}

Loading…
Cancel
Save