zhengkun 3 years ago
parent
commit
c7489f62d9

+ 70 - 10
process_ medical/src/main.go

@@ -2,11 +2,69 @@ package main
 
 var (
 	sysconfig    		map[string]interface{} //配置文件
-	save_mgo        	*MongodbSim            //mongodb操作对象
+	save_mgo,qy_mgo,spi_mgo     *MongodbSim            //mongodb操作对象
     MysqlTool			*Mysql
 )
 
 func init()  {
+	//qy_mgo = &MongodbSim{
+	//	MongodbAddr: "172.17.145.163:27083,172.17.4.187:27082",
+	//	DbName:      "mixdata",
+	//	Size:        10,
+	//	UserName: "zhengkun",
+	//	Password: "zk@123123",
+	//}
+	//qy_mgo.InitPool()
+	//
+	//spi_mgo = &MongodbSim{
+	//	MongodbAddr: "172.17.4.181:27001",
+	//	DbName:      "mixdata",
+	//	Size:        10,
+	//	UserName: "",
+	//	Password: "",
+	//}
+	//spi_mgo.InitPool()
+	//
+	//save_mgo = &MongodbSim{
+	//	MongodbAddr: "172.17.4.87:27080",
+	//	DbName:      "py_spider",
+	//	Size:        10,
+	//	UserName: "",
+	//	Password: "",
+	//}
+	//save_mgo.InitPool()
+
+
+
+
+
+
+
+	//save_mgo = &MongodbSim{
+	//	MongodbAddr: "192.168.3.207:27092",
+	//	DbName:      "zhengkun",
+	//	Size:        10,
+	//	UserName: "",
+	//	Password: "",
+	//}
+	//save_mgo.InitPool()
+	//
+	//MysqlTool = &Mysql{
+	//	Address: "192.168.3.109:4000",
+	//	UserName: "jianyu",
+	//	PassWord: "top@123",
+	//	DBName: "jy_lycp",
+	//}
+	//MysqlTool.Init()
+
+	MysqlTool = &Mysql{
+		Address: "127.0.0.1:3306",
+		UserName: "root",
+		PassWord: "123456",
+		DBName: "zhengkun",
+	}
+	MysqlTool.Init()
+
 	save_mgo = &MongodbSim{
 		MongodbAddr: "127.0.0.1:27017",
 		DbName:      "mixdata",
@@ -15,19 +73,21 @@ func init()  {
 		Password: "",
 	}
 	save_mgo.InitPool()
+}
+
 
-	//MysqlTool = &Mysql{
-	//	Address: "192.168.3.109:4000",
-	//	UserName: "jianyu",
-	//	PassWord: "top@123",
-	//	DBName: "zktest",
-	//}
-	//MysqlTool.Init()
 
-}
 
 func main()  {
-	v_area()
+
+	//生产经营企业-信息
+	//companySaveMysql()
+
+	//企业许可备案信息
+	//forReference()
+
+	//v表
+	//v_area()
 	//v_ylqxclass()
 
 }

+ 175 - 0
process_ medical/src/medical_company.go

@@ -0,0 +1,175 @@
+package main
+
+import (
+	log "github.com/donnie4w/go-logger/logger"
+	qu "qfw/util"
+	"strings"
+)
+
+var fieldArr = []string{
+	"company_id",
+	"province_short",
+	"company_name",
+	"company_code",
+	"credit_no",
+	"org_code",
+	"tax_code",
+	"establish_date",
+	"legal_person",
+	"legal_person_caption",
+	"company_status",
+	"company_type",
+	"authority",
+	"issue_date",
+	"operation_startdate",
+	"operation_enddate",
+	"capital",
+	"company_address",
+	"business_scope",
+	"cancel_date",
+	"cancel_reason",
+	"revoke_date",
+	"revoke_reason",
+	"use_flag",
+	"create_time",
+	"update_time",
+	"legal_person_type",
+	"real_capital",
+	"en_name",
+	"list_code",
+}
+
+func companySaveMysql()  {
+	sess := save_mgo.GetMgoConn()
+	defer save_mgo.DestoryMongoConn(sess)
+	q,total:=map[string]interface{}{},0
+	it := sess.DB(save_mgo.DbName).C("zktest_mysql_company").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
+		if total%10000==0 {
+			log.Debug("curent index ",total)
+		}
+		delete(tmp,"_id")
+		MysqlTool.Insert("f_company",tmp)
+		tmp = make(map[string]interface{})
+	}
+
+	log.Debug("is over ",total)
+}
+
+
+//关联企业信息-升数据
+func dealWithCompanyData()  {
+	sess := save_mgo.GetMgoConn()
+	defer save_mgo.DestoryMongoConn(sess)
+	q,total:=map[string]interface{}{},0
+	isok:=0
+	it := sess.DB(save_mgo.DbName).C("zktest_nmpa_cpmpany").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
+		if total%10000==0 {
+			log.Debug("curent index ",total,isok)
+		}
+		company:= qu.ObjToString(tmp["name"])
+		type_str := qu.ObjToString(tmp["type"])
+		dataArr,_ :=spi_mgo.Find("company_base", map[string]interface{}{
+			"company_name":company,
+		},nil,nil)
+
+		for _,v := range dataArr {
+			isok++
+			data := updateData(v,type_str)
+			if len(data)>2 && data!=nil {
+				save_mgo.Save("111111111111111",data)
+			}
+		}
+		tmp = make(map[string]interface{})
+	}
+
+	log.Debug("is over ",total,isok)
+}
+
+
+func updateData(tmp map[string]interface{},type_str string) map[string]interface{} {
+	update := map[string]interface{}{}
+	for _,v := range fieldArr{
+		if tmp[v]!=nil {
+			update[v] = tmp[v]
+		}
+	}
+
+	company_id := qu.ObjToString(update["company_id"])
+	if company_id=="" {
+		return map[string]interface{}{}
+	}
+
+	qy_data := qy_mgo.FindByStrId("qyxy_std",company_id)
+	update["area"] = ""
+	update["city"] = ""
+	update["district"] = ""
+	if qy_data!=nil && len(qy_data)>2 {
+		update["area"] = qu.ObjToString(qy_data["company_area"])
+		update["city"] = qu.ObjToString(qy_data["company_city"])
+		update["district"] = qu.ObjToString(qy_data["company_district"])
+	}
+
+	if strings.Contains(type_str,"&") {
+		update["business_type"] = "3"
+	}else {
+		if strings.Contains(type_str,"生产") {
+			update["business_type"] = "1"
+		}else if strings.Contains(type_str,"经营") {
+			update["business_type"] = "2"
+		}else {
+			update["business_type"] = ""
+		}
+	}
+
+	return update
+}
+
+
+
+
+
+
+
+
+
+//已结束
+func exportCompany()  {
+	dict := map[string]string{}
+	sess := save_mgo.GetMgoConn()
+	defer save_mgo.DestoryMongoConn(sess)
+	q,total:=map[string]interface{}{},0
+	isok:=0
+	it := sess.DB(save_mgo.DbName).C("nmpa_company").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
+		if total%10000==0 {
+			log.Debug("curent index ",total,isok)
+		}
+		company:= qu.ObjToString(tmp["company"])
+		class := qu.ObjToString(tmp["class"])
+		if company!="" {
+			if dict[company]=="" {
+				isok++
+				dict[company] = class
+			}else {
+				pre_class := dict[company]
+				if pre_class!=class && !strings.Contains(pre_class,"&") {
+					dict[company] = pre_class+"&"+class
+				}
+			}
+		}
+		tmp = make(map[string]interface{})
+	}
+	log.Debug("is over ",total,isok)
+
+	for k,v := range dict {
+		save_mgo.Save("zktest_nmpa_cpmpany", map[string]interface{}{
+			"name":k,
+			"type":v,
+		})
+	}
+}
+
+
+

+ 96 - 0
process_ medical/src/medical_for_reference.go

@@ -0,0 +1,96 @@
+package main
+
+import (
+	log "github.com/donnie4w/go-logger/logger"
+	qu "qfw/util"
+	"regexp"
+	"strings"
+)
+
+var timeReg = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2})$`)
+//企业许可备案信息
+func forReference()  {
+	sess := save_mgo.GetMgoConn()
+	defer save_mgo.DestoryMongoConn(sess)
+	q,total:=map[string]interface{}{},0
+	ok1,ok2:=0,0
+	it := sess.DB(save_mgo.DbName).C("nmpa_company").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
+		if total%10000==0 {
+			log.Debug("curent index ",total,ok1,ok2)
+		}
+		class := qu.ObjToString(tmp["class"])
+		if class=="生产型"{
+			ok1++
+			//data := dealWithSCX(tmp)
+			//MysqlTool.Insert("f_production_register",data)
+		}else if class=="经营型" {
+			ok2++
+			data := dealWithJYX(tmp)
+			MysqlTool.Insert("f_business_register",data)
+		}else {
+
+		}
+
+		tmp = make(map[string]interface{})
+	}
+	log.Debug("is over ",total,ok1,ok2)
+}
+
+//处理生产型
+func dealWithSCX (tmp map[string]interface{}) map[string]interface{}{
+	data := map[string]interface{}{}
+	yxqx := qu.ObjToString(tmp["yxqx"])
+	barq := qu.ObjToString(tmp["barq"])
+	if yxqx!="" && timeReg.MatchString(yxqx) {
+		data["validitydate"] = yxqx
+	}
+	if barq!="" && timeReg.MatchString(barq){
+		data["approvedate"] = barq
+	}
+
+	data["regnum"] = qu.ObjToString(tmp["reg_no"])
+	type_str:=strings.ReplaceAll(qu.ObjToString(tmp["type"]),"企业","")
+	data["type"] = type_str
+	data["address"] = qu.ObjToString(tmp["product_address"])
+	data["scope"] = qu.ObjToString(tmp["product_range"])
+	data["approvedepart"] = qu.ObjToString(tmp["badw"])
+	data["companyname"] = qu.ObjToString(tmp["company"])
+	data["responsible_person"] = qu.ObjToString(tmp["responsible_persons"])
+	data["legal_person"] = qu.ObjToString(tmp["legal_person"])
+	data["residence"] = qu.ObjToString(tmp["address"])
+
+	return data
+}
+//处理经营型
+func dealWithJYX (tmp map[string]interface{}) map[string]interface{}{
+	data := map[string]interface{}{}
+	yxqx := qu.ObjToString(tmp["yxqx"])
+	barq := qu.ObjToString(tmp["barq"])
+	if yxqx!="" && timeReg.MatchString(yxqx) {
+		data["validitydate"] = yxqx
+	}
+	if barq!="" && timeReg.MatchString(barq){
+		data["approvedate"] = barq
+	}
+
+	data["regnum"] = qu.ObjToString(tmp["reg_no"])
+	type_str:=strings.ReplaceAll(qu.ObjToString(tmp["type"]),"企业","")
+	data["type"] = type_str
+	data["address"] = qu.ObjToString(tmp["business_address"])
+	data["scope"] = qu.ObjToString(tmp["business_range"])
+	data["business_type"] = qu.ObjToString(tmp["business_mode"])
+	data["approvedepart"] = qu.ObjToString(tmp["badw"])
+	data["websitename"] = ""
+	data["website"] = ""
+	data["platformname"] = ""
+	data["clientname"] = ""
+	data["storageroom"] = qu.ObjToString(tmp["storehouse_address"])
+	data["companyname"] = qu.ObjToString(tmp["company"])
+	data["responsible_person"] = qu.ObjToString(tmp["legal_person"])
+	data["legal_person"] = qu.ObjToString(tmp["responsible_persons"])
+	data["residence"] = qu.ObjToString(tmp["address"])
+
+	return data
+}
+

+ 23 - 7
process_ medical/src/medical_v.go → process_ medical/src/medical_vdata.go

@@ -1,5 +1,8 @@
 package main
 
+
+//v表处理
+
 import (
 	"fmt"
 	log "github.com/donnie4w/go-logger/logger"
@@ -9,8 +12,23 @@ import (
 	"strings"
 )
 
-func v_ylqxclass() {
 
+
+
+func v_ylqxclass() {
+	sess := save_mgo.GetMgoConn()
+	defer save_mgo.DestoryMongoConn(sess)
+	q,total:=map[string]interface{}{},0
+	it := sess.DB(save_mgo.DbName).C("mysql_ylqxclass").Sort("_id").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
+		if total%1000==0 {
+			log.Debug("curent index ",total)
+		}
+		delete(tmp,"_id")
+		MysqlTool.Insert("v_ylqxclass",tmp)
+		tmp = make(map[string]interface{})
+	}
+	log.Debug("is over ",total)
 }
 func v_area() {
 	sess := save_mgo.GetMgoConn()
@@ -22,9 +40,7 @@ func v_area() {
 			log.Debug("curent index ",total)
 		}
 		delete(tmp,"_id")
-
-
-
+		MysqlTool.Insert("v_area",tmp)
 		tmp = make(map[string]interface{})
 	}
 	log.Debug("is over ",total)
@@ -86,7 +102,6 @@ func citysClassification() {
 }
 
 
-
 //医疗分类-mgo
 func medicalClassification() {
 	ff,_ := xlsx.OpenFile("table.xlsx")
@@ -118,6 +133,7 @@ func medicalClassification() {
 			class_2,class_3,class_example := str[1],str[2],str[5]
 			class_2 = spaceReg.ReplaceAllString(class_2,"")
 			class_3 = spaceReg.ReplaceAllString(class_3,"")
+			new_class_2 := proReg.ReplaceAllString(class_2,"")
 			new_class_3 := proReg.ReplaceAllString(class_3,"")
 			sort_1 := qu.IntAll(str[0])
 			if sort_1 > sort { //1-4
@@ -127,7 +143,7 @@ func medicalClassification() {
 					"code":code_2,
 					"pcode":code_1,
 					"level":"2",
-					"name":class_2,
+					"name":new_class_2,
 				}
 				save_mgo.Save("mysql_ylqxclass",dict_2)
 				code_3 := code_2+proReg.FindString(class_3)
@@ -164,7 +180,7 @@ func medicalClassification() {
 						"code":code_3,
 						"pcode":code_2,
 						"level":"3",
-						"name":class_3,
+						"name":new_class_3,
 					}
 					save_mgo.Save("mysql_ylqxclass",dict_3)
 				}

+ 11 - 0
process_ medical/src/mgo.go

@@ -283,6 +283,17 @@ func (m *MongodbSim) FindById(c, id string) map[string]interface{} {
 	return v
 }
 
+//findbystrid
+func (m *MongodbSim) FindByStrId(c, id string) map[string]interface{} {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	r := coll.FindOne(m.Ctx, map[string]interface{}{"_id": id})
+	v := map[string]interface{}{}
+	r.Decode(&v)
+	return v
+}
+
 //findone
 func (m *MongodbSim) FindOne(c string, query map[string]interface{}) map[string]interface{} {
 	m.Open()

+ 1 - 2
process_ medical/src/mysql.go

@@ -31,7 +31,6 @@ func (m *Mysql) Init() {
 	}
 	var err error  //utf8mb4
 	m.DB, err = sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", m.UserName, m.PassWord, m.Address, m.DBName))
-	log.Println(fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", m.UserName, m.PassWord, m.Address, m.DBName))
 	if err != nil {
 		log.Println(err)
 		return
@@ -66,7 +65,7 @@ func (m *Mysql) InsertByTx(tx *sql.Tx, tableName string, data map[string]interfa
 		placeholders = append(placeholders, "?")
 	}
 	q := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", tableName, strings.Join(fields, ","), strings.Join(placeholders, ","))
-	log.Println("mysql", q, values)
+	//log.Println("mysql", q, values)
 	return m.InsertBySqlByTx(tx, q, values...)
 }