|
@@ -7,6 +7,7 @@ import (
|
|
"github.com/donnie4w/go-logger/logger"
|
|
"github.com/donnie4w/go-logger/logger"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"mime/multipart"
|
|
"mime/multipart"
|
|
|
|
+ "mongodb"
|
|
qu "qfw/util"
|
|
qu "qfw/util"
|
|
. "spiderutil"
|
|
. "spiderutil"
|
|
"strings"
|
|
"strings"
|
|
@@ -95,8 +96,9 @@ func (f *Front) WarnEdit() {
|
|
num, _ := f.GetInteger("num")
|
|
num, _ := f.GetInteger("num")
|
|
data := map[string]interface{}{}
|
|
data := map[string]interface{}{}
|
|
bidId := ""
|
|
bidId := ""
|
|
- one, _ := MgoS.FindById("spider_warn_err", id, map[string]interface{}{"data": 1, "field": 1})
|
|
|
|
|
|
+ one, _ := MgoS.FindById("spider_warn_err", id, map[string]interface{}{"data": 1, "field": 1, "entry": 1})
|
|
if one != nil && len(*one) > 0 {
|
|
if one != nil && len(*one) > 0 {
|
|
|
|
+ entry, _ := (*one)["entry"].(bool) //数据是否入库标记
|
|
data, _ = (*one)["data"].(map[string]interface{})
|
|
data, _ = (*one)["data"].(map[string]interface{})
|
|
detail := qu.ObjToString((data)["detail"])
|
|
detail := qu.ObjToString((data)["detail"])
|
|
contenthtml := qu.ObjToString((data)["contenthtml"])
|
|
contenthtml := qu.ObjToString((data)["contenthtml"])
|
|
@@ -104,6 +106,7 @@ func (f *Front) WarnEdit() {
|
|
f.T["detail"] = detail
|
|
f.T["detail"] = detail
|
|
f.T["contenthtml"] = contenthtml
|
|
f.T["contenthtml"] = contenthtml
|
|
f.T["summary"] = summary
|
|
f.T["summary"] = summary
|
|
|
|
+ f.T["entry"] = entry
|
|
delete(data, "_id")
|
|
delete(data, "_id")
|
|
delete(data, "detail")
|
|
delete(data, "detail")
|
|
delete(data, "contenthtml")
|
|
delete(data, "contenthtml")
|
|
@@ -202,128 +205,69 @@ func (f *Front) LuaDataSend() {
|
|
FormatFields(update)
|
|
FormatFields(update)
|
|
FormatNumber(update) //解决超大金额转成科学计数法的问题
|
|
FormatNumber(update) //解决超大金额转成科学计数法的问题
|
|
}
|
|
}
|
|
|
|
+ qu.Debug("update:", update)
|
|
one, _ := MgoS.FindById("spider_warn_err", id, map[string]interface{}{"data": 1})
|
|
one, _ := MgoS.FindById("spider_warn_err", id, map[string]interface{}{"data": 1})
|
|
if len(*one) > 0 {
|
|
if len(*one) > 0 {
|
|
data, _ := (*one)["data"].(map[string]interface{})
|
|
data, _ := (*one)["data"].(map[string]interface{})
|
|
- mustFiledNum := 0 //记录更新有效字段个数
|
|
|
|
- result := map[string]interface{}{}
|
|
|
|
- for k, _ := range Fields {
|
|
|
|
- if v := update[k]; v != nil {
|
|
|
|
- result[k] = v
|
|
|
|
- mustFiledNum++
|
|
|
|
- } else if v := data[k]; v != nil {
|
|
|
|
- mustFiledNum++
|
|
|
|
- result[k] = v
|
|
|
|
|
|
+ if stype == -1 { //bidding数据直接修改数据
|
|
|
|
+ success, msg = updateBidding(id, reasons, data, update)
|
|
|
|
+ } else { //非bidding数据推送保存服务
|
|
|
|
+ mustFiledNum := 0 //记录更新有效字段个数
|
|
|
|
+ result := map[string]interface{}{}
|
|
|
|
+ for k, _ := range Fields {
|
|
|
|
+ if v := update[k]; v != nil {
|
|
|
|
+ result[k] = v
|
|
|
|
+ mustFiledNum++
|
|
|
|
+ } else if v := data[k]; v != nil {
|
|
|
|
+ mustFiledNum++
|
|
|
|
+ result[k] = v
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if mustFiledNum > 0 {
|
|
|
|
- flag, bidid, bidcoll := SaveObj(4002, "title", result)
|
|
|
|
- logger.Info(bid, " ", flag, " ", bidid, " ", bidcoll)
|
|
|
|
- update["sendflag"] = flag
|
|
|
|
- update["biddingid"] = bidid
|
|
|
|
- update["biddingcoll"] = bidcoll
|
|
|
|
- TagToSpiderWarnErr(stype, id, reasons, update) //spider_warn_err日志
|
|
|
|
- if flag == "true" {
|
|
|
|
- success = true
|
|
|
|
- if bidcoll != "" && bidid != "" {
|
|
|
|
- msg = "保存成功;数据所在表:" + bidcoll + ";数据ID:" + bidid
|
|
|
|
- } else {
|
|
|
|
- msg = "推送成功,但数据存在异常或被判重!"
|
|
|
|
|
|
+ if mustFiledNum > 0 {
|
|
|
|
+ flag, bidid, bidcoll := SaveObj(4002, "title", result)
|
|
|
|
+ logger.Info(bid, " ", flag, " ", bidid, " ", bidcoll)
|
|
|
|
+ update["sendflag"] = flag
|
|
|
|
+ update["biddingid"] = bidid
|
|
|
|
+ update["biddingcoll"] = bidcoll
|
|
|
|
+ TagToSpiderWarnErr(stype, id, reasons, update) //spider_warn_err日志
|
|
|
|
+ if flag == "true" {
|
|
|
|
+ success = true
|
|
|
|
+ if bidcoll != "" && bidid != "" {
|
|
|
|
+ msg = "保存成功;数据所在表:" + bidcoll + ";数据ID:" + bidid
|
|
|
|
+ } else {
|
|
|
|
+ msg = "推送成功,但数据存在异常或被判重!"
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ msg = "推送失败,无有效字段"
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- msg = "推送失败,无有效字段"
|
|
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
msg = "未找到该数据"
|
|
msg = "未找到该数据"
|
|
}
|
|
}
|
|
- //if stype == 1 { //修复更新
|
|
|
|
- // if bid == "" {
|
|
|
|
- // rep = "bidding id 为空"
|
|
|
|
- // goto L
|
|
|
|
- // }
|
|
|
|
- // old_data, _ := JYMgo.FindById("bidding", bid, nil) //查询原始信息,用作修改日志记录
|
|
|
|
- // if old_data != nil && len(*old_data) > 0 {
|
|
|
|
- // delete(*old_data, "_id")
|
|
|
|
- // if (*old_data)["modifyinfo"] != nil {
|
|
|
|
- // if m, ok := (*old_data)["modifyinfo"].(map[string]interface{}); ok { //合并modifyinfo
|
|
|
|
- // for k, v := range m {
|
|
|
|
- // modifyinfo[k] = v
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // } else {
|
|
|
|
- // rep = "未找到bidding数据,id:" + bid
|
|
|
|
- // goto L
|
|
|
|
- // }
|
|
|
|
- // if len(modifyinfo) > 0 { //记录修改字段
|
|
|
|
- // update["modifyinfo"] = modifyinfo
|
|
|
|
- // }
|
|
|
|
- // b := JYMgo.UpdateById("bidding", bid, map[string]interface{}{"$set": update}) //更新
|
|
|
|
- // if b { //更新成功 //更新成功 重生bidding索引 项目合并
|
|
|
|
- // qu.Debug("更新成功")
|
|
|
|
- // udptask.BiddingIndexUdp(bid, "bidding") //coll:bidding 是因为调用此方法的数据都是增量数据
|
|
|
|
- // if IsModifyPro(modifyinfo) { //修改了影响项目合并的字段 进行项目合并
|
|
|
|
- // udptask.ProjectSetUdp(bid, "bidding")
|
|
|
|
- // }
|
|
|
|
- // delName1 := RedisDelKey1 + "*_" + bid
|
|
|
|
- // redis.DelByCodePattern(RedisJYName, delName1)
|
|
|
|
- // delete(update, "modifyinfo")
|
|
|
|
- // l.SaveUpdateLog(2, reasons, bid, *old_data, update, modifyinfo) //标签日志
|
|
|
|
- // TagToSpiderWarnErr(stype, id, reasons, update) //spider_warn_err日志
|
|
|
|
- // success = true
|
|
|
|
- // } else { //更新失败
|
|
|
|
- // rep = "更新bidding失败,id:" + bid
|
|
|
|
- // qu.Debug("更新失败")
|
|
|
|
- // }
|
|
|
|
- //} else { //3:修复发布 4:直接发布
|
|
|
|
- // href := qu.ObjToString(update["href"])
|
|
|
|
- // shaid := qu.ObjToString(update["s_sha"])
|
|
|
|
- // competehref := qu.ObjToString(update["competehref"]) //竞品数据
|
|
|
|
- // iscompete, _ := update["iscompete"].(bool) //新爬虫数据
|
|
|
|
- // newId := primitive.NewObjectID()
|
|
|
|
- // newSid := mongodb.BsonIdToSId(newId)
|
|
|
|
- // qu.Debug("newId:", newSid)
|
|
|
|
- // update["_id"] = newId
|
|
|
|
- // if competehref != "" { //竞品爬虫
|
|
|
|
- // href = competehref
|
|
|
|
- // update["href"] = GetJyHref(newSid)
|
|
|
|
- // } else if iscompete { //新爬虫
|
|
|
|
- // update["competehref"] = "#"
|
|
|
|
- // }
|
|
|
|
- // delete(update, "iscompete")
|
|
|
|
- // update["comeintime"] = time.Now().Unix() //更新入库时间
|
|
|
|
- // update["modifyinfo"] = map[string]interface{}{} //添加空modifyinfo作为标识
|
|
|
|
- // PutHrefRedis(href, shaid, newSid) //添加href进redis
|
|
|
|
- // qu.Debug(update)
|
|
|
|
- // JYMgo.SaveByOriID("bidding", update) //入bidding
|
|
|
|
- // l.SaveUpdateLog(1, reasons, newSid, map[string]interface{}{}, update, map[string]interface{}{}) //标签日志
|
|
|
|
- // TagToSpiderWarnErr(stype, id, reasons, update) //spider_warn_err日志
|
|
|
|
- // success = true
|
|
|
|
- //}
|
|
|
|
}
|
|
}
|
|
f.ServeJson(map[string]interface{}{"success": success, "msg": msg})
|
|
f.ServeJson(map[string]interface{}{"success": success, "msg": msg})
|
|
}
|
|
}
|
|
|
|
|
|
func (f *Front) SpiderUpdate() {
|
|
func (f *Front) SpiderUpdate() {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
- state, _ := f.GetInteger("state")
|
|
|
|
|
|
+ stype, _ := f.GetInteger("stype")
|
|
reason := "批量处理无需更新"
|
|
reason := "批量处理无需更新"
|
|
- if state == 4 { //批量直接发布
|
|
|
|
|
|
+ if stype == 4 { //批量直接发布
|
|
reason = "批量处理直接发布"
|
|
reason = "批量处理直接发布"
|
|
}
|
|
}
|
|
ids := strings.Split(f.GetString("ids"), ",")
|
|
ids := strings.Split(f.GetString("ids"), ",")
|
|
for _, id := range ids {
|
|
for _, id := range ids {
|
|
- TagToSpiderWarnErr(state, id, reason, map[string]interface{}{})
|
|
|
|
|
|
+ TagToSpiderWarnErr(stype, id, reason, map[string]interface{}{})
|
|
}
|
|
}
|
|
f.ServeJson(map[string]interface{}{"success": true})
|
|
f.ServeJson(map[string]interface{}{"success": true})
|
|
}
|
|
}
|
|
|
|
|
|
-func TagToSpiderWarnErr(state int, id, reason string, update map[string]interface{}) {
|
|
|
|
|
|
+func TagToSpiderWarnErr(stype int, id, reason string, update map[string]interface{}) {
|
|
defer qu.Catch()
|
|
defer qu.Catch()
|
|
set := map[string]interface{}{
|
|
set := map[string]interface{}{
|
|
"ok": true,
|
|
"ok": true,
|
|
- "state": state,
|
|
|
|
|
|
+ "stype": stype,
|
|
"reason": reason,
|
|
"reason": reason,
|
|
"updatetime": time.Now().Unix(),
|
|
"updatetime": time.Now().Unix(),
|
|
}
|
|
}
|
|
@@ -440,3 +384,21 @@ func (f *Front) FilterSave() {
|
|
// }
|
|
// }
|
|
// MgoS.Save(JyRecord, log_data)
|
|
// MgoS.Save(JyRecord, log_data)
|
|
//}
|
|
//}
|
|
|
|
+
|
|
|
|
+func updateBidding(errId, reasons string, data, update map[string]interface{}) (bool, string) {
|
|
|
|
+ title := qu.ObjToString(data["title"])
|
|
|
|
+ href := qu.ObjToString(data["href"])
|
|
|
|
+ spidercode := qu.ObjToString(data["spidercode"])
|
|
|
|
+ list, _ := MgoB.Find("bidding", map[string]interface{}{"title": title}, map[string]interface{}{"_id": -1}, map[string]interface{}{"title": 1, "href": 1, "spidercode": 1}, false, -1, -1)
|
|
|
|
+ for _, tmp := range *list {
|
|
|
|
+ hrefTmp := qu.ObjToString(tmp["href"])
|
|
|
|
+ spidercodeTmp := qu.ObjToString(tmp["spidercode"])
|
|
|
|
+ if hrefTmp == href && spidercodeTmp == spidercode {
|
|
|
|
+ if MgoB.UpdateById("bidding", tmp["_id"], map[string]interface{}{"$set": update}) {
|
|
|
|
+ TagToSpiderWarnErr(-1, errId, reasons, update) //spider_warn_err日志
|
|
|
|
+ return true, "修复成功;数据所在表:bidding;数据ID:" + mongodb.BsonIdToSId(tmp["_id"])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false, "未匹配到bidding信息"
|
|
|
|
+}
|