zhengkun 1 éve
szülő
commit
7935273662
4 módosított fájl, 133 hozzáadás és 101 törlés
  1. 9 12
      ent_contact/contact_full.go
  2. 34 0
      ent_util/code.go
  3. 75 86
      ent_util/global.go
  4. 15 3
      main.go

+ 9 - 12
ent_contact/contact_full.go

@@ -48,7 +48,6 @@ L:
 // from 凭安库
 func InjectContactPingAnInfo(uid string, qyxy_info map[string]interface{}) {
 	//企业信息...
-	qy_id := qu.ObjToString(qyxy_info["_id"])
 	qy_name := qu.ObjToString(qyxy_info["legal_person"])
 	qy_phone := qu.ObjToString(qyxy_info["company_phone"])
 	qy_email := qu.ObjToString(qyxy_info["company_email"])
@@ -60,18 +59,20 @@ func InjectContactPingAnInfo(uid string, qyxy_info map[string]interface{}) {
 			"email": qy_email,
 		})
 	}
-	GetAnnualInfo(qy_id, qy_name, &cts)
+	annual_reports := ul.IsMarkInterfaceMap(qyxy_info["annual_reports"])
+	GetAnnualInfo(annual_reports, qy_name, &cts)
 	if len(cts) > 0 {
 		msgs := GetEntContacts(uid)
 		for _, v := range cts {
 			c_name := qu.ObjToString(v["name"])
 			c_phone := qu.ObjToString(v["phone"])
 			c_email := qu.ObjToString(v["email"])
-			createtime := time.Now().Format(ul.TimeLayout_New)
+			c_source_type := 2
+			createtime := time.Now().Unix()
 			if !QueryingExists(msgs, c_name, c_phone) {
 				query := "INSERT INTO information.ent_contact(id,phone,name,email,source_type,create_time,update_time) VALUES(?,?,?,?,?,?,?)"
 				//插入数据
-				err := ul.ClickHouseConn.Exec(context.Background(), query, uid, c_phone, c_name, c_email, 2, createtime, createtime)
+				err := ul.ClickHouseConn.Exec(context.Background(), query, uid, c_phone, c_name, c_email, c_source_type, createtime, createtime)
 				if err != nil {
 					log.Debug(err)
 				}
@@ -138,17 +139,13 @@ type Msg struct {
 }
 
 // 创建年报字段~与现有的通讯录
-func GetAnnualInfo(company_id string, legal_person string, contact_arr *[]map[string]interface{}) {
+func GetAnnualInfo(annual_reports []map[string]interface{}, legal_person string, cts *[]map[string]interface{}) {
 	keys := map[string]string{}
-	for _, v := range *contact_arr {
+	for _, v := range *cts {
 		key := qu.ObjToString(v["name"]) + "~" + qu.ObjToString(v["phone"])
 		keys[key] = key
 	}
-	dataArr, _ := ul.SpiMgo.Find("annual_report_base", map[string]interface{}{"company_id": company_id}, nil, map[string]interface{}{
-		"company_phone": 1,
-		"company_email": 1,
-	})
-	for _, v := range dataArr {
+	for _, v := range annual_reports {
 		company_phone := qu.ObjToString(v["company_phone"])
 		company_email := qu.ObjToString(v["company_email"])
 		if company_phone != "" {
@@ -159,7 +156,7 @@ func GetAnnualInfo(company_id string, legal_person string, contact_arr *[]map[st
 					"phone": company_phone,
 					"email": company_email,
 				}
-				(*contact_arr) = append((*contact_arr), dict)
+				*cts = append(*cts, dict)
 				keys[key] = key
 			}
 		}

+ 34 - 0
ent_util/code.go

@@ -0,0 +1,34 @@
+package ent_util
+
+// 处理地域代码
+func CalculateRegionCode(area string, city string, district string) (area_code string, city_code string, district_code string) {
+	area_code, city_code, district_code = "000000", "", ""
+	if district != "" {
+		key := area + "~" + city + "~" + district + "~"
+		code := RegionCodeData[key]
+		if code != "" {
+			district_code = code
+			city_code = code[:4] + "00"
+			area_code = code[:2] + "0000"
+			return
+		}
+	}
+	if city != "" {
+		key := area + "~" + city + "~" + "" + "~"
+		code := RegionCodeData[key]
+		if code != "" {
+			city_code = code
+			area_code = city_code[:2] + "0000"
+			return
+		}
+	}
+	if area != "" {
+		key := area + "~" + "" + "~" + "" + "~"
+		code := RegionCodeData[key]
+		if code != "" {
+			area_code = code
+			return
+		}
+	}
+	return
+}

+ 75 - 86
ent_util/info.go → ent_util/global.go

@@ -10,51 +10,6 @@ import (
 	"unicode/utf8"
 )
 
-type Info struct {
-	Contact map[string]*Contact
-}
-type Contact struct {
-	Per    string
-	Tel    string
-	Buyer  bool
-	Agency bool
-	Winner bool
-	Owner  bool
-}
-
-// 处理地域代码
-func CalculateRegionCode(area string, city string, district string) (area_code string, city_code string, district_code string) {
-	area_code, city_code, district_code = "000000", "", ""
-	if district != "" {
-		key := area + "~" + city + "~" + district + "~"
-		code := RegionCodeData[key]
-		if code != "" {
-			district_code = code
-			city_code = code[:4] + "00"
-			area_code = code[:2] + "0000"
-			return
-		}
-	}
-	if city != "" {
-		key := area + "~" + city + "~" + "" + "~"
-		code := RegionCodeData[key]
-		if code != "" {
-			city_code = code
-			area_code = city_code[:2] + "0000"
-			return
-		}
-	}
-	if area != "" {
-		key := area + "~" + "" + "~" + "" + "~"
-		code := RegionCodeData[key]
-		if code != "" {
-			area_code = code
-			return
-		}
-	}
-	return
-}
-
 // 单位分割~去重 中标单位
 func SegmentationEntName(name_1 string, name_2 string) ([]string, []bool) {
 	new_arr := []string{}
@@ -94,47 +49,6 @@ func SegmentationEntName(name_1 string, name_2 string) ([]string, []bool) {
 	return new_arr, new_bool
 }
 
-// 转二进制
-func Str2DEC(s string) (num int) {
-	l := len(s)
-	for i := l - 1; i >= 0; i-- {
-		num += (int(s[l-i-1]) & 0xf) << uint8(i)
-	}
-	return
-}
-func ConvertToBin(num int) string {
-	s := ""
-	if num == 0 {
-		return "0"
-	}
-	for ; num > 0; num /= 2 {
-		lsb := num % 2
-		s = strconv.Itoa(lsb) + s
-	}
-	return s
-}
-
-func toMegaBytes(bytes uint64) float64 {
-	return float64(bytes) / 1024 / 1024
-}
-func traceMemStats() {
-	var ms runtime.MemStats
-	runtime.ReadMemStats(&ms)
-	var result = make([]float64, 7)
-	result[0] = float64(ms.HeapObjects)
-	result[1] = toMegaBytes(ms.HeapAlloc)
-	result[2] = toMegaBytes(ms.TotalAlloc)
-	result[3] = toMegaBytes(ms.HeapSys)
-	result[4] = toMegaBytes(ms.HeapIdle)
-	result[5] = toMegaBytes(ms.HeapReleased)
-	result[6] = toMegaBytes(ms.HeapIdle - ms.HeapReleased)
-
-	for _, v := range result {
-		fmt.Printf("%.2f\t", v)
-	}
-	fmt.Printf("\n")
-}
-
 func IsMarkInterfaceArr(t interface{}) []string {
 	sub_list := []string{}
 	if list_3, ok_3 := t.([]string); ok_3 {
@@ -151,6 +65,22 @@ func IsMarkInterfaceArr(t interface{}) []string {
 	return sub_list
 }
 
+func IsMarkInterfaceMap(t interface{}) []map[string]interface{} {
+	p_list := []map[string]interface{}{}
+	if yl_list_1, ok_3 := t.([]map[string]interface{}); ok_3 {
+		p_list = yl_list_1
+		return p_list
+	}
+	if yl_list_1, ok_1 := t.(primitive.A); ok_1 {
+		p_list = qu.ObjArrToMapArr(yl_list_1)
+	} else {
+		if yl_list_2, ok_2 := t.([]interface{}); ok_2 {
+			p_list = qu.ObjArrToMapArr(yl_list_2)
+		}
+	}
+	return p_list
+}
+
 // 获取最优企业
 func GetOneBaseCompany(arr []map[string]interface{}) int {
 	index := 0
@@ -172,6 +102,24 @@ func GetOneBaseCompany(arr []map[string]interface{}) int {
 	return index
 }
 
+// 创建企业信息
+func GetOneQyxyInfo(name string) map[string]interface{} {
+	qyxy_info := map[string]interface{}{}
+	dataArr, _ := QyxyMgo.Find("qyxy_std", map[string]interface{}{"company_name": name}, map[string]interface{}{"updatetime": -1}, nil)
+	if len(dataArr) > 0 {
+		qyxy_info = dataArr[0] //补充企业信息
+	} else {
+		data := SpiMgo.FindOne("company_history_name", map[string]interface{}{
+			"history_name": name,
+		})
+		if len(data) > 0 {
+			company_id := qu.ObjToString(data["company_id"])
+			qyxy_info = QyxyMgo.FindOne("qyxy_std", map[string]interface{}{"_id": company_id})
+		}
+	}
+	return qyxy_info
+}
+
 // 清洗日期~
 func cleanErrDateTime(datetime string) bool {
 	arr := strings.Split(datetime, "-")
@@ -183,3 +131,44 @@ func cleanErrDateTime(datetime string) bool {
 	}
 	return false
 }
+
+// 转二进制 用不到......
+func Str2DEC(s string) (num int) {
+	l := len(s)
+	for i := l - 1; i >= 0; i-- {
+		num += (int(s[l-i-1]) & 0xf) << uint8(i)
+	}
+	return
+}
+func ConvertToBin(num int) string {
+	s := ""
+	if num == 0 {
+		return "0"
+	}
+	for ; num > 0; num /= 2 {
+		lsb := num % 2
+		s = strconv.Itoa(lsb) + s
+	}
+	return s
+}
+
+func toMegaBytes(bytes uint64) float64 {
+	return float64(bytes) / 1024 / 1024
+}
+func traceMemStats() {
+	var ms runtime.MemStats
+	runtime.ReadMemStats(&ms)
+	var result = make([]float64, 7)
+	result[0] = float64(ms.HeapObjects)
+	result[1] = toMegaBytes(ms.HeapAlloc)
+	result[2] = toMegaBytes(ms.TotalAlloc)
+	result[3] = toMegaBytes(ms.HeapSys)
+	result[4] = toMegaBytes(ms.HeapIdle)
+	result[5] = toMegaBytes(ms.HeapReleased)
+	result[6] = toMegaBytes(ms.HeapIdle - ms.HeapReleased)
+
+	for _, v := range result {
+		fmt.Printf("%.2f\t", v)
+	}
+	fmt.Printf("\n")
+}

+ 15 - 3
main.go

@@ -6,6 +6,8 @@ import (
 	"data_ent_wuye/ent_util"
 	log "github.com/donnie4w/go-logger/logger"
 	_ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
+	"github.com/google/uuid"
+	"strings"
 )
 
 func init() {
@@ -14,14 +16,24 @@ func init() {
 
 func main() {
 	log.Debug("main...")
-	ent_contact.InjectContactTidbInfo()
-
 	log.Debug("......")
 	lock := make(chan bool)
 	<-lock
 }
 
 // 以下测试...
+func test() {
+	//tidb全量
+	ent_contact.InjectContactTidbInfo()
+	//凭安全量
+	info := ent_util.GetOneQyxyInfo("湖南德成大药房连锁有限公司鼎城淮阳店")
+	name_id := uuid.New().String()
+	name_id = strings.ReplaceAll(name_id, "-", "")
+	ent_contact.InjectContactPingAnInfo(name_id, info)
+	//马克全量
+	ent_contact.InjectContactMaKeInfo(name_id, map[string]interface{}{"phone": "手机号"})
+}
+
 func test1() {
 	query := `SELECT id,title FROM information.information WHERE id = '000fcf377e334bcc9380b921df93c268'`
 	rows, err := ent_util.ClickHouseConn.Query(context.Background(), query)
@@ -51,7 +63,7 @@ func test1() {
 	log.Debug("总计数量", isok)
 }
 
-func test() {
+func test2() {
 
 	query := `ALTER TABLE information.information DELETE WHERE id='676470119ae64a18bab5d1fdb5f06bb3' `
 	query = `-- TRUNCATE TABLE information.information_copy;`