taskManager.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. package taskManager
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. ft "luaweb/finishtime"
  7. sp "luaweb/front"
  8. qu "qfw/util"
  9. mgdb "qfw/util/mongodb"
  10. mgu "qfw/util/mongodbutil"
  11. "sort"
  12. util "spiderutil"
  13. "strconv"
  14. "strings"
  15. "time"
  16. "github.com/go-xweb/xweb"
  17. "github.com/tealeg/xlsx"
  18. "gopkg.in/mgo.v2/bson"
  19. )
  20. type TaskM struct {
  21. *xweb.Action
  22. managerTask xweb.Mapper `xweb:"/center/managerTask"` //任务管理
  23. taskfile xweb.Mapper `xweb:"/center/taskfile"` //任务导入
  24. mytask xweb.Mapper `xweb:"/center/mytask"` //我的任务
  25. checkCode xweb.Mapper `xweb:"/center/task/checkCode"` //检验任务是否存在
  26. searchMintainer xweb.Mapper `xweb:"/center/searchMintainer"` //查询所有维护人员
  27. saveNewTask xweb.Mapper `xweb:"/center/task/saveNewTask"` //新建任务
  28. editTask xweb.Mapper `xweb:"/center/task/edit/(.*)"` //编辑任务
  29. updateTask xweb.Mapper `xweb:"/center/task/updateTask"` //修改任务
  30. updateTaskState xweb.Mapper `xweb:"/center/task/updateTaskState"` //修改状态为处理中
  31. saveRecord xweb.Mapper `xweb:"/center/task/saveRecord"` //保存记录提交审核
  32. audit xweb.Mapper `xweb:"/center/task/audit"` //审核任务
  33. assignChangeTaskState xweb.Mapper `xweb:"/center/task/assignChangeTaskState"` //分发任务
  34. closeChangeTaskState xweb.Mapper `xweb:"/center/task/closeChangeTaskState"` //关闭任务
  35. batchAssign xweb.Mapper `xweb:"/center/task/batchAssign"` //批量分发任务
  36. batchClose xweb.Mapper `xweb:"/center/task/batchClose"` //批量关闭任务
  37. getJumpMark xweb.Mapper `xweb:"/center/task/getJumpMark"` //跳转标记
  38. searchErrLog xweb.Mapper `xweb:"/center/task/searchErrLog"` //搜索错误日志
  39. searchDataInfo xweb.Mapper `xweb:"/center/task/searchDataInfo"` //搜索数据的标题和发布时间
  40. //del xweb.Mapper `xweb:"/center/task/del"` //删除任务
  41. //searchTask xweb.Mapper `xweb:"/center/task/searchTask"` //查询任务
  42. }
  43. //session是否失效
  44. var SessionFailuer bool //检测每次登陆
  45. const role_admin, role_examine, role_dev = 3, 2, 1 //管理员,审核员,开发员
  46. //任务导入
  47. func (t *TaskM) Taskfile() {
  48. auth := qu.IntAll(t.GetSession("auth"))
  49. if auth != role_admin {
  50. t.ServeJson("没有权限")
  51. return
  52. }
  53. if t.Method() == "POST" {
  54. mf, _, err := t.GetFile("xlsx")
  55. errorinfo := map[string]interface{}{}
  56. o := make(map[string]interface{})
  57. o["s_date"] = time.Now().Format("2006-01-02")
  58. o["s_source"] = "人工"
  59. o["s_type"] = "0"
  60. var ug string = ""
  61. if err == nil {
  62. binary, _ := ioutil.ReadAll(mf)
  63. xls, _ := xlsx.OpenBinary(binary)
  64. sheet := xls.Sheets[0]
  65. rows := sheet.Rows
  66. for k, v := range rows {
  67. if k != 0 {
  68. cells := v.Cells
  69. if len(cells) == 0 {
  70. continue
  71. }
  72. if cells[0].Value == "" { //没有code
  73. continue
  74. } else { //有code
  75. o["s_code"] = cells[0].Value
  76. queryT := bson.M{
  77. "s_code": cells[0].Value,
  78. "i_state": bson.M{
  79. "$in": []int{1, 2, 5},
  80. },
  81. }
  82. task := *mgdb.FindOne("task", queryT)
  83. //if len(task) != 0 { //任务已存在 追加描述 并修改紧急度和最迟完成时间
  84. //errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行数据已导入"
  85. //continue
  86. //} else { //任务不存在
  87. if len(cells) == 4 && cells[3].Value != "" { //必有code和最终完成时间
  88. if cells[1].Value == "" || cells[2].Value == "" { //没有描述或者紧急度
  89. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行数据不完整"
  90. continue
  91. } else {
  92. if !strings.Contains(cells[3].Value, "-") { //日期格式不对
  93. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行日期格式错误"
  94. continue
  95. } else {
  96. if len(task) != 0 { //有该任务 追加描述 比较紧急度和最迟完成时间
  97. //追加描述
  98. text := time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + cells[1].Value + "\n"
  99. s_descript := task["s_descript"].(string) + text
  100. //比较、更新最迟完成时间
  101. var l_complete int64
  102. var s_urgency string
  103. s_urgency = isUrgency(cells)
  104. if s_urgency == "0" {
  105. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行紧急度填写错误"
  106. continue
  107. }
  108. timeDate, _ := time.ParseInLocation("2006-01-02", cells[3].Value, time.Local)
  109. complete := timeDate.Unix() + 64800
  110. taskComplete := qu.Int64All(task["l_complete"])
  111. if complete <= taskComplete { //取excel中的最迟完成时间和紧急度
  112. l_complete = complete
  113. } else { //取task中的最迟完成时间和紧急度
  114. l_complete = taskComplete
  115. s_urgency = task["s_urgency"].(string)
  116. }
  117. if task["i_state"].(int) == 2 {
  118. errorinfo[cells[0].Value] = "任务已存在"
  119. }
  120. //更新task
  121. UpdateOldTask(task["_id"].(bson.ObjectId).Hex(), s_descript, s_urgency, l_complete)
  122. } else {
  123. timeDate, err := time.ParseInLocation("2006-01-02", cells[3].Value, time.Local)
  124. if err == nil {
  125. o["l_complete"] = timeDate.Unix() + 64800
  126. }
  127. o["s_descript"] = cells[1].Value + "\n"
  128. ug = isUrgency(cells)
  129. if ug == "0" {
  130. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行紧急度填写错误"
  131. continue
  132. }
  133. o["s_urgency"] = ug
  134. }
  135. }
  136. }
  137. } else if len(cells) == 4 && cells[3].Value == "" { //避免添加最终时间后又手动删除
  138. if len(task) != 0 {
  139. //追加描述
  140. text := time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + cells[1].Value + "\n"
  141. s_descript := task["s_descript"].(string) + text
  142. //比较、更新最迟完成时间
  143. var l_complete int64
  144. var s_urgency string
  145. s_urgency = isUrgency(cells)
  146. if s_urgency == "0" {
  147. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行紧急度填写错误"
  148. continue
  149. }
  150. complete := ft.CompleteTime(s_urgency)
  151. taskComplete := qu.Int64All(task["l_complete"])
  152. if complete <= taskComplete { //取excel中的最迟完成时间和紧急度
  153. l_complete = complete
  154. } else { //取task中的最迟完成时间和紧急度
  155. l_complete = taskComplete
  156. s_urgency = task["s_urgency"].(string)
  157. }
  158. if task["i_state"].(int) == 2 {
  159. errorinfo[cells[0].Value] = "任务已存在"
  160. }
  161. //更新task
  162. UpdateOldTask(task["_id"].(bson.ObjectId).Hex(), s_descript, s_urgency, l_complete)
  163. } else {
  164. if cells[1].Value != "" {
  165. ug = isUrgency(cells)
  166. if ug == "0" {
  167. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行紧急度填写错误"
  168. continue
  169. }
  170. o["l_complete"] = ft.CompleteTime(ug)
  171. o["s_descript"] = cells[1].Value + "\n"
  172. o["s_urgency"] = ug
  173. } else {
  174. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行数据不完整"
  175. }
  176. }
  177. } else if len(cells) == 3 { //必没有最终完成时间 自动生成
  178. if len(task) != 0 {
  179. //追加描述
  180. text := time.Now().Format(qu.Date_Short_Layout) + "追加描述:------------------------------\n" + cells[1].Value + "\n"
  181. s_descript := task["s_descript"].(string) + text
  182. //比较、更新最迟完成时间
  183. var l_complete int64
  184. var s_urgency string
  185. s_urgency = isUrgency(cells)
  186. if s_urgency == "0" {
  187. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行紧急度填写错误"
  188. continue
  189. }
  190. complete := ft.CompleteTime(s_urgency)
  191. taskComplete := qu.Int64All(task["l_complete"])
  192. if complete <= taskComplete { //取excel中的最迟完成时间和紧急度
  193. l_complete = complete
  194. } else { //取task中的最迟完成时间和紧急度
  195. l_complete = taskComplete
  196. s_urgency = task["s_urgency"].(string)
  197. }
  198. if task["i_state"].(int) == 2 {
  199. errorinfo[cells[0].Value] = "任务已存在"
  200. }
  201. //更新task
  202. UpdateOldTask(task["_id"].(bson.ObjectId).Hex(), s_descript, s_urgency, l_complete)
  203. } else {
  204. if cells[1].Value != "" {
  205. ug = isUrgency(cells)
  206. if ug == "0" {
  207. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行紧急度填写错误"
  208. continue
  209. }
  210. o["l_complete"] = ft.CompleteTime(ug)
  211. o["s_descript"] = cells[1].Value + "\n"
  212. o["s_urgency"] = ug
  213. } else {
  214. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行数据不完整"
  215. }
  216. }
  217. } else {
  218. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行数据不完整"
  219. continue
  220. }
  221. if len(task) == 0 {
  222. queryL := bson.M{"code": cells[0].Value}
  223. lua := *mgdb.FindOne("luaconfig", queryL)
  224. if lua != nil {
  225. param := lua["param_common"]
  226. o["s_site"] = param.([]interface{})[1] //取数组中的某个值
  227. o["s_channel"] = param.([]interface{})[2]
  228. o["i_state"] = 1
  229. o["s_modify"] = lua["createuser"]
  230. o["s_modifyid"] = lua["createuserid"]
  231. o["l_comeintime"] = time.Now().Unix()
  232. o["i_event"] = lua["event"]
  233. o["i_times"] = 0
  234. } else {
  235. errorinfo[cells[0].Value] = "第" + strconv.Itoa(k+1) + "行爬虫代码填写错误"
  236. continue
  237. }
  238. mgdb.Save("task", o)
  239. //清空map
  240. o = map[string]interface{}{}
  241. }
  242. //}
  243. }
  244. }
  245. }
  246. t.ServeJson(errorinfo)
  247. } else {
  248. t.ServeJson(false)
  249. }
  250. }
  251. }
  252. func (t *TaskM) ManagerTask() {
  253. auth := qu.IntAll(t.GetSession("auth"))
  254. urgency, _ := t.GetInteger("state") //紧急程度
  255. taskState, _ := t.GetInteger("taskState") //任务状态
  256. event, _ := t.GetInteger("taskEvent") //节点
  257. stype, _ := t.GetInteger("taskStype") //任务类型
  258. searchStr := t.GetString("search[value]")
  259. //search := strings.Replace(searchStr, " ", "", -1)
  260. search := strings.TrimSpace(searchStr)
  261. draw, _ := t.GetInteger("draw")
  262. start, _ := t.GetInteger("start")
  263. limit, _ := t.GetInteger("length")
  264. if auth == role_admin {
  265. if t.Method() == "GET" {
  266. events := []string{}
  267. for k, _ := range util.Config.Uploadevents {
  268. events = append(events, k)
  269. }
  270. sort.Strings(events)
  271. t.T["events"] = events
  272. t.Render("task.html", &t.T)
  273. } else {
  274. query := queryCriteria(urgency, taskState, event, stype)
  275. if search != "" {
  276. query["$or"] = []interface{}{
  277. bson.M{"s_code": bson.M{"$regex": search}},
  278. bson.M{"s_modify": bson.M{"$regex": search}},
  279. bson.M{"s_site": bson.M{"$regex": search}},
  280. bson.M{"s_channel": bson.M{"$regex": search}},
  281. }
  282. }
  283. sort := `{"%s":%d}`
  284. orderIndex := t.GetString("order[0][column]")
  285. orderName := t.GetString(fmt.Sprintf("columns[%s][data]", orderIndex))
  286. orderType := 1
  287. if t.GetString("order[0][dir]") != "asc" {
  288. orderType = -1
  289. }
  290. sort = fmt.Sprintf(sort, orderName, orderType)
  291. if orderIndex == "9" { //按下载/下限排序时 先按完成时间排序
  292. sorta := strings.Replace(sort, "{", "", -1)
  293. sortb := strings.Replace(sorta, "}", "", -1)
  294. //sort = `{"l_complete":1,` + sortb + `}`
  295. sort = `{` + sortb + `,"l_complete":1}`
  296. }
  297. task := *mgdb.Find("task", query, sort, nil, false, start, limit)
  298. count := mgdb.Count("task", query)
  299. page := start / 10
  300. if len(task) > 0 {
  301. for k, v := range task {
  302. // if v["f_num"] == nil {
  303. // v["f_num"] = 0
  304. // }
  305. // if v["f_min"] == nil {
  306. // v["f_min"] = 0
  307. // }
  308. // if v["i_minNum"] == nil {
  309. // v["i_minNum"] = 0
  310. // }
  311. v["num"] = k + 1 + page*10
  312. v["encode"] = util.Se.Encode2Hex(fmt.Sprint(v["s_code"]))
  313. s_urgency := qu.IntAll(v["s_urgency"])
  314. if s_urgency == 1 {
  315. v["s_urgency"] = "普通"
  316. } else if s_urgency == 2 {
  317. v["s_urgency"] = "紧急"
  318. } else if s_urgency == 3 {
  319. v["s_urgency"] = "非常紧急"
  320. } else if s_urgency == 4 {
  321. v["s_urgency"] = "特别紧急"
  322. }
  323. if v["i_state"] == 0 {
  324. v["i_state"] = "待确认"
  325. } else if v["i_state"] == 1 {
  326. v["i_state"] = "待处理"
  327. } else if v["i_state"] == 2 {
  328. v["i_state"] = "处理中"
  329. } else if v["i_state"] == 3 {
  330. v["i_state"] = "待审核"
  331. } else if v["i_state"] == 4 {
  332. v["i_state"] = "审核通过"
  333. } else if v["i_state"] == 5 {
  334. v["i_state"] = "未通过"
  335. } else if v["i_state"] == 6 {
  336. v["i_state"] = "关闭"
  337. }
  338. if v["i_event"] == nil { //节点
  339. v["i_event"] = 0
  340. }
  341. // if v["continueTimes"] == nil { //特别紧急任务连续报错次数
  342. // v["continueTimes"] = 0
  343. // } else {
  344. // for _, times := range v["continueTimes"].(map[string]interface{}) {
  345. // v["continueTimes"] = times
  346. // }
  347. // }
  348. l_complete := qu.Int64All(v["l_complete"])
  349. v["l_complete"] = qu.FormatDateByInt64(&l_complete, qu.Date_Full_Layout)
  350. //v["l_complete"] = time.Unix(v["l_complete"].(int64), 0).Format("2006-01-02 15:04:05")
  351. v["_id"] = v["_id"].(bson.ObjectId).Hex()
  352. //根据code查询luaconfig
  353. param := findLua(v["s_code"].(string))
  354. if len(param) < 13 || param == nil {
  355. v["href"] = "javascript:void(0)"
  356. } else {
  357. v["href"] = param[11]
  358. }
  359. }
  360. }
  361. t.ServeJson(map[string]interface{}{"draw": draw, "data": task, "recordsFiltered": count, "recordsTotal": count})
  362. }
  363. } else {
  364. t.Write("您没有导入任务的权限")
  365. }
  366. }
  367. func findLua(code string) []interface{} {
  368. lua := *mgdb.FindOneByField("luaconfig", `{"code":"`+code+`"}`, `{"param_common":1}`)
  369. param := lua["param_common"].([]interface{})
  370. return param
  371. }
  372. //我的任务
  373. func (t *TaskM) Mytask() {
  374. auth := qu.IntAll(t.GetSession("auth"))
  375. if auth != role_dev {
  376. t.ServeJson("没有权限")
  377. return
  378. }
  379. userid := t.GetSession("userid")
  380. query := bson.M{}
  381. if t.Method() == "POST" {
  382. start, _ := t.GetInteger("start")
  383. limit, _ := t.GetInteger("length")
  384. draw, _ := t.GetInteger("draw")
  385. //state, _ := t.GetInteger("state")
  386. urgency, _ := t.GetInteger("state")
  387. taskState, _ := t.GetInteger("taskState")
  388. stype, _ := t.GetInteger("taskStype") //任务类型
  389. event, _ := t.GetInteger("taskEvent") //节点
  390. searchStr := t.GetString("search[value]")
  391. //search := strings.Replace(searchStr, " ", "", -1)
  392. search := strings.TrimSpace(searchStr)
  393. //查询自己的任务
  394. query = queryCriteria(urgency, taskState, event, stype)
  395. query["s_modifyid"] = userid
  396. if search != "" {
  397. query["$or"] = []interface{}{
  398. bson.M{"s_code": bson.M{"$regex": search}},
  399. bson.M{"s_site": bson.M{"$regex": search}},
  400. bson.M{"s_channel": bson.M{"$regex": search}},
  401. }
  402. }
  403. sort := `{"%s":%d}`
  404. orderIndex := t.GetString("order[0][column]")
  405. orderName := t.GetString(fmt.Sprintf("columns[%s][data]", orderIndex))
  406. orderType := 1
  407. if t.GetString("order[0][dir]") != "asc" {
  408. orderType = -1
  409. }
  410. sort = fmt.Sprintf(sort, orderName, orderType)
  411. // sorta := strings.Replace(sort, "{", "", -1)
  412. // sortb := strings.Replace(sorta, "}", "", -1)
  413. // sortNew := `{"l_complete": 1,` + sortb + `}`
  414. task := *mgdb.Find("task", query, sort, nil, false, start, limit)
  415. count := mgdb.Count("task", query)
  416. if task != nil {
  417. for _, v := range task {
  418. v["encode"] = util.Se.Encode2Hex(fmt.Sprint(v["s_code"]))
  419. if v["s_urgency"] == "1" {
  420. v["s_urgency"] = "普通"
  421. } else if v["s_urgency"] == "2" {
  422. v["s_urgency"] = "紧急"
  423. } else if v["s_urgency"] == "3" {
  424. v["s_urgency"] = "非常紧急"
  425. } else if v["s_urgency"] == "4" {
  426. v["s_urgency"] = "特别紧急"
  427. }
  428. if v["i_state"] == 0 {
  429. v["i_state"] = "待确认"
  430. } else if v["i_state"] == 1 {
  431. v["i_state"] = "待处理"
  432. } else if v["i_state"] == 2 {
  433. v["i_state"] = "处理中"
  434. } else if v["i_state"] == 3 {
  435. v["i_state"] = "待审核"
  436. } else if v["i_state"] == 4 {
  437. v["i_state"] = "审核通过"
  438. } else if v["i_state"] == 5 {
  439. v["i_state"] = "未通过"
  440. } else if v["i_state"] == 6 {
  441. v["i_state"] = "关闭"
  442. }
  443. if v["i_event"] == nil { //节点
  444. v["i_event"] = 0
  445. }
  446. v["l_complete"] = time.Unix(v["l_complete"].(int64), 0).Format("2006-01-02 15:04:05")
  447. v["_id"] = v["_id"].(bson.ObjectId).Hex()
  448. }
  449. }
  450. t.ServeJson(map[string]interface{}{"draw": draw, "data": task, "recordsFiltered": count, "recordsTotal": count})
  451. } else {
  452. events := []string{}
  453. for k, _ := range util.Config.Uploadevents {
  454. events = append(events, k)
  455. }
  456. sort.Strings(events)
  457. t.T["events"] = events
  458. failedtasknum := 0
  459. if SessionFailuer {
  460. query["s_modifyid"] = userid
  461. query["i_state"] = 5
  462. task := *mgdb.Find("task", query, nil, nil, false, -1, -1)
  463. failedtasknum = len(task)
  464. SessionFailuer = false
  465. }
  466. t.T["failedtasknum"] = failedtasknum
  467. t.Render("mytask.html", &t.T)
  468. }
  469. }
  470. //检验任务是否存在
  471. func (t *TaskM) CheckCode() {
  472. code := t.GetString("code")
  473. status := "notHasCode"
  474. var lua map[string]interface{}
  475. if code != "" {
  476. query := bson.M{
  477. "s_code": code,
  478. "i_state": bson.M{
  479. "$in": []int{1, 2, 5},
  480. },
  481. }
  482. task := *mgdb.FindOne("task", query)
  483. if task != nil {
  484. task["l_complete"] = time.Unix(task["l_complete"].(int64), 0).Format("2006-01-02 15:04:05")
  485. status = "hasCode"
  486. } else {
  487. luaQuery := bson.M{
  488. "code": code,
  489. }
  490. lua = *mgdb.FindOne("luaconfig", luaQuery)
  491. }
  492. t.ServeJson(map[string]interface{}{
  493. "status": status,
  494. "task": task,
  495. "lua": lua,
  496. })
  497. }
  498. }
  499. //查询维护人员
  500. func (t *TaskM) SearchMintainer() {
  501. query := bson.M{
  502. "i_auth": 1,
  503. }
  504. mintainer := *mgdb.Find("user", query, nil, nil, false, -1, -1)
  505. if len(mintainer) > 0 {
  506. t.SetSession("mintainer", mintainer)
  507. t.ServeJson(map[string]interface{}{
  508. "mintainer": mintainer,
  509. })
  510. } else {
  511. log.Println("查询维护人员名单错误")
  512. }
  513. }
  514. //保存新建任务
  515. func (t *TaskM) SaveNewTask() {
  516. auth := qu.IntAll(t.GetSession("auth"))
  517. if auth != role_admin {
  518. t.ServeJson("没有权限")
  519. return
  520. }
  521. site := t.GetString("site")
  522. code := t.GetString("code")
  523. channel := t.GetString("channel")
  524. modify := t.GetString("modify")
  525. descript := t.GetString("descript")
  526. urgency := t.GetString("urgency")
  527. complete := t.GetString("complete")
  528. comeintime := time.Now().Unix()
  529. var ug string = ""
  530. newTask := make(map[string]interface{})
  531. newTask["s_source"] = "人工"
  532. newTask["s_type"] = "0"
  533. newTask["s_site"] = site //站点
  534. newTask["s_channel"] = channel //栏目
  535. newTask["s_code"] = code //代码
  536. newTask["i_state"] = 1 //完成状态
  537. newTask["l_comeintime"] = comeintime //创建时间
  538. newTask["s_date"] = time.Now().Format("2006-01-02")
  539. newTask["i_times"] = 0
  540. queryL := bson.M{
  541. "code": code,
  542. }
  543. lua := *mgdb.FindOne("luaconfig", queryL)
  544. if lua != nil {
  545. newTask["s_modifyid"] = lua["createuserid"] //维护人员id
  546. newTask["i_event"] = lua["event"] //节点
  547. }
  548. newTask["s_modify"] = modify //维护人员
  549. newTask["s_descript"] = descript //描述
  550. if urgency == "普通" {
  551. ug = "1"
  552. newTask["s_urgency"] = "1" //紧急度
  553. } else if urgency == "紧急" {
  554. ug = "2"
  555. newTask["s_urgency"] = "2"
  556. } else if urgency == "非常紧急" {
  557. ug = "3"
  558. newTask["s_urgency"] = "3"
  559. } else if urgency == "特别紧急" {
  560. ug = "4"
  561. newTask["s_urgency"] = "4"
  562. }
  563. //根据紧急度自动生成最终完成时间
  564. if complete == "" {
  565. //newTask["l_complete"] = ft.LastTime(timeHour) //最迟完成时间
  566. newTask["l_complete"] = ft.CompleteTime(ug)
  567. } else { //转成时间戳
  568. timeDate, err := time.ParseInLocation("2006-01-02 15:04:05", complete, time.Local)
  569. if err == nil {
  570. newTask["l_complete"] = timeDate.Unix()
  571. }
  572. }
  573. task := mgdb.Save("task", newTask)
  574. if task != "" {
  575. t.ServeJson(map[string]interface{}{
  576. "state": "ok",
  577. })
  578. }
  579. }
  580. //编辑 查看任务
  581. func (t *TaskM) EditTask(ids string) error {
  582. auth := t.GetSession("auth")
  583. //code := strings.Split(codes, "__")[0]
  584. id := strings.Split(ids, "__")[0]
  585. param := strings.Split(ids, "__")[1]
  586. if t.Method() == "GET" {
  587. query := bson.M{
  588. //"s_code": util.Se.Decode4Hex(code),
  589. "_id": bson.ObjectIdHex(id),
  590. }
  591. task := *mgdb.FindOne("task", query)
  592. if task != nil {
  593. task["l_comeintime"] = time.Unix(task["l_comeintime"].(int64), 0).Format("2006-01-02 15:04:05")
  594. task["l_complete"] = time.Unix(task["l_complete"].(int64), 0).Format("2006-01-02 15:04:05")
  595. if task["a_mrecord"] != nil {
  596. mrecord := qu.ObjArrToMapArr(task["a_mrecord"].([]interface{}))
  597. if mrecord != nil && len(mrecord) > 0 {
  598. for _, v := range mrecord {
  599. v["l_mrecord_comeintime"] = time.Unix(qu.Int64All(v["l_mrecord_comeintime"]), 0).Format("2006-01-02 15:04:05")
  600. v["l_mrecord_complete"] = time.Unix(qu.Int64All(v["l_mrecord_complete"]), 0).Format("2006-01-02 15:04:05")
  601. }
  602. }
  603. }
  604. if task["a_check"] != nil {
  605. check := qu.ObjArrToMapArr(task["a_check"].([]interface{}))
  606. if check != nil && len(check) > 0 {
  607. for _, v := range check {
  608. v["l_check_checkTime"] = time.Unix(qu.Int64All(v["l_check_checkTime"]), 0).Format("2006-01-02 15:04:05")
  609. }
  610. }
  611. }
  612. t.T["encode"] = util.Se.Encode2Hex(fmt.Sprint(task["s_code"]))
  613. t.T["id"] = id
  614. t.T["task"] = task
  615. t.T["param"] = param
  616. if t.GetSession(id) == "" || t.GetSession(id) == nil {
  617. t.T["xgTime"] = time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05")
  618. } else {
  619. t.T["xgTime"] = qu.ObjToString(t.GetSession(id))
  620. }
  621. t.DelSession(id)
  622. if auth == 3 {
  623. return t.Render("taskedit.html", &t.T)
  624. } else if auth == 1 {
  625. return t.Render("mytaskedit.html", &t.T)
  626. } else if auth == 2 {
  627. return t.Render("auditedit.html", &t.T)
  628. }
  629. }
  630. }
  631. return nil
  632. }
  633. //删除任务
  634. func (t *TaskM) Del() {
  635. auth := qu.IntAll(t.GetSession("auth"))
  636. id := t.GetString("id")
  637. state := "no"
  638. if auth != role_admin {
  639. t.ServeJson("没有权限")
  640. return
  641. }
  642. del := bson.M{
  643. "_id": bson.ObjectIdHex(id),
  644. }
  645. ok := mgdb.Del("task", del)
  646. if ok {
  647. state = "ok"
  648. }
  649. t.ServeJson(map[string]interface{}{
  650. "state": state,
  651. })
  652. }
  653. //修改任务
  654. func (t *TaskM) UpdateTask() {
  655. auth := qu.IntAll(t.GetSession("auth"))
  656. if auth != role_admin {
  657. t.ServeJson("没有权限")
  658. return
  659. }
  660. modify := t.GetString("modify")
  661. id := t.GetString("id")
  662. descript := t.GetString("descript")
  663. urgency := t.GetString("urgency")
  664. complete := t.GetString("complete")
  665. completeChange := t.GetString("completeChange")
  666. urgencyChange := t.GetString("urgencyChange")
  667. var l_complete int64
  668. var state = "no"
  669. if "普通" == urgency {
  670. urgency = "1"
  671. } else if "紧急" == urgency {
  672. urgency = "2"
  673. } else if "非常紧急" == urgency {
  674. urgency = "3"
  675. } else if "特别紧急" == urgency {
  676. urgency = "4"
  677. }
  678. if "no" == completeChange { //时间格式未改变
  679. completeTime, _ := time.ParseInLocation("2006-01-02 15:04:05", complete, time.Local)
  680. l_complete = completeTime.Unix()
  681. } else if "yes" == completeChange { //时间格式改变
  682. timeDate, err := time.ParseInLocation("2006-01-02", complete, time.Local)
  683. if err == nil {
  684. l_complete = timeDate.Unix() + 64800
  685. }
  686. }
  687. if "yes" == urgencyChange { //紧急度改变 根据紧急度修改最迟完成时间
  688. l_complete = ft.CompleteTime(urgency)
  689. }
  690. queryU := bson.M{
  691. "s_name": modify,
  692. }
  693. task := *mgdb.FindOne("user", queryU)
  694. queryT := bson.M{
  695. "_id": bson.ObjectIdHex(id),
  696. }
  697. update := bson.M{
  698. "$set": bson.M{
  699. "s_modify": modify,
  700. "s_descript": descript,
  701. "s_urgency": urgency,
  702. "l_complete": l_complete,
  703. "s_modifyid": task["_id"].(bson.ObjectId).Hex(),
  704. },
  705. }
  706. ok := mgdb.Update("task", queryT, update, false, false)
  707. if ok {
  708. state = "ok"
  709. t.SetSession("jumpMark", "y")
  710. }
  711. t.ServeJson(map[string]interface{}{
  712. "state": state,
  713. })
  714. }
  715. //修改任务状态为处理中
  716. func (t *TaskM) UpdateTaskState() {
  717. xgTime := time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05")
  718. //判断之前是否已有
  719. id := t.GetString("id")
  720. if t.GetSession(id) == nil {
  721. t.SetSession(id, xgTime)
  722. }
  723. query := bson.M{
  724. "_id": bson.ObjectIdHex(id),
  725. }
  726. task := *mgdb.FindOne("task", query)
  727. updateOk := false
  728. if len(task) > 0 {
  729. state := qu.IntAll(task["i_state"])
  730. if state == 1 { //修改任务状态为待处理
  731. update := bson.M{
  732. "$set": bson.M{
  733. "i_state": 2,
  734. },
  735. }
  736. updateOk = mgdb.Update("task", query, update, false, false) //更新任务状态
  737. code := qu.ObjToString(task["s_code"])
  738. mgdb.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"ismodify": true}}, false, false)
  739. // code := qu.ObjToString(task["s_code"])
  740. // lua := *mgdb.FindOne("luaconfig", map[string]interface{}{"code": code})
  741. // if len(lua) > 0 {
  742. // lua_state := qu.IntAll(lua["state"])
  743. // if lua_state == sp.Sp_state_5 {
  744. // b, err := sp.UpStateAndUpSpider(code, "", "", "", sp.Sp_state_6) //点击修改爬虫时,线上爬虫下架
  745. // if b && err == nil { //下架成功
  746. // log.Println("爬虫下架成功", code, ",任务id:", id)
  747. // ok := mgdb.Update("task", query, update, false, false) //更新任务状态
  748. // if ok {
  749. // updateOk = true
  750. // }
  751. // } else {
  752. // log.Println("修改任务失败", id)
  753. // }
  754. // } else {
  755. // ok := mgdb.Update("task", query, update, false, false) //更新任务状态
  756. // if ok {
  757. // updateOk = true
  758. // }
  759. // }
  760. // }
  761. } else {
  762. updateOk = true
  763. }
  764. }
  765. t.ServeJson(map[string]interface{}{
  766. "state": updateOk,
  767. })
  768. }
  769. //保存记录
  770. func (t *TaskM) SaveRecord() {
  771. auth := qu.IntAll(t.GetSession("auth"))
  772. if auth != role_dev {
  773. t.ServeJson("没有权限")
  774. return
  775. }
  776. state := "no"
  777. id := t.GetString("id")
  778. startTime := t.GetString("startTime")
  779. endTime := t.GetString("endTime")
  780. remark := t.GetString("remark")
  781. query := bson.M{
  782. "_id": bson.ObjectIdHex(id),
  783. }
  784. task := *mgdb.FindOne("task", query)
  785. mrecordData := task["a_mrecord"]
  786. var mreArr []map[string]interface{}
  787. newData := make(map[string]interface{})
  788. comeintime, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
  789. l_comeintime := comeintime.Unix()
  790. completeTime, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
  791. l_complete := completeTime.Unix()
  792. newData["l_mrecord_comeintime"] = l_comeintime
  793. newData["l_mrecord_complete"] = l_complete
  794. newData["s_mrecord_remark"] = remark
  795. if mrecordData != nil {
  796. myArr := qu.ObjArrToMapArr(mrecordData.([]interface{}))
  797. if myArr != nil && len(myArr) > 0 {
  798. for _, v := range myArr {
  799. mreArr = append(mreArr, v)
  800. }
  801. }
  802. }
  803. mreArr = append(mreArr, newData)
  804. task["a_mrecord"] = mreArr
  805. //保存记录
  806. ok := mgdb.Update("task", query, map[string]interface{}{
  807. "$set": task,
  808. }, false, false)
  809. var codeArr = []string{id}
  810. if ok {
  811. //修改状态
  812. sp.UpTaskState(codeArr, 1, "", int64(0))
  813. state = "yes"
  814. }
  815. t.ServeJson(map[string]interface{}{
  816. "state": state,
  817. })
  818. }
  819. //审核任务
  820. func (t *TaskM) Audit() {
  821. auth := qu.IntAll(t.GetSession("auth"))
  822. if auth != role_examine {
  823. t.ServeJson("没有权限")
  824. return
  825. }
  826. if t.Method() == "POST" {
  827. start, _ := t.GetInteger("start")
  828. limit, _ := t.GetInteger("length")
  829. draw, _ := t.GetInteger("draw")
  830. state, _ := t.GetInteger("state") //紧急程度
  831. taskState, _ := t.GetInteger("taskState")
  832. searchStr := t.GetString("search[value]")
  833. //search := strings.Replace(searchStr, " ", "", -1)
  834. search := strings.TrimSpace(searchStr)
  835. //查询自己的任务
  836. query := bson.M{}
  837. query = bson.M{
  838. "i_state": bson.M{
  839. "$gte": 3,
  840. "$lte": 5,
  841. },
  842. }
  843. if state >= 0 && taskState >= 0 {
  844. query = bson.M{
  845. "s_urgency": strconv.Itoa(state),
  846. "i_state": taskState,
  847. }
  848. } else if state < 0 && taskState >= 0 {
  849. query = bson.M{
  850. "i_state": taskState,
  851. }
  852. } else if state >= 0 && taskState < 0 {
  853. query = bson.M{
  854. "s_urgency": strconv.Itoa(state),
  855. "i_state": bson.M{
  856. "$gte": 3,
  857. "$lte": 5,
  858. },
  859. }
  860. }
  861. if search != "" {
  862. query["$or"] = []interface{}{
  863. bson.M{"s_code": bson.M{"$regex": search}},
  864. bson.M{"s_site": bson.M{"$regex": search}},
  865. bson.M{"s_channel": bson.M{"$regex": search}},
  866. }
  867. }
  868. sort := `{"%s":%d}`
  869. orderIndex := t.GetString("order[0][column]")
  870. orderName := t.GetString(fmt.Sprintf("columns[%s][data]", orderIndex))
  871. orderType := 1
  872. if t.GetString("order[0][dir]") != "asc" {
  873. orderType = -1
  874. }
  875. sort = fmt.Sprintf(sort, orderName, orderType)
  876. sorta := strings.Replace(sort, "{", "", -1)
  877. sortb := strings.Replace(sorta, "}", "", -1)
  878. sortNew := `{"l_complete": 1,` + sortb + `}`
  879. task := *mgdb.Find("task", query, sortNew, nil, false, start, limit)
  880. count := mgdb.Count("task", query)
  881. if task != nil {
  882. for _, v := range task {
  883. v["encode"] = util.Se.Encode2Hex(fmt.Sprint(v["s_code"]))
  884. if v["s_urgency"] == "1" {
  885. v["s_urgency"] = "普通"
  886. } else if v["s_urgency"] == "2" {
  887. v["s_urgency"] = "紧急"
  888. } else if v["s_urgency"] == "3" {
  889. v["s_urgency"] = "非常紧急"
  890. } else if v["s_urgency"] == "4" {
  891. v["s_urgency"] = "特别紧急"
  892. }
  893. if v["i_state"] == 0 {
  894. v["i_state"] = "待确认"
  895. } else if v["i_state"] == 1 {
  896. v["i_state"] = "待处理"
  897. } else if v["i_state"] == 2 {
  898. v["i_state"] = "处理中"
  899. } else if v["i_state"] == 3 {
  900. v["i_state"] = "待审核"
  901. } else if v["i_state"] == 4 {
  902. v["i_state"] = "审核通过"
  903. } else if v["i_state"] == 5 {
  904. v["i_state"] = "未通过"
  905. } else if v["i_state"] == 6 {
  906. v["i_state"] = "关闭"
  907. }
  908. v["l_complete"] = time.Unix(v["l_complete"].(int64), 0).Format("2006-01-02 15:04:05")
  909. v["_id"] = v["_id"].(bson.ObjectId).Hex()
  910. }
  911. }
  912. t.ServeJson(map[string]interface{}{"draw": draw, "data": task, "recordsFiltered": count, "recordsTotal": count})
  913. } else {
  914. t.Render("audit.html")
  915. }
  916. }
  917. //判断紧急度
  918. func isUrgency(cells []*xlsx.Cell) string {
  919. ug := "0"
  920. if cells[2].Value == "普通" { //不紧急
  921. ug = "1" //5天
  922. } else if cells[2].Value == "紧急" {
  923. ug = "2" //2天
  924. } else if cells[2].Value == "非常紧急" {
  925. ug = "3" //6小时
  926. } else if cells[2].Value == "特别紧急" { //非常紧急
  927. ug = "4" //2小时
  928. }
  929. return ug
  930. }
  931. //更新task
  932. func UpdateOldTask(id, descript, urgency string, complete int64) {
  933. queryT := bson.M{
  934. "_id": bson.ObjectIdHex(id),
  935. }
  936. update := bson.M{
  937. "$set": bson.M{
  938. "s_descript": descript,
  939. "s_urgency": urgency,
  940. "l_complete": complete,
  941. "l_comeintime": time.Now().Unix(),
  942. },
  943. }
  944. ok := mgdb.Update("task", queryT, update, false, false)
  945. if ok {
  946. log.Println("更新已有任务成功")
  947. } else {
  948. log.Println("更新已有任务失败")
  949. }
  950. }
  951. //分发任务
  952. func (t *TaskM) AssignChangeTaskState() {
  953. id := t.GetString("id")
  954. code := t.GetString("code")
  955. auth := qu.IntAll(t.GetSession("auth"))
  956. if auth == role_admin {
  957. //先根据code查有没有相关任务,再根据id修改任务状态
  958. query := bson.M{
  959. "s_code": code,
  960. "i_state": bson.M{
  961. "$in": []int{1, 2, 3, 5},
  962. },
  963. }
  964. task := *mgdb.FindOne("task", query)
  965. if len(task) > 0 { //有相关任务不能分发
  966. t.ServeJson("e")
  967. return
  968. }
  969. //没有相关任务,修改状态
  970. query = bson.M{
  971. "_id": bson.ObjectIdHex(id),
  972. }
  973. update := bson.M{
  974. "$set": bson.M{
  975. "i_state": 1,
  976. },
  977. }
  978. flag := mgdb.Update("task", query, update, false, false)
  979. if flag {
  980. t.ServeJson("y")
  981. t.SetSession("jumpMark", "y")
  982. } else {
  983. t.ServeJson("n")
  984. }
  985. } else {
  986. t.ServeJson("没有权限")
  987. }
  988. }
  989. //关闭任务
  990. func (t *TaskM) CloseChangeTaskState() {
  991. id := t.GetString("id")
  992. code := t.GetString("code")
  993. auth := qu.IntAll(t.GetSession("auth"))
  994. if auth == role_admin {
  995. //根据id关闭任务
  996. query := bson.M{
  997. "_id": bson.ObjectIdHex(id),
  998. }
  999. update := bson.M{
  1000. "$set": bson.M{
  1001. "i_state": 6,
  1002. },
  1003. }
  1004. flag := mgdb.Update("task", query, update, false, false)
  1005. if flag {
  1006. go updateClose(code) //更新closerate数据
  1007. t.ServeJson("y")
  1008. t.SetSession("jumpMark", "y")
  1009. } else {
  1010. t.ServeJson("n")
  1011. }
  1012. } else {
  1013. t.ServeJson("没有权限")
  1014. }
  1015. }
  1016. //批量分发任务
  1017. func (t *TaskM) BatchAssign() {
  1018. ids := strings.Split(t.GetString("ids"), ",")
  1019. codes := strings.Split(t.GetString("codes"), ",")
  1020. auth := qu.IntAll(t.GetSession("auth"))
  1021. query := bson.M{}
  1022. var existCode []string
  1023. if auth == role_admin {
  1024. for k, code := range codes {
  1025. query = bson.M{
  1026. "s_code": code,
  1027. "i_state": bson.M{
  1028. "$in": []int{1, 2, 3, 5},
  1029. },
  1030. }
  1031. task := *mgdb.FindOne("task", query)
  1032. //log.Println("task", task)
  1033. if len(task) > 0 { //任务已经存在
  1034. existCode = append(existCode, code)
  1035. } else {
  1036. id := ids[k]
  1037. query = bson.M{
  1038. "_id": bson.ObjectIdHex(id),
  1039. }
  1040. update := bson.M{
  1041. "$set": bson.M{
  1042. "i_state": 1,
  1043. },
  1044. }
  1045. flag := mgdb.Update("task", query, update, false, false)
  1046. log.Println("任务id:", id, " 更新:", flag)
  1047. }
  1048. }
  1049. t.ServeJson(existCode)
  1050. } else {
  1051. t.ServeJson("没有权限")
  1052. }
  1053. }
  1054. //批量关闭任务
  1055. func (t *TaskM) BatchClose() {
  1056. ids := strings.Split(t.GetString("ids"), ",")
  1057. codes := strings.Split(t.GetString("codes"), ",")
  1058. auth := qu.IntAll(t.GetSession("auth"))
  1059. var falseCode []string
  1060. if auth == role_admin {
  1061. for k, id := range ids {
  1062. query := bson.M{
  1063. "_id": bson.ObjectIdHex(id),
  1064. }
  1065. update := bson.M{
  1066. "$set": bson.M{
  1067. "i_state": 6,
  1068. },
  1069. }
  1070. flag := mgdb.Update("task", query, update, false, false)
  1071. log.Println("任务id:", id, " 关闭:", flag)
  1072. if !flag {
  1073. falseCode = append(falseCode, codes[k])
  1074. } else {
  1075. go updateClose(codes[k]) //更新closeRate
  1076. }
  1077. }
  1078. t.ServeJson(falseCode)
  1079. } else {
  1080. t.ServeJson("没有权限")
  1081. }
  1082. }
  1083. func (t *TaskM) GetJumpMark() {
  1084. jumpMark := t.GetSession("jumpMark")
  1085. if jumpMark == "y" {
  1086. t.DelSession("jumpMark")
  1087. t.ServeJson("y")
  1088. } else {
  1089. return
  1090. }
  1091. }
  1092. //更新closerate
  1093. func updateClose(code string) {
  1094. defer qu.Catch()
  1095. query := bson.M{
  1096. "s_code": code,
  1097. }
  1098. data := *mgdb.FindOne("closerate", query)
  1099. if data != nil && len(data) > 0 {
  1100. arr := qu.ObjArrToStringArr(data["timeClose"].([]interface{}))
  1101. last := arr[len(arr)-1] //更新最后一天的数据
  1102. timeAndClose := strings.Split(last, ":")
  1103. if len(timeAndClose) >= 2 {
  1104. arr[len(arr)-1] = timeAndClose[0] + ":3"
  1105. }
  1106. //更新
  1107. update := bson.M{
  1108. "$set": bson.M{
  1109. "timeClose": arr,
  1110. },
  1111. }
  1112. flag := mgdb.Update("closerate", query, update, false, false)
  1113. fmt.Println("closerate关闭任务:code ", flag)
  1114. }
  1115. }
  1116. func queryCriteria(urgency, taskState, event, stype int) (query bson.M) {
  1117. query = bson.M{}
  1118. if urgency >= 0 {
  1119. query["s_urgency"] = strconv.Itoa(urgency)
  1120. }
  1121. if taskState >= 0 {
  1122. query["i_state"] = taskState
  1123. }
  1124. if event >= 0 {
  1125. query["i_event"] = event
  1126. }
  1127. if stype >= 0 {
  1128. query["s_type"] = strconv.Itoa(stype)
  1129. }
  1130. // if urgency >= 0 && taskState >= 0 && event >= 0 { //选择节点,状态和紧急度
  1131. // query = bson.M{
  1132. // "s_urgency": strconv.Itoa(urgency),
  1133. // "i_state": taskState,
  1134. // "i_event": event,
  1135. // }
  1136. // } else if event >= 0 && urgency < 0 && taskState >= 0 { //选择节点和状态,未选择紧急度
  1137. // query = bson.M{
  1138. // "i_state": taskState,
  1139. // "i_event": event,
  1140. // }
  1141. // } else if event >= 0 && urgency >= 0 && taskState < 0 { //选择节点和紧急度,未选择状态
  1142. // query = bson.M{
  1143. // "i_event": event,
  1144. // "s_urgency": strconv.Itoa(urgency),
  1145. // }
  1146. // } else if event >= 0 && urgency < 0 && taskState < 0 { //选择节点,未选择紧急度和状态
  1147. // query = bson.M{
  1148. // "i_event": event,
  1149. // }
  1150. // } else if event < 0 && urgency >= 0 && taskState >= 0 { //未选择节点,选择紧急度和状态
  1151. // query = bson.M{
  1152. // "s_urgency": strconv.Itoa(urgency),
  1153. // "i_state": taskState,
  1154. // }
  1155. // } else if event < 0 && urgency < 0 && taskState >= 0 { //未选择节点和紧急度,选择状态
  1156. // query = bson.M{
  1157. // "i_state": taskState,
  1158. // }
  1159. // } else if event < 0 && urgency >= 0 && taskState < 0 { //未选择节点和状态,选择紧急度
  1160. // query = bson.M{
  1161. // "s_urgency": strconv.Itoa(urgency),
  1162. // }
  1163. // } else {
  1164. // query = make(map[string]interface{})
  1165. // }
  1166. return
  1167. }
  1168. func (t *TaskM) SearchErrLog() {
  1169. href := t.GetString("href")
  1170. data := *mgu.FindOne("regatherdata", "spider", "spider", map[string]interface{}{"href": href})
  1171. if data != nil && len(data) > 0 {
  1172. t.ServeJson("日志:" + qu.ObjToString(data["error"]))
  1173. } else {
  1174. t.ServeJson("无信息")
  1175. }
  1176. }
  1177. func (t *TaskM) SearchDataInfo() {
  1178. href := t.GetString("href")
  1179. data := *mgu.FindOne("spider_highlistdata", "spider", "spider", map[string]interface{}{"href": href})
  1180. if data != nil && len(data) > 0 {
  1181. t.ServeJson("标题:" + qu.ObjToString(data["title"]) + "\n" + "发布时间:" + qu.ObjToString(data["publishtime"]))
  1182. } else {
  1183. t.ServeJson("无信息")
  1184. }
  1185. }