Browse Source

调整上架机制先下架在上架

maxiaoshan 3 years ago
parent
commit
8e0b01a85e
2 changed files with 25 additions and 19 deletions
  1. 1 1
      src/front/front.go
  2. 24 18
      src/front/spider.go

+ 1 - 1
src/front/front.go

@@ -39,7 +39,7 @@ type Front struct {
 	downSpider   xweb.Mapper `xweb:"/center/spider/download/(.*)"` //爬虫下载
 	downSpider   xweb.Mapper `xweb:"/center/spider/download/(.*)"` //爬虫下载
 	upState      xweb.Mapper `xweb:"/center/spider/upstate"`       //爬虫状态更新
 	upState      xweb.Mapper `xweb:"/center/spider/upstate"`       //爬虫状态更新
 	assort       xweb.Mapper `xweb:"/center/spider/assort"`        //审核人员分类
 	assort       xweb.Mapper `xweb:"/center/spider/assort"`        //审核人员分类
-	batchShelves xweb.Mapper `xweb:"/center/spider/batchShelves"`  //爬虫状态更新
+	batchShelves xweb.Mapper `xweb:"/center/spider/batchShelves"`  //批量上下架
 	checktime    xweb.Mapper `xweb:"/center/spider/checktime"`     //爬虫核对
 	checktime    xweb.Mapper `xweb:"/center/spider/checktime"`     //爬虫核对
 	disables     xweb.Mapper `xweb:"/center/spider/disable"`       //批量作废
 	disables     xweb.Mapper `xweb:"/center/spider/disable"`       //批量作废
 	changeEvent  xweb.Mapper `xweb:"/center/changeEvent"`          //节点更新
 	changeEvent  xweb.Mapper `xweb:"/center/changeEvent"`          //节点更新

+ 24 - 18
src/front/spider.go

@@ -940,17 +940,21 @@ func UpStateAndUpSpider(code, id, reason, username string, state int) (bool, err
 		}
 		}
 		//oldstate := qu.IntAll(one["state"])
 		//oldstate := qu.IntAll(one["state"])
 		switch state {
 		switch state {
-		case Sp_state_4: //作废
+		case Sp_state_4, Sp_state_6: //作废、下架
 			// if oldstate == Sp_state_5 {
 			// if oldstate == Sp_state_5 {
 			// 	upresult = false
 			// 	upresult = false
 			// 	err = errors.New("已上架不允许作废")
 			// 	err = errors.New("已上架不允许作废")
 			// } else {
 			// } else {
 			// 	upresult = true
 			// 	upresult = true
 			// }
 			// }
-			upresult, err = spider.UpdateSpiderByCodeState(code, "6", event) //下架
-		case Sp_state_5, Sp_state_6: //上下架
-			upresult, err = spider.UpdateSpiderByCodeState(code, fmt.Sprint(state), event)
-			//log.Println(upresult, err)
+			upresult, err = spider.UpdateSpiderByCodeState(code, fmt.Sprint(state), event) //下架
+		case Sp_state_5: //上架(爬虫端在更新上架的时候为了更新内存中字段,采用先下架在上架)
+			upresult, err = spider.UpdateSpiderByCodeState(code, "6", event)
+			qu.Debug("下架:", upresult, code)
+			if upresult && err == nil {
+				upresult, err = spider.UpdateSpiderByCodeState(code, fmt.Sprint(state), event)
+				qu.Debug("上架:", upresult, code)
+			}
 		default:
 		default:
 			upresult = true
 			upresult = true
 			err = nil
 			err = nil
@@ -985,19 +989,21 @@ func UpStateAndUpSpider(code, id, reason, username string, state int) (bool, err
 					upset["disablereason"] = reason
 					upset["disablereason"] = reason
 					upset["modifytime"] = time.Now().Unix()
 					upset["modifytime"] = time.Now().Unix()
 				}
 				}
-				upresult = mgdb.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": upset}, false, false)
-				if state == Sp_state_1 { //提交审核,验证是否提交成功
-					for i := 1; i <= 5; i++ { //解决提交不上,重试5次
-						lua := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": code})
-						tmpState := qu.IntAll(lua["state"])
-						if state == tmpState {
-							break
-						} else {
-							upresult = mgdb.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": upset}, false, false)
-							upresult = false
-						}
-					}
-				}
+				qu.Debug("set:", upset)
+				upresult = u.MgoE.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": upset}, false, false)
+				//upresult = mgdb.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": upset}, false, false)
+				// if state == Sp_state_1 { //提交审核,验证是否提交成功
+				// 	for i := 1; i <= 5; i++ { //解决提交不上,重试5次
+				// 		lua := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": code})
+				// 		tmpState := qu.IntAll(lua["state"])
+				// 		if state == tmpState {
+				// 			break
+				// 		} else {
+				// 			upresult = mgdb.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": upset}, false, false)
+				// 			upresult = false
+				// 		}
+				// 	}
+				// }
 				qu.Debug("提交日志:", code, upset, upresult)
 				qu.Debug("提交日志:", code, upset, upresult)
 				if upresult && (state == Sp_state_2 || state == Sp_state_3) { //打回、审核记录日志
 				if upresult && (state == Sp_state_2 || state == Sp_state_3) { //打回、审核记录日志
 					types := "打回"
 					types := "打回"