修改base go机构批量同步

master
zhangjun 5 years ago
parent a2e2377676
commit 2bede317ca

@ -12,13 +12,20 @@ pwd = dsideal
;pwd = DsideaL147258369 ;pwd = DsideaL147258369
[redis] [redis]
ip =server.dsmin.com ip = 127.0.0.1
port = 18890 port = 6379
db = 0 db = 1
expireTime = 86400 expireTime = 86400
;ip =server.dsmin.com
;port = 18890
;db = 0
;expireTime = 86400
[kafka] [kafka]
KafkaAddress = 192.168.0.200:9092 KafkaAddress = 127.0.0.1:9092
[elasticsearch] [elasticsearch]
nodes = http://10.10.14.61:9200,http://10.10.14.62:9200,http://10.10.14.63:9200 nodes = http://10.10.14.61:9200,http://10.10.14.62:9200,http://10.10.14.63:9200

@ -12,6 +12,7 @@ type TDataexError struct {
DataId string `json:"data_id" xorm:"not null comment('数据ID【输入参数】') VARCHAR(36)"` DataId string `json:"data_id" xorm:"not null comment('数据ID【输入参数】') VARCHAR(36)"`
DataContent string `json:"data_content" xorm:"default 'NULL' comment('数据内容【Json格式输入参数】') VARCHAR"` DataContent string `json:"data_content" xorm:"default 'NULL' comment('数据内容【Json格式输入参数】') VARCHAR"`
FileUri string `json:"file_uri" xorm:"default 'NULL' comment('文件地址【文件交换】') VARCHAR(500)"` FileUri string `json:"file_uri" xorm:"default 'NULL' comment('文件地址【文件交换】') VARCHAR(500)"`
ErrorInfo string `json:"error_info" xorm:"default 'NULL' comment('错误信息说明') VARCHAR(5000)"`
CreateTime time.Time `json:"create_time" xorm:"default 'NULL' created comment('建立时间') DATETIME"` CreateTime time.Time `json:"create_time" xorm:"default 'NULL' created comment('建立时间') DATETIME"`
ChangeTime time.Time `json:"change_time" xorm:"default 'NULL' updated comment('最近修改时间') DATETIME"` ChangeTime time.Time `json:"change_time" xorm:"default 'NULL' updated comment('最近修改时间') DATETIME"`
DeleteTime time.Time `json:"delete_time" xorm:"default 'NULL' deleted comment('删除时间') DATETIME"` DeleteTime time.Time `json:"delete_time" xorm:"default 'NULL' deleted comment('删除时间') DATETIME"`

@ -1,6 +1,7 @@
package DataexDAO package DataexDAO
import ( import (
"dsDataex/MyService/MySwagger"
"dsDataex/Utils/CacheUtil" "dsDataex/Utils/CacheUtil"
"dsDataex/Utils/DbUtil" "dsDataex/Utils/DbUtil"
"html" "html"
@ -93,6 +94,7 @@ func CheckDatasourceSet(systemID string,datasource string) (bool, string, map[st
return false, "数据源校验失败,接入系统无权操作此数据源", nil,nil return false, "数据源校验失败,接入系统无权操作此数据源", nil,nil
} }
} }
/** /**
* @Author zhangjun * @Author zhangjun
* @Description * @Description
@ -252,4 +254,11 @@ func CheckConsumeOrgID(consumeType int, consumeOrgid string,orgID string) (bool,
break break
} }
return false, "数据权限校验不通过,无权访问此机构下属数据", nil return false, "数据权限校验不通过,无权访问此机构下属数据", nil
}
func SaveDataError(fails []MySwagger.FailResult,esData string) (bool, string, error) {
return true, "数据添加成功", nil
} }

@ -47,13 +47,38 @@ func OrgtreeProc(datas []MySwagger.Data) {
} else { } else {
var areaCode string var areaCode string
if jsonData["area_code"].(string)[4:] != "00" { if jsonData["area_code"].(string)[2:] == "0000" {//省级
areaCode = jsonData["area_code"].(string)[0:4] + "00"
} else { areaCode="100000"
}else if jsonData["area_code"].(string)[4:] == "00" {//市级
areaCode = jsonData["area_code"].(string)[0:2] + "0000" areaCode = jsonData["area_code"].(string)[0:2] + "0000"
} } else { //县区级
areaCode = jsonData["area_code"].(string)[0:4] + "00"
//处理直辖市
if areaCode == "110100" {
areaCode = "110000" //北京
}
if areaCode == "120100" {
areaCode = "120000" //天津
}
if areaCode == "310100" {
areaCode = "310000" //上海
}
if areaCode == "500100" {
areaCode = "500000" //重庆
}
if areaCode == "500200" {
areaCode = "500000"
}
if areaCode == "371200" {
areaCode = "370100" //济南
}
data.ParentId = DataexDAO.GetParentIDBaseGO(areaCode) data.ParentId = DataexDAO.GetParentIDBaseGO(areaCode)
}
} }
break break
@ -137,6 +162,9 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
var sqls []string var sqls []string
var sql string var sql string
//补 parent_id
var sqls2 []string
var refresh = false
for no:=0;no< len(datas) ;no++{ for no:=0;no< len(datas) ;no++{
@ -182,32 +210,40 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
//处理直辖市 //处理直辖市
if areaCode=="110100"{ if areaCode=="110100"{
areaCode="110000" areaCode="110000"//北京
} }
if areaCode=="120100"{ if areaCode=="120100"{
areaCode="120000" areaCode="120000"//天津
} }
if areaCode=="310100"{ if areaCode=="310100"{
areaCode="310000" areaCode="310000"//上海
} }
if areaCode=="500100"{ if areaCode=="500100"{
areaCode="500000" areaCode="500000"//重庆
} }
if areaCode=="500200"{ if areaCode=="500200"{
areaCode="500000" areaCode="500000"
} }
if areaCode=="371200"{
areaCode="370100"//济南
}
} }
parentID = parentMap[areaCode] parentID = parentMap[areaCode]
if parentID==""{
parentID = DataexDAO.GetParentIDBaseGO(areaCode)
}
//处理教育部 //处理教育部
if jsonData["area_code"].(string)=="100000"{ if jsonData["area_code"].(string)=="100000"{
parentID="0" parentID="0"
} }
//delete by zhangjun 2020-07-17
//if parentID==""{
// parentID = DataexDAO.GetParentIDBaseGO(areaCode)
//}
if parentID==""{
sqls2=append(sqls2,"update t_dataex_orgtree set parent_id =(select id from t_dataex_orgtree where org_type=1 and area_id='" + areaCode + "') where id='"+IDs[no] +"'")
}
}else { }else {
parentID = parentMap[jsonData["area_code"].(string)] parentID = parentMap[jsonData["area_code"].(string)]
@ -216,8 +252,10 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
} }
} }
} }
//是否需要刷新 机构访问控制缓存
if Contains( CacheUtil.PARENT_IDS,parentID)>-1{
refresh=true
}
var provinceId = jsonData["province_code"].(string) var provinceId = jsonData["province_code"].(string)
@ -247,6 +285,15 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
} }
DbUtil.Engine.Sqls(sqls).Execute() DbUtil.Engine.Sqls(sqls).Execute()
if len(sqls2)>0{
DbUtil.Engine.Sqls(sqls2).Execute()
}
//缓存命中、缓存为空、parent_id未知 刷新缓存
if refresh || len(CacheUtil.PARENT_IDS)==0 || len(sqls2)>0{
CacheUtil.RefreshOrgtree()
}
} }
func Contains(array interface{}, val interface{}) (index int) { func Contains(array interface{}, val interface{}) (index int) {

@ -12,6 +12,8 @@ var GBT2260 map[string]string
var XXBXLXM map[string]string var XXBXLXM map[string]string
var PARENT_IDS []string
/** /**
* @Author zhangjun * @Author zhangjun
* @Description Redis * @Description Redis
@ -29,6 +31,8 @@ func OrgtreeCacheInit(){
list, count, _ := Page(sql, 1000,0) list, count, _ := Page(sql, 1000,0)
PARENT_IDS=make([]string,0)
if count>0{ if count>0{
for no:=0;no<int(count);no++{ for no:=0;no<int(count);no++{
//TODO:目前只支持教育局下属学校的数据访问控制,暂不支持其他机构类型(如:大学区、主校分校... //TODO:目前只支持教育局下属学校的数据访问控制,暂不支持其他机构类型(如:大学区、主校分校...
@ -40,6 +44,8 @@ func OrgtreeCacheInit(){
if count2>0{ if count2>0{
Orgtree2Redis(list2,"Dataex_Scope_"+list[no]["id"].(string)) 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)) OrgCacheCreate(list[no]["id"].(string),list[no]["id"].(string))
} }
} }
@ -115,6 +121,36 @@ func OrgtreeCacheInit(){
XXBXLXM["933"]="其他培训机构" 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 * @Author zhangjun
* @Description * @Description
@ -138,6 +174,8 @@ func OrgCacheCreate(orgID string,scope... string) {
if count2>0{ if count2>0{
Orgtree2Redis(list2,"Dataex_Scope_"+list[no]["id"].(string)) 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)) var newscope =append( scope ,list[no]["id"].(string))
for no:=0;no<len(scope);no++{ for no:=0;no<len(scope);no++{

@ -8,6 +8,7 @@ import (
garybudRedis "github.com/garyburd/redigo/redis" garybudRedis "github.com/garyburd/redigo/redis"
"github.com/go-redis/redis/v7" "github.com/go-redis/redis/v7"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"strconv"
"time" "time"
) )
@ -21,6 +22,7 @@ var (
func init() { func init() {
// 从配置文件获取redis的ip以及db // 从配置文件获取redis的ip以及db
var redisHost = ConfigUtil.RedisIp + ":" + ConfigUtil.RedisPort var redisHost = ConfigUtil.RedisIp + ":" + ConfigUtil.RedisPort
Pool = &garybudRedis.Pool{ Pool = &garybudRedis.Pool{
Dial: func() (garybudRedis.Conn, error) { Dial: func() (garybudRedis.Conn, error) {
conn, err := garybudRedis.Dial("tcp", redisHost) conn, err := garybudRedis.Dial("tcp", redisHost)
@ -30,11 +32,13 @@ func init() {
return conn, nil return conn, nil
}, },
} }
var db,_=strconv.Atoi(ConfigUtil.RedisDb)
//这个是以后项目中广泛使用的redis池 //这个是以后项目中广泛使用的redis池
RedisClient = redis.NewClient(&redis.Options{ RedisClient = redis.NewClient(&redis.Options{
Addr: redisHost, // Redis地址 Addr: redisHost, // Redis地址
Password: "", // Redis账号 Password: "", // Redis账号
DB: 1, // Redis库 //change by zhangjun 2020-06-15 DataEX DB: db, // Redis库 //change by zhangjun 2020-06-15 DataEX
PoolSize: 100, // Redis连接池大小 PoolSize: 100, // Redis连接池大小
MaxRetries: 3, // 最大重试次数 MaxRetries: 3, // 最大重试次数
IdleTimeout: 10 * time.Second, // 空闲链接超时时间 IdleTimeout: 10 * time.Second, // 空闲链接超时时间

Loading…
Cancel
Save