front.go 37 KB

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