@ -12,6 +12,7 @@ import (
"reflect"
"strconv"
"strings"
"time"
)
func OrgtreeProc ( datas [ ] MySwagger . Data ) {
@ -118,7 +119,9 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
IDs = append ( IDs , strings . ToLower ( jsonData [ "org_id" ] . ( string ) ) )
areaIDs = append ( areaIDs , strings . ToLower ( jsonData [ "area_code" ] . ( string ) ) )
if Contains ( areaIDs , jsonData [ "area_code" ] . ( string ) ) == - 1 {
areaIDs = append ( areaIDs , jsonData [ "area_code" ] . ( string ) )
}
}
result := CacheUtil . GetListByIds ( IDs , CacheUtil . GetBean ( "t_dataex_orgtree" ) )
@ -129,10 +132,13 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
updateIDs = append ( updateIDs , result [ no ] [ "id" ] . ( string ) )
}
var parentMap map [ string ] string
parentMap = DataexDAO . GetParentID2BaseGO ( areaIDs )
var sqls [ ] string
var sql string
for no := 0 ; no < len ( datas ) && no < 1000 ; no ++ {
for no := 0 ; no < len ( datas ) ; no ++ {
var jsonData map [ string ] interface { }
json . Unmarshal ( [ ] byte ( datas [ no ] . Data ) , & jsonData )
@ -150,6 +156,10 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
break
}
if orgType != "1" && orgType != "2" && orgType != "7" {
continue
}
if orgType == "2" {
schoolType = jsonData [ "xxbxlxm" ] . ( string )
}
@ -160,23 +170,77 @@ func OrgtreeProcBatch(datas []MySwagger.Data) {
if orgType == "1" {
var areaCode string
if jsonData [ "area_code" ] . ( string ) [ 4 : ] != "00" {
areaCode = jsonData [ "area_code" ] . ( string ) [ 0 : 4 ] + "00"
} else {
if jsonData [ "area_code" ] . ( string ) [ 2 : ] == "0000" { //省级
areaCode = "100000"
} else if jsonData [ "area_code" ] . ( string ) [ 4 : ] == "00" { //市级
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"
}
}
parentID = parentMap [ areaCode ]
if parentID == "" {
parentID = DataexDAO . GetParentIDBaseGO ( areaCode )
}
//处理教育部
if jsonData [ "area_code" ] . ( string ) == "100000" {
parentID = "0"
}
} else {
parentID = parentMap [ jsonData [ "area_code" ] . ( string ) ]
if parentID == "" {
parentID = DataexDAO . GetParentIDBaseGO ( jsonData [ "area_code" ] . ( string ) )
}
}
}
var provinceId = jsonData [ "province_code" ] . ( string )
var cityId = ""
if jsonData [ "city_code" ] . ( string ) == "" || jsonData [ "city_code" ] . ( string ) == "-1" {
cityId = jsonData [ "province_code" ] . ( string )
} else {
cityId = jsonData [ "city_code" ] . ( string )
}
var areaId = ""
if jsonData [ "district_code" ] . ( string ) == "" || jsonData [ "district_code" ] . ( string ) == "-1" {
areaId = cityId
} else {
areaId = jsonData [ "district_code" ] . ( string )
}
if Contains ( updateIDs , IDs [ no ] ) > - 1 {
sql = "update t_dataex_orgtree set org_name = '" + jsonData [ "org_name" ] . ( string ) + "',org_type=" + orgType + ",school_type='" + schoolType + "',parent_id ='" + parentID + "' where id='" + IDs [ no ] + "'"
sql = "update t_dataex_orgtree set org_name = '" + jsonData [ "org_name" ] . ( string ) + "',org_type=" + orgType + ",school_type='" + schoolType + "',parent_id ='" + parentID + "' ,province_id='"+ provinceId + "',city_id='" + cityId + "',area_id='" + areaId + "',change_time='" + time . Now ( ) . Format ( "2006-01-02 15:04:05" ) + "' where id='" + IDs [ no ] + "'"
} else {
sql = "insert into t_dataex_orgtree (id,org_name,org_type,school_type,parent_id,province_id,city_id,area_id,create_time,delete_flag,enable_flag) values ('" + jsonData [ "org_id" ] . ( string ) + "','" + jsonData [ "org_name" ] . ( string ) + "'," + orgType + ",'" + schoolType + "','" + parentID + "','" + provinceId + "','" + cityId + "','" + areaId + "','" + time . Now ( ) . Format ( "2006-01-02 15:04:05" ) + "',-1,1)"
}
sqls = append ( sqls , sql )