|
@@ -47,15 +47,15 @@ func IncTransactionDataFromBidAndPro() {
|
|
IncTransactionDataFromBid() //bidding
|
|
IncTransactionDataFromBid() //bidding
|
|
IncTransactionDataFromPro() //project
|
|
IncTransactionDataFromPro() //project
|
|
return
|
|
return
|
|
- IncTransactionDataMgoToCkh() //mongodb迁移至clickhouse
|
|
|
|
|
|
+ IncTransactionDataMgoToCkhAndEs() //mongodb迁移至clickhouse
|
|
}
|
|
}
|
|
|
|
|
|
// IncTransactionDataFromBid 增量bidding
|
|
// IncTransactionDataFromBid 增量bidding
|
|
func IncTransactionDataFromBid() {
|
|
func IncTransactionDataFromBid() {
|
|
endTime := GetTime(-1) //前一天凌晨
|
|
endTime := GetTime(-1) //前一天凌晨
|
|
- fmt.Println("开始执行增量采购意向信息", BidStartTime, endTime)
|
|
|
|
|
|
+ fmt.Println("开始执行增量采购意向、拟建信息", BidStartTime, endTime)
|
|
if BidStartTime >= endTime {
|
|
if BidStartTime >= endTime {
|
|
- fmt.Println("增量bidding采购意向查询异常:", BidStartTime, endTime)
|
|
|
|
|
|
+ fmt.Println("增量bidding采购意向、拟建查询异常:", BidStartTime, endTime)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
query := map[string]interface{}{
|
|
query := map[string]interface{}{
|
|
@@ -83,6 +83,7 @@ func IncTransactionDataFromBid() {
|
|
"city": 1,
|
|
"city": 1,
|
|
"district": 1,
|
|
"district": 1,
|
|
//
|
|
//
|
|
|
|
+ "s_topscopeclass": 1,
|
|
"publishtime": 1,
|
|
"publishtime": 1,
|
|
"toptype": 1,
|
|
"toptype": 1,
|
|
"extracttype": 1,
|
|
"extracttype": 1,
|
|
@@ -94,6 +95,7 @@ func IncTransactionDataFromBid() {
|
|
arr := []map[string]interface{}{}
|
|
arr := []map[string]interface{}{}
|
|
it := sess.DB(MgoB.DbName).C("bidding").Find(&query).Select(&fields).Iter()
|
|
it := sess.DB(MgoB.DbName).C("bidding").Find(&query).Select(&fields).Iter()
|
|
n := 0
|
|
n := 0
|
|
|
|
+ count := 0
|
|
for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
|
|
for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
|
|
ch <- true
|
|
ch <- true
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
@@ -102,19 +104,34 @@ func IncTransactionDataFromBid() {
|
|
<-ch
|
|
<-ch
|
|
wg.Done()
|
|
wg.Done()
|
|
}()
|
|
}()
|
|
- if gconv.String(tmp["toptype"]) != "采购意向" { //非采购意向数据过滤
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
if gconv.Int(tmp["extracttype"]) == -1 { //重复数据过滤
|
|
if gconv.Int(tmp["extracttype"]) == -1 { //重复数据过滤
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if tmp["tag_topinformation"] == nil && tmp["tag_topinformation_ai"] == nil { //无效数据过滤
|
|
|
|
|
|
+ toptype := gconv.String(tmp["toptype"])
|
|
|
|
+ tag_topinformation := gconv.String(tmp["tag_topinformation"])
|
|
|
|
+ tag_topinformation_ai := gconv.String(tmp["tag_topinformation_ai"])
|
|
|
|
+ var business_type string
|
|
|
|
+ var project_bidstatus int
|
|
|
|
+ if toptype == "采购意向" { //采购意向数据
|
|
|
|
+ if !strings.Contains(tag_topinformation, "物业") && !strings.Contains(tag_topinformation_ai, "物业") {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ business_type = "采购意向"
|
|
|
|
+ project_bidstatus = 3
|
|
|
|
+ } else if toptype == "拟建" {
|
|
|
|
+ if strings.Contains(tag_topinformation, "物业") || strings.Contains(tag_topinformation_ai, "物业") {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ business_type = "新增项目"
|
|
|
|
+ project_bidstatus = 4
|
|
|
|
+ } else {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- result := DealTransactionForBid(tmp)
|
|
|
|
|
|
+ result := DealTransactionForBid(tmp, business_type, project_bidstatus)
|
|
lock.Lock()
|
|
lock.Lock()
|
|
if len(result) > 0 {
|
|
if len(result) > 0 {
|
|
arr = append(arr, result)
|
|
arr = append(arr, result)
|
|
|
|
+ count++
|
|
}
|
|
}
|
|
if len(arr) > 50 {
|
|
if len(arr) > 50 {
|
|
MgoPro.SaveBulk("projectset_wy", arr...)
|
|
MgoPro.SaveBulk("projectset_wy", arr...)
|
|
@@ -132,12 +149,12 @@ func IncTransactionDataFromBid() {
|
|
MgoPro.SaveBulk("projectset_wy", arr...)
|
|
MgoPro.SaveBulk("projectset_wy", arr...)
|
|
arr = []map[string]interface{}{}
|
|
arr = []map[string]interface{}{}
|
|
}
|
|
}
|
|
- fmt.Println("执行增量采购意向信息完毕", BidStartTime, endTime)
|
|
|
|
|
|
+ fmt.Println("执行增量采购意向、拟建信息完毕", BidStartTime, endTime, count)
|
|
BidStartTime = endTime //替换
|
|
BidStartTime = endTime //替换
|
|
}
|
|
}
|
|
|
|
|
|
// DealTransactionForBid bidding采购意向数据处理
|
|
// DealTransactionForBid bidding采购意向数据处理
|
|
-func DealTransactionForBid(tmp map[string]interface{}) map[string]interface{} {
|
|
|
|
|
|
+func DealTransactionForBid(tmp map[string]interface{}, business_type string, project_bidstatus int) map[string]interface{} {
|
|
//基本信息封装
|
|
//基本信息封装
|
|
id := mongodb.BsonIdToSId(tmp["_id"])
|
|
id := mongodb.BsonIdToSId(tmp["_id"])
|
|
buyer := gconv.String(tmp["buyer"])
|
|
buyer := gconv.String(tmp["buyer"])
|
|
@@ -162,6 +179,17 @@ func DealTransactionForBid(tmp map[string]interface{}) map[string]interface{} {
|
|
subclass = gconv.Strings(tag_subinformation_ai)
|
|
subclass = gconv.Strings(tag_subinformation_ai)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //TODO 情报库信息(待补充)
|
|
|
|
+ information_id := ""
|
|
|
|
+ starttime, endtime := int64(0), int64(0)
|
|
|
|
+ //if project_bidstatus == 4 {//补充情报信息
|
|
|
|
+ // //bidId = "65fbf3f566cf0db42a2a99d2"
|
|
|
|
+ // info := FindInfomationData(id) //情报信息查询
|
|
|
|
+ // information_id = info.Id
|
|
|
|
+ // starttime = info.Starttime
|
|
|
|
+ // endtime = info.Endtime
|
|
|
|
+ //}
|
|
|
|
+
|
|
//TODO 查询法人库信息(待补充)
|
|
//TODO 查询法人库信息(待补充)
|
|
winners := []string{}
|
|
winners := []string{}
|
|
if winner != "" {
|
|
if winner != "" {
|
|
@@ -177,10 +205,10 @@ func DealTransactionForBid(tmp map[string]interface{}) map[string]interface{} {
|
|
Project_Budget: budget,
|
|
Project_Budget: budget,
|
|
Project_Bidamount: bidamount,
|
|
Project_Bidamount: bidamount,
|
|
Project_Money: money,
|
|
Project_Money: money,
|
|
- Business_Type: "采购意向",
|
|
|
|
- Project_Bidstatus: 3,
|
|
|
|
|
|
+ Business_Type: business_type,
|
|
|
|
+ Project_Bidstatus: project_bidstatus,
|
|
Info_Id: id,
|
|
Info_Id: id,
|
|
- Information_Id: "",
|
|
|
|
|
|
+ Information_Id: information_id,
|
|
Buyer: buyer,
|
|
Buyer: buyer,
|
|
Winner: winners,
|
|
Winner: winners,
|
|
Agency: agency,
|
|
Agency: agency,
|
|
@@ -195,8 +223,8 @@ func DealTransactionForBid(tmp map[string]interface{}) map[string]interface{} {
|
|
District: gconv.String(tmp["district"]),
|
|
District: gconv.String(tmp["district"]),
|
|
ZbTime: gconv.Int64(tmp["publishtime"]),
|
|
ZbTime: gconv.Int64(tmp["publishtime"]),
|
|
JgTime: int64(0),
|
|
JgTime: int64(0),
|
|
- StartTime: int64(0),
|
|
|
|
- EndTime: int64(0),
|
|
|
|
|
|
+ StartTime: starttime,
|
|
|
|
+ EndTime: endtime,
|
|
Create_Time: time.Now().Unix(),
|
|
Create_Time: time.Now().Unix(),
|
|
Update_Time: time.Now().Unix(),
|
|
Update_Time: time.Now().Unix(),
|
|
//
|
|
//
|
|
@@ -256,6 +284,7 @@ func IncTransactionDataFromPro() {
|
|
arr := [][]map[string]interface{}{}
|
|
arr := [][]map[string]interface{}{}
|
|
it := sess.DB(MgoPro.DbName).C("projectset_20230904").Find(&query).Select(&fields).Iter()
|
|
it := sess.DB(MgoPro.DbName).C("projectset_20230904").Find(&query).Select(&fields).Iter()
|
|
n := 0
|
|
n := 0
|
|
|
|
+ count := 0
|
|
for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
|
|
for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
|
|
ch <- true
|
|
ch <- true
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
@@ -270,6 +299,7 @@ func IncTransactionDataFromPro() {
|
|
result := DealTransactionForPro(tmp)
|
|
result := DealTransactionForPro(tmp)
|
|
lock.Lock()
|
|
lock.Lock()
|
|
if len(result) > 0 {
|
|
if len(result) > 0 {
|
|
|
|
+ count++
|
|
update := []map[string]interface{}{
|
|
update := []map[string]interface{}{
|
|
{"project_id": tmp["_id"]},
|
|
{"project_id": tmp["_id"]},
|
|
{"$set": result},
|
|
{"$set": result},
|
|
@@ -292,7 +322,7 @@ func IncTransactionDataFromPro() {
|
|
MgoPro.UpSertBulk("projectset_wy_back", arr...)
|
|
MgoPro.UpSertBulk("projectset_wy_back", arr...)
|
|
arr = [][]map[string]interface{}{}
|
|
arr = [][]map[string]interface{}{}
|
|
}
|
|
}
|
|
- fmt.Println("执行增量项目信息完毕", ProStartTime, endTime)
|
|
|
|
|
|
+ fmt.Println("执行增量项目信息完毕", ProStartTime, endTime, count)
|
|
ProStartTime = endTime //替换
|
|
ProStartTime = endTime //替换
|
|
}
|
|
}
|
|
|
|
|
|
@@ -304,6 +334,9 @@ func DealTransactionForPro(data map[string]interface{}) map[string]interface{} {
|
|
winner := gconv.String(data["s_winner"])
|
|
winner := gconv.String(data["s_winner"])
|
|
agency := gconv.String(data["agency"])
|
|
agency := gconv.String(data["agency"])
|
|
zbtime := gconv.Int64(data["zbtime"])
|
|
zbtime := gconv.Int64(data["zbtime"])
|
|
|
|
+ if zbtime == 0 {
|
|
|
|
+ zbtime = gconv.Int64(data["firsttime"])
|
|
|
|
+ }
|
|
property_form := []string{}
|
|
property_form := []string{}
|
|
if data["property_form"] != nil {
|
|
if data["property_form"] != nil {
|
|
property_form = gconv.Strings(data["property_form"])
|
|
property_form = gconv.Strings(data["property_form"])
|
|
@@ -334,11 +367,7 @@ func DealTransactionForPro(data map[string]interface{}) map[string]interface{} {
|
|
project_bidstatus = 0
|
|
project_bidstatus = 0
|
|
} else if bidstatus == "招标" {
|
|
} else if bidstatus == "招标" {
|
|
business_type = "招标项目"
|
|
business_type = "招标项目"
|
|
- if zbtime == 0 {
|
|
|
|
- zbtime = gconv.Int64(data["firsttime"])
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
//查询情报信息
|
|
//查询情报信息
|
|
//bidId = "65fbf3f566cf0db42a2a99d2"
|
|
//bidId = "65fbf3f566cf0db42a2a99d2"
|
|
ids := gconv.Strings(data["ids"])
|
|
ids := gconv.Strings(data["ids"])
|
|
@@ -390,8 +419,8 @@ func DealTransactionForPro(data map[string]interface{}) map[string]interface{} {
|
|
return result
|
|
return result
|
|
}
|
|
}
|
|
|
|
|
|
-// IncTransactionDataMgoToCkh 数据迁移
|
|
|
|
-func IncTransactionDataMgoToCkh() {
|
|
|
|
|
|
+// IncTransactionDataMgoToCkhAndEs 数据迁移
|
|
|
|
+func IncTransactionDataMgoToCkhAndEs() {
|
|
/*
|
|
/*
|
|
数据根据update_time查询
|
|
数据根据update_time查询
|
|
1、采购意向数据(from=bidding)只插入
|
|
1、采购意向数据(from=bidding)只插入
|
|
@@ -400,7 +429,7 @@ func IncTransactionDataMgoToCkh() {
|
|
fmt.Println("开始执行迁移...")
|
|
fmt.Println("开始执行迁移...")
|
|
sess := MgoPro.GetMgoConn()
|
|
sess := MgoPro.GetMgoConn()
|
|
defer MgoPro.DestoryMongoConn(sess)
|
|
defer MgoPro.DestoryMongoConn(sess)
|
|
- ch := make(chan bool, 10)
|
|
|
|
|
|
+ ch := make(chan bool, 2)
|
|
wg := &sync.WaitGroup{}
|
|
wg := &sync.WaitGroup{}
|
|
query := map[string]interface{}{
|
|
query := map[string]interface{}{
|
|
"update_time": map[string]interface{}{
|
|
"update_time": map[string]interface{}{
|
|
@@ -417,18 +446,16 @@ func IncTransactionDataMgoToCkh() {
|
|
<-ch
|
|
<-ch
|
|
wg.Done()
|
|
wg.Done()
|
|
}()
|
|
}()
|
|
- var err error
|
|
|
|
from := gconv.String(tmp["from"])
|
|
from := gconv.String(tmp["from"])
|
|
- delete(tmp, "from") //无用字段删除
|
|
|
|
- delete(tmp, "_id") //无用字段删除
|
|
|
|
- if from == "bidding" { //采购意向,插入
|
|
|
|
- err = SaveDataToClickHouse(tmp)
|
|
|
|
- } else { //项目信息,更新,插入
|
|
|
|
- project_id := gconv.String(tmp["project_id"])
|
|
|
|
- err = UpdateOrSaveDataToClickHouse(project_id, tmp)
|
|
|
|
|
|
+ delete(tmp, "from") //无用字段删除
|
|
|
|
+ delete(tmp, "_id") //无用字段删除
|
|
|
|
+ if !SaveDataToEs(tmp) { //保存、更新es
|
|
|
|
+ fmt.Println("数据保存es失败,项目project_id", tmp["project_id"])
|
|
}
|
|
}
|
|
- if err != nil {
|
|
|
|
- fmt.Println("数据迁移失败,数据类型", from, " 项目project_id", tmp["project_id"], err)
|
|
|
|
|
|
+ if from == "bidding" { //采购意向、拟建,插入
|
|
|
|
+ SaveDataToClickHouse(tmp)
|
|
|
|
+ } else { //项目信息,更新,插入
|
|
|
|
+ UpdateOrSaveDataToClickHouse(tmp)
|
|
}
|
|
}
|
|
}(tmp)
|
|
}(tmp)
|
|
if n%100 == 0 {
|
|
if n%100 == 0 {
|
|
@@ -446,7 +473,7 @@ type Infomation struct {
|
|
Endtime int64
|
|
Endtime int64
|
|
}
|
|
}
|
|
|
|
|
|
-// 情报信息查询
|
|
|
|
|
|
+// FindInfomationData 情报信息查询
|
|
func FindInfomationData(ids ...string) (info Infomation) {
|
|
func FindInfomationData(ids ...string) (info Infomation) {
|
|
for _, id := range ids {
|
|
for _, id := range ids {
|
|
query := fmt.Sprintf(`SELECT id,starttime,endtime FROM %s WHERE datajson_id = ?`, Config.ClickHouse.DataBase+".information")
|
|
query := fmt.Sprintf(`SELECT id,starttime,endtime FROM %s WHERE datajson_id = ?`, Config.ClickHouse.DataBase+".information")
|
|
@@ -468,7 +495,7 @@ func FindInfomationData(ids ...string) (info Infomation) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-// 法人信息查询
|
|
|
|
|
|
+// FindEntInfoData 法人信息查询
|
|
func FindEntInfoData(bid, buyer, agency string, winners []string) (buyer_id, agency_id string, winner_ids []string) {
|
|
func FindEntInfoData(bid, buyer, agency string, winners []string) (buyer_id, agency_id string, winner_ids []string) {
|
|
winner_ids = []string{}
|
|
winner_ids = []string{}
|
|
winnerMap := map[string]bool{} //记录所有中标单位
|
|
winnerMap := map[string]bool{} //记录所有中标单位
|
|
@@ -515,14 +542,21 @@ func FindEntInfoData(bid, buyer, agency string, winners []string) (buyer_id, age
|
|
}
|
|
}
|
|
|
|
|
|
// UpdateOrSaveDataToClickHouse 判断clickhouse更新or保存
|
|
// UpdateOrSaveDataToClickHouse 判断clickhouse更新or保存
|
|
-func UpdateOrSaveDataToClickHouse(project_id string, data map[string]interface{}) (err error) {
|
|
|
|
|
|
+func UpdateOrSaveDataToClickHouse(data map[string]interface{}) (err error) {
|
|
|
|
+ project_id := gconv.String(data["project_id"])
|
|
count := FindClickHouseByProjectId(project_id) //查询
|
|
count := FindClickHouseByProjectId(project_id) //查询
|
|
if count > 0 { //更新
|
|
if count > 0 { //更新
|
|
delete(data, "create_time") //不更新创建时间
|
|
delete(data, "create_time") //不更新创建时间
|
|
delete(data, "project_id") //不更新项目id(主键)
|
|
delete(data, "project_id") //不更新项目id(主键)
|
|
err = UpdateDataToClickHouse(data, map[string]interface{}{"project_id": project_id})
|
|
err = UpdateDataToClickHouse(data, map[string]interface{}{"project_id": project_id})
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("clickhouse更新失败", project_id, data)
|
|
|
|
+ }
|
|
} else { //插入
|
|
} else { //插入
|
|
err = SaveDataToClickHouse(data)
|
|
err = SaveDataToClickHouse(data)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("clickhouse保存失败", project_id, data)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -567,6 +601,57 @@ func UpdateDataToClickHouse(data, querys map[string]interface{}) error {
|
|
return CkhTool.Exec(context.Background(), query, values...)
|
|
return CkhTool.Exec(context.Background(), query, values...)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// SaveDataToEs es存储
|
|
|
|
+func SaveDataToEs(data map[string]interface{}) bool {
|
|
|
|
+ tmp := map[string]interface{}{}
|
|
|
|
+ for k, v := range data {
|
|
|
|
+ if k == "project_id" {
|
|
|
|
+ k = "_id"
|
|
|
|
+ }
|
|
|
|
+ tmp[k] = v
|
|
|
|
+ }
|
|
|
|
+ err, result := Es.GetById(Config.Es.Index, gconv.String(tmp["_id"]))
|
|
|
|
+ if err == nil && len(result) > 0 { //存在,更新
|
|
|
|
+ tmp["create_time"] = result["create_time"] //不更新create_time
|
|
|
|
+ }
|
|
|
|
+ return Es.Save(Config.Es.Index, tmp)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func FindEntInfoData2(bid, buyer, agency string, winners []string) (buyer_id, agency_id string, winner_ids []string) {
|
|
|
|
+ query := fmt.Sprintf(`SELECT id FROM %s WHERE company_name = ?`, Config.ClickHouse.DataBase+".ent_info")
|
|
|
|
+ if buyer != "" {
|
|
|
|
+ buyer_id = GetClickHouseData(bid, query, buyer)
|
|
|
|
+ }
|
|
|
|
+ if agency != "" {
|
|
|
|
+ agency_id = GetClickHouseData(bid, query, agency)
|
|
|
|
+ }
|
|
|
|
+ if len(winners) > 0 {
|
|
|
|
+ for _, w := range winners {
|
|
|
|
+ winner_id := GetClickHouseData(bid, query, w)
|
|
|
|
+ if winner_id != "" {
|
|
|
|
+ winner_ids = append(winner_ids, winner_id)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetClickHouseData(bid, query, value string) string {
|
|
|
|
+ rows, err := CkhTool.Query(context.Background(), query, value)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
|
|
+ for rows.Next() {
|
|
|
|
+ var id string
|
|
|
|
+ if err := rows.Scan(&id); err == nil {
|
|
|
|
+ return id
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Println("查询情报信息异常:", err, bid)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ""
|
|
|
|
+}
|
|
|
|
+
|
|
/*// SaveTransactionData 保存增量物业信息
|
|
/*// SaveTransactionData 保存增量物业信息
|
|
func SaveTransactionData() {
|
|
func SaveTransactionData() {
|
|
fmt.Println("save projectset_wy...")
|
|
fmt.Println("save projectset_wy...")
|