front.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. package front
  2. import (
  3. "math"
  4. //"container/list"
  5. "fmt"
  6. qu "qfw/util"
  7. "qfw/util/redis"
  8. "sync/atomic"
  9. mgo "mongodb"
  10. "sort"
  11. "strings"
  12. "sync"
  13. "time"
  14. "util"
  15. )
  16. //查找未被标注的数据id
  17. func GetNoCheckedId(id, coll string) (string, bool) {
  18. defer qu.Catch()
  19. q := map[string]interface{}{
  20. "_id": map[string]interface{}{
  21. "$gt": mgo.StringTOBsonId(id),
  22. },
  23. }
  24. sess := util.MgoM.GetMgoConn()
  25. defer util.MgoM.DestoryMongoConn(sess)
  26. it := sess.DB(util.MgoM.DbName).C(coll).Find(q).Sort("_id").Select(map[string]interface{}{"_id": 1}).Iter()
  27. for tmp := make(map[string]interface{}); it.Next(&tmp); {
  28. id = mgo.BsonIdToSId(tmp["_id"])
  29. exists, err := redis.Exists("extcheck", coll+"_"+id)
  30. if err == nil && !exists {
  31. return id, exists
  32. }
  33. tmp = map[string]interface{}{}
  34. }
  35. return id, true
  36. }
  37. //查询列表数据
  38. func getListInfo(coll string, query map[string]interface{}, currentpage int) []map[string]interface{} {
  39. start := (currentpage - 1) * 50
  40. infoList, _ := util.MgoM.Find(coll, query, `{"_id":1}`, `{"_id":1,"title":1,"detail":1,"site":1,"href":1,"ck_data":1}`, false, start, 50)
  41. for k, v := range *infoList {
  42. ck_data := qu.IntAll(v["ck_data"])
  43. if ck_data > 0 {
  44. v["checked"] = true
  45. } else {
  46. v["checked"] = false
  47. }
  48. href := fmt.Sprint(v["href"])
  49. if !strings.HasPrefix(href, "http") {
  50. v["href"] = "http://" + href
  51. }
  52. v["_id"] = mgo.BsonIdToSId(v["_id"])
  53. (*infoList)[k] = v
  54. v["num"] = k + 1 + start
  55. }
  56. return *infoList
  57. }
  58. func getDetail(id, coll string) map[string]interface{} {
  59. rep := map[string]interface{}{}
  60. infoTmp, _ := util.MgoM.FindById(coll, id, ``)
  61. info := *infoTmp
  62. // if qu.ObjToString(info["check"]) == "ok" && flag != "y" {
  63. // bz_info, _ := util.MgoM.FindById(util.Config.Totablel, id, ``)
  64. // for k, v := range *bz_info {
  65. // info[k] = v
  66. // }
  67. // }
  68. info["_id"] = mgo.BsonIdToSId(info["_id"])
  69. //ck_pclisext, _ := info["ck_pclisext"].(bool)
  70. ck_pclistag, _ := info["ck_pclistag"].(bool)
  71. //ck_wodrisext, _ := info["ck_wodrisext"].(bool)
  72. //ck_pkgisext, _ := info["ck_pkgisext"].(bool)
  73. //rep["ck_pclisext"] = ck_pclisext
  74. rep["ck_pclistag"] = ck_pclistag
  75. //rep["ck_wodrisext"] = ck_wodrisext
  76. //rep["ck_pkgisext"] = ck_pkgisext
  77. href := qu.ObjToString(info["href"])
  78. if !strings.HasPrefix(href, "http") {
  79. info["href"] = "http://" + href
  80. }
  81. //info["filetext"] = util.GetFileText(info) //获取附件信息
  82. //rep["type"] = ftype
  83. rep["info"] = info
  84. common, timeplace, other := setExtComMap(info) //拼装抽取common值
  85. rep["common"] = common
  86. rep["timeplace"] = timeplace
  87. rep["other"] = other
  88. packs, packskey, pkg_new := setPaceMap(info) //拼装子包信息
  89. rep["packs"] = packs
  90. rep["packskey"] = packskey
  91. rep["pkg_new"] = pkg_new
  92. purchasinglist, isNewStatus := setPurchasingMap(info) //标的物
  93. rep["purchasinglist"] = purchasinglist
  94. rep["pcl_new"] = isNewStatus
  95. worder, worder_new := setWorderMap(info) //中标候选人
  96. rep["worder"] = worder
  97. rep["worder_new"] = worder_new
  98. otherInfo, moreInfo := setOtherInfo(info) //处理公告关联信息
  99. rep["otherInfo"] = otherInfo
  100. rep["moreInfo"] = moreInfo
  101. //
  102. if info[preKey+"purchasinglist"] != nil {
  103. rep[preKey+"purchasinglist"] = "1"
  104. } else {
  105. rep[preKey+"purchasinglist"] = "-1"
  106. }
  107. if info[preKey+"package"] != nil {
  108. rep[preKey+"package"] = "1"
  109. } else {
  110. rep[preKey+"package"] = "-1"
  111. }
  112. if info[preKey+"winnerorder"] != nil {
  113. rep[preKey+"winnerorder"] = "1"
  114. } else {
  115. rep[preKey+"winnerorder"] = "-1"
  116. }
  117. return rep
  118. }
  119. //获取公告关联信息
  120. func setOtherInfo(info map[string]interface{}) (result, moreArr []map[string]interface{}) {
  121. if otherInfo, ok := info["info"].([]interface{}); ok && len(otherInfo) > 0 {
  122. //中标,成交、合同、招标(不含变更)
  123. /*
  124. [
  125. {},
  126. {},
  127. ]
  128. */
  129. zbArr := []map[string]interface{}{}
  130. cjArr := []map[string]interface{}{}
  131. htArr := []map[string]interface{}{}
  132. zbbArr := []map[string]interface{}{}
  133. for _, tmp := range otherInfo {
  134. tmpInfo := tmp.(map[string]interface{})
  135. toptype := tmpInfo["toptype"]
  136. subtype := tmpInfo["subtype"]
  137. ptime := ""
  138. tmpPtime := qu.Int64All(tmpInfo["publishtime"])
  139. if tmpPtime > 0 {
  140. ptime = qu.FormatDateByInt64(&tmpPtime, qu.Date_Full_Layout)
  141. }
  142. tmpInfo["publishtime_str"] = ptime
  143. if subtype == "中标" {
  144. zbArr = append(zbArr, tmpInfo)
  145. } else if subtype == "成交" {
  146. cjArr = append(cjArr, tmpInfo)
  147. } else if subtype == "合同" {
  148. htArr = append(htArr, tmpInfo)
  149. } else if toptype == "招标" && subtype != "变更" {
  150. zbbArr = append(zbbArr, tmpInfo)
  151. } else { //标注页不展示的信息,更多中展示
  152. moreArr = append(moreArr, map[string]interface{}{
  153. "publishtime": tmpInfo["publishtime_str"],
  154. "subtype": subtype,
  155. "title": tmpInfo["title"],
  156. "href": util.GetJyHref(qu.ObjToString(tmpInfo["id"])),
  157. })
  158. }
  159. }
  160. publishtime := qu.Float64All(info["publishtime"])
  161. //中标信息
  162. if zbLen := len(zbArr); zbLen > 0 {
  163. rzb := DealData(zbLen, publishtime, zbArr, &moreArr)
  164. result = append(result, rzb)
  165. }
  166. //成交
  167. if cjLen := len(cjArr); cjLen > 0 {
  168. rcj := DealData(cjLen, publishtime, cjArr, &moreArr)
  169. result = append(result, rcj)
  170. }
  171. //合同
  172. if htLen := len(htArr); htLen > 0 {
  173. rht := DealData(htLen, publishtime, htArr, &moreArr)
  174. result = append(result, rht)
  175. }
  176. result = append(result, zbbArr...)
  177. }
  178. return
  179. }
  180. func DealData(tmpLen int, publishtime float64, tmp []map[string]interface{}, moreArr *[]map[string]interface{}) (resultTmp map[string]interface{}) {
  181. if tmpLen == 1 || publishtime <= 0 { //相同类型只有一条或者原公告发布时间异常取第一条公告
  182. resultTmp = tmp[0]
  183. for _, t := range tmp[1:] { //将过滤掉的数据加入到更多中
  184. *moreArr = append(*moreArr, map[string]interface{}{
  185. "publishtime": t["publishtime_str"],
  186. "subtype": t["subtype"],
  187. "title": t["title"],
  188. "href": util.GetJyHref(qu.ObjToString(t["id"])),
  189. })
  190. }
  191. return
  192. } else {
  193. diff := float64(0) //记录差值
  194. index := 0
  195. for i, zb := range tmp {
  196. pTmp := qu.Float64All(zb["publishtime"])
  197. diffTmp := math.Abs(publishtime - pTmp) //绝对值
  198. if i == 0 {
  199. diff = diffTmp
  200. } else if diffTmp < diff { //记录较小差值的数据索引位置
  201. diff = diffTmp
  202. index = i
  203. } else { //将过滤掉的数据加入到更多中
  204. *moreArr = append(*moreArr, map[string]interface{}{
  205. "publishtime": zb["publishtime_str"],
  206. "subtype": zb["subtype"],
  207. "title": zb["title"],
  208. "href": util.GetJyHref(qu.ObjToString(zb["id"])),
  209. })
  210. }
  211. }
  212. resultTmp = tmp[index]
  213. }
  214. return
  215. }
  216. //拼装中标候选人
  217. func setWorderMap(info map[string]interface{}) ([]interface{}, []map[string]interface{}) {
  218. //基本参数--中标候选人
  219. winnerorder, _ := util.Config.Biaozhu["winnerorder"].([]interface{})
  220. worders := []interface{}{}
  221. isNewAndStatus := []map[string]interface{}{}
  222. if tmpwds, ok := info["winnerorder"].([]interface{}); ok {
  223. for _, v := range tmpwds {
  224. if wd, ok := v.(map[string]interface{}); ok {
  225. //isNew, _ := wd["ck_isnew"].(bool)
  226. isNew := false
  227. status := "-1"
  228. if wd["ck_winnerorder"] != nil {
  229. status = "1"
  230. }
  231. isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status})
  232. wds := []interface{}{}
  233. for _, cp := range winnerorder {
  234. cp, _ := cp.(map[string]interface{})
  235. value := wd[qu.ObjToString(cp["key"])]
  236. if value == nil {
  237. value = ""
  238. }
  239. tp := map[string]interface{}{
  240. "key": cp["key"],
  241. "descript": cp["descript"],
  242. "value": value,
  243. "status": status,
  244. }
  245. wds = append(wds, tp)
  246. }
  247. worders = append(worders, wds)
  248. }
  249. }
  250. }
  251. return worders, isNewAndStatus
  252. }
  253. //拼装标的物
  254. func setPurchasingMap(info map[string]interface{}) ([]interface{}, []map[string]interface{}) {
  255. purchasinglist, _ := util.Config.Biaozhu["purchasinglist"].([]interface{})
  256. purchasinglists := []interface{}{}
  257. //isNewPcl := []bool{} //记录子包是否是新增的
  258. isNewAndStatus := []map[string]interface{}{}
  259. if tmpcls, ok := info["purchasinglist"].([]interface{}); ok {
  260. for _, v := range tmpcls {
  261. if pcl, ok := v.(map[string]interface{}); ok {
  262. //isNew, _ := pcl["ck_isnew"].(bool)
  263. isNew := false
  264. status := "-1"
  265. if pcl["ck_purchasinglist"] != nil {
  266. status = "1"
  267. }
  268. //isNewPcl = append(isNewPcl, isNew)
  269. isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status})
  270. pcls := []interface{}{}
  271. for _, ps := range purchasinglist {
  272. ps, _ := ps.(map[string]interface{})
  273. value := pcl[qu.ObjToString(ps["key"])]
  274. if value == nil {
  275. value = ""
  276. }
  277. tp := map[string]interface{}{
  278. "key": ps["key"],
  279. "descript": ps["descript"],
  280. "value": value,
  281. "status": status,
  282. }
  283. // if pcl[preKey+fmt.Sprint(tp["key"])] == nil {
  284. // tp["status"] = "-1"
  285. // } else {
  286. // tp["status"] = "1"
  287. // }
  288. pcls = append(pcls, tp)
  289. }
  290. purchasinglists = append(purchasinglists, pcls)
  291. }
  292. }
  293. }
  294. return purchasinglists, isNewAndStatus
  295. }
  296. //拼装子包信息
  297. func setPaceMap(info map[string]interface{}) ([]map[string]interface{}, []string, []bool) {
  298. var confpack []interface{}
  299. confpack, _ = util.Config.Biaozhu["package"].([]interface{})
  300. packs := map[string]map[string]interface{}{}
  301. sortpackskey := []string{}
  302. isNewPkg := map[string]bool{} //记录子包是否是新增的
  303. if packages, ok := info["package"].(map[string]interface{}); ok && len(packages) > 0 {
  304. for k, tmpackage := range packages { //遍历分包
  305. if tmppack, ok := tmpackage.(map[string]interface{}); ok {
  306. //isNew, _ := tmppack["ck_isnew"].(bool)
  307. isNew := false
  308. status := "-1"
  309. if tmppack["ck_package"] != nil {
  310. status = "1"
  311. }
  312. isNewPkg[k] = isNew
  313. sortpackskey = append(sortpackskey, k)
  314. pack := []interface{}{}
  315. for _, cpack := range confpack {
  316. cpack, _ := cpack.(map[string]interface{})
  317. key := qu.ObjToString(cpack["key"])
  318. if key == "winner" || key == "bidamount" { //中标单位和中标金额winner_all特殊处理
  319. continue
  320. }
  321. tp := map[string]interface{}{
  322. "key": key,
  323. "descript": cpack["descript"],
  324. }
  325. if tmppack[fmt.Sprint(tp["key"])] != nil {
  326. tp["value"] = tmppack[qu.ObjToString(tp["key"])]
  327. } else {
  328. tp["value"] = ""
  329. }
  330. tp["status"] = status
  331. pack = append(pack, tp)
  332. }
  333. //特殊处理中标单位和中标金额
  334. winnerall := []interface{}{}
  335. if tmpWinnerAll, ok := tmppack["winner_all"].([]interface{}); ok && len(tmpWinnerAll) > 0 {
  336. for _, tmp := range tmpWinnerAll {
  337. tmpMap := tmp.(map[string]interface{})
  338. win := map[string]interface{}{
  339. "descript": "标段(包)中标单位",
  340. "key": "winner",
  341. "status": status,
  342. "value": qu.ObjToString(tmpMap["winner"]),
  343. }
  344. winnerall = append(winnerall, win)
  345. var bidamount interface{}
  346. if tmpMap["bidamount"] == nil {
  347. bidamount = ""
  348. } else {
  349. bidamount = fmt.Sprint(tmpMap["bidamount"])
  350. }
  351. bid := map[string]interface{}{
  352. "descript": "标段(包)中标金额",
  353. "key": "bidamount",
  354. "status": status,
  355. "value": bidamount,
  356. }
  357. winnerall = append(winnerall, bid)
  358. }
  359. } else {
  360. winnerall = append(winnerall, map[string]interface{}{
  361. "descript": "标段(包)中标单位",
  362. "key": "winner",
  363. "status": "-1",
  364. "value": "",
  365. })
  366. winnerall = append(winnerall, map[string]interface{}{
  367. "descript": "标段(包)中标金额",
  368. "key": "bidamount",
  369. "status": "-1",
  370. "value": "",
  371. })
  372. }
  373. packs[k] = map[string]interface{}{
  374. "pack": pack,
  375. "packstatus": status,
  376. "winnerall": winnerall,
  377. }
  378. }
  379. }
  380. }
  381. sort.Strings(sortpackskey)
  382. packages := []map[string]interface{}{}
  383. isNewPkgArr := []bool{}
  384. for _, v := range sortpackskey {
  385. packages = append(packages, packs[v])
  386. isNewPkgArr = append(isNewPkgArr, isNewPkg[v])
  387. }
  388. return packages, sortpackskey, isNewPkgArr
  389. }
  390. //拼装抽取common值
  391. func setExtComMap(info map[string]interface{}) ([]interface{}, []interface{}, []interface{}) {
  392. //基本参数
  393. common, _ := util.Config.Biaozhu["common"].([]interface{})
  394. for k, tmp := range common {
  395. if cp, ok := tmp.(map[string]interface{}); ok {
  396. if info[fmt.Sprint(cp["key"])] == nil {
  397. cp["value"] = ""
  398. } else {
  399. if cp["key"] == "subtype" {
  400. if info["toptype"] != nil && info["subtype"] != nil {
  401. cp["value"] = qu.ObjToString(info["toptype"]) + "-" + qu.ObjToString(info[fmt.Sprint(cp["key"])])
  402. } else {
  403. cp["value"] = ""
  404. }
  405. } else {
  406. cp["value"] = info[fmt.Sprint(cp["key"])]
  407. }
  408. }
  409. if info[preKey+fmt.Sprint(cp["key"])] == nil {
  410. cp["status"] = "-1"
  411. } else {
  412. cp["status"] = "1"
  413. }
  414. common[k] = cp
  415. }
  416. }
  417. //时间地点信息
  418. timeplace, _ := util.Config.Biaozhu["timeplace"].([]interface{})
  419. for k, tmp := range timeplace {
  420. if tp, ok := tmp.(map[string]interface{}); ok {
  421. if info[fmt.Sprint(tp["key"])] == nil {
  422. tp["value"] = ""
  423. } else {
  424. key := tp["key"]
  425. if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" {
  426. tmpTime := qu.Int64All(info[fmt.Sprint(tp["key"])])
  427. if tmpTime > 0 {
  428. tp["value"] = qu.FormatDateByInt64(&tmpTime, qu.Date_Full_Layout)
  429. } else {
  430. tp["value"] = info[qu.ObjToString(tp["key"])]
  431. }
  432. } else {
  433. tp["value"] = info[fmt.Sprint(tp["key"])]
  434. }
  435. }
  436. if info[preKey+fmt.Sprint(tp["key"])] == nil {
  437. tp["status"] = "-1"
  438. } else {
  439. tp["status"] = "1"
  440. }
  441. timeplace[k] = tp
  442. }
  443. }
  444. //other信息
  445. other, _ := util.Config.Biaozhu["other"].([]interface{})
  446. for k, tmp := range other {
  447. if cp, ok := tmp.(map[string]interface{}); ok {
  448. if info[fmt.Sprint(cp["key"])] == nil {
  449. cp["value"] = ""
  450. } else {
  451. if cp["key"] == "signaturedate" {
  452. bidopentime := qu.Int64All(info[fmt.Sprint(cp["key"])])
  453. if bidopentime > 0 {
  454. cp["value"] = qu.FormatDateByInt64(&bidopentime, qu.Date_Full_Layout)
  455. } else {
  456. cp["value"] = info[qu.ObjToString(cp["key"])]
  457. }
  458. } else {
  459. cp["value"] = info[fmt.Sprint(cp["key"])]
  460. }
  461. }
  462. //log.Println(cp)
  463. if info[preKey+fmt.Sprint(cp["key"])] == nil {
  464. cp["status"] = "-1"
  465. } else {
  466. cp["status"] = "1"
  467. }
  468. other[k] = cp
  469. }
  470. }
  471. return common, timeplace, other
  472. }
  473. //标注基本字段
  474. func BzJBZD(content []interface{}, set, unset, errset map[string]interface{}) {
  475. info, _ := content[0].(map[string]interface{})
  476. if uInputs, ok := info["uInput"].([]interface{}); ok {
  477. for _, tmp := range uInputs {
  478. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  479. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  480. key := qu.ObjToString(tmpMap["key"]) //字段
  481. if key == "" {
  482. continue
  483. }
  484. if status == 2 || status == 3 { //新增、修改
  485. input := tmpMap["input"] //值
  486. if key == "bidamounttype" || key == "subtype" || key == "attach_discern" || key == "attach_ext" || key == "isrepeat" { //附件识别、抽取select
  487. input = tmpMap["select"]
  488. }
  489. if input == "" {
  490. unset[key] = "" //表示删除
  491. } else {
  492. if key == "budget" || key == "bidamount" || key == "biddiscount" {
  493. input = qu.Float64All(input)
  494. }
  495. if key == "subtype" {
  496. if topsubtype := strings.Split(qu.ObjToString(input), "-"); len(topsubtype) == 2 {
  497. set["toptype"] = topsubtype[0]
  498. set[key] = topsubtype[1]
  499. }
  500. } else {
  501. set[key] = input
  502. }
  503. }
  504. errset[key] = status
  505. } else if status == 4 { //删除
  506. unset[key] = ""
  507. errset[key] = status
  508. }
  509. set[preKey+key] = status //记录状态
  510. }
  511. }
  512. }
  513. }
  514. //qu.Debug("set---", set)
  515. // qu.Debug("unset---", unset)
  516. }
  517. //标注时间地点
  518. func BzSJDD(content []interface{}, set, unset, errset map[string]interface{}) {
  519. info, _ := content[0].(map[string]interface{})
  520. if uInputs, ok := info["uInput"].([]interface{}); ok {
  521. for _, tmp := range uInputs {
  522. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  523. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  524. key := qu.ObjToString(tmpMap["key"]) //字段
  525. if status == 2 || status == 3 { //新增、修改
  526. input := tmpMap["input"] //值
  527. if input == "" {
  528. unset[key] = ""
  529. } else {
  530. if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" {
  531. inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local)
  532. input = inputTmp.Unix()
  533. } else if key == "project_duration" {
  534. input = qu.IntAll(input)
  535. }
  536. set[key] = input
  537. }
  538. errset[key] = status
  539. } else if status == 4 { //删除
  540. unset[key] = ""
  541. errset[key] = status
  542. }
  543. set[preKey+key] = status
  544. }
  545. }
  546. }
  547. }
  548. // qu.Debug("set---", set)
  549. // qu.Debug("unset---", unset)
  550. }
  551. //标注标的信息
  552. func BzBDXX(content []interface{}, set, unset, errset map[string]interface{}, isext, istag bool, status int) {
  553. //qu.Debug("是否抽取:", status, isext, len(content), errset)
  554. if status == -1 {
  555. return
  556. }
  557. //set["ck_pclisext"] = isext //标的信息是否抽取标记
  558. set["ck_pclistag"] = istag //标的信息是否标注完全
  559. purchasinglist := []interface{}{}
  560. delpclson := 0
  561. for _, con := range content {
  562. info, _ := con.(map[string]interface{})
  563. isNew, _ := info["ck_isnew"].(bool) //是否是新增子包
  564. pclSonStatus := qu.IntAll(info["status"])
  565. if pclSonStatus == 4 {
  566. delpclson++
  567. }
  568. if uInputs, ok := info["uInput"].([]interface{}); ok {
  569. result := map[string]interface{}{
  570. "ck_isnew": isNew,
  571. }
  572. for _, tmp := range uInputs {
  573. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  574. key := qu.ObjToString(tmpMap["key"]) //字段
  575. input := tmpMap["input"] //值
  576. //status := qu.IntAll(tmpMap["status"])
  577. isNull := false
  578. if input == "" { //判断前台页面是否填值,无值不进行字段存储
  579. isNull = true
  580. } else if key == "number" || key == "unitprice" || key == "totalprice" {
  581. input = qu.Float64All(input)
  582. }
  583. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  584. result[key] = input
  585. }
  586. //result[preKey+key] = status
  587. // if !isNew && (status == 2 || status == 3 || status == 4) {
  588. // errResult[key] = status //记录哪个字段错误
  589. // }
  590. }
  591. }
  592. if pclSonStatus != -1 { //没有标注的标的信息不打标记
  593. result["ck_purchasinglist"] = pclSonStatus
  594. }
  595. if len(result) > 0 && pclSonStatus != 4 {
  596. purchasinglist = append(purchasinglist, result)
  597. }
  598. }
  599. }
  600. if status != 1 { //如果purchasinglist状态不是1,errdata则记录原purchasinglist字段
  601. errset["purchasinglist"] = true
  602. }
  603. qu.Debug("purchasinglist", len(purchasinglist))
  604. if len(purchasinglist)+delpclson == len(content) {
  605. if len(purchasinglist) > 0 {
  606. set["purchasinglist"] = purchasinglist
  607. }
  608. set[preKey+"purchasinglist"] = status
  609. if len(content) > 0 && delpclson == len(content) { //只有删除
  610. unset["purchasinglist"] = ""
  611. }
  612. }
  613. qu.Debug("set---", set)
  614. qu.Debug("errset---", errset)
  615. qu.Debug("unset---", unset)
  616. }
  617. //标注多包信息
  618. func BzDBXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) {
  619. //qu.Debug("是否抽取:", status, isext, len(content), errset)
  620. if status == -1 {
  621. return
  622. }
  623. //set["ck_pkgisext"] = isext //多包是否抽取标记
  624. pkgs := map[string]interface{}{}
  625. //errMap := map[string]interface{}{}
  626. newNum := 1
  627. delpkgson := 0 //记录子包删除个数
  628. for _, con := range content {
  629. info, _ := con.(map[string]interface{})
  630. pkgSonStatus := qu.IntAll(info["status"])
  631. if pkgSonStatus == 4 {
  632. delpkgson++
  633. }
  634. num := fmt.Sprint(info["num"]) //包号
  635. isNew, _ := info["ck_isnew"].(bool) //是否是新增子包
  636. if isNew { //新增子包新建包名
  637. num = "new" + fmt.Sprint(newNum)
  638. newNum++
  639. }
  640. if uInputs, ok := info["uInput"].([]interface{}); ok {
  641. result := map[string]interface{}{
  642. "ck_isnew": isNew,
  643. }
  644. //errResult := map[string]interface{}{}
  645. winnerArr := []interface{}{}
  646. bidamountArr := []interface{}{}
  647. for _, tmp := range uInputs {
  648. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  649. key := qu.ObjToString(tmpMap["key"]) //字段
  650. input := tmpMap["input"] //值
  651. //status := qu.IntAll(tmpMap["status"])
  652. isNull := false //记录字段是否有值
  653. if key == "bidamounttype" {
  654. input = tmpMap["select"]
  655. } else {
  656. if input == "" { //判断前台页面是否填值,无值不进行字段存储
  657. isNull = true
  658. } else if key == "bidamount" || key == "budget" {
  659. input = qu.Float64All(input)
  660. }
  661. }
  662. if key == "winner" {
  663. if isNull {
  664. winnerArr = append(winnerArr, nil)
  665. } else {
  666. winnerArr = append(winnerArr, input)
  667. }
  668. continue
  669. } else if key == "bidamount" {
  670. if isNull {
  671. bidamountArr = append(bidamountArr, nil)
  672. } else {
  673. bidamountArr = append(bidamountArr, input)
  674. }
  675. continue
  676. }
  677. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  678. result[key] = input
  679. }
  680. //result[preKey+key] = status
  681. // if !isNew && status >= 2 {
  682. // errResult[key] = status //记录哪个字段错误
  683. // }
  684. }
  685. }
  686. winner_all := []interface{}{}
  687. if len(winnerArr) == len(bidamountArr) {
  688. for i, w := range winnerArr {
  689. b := bidamountArr[i]
  690. wbMap := map[string]interface{}{}
  691. if w != nil {
  692. wbMap["winner"] = w
  693. }
  694. if b != nil {
  695. wbMap["bidamount"] = b
  696. }
  697. if len(wbMap) > 0 {
  698. winner_all = append(winner_all, wbMap)
  699. }
  700. }
  701. }
  702. if len(winner_all) > 0 {
  703. result["winner_all"] = winner_all
  704. }
  705. result["ck_package"] = pkgSonStatus
  706. // if len(errResult) > 0 {
  707. // errMap[num] = errResult
  708. // }
  709. if len(result) > 0 && pkgSonStatus != 4 { //要删除的子包不再保存
  710. pkgs[num] = result
  711. }
  712. }
  713. }
  714. if status != 1 { //如果package状态不是1,errdata则记录原package字段
  715. errset["package"] = true
  716. }
  717. // if len(errMap) > 0 {
  718. // errset["package"] = errMap
  719. // }
  720. qu.Debug("pkgs", len(pkgs))
  721. if len(pkgs)+delpkgson == len(content) {
  722. if len(pkgs) > 0 {
  723. set["package"] = pkgs
  724. }
  725. set[preKey+"package"] = status
  726. if len(content) > 0 && delpkgson == len(content) { //只有删除
  727. unset["package"] = ""
  728. }
  729. }
  730. // qu.Debug("set---", set)
  731. // qu.Debug("errset---", errset)
  732. }
  733. //标注中标候选人信息
  734. func BzZBHXRXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) {
  735. //qu.Debug("是否抽取:", status, isext, len(content), errset)
  736. if status == -1 {
  737. return
  738. }
  739. //set["ck_wodrisext"] = isext //中标候选人是否抽取标记
  740. winnerorder := []interface{}{}
  741. delwodrson := 0
  742. for _, con := range content {
  743. info, _ := con.(map[string]interface{})
  744. isNew, _ := info["ck_isnew"].(bool) //是否是新增子包
  745. wodrSonStatus := qu.IntAll(info["status"])
  746. if wodrSonStatus == 4 {
  747. delwodrson++
  748. }
  749. if uInputs, ok := info["uInput"].([]interface{}); ok {
  750. result := map[string]interface{}{
  751. "ck_isnew": isNew,
  752. }
  753. for _, tmp := range uInputs {
  754. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  755. key := qu.ObjToString(tmpMap["key"]) //字段
  756. input := tmpMap["input"] //值
  757. isNull := false
  758. if input == "" { //判断前台页面是否填值,无值不进行字段存储
  759. isNull = true
  760. } else if key == "price" {
  761. input = qu.Float64All(input)
  762. }
  763. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  764. result[key] = input
  765. }
  766. result["ck_winnerorder"] = wodrSonStatus
  767. // result[preKey+key] = status
  768. // if !isNew && (status == 2 || status == 3 || status == 4) {
  769. // errResult[key] = status //记录哪个字段错误
  770. // }
  771. }
  772. }
  773. if len(result) > 0 && wodrSonStatus != 4 {
  774. winnerorder = append(winnerorder, result)
  775. }
  776. }
  777. }
  778. if status != 1 { //如果winnerorder状态不是1,errdata则记录原winnerorder字段
  779. errset["winnerorder"] = true
  780. }
  781. qu.Debug("winnerorder", len(winnerorder))
  782. if len(winnerorder)+delwodrson == len(content) {
  783. if len(winnerorder) > 0 {
  784. set["winnerorder"] = winnerorder
  785. }
  786. set[preKey+"winnerorder"] = status
  787. if len(content) > 0 && delwodrson == len(content) { //只有删除
  788. unset["winnerorder"] = ""
  789. }
  790. }
  791. qu.Debug("set---", set)
  792. qu.Debug("unset---", unset)
  793. qu.Debug("errset---", errset)
  794. }
  795. //标注其余信息
  796. func BzQYXX(content []interface{}, set, unset, errset map[string]interface{}) {
  797. info, _ := content[0].(map[string]interface{})
  798. if uInputs, ok := info["uInput"].([]interface{}); ok {
  799. for _, tmp := range uInputs {
  800. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  801. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  802. key := qu.ObjToString(tmpMap["key"]) //字段
  803. qu.Debug(key, "-----", status)
  804. if status == 2 || status == 3 { //新增、修改
  805. input := tmpMap["input"] //值
  806. if key == "isppp" || key == "contract_guarantee" || key == "bid_guarantee" {
  807. input = tmpMap["select"]
  808. }
  809. if input == "" {
  810. unset[key] = ""
  811. } else {
  812. if key == "signaturedate" { //
  813. inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local)
  814. input = inputTmp.Unix()
  815. } else if key == "bid_bond" || key == "contract_bond" || key == "supervisorrate" || key == "agencyrate" || key == "docamount" || key == "agencyfee" {
  816. input = qu.Float64All(input)
  817. }
  818. set[key] = input
  819. }
  820. errset[key] = status
  821. } else if status == 4 { //删除
  822. unset[key] = ""
  823. errset[key] = status
  824. }
  825. set[preKey+key] = status
  826. }
  827. }
  828. }
  829. }
  830. // qu.Debug("set---", set)
  831. // qu.Debug("unset---", unset)
  832. }
  833. func mapIntAdd(k, val string, tmp map[string]map[string]int) map[string]map[string]int {
  834. key := k[3:]
  835. var keyct map[string]int
  836. if tmp[key] == nil {
  837. keyct = map[string]int{
  838. "ok": 0,
  839. "fail": 0,
  840. "default": 0,
  841. }
  842. } else {
  843. keyct = tmp[key]
  844. }
  845. if val == "1" {
  846. keyct["ok"] += 1
  847. } else if val == "0" {
  848. keyct["fail"] += 1
  849. } else {
  850. keyct["default"] += 1
  851. }
  852. tmp[key] = keyct
  853. return tmp
  854. }
  855. //通过id查询数据
  856. func GetDataById(coll string, ids []string, stype string, tmp map[string]map[string]interface{}) (bool, string, int64) {
  857. defer qu.Catch()
  858. success := true
  859. msg := ""
  860. wg := &sync.WaitGroup{}
  861. lock := &sync.Mutex{}
  862. ch := make(chan bool, 10)
  863. n := int64(0)
  864. for i, id := range ids {
  865. wg.Add(1)
  866. ch <- true
  867. go func(i int, id string, success *bool, msg *string) {
  868. defer func() {
  869. wg.Done()
  870. <-ch
  871. }()
  872. /*
  873. 1.查bidding
  874. 2.查extract
  875. 3.extract合并到bidding(删除item字段以为与客户需要的item不是一个含义)
  876. 4.对比marked表,替换已标注过的字段值,补充标记
  877. 5.合并客户所需字段信息,补充id字段
  878. 6.若为同步时,删除原有id对应的信息,新增该id对应的_id信息
  879. */
  880. tmpBidColl := util.BidColl1 //bidding
  881. //查询bidding
  882. if id < util.BIDDINGSTARTID {
  883. tmpBidColl = util.BidColl2 //bidding_back
  884. }
  885. bidData, _ := util.MgoB.FindById(tmpBidColl, id, nil)
  886. if bidData != nil && len(*bidData) > 0 { //bidding表数据存在
  887. //查询extract
  888. extData, _ := util.MgoE.FindById(util.ExtColl1, id, nil)
  889. if extData == nil || len(*extData) == 0 {
  890. extData, _ = util.MgoE.FindById(util.ExtColl2, id, nil)
  891. }
  892. //抽取表字段合并到bidding
  893. if extData != nil && len(*extData) > 0 {
  894. for k, v := range *extData {
  895. (*bidData)[k] = v
  896. }
  897. }
  898. //删除item
  899. delete((*bidData), "item")
  900. //对比marked表是否已标注该数据
  901. markData, _ := util.MgoM.FindById(util.Config.Fromtable, id, nil)
  902. if markData != nil && len(*markData) > 0 {
  903. UpdateMarkColl(bidData, markData) //比对更新数据
  904. } else {
  905. (*bidData)["ck_data"] = 0 //设置ck_data默认值0
  906. //多包、中标候选人、标的信息是否抽取
  907. if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 {
  908. (*bidData)["ck_pkgisext"] = true
  909. } else {
  910. (*bidData)["ck_pkgisext"] = false
  911. }
  912. if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 {
  913. (*bidData)["ck_wodrisext"] = true
  914. } else {
  915. (*bidData)["ck_wodrisext"] = false
  916. }
  917. if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 {
  918. (*bidData)["ck_pclisext"] = true
  919. } else {
  920. (*bidData)["ck_pclisext"] = false
  921. }
  922. }
  923. //合并导入表中客户所需的字段
  924. if len(tmp) > 0 {
  925. for k, v := range tmp[id] {
  926. (*bidData)[k] = v
  927. }
  928. }
  929. //补充id
  930. (*bidData)["id"] = id
  931. if stype == "syncoll" { //同步数据时删除原始数据
  932. if util.MgoM.Delete(coll, `{"id":"`+id+`"}`) == 0 {
  933. lock.Lock()
  934. *msg += "同步未删除成功数据id:" + id + ";\n"
  935. *success = false
  936. lock.Unlock()
  937. }
  938. }
  939. //保存数据
  940. if util.MgoM.SaveByOriID(coll, bidData) {
  941. atomic.AddInt64(&n, 1) //计数
  942. } else {
  943. lock.Lock()
  944. *success = false
  945. if stype == "excel" {
  946. *msg += "第" + fmt.Sprint(i+2) + "行未保存成功数据_id:" + id + ";\n"
  947. } else {
  948. *msg += "未保存成功数据_id:" + id + ";\n"
  949. }
  950. lock.Unlock()
  951. }
  952. } else {
  953. lock.Lock()
  954. *success = false
  955. if stype == "excel" {
  956. *msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n"
  957. } else {
  958. *msg += "未查询到数据_id:" + id + ";\n"
  959. }
  960. lock.Unlock()
  961. }
  962. }(i, id, &success, &msg)
  963. }
  964. wg.Wait()
  965. return success, msg, n
  966. }
  967. //通过id查询数据
  968. func GetDataById1(coll string, ids []string, stype string, tmp map[string]map[string]interface{}) (bool, string, int64) {
  969. defer qu.Catch()
  970. success := true
  971. msg := ""
  972. wg := &sync.WaitGroup{}
  973. lock := &sync.Mutex{}
  974. ch := make(chan bool, 10)
  975. n := int64(0)
  976. for i, id := range ids {
  977. wg.Add(1)
  978. ch <- true
  979. go func(i int, id string, success *bool, msg *string) {
  980. defer func() {
  981. wg.Done()
  982. <-ch
  983. }()
  984. /*
  985. 1.查bidding
  986. 2.查extract
  987. 3.extract合并到bidding(删除item字段以为与客户需要的item不是一个含义)
  988. 4.对比marked表,替换已标注过的字段值,补充标记
  989. 5.合并客户所需字段信息,补充id字段
  990. 6.若为同步时,删除原有id对应的信息,新增该id对应的_id信息
  991. */
  992. tmpBidColl := util.BidColl1 //bidding
  993. //查询bidding
  994. if id < util.BIDDINGSTARTID {
  995. tmpBidColl = util.BidColl2 //bidding_back
  996. }
  997. bidData, _ := util.MgoB.FindById(tmpBidColl, id, nil)
  998. if bidData != nil && len(*bidData) > 0 { //bidding表数据存在
  999. //查询extract
  1000. extData, _ := util.MgoE.FindById(util.ExtColl1, id, nil)
  1001. if extData == nil || len(*extData) == 0 {
  1002. extData, _ = util.MgoE.FindById(util.ExtColl2, id, nil)
  1003. }
  1004. //抽取表字段合并到bidding
  1005. if extData != nil && len(*extData) > 0 {
  1006. for k, v := range *extData {
  1007. (*bidData)[k] = v
  1008. }
  1009. }
  1010. //删除item
  1011. delete((*bidData), "item")
  1012. //对比marked表是否已标注该数据
  1013. markData, _ := util.MgoM.FindById(util.Config.Fromtable, id, nil)
  1014. if markData != nil && len(*markData) > 0 {
  1015. UpdateMarkColl(bidData, markData) //比对更新数据
  1016. } else {
  1017. (*bidData)["ck_data"] = 0 //设置ck_data默认值0
  1018. //多包、中标候选人、标的信息是否抽取
  1019. if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 {
  1020. (*bidData)["ck_pkgisext"] = true
  1021. } else {
  1022. (*bidData)["ck_pkgisext"] = false
  1023. }
  1024. if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 {
  1025. (*bidData)["ck_wodrisext"] = true
  1026. } else {
  1027. (*bidData)["ck_wodrisext"] = false
  1028. }
  1029. if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 {
  1030. (*bidData)["ck_pclisext"] = true
  1031. } else {
  1032. (*bidData)["ck_pclisext"] = false
  1033. }
  1034. }
  1035. //合并导入表中客户所需的字段
  1036. if len(tmp) > 0 {
  1037. for k, v := range tmp[id] {
  1038. (*bidData)[k] = v
  1039. }
  1040. }
  1041. //补充id
  1042. (*bidData)["id"] = id
  1043. if stype == "syncoll" { //同步数据时删除原始数据
  1044. if util.MgoM.Delete(coll, `{"id":"`+id+`"}`) == 0 {
  1045. lock.Lock()
  1046. *msg += "同步未删除成功数据id:" + id + ";\n"
  1047. *success = false
  1048. lock.Unlock()
  1049. }
  1050. }
  1051. // 处理 package winner_all
  1052. if p, o1 := (*bidData)["package"].(map[string]interface{}); o1 {
  1053. for _, v := range p {
  1054. v1 := v.(map[string]interface{})
  1055. t := make(map[string]interface{})
  1056. if v1["winner"] != nil {
  1057. t["winner"] = v1["winner"]
  1058. }
  1059. if v1["bidamount"] != nil {
  1060. t["bidamount"] = v1["bidamount"]
  1061. }
  1062. if len(t) > 0 {
  1063. v1["winner_all"] = append([]map[string]interface{}{}, t)
  1064. }
  1065. }
  1066. }
  1067. // 补充filetext
  1068. (*bidData)["filetext"] = util.GetFileText(*bidData)
  1069. qu.Debug("es find project")
  1070. // es查询项目合并信息
  1071. esQ := `{"query":{"bool":{"must":[{"term":{"ids":"` + id + `"}}]}}}`
  1072. info := util.Es.Get("projectset", "projectset", esQ)
  1073. if len(*info) == 1 {
  1074. ids := qu.ObjArrToStringArr((*info)[0]["ids"].([]interface{}))
  1075. if len(ids) > 0 {
  1076. var infolist []map[string]interface{}
  1077. for _, v := range ids {
  1078. if v == id { // 当前公告
  1079. continue
  1080. }
  1081. if v < util.BIDDINGSTARTID {
  1082. tmpBidColl = util.BidColl2 //bidding_back
  1083. }
  1084. bid, b := util.MgoB.FindById(tmpBidColl, id, nil)
  1085. if b && len(*bid) > 0 {
  1086. tmp := make(map[string]interface{})
  1087. tmp["id"] = v
  1088. tmp["title"] = (*bid)["title"]
  1089. tmp["href"] = (*bid)["href"]
  1090. tmp["toptype"] = (*bid)["toptype"]
  1091. tmp["subtype"] = (*bid)["subtype"]
  1092. tmp["publishtime"] = (*bid)["publishtime"]
  1093. tmp["detail"] = (*bid)["detail"]
  1094. tmp["filetext"] = util.GetFileText(*bid)
  1095. infolist = append(infolist, tmp)
  1096. }
  1097. }
  1098. (*bidData)["info"] = infolist
  1099. }
  1100. } else {
  1101. qu.Debug("projectset find err", esQ)
  1102. }
  1103. //保存数据
  1104. if util.MgoM.SaveByOriID(coll, bidData) {
  1105. atomic.AddInt64(&n, 1) //计数
  1106. } else {
  1107. lock.Lock()
  1108. *success = false
  1109. if stype == "excel" {
  1110. *msg += "第" + fmt.Sprint(i+2) + "行未保存成功数据_id:" + id + ";\n"
  1111. } else {
  1112. *msg += "未保存成功数据_id:" + id + ";\n"
  1113. }
  1114. lock.Unlock()
  1115. }
  1116. } else {
  1117. lock.Lock()
  1118. *success = false
  1119. if stype == "excel" {
  1120. *msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n"
  1121. } else {
  1122. *msg += "未查询到数据_id:" + id + ";\n"
  1123. }
  1124. lock.Unlock()
  1125. }
  1126. }(i, id, &success, &msg)
  1127. }
  1128. wg.Wait()
  1129. return success, msg, n
  1130. }
  1131. //更新数据
  1132. func UpdateMarkColl(bidData, markData *map[string]interface{}) {
  1133. defer qu.Catch()
  1134. ck_data := qu.IntAll((*markData)["ck_data"])
  1135. if ck_data == 2 { //某些字段已标注
  1136. for fk, fv := range *markData {
  1137. ckFieldArr := strings.Split(fk, preKey)
  1138. if len(ckFieldArr) == 2 {
  1139. field := ckFieldArr[1]
  1140. (*bidData)[fk] = fv //补充标记
  1141. if (*markData)[field] != nil {
  1142. (*bidData)[field] = (*markData)[field] //字段更新
  1143. }
  1144. }
  1145. }
  1146. (*bidData)["ck_data"] = 0 //marked表中该条数据如果为字段验证,临时表ck_data:0;若为数据验证ck_data:1
  1147. } else if ck_data == 1 {
  1148. *bidData = *markData
  1149. (*bidData)["ck_data"] = 1
  1150. }
  1151. }
  1152. //获取当前数据下一条的id
  1153. func GetNextDataId(id, coll string, query map[string]interface{}) string {
  1154. nextIdQuery := map[string]interface{}{
  1155. "_id": map[string]interface{}{
  1156. "$gt": mgo.StringTOBsonId(id),
  1157. },
  1158. }
  1159. for k, v := range query {
  1160. nextIdQuery[k] = v
  1161. }
  1162. one, _ := util.MgoM.Find(coll, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1)
  1163. if one != nil && len(*one) == 1 {
  1164. return mgo.BsonIdToSId((*one)[0]["_id"])
  1165. }
  1166. return id
  1167. }
  1168. //获取已标注和数据总数的信息
  1169. func GetCheckedAndAllDataInfo(query map[string]interface{}, coll string) (int, int) {
  1170. allCount := util.MgoM.Count(coll, query)
  1171. ckDataQuery := map[string]interface{}{
  1172. "ck_data": map[string]interface{}{
  1173. "$gt": 0,
  1174. },
  1175. }
  1176. for k, v := range query {
  1177. ckDataQuery[k] = v
  1178. }
  1179. checkedCount := util.MgoM.Count(coll, ckDataQuery)
  1180. return checkedCount, allCount
  1181. }
  1182. //查询表中已标数据的标注人
  1183. func GetLabeler(coll string) (labeler []string) {
  1184. defer qu.Catch()
  1185. sess := util.MgoM.GetMgoConn()
  1186. defer util.MgoM.DestoryMongoConn(sess)
  1187. it := sess.DB(util.MgoM.DbName).C(coll).Pipe([]map[string]interface{}{
  1188. // map[string]interface{}{
  1189. // "$match": map[string]interface{}{
  1190. // "s_province": "河南省",
  1191. // },
  1192. // },
  1193. {
  1194. "$group": map[string]interface{}{
  1195. "_id": "$modifyuser",
  1196. },
  1197. },
  1198. }).Iter()
  1199. for user := make(map[string]interface{}); it.Next(&user); {
  1200. if name := qu.ObjToString(user["_id"]); name != "" {
  1201. labeler = append(labeler, name)
  1202. }
  1203. }
  1204. sort.Strings(labeler)
  1205. qu.Debug("labeler:", labeler)
  1206. return
  1207. }