You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
7.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package CacheUtil
import (
"dsDataex/Utils/ErrorConst"
"dsDataex/Utils/LogUtil"
"dsDataex/Utils/RedisUtil"
"strings"
"time"
)
var GBT2260 map[string]string
var XXBXLXM map[string]string
var PARENT_IDS []string
/**
* @Author zhangjun
* @Description 组织机构树缓存初始化,【机构下属学校】递归查询、并缓存 Redis
* @Description TODO如果性能还不行使用全局静态变量存储【机构下属学校】
* @Date 2020-06-16 10:06
* @Param
* @return
**/
func OrgtreeCacheInit(){
//删除Redis缓存
RedisUtil.RedisClient.FlushDB()
//机构树缓存
sql := "SELECT id from t_dataex_orgtree where delete_flag = -1 and enable_flag = 1 and parent_id = '-1'"
list, count, _ := Page(sql, 1000,0)
PARENT_IDS=make([]string,0)
if count>0{
for no:=0;no<int(count);no++{
//TODO:目前只支持教育局下属学校的数据访问控制,暂不支持其他机构类型(如:大学区、主校分校...
if list[no]["org_type"].(string)=="1"{
sql = "SELECT id from t_dataex_orgtree where delete_flag = -1 and enable_flag = 1 and parent_id = '"+list[no]["id"].(string)+"'"
list2, count2, _ := Page(sql, 1000,0)
if count2>0{
Orgtree2Redis(list2,"Dataex_Scope_"+list[no]["id"].(string))
PARENT_IDS =append(PARENT_IDS,list[no]["id"].(string))
OrgCacheCreate(list[no]["id"].(string),list[no]["id"].(string))
}
}
}
}
//行政区划缓存
sql = "SELECT area_code from t_dataex_gbt2260"
list,_,_= Page(sql, 5000,0)
GBT2260=make( map[string]string)
for no:=0;no< len(list);no++{
GBT2260[list[no]["area_code"].(string)]=list[no]["area_name"].(string)
}
XXBXLXM=make( map[string]string)
XXBXLXM["111"]="幼儿园"
XXBXLXM["119"]="附设幼儿班"
XXBXLXM["211"]="小学"
XXBXLXM["218"]="小学教学点"
XXBXLXM["219"]="附设小学班"
XXBXLXM["221"]="职工小学"
XXBXLXM["222"]="农民小学"
XXBXLXM["228"]="小学班"
XXBXLXM["229"]="扫盲班"
XXBXLXM["311"]="初级中学"
XXBXLXM["312"]="九年一贯制学校"
XXBXLXM["319"]="附设普通初中班"
XXBXLXM["321"]="职业初中"
XXBXLXM["329"]="附设职业初中班"
XXBXLXM["331"]="成人职工初中"
XXBXLXM["332"]="成人农民初中"
XXBXLXM["341"]="完全中学"
XXBXLXM["342"]="高级中学"
XXBXLXM["345"]="十二年一贯制学校"
XXBXLXM["349"]="附设普通高中班"
XXBXLXM["351"]="成人职工高中"
XXBXLXM["352"]="成人农民高中"
XXBXLXM["361"]="中等职业学校"
XXBXLXM["362"]="中等技术学校"
XXBXLXM["363"]="中等师范学校"
XXBXLXM["364"]="成人中等专业学校"
XXBXLXM["365"]="职业高中学校"
XXBXLXM["366"]="技工学校"
XXBXLXM["368"]="附设中职班"
XXBXLXM["369"]="其他机构"
XXBXLXM["371"]="工读学校"
XXBXLXM["411"]="大学"
XXBXLXM["412"]="学院"
XXBXLXM["413"]="独立学院"
XXBXLXM["414"]="高等专科学校"
XXBXLXM["415"]="高等职业学校"
XXBXLXM["419"]="分校、大专班"
XXBXLXM["421"]="职工高校"
XXBXLXM["422"]="农民高校"
XXBXLXM["423"]="管理干部学院"
XXBXLXM["424"]="教育学院"
XXBXLXM["425"]="独立函授学院"
XXBXLXM["426"]="广播电视大学"
XXBXLXM["429"]="其他成人高等教育机构"
XXBXLXM["511"]="盲人学校"
XXBXLXM["512"]="聋人学校"
XXBXLXM["513"]="弱智学校"
XXBXLXM["514"]="特殊教育学校"
XXBXLXM["519"]="附设特教班"
XXBXLXM["911"]="培养研究生的科研机构"
XXBXLXM["921"]="民办的其他高等教育机构"
XXBXLXM["931"]="职工技术培训学校"
XXBXLXM["932"]="农村成人文化技术培训学校"
XXBXLXM["933"]="其他培训机构"
}
func RefreshOrgtree(){
//删除Redis缓存
RedisUtil.RedisClient.FlushDB()
//机构树缓存
sql := "SELECT id from t_dataex_orgtree where delete_flag = -1 and enable_flag = 1 and parent_id = '-1'"
list, count, _ := Page(sql, 1000,0)
if count>0{
for no:=0;no<int(count);no++{
//TODO:目前只支持教育局下属学校的数据访问控制,暂不支持其他机构类型(如:大学区、主校分校...
if list[no]["org_type"].(string)=="1"{
sql = "SELECT id from t_dataex_orgtree where delete_flag = -1 and enable_flag = 1 and parent_id = '"+list[no]["id"].(string)+"'"
list2, count2, _ := Page(sql, 1000,0)
if count2>0{
Orgtree2Redis(list2,"Dataex_Scope_"+list[no]["id"].(string))
PARENT_IDS =append(PARENT_IDS,list[no]["id"].(string))
OrgCacheCreate(list[no]["id"].(string),list[no]["id"].(string))
}
}
}
}
}
/**
* @Author zhangjun
* @Description 刷新机构下属学校缓存
* @Date 2020-06-16 10:14
* @Param orgID string 教育局机构ID
* @return
**/
func OrgCacheCreate(orgID string,scope... string) {
sql := "SELECT id from t_dataex_orgtree where delete_flag = -1 and enable_flag = 1 and parent_id = '" + orgID + "'"
list, count, _ := Page(sql, 1000,0)
if count>0{
for no:=0;no<int(count);no++{
//TODO:目前只支持教育局下属学校的数据访问控制,暂不支持其他机构类型(如:大学区、主校分校...
if list[no]["org_type"].(string)=="1"{
sql = "SELECT id from t_dataex_orgtree where delete_flag = -1 and enable_flag = 1 and parent_id = '"+list[no]["id"].(string)+"'"
list2, count2, _ := Page(sql, 1000,0)
if count2>0{
Orgtree2Redis(list2,"Dataex_Scope_"+list[no]["id"].(string))
PARENT_IDS =append(PARENT_IDS,list[no]["id"].(string))
var newscope =append( scope ,list[no]["id"].(string))
for no:=0;no<len(scope);no++{
Orgtree2Redis(list2,"Dataex_Scope_"+scope[no])
}
OrgCacheCreate(list[no]["id"].(string),newscope...)
}
}
}
}
}
/**
* @Author zhangjun
* @Description
* @Date 2020-06-16 10:49
* @Param list 【】map 机构范围数据【】数组
* @Param cacheName string 缓存名称
* @return
**/
func Orgtree2Redis(list []map[string]interface{}, cacheName string) {
var ids string
for i := 0; i < len(list); i++ {
bean := list[i]
ids=ids+"##"+bean["id"].(string)
}
RedisUtil.RedisClient.Set(cacheName, ids,10*time.Hour)
}
func Orgtree2Redis2(list []map[string]interface{}, cacheName string) {
//声明管道
pipe := RedisUtil.RedisClient.Pipeline()
for i := 0; i < len(list); i++ {
bean := list[i]
key := cacheName + ":" + bean["id"].(string)
pipe.HSet(key, bean)
pipe.Expire(key, 24*time.Hour)
}
_, err := pipe.Exec()
if err != nil {
LogUtil.Error(ErrorConst.SqlQueryError, err.Error())
}
}
/**
* @Author zhangjun
* @Description
* @Date 2020-06-16 11:21
* @Param
* @return
**/
func OrgtreeCheckScope(provideID string,orgID string)bool{
result,err:= RedisUtil.RedisClient.Get("Dataex_Scope_"+provideID).Result()
if err == nil{
if strings.Contains(result,orgID){
return true
}else {
return false
}
}
return false
}
func OrgtreeCheckScope2(provideID string,orgID string)bool{
count,_:= RedisUtil.RedisClient.Exists("Dataex_Scope_"+provideID+":"+orgID).Result()
if count>0{
return true
}
return false
}
func OrgtreeGetScope(orgId string) []string {
result,_:= RedisUtil.RedisClient.Get("Dataex_Scope_"+orgId).Result()
if result != ""{
return strings.Split(result,"##")
}
return nil
}