front.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. "site_subtype": "",
  506. "site_toptype": "",
  507. "type_plate": "",
  508. }
  509. u.MgoEB.Save("site", siteInfo)
  510. }
  511. }
  512. return ok, (*one)["s_name"].(string)
  513. }
  514. func (f *Front) Importdata() {
  515. auth := qu.IntAll(f.GetSession("auth"))
  516. if auth == u.Role_Admin {
  517. if f.Method() == "GET" {
  518. f.Render("import.html")
  519. } else {
  520. query := map[string]interface{}{}
  521. searchStr := f.GetString("search[value]")
  522. search := strings.TrimSpace(searchStr)
  523. if search != "" {
  524. query["$or"] = []interface{}{
  525. map[string]interface{}{"code": map[string]interface{}{"$regex": search}},
  526. map[string]interface{}{"name": map[string]interface{}{"$regex": search}},
  527. }
  528. }
  529. start, _ := f.GetInteger("start")
  530. limit, _ := f.GetInteger("length")
  531. draw, _ := f.GetInteger("draw")
  532. data, _ := u.MgoEB.Find("import", query, `{"timestamp": -1}`, nil, false, start, limit)
  533. count := u.MgoEB.Count("import", query)
  534. f.ServeJson(map[string]interface{}{
  535. "draw": draw,
  536. "data": data,
  537. "recordsFiltered": count,
  538. "recordsTotal": count,
  539. })
  540. }
  541. } else {
  542. f.Write("您没有导入脚本的权限")
  543. }
  544. }
  545. func Wlog(name, code, man, manid, types string, content map[string]interface{}) {
  546. obj := map[string]interface{}{
  547. "name": name,
  548. "code": code,
  549. "man": man,
  550. "manid": manid,
  551. "types": types,
  552. "time": time.Now().Unix(),
  553. "content": content,
  554. }
  555. u.MgoEB.Save("lua_logs", obj)
  556. }
  557. func (f *Front) Oldedit() {
  558. if f.Method() == "GET" {
  559. f.Render("oldedit.html")
  560. } else {
  561. }
  562. }
  563. func (f *Front) FindName() {
  564. words := f.GetString("words")
  565. if words == "" {
  566. f.ServeJson(map[string]interface{}{"error": "null"})
  567. }
  568. //query := bson.M{"$or": []interface{}{
  569. // bson.M{"param_common.0": bson.M{"$regex": words}},
  570. // bson.M{"param_common.1": bson.M{"$regex": words}},
  571. // bson.M{"createuser": bson.M{"$regex": words}},
  572. //}, "oldlua": bson.M{"$exists": false}}
  573. query := map[string]interface{}{
  574. "$or": []interface{}{
  575. map[string]interface{}{"param_common.0": map[string]interface{}{"$regex": words}},
  576. map[string]interface{}{"param_common.1": map[string]interface{}{"$regex": words}},
  577. map[string]interface{}{"createuser": map[string]interface{}{"$regex": words}},
  578. },
  579. "oldlua": map[string]interface{}{
  580. "$exists": false,
  581. },
  582. }
  583. //rs := *mgdb.Find("luaconfig", query, bson.M{"modifytime": -1}, bson.M{"param_common": 1}, false, -1, -1)
  584. rs, _ := u.MgoEB.Find("luaconfig", query, map[string]interface{}{"modifytime": -1}, map[string]interface{}{"param_common": 1}, false, -1, -1)
  585. if len(*rs) > 0 {
  586. f.ServeJson(map[string]interface{}{"data": (*rs)})
  587. } else {
  588. f.ServeJson(map[string]interface{}{"error": "data"})
  589. }
  590. }
  591. // 分配爬虫
  592. func (f *Front) Assign() {
  593. auth := qu.IntAll(f.GetSession("auth"))
  594. if auth != u.Role_Admin {
  595. f.Write("n")
  596. return
  597. }
  598. codes := f.GetString("codes")
  599. userid := f.GetString("userid") //分配给谁
  600. codesarr := strings.Split(codes, ",") //被分配的爬虫
  601. user, _ := u.MgoEB.FindById("user", userid, nil)
  602. if user != nil && len(*user) > 0 {
  603. name := qu.ObjToString((*user)["s_name"])
  604. query := map[string]interface{}{
  605. "code": map[string]interface{}{
  606. "$in": codesarr,
  607. },
  608. }
  609. qu.Debug(query)
  610. set := map[string]interface{}{
  611. "$set": map[string]interface{}{
  612. "createuserid": userid,
  613. "createuser": name,
  614. "createuseremail": (*user)["s_email"],
  615. "modifyuser": name,
  616. "modifyuserid": userid,
  617. "platform": (*user)["s_platform"],
  618. },
  619. }
  620. //b := u.MgoE.Update("luaconfig", query, set, false, true)
  621. b := u.MgoEB.Update("luaconfig", query, set, false, true)
  622. if b {
  623. go editModify(codesarr, userid, name) //修改爬虫对应任务的维护人
  624. f.Write("y")
  625. } else {
  626. f.Write("n")
  627. }
  628. } else {
  629. f.Write("null")
  630. }
  631. }
  632. // 审核日志导出
  633. func (f *Front) AuditExport() {
  634. auth := qu.IntAll(f.GetSession("auth"))
  635. if auth > u.Role_Admin {
  636. exportnames := f.GetString("exportnames")
  637. exporttype := f.GetString("exporttype")
  638. starttime := f.GetString("starttime")
  639. endtime := f.GetString("endtime")
  640. qu.Debug(exportnames, exporttype, starttime, endtime)
  641. file, err := xlsx.OpenFile("爬虫审核记录.xlsx")
  642. if err != nil {
  643. f.Write("文件打开失败!")
  644. return
  645. }
  646. sheet := file.Sheets[0]
  647. exportLogs(sheet, exportnames, exporttype, starttime, endtime) //导出数据
  648. fname := fmt.Sprintf("爬虫审核打回记录%d.xlsx", time.Now().Unix())
  649. err = file.Save(fname)
  650. if err != nil {
  651. qu.Debug("Save Excel" + fname + "Error")
  652. f.ServeJson("导出失败")
  653. return
  654. }
  655. f.ResponseWriter.Header().Add("Content-Disposition", "attachment;filename=爬虫审核打回记录.xlsx")
  656. f.ServeFile(fname)
  657. go func(path string) { //删除
  658. time.Sleep(time.Second * 30)
  659. os.Remove(path)
  660. }(fname)
  661. } else {
  662. f.Write("您没有权限")
  663. }
  664. }
  665. func exportLogs(sheet *xlsx.Sheet, exportnames, exporttype, starttime, endtime string) {
  666. st, _ := time.ParseInLocation(qu.Date_Short_Layout, starttime, time.Local)
  667. et, _ := time.ParseInLocation(qu.Date_Short_Layout, endtime, time.Local)
  668. query := map[string]interface{}{
  669. "comeintime": map[string]interface{}{
  670. "$gte": st.Unix(),
  671. "$lt": et.Unix(),
  672. },
  673. }
  674. if exporttype == "repulse" { //打回
  675. query["types"] = "打回"
  676. } else if exporttype == "audit" { //审核
  677. query["types"] = "审核"
  678. }
  679. users := map[string]bool{}
  680. for _, user := range strings.Split(exportnames, ",") {
  681. users[user] = true
  682. }
  683. qu.Debug("audit log query:", query)
  684. sess := u.MgoEB.GetMgoConn()
  685. defer u.MgoEB.DestoryMongoConn(sess)
  686. lock := &sync.Mutex{}
  687. wg := &sync.WaitGroup{}
  688. ch := make(chan bool, 10)
  689. n := 0
  690. it := sess.DB(u.MgoEB.DbName).C("lua_logs_auditor").Find(&query).Iter()
  691. count, _ := sess.DB(u.MgoEB.DbName).C("lua_logs_auditor").Find(&query).Count()
  692. qu.Debug("count:", count)
  693. for tmp := map[string]interface{}{}; it.Next(tmp); n++ {
  694. ch <- true
  695. wg.Add(1)
  696. go func(tmp map[string]interface{}) {
  697. defer func() {
  698. <-ch
  699. wg.Done()
  700. }()
  701. id := mongodb.BsonIdToSId(tmp["_id"])
  702. auditor := qu.ObjToString(tmp["auditor"])
  703. code := qu.ObjToString(tmp["code"])
  704. comeintime := qu.Int64All(tmp["comeintime"])
  705. comeintime_z := qu.FormatDateByInt64(&comeintime, qu.Date_Full_Layout)
  706. event := qu.IntAll(tmp["event"])
  707. modifytime := qu.Int64All(tmp["modifytime"])
  708. modifytime_z := qu.FormatDateByInt64(&modifytime, qu.Date_Full_Layout)
  709. reason := qu.ObjToString(tmp["reason"])
  710. types := qu.ObjToString(tmp["types"])
  711. spideruser := qu.ObjToString(tmp["spideruser"])
  712. if !users[spideruser] {
  713. return
  714. }
  715. lock.Lock()
  716. row := sheet.AddRow()
  717. lock.Unlock()
  718. row.AddCell().SetValue(id)
  719. row.AddCell().SetValue(auditor)
  720. row.AddCell().SetValue(code)
  721. row.AddCell().SetValue(comeintime)
  722. row.AddCell().SetValue(comeintime_z)
  723. row.AddCell().SetValue(event)
  724. row.AddCell().SetValue(modifytime)
  725. row.AddCell().SetValue(modifytime_z)
  726. row.AddCell().SetValue(reason)
  727. row.AddCell().SetValue(spideruser)
  728. row.AddCell().SetValue(types)
  729. }(tmp)
  730. tmp = make(map[string]interface{})
  731. }
  732. }
  733. // 修改维护人
  734. func editModify(codesarr []string, userid, name string) {
  735. qu.Debug("修改爬虫对应任务的维护人:", name, codesarr)
  736. //修改modifyid和modify
  737. query := map[string]interface{}{
  738. "s_code": map[string]interface{}{
  739. "$in": codesarr,
  740. },
  741. "i_state": map[string]interface{}{
  742. "$nin": []int{4, 6},
  743. },
  744. }
  745. set := map[string]interface{}{
  746. "$set": map[string]interface{}{
  747. "s_modify": name,
  748. "s_modifyid": userid,
  749. },
  750. }
  751. b := u.MgoEB.Update("task", query, set, false, true)
  752. qu.Debug("任务重新分配成功", b)
  753. }
  754. func (f *Front) UpdatePendState() {
  755. success := false
  756. pendstate, _ := f.GetInteger("pendstate")
  757. code := f.GetString("code")
  758. stype := f.GetString("stype")
  759. qu.Debug(code, stype, pendstate)
  760. //success = u.MgoE.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"pendstate": pendstate}}, false, false)
  761. 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)
  762. if success {
  763. if stype == "code" { //爬虫挂起时,关闭所有任务
  764. 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)
  765. } else if stype == "task" { //任务挂起任务时任务关闭
  766. id := f.GetString("id")
  767. u.MgoEB.UpdateById("task", id, map[string]interface{}{"$set": map[string]interface{}{"i_pendstate": pendstate, "i_state": 6, "l_pendtime": time.Now().Unix()}})
  768. }
  769. }
  770. f.ServeJson(map[string]interface{}{"success": success})
  771. }
  772. func (f *Front) UpdateESP() {
  773. val := f.GetString("val")
  774. w := f.GetString("w")
  775. id := f.GetString("id")
  776. code := f.GetString("c")
  777. query := map[string]interface{}{
  778. "_id": mongodb.StringTOBsonId(id),
  779. }
  780. set := map[string]interface{}{}
  781. update := map[string]interface{}{
  782. "$set": set,
  783. }
  784. //one, _ := u.MgoE.FindById("luaconfig", id, nil)
  785. one, _ := u.MgoEB.FindById("luaconfig", id, nil)
  786. if len(*one) == 0 {
  787. f.Write("n")
  788. return
  789. }
  790. if w == "infoformat" {
  791. infoformat, _ := f.GetInteger("val")
  792. set["infoformat"] = infoformat
  793. } else if w == "urgency" { //修改紧急度
  794. urgency, _ := f.GetInteger("val")
  795. set["urgency"] = urgency
  796. } else if w == "state" { //无效爬虫改为待完成
  797. tmpEvent := qu.IntAll((*one)["event"])
  798. if one != nil && len(*one) > 0 {
  799. if (*one)["incrementevent"] == nil && tmpEvent != 7000 { //除7000节点外没有incrementevent的要重新设置
  800. set["incrementevent"] = tmpEvent
  801. }
  802. }
  803. set["state"] = 0
  804. set["event"] = 7000
  805. set["spidertype"] = "history"
  806. go ModifyLogs_UpdateCodeState(code)
  807. //更新、新建任务
  808. //task, _ := u.MgoEB.FindOne("task", map[string]interface{}{"s_code": code, "i_state": map[string]interface{}{"$in": []int{0, 1, 2, 3, 5}}})
  809. //text := "指定追加描述:------------------------------\n无发布转待完成\n"
  810. //if len(*task) > 0 { //已有任务,更新
  811. // u.MgoEB.UpdateById("task", (*task)["_id"],
  812. // map[string]interface{}{
  813. // "$set": map[string]interface{}{
  814. // "i_state": 2,
  815. // "s_descript": qu.ObjToString((*task)["s_descript"]) + text,
  816. // "l_updatetime": time.Now().Unix(),
  817. // },
  818. // })
  819. //} else {
  820. // save := map[string]interface{}{
  821. // "s_channel": (*one)["channel"],
  822. // "i_event": (*one)["event"],
  823. // "i_frequencyerrtimes": 0,
  824. // "i_state": 2,
  825. // "s_descript": text,
  826. // "l_complete": time.Now().Unix() + int64(24*3600),
  827. // "s_urgency": "4",
  828. // "i_pendstate": 0,
  829. // "s_modifyid": (*one)["modifyuserid"],
  830. // "s_source": "人工",
  831. // "i_times": 0,
  832. // "l_comeintime": time.Now().Unix(),
  833. // "i_num": 0,
  834. // "s_modify": (*one)["modifyuser"],
  835. // "s_code": code,
  836. // "s_site": (*one)["site"],
  837. // "s_type": "0",
  838. // }
  839. // u.MgoEB.Save("task", save)
  840. //}
  841. } else if w == "platform" {
  842. set["platform"] = val
  843. set["comeintime"] = time.Now().Unix()
  844. if val != "golua平台" && val != "chrome" {
  845. b := u.MgoS.Update("spider_heart", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"del": true}}, false, true)
  846. qu.Debug("Del Heart:", b)
  847. b, err := spider.UpdateSpiderByCodeState(code, "6", qu.IntAll((*one)["event"])) //下架
  848. if b && err == nil {
  849. //历史节点下架为了避免线上运行爬虫待完成时改为7000采集历史,但是又转到其他平台,导致原线上运行节点爬虫并未下线,心跳异常
  850. if incrementevent := (*one)["incrementevent"]; incrementevent != nil {
  851. b, err = spider.UpdateSpiderByCodeState(code, "6", qu.IntAll(incrementevent))
  852. }
  853. //关闭任务
  854. 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)
  855. if b && err == nil {
  856. set["state"] = 0 //更新状态
  857. set["luauser"] = map[string]interface{}{
  858. "createuser": (*one)["createuser"],
  859. "createuserid": (*one)["createuserid"],
  860. "createuseremail": (*one)["createuseremail"],
  861. "modifyuser": (*one)["modifyuser"],
  862. "modifyuserid": (*one)["modifyuserid"],
  863. }
  864. } else {
  865. qu.Debug("历史节点下架失败")
  866. f.Write("n")
  867. return
  868. }
  869. } else {
  870. qu.Debug("增量节点下架失败")
  871. f.Write("n")
  872. return
  873. }
  874. //qu.Debug("下架:", upresult, code)
  875. //b, err := UpStateAndUpSpider(code, "", "", "", Sp_state_6) //线上爬虫下架
  876. //qu.Debug("爬虫下架成功:", b)
  877. //if !b || err != nil {
  878. // f.Write("n")
  879. // return
  880. //}
  881. }
  882. } else { //修改节点
  883. event, _ := strconv.Atoi(val)
  884. set["event"] = event
  885. set["incrementevent"] = event
  886. //state := f.GetString("s")
  887. //if state == "5" { //已上架状态改为下架
  888. code := f.GetString("c")
  889. set["state"] = 6
  890. b, err := UpStateAndUpSpider(code, "", "", "", Sp_state_6) //线上爬虫下架
  891. qu.Debug("爬虫下架成功:", b)
  892. if !b || err != nil {
  893. f.Write("n")
  894. return
  895. }
  896. //}
  897. }
  898. //if mgdb.Update("luaconfig", query, update, false, false) {
  899. if u.MgoEB.Update("luaconfig", query, update, false, false) {
  900. log.Println("Id:", id, " Update", w, val, "Success")
  901. f.Write("y")
  902. return
  903. } else {
  904. log.Println("Id:", id, " Update", w, val, "Failed")
  905. f.Write("n")
  906. return
  907. }
  908. f.Write("n")
  909. }
  910. func (f *Front) GetCity() {
  911. area := f.GetString("area")
  912. cityArr := []string{}
  913. cityArr = u.Province[area]
  914. f.ServeJson(cityArr)
  915. }
  916. func (f *Front) SpiderCopy() {
  917. defer qu.Catch()
  918. code := f.GetString("code")
  919. code = strings.TrimSpace(code)
  920. success := false
  921. text := ""
  922. encode := ""
  923. if code != "" {
  924. //lua := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": code})
  925. lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
  926. if len(*lua) > 0 {
  927. codeOld := qu.ObjToString((*lua)["code"])
  928. codeNew := codeOld + u.Bu
  929. //luaTmp := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": codeNew})
  930. luaTmp, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": codeNew})
  931. if len(*luaTmp) > 0 {
  932. f.ServeJson(map[string]interface{}{"success": false, "text": "已存在补漏爬虫"})
  933. return
  934. }
  935. //u.MgoE.Update("luaconfig", map[string]interface{}{"code": codeOld}, map[string]interface{}{"$set": map[string]interface{}{"relatecode": codeNew}}, false, false)
  936. u.MgoEB.Update("luaconfig", map[string]interface{}{"code": codeOld}, map[string]interface{}{"$set": map[string]interface{}{"relatecode": codeNew}}, false, false)
  937. (*lua)["code"] = codeNew
  938. (*lua)["relatecode"] = codeOld
  939. if param_common := (*lua)["param_common"].([]interface{}); len(param_common) < 13 {
  940. f.ServeJson(map[string]interface{}{"success": false, "text": "脚本异常,请联系管理员"})
  941. return
  942. } else {
  943. param_common = param_common[:13]
  944. param_common[0] = codeNew //code
  945. param_common = append(param_common, true) //历史补漏
  946. param_common = append(param_common, false) //强制下载
  947. (*lua)["param_common"] = param_common
  948. }
  949. str_list := qu.ObjToString((*lua)["str_list"])
  950. (*lua)["str_list"] = strings.ReplaceAll(str_list, codeOld, codeNew)
  951. (*lua)["comeintime"] = time.Now().Unix()
  952. (*lua)["modifytime"] = time.Now().Unix()
  953. (*lua)["spidertype"] = "increment"
  954. (*lua)["event"] = 7000
  955. (*lua)["state"] = 6
  956. id := u.MgoEB.Save("luaconfig", (*lua))
  957. if id != "" {
  958. success = true
  959. encode = util.Se.Encode2Hex(codeNew)
  960. } else {
  961. text = "新爬虫保存失败"
  962. }
  963. } else {
  964. text = "未查询到复制原"
  965. }
  966. } else {
  967. text = "脚本不能为空"
  968. }
  969. f.ServeJson(map[string]interface{}{"success": success, "text": text, "encode": encode})
  970. }
  971. func (f *Front) SpiderSplitCopy() {
  972. defer qu.Catch()
  973. code := f.GetString("code")
  974. code = strings.TrimSpace(code)
  975. num, _ := f.GetInteger("num")
  976. text := ""
  977. lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
  978. if len(*lua) > 0 {
  979. param_common := (*lua)["param_common"].([]interface{})
  980. str_list := qu.ObjToString((*lua)["str_list"])
  981. channelOld := qu.ObjToString((*lua)["channel"])
  982. copyNum := qu.IntAll((*lua)["copynum"]) //当前已经拆分了多少个爬虫
  983. delete(*lua, "relatecode") //删除关联爬虫字段
  984. for i := 1; i <= num; i++ {
  985. copyNum++
  986. var codeSuffix string
  987. if copyNum < 10 {
  988. codeSuffix = fmt.Sprintf("0%s", fmt.Sprint(copyNum))
  989. } else {
  990. codeSuffix = fmt.Sprint(copyNum)
  991. }
  992. (*lua)["code"] = code + "_" + codeSuffix
  993. (*lua)["channel"] = channelOld + "_" + codeSuffix
  994. (*lua)["str_list"] = strings.ReplaceAll(str_list, code, code+"_"+codeSuffix)
  995. (*lua)["comeintime"] = time.Now().Unix()
  996. (*lua)["modifytime"] = time.Now().Unix()
  997. (*lua)["state"] = 0
  998. param_common[0] = code + "_" + codeSuffix
  999. param_common[2] = channelOld + "_" + codeSuffix
  1000. (*lua)["param_common"] = param_common
  1001. u.MgoEB.Save("luaconfig", (*lua))
  1002. }
  1003. u.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"copynum": copyNum}}, false, false)
  1004. } else {
  1005. text = "未查询到复制原"
  1006. }
  1007. f.ServeJson(map[string]interface{}{"text": text})
  1008. }
  1009. /*// 清理Redis
  1010. func (f *Front) DelRedis() {
  1011. hrefs := f.GetString("href")
  1012. hrefsarr := strings.Split(hrefs, ",")
  1013. auth := qu.IntAll(f.GetSession("auth"))
  1014. err := []string{}
  1015. if auth == u.Role_Admin { //权限控制
  1016. if len(hrefsarr) > 0 {
  1017. for k1, h := range hrefsarr {
  1018. href := Reg.FindString(h)
  1019. if href != "" {
  1020. href = "url_repeat_" + href + "*"
  1021. res := redis.GetKeysByPattern("title_repeat_judgement", href)
  1022. if res != nil {
  1023. for _, v := range res {
  1024. hf := string(v.([]uint8))
  1025. b := redis.Del("title_repeat_judgement", hf)
  1026. if !b {
  1027. err = append(err, "第"+strconv.Itoa(k1+1)+"个")
  1028. }
  1029. }
  1030. }
  1031. } else {
  1032. err = append(err, "第"+strconv.Itoa(k1+1)+"个")
  1033. }
  1034. }
  1035. }
  1036. } else {
  1037. err = append(err, "没有权限")
  1038. }
  1039. f.ServeJson(err)
  1040. }*/