taskManager.go 35 KB

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