From c6a00139992120f9a96202c89120baa276535093 Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Mon, 5 Sep 2022 15:53:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 ++++++ api/version1/empower/system_license.go | 26 ++++--- config/configDatabase/database.go | 1 + config/configDatabase/database.yaml | 15 ++++ identification/interceptor/identity.go | 10 +-- initialization/databaseinit/mysql.go | 7 ++ .../{system_nenu.go => system_menu.go} | 35 +++++++-- models/modelsstorage/accesstoaddress.go | 65 +++++++++++++++++ overall/appConfig.go | 1 + overall/publicmethod/technique.go | 73 +++++++++++++++++++ 10 files changed, 230 insertions(+), 26 deletions(-) rename models/modelsschool/{system_nenu.go => system_menu.go} (61%) create mode 100644 models/modelsstorage/accesstoaddress.go diff --git a/README.md b/README.md index 94ac8a6..73c4428 100644 --- a/README.md +++ b/README.md @@ -320,4 +320,27 @@ systemPermission: } else { 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) + } ``` \ No newline at end of file diff --git a/api/version1/empower/system_license.go b/api/version1/empower/system_license.go index dce91cd..defc4ca 100644 --- a/api/version1/empower/system_license.go +++ b/api/version1/empower/system_license.go @@ -1,9 +1,7 @@ package empower import ( - "key_performance_indicators/models/modelssystempermission" "key_performance_indicators/overall/publicmethod" - "strings" "github.com/gin-gonic/gin" ) @@ -26,17 +24,23 @@ func (a *ApiMethod) ObtainAuthorization(c *gin.Context) { publicmethod.Result(1, err, c, "未知身份!不可授权!") 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 { publicmethod.Result(1, err, c, "没有可使用的授权信息!") return } - // var pointId []string - pointId := strings.Split(systemPermission.PointId, ",") - if len(pointId) < 1 { - publicmethod.Result(1, err, c, "没有可使用的授23权信息!") - return - } - publicmethod.Result(0, pointId, c) + // // var pointId []string + // pointId := strings.Split(systemPermission.PointId, ",") + // if len(pointId) < 1 { + // publicmethod.Result(1, err, c, "没有可使用的授23权信息!") + // return + // } + sendData := publicmethod.MapOut[string]() + sendData["powerid"] = menuIdAry + sendData["powerurl"] = menuUrl + publicmethod.Result(0, sendData, c) } diff --git a/config/configDatabase/database.go b/config/configDatabase/database.go index cb80c86..9f304fa 100644 --- a/config/configDatabase/database.go +++ b/config/configDatabase/database.go @@ -25,6 +25,7 @@ type MysqlSetUp struct { WechatCallBackLogDate MasterMysqlSetUp `mapstructure:"wechatCallBackLogDate" json:"wechatCallBackLogDate" yaml:"wechatCallBackLogDate"` //企业微信回调记录 Managearchives MasterMysqlSetUp `mapstructure:"managearchives" json:"managearchives" yaml:"managearchives"` //管理档案 SystemPermission MasterMysqlSetUp `mapstructure:"systempermission" json:"systempermission" yaml:"systempermission"` //系统权限配置数据库 + Storage MasterMysqlSetUp `mapstructure:"storage" json:"storage" yaml:"storage"` //仓储系统数据库 } type MasterMysqlSetUp struct { diff --git a/config/configDatabase/database.yaml b/config/configDatabase/database.yaml index 1595c85..fc5222e 100644 --- a/config/configDatabase/database.yaml +++ b/config/configDatabase/database.yaml @@ -203,4 +203,19 @@ systemPermission: password: 'root' #数据库密码 max_idle_conns: 100 #最大空闲数量 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日志 \ No newline at end of file diff --git a/identification/interceptor/identity.go b/identification/interceptor/identity.go index cfd75e8..6327a83 100644 --- a/identification/interceptor/identity.go +++ b/identification/interceptor/identity.go @@ -3,7 +3,6 @@ package interceptor import ( "fmt" "key_performance_indicators/middleware/grocerystore" - "key_performance_indicators/models/modelssystempermission" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" @@ -131,15 +130,8 @@ func VerifyUrl() gin.HandlerFunc { // 获取请求方法 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) 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 { - } -} diff --git a/initialization/databaseinit/mysql.go b/initialization/databaseinit/mysql.go index 87f2b08..5c7b1f9 100644 --- a/initialization/databaseinit/mysql.go +++ b/initialization/databaseinit/mysql.go @@ -114,4 +114,11 @@ func LoadDatabase() { } else { 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) + } } diff --git a/models/modelsschool/system_nenu.go b/models/modelsschool/system_menu.go similarity index 61% rename from models/modelsschool/system_nenu.go rename to models/modelsschool/system_menu.go index be33325..ec6e4fe 100644 --- a/models/modelsschool/system_nenu.go +++ b/models/modelsschool/system_menu.go @@ -28,15 +28,15 @@ type SystemMenuOperation struct { MenuPermit []MenuOperation `json:"menupermit"` } -// 根据条件获取总数 -func (cont *SystemMenu) CountCont(whereMap map[string]interface{}) (countId int64) { - overall.CONSTANT_DB_Master.Model(&cont).Where(whereMap).Count(&countId) +// 编辑内容 +func (cont *SystemMenu) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Updates(saveData).Error return } -// 获取行政组织内容 -func (cont *SystemMenu) GetCont(whereMap map[string]interface{}, field ...string) (err error) { - gormDb := overall.CONSTANT_DB_Master.Model(&cont) +// 获取内容 +func (cont *SystemMenu) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_KPI.Model(&cont) if len(field) > 0 { fieldStr := strings.Join(field, ",") gormDb = gormDb.Select(fieldStr) @@ -45,3 +45,26 @@ func (cont *SystemMenu) GetCont(whereMap map[string]interface{}, field ...string err = gormDb.First(&cont).Error 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 +} diff --git a/models/modelsstorage/accesstoaddress.go b/models/modelsstorage/accesstoaddress.go new file mode 100644 index 0000000..6f46bf6 --- /dev/null +++ b/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 +} diff --git a/overall/appConfig.go b/overall/appConfig.go index beb5585..d4bd3d2 100644 --- a/overall/appConfig.go +++ b/overall/appConfig.go @@ -38,6 +38,7 @@ var ( CONSTANT_DB_WECHAT_LOG *gorm.DB //企业微信回调记录 CONSTANT_DB_MANAGE_ARCHIVES *gorm.DB //管理档案 CONSTANT_DB_System_Permission *gorm.DB //系统权限配置数据库 + CONSTANT_DB_Storage *gorm.DB //仓储系统数据库 //Redis CONSTANT_REDIS0 *redis.Client CONSTANT_REDIS1 *redis.Client diff --git a/overall/publicmethod/technique.go b/overall/publicmethod/technique.go index b44e440..945c542 100644 --- a/overall/publicmethod/technique.go +++ b/overall/publicmethod/technique.go @@ -11,11 +11,15 @@ import ( "key_performance_indicators/middleware/grocerystore" "key_performance_indicators/middleware/snowflake" "key_performance_indicators/models/modelshr" + "key_performance_indicators/models/modelsschool" + "key_performance_indicators/models/modelsstorage" + "key_performance_indicators/models/modelssystempermission" "key_performance_indicators/overall" "math" "math/big" "reflect" "strconv" + "strings" "time" "github.com/mozillazg/go-pinyin" @@ -682,3 +686,72 @@ func ComputingTime(timeStamp int64, timeType int) (timeDataInt int64) { } 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 +}