front.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. // front
  2. package front
  3. import (
  4. "fmt"
  5. "github.com/go-xweb/httpsession"
  6. "github.com/go-xweb/xweb"
  7. "github.com/lauyoume/gopinyin"
  8. "github.com/tealeg/xlsx"
  9. "io/ioutil"
  10. "log"
  11. "mongodb"
  12. "os"
  13. qu "qfw/util"
  14. "regexp"
  15. "sort"
  16. "spider"
  17. util "spiderutil"
  18. "strconv"
  19. "strings"
  20. "sync"
  21. task "taskManager"
  22. "time"
  23. u "util"
  24. )
  25. type Front struct {
  26. *xweb.Action
  27. login xweb.Mapper `xweb:"/"`
  28. logout xweb.Mapper `xweb:"/center/logout"` //退出
  29. loadIndex xweb.Mapper `xweb:"/center"` //控制中心
  30. spidernew xweb.Mapper `xweb:"/center/spider"` //爬虫新建
  31. reg xweb.Mapper `xweb:"/center/reg"` //爬虫注册
  32. assign xweb.Mapper `xweb:"/center/user/assign"` //分配爬虫
  33. auditExport xweb.Mapper `xweb:"/center/user/auditexport"` //导出审核日志
  34. loadSpider xweb.Mapper `xweb:"/center/spider/edit/(.*)"` //爬虫加载
  35. viewSpider xweb.Mapper `xweb:"/center/spider/view/(.*)"` //爬虫查看
  36. downSpider xweb.Mapper `xweb:"/center/spider/download/(.*)"` //爬虫下载
  37. upState xweb.Mapper `xweb:"/center/spider/upstate"` //爬虫状态更新
  38. assort xweb.Mapper `xweb:"/center/spider/assort"` //审核人员分类(无发布、需登录、无法处理、需删除)
  39. batchShelves xweb.Mapper `xweb:"/center/spider/batchShelves"` //批量上下架
  40. checktime xweb.Mapper `xweb:"/center/spider/checktime"` //爬虫核对
  41. disables xweb.Mapper `xweb:"/center/spider/disable"` //批量作废
  42. changeEvent xweb.Mapper `xweb:"/center/changeEvent"` //节点更新
  43. getJson xweb.Mapper `xweb:"/center/spider/json"` //
  44. //delRedis xweb.Mapper `xweb:"/center/spider/delRedis"` //清理Redis
  45. updateESP xweb.Mapper `xweb:"/center/spider/updateesp"` //修改爬虫的节点/状态/平台
  46. updatePendState xweb.Mapper `xweb:"/center/spider/updatePendState"` //更新爬虫挂起状态
  47. tagCode xweb.Mapper `xweb:"/center/spider/tagcode"` //标记爬虫
  48. spiderRemark xweb.Mapper `xweb:"/center/spider/spiderremark"` //标记爬虫
  49. spiderModel xweb.Mapper `xweb:"/center/model"` //获取补充模型
  50. runStep xweb.Mapper `xweb:"/center/run"` //方法测试
  51. spiderPass xweb.Mapper `xweb:"/center/spider/pass"` //整体测试
  52. runPinYin xweb.Mapper `xweb:"/center/runpy"` //获取拼音
  53. saveStep xweb.Mapper `xweb:"/center/save"` //爬虫保存
  54. saveJs xweb.Mapper `xweb:"/center/save/js"` //保存js
  55. loadModel xweb.Mapper `xweb:"/center/gmodel/(.*)"` //加载模型
  56. importdata xweb.Mapper `xweb:"/center/importdata"` //导入爬虫列表页面
  57. importLua xweb.Mapper `xweb:"/center/importlua"` //导入爬虫
  58. oldedit xweb.Mapper `xweb:"/center/oldedit"` //老文件编辑
  59. findName xweb.Mapper `xweb:"/center/findname"` //即时查询名称
  60. checkrepeat xweb.Mapper `xweb:"/center/spider/isrepeat"` //脚本代码判重
  61. heart xweb.Mapper `xweb:"/center/heart"` //心跳监控
  62. spiderCopy xweb.Mapper `xweb:"/center/spider/copy"` //补采复制爬虫
  63. spiderSplitCopy xweb.Mapper `xweb:"/center/spider/splitcopy"` //拆分复制爬虫
  64. spiderCloseErr xweb.Mapper `xweb:"/center/spider/closeerr"` //删除错误爬虫
  65. Base Base
  66. OtherBase OtherBase
  67. Step1 Step1
  68. Step2 Step2
  69. Step3 Step3
  70. StepRe3 StepRe3
  71. U U
  72. luaList xweb.Mapper `xweb:"/center/lualist.html"` //脚本管理
  73. user xweb.Mapper `xweb:"/center/user.html"` //用户管理
  74. delUser xweb.Mapper `xweb:"/center/user/del"` //删除用户
  75. updateUser xweb.Mapper `xweb:"/center/user/updateUser"` //修改用户信息
  76. checkUsenamer xweb.Mapper `xweb:"/center/user/checkUsenamer"` //校验用户名的唯一性
  77. checkEmail xweb.Mapper `xweb:"/center/user/checkEmail"` //校验邮箱的唯一性
  78. saveNewUser xweb.Mapper `xweb:"/center/user/saveNewUser"` //添加用户
  79. getCity xweb.Mapper `xweb:"/center/getCity"` //获取城市
  80. //补采信息
  81. supplementDayList xweb.Mapper `xweb:"/center/supplement/daylist"` //日补采列表
  82. supplementWeekList xweb.Mapper `xweb:"/center/supplement/weeklist"` //周补采列表
  83. }
  84. const Sp_state_0, Sp_state_1, Sp_state_2, Sp_state_3, Sp_state_4, Sp_state_5, Sp_state_6, Sp_state_7, Sp_state_8, Sp_state_9, Sp_state_10 = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 //0待完成,1待审核,2打回,3发布,4作废,5已上架,6已下架,7无发布,8需登录,9转python,10已删除
  85. var LuaReg = regexp.MustCompile(`(:(find|match)|string\.|com\.getPureContent)`)
  86. var spinfos sync.Map = sync.Map{}
  87. var SessMap map[string]*httpsession.Session
  88. var AutoTpl map[string]interface{}
  89. var Mails *util.Mail
  90. var Reg = regexp.MustCompile(`(http|https)://([\w]+\.)+[\w]+`)
  91. var ListFilterReg = regexp.MustCompile("关键词过滤")
  92. var ProjectHrefReg = regexp.MustCompile("projecthref")
  93. var Transfercode map[string]interface{}
  94. // 控制中心
  95. func (f *Front) LoadIndex() {
  96. auth := qu.IntAll(f.GetSession("auth"))
  97. if f.Method() == "POST" {
  98. start, _ := f.GetInteger("start")
  99. limit, _ := f.GetInteger("length")
  100. draw, _ := f.GetInteger("draw")
  101. searchStr := f.GetString("search[value]")
  102. event, _ := f.GetInteger("taskEvent") //节点
  103. //searchN := strings.Replace(searchStr, " ", "", -1)
  104. //search := strings.Replace(searchN, "\n", "", -1)
  105. search := strings.TrimSpace(searchStr)
  106. state, _ := f.GetInteger("state")
  107. urgency, _ := f.GetInteger("urgency") //节点
  108. platform := f.GetString("platform")
  109. modifyuser := f.GetString("modifyuser")
  110. infoformat, _ := f.GetInteger("infoformat") //节点
  111. query := map[string]interface{}{}
  112. if event > -1 {
  113. query["event"] = event
  114. }
  115. if urgency > -1 {
  116. query["urgency"] = urgency
  117. }
  118. if platform != "-1" {
  119. query["platform"] = platform
  120. }
  121. if modifyuser != "-1" {
  122. query["modifyuser"] = modifyuser
  123. }
  124. if infoformat > -1 {
  125. query["infoformat"] = infoformat
  126. }
  127. if search != "" {
  128. query["$or"] = []interface{}{
  129. map[string]interface{}{"code": map[string]interface{}{"$regex": search}},
  130. map[string]interface{}{"createuser": map[string]interface{}{"$regex": search}},
  131. map[string]interface{}{"param_common.1": map[string]interface{}{"$regex": search}},
  132. }
  133. }
  134. if auth == u.Role_Examine { //审核员
  135. if state > -1 {
  136. query["state"] = state
  137. } else {
  138. query["state"] = Sp_state_1
  139. }
  140. } else if auth == u.Role_Dev { //开发员
  141. if state > -1 {
  142. query["state"] = state
  143. }
  144. query["createuserid"] = f.GetSession("userid")
  145. } else { //管理员
  146. if state > -1 {
  147. query["state"] = state
  148. }
  149. }
  150. sort := `{"%s":%d}`
  151. orderIndex := f.GetString("order[0][column]")
  152. orderName := f.GetString(fmt.Sprintf("columns[%s][data]", orderIndex))
  153. orderType := 1
  154. if f.GetString("order[0][dir]") != "asc" {
  155. orderType = -1
  156. }
  157. if orderName == "param_common" {
  158. orderName = orderName + ".1"
  159. }
  160. sort = fmt.Sprintf(sort, orderName, orderType)
  161. page := start / 10
  162. //log.Println("sort", sort, orderName)
  163. qu.Debug("query:", query, "sort:", sort)
  164. //luas := *mgdb.Find("luaconfig", query, sort, list_fields, false, start, limit)
  165. //count := mgdb.Count("luaconfig", query)
  166. luas, _ := u.MgoEB.Find("luaconfig", query, sort, map[string]interface{}{"str_list": 0, "str_content": 0}, false, start, limit)
  167. count := u.MgoEB.Count("luaconfig", query)
  168. for k, v := range *luas {
  169. v["num"] = k + 1 + page*10
  170. if v["modifytime"] != nil {
  171. v["modifytime"] = time.Unix(v["modifytime"].(int64), 0).Format("2006-01-02 15:04:05")
  172. } else {
  173. v["modifytime"] = "-"
  174. }
  175. if v["modifyuser"] == nil {
  176. v["modifytime"] = "-"
  177. }
  178. v["encode"] = util.Se.Encode2Hex(fmt.Sprint(v["code"]))
  179. if v["event"] == nil { //节点
  180. v["event"] = 0
  181. }
  182. user, _ := u.MgoEB.FindOne("user", map[string]interface{}{"s_name": qu.ObjToString(v["createuser"])})
  183. //v["state"] = LuaStateMap[qu.IntAll(v["state"])]
  184. v["i_scope"] = (*user)["i_scope"]
  185. }
  186. f.ServeJson(map[string]interface{}{"draw": draw, "data": luas, "recordsFiltered": count, "recordsTotal": count})
  187. } else {
  188. events := []string{}
  189. for k, _ := range util.Config.Uploadevents {
  190. events = append(events, k)
  191. }
  192. f.T["modifyusers"] = task.GetModifyUsers()
  193. sort.Strings(events)
  194. f.T["events"] = events
  195. f.Render("index.html", &f.T)
  196. }
  197. }
  198. func (f *Front) Checkrepeat() {
  199. code := f.GetString("code")
  200. //one := *mgdb.FindOne("luaconfig", bson.M{"code": code})
  201. one, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
  202. if len(*one) > 0 {
  203. f.ServeJson("y")
  204. } else {
  205. f.ServeJson("n")
  206. }
  207. }
  208. // 新建
  209. func (f *Front) Spidernew() error {
  210. auth := qu.IntAll(f.GetSession("auth"))
  211. if auth != u.Role_Admin {
  212. return nil
  213. }
  214. copy := f.GetString("copy")
  215. if copy != "" {
  216. //one := *mgdb.FindOne("luaconfig", bson.M{"code": copy})
  217. one, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": copy})
  218. delete((*one), "_id")
  219. delete((*one), "code")
  220. base := (*one)["param_common"].([]interface{})
  221. base[0] = ""
  222. base[1] = ""
  223. (*one)["param_common"] = base
  224. f.T["lua"] = one
  225. }
  226. f.T["isflow"] = 1 //新建爬虫时,初始化isflow的值
  227. f.T["actiontext"] = "新建"
  228. f.T["restate"] = 4 //此处设置restate=4无意义,只为了页面不报错
  229. f.T["areas"] = u.Area //
  230. f.T["citys"] = u.City //
  231. f.T["provinces"] = u.Province //
  232. return f.Render("spideredit.html", &f.T)
  233. }
  234. // 得到模型
  235. func (f *Front) SpiderModel() {
  236. f.ServeJson(util.Config.Model)
  237. }
  238. func (f *Front) RunPinYin() {
  239. word := f.GetString("word")
  240. str := gopinyin.Convert(word, true)
  241. f.Write(str)
  242. }
  243. type U struct {
  244. User string
  245. Name string
  246. Pwd string
  247. }
  248. func (f *Front) Reg() {
  249. }
  250. func (f *Front) ImportLua() {
  251. auth := qu.IntAll(f.GetSession("auth"))
  252. if auth != u.Role_Admin {
  253. f.ServeJson("没有权限")
  254. return
  255. }
  256. if f.Method() == "POST" {
  257. mf, _, err := f.GetFile("xlsx")
  258. errorinfo := map[string]interface{}{}
  259. if err == nil {
  260. binary, _ := ioutil.ReadAll(mf)
  261. xls, _ := xlsx.OpenBinary(binary)
  262. sheet := xls.Sheets[0]
  263. rows := sheet.Rows
  264. for k, v := range rows {
  265. if k != 0 {
  266. cells := v.Cells
  267. if cells[1].Value != "" {
  268. code := cells[1].Value
  269. code = u.SymbolReg.ReplaceAllString(code, "")
  270. query := map[string]interface{}{"code": cells[1].Value}
  271. rs, _ := u.MgoEB.FindOne("import", query)
  272. if len(*rs) > 0 {
  273. errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫代码重复,请修改"
  274. continue
  275. }
  276. o := make(map[string]interface{})
  277. o["name"] = cells[0].Value
  278. o["code"] = code
  279. o["channel"] = cells[2].Value
  280. spiderremark := cells[3].Value
  281. if spiderremark == "" {
  282. spiderremark = `采集“` + cells[2].Value + `”栏目(含子栏目)`
  283. }
  284. o["spiderremark"] = spiderremark
  285. //重复域名的网站不再新增爬虫
  286. href := cells[4].Value
  287. one, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"href": href})
  288. if len(*one) > 0 {
  289. errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫" + cells[1].Value + ",该栏目已存在,请确认"
  290. //continue
  291. }
  292. o["channeladdr"] = href
  293. o["author"] = cells[5].Value
  294. o["timestamp"] = time.Now().Unix()
  295. o["status"] = 1
  296. o["next"] = cells[5].Value
  297. o["event"] = cells[6].Value
  298. o["incrementevent"] = cells[7].Value
  299. if cells[8].Value == "是" {
  300. o["isflow"] = 1
  301. } else {
  302. o["isflow"] = 0
  303. }
  304. if cells[9].Value == "紧急" {
  305. o["urgency"] = 1
  306. } else {
  307. o["urgency"] = 0
  308. }
  309. o["platform"] = cells[10].Value
  310. o["area"] = cells[11].Value
  311. o["city"] = cells[12].Value
  312. o["district"] = cells[13].Value
  313. weigh, _ := cells[14].Int()
  314. o["weight"] = weigh
  315. //爬虫类型
  316. infoformat, _ := cells[15].Int()
  317. if infoformat < 1 {
  318. errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫" + cells[1].Value + ",缺少爬虫类型信息"
  319. continue
  320. }
  321. o["infoformat"] = infoformat
  322. //存储表
  323. coll := cells[16].Value
  324. if strings.Contains(code, "bidding") {
  325. errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行爬虫" + cells[1].Value + ",存储表错误"
  326. continue
  327. }
  328. o["coll"] = coll
  329. //table := cells[6].Value
  330. //o["table"] = table
  331. //o["transfercode"] = qu.IntAll(Transfercode[table])
  332. ok, name := saveLua(o) //保存爬虫
  333. if ok == false {
  334. errorinfo[cells[1].Value] = "第" + strconv.Itoa(k) + "行找不到作者,已经过滤"
  335. } else {
  336. o["author"] = name
  337. o["importuser"] = f.GetSession("username")
  338. u.MgoEB.Save("import", o)
  339. }
  340. }
  341. }
  342. }
  343. f.ServeJson(errorinfo)
  344. } else {
  345. f.ServeJson(false)
  346. }
  347. }
  348. }
  349. func saveLua(o map[string]interface{}) (bool, string) {
  350. AutoTpl["Base.SpiderName"] = o["name"]
  351. AutoTpl["Base.SpiderCode"] = o["code"]
  352. AutoTpl["Base.SpiderChannel"] = o["channel"]
  353. AutoTpl["Base.SpiderTargetChannelUrl"] = o["channeladdr"]
  354. author := o["author"].(string)
  355. one, _ := u.MgoEB.FindOne("user", map[string]interface{}{"s_email": author})
  356. id := mongodb.BsonIdToSId((*one)["_id"])
  357. if len(*one) == 0 {
  358. return false, ""
  359. }
  360. common := []interface{}{
  361. AutoTpl["Base.SpiderCode"],
  362. AutoTpl["Base.SpiderName"],
  363. AutoTpl["Base.SpiderChannel"],
  364. AutoTpl["Base.SpiderDownDetailPage"],
  365. AutoTpl["Base.SpiderStartPage"],
  366. AutoTpl["Base.SpiderMaxPage"],
  367. AutoTpl["Base.SpiderRunRate"],
  368. //AutoTpl["Base.Spider2Collection"],
  369. //"bidding", //爬虫导入新建默认为bidding
  370. qu.ObjToString(o["coll"]),
  371. AutoTpl["Base.SpiderPageEncoding"],
  372. AutoTpl["Base.SpiderStoreMode"],
  373. AutoTpl["Base.SpiderStoreToMsgEvent"],
  374. AutoTpl["Base.SpiderTargetChannelUrl"],
  375. AutoTpl["Base.SpiderLastDownloadTime"],
  376. AutoTpl["Base.SpiderIsHistoricalMend"],
  377. AutoTpl["Base.SpiderIsMustDownload"],
  378. }
  379. ptime := []interface{}{
  380. AutoTpl["Step1.DateFormat"],
  381. AutoTpl["Step1.Address"],
  382. AutoTpl["Step1.ContentChooser"],
  383. }
  384. list := []interface{}{
  385. AutoTpl["Step2.Listadd"],
  386. AutoTpl["Step2.Listadds"],
  387. AutoTpl["Step2.BlockChooser"],
  388. AutoTpl["Step2.AddressChooser"],
  389. AutoTpl["Step2.TitleChooser"],
  390. AutoTpl["Step2.DateChooser"],
  391. AutoTpl["Step2.DateFormat"],
  392. }
  393. content := []interface{}{
  394. AutoTpl["Step3.ContentChooser"],
  395. AutoTpl["Step3.ElementChooser"],
  396. }
  397. param := map[string]interface{}{}
  398. param["param_common"] = common
  399. //向导模式
  400. param["param_time"] = ptime
  401. param["param_list"] = list
  402. param["param_content"] = content
  403. param["type_time"] = 0
  404. param["type_list"] = 0
  405. param["type_content"] = 0
  406. //专家模式
  407. param["str_time"] = ""
  408. param["str_list"] = ""
  409. param["str_content"] = ""
  410. param["comeintime"] = time.Now().Unix()
  411. param["code"] = o["code"]
  412. param["site"] = o["name"]
  413. param["href"] = o["channeladdr"]
  414. param["channel"] = o["channel"]
  415. param["createuser"] = (*one)["s_name"]
  416. param["createuserid"] = id
  417. param["createuseremail"] = (*one)["s_email"]
  418. param["modifyuser"] = (*one)["s_name"]
  419. param["modifyuserid"] = id
  420. param["modifytime"] = time.Now().Unix()
  421. param["state"] = 0 //未完成
  422. if qu.IntAll(o["event"]) > 0 {
  423. param["event"] = qu.IntAll(o["event"])
  424. }
  425. s_model := "bid"
  426. configModel := util.Config.Model[s_model]
  427. model := map[string]interface{}{}
  428. for k, _ := range configModel {
  429. model[k] = qu.ObjToString(o[k])
  430. }
  431. param["model"] = model
  432. param["next"] = o["next"]
  433. param["urgency"] = o["urgency"]
  434. param["isflow"] = o["isflow"]
  435. param["spidertype"] = "history"
  436. param["spiderremark"] = o["spiderremark"]
  437. incrementevent := qu.ObjToString(o["incrementevent"])
  438. if movevent, ok := util.Config.Uploadevents[incrementevent].(string); ok && movevent != "" {
  439. param["spidermovevent"] = movevent
  440. }
  441. //} else {
  442. // param["spidermovevent"] = "7700"
  443. //}
  444. param["incrementevent"] = qu.IntAll(o["incrementevent"])
  445. param["platform"] = o["platform"]
  446. param["weight"] = o["weight"]
  447. param["infoformat"] = o["infoformat"]
  448. infoformat := qu.IntAll(o["infoformat"])
  449. infotype := "招标"
  450. if infoformat == 2 {
  451. infotype = "拟建/审批"
  452. } else if infoformat == 3 {
  453. infotype = "产权"
  454. } else if infoformat == 4 {
  455. infotype = "舆情"
  456. }
  457. //默认字段
  458. param["spidercompete"] = true //2021-11-20后爬虫加此字段(表示新爬虫,剑鱼网站不展示原文)
  459. param["spiderhistorymaxpage"] = 1 //历史最大页
  460. param["pendstate"] = 0 //
  461. param["grade"] = 0 //爬虫难易度(主要用于python爬虫使用)
  462. //qu.Debug("param---", param)
  463. ok := spider.SaveSpider(o["code"].(string), param)
  464. if ok { //保存成功,校验新导入的爬虫对应站点是否存在,否则加站点记录
  465. if u.MgoEB.Count("site", map[string]interface{}{"site": o["name"]}) == 0 {
  466. qu.Debug("补充站点信息:", o["name"])
  467. domain := u.DomainReg.FindString(qu.ObjToString(AutoTpl["Base.SpiderTargetChannelUrl"]))
  468. if domain != "" {
  469. domain = u.ReplaceReg.ReplaceAllString(domain, "")
  470. }
  471. siteInfo := map[string]interface{}{
  472. "site": o["name"],
  473. "domain": domain, //
  474. "another_name": "",
  475. "area": qu.ObjToString(model["area"]),
  476. "city": qu.ObjToString(model["city"]),
  477. "district": qu.ObjToString(model["district"]),
  478. "site_type": "",
  479. "second_type": "",
  480. "industry": "",
  481. "p_site": "",
  482. "s_site": "",
  483. "remarktime": time.Now().Unix(),
  484. "event": incrementevent,
  485. "platform": o["platform"],
  486. "spider_status": "0/1",
  487. "updatetime": time.Now().Unix(),
  488. "delete": false,
  489. "comeintime": time.Now().Unix(),
  490. "important": 0,
  491. "site_status": 1,
  492. "lasttime": int64(0),
  493. "site_datanum": 0,
  494. "period": float32(0),
  495. "infotype": infotype,
  496. "sponsor": "",
  497. "isneedregister": 0,
  498. "isregistered": 0,
  499. "special_type": "",
  500. "account": "",
  501. "password": "",
  502. "f_area": "",
  503. "f_city": "",
  504. "f_district": "",
  505. }
  506. u.MgoEB.Save("site", siteInfo)
  507. }
  508. }
  509. return ok, (*one)["s_name"].(string)
  510. }
  511. func (f *Front) Importdata() {
  512. auth := qu.IntAll(f.GetSession("auth"))
  513. if auth == u.Role_Admin {
  514. if f.Method() == "GET" {
  515. f.Render("import.html")
  516. } else {
  517. query := map[string]interface{}{}
  518. searchStr := f.GetString("search[value]")
  519. search := strings.TrimSpace(searchStr)
  520. if search != "" {
  521. query["$or"] = []interface{}{
  522. map[string]interface{}{"code": map[string]interface{}{"$regex": search}},
  523. map[string]interface{}{"name": map[string]interface{}{"$regex": search}},
  524. }
  525. }
  526. start, _ := f.GetInteger("start")
  527. limit, _ := f.GetInteger("length")
  528. draw, _ := f.GetInteger("draw")
  529. data, _ := u.MgoEB.Find("import", query, `{"timestamp": -1}`, nil, false, start, limit)
  530. count := u.MgoEB.Count("import", query)
  531. f.ServeJson(map[string]interface{}{
  532. "draw": draw,
  533. "data": data,
  534. "recordsFiltered": count,
  535. "recordsTotal": count,
  536. })
  537. }
  538. } else {
  539. f.Write("您没有导入脚本的权限")
  540. }
  541. }
  542. func Wlog(name, code, man, manid, types string, content map[string]interface{}) {
  543. obj := map[string]interface{}{
  544. "name": name,
  545. "code": code,
  546. "man": man,
  547. "manid": manid,
  548. "types": types,
  549. "time": time.Now().Unix(),
  550. "content": content,
  551. }
  552. u.MgoEB.Save("lua_logs", obj)
  553. }
  554. func (f *Front) Oldedit() {
  555. if f.Method() == "GET" {
  556. f.Render("oldedit.html")
  557. } else {
  558. }
  559. }
  560. func (f *Front) FindName() {
  561. words := f.GetString("words")
  562. if words == "" {
  563. f.ServeJson(map[string]interface{}{"error": "null"})
  564. }
  565. //query := bson.M{"$or": []interface{}{
  566. // bson.M{"param_common.0": bson.M{"$regex": words}},
  567. // bson.M{"param_common.1": bson.M{"$regex": words}},
  568. // bson.M{"createuser": bson.M{"$regex": words}},
  569. //}, "oldlua": bson.M{"$exists": false}}
  570. query := map[string]interface{}{
  571. "$or": []interface{}{
  572. map[string]interface{}{"param_common.0": map[string]interface{}{"$regex": words}},
  573. map[string]interface{}{"param_common.1": map[string]interface{}{"$regex": words}},
  574. map[string]interface{}{"createuser": map[string]interface{}{"$regex": words}},
  575. },
  576. "oldlua": map[string]interface{}{
  577. "$exists": false,
  578. },
  579. }
  580. //rs := *mgdb.Find("luaconfig", query, bson.M{"modifytime": -1}, bson.M{"param_common": 1}, false, -1, -1)
  581. rs, _ := u.MgoEB.Find("luaconfig", query, map[string]interface{}{"modifytime": -1}, map[string]interface{}{"param_common": 1}, false, -1, -1)
  582. if len(*rs) > 0 {
  583. f.ServeJson(map[string]interface{}{"data": (*rs)})
  584. } else {
  585. f.ServeJson(map[string]interface{}{"error": "data"})
  586. }
  587. }
  588. // 分配爬虫
  589. func (f *Front) Assign() {
  590. auth := qu.IntAll(f.GetSession("auth"))
  591. if auth != u.Role_Admin {
  592. f.Write("n")
  593. return
  594. }
  595. codes := f.GetString("codes")
  596. userid := f.GetString("userid") //分配给谁
  597. codesarr := strings.Split(codes, ",") //被分配的爬虫
  598. user, _ := u.MgoEB.FindById("user", userid, nil)
  599. if user != nil && len(*user) > 0 {
  600. name := qu.ObjToString((*user)["s_name"])
  601. query := map[string]interface{}{
  602. "code": map[string]interface{}{
  603. "$in": codesarr,
  604. },
  605. }
  606. qu.Debug(query)
  607. set := map[string]interface{}{
  608. "$set": map[string]interface{}{
  609. "createuserid": userid,
  610. "createuser": name,
  611. "createuseremail": (*user)["s_email"],
  612. "modifyuser": name,
  613. "modifyuserid": userid,
  614. "platform": (*user)["s_platform"],
  615. },
  616. }
  617. //b := u.MgoE.Update("luaconfig", query, set, false, true)
  618. b := u.MgoEB.Update("luaconfig", query, set, false, true)
  619. if b {
  620. go editModify(codesarr, userid, name) //修改爬虫对应任务的维护人
  621. f.Write("y")
  622. } else {
  623. f.Write("n")
  624. }
  625. } else {
  626. f.Write("null")
  627. }
  628. }
  629. // 审核日志导出
  630. func (f *Front) AuditExport() {
  631. auth := qu.IntAll(f.GetSession("auth"))
  632. if auth > u.Role_Admin {
  633. exportnames := f.GetString("exportnames")
  634. exporttype := f.GetString("exporttype")
  635. starttime := f.GetString("starttime")
  636. endtime := f.GetString("endtime")
  637. qu.Debug(exportnames, exporttype, starttime, endtime)
  638. file, err := xlsx.OpenFile("爬虫审核记录.xlsx")
  639. if err != nil {
  640. f.Write("文件打开失败!")
  641. return
  642. }
  643. sheet := file.Sheets[0]
  644. exportLogs(sheet, exportnames, exporttype, starttime, endtime) //导出数据
  645. fname := fmt.Sprintf("爬虫审核打回记录%d.xlsx", time.Now().Unix())
  646. err = file.Save(fname)
  647. if err != nil {
  648. qu.Debug("Save Excel" + fname + "Error")
  649. f.ServeJson("导出失败")
  650. return
  651. }
  652. f.ResponseWriter.Header().Add("Content-Disposition", "attachment;filename=爬虫审核打回记录.xlsx")
  653. f.ServeFile(fname)
  654. go func(path string) { //删除
  655. time.Sleep(time.Second * 30)
  656. os.Remove(path)
  657. }(fname)
  658. } else {
  659. f.Write("您没有权限")
  660. }
  661. }
  662. func exportLogs(sheet *xlsx.Sheet, exportnames, exporttype, starttime, endtime string) {
  663. st, _ := time.ParseInLocation(qu.Date_Short_Layout, starttime, time.Local)
  664. et, _ := time.ParseInLocation(qu.Date_Short_Layout, endtime, time.Local)
  665. query := map[string]interface{}{
  666. "comeintime": map[string]interface{}{
  667. "$gte": st.Unix(),
  668. "$lt": et.Unix(),
  669. },
  670. }
  671. if exporttype == "repulse" { //打回
  672. query["types"] = "打回"
  673. } else if exporttype == "audit" { //审核
  674. query["types"] = "审核"
  675. }
  676. users := map[string]bool{}
  677. for _, user := range strings.Split(exportnames, ",") {
  678. users[user] = true
  679. }
  680. qu.Debug("audit log query:", query)
  681. sess := u.MgoEB.GetMgoConn()
  682. defer u.MgoEB.DestoryMongoConn(sess)
  683. lock := &sync.Mutex{}
  684. wg := &sync.WaitGroup{}
  685. ch := make(chan bool, 10)
  686. n := 0
  687. it := sess.DB(u.MgoEB.DbName).C("lua_logs_auditor").Find(&query).Iter()
  688. count, _ := sess.DB(u.MgoEB.DbName).C("lua_logs_auditor").Find(&query).Count()
  689. qu.Debug("count:", count)
  690. for tmp := map[string]interface{}{}; it.Next(tmp); n++ {
  691. ch <- true
  692. wg.Add(1)
  693. go func(tmp map[string]interface{}) {
  694. defer func() {
  695. <-ch
  696. wg.Done()
  697. }()
  698. id := mongodb.BsonIdToSId(tmp["_id"])
  699. auditor := qu.ObjToString(tmp["auditor"])
  700. code := qu.ObjToString(tmp["code"])
  701. comeintime := qu.Int64All(tmp["comeintime"])
  702. comeintime_z := qu.FormatDateByInt64(&comeintime, qu.Date_Full_Layout)
  703. event := qu.IntAll(tmp["event"])
  704. modifytime := qu.Int64All(tmp["modifytime"])
  705. modifytime_z := qu.FormatDateByInt64(&modifytime, qu.Date_Full_Layout)
  706. reason := qu.ObjToString(tmp["reason"])
  707. types := qu.ObjToString(tmp["types"])
  708. spideruser := qu.ObjToString(tmp["spideruser"])
  709. if !users[spideruser] {
  710. return
  711. }
  712. lock.Lock()
  713. row := sheet.AddRow()
  714. lock.Unlock()
  715. row.AddCell().SetValue(id)
  716. row.AddCell().SetValue(auditor)
  717. row.AddCell().SetValue(code)
  718. row.AddCell().SetValue(comeintime)
  719. row.AddCell().SetValue(comeintime_z)
  720. row.AddCell().SetValue(event)
  721. row.AddCell().SetValue(modifytime)
  722. row.AddCell().SetValue(modifytime_z)
  723. row.AddCell().SetValue(reason)
  724. row.AddCell().SetValue(spideruser)
  725. row.AddCell().SetValue(types)
  726. }(tmp)
  727. tmp = make(map[string]interface{})
  728. }
  729. }
  730. // 修改维护人
  731. func editModify(codesarr []string, userid, name string) {
  732. qu.Debug("修改爬虫对应任务的维护人:", name, codesarr)
  733. //修改modifyid和modify
  734. query := map[string]interface{}{
  735. "s_code": map[string]interface{}{
  736. "$in": codesarr,
  737. },
  738. "i_state": map[string]interface{}{
  739. "$nin": []int{4, 6},
  740. },
  741. }
  742. set := map[string]interface{}{
  743. "$set": map[string]interface{}{
  744. "s_modify": name,
  745. "s_modifyid": userid,
  746. },
  747. }
  748. b := u.MgoEB.Update("task", query, set, false, true)
  749. qu.Debug("任务重新分配成功", b)
  750. }
  751. func (f *Front) UpdatePendState() {
  752. success := false
  753. pendstate, _ := f.GetInteger("pendstate")
  754. code := f.GetString("code")
  755. stype := f.GetString("stype")
  756. qu.Debug(code, stype, pendstate)
  757. //success = u.MgoE.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"pendstate": pendstate}}, false, false)
  758. success = u.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"pendstate": pendstate, "pendtime": time.Now().Unix()}}, false, false)
  759. if success {
  760. if stype == "code" { //爬虫挂起时,关闭所有任务
  761. u.MgoEB.Update("task", map[string]interface{}{"s_code": code, "i_state": map[string]interface{}{"$ne": 6}}, map[string]interface{}{"$set": map[string]interface{}{"i_state": 6, "l_pendtime": time.Now().Unix()}}, false, true)
  762. } else if stype == "task" { //任务挂起任务时任务关闭
  763. id := f.GetString("id")
  764. u.MgoEB.UpdateById("task", id, map[string]interface{}{"$set": map[string]interface{}{"i_pendstate": pendstate, "i_state": 6, "l_pendtime": time.Now().Unix()}})
  765. }
  766. }
  767. f.ServeJson(map[string]interface{}{"success": success})
  768. }
  769. func (f *Front) UpdateESP() {
  770. val := f.GetString("val")
  771. w := f.GetString("w")
  772. id := f.GetString("id")
  773. code := f.GetString("c")
  774. query := map[string]interface{}{
  775. "_id": mongodb.StringTOBsonId(id),
  776. }
  777. set := map[string]interface{}{}
  778. update := map[string]interface{}{
  779. "$set": set,
  780. }
  781. //one, _ := u.MgoE.FindById("luaconfig", id, nil)
  782. one, _ := u.MgoEB.FindById("luaconfig", id, nil)
  783. if len(*one) == 0 {
  784. f.Write("n")
  785. return
  786. }
  787. if w == "infoformat" {
  788. infoformat, _ := f.GetInteger("val")
  789. set["infoformat"] = infoformat
  790. } else if w == "urgency" { //修改紧急度
  791. urgency, _ := f.GetInteger("val")
  792. set["urgency"] = urgency
  793. } else if w == "state" { //无效爬虫改为待完成
  794. tmpEvent := qu.IntAll((*one)["event"])
  795. if one != nil && len(*one) > 0 {
  796. if (*one)["incrementevent"] == nil && tmpEvent != 7000 { //除7000节点外没有incrementevent的要重新设置
  797. set["incrementevent"] = tmpEvent
  798. }
  799. }
  800. set["state"] = 0
  801. set["event"] = 7000
  802. set["spidertype"] = "history"
  803. go ModifyLogs_UpdateCodeState(code)
  804. //更新、新建任务
  805. //task, _ := u.MgoEB.FindOne("task", map[string]interface{}{"s_code": code, "i_state": map[string]interface{}{"$in": []int{0, 1, 2, 3, 5}}})
  806. //text := "指定追加描述:------------------------------\n无发布转待完成\n"
  807. //if len(*task) > 0 { //已有任务,更新
  808. // u.MgoEB.UpdateById("task", (*task)["_id"],
  809. // map[string]interface{}{
  810. // "$set": map[string]interface{}{
  811. // "i_state": 2,
  812. // "s_descript": qu.ObjToString((*task)["s_descript"]) + text,
  813. // "l_updatetime": time.Now().Unix(),
  814. // },
  815. // })
  816. //} else {
  817. // save := map[string]interface{}{
  818. // "s_channel": (*one)["channel"],
  819. // "i_event": (*one)["event"],
  820. // "i_frequencyerrtimes": 0,
  821. // "i_state": 2,
  822. // "s_descript": text,
  823. // "l_complete": time.Now().Unix() + int64(24*3600),
  824. // "s_urgency": "4",
  825. // "i_pendstate": 0,
  826. // "s_modifyid": (*one)["modifyuserid"],
  827. // "s_source": "人工",
  828. // "i_times": 0,
  829. // "l_comeintime": time.Now().Unix(),
  830. // "i_num": 0,
  831. // "s_modify": (*one)["modifyuser"],
  832. // "s_code": code,
  833. // "s_site": (*one)["site"],
  834. // "s_type": "0",
  835. // }
  836. // u.MgoEB.Save("task", save)
  837. //}
  838. } else if w == "platform" {
  839. set["platform"] = val
  840. set["comeintime"] = time.Now().Unix()
  841. if val != "golua平台" && val != "chrome" {
  842. b := u.MgoS.Update("spider_heart", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"del": true}}, false, true)
  843. qu.Debug("Del Heart:", b)
  844. b, err := spider.UpdateSpiderByCodeState(code, "6", qu.IntAll((*one)["event"])) //下架
  845. if b && err == nil {
  846. //历史节点下架为了避免线上运行爬虫待完成时改为7000采集历史,但是又转到其他平台,导致原线上运行节点爬虫并未下线,心跳异常
  847. if incrementevent := (*one)["incrementevent"]; incrementevent != nil {
  848. b, err = spider.UpdateSpiderByCodeState(code, "6", qu.IntAll(incrementevent))
  849. }
  850. //关闭任务
  851. u.MgoEB.Update("task", map[string]interface{}{"s_code": code, "i_state": map[string]interface{}{"$in": []int{0, 1, 2, 3, 5}}}, map[string]interface{}{"$set": map[string]interface{}{"i_state": 6}}, false, true)
  852. if b && err == nil {
  853. set["state"] = 0 //更新状态
  854. set["luauser"] = map[string]interface{}{
  855. "createuser": (*one)["createuser"],
  856. "createuserid": (*one)["createuserid"],
  857. "createuseremail": (*one)["createuseremail"],
  858. "modifyuser": (*one)["modifyuser"],
  859. "modifyuserid": (*one)["modifyuserid"],
  860. }
  861. } else {
  862. qu.Debug("历史节点下架失败")
  863. f.Write("n")
  864. return
  865. }
  866. } else {
  867. qu.Debug("增量节点下架失败")
  868. f.Write("n")
  869. return
  870. }
  871. //qu.Debug("下架:", upresult, code)
  872. //b, err := UpStateAndUpSpider(code, "", "", "", Sp_state_6) //线上爬虫下架
  873. //qu.Debug("爬虫下架成功:", b)
  874. //if !b || err != nil {
  875. // f.Write("n")
  876. // return
  877. //}
  878. }
  879. } else { //修改节点
  880. event, _ := strconv.Atoi(val)
  881. set["event"] = event
  882. set["incrementevent"] = event
  883. //state := f.GetString("s")
  884. //if state == "5" { //已上架状态改为下架
  885. code := f.GetString("c")
  886. set["state"] = 6
  887. b, err := UpStateAndUpSpider(code, "", "", "", Sp_state_6) //线上爬虫下架
  888. qu.Debug("爬虫下架成功:", b)
  889. if !b || err != nil {
  890. f.Write("n")
  891. return
  892. }
  893. //}
  894. }
  895. //if mgdb.Update("luaconfig", query, update, false, false) {
  896. if u.MgoEB.Update("luaconfig", query, update, false, false) {
  897. log.Println("Id:", id, " Update", w, val, "Success")
  898. f.Write("y")
  899. return
  900. } else {
  901. log.Println("Id:", id, " Update", w, val, "Failed")
  902. f.Write("n")
  903. return
  904. }
  905. f.Write("n")
  906. }
  907. func (f *Front) GetCity() {
  908. area := f.GetString("area")
  909. cityArr := []string{}
  910. cityArr = u.Province[area]
  911. f.ServeJson(cityArr)
  912. }
  913. func (f *Front) SpiderCopy() {
  914. defer qu.Catch()
  915. code := f.GetString("code")
  916. code = strings.TrimSpace(code)
  917. success := false
  918. text := ""
  919. encode := ""
  920. if code != "" {
  921. //lua := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": code})
  922. lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
  923. if len(*lua) > 0 {
  924. codeOld := qu.ObjToString((*lua)["code"])
  925. codeNew := codeOld + u.Bu
  926. //luaTmp := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": codeNew})
  927. luaTmp, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": codeNew})
  928. if len(*luaTmp) > 0 {
  929. f.ServeJson(map[string]interface{}{"success": false, "text": "已存在补漏爬虫"})
  930. return
  931. }
  932. //u.MgoE.Update("luaconfig", map[string]interface{}{"code": codeOld}, map[string]interface{}{"$set": map[string]interface{}{"relatecode": codeNew}}, false, false)
  933. u.MgoEB.Update("luaconfig", map[string]interface{}{"code": codeOld}, map[string]interface{}{"$set": map[string]interface{}{"relatecode": codeNew}}, false, false)
  934. (*lua)["code"] = codeNew
  935. (*lua)["relatecode"] = codeOld
  936. if param_common := (*lua)["param_common"].([]interface{}); len(param_common) < 13 {
  937. f.ServeJson(map[string]interface{}{"success": false, "text": "脚本异常,请联系管理员"})
  938. return
  939. } else {
  940. param_common = param_common[:13]
  941. param_common[0] = codeNew //code
  942. param_common = append(param_common, true) //历史补漏
  943. param_common = append(param_common, false) //强制下载
  944. (*lua)["param_common"] = param_common
  945. }
  946. str_list := qu.ObjToString((*lua)["str_list"])
  947. (*lua)["str_list"] = strings.ReplaceAll(str_list, codeOld, codeNew)
  948. (*lua)["comeintime"] = time.Now().Unix()
  949. (*lua)["modifytime"] = time.Now().Unix()
  950. (*lua)["spidertype"] = "increment"
  951. (*lua)["event"] = 7000
  952. (*lua)["state"] = 6
  953. id := u.MgoEB.Save("luaconfig", (*lua))
  954. if id != "" {
  955. success = true
  956. encode = util.Se.Encode2Hex(codeNew)
  957. } else {
  958. text = "新爬虫保存失败"
  959. }
  960. } else {
  961. text = "未查询到复制原"
  962. }
  963. } else {
  964. text = "脚本不能为空"
  965. }
  966. f.ServeJson(map[string]interface{}{"success": success, "text": text, "encode": encode})
  967. }
  968. func (f *Front) SpiderSplitCopy() {
  969. defer qu.Catch()
  970. code := f.GetString("code")
  971. code = strings.TrimSpace(code)
  972. num, _ := f.GetInteger("num")
  973. text := ""
  974. lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
  975. if len(*lua) > 0 {
  976. param_common := (*lua)["param_common"].([]interface{})
  977. str_list := qu.ObjToString((*lua)["str_list"])
  978. channelOld := qu.ObjToString((*lua)["channel"])
  979. copyNum := qu.IntAll((*lua)["copynum"]) //当前已经拆分了多少个爬虫
  980. delete(*lua, "relatecode") //删除关联爬虫字段
  981. for i := 1; i <= num; i++ {
  982. copyNum++
  983. var codeSuffix string
  984. if copyNum < 10 {
  985. codeSuffix = fmt.Sprintf("0%s", fmt.Sprint(copyNum))
  986. } else {
  987. codeSuffix = fmt.Sprint(copyNum)
  988. }
  989. (*lua)["code"] = code + "_" + codeSuffix
  990. (*lua)["channel"] = channelOld + "_" + codeSuffix
  991. (*lua)["str_list"] = strings.ReplaceAll(str_list, code, code+"_"+codeSuffix)
  992. (*lua)["comeintime"] = time.Now().Unix()
  993. (*lua)["modifytime"] = time.Now().Unix()
  994. (*lua)["state"] = 0
  995. param_common[0] = code + "_" + codeSuffix
  996. param_common[2] = channelOld + "_" + codeSuffix
  997. (*lua)["param_common"] = param_common
  998. u.MgoEB.Save("luaconfig", (*lua))
  999. }
  1000. u.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"copynum": copyNum}}, false, false)
  1001. } else {
  1002. text = "未查询到复制原"
  1003. }
  1004. f.ServeJson(map[string]interface{}{"text": text})
  1005. }
  1006. /*// 清理Redis
  1007. func (f *Front) DelRedis() {
  1008. hrefs := f.GetString("href")
  1009. hrefsarr := strings.Split(hrefs, ",")
  1010. auth := qu.IntAll(f.GetSession("auth"))
  1011. err := []string{}
  1012. if auth == u.Role_Admin { //权限控制
  1013. if len(hrefsarr) > 0 {
  1014. for k1, h := range hrefsarr {
  1015. href := Reg.FindString(h)
  1016. if href != "" {
  1017. href = "url_repeat_" + href + "*"
  1018. res := redis.GetKeysByPattern("title_repeat_judgement", href)
  1019. if res != nil {
  1020. for _, v := range res {
  1021. hf := string(v.([]uint8))
  1022. b := redis.Del("title_repeat_judgement", hf)
  1023. if !b {
  1024. err = append(err, "第"+strconv.Itoa(k1+1)+"个")
  1025. }
  1026. }
  1027. }
  1028. } else {
  1029. err = append(err, "第"+strconv.Itoa(k1+1)+"个")
  1030. }
  1031. }
  1032. }
  1033. } else {
  1034. err = append(err, "没有权限")
  1035. }
  1036. f.ServeJson(err)
  1037. }*/