|
@@ -12,20 +12,25 @@ import (
|
|
|
|
|
|
var hossqllock sync.Mutex
|
|
|
|
|
|
-//医院基本信息
|
|
|
-func exportHospitalInfoToMysql() {
|
|
|
+//医院基本信息~相关~生成sql数据
|
|
|
+func ExportHospitalInfoToMysql() {
|
|
|
log.Debug("生成sql数据~医院信息~")
|
|
|
sess := class.Save_Mgo.GetMgoConn()
|
|
|
defer class.Save_Mgo.DestoryMongoConn(sess)
|
|
|
q := map[string]interface{}{}
|
|
|
- it := sess.DB(class.Save_Mgo.DbName).C("zktest_hospital_info_new").Find(&q).Sort("_id").Iter()
|
|
|
+ it := sess.DB(class.Save_Mgo.DbName).C(merge_coll).Find(&q).Sort("_id").Iter()
|
|
|
pool := make(chan bool, 1)
|
|
|
wg := &sync.WaitGroup{}
|
|
|
total, isok := 0, 0
|
|
|
for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
- if total%10000 == 0 {
|
|
|
- log.Debug("cur index ", total)
|
|
|
+ if total%1000 == 0 {
|
|
|
+ log.Debug("cur index ", total, "~", isok)
|
|
|
}
|
|
|
+ if qu.IntAll(tmp["mark_id"]) == 0 {
|
|
|
+ tmp = make(map[string]interface{})
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ isok++
|
|
|
pool <- true
|
|
|
wg.Add(1)
|
|
|
go func(tmp map[string]interface{}) {
|
|
@@ -33,123 +38,163 @@ func exportHospitalInfoToMysql() {
|
|
|
<-pool
|
|
|
wg.Done()
|
|
|
}()
|
|
|
-
|
|
|
- data := tmp
|
|
|
- //线上版~可以直接查询表
|
|
|
-
|
|
|
- //等级~性质~代码
|
|
|
- //n_level, n_type, n_bus_type := clenaHospitalLevelType(qu.ObjToString(tmp["level"]), qu.ObjToString(tmp["type"]), qu.ObjToString(tmp["business_type"]))
|
|
|
- //data["level_code"] = n_level
|
|
|
- //data["mi_type_code"] = n_type
|
|
|
- //data["mi_business_type"] = qu.IntAll(n_bus_type)
|
|
|
-
|
|
|
- //行政区划代码~匹配
|
|
|
- region_code := regionallyCode(qu.ObjToString(tmp["area"]), qu.ObjToString(tmp["city"]), qu.ObjToString(tmp["district"]))
|
|
|
- data["areacode"] = region_code
|
|
|
-
|
|
|
- //时间相关
|
|
|
- data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeTmeplate)
|
|
|
- data["updatetime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeTmeplate)
|
|
|
+ //医院基本信息~类型标签
|
|
|
+ new_level := createBaseInfo(tmp)
|
|
|
+ //别名信息
|
|
|
+ createAliasInfo(tmp)
|
|
|
+ //科室信息~科室标签
|
|
|
+ createDepartsInfo(tmp, new_level)
|
|
|
|
|
|
}(tmp)
|
|
|
tmp = make(map[string]interface{})
|
|
|
}
|
|
|
wg.Wait()
|
|
|
+
|
|
|
log.Debug("is cur over ", total, "~", isok)
|
|
|
|
|
|
}
|
|
|
|
|
|
-//医院别名信息
|
|
|
-func exportHospitalAliasToMysql() {
|
|
|
- log.Debug("生成sql数据~医院信息~")
|
|
|
- sess := class.Save_Mgo.GetMgoConn()
|
|
|
- defer class.Save_Mgo.DestoryMongoConn(sess)
|
|
|
- q := map[string]interface{}{}
|
|
|
- it := sess.DB(class.Save_Mgo.DbName).C("zktest_hospital_info_new").Find(&q).Sort("_id").Iter()
|
|
|
- pool := make(chan bool, 1)
|
|
|
- wg := &sync.WaitGroup{}
|
|
|
- total, isok := 0, 0
|
|
|
- for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
- if total%10000 == 0 {
|
|
|
- log.Debug("cur index ", total)
|
|
|
- }
|
|
|
- pool <- true
|
|
|
- wg.Add(1)
|
|
|
- go func(tmp map[string]interface{}) {
|
|
|
- defer func() {
|
|
|
- <-pool
|
|
|
- wg.Done()
|
|
|
- }()
|
|
|
+//基础信息
|
|
|
+func createBaseInfo(tmp map[string]interface{}) string {
|
|
|
+ data_info := map[string]interface{}{}
|
|
|
+ name := qu.ObjToString(tmp["name"])
|
|
|
+ data_info["company_id"] = qu.ObjToString(tmp["company_id"])
|
|
|
+ data_info["mi_name"] = name
|
|
|
+ data_info["introduce"] = qu.ObjToString(tmp["introduce"])
|
|
|
+ //代码标准化
|
|
|
+ new_level, new_type, new_bustype := codificationOfInfo(qu.ObjToString(tmp["level"]), qu.ObjToString(tmp["type"]), qu.ObjToString(tmp["business_type"]))
|
|
|
+ data_info["level_code"] = new_level
|
|
|
+ data_info["mi_type_code"] = new_type
|
|
|
+ data_info["business_type"] = new_bustype
|
|
|
+ data_info["address"] = qu.ObjToString(tmp["address"])
|
|
|
+ data_info["equipment"] = qu.ObjToString(tmp["equipment"])
|
|
|
+ beds := qu.IntAll(tmp["beds"])
|
|
|
+ visit_perday := qu.IntAll(tmp["visit_perday"])
|
|
|
+ doctorsnum := qu.IntAll(tmp["doctorsnum"])
|
|
|
+ if beds > 0 {
|
|
|
+ data_info["beds"] = beds
|
|
|
+ }
|
|
|
+ if visit_perday > 0 {
|
|
|
+ data_info["visit_perday"] = visit_perday
|
|
|
+ }
|
|
|
+ if doctorsnum > 0 {
|
|
|
+ data_info["doctorsnum"] = doctorsnum
|
|
|
+ }
|
|
|
+ data_info["tel"] = qu.ObjToString(tmp["tel"])
|
|
|
+ data_info["fax_number"] = qu.ObjToString(tmp["fax_number"])
|
|
|
+ data_info["website"] = qu.ObjToString(tmp["website"])
|
|
|
+ //地域代码
|
|
|
+ area_code := regionallyCode(qu.ObjToString(tmp["area"]), qu.ObjToString(tmp["city"]), qu.ObjToString(tmp["district"]))
|
|
|
+ data_info["area_code"] = area_code
|
|
|
+ data_info["sourceweb"] = qu.ObjToString(tmp["sourceweb"])
|
|
|
+ data_info["pcompany_id"] = qu.ObjToString(tmp["pcompany_id"])
|
|
|
+ data_info["mark_id"] = qu.IntAll(tmp["mark_id"])
|
|
|
+ data_info["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ data_info["updatetime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ //插入sql medical_institution_info
|
|
|
+ class.InsertMysqlData("medical_institution_info", data_info, name)
|
|
|
+
|
|
|
+ //类型标签
|
|
|
+ data_tag := map[string]interface{}{}
|
|
|
+ data_tag["company_id"] = qu.ObjToString(tmp["company_id"])
|
|
|
+ data_tag["labelcode"] = new_type
|
|
|
+ data_tag["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ //插入sql medical_institution_typetags
|
|
|
+ class.InsertMysqlData("medical_institution_typetags", data_tag, name)
|
|
|
+
|
|
|
+ return new_level
|
|
|
+}
|
|
|
|
|
|
- data := map[string]interface{}{}
|
|
|
- name := qu.ObjToString(tmp["name"])
|
|
|
- alias := qu.ObjToString(tmp["alias"])
|
|
|
- aliasArr := strings.Split(alias, ",")
|
|
|
- //查询关联id~
|
|
|
- for _, v := range aliasArr {
|
|
|
- if v == "" || v == name {
|
|
|
- continue
|
|
|
- }
|
|
|
- data["company_id"] = qu.ObjToString(tmp["_id"])
|
|
|
- data["alias"] = v
|
|
|
- data["sourcetype"] = "2"
|
|
|
- data["company_id"] = qu.ObjToString(tmp["_id"])
|
|
|
- data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeTmeplate)
|
|
|
- }
|
|
|
+//别名信息
|
|
|
+func createAliasInfo(tmp map[string]interface{}) {
|
|
|
+ name := qu.ObjToString(tmp["name"])
|
|
|
+ alias := qu.ObjToString(tmp["alias"])
|
|
|
+ aliasArr := strings.Split(alias, ",")
|
|
|
+ data := map[string]interface{}{}
|
|
|
+ for _, v := range aliasArr {
|
|
|
+ if v == "" || v == name {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ data["company_id"] = qu.ObjToString(tmp["company_id"])
|
|
|
+ data["alias"] = v
|
|
|
+ data["alias_type"] = 2
|
|
|
+ data["source_type"] = 2
|
|
|
+ data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ //插入~sql medical_institution_alias
|
|
|
+ class.InsertMysqlData("medical_institution_alias", data, name)
|
|
|
|
|
|
- }(tmp)
|
|
|
- tmp = make(map[string]interface{})
|
|
|
}
|
|
|
- wg.Wait()
|
|
|
- log.Debug("is cur over ", total, "~", isok)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-//医院科室信息
|
|
|
-func exportHospitalDepartsToMysql() {
|
|
|
- log.Debug("生成sql数据~医院信息~")
|
|
|
- sess := class.Save_Mgo.GetMgoConn()
|
|
|
- defer class.Save_Mgo.DestoryMongoConn(sess)
|
|
|
- q := map[string]interface{}{}
|
|
|
- it := sess.DB(class.Save_Mgo.DbName).C("zktest_hospital_info_new").Find(&q).Sort("_id").Iter()
|
|
|
- pool := make(chan bool, 1)
|
|
|
- wg := &sync.WaitGroup{}
|
|
|
- total, isok := 0, 0
|
|
|
- for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
|
|
|
- if total%10000 == 0 {
|
|
|
- log.Debug("cur index ", total)
|
|
|
+//科室信息
|
|
|
+func createDepartsInfo(tmp map[string]interface{}, level string) {
|
|
|
+ name := qu.ObjToString(tmp["name"])
|
|
|
+ departsArr := []map[string]interface{}{}
|
|
|
+ if arr, ok := tmp["departs"].([]interface{}); ok {
|
|
|
+ departsArr = qu.ObjArrToMapArr(arr)
|
|
|
+ }
|
|
|
+ if arr, ok := tmp["departs"].(primitive.A); ok {
|
|
|
+ departsArr = qu.ObjArrToMapArr(arr)
|
|
|
+ }
|
|
|
+ for _, v := range departsArr {
|
|
|
+ depart_code := qu.ObjToString(v["depart_code"])
|
|
|
+ if depart_code == "" {
|
|
|
+ continue
|
|
|
}
|
|
|
- pool <- true
|
|
|
- wg.Add(1)
|
|
|
- go func(tmp map[string]interface{}) {
|
|
|
- defer func() {
|
|
|
- <-pool
|
|
|
- wg.Done()
|
|
|
- }()
|
|
|
- departsArr := []map[string]interface{}{}
|
|
|
- if arr, ok := tmp["departs"].([]interface{}); ok {
|
|
|
- departsArr = qu.ObjArrToMapArr(arr)
|
|
|
- }
|
|
|
- if arr, ok := tmp["departs"].(primitive.A); ok {
|
|
|
- departsArr = qu.ObjArrToMapArr(arr)
|
|
|
- }
|
|
|
-
|
|
|
- for _, v := range departsArr {
|
|
|
- data := map[string]interface{}{}
|
|
|
- data["company_id"] = qu.ObjToString(tmp["company_id"])
|
|
|
- data["departname_class1"] = qu.ObjToString(v["departclass1"])
|
|
|
- data["departname_class2"] = qu.ObjToString(v["departclass2"])
|
|
|
- data["introduce"] = qu.ObjToString(v["depart_introduce"])
|
|
|
- data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeTmeplate)
|
|
|
- data["updatetime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeTmeplate)
|
|
|
- departname_code := confirmDepartCode
|
|
|
- data["departname_code"] = departname_code
|
|
|
- }
|
|
|
+ data := map[string]interface{}{}
|
|
|
+ data["company_id"] = qu.ObjToString(tmp["company_id"])
|
|
|
+
|
|
|
+ data["departname_code"] = depart_code
|
|
|
+ //equipment_code 设备代码~需要构建
|
|
|
+ equipment_code := level + depart_code
|
|
|
+ data["equipment_code"] = equipment_code
|
|
|
+
|
|
|
+ data["departname_class1"] = qu.ObjToString(v["departclass1"])
|
|
|
+ data["departname_class2"] = qu.ObjToString(v["departclass2"])
|
|
|
+ data["introduce"] = qu.ObjToString(v["depart_introduce"])
|
|
|
+ data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ data["updatetime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ //插入~sql medical_institution_department
|
|
|
+ class.InsertMysqlData("medical_institution_department", data, name)
|
|
|
+
|
|
|
+ data_tag := map[string]interface{}{}
|
|
|
+ data_tag["company_id"] = qu.ObjToString(tmp["company_id"])
|
|
|
+ data_tag["labelcode"] = depart_code
|
|
|
+ data_tag["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
|
|
|
+ //插入~sql medical_institution_departtags
|
|
|
+ class.InsertMysqlData("medical_institution_departtags", data_tag, name)
|
|
|
|
|
|
- }(tmp)
|
|
|
- tmp = make(map[string]interface{})
|
|
|
}
|
|
|
- wg.Wait()
|
|
|
- log.Debug("is cur over ", total, "~", isok)
|
|
|
+}
|
|
|
|
|
|
+//等级,类型,性质代码化
|
|
|
+func codificationOfInfo(med_level string, med_type string, med_bustype string) (string, string, int) {
|
|
|
+ new_level := class.Medical_Level[med_level]
|
|
|
+ new_type := class.Medical_Type[med_type]
|
|
|
+ new_bustype := class.Medical_BusType[med_bustype]
|
|
|
+ return new_level, new_type, new_bustype
|
|
|
+}
|
|
|
+
|
|
|
+//区域代码
|
|
|
+func regionallyCode(area string, city string, district string) string {
|
|
|
+ region_code := "000000"
|
|
|
+ if area == "全国" || area == "" {
|
|
|
+ return region_code
|
|
|
+ }
|
|
|
+ if class.AreaCode[area] != "" {
|
|
|
+ region_code = class.AreaCode[area]
|
|
|
+ }
|
|
|
+ if city != "" {
|
|
|
+ key := area + "~" + city
|
|
|
+ if class.CityCode[key] != "" {
|
|
|
+ region_code = class.CityCode[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if district != "" {
|
|
|
+ key := area + "~" + city + "~" + district
|
|
|
+ if class.DistrictCode[key] != "" {
|
|
|
+ region_code = class.DistrictCode[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return region_code
|
|
|
}
|