front.go 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  1. // front
  2. package front
  3. import (
  4. //"container/list"
  5. "encoding/json"
  6. "fmt"
  7. "io/ioutil"
  8. qu "qfw/util"
  9. "sync/atomic"
  10. //"qfw/util/mongodb"
  11. mgo "mongodb"
  12. //"qfw/util/redis"
  13. "sort"
  14. "strings"
  15. "sync"
  16. "time"
  17. "util"
  18. "github.com/go-xweb/xweb"
  19. _ "github.com/influxdata/influxdb-client"
  20. "github.com/tealeg/xlsx"
  21. es "gopkg.in/olivere/elastic.v1"
  22. )
  23. type Front struct {
  24. *xweb.Action
  25. //index xweb.Mapper `xweb:"/"`
  26. // pack xweb.Mapper `xweb:"/package"`
  27. listInfo xweb.Mapper `xweb:"/list"`
  28. elist xweb.Mapper `xweb:"/elist"`
  29. detail xweb.Mapper `xweb:"/detail/(.*).html"`
  30. biaozhu xweb.Mapper `xweb:"/biaozhu"`
  31. tj xweb.Mapper `xweb:"/tj"`
  32. importByExcel xweb.Mapper `xweb:"/importbyexcel"`
  33. importByEs xweb.Mapper `xweb:"/importbyes"`
  34. getEsCount xweb.Mapper `xweb:"/getescount"`
  35. finishCheck xweb.Mapper `xweb:"/finishcheck"`
  36. syncMarked xweb.Mapper `xweb:"/syncmarked"`
  37. }
  38. //var IdList *list.List //所有数据
  39. //var IdPackList *list.List //含有分包的数据
  40. var preKey = "ck_"
  41. var preErr = "err_"
  42. var SE = qu.SimpleEncrypt{Key: "topJYBX2019"}
  43. var Max, Min string
  44. var HasNo bool //预算和中标金额是否存在标记
  45. var QueryFind map[string]interface{} //查询
  46. /*
  47. status
  48. -1:初始未验证
  49. 1:正确
  50. 2:新增
  51. 3:修改
  52. 4:删除
  53. */
  54. /**
  55. //查询初始化的数据
  56. func (i *Front) Index() error {
  57. _id := ""
  58. ran := 0
  59. for {
  60. index, invalid := 0, 0
  61. if IdList.Len() == 0 {
  62. return i.Render("finish.html")
  63. }
  64. ran = util.Getrand(IdList.Len())
  65. for e := IdList.Front(); e != nil; e = e.Next() { //遍历IdList,获取id
  66. if index == ran {
  67. _id = qu.ObjToString(e.Value)
  68. invalid = redis.GetInt("extcheck", "extcheck_"+_id)
  69. break
  70. }
  71. index++
  72. }
  73. if invalid == 0 {
  74. break
  75. }
  76. if IdList.Len() < 500 { //|| IdPackList.Len() < 100
  77. qu.Debug("抽查数据剩余不足", IdList.Len())
  78. break
  79. }
  80. }
  81. redis.Put("extcheck", "extcheck_"+_id, 1, 10*60)
  82. qu.Debug("_id", _id, "---", IdList.Len())
  83. rep := getDetail(_id)
  84. //i.T["ispackage"] = ispackage
  85. //i.T["type"] = rep["type"]
  86. i.T["info"] = rep["info"]
  87. i.T["common"] = rep["common"]
  88. i.T["worder"] = rep["worder"]
  89. i.T["packs"] = rep["packs"]
  90. i.T["packskey"] = rep["packskey"]
  91. i.T["ck_pclisext"] = rep["ck_pclisext"]
  92. i.T["ck_wodrisext"] = rep["ck_wodrisext"]
  93. i.T["ck_pkgisext"] = rep["ck_pkgisext"]
  94. i.T["timeplace"] = rep["timeplace"]
  95. i.T["purchasinglist"] = rep["purchasinglist"]
  96. i.T["other"] = rep["other"]
  97. //qu.Debug(util.PurchasinglistField, util.WinnerorderField, util.PackageField)
  98. i.T["PurchasinglistField"] = util.PurchasinglistField
  99. i.T["WinnerorderField"] = util.WinnerorderField
  100. i.T["PackageField"] = util.PackageField
  101. i.T[preKey+"purchasinglist"] = rep[preKey+"purchasinglist"]
  102. i.T[preKey+"package"] = rep[preKey+"package"]
  103. i.T[preKey+"winnerorder"] = rep[preKey+"winnerorder"]
  104. i.T["worder_new"] = rep["worder_new"]
  105. i.T["pcl_new"] = rep["pcl_new"]
  106. i.T["pkg_new"] = rep["pkg_new"]
  107. return i.Render("detail.html", &i.T)
  108. }
  109. */
  110. //列表
  111. func (i *Front) ListInfo() error {
  112. spidercode := i.GetString("spidercode")
  113. coll := i.GetString("coll")
  114. field := i.GetString("field")
  115. stype := i.GetString("type")
  116. Min = i.GetString("minval")
  117. Max = i.GetString("maxval")
  118. HasNo, _ = i.GetBool("hasno")
  119. pagenum, _ := i.GetInteger("pagenum")
  120. if pagenum == 0 {
  121. pagenum = 1
  122. }
  123. if coll != "" { //指定表
  124. util.Coll = coll
  125. }
  126. if stype == "" {
  127. stype = "-1"
  128. }
  129. if field == "" {
  130. field = "-1"
  131. }
  132. listData := getListInfo(spidercode, stype, field, pagenum)
  133. //if len(listData) > 0 { //每次查询更新内存中标注数据
  134. // IdList = list.New()
  135. // for _, v := range listData {
  136. // IdList.PushBack(mgo.BsonIdToSId(v["_id"]))
  137. // }
  138. //}
  139. i.T["list"] = listData
  140. i.T["type"] = stype
  141. i.T["field"] = field
  142. i.T["spidercode"] = spidercode
  143. i.T["coll"] = coll
  144. i.T["topsubtype"] = util.TopSubStypeArr
  145. i.T["allfield"] = util.AllFieldArr
  146. i.T["fromtable"] = util.Coll
  147. i.T["dbname"] = util.Config.Dbname
  148. i.T["max"] = Max
  149. i.T["min"] = Min
  150. i.T["hasno"] = HasNo
  151. checkedNum, allNum := GetCheckedAndAllDataInfo() //已标和总数信息
  152. i.T["checkednum"] = checkedNum
  153. i.T["allnum"] = allNum
  154. i.T["pagenum"] = pagenum
  155. return i.Render("list.html", &i.T)
  156. }
  157. //标错列表
  158. func (i *Front) Elist() error {
  159. attrname := i.GetString("attrname")
  160. common := util.Config.Biaozhu["common"]
  161. elist, _ := util.MgoM.Find(util.Config.Totablel, `{"ck_`+attrname+`":"0"}`, `{"_id":1}`, `{"_id":1}`, false, -1, -1)
  162. for _, v := range *elist {
  163. v["_id"] = mgo.BsonIdToSId(v["_id"])
  164. }
  165. i.T["elist"] = *elist
  166. i.T["attrname"] = attrname
  167. i.T["common"] = common
  168. return i.Render("elist.html", &i.T)
  169. }
  170. //标注
  171. func (i *Front) Biaozhu() error {
  172. b := false
  173. obj := []map[string]interface{}{}
  174. //ispackage := i.GetString("ispackage")
  175. key := i.GetString("key")
  176. _id := i.GetString("_id")
  177. stype, _ := i.GetInteger("stype")
  178. err := json.Unmarshal([]byte(key), &obj)
  179. if err != nil {
  180. i.ServeJson(b)
  181. return nil
  182. }
  183. //base := map[string]interface{}{}
  184. set := map[string]interface{}{} //更新、新增字段
  185. unset := map[string]interface{}{} //删除字段
  186. errset := map[string]interface{}{} //记录修改的字段信息
  187. isSaveMarked := false
  188. if len(obj) == 1 { //单独保存某个一级
  189. content, ok := obj[0]["content"].([]interface{})
  190. if !ok || len(content) == 0 {
  191. i.ServeJson(b)
  192. return nil
  193. }
  194. title := qu.ObjToString(obj[0]["title"])
  195. isext, _ := obj[0]["checkType"].(bool)
  196. status := qu.IntAll(obj[0]["status"])
  197. switch title {
  198. case "基本字段":
  199. BzJBZD(content, set, unset, errset)
  200. case "时间地点":
  201. BzSJDD(content, set, unset, errset)
  202. case "标的信息":
  203. BzBDXX(content, set, unset, errset, isext, status)
  204. case "多包信息":
  205. BzDBXX(content, set, unset, errset, isext, status)
  206. case "中标候选人信息":
  207. BzZBHXRXX(content, set, unset, errset, isext, status)
  208. case "其余信息":
  209. BzQYXX(content, set, unset, errset)
  210. }
  211. } else {
  212. isSaveMarked = true
  213. for j, val := range obj {
  214. content, ok := val["content"].([]interface{})
  215. status := qu.IntAll(val["status"])
  216. if !ok {
  217. continue
  218. // i.ServeJson(b)
  219. // return nil
  220. }
  221. isext, _ := val["checkType"].(bool)
  222. if j == 0 { //基本信息
  223. BzJBZD(content, set, unset, errset)
  224. } else if j == 1 { //时间地点
  225. BzSJDD(content, set, unset, errset)
  226. } else if j == 2 { //标的物
  227. BzBDXX(content, set, unset, errset, isext, status)
  228. } else if j == 3 { //多包
  229. BzDBXX(content, set, unset, errset, isext, status)
  230. } else if j == 4 { //候选人
  231. BzZBHXRXX(content, set, unset, errset, isext, status)
  232. } else { //其余信息
  233. BzQYXX(content, set, unset, errset)
  234. }
  235. }
  236. }
  237. // qu.Debug("errset---", errset)
  238. // qu.Debug("set---", set)
  239. // qu.Debug("unset---", unset)
  240. unerrset := map[string]interface{}{} //记录errdata错误信息表删除
  241. data, _ := util.MgoM.FindById(util.Coll, _id, nil)
  242. //标注误操作处理
  243. if len(set) > 0 { //set中为本次标注保存的数据(ck_bidopentime:1;ck_buyer:2;buyer:"XXX")
  244. for s, sv := range set {
  245. //区分是标记字段,还是普通字段(标记字段:ck_buyer;普通字段:buyer)
  246. if strings.HasPrefix(s, preKey) { //标记字段
  247. status := qu.IntAll(sv)
  248. field := s[3:] //去除前缀,获得字段
  249. if s == preKey+"package" || s == preKey+"purchasinglist" || s == preKey+"winnerorder" {
  250. if (*data)[s] != nil { //package、purchasinglist、winnerorder已标注,不再修改
  251. delete(set, s)
  252. delete(set, field)
  253. continue
  254. }
  255. }
  256. if set[field] == nil && status != 4 { //表示该字段没有要修改的值,此时标记为1或4(亦或是ck_wodrisext;ck_pkgisext;ck_pclisext)
  257. continue
  258. } else { //此时有修改的值和标记2、3、4
  259. if checkedStatus := qu.IntAll((*data)[s]); checkedStatus != 0 { //已有标注信息的状态
  260. if status == 2 && checkedStatus == 4 { //4>2,errdata删除,marked新增该字段,标记变为1
  261. unerrset[field] = ""
  262. set[s] = 1
  263. } else if status == 3 {
  264. if checkedStatus == 2 { //2>3,marked 修改该字段,标记变为2
  265. set[s] = 2
  266. } else if checkedStatus == 3 { //3>3,对比errdata错误值:相等变为1,errdata删除;不等变为3,marked修改该字段
  267. errdata, _ := util.MgoM.FindById(util.Config.Totablel, _id, `{"`+field+`":1}`)
  268. if errdata != nil && len(*errdata) != 0 {
  269. errText := fmt.Sprint((*errdata)[field])
  270. text := fmt.Sprint(set[field])
  271. if errText == text {
  272. set[s] = 1
  273. unerrset[field] = ""
  274. }
  275. }
  276. }
  277. } else if status == 4 {
  278. if checkedStatus == 2 { //2>4,errdata删除,marked删除该字段,标记变为1
  279. unerrset[field] = ""
  280. set[s] = 1
  281. unset[field] = ""
  282. } else if checkedStatus == 3 { //3>4,marked删除该字段,标记变为4
  283. set[s] = 4
  284. unset[field] = ""
  285. }
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. //存储原错误信息
  293. errUpdata := map[string]interface{}{}
  294. if len(errset) > 0 {
  295. for f, v := range errset {
  296. if (*data)[preKey+f] != nil { //已标注保存过不再记录错误信息
  297. delete(errset, f)
  298. continue
  299. }
  300. // if ck, ok := (*data)[preKey+f].(int32); ok && ck != 1 { //已标注保存过不再记录错误信息
  301. // delete(errset, f)
  302. // continue
  303. // }
  304. if f == "purchasinglist" || f == "winnerorder" {
  305. pcl, _ := (*data)[f].([]interface{})
  306. pcl_err := v.([]interface{})
  307. for j, perr := range pcl_err {
  308. perrMap := perr.(map[string]interface{})
  309. if len(perrMap) > 0 {
  310. for k, status := range perrMap {
  311. if pMap, ok := pcl[j].(map[string]interface{}); ok && len(pMap) > 0 { //避免手动增加的子包找不到原数据
  312. pMap[preErr+k] = status //打上错误标记
  313. pMap[k] = pMap[k]
  314. }
  315. }
  316. }
  317. }
  318. errset[f] = (*data)[f]
  319. } else if f == "package" {
  320. pkg_err, _ := v.(map[string]interface{})
  321. pkg := (*data)["package"].(map[string]interface{})
  322. for num, v := range pkg_err {
  323. result_err := map[string]interface{}{}
  324. vMap := v.(map[string]interface{})
  325. for k, status := range vMap {
  326. if pMap, ok := pkg[num].(map[string]interface{}); ok && len(pMap) > 0 {
  327. result_err[preErr+k] = status
  328. result_err[k] = pMap[k]
  329. }
  330. }
  331. pkg_err[num] = result_err
  332. }
  333. } else {
  334. errset[f] = (*data)[f]
  335. }
  336. }
  337. //qu.Debug("errset---", errset)
  338. errset["updatetime"] = time.Now().Unix()
  339. errUpdata["$set"] = errset
  340. }
  341. if len(unerrset) > 0 {
  342. //qu.Debug("unerrset---", unerrset)
  343. errUpdata["$unset"] = unerrset
  344. }
  345. if len(errUpdata) > 0 {
  346. util.MgoM.Update(util.Config.Totablel, `{"_id":"`+_id+`"}`, errUpdata, true, false)
  347. }
  348. //qu.Debug("set---", set)
  349. //更新正确信息
  350. update := map[string]interface{}{}
  351. if len(set) > 0 {
  352. set["ck_data"] = stype
  353. set["updatetime"] = time.Now().Unix()
  354. update["$set"] = set
  355. }
  356. if len(unset) > 0 {
  357. update["$unset"] = unset
  358. }
  359. if len(update) > 0 {
  360. b = util.MgoM.Update(util.Coll, `{"_id":"`+_id+`"}`, update, false, false)
  361. if b {
  362. //for e := IdList.Front(); e != nil; e = e.Next() { //遍历IdList,删除元素
  363. // if _id == qu.ObjToString(e.Value) {
  364. // IdList.Remove(e)
  365. // break
  366. // }
  367. //}
  368. if util.Coll != util.Config.Fromtable && isSaveMarked { //util.coll此时的标注表 util.Config.Fromtable默认标注表
  369. data, _ := util.MgoM.FindById(util.Coll, _id, nil)
  370. if data != nil && len(*data) > 0 {
  371. update := map[string]interface{}{"$set": *data}
  372. if len(unset) > 0 {
  373. update["$unset"] = unset
  374. }
  375. if !util.MgoM.Update(util.Config.Fromtable, map[string]interface{}{"_id": (*data)["_id"]}, update, true, false) {
  376. qu.Debug("同步marked失败,", _id)
  377. }
  378. }
  379. }
  380. }
  381. i.ServeJson(b)
  382. }
  383. return nil
  384. }
  385. //查询信息
  386. func (i *Front) Detail(id string) error {
  387. rep := getDetail(id)
  388. //i.T["type"] = rep["type"]
  389. i.T["info"] = rep["info"]
  390. i.T["common"] = rep["common"]
  391. i.T["worder"] = rep["worder"]
  392. i.T["packs"] = rep["packs"]
  393. i.T["packskey"] = rep["packskey"]
  394. i.T["ck_pclisext"] = rep["ck_pclisext"]
  395. i.T["ck_wodrisext"] = rep["ck_wodrisext"]
  396. i.T["ck_pkgisext"] = rep["ck_pkgisext"]
  397. i.T["timeplace"] = rep["timeplace"]
  398. i.T["purchasinglist"] = rep["purchasinglist"]
  399. i.T["other"] = rep["other"]
  400. i.T["PurchasinglistField"] = util.PurchasinglistField
  401. i.T["WinnerorderField"] = util.WinnerorderField
  402. i.T["PackageField"] = util.PackageField
  403. i.T[preKey+"purchasinglist"] = rep[preKey+"purchasinglist"]
  404. i.T[preKey+"package"] = rep[preKey+"package"]
  405. i.T[preKey+"winnerorder"] = rep[preKey+"winnerorder"]
  406. i.T["worder_new"] = rep["worder_new"]
  407. i.T["pcl_new"] = rep["pcl_new"]
  408. i.T["pkg_new"] = rep["pkg_new"]
  409. i.T["nextid"] = GetNextDataId(id) //下一条id
  410. checkedNum, allNum := GetCheckedAndAllDataInfo() //已标和总数信息
  411. i.T["checkednum"] = checkedNum
  412. i.T["allnum"] = allNum
  413. return i.Render("detail.html", &i.T)
  414. }
  415. //通过excel表格导入
  416. func (i *Front) ImportByExcel() {
  417. defer qu.Catch()
  418. //success := false
  419. msg := ""
  420. importNum := 0
  421. successNum := int64(0)
  422. coll := i.GetString("excelcoll")
  423. if coll == "" {
  424. i.ServeJson(map[string]interface{}{"msg": "表名错误"})
  425. return
  426. }
  427. mf, _, err := i.GetFile("xlsx")
  428. if err == nil {
  429. binary, _ := ioutil.ReadAll(mf)
  430. xls, _ := xlsx.OpenBinary(binary)
  431. sheet := xls.Sheets[0]
  432. rows := sheet.Rows
  433. idcolnum := -1
  434. ids := []string{}
  435. cellFieldName := map[int]string{} //记录客户需求字段所在的列
  436. tmpMap := map[string]map[string]interface{}{} //excel表中需要保存字段集合
  437. for rn, row := range rows {
  438. if rn == 0 {
  439. for j, cell := range row.Cells {
  440. title := cell.Value
  441. if fieldName := util.Config.CustomerField[title]; fieldName != "" { //客户需求字段
  442. cellFieldName[j] = fieldName
  443. }
  444. if title == "唯一标识" || title == "信息标识" { //id所在列
  445. idcolnum = j
  446. }
  447. }
  448. if idcolnum == -1 {
  449. break
  450. }
  451. continue
  452. }
  453. if len(row.Cells) < len(rows[0].Cells) {
  454. break
  455. }
  456. tmp := map[string]interface{}{}
  457. for j, f := range cellFieldName {
  458. if val := row.Cells[j].Value; val != "" {
  459. if f == "capital" { //注册资金(万元)
  460. cf, _ := row.Cells[j].Float()
  461. tmp[f] = cf
  462. } else if f == "createtime" { //创建时间
  463. ci, _ := row.Cells[j].Int64()
  464. tmp[f] = ci
  465. } else {
  466. tmp[f] = val
  467. }
  468. }
  469. }
  470. id := row.Cells[idcolnum].String() //加密的id
  471. if id == "" {
  472. break
  473. }
  474. id = SE.DecodeString(id) //解密后id
  475. tmpMap[id] = tmp
  476. ids = append(ids, id)
  477. }
  478. importNum = len(ids) //excel表数据个数
  479. if importNum > 0 {
  480. _, msg, successNum = GetDataById(coll, ids, "excel", tmpMap)
  481. tmpMap = map[string]map[string]interface{}{}
  482. ids = []string{}
  483. }
  484. }
  485. msg = fmt.Sprintf("共查询%d条,导入成功%d条\n", importNum, successNum) + msg
  486. i.ServeJson(map[string]interface{}{"msg": msg})
  487. }
  488. func (i *Front) GetEsCount() {
  489. defer qu.Catch()
  490. msg := ""
  491. count := int64(0)
  492. estext := i.GetString("estext") //es查询语句
  493. esJson := map[string]interface{}{}
  494. if json.Unmarshal([]byte(estext), &esJson) != nil || len(esJson) == 0 {
  495. msg = "Es语句错误"
  496. } else {
  497. count = util.Es.Count(util.Index, util.Itype, estext)
  498. }
  499. i.ServeJson(map[string]interface{}{"count": count, "msg": msg})
  500. }
  501. //通过es语句导入
  502. func (i *Front) ImportByEs() {
  503. defer qu.Catch()
  504. //success := false
  505. msg := ""
  506. successNum := int64(0)
  507. estext := i.GetString("estext") //es查询语句
  508. coll := i.GetString("coll") //导入表
  509. if coll == "" {
  510. i.ServeJson(map[string]interface{}{"msg": "表名错误"})
  511. return
  512. }
  513. client := util.Es.GetEsConn()
  514. defer util.Es.DestoryEsConn(client)
  515. ch := make(chan bool, 5)
  516. wg := &sync.WaitGroup{}
  517. lock := &sync.Mutex{}
  518. escount := util.Es.Count(util.Index, util.Itype, estext)
  519. qu.Debug("查询总数:", escount)
  520. if escount > 0 {
  521. //查询条件类型转换
  522. var q es.Query
  523. tmpQuery := es.BoolQuery{
  524. QueryStrings: estext,
  525. }
  526. q = tmpQuery
  527. //游标查询,index不支持别名,只能写索引库的名称
  528. res, err := client.Scroll(util.Index).Query(q).Size(200).Do() //查询一条获取游标
  529. ids := []string{} //id数据
  530. if err == nil {
  531. numDocs := 0
  532. scrollId := res.ScrollId
  533. for {
  534. if scrollId == "" {
  535. qu.Debug("ScrollId Is Error")
  536. break
  537. }
  538. searchResult, err := client.Scroll(util.Index).Size(200).ScrollId(scrollId).Do() //查询
  539. if err != nil {
  540. if err.Error() == "EOS" { //迭代完毕
  541. qu.Debug("Es Search Data Over:", err)
  542. } else {
  543. qu.Debug("Es Search Data Error:", err)
  544. }
  545. break
  546. }
  547. for _, hit := range searchResult.Hits.Hits {
  548. //开始处理数据
  549. wg.Add(1)
  550. ch <- true
  551. go func(tmpHit *es.SearchHit) {
  552. defer func() {
  553. <-ch
  554. wg.Done()
  555. }()
  556. tmp := make(map[string]interface{})
  557. if json.Unmarshal(*tmpHit.Source, &tmp) == nil {
  558. id := qu.ObjToString(tmp["_id"])
  559. tmp["id"] = id //记录数据原有id
  560. lock.Lock()
  561. ids = append(ids, id)
  562. lock.Unlock()
  563. }
  564. }(hit)
  565. numDocs += 1
  566. if numDocs%500 == 0 {
  567. qu.Debug("Current:", numDocs)
  568. }
  569. }
  570. scrollId = searchResult.ScrollId
  571. }
  572. wg.Wait()
  573. client.ClearScroll().ScrollId(scrollId).Do() //清理游标
  574. //qu.Debug("Result Data Count:", numDocs)
  575. } else {
  576. qu.Debug("Es Search Data Error")
  577. }
  578. //判断数量
  579. if int64(len(ids)) != escount {
  580. msg = "查询数据和结果不一致"
  581. } else { //入库
  582. _, msg, successNum = GetDataById(coll, ids, "es", map[string]map[string]interface{}{})
  583. }
  584. } else {
  585. msg = "无查询数据"
  586. }
  587. msg = fmt.Sprintf("共查询%d条,导入成功%d条\n", escount, successNum) + msg
  588. i.ServeJson(map[string]interface{}{"msg": msg})
  589. }
  590. //同步数据
  591. func (i *Front) SyncMarked() {
  592. syncColl := i.GetString("coll")
  593. sess := util.MgoM.GetMgoConn()
  594. defer util.MgoM.DestoryMongoConn(sess)
  595. it := sess.DB(util.Config.Dbname).C(syncColl).Find(nil).Iter()
  596. count, _ := sess.DB(util.Config.Dbname).C(syncColl).Find(nil).Count()
  597. qu.Debug(syncColl, count)
  598. n := 0
  599. lock := &sync.Mutex{}
  600. wg := &sync.WaitGroup{}
  601. ch := make(chan bool, 3)
  602. result := map[string]map[string]interface{}{}
  603. idArr := []string{}
  604. for tmp := make(map[string]interface{}); it.Next(tmp); n++ {
  605. wg.Add(1)
  606. ch <- true
  607. go func(tmp map[string]interface{}) {
  608. defer func() {
  609. <-ch
  610. wg.Done()
  611. }()
  612. id := qu.ObjToString(tmp["id"])
  613. if id == "" {
  614. return
  615. }
  616. tmpMap := map[string]interface{}{}
  617. for _, f := range util.Config.CustomerField {
  618. if val := tmp[f]; val != nil {
  619. tmpMap[f] = val
  620. }
  621. }
  622. lock.Lock()
  623. idArr = append(idArr, id)
  624. result[id] = tmpMap
  625. lock.Unlock()
  626. }(tmp)
  627. tmp = map[string]interface{}{}
  628. }
  629. wg.Wait()
  630. if count != int64(len(result)) {
  631. i.ServeJson(map[string]interface{}{"msg": "同步失败", "flag": false})
  632. return
  633. }
  634. //util.MgoM.C.Database(util.Config.Dbname).Collection(syncColl).Drop(util.MgoM.Ctx) //删除syncColl表(清空数据)
  635. success, msg, successNum := GetDataById(syncColl, idArr, "syncoll", result)
  636. result = map[string]map[string]interface{}{}
  637. idArr = []string{}
  638. msg = fmt.Sprintf("共查询%d条,同步成功%d条\n", count, successNum) + msg
  639. i.ServeJson(map[string]interface{}{"msg": msg, "flag": success})
  640. }
  641. //标注完成
  642. func (i *Front) FinishCheck() {
  643. i.Render("finish.html")
  644. }
  645. //查询列表数据
  646. func getListInfo(spidercode, stype, field string, currentpage int) []map[string]interface{} {
  647. QueryFind = map[string]interface{}{}
  648. if spidercode != "" {
  649. QueryFind["spidercode"] = spidercode
  650. }
  651. if stype != "-1" && stype != "" {
  652. if stype == util.SPECIALTYPE {
  653. QueryFind["subtype"] = map[string]interface{}{
  654. "$exists": false,
  655. }
  656. } else {
  657. subtype := strings.Split(stype, "-")[1]
  658. QueryFind["subtype"] = subtype
  659. }
  660. }
  661. if field != "-1" && field != "" {
  662. //query[field] = map[string]interface{}{
  663. // "$exists": true, //字段存在
  664. //}
  665. QueryFind[preKey+field] = map[string]interface{}{
  666. "$exists": false, //field未曾标记
  667. }
  668. if field == "budget" || field == "bidamount" { //金额区间
  669. numMap := map[string]interface{}{}
  670. if Min != "" {
  671. minint := qu.IntAll(Min)
  672. numMap["$gte"] = minint
  673. }
  674. if Max != "" {
  675. maxint := qu.IntAll(Max)
  676. numMap["$lte"] = maxint
  677. }
  678. queryArr := []interface{}{}
  679. if HasNo { //包含field不存在的数据
  680. queryArr = append(queryArr, map[string]interface{}{
  681. field: map[string]interface{}{
  682. "$exists": false,
  683. },
  684. })
  685. }
  686. if len(numMap) > 0 { //给定了区间,查询此区间或者budget、bidamount不存在的数据
  687. queryArr = append(queryArr, map[string]interface{}{
  688. field: numMap,
  689. })
  690. }
  691. if len(queryArr) > 0 {
  692. QueryFind["$or"] = queryArr
  693. }
  694. } else {
  695. HasNo = false //当字段不是budget、bidamount时,HasNo改为false,仅作用于页面展示
  696. }
  697. }
  698. qu.Debug("query:", util.Coll, QueryFind)
  699. start := (currentpage - 1) * 50
  700. infoList, _ := util.MgoM.Find(util.Coll, QueryFind, `{"_id":1}`, `{"_id":1,"title":1,"detail":1,"site":1,"href":1,"ck_data":1}`, false, start, 50)
  701. for k, v := range *infoList {
  702. ck_data := qu.IntAll(v["ck_data"])
  703. if ck_data > 0 {
  704. v["checked"] = true
  705. } else {
  706. v["checked"] = false
  707. }
  708. href := fmt.Sprint(v["href"])
  709. if !strings.HasPrefix(href, "http") {
  710. v["href"] = "http://" + href
  711. }
  712. v["_id"] = mgo.BsonIdToSId(v["_id"])
  713. (*infoList)[k] = v
  714. v["num"] = k + 1 + start
  715. }
  716. return *infoList
  717. }
  718. func getDetail(id string) map[string]interface{} {
  719. rep := map[string]interface{}{}
  720. infoTmp, _ := util.MgoM.FindById(util.Coll, id, ``)
  721. info := *infoTmp
  722. // if qu.ObjToString(info["check"]) == "ok" && flag != "y" {
  723. // bz_info, _ := util.MgoM.FindById(util.Config.Totablel, id, ``)
  724. // for k, v := range *bz_info {
  725. // info[k] = v
  726. // }
  727. // }
  728. info["_id"] = mgo.BsonIdToSId(info["_id"])
  729. ck_pclisext, _ := info["ck_pclisext"].(bool)
  730. ck_wodrisext, _ := info["ck_wodrisext"].(bool)
  731. ck_pkgisext, _ := info["ck_pkgisext"].(bool)
  732. rep["ck_pclisext"] = ck_pclisext
  733. rep["ck_wodrisext"] = ck_wodrisext
  734. rep["ck_pkgisext"] = ck_pkgisext
  735. href := qu.ObjToString(info["href"])
  736. if !strings.HasPrefix(href, "http") {
  737. info["href"] = "http://" + href
  738. }
  739. info["filetext"] = util.GetFileText(info) //获取附件信息
  740. //rep["type"] = ftype
  741. rep["info"] = info
  742. common, timeplace, other := setExtComMap(info) //拼装抽取common值
  743. rep["common"] = common
  744. rep["timeplace"] = timeplace
  745. rep["other"] = other
  746. packs, packskey, pkg_new := setPaceMap(info) //拼装子包信息
  747. rep["packs"] = packs
  748. rep["packskey"] = packskey
  749. rep["pkg_new"] = pkg_new
  750. purchasinglist, pcl_new := setPurchasingMap(info) //标的物
  751. rep["purchasinglist"] = purchasinglist
  752. rep["pcl_new"] = pcl_new
  753. worder, worder_new := setWorderMap(info) //中标候选人
  754. rep["worder"] = worder
  755. rep["worder_new"] = worder_new
  756. //
  757. if info[preKey+"purchasinglist"] != nil {
  758. rep[preKey+"purchasinglist"] = "1"
  759. } else {
  760. rep[preKey+"purchasinglist"] = "-1"
  761. }
  762. if info[preKey+"package"] != nil {
  763. rep[preKey+"package"] = "1"
  764. } else {
  765. rep[preKey+"package"] = "-1"
  766. }
  767. if info[preKey+"winnerorder"] != nil {
  768. rep[preKey+"winnerorder"] = "1"
  769. } else {
  770. rep[preKey+"winnerorder"] = "-1"
  771. }
  772. return rep
  773. }
  774. //拼装中标候选人
  775. func setWorderMap(info map[string]interface{}) ([]interface{}, []bool) {
  776. //基本参数--中标候选人
  777. winnerorder, _ := util.Config.Biaozhu["winnerorder"].([]interface{})
  778. worders := []interface{}{}
  779. isNewWorder := []bool{} //记录子包是否是新增的
  780. if tmpwds, ok := info["winnerorder"].([]interface{}); ok {
  781. for _, v := range tmpwds {
  782. if wd, ok := v.(map[string]interface{}); ok {
  783. isNew, _ := wd["ck_isnew"].(bool)
  784. isNewWorder = append(isNewWorder, isNew)
  785. wds := []interface{}{}
  786. for _, cp := range winnerorder {
  787. cp, _ := cp.(map[string]interface{})
  788. tp := map[string]interface{}{
  789. "key": cp["key"],
  790. "descript": cp["descript"],
  791. "value": wd[qu.ObjToString(cp["key"])],
  792. }
  793. if wd[preKey+fmt.Sprint(tp["key"])] == nil {
  794. tp["status"] = "-1"
  795. } else {
  796. tp["status"] = "1"
  797. }
  798. wds = append(wds, tp)
  799. }
  800. worders = append(worders, wds)
  801. }
  802. }
  803. }
  804. return worders, isNewWorder
  805. }
  806. //拼装标的物
  807. func setPurchasingMap(info map[string]interface{}) ([]interface{}, []bool) {
  808. purchasinglist, _ := util.Config.Biaozhu["purchasinglist"].([]interface{})
  809. purchasinglists := []interface{}{}
  810. isNewPcl := []bool{} //记录子包是否是新增的
  811. if tmpcls, ok := info["purchasinglist"].([]interface{}); ok {
  812. for _, v := range tmpcls {
  813. if pcl, ok := v.(map[string]interface{}); ok {
  814. isNew, _ := pcl["ck_isnew"].(bool)
  815. isNewPcl = append(isNewPcl, isNew)
  816. pcls := []interface{}{}
  817. for _, ps := range purchasinglist {
  818. ps, _ := ps.(map[string]interface{})
  819. value := pcl[qu.ObjToString(ps["key"])]
  820. if value == nil {
  821. value = ""
  822. }
  823. tp := map[string]interface{}{
  824. "key": ps["key"],
  825. "descript": ps["descript"],
  826. "value": value,
  827. }
  828. if pcl[preKey+fmt.Sprint(tp["key"])] == nil {
  829. tp["status"] = "-1"
  830. } else {
  831. tp["status"] = "1"
  832. }
  833. pcls = append(pcls, tp)
  834. }
  835. purchasinglists = append(purchasinglists, pcls)
  836. }
  837. }
  838. }
  839. return purchasinglists, isNewPcl
  840. }
  841. //拼装子包信息
  842. func setPaceMap(info map[string]interface{}) ([]map[string]interface{}, []string, map[string]bool) {
  843. var confpack []interface{}
  844. confpack, _ = util.Config.Biaozhu["package"].([]interface{})
  845. packs := map[string]map[string]interface{}{}
  846. sortpackskey := []string{}
  847. isNewPkg := map[string]bool{} //记录子包是否是新增的
  848. if packages, ok := info["package"].(map[string]interface{}); ok && len(packages) > 0 {
  849. for k, tmpackage := range packages { //遍历分包
  850. if tmppack, ok := tmpackage.(map[string]interface{}); ok {
  851. isNew, _ := tmppack["ck_isnew"].(bool)
  852. isNewPkg[k] = isNew
  853. sortpackskey = append(sortpackskey, k)
  854. pack := []interface{}{}
  855. for _, cpack := range confpack {
  856. cpack, _ := cpack.(map[string]interface{})
  857. tp := map[string]interface{}{
  858. "key": cpack["key"],
  859. "descript": cpack["descript"],
  860. }
  861. if tmppack[fmt.Sprint(tp["key"])] != nil {
  862. tp["value"] = tmppack[qu.ObjToString(tp["key"])]
  863. } else {
  864. tp["value"] = ""
  865. }
  866. if tmppack[preKey+fmt.Sprint(tp["key"])] == nil {
  867. tp["status"] = "-1"
  868. } else {
  869. tp["status"] = "1"
  870. }
  871. pack = append(pack, tp)
  872. }
  873. packs[k] = map[string]interface{}{
  874. "pack": pack,
  875. //"pack_worder": pack_worder,
  876. }
  877. }
  878. }
  879. }
  880. sort.Strings(sortpackskey)
  881. packages := []map[string]interface{}{}
  882. for _, v := range sortpackskey {
  883. packages = append(packages, packs[v])
  884. }
  885. //qu.Debug("分包---", packages)
  886. return packages, sortpackskey, isNewPkg
  887. }
  888. //拼装抽取common值
  889. func setExtComMap(info map[string]interface{}) ([]interface{}, []interface{}, []interface{}) {
  890. //基本参数
  891. common, _ := util.Config.Biaozhu["common"].([]interface{})
  892. for k, tmp := range common {
  893. if cp, ok := tmp.(map[string]interface{}); ok {
  894. if info[fmt.Sprint(cp["key"])] == nil {
  895. cp["value"] = ""
  896. } else {
  897. cp["value"] = info[fmt.Sprint(cp["key"])]
  898. }
  899. if info[preKey+fmt.Sprint(cp["key"])] == nil {
  900. cp["status"] = "-1"
  901. } else {
  902. cp["status"] = "1"
  903. }
  904. common[k] = cp
  905. }
  906. }
  907. //时间地点信息
  908. timeplace, _ := util.Config.Biaozhu["timeplace"].([]interface{})
  909. for k, tmp := range timeplace {
  910. if tp, ok := tmp.(map[string]interface{}); ok {
  911. if info[fmt.Sprint(tp["key"])] == nil {
  912. tp["value"] = ""
  913. } else {
  914. key := tp["key"]
  915. if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" {
  916. tmpTime := qu.Int64All(info[fmt.Sprint(tp["key"])])
  917. if tmpTime > 0 {
  918. tp["value"] = qu.FormatDateByInt64(&tmpTime, qu.Date_Full_Layout)
  919. } else {
  920. tp["value"] = info[qu.ObjToString(tp["key"])]
  921. }
  922. } else {
  923. tp["value"] = info[fmt.Sprint(tp["key"])]
  924. }
  925. }
  926. if info[preKey+fmt.Sprint(tp["key"])] == nil {
  927. tp["status"] = "-1"
  928. } else {
  929. tp["status"] = "1"
  930. }
  931. timeplace[k] = tp
  932. }
  933. }
  934. //other信息
  935. other, _ := util.Config.Biaozhu["other"].([]interface{})
  936. for k, tmp := range other {
  937. if cp, ok := tmp.(map[string]interface{}); ok {
  938. if info[fmt.Sprint(cp["key"])] == nil {
  939. cp["value"] = ""
  940. } else {
  941. if cp["key"] == "signaturedate" {
  942. bidopentime := qu.Int64All(info[fmt.Sprint(cp["key"])])
  943. if bidopentime > 0 {
  944. cp["value"] = qu.FormatDateByInt64(&bidopentime, qu.Date_Full_Layout)
  945. } else {
  946. cp["value"] = info[qu.ObjToString(cp["key"])]
  947. }
  948. } else {
  949. cp["value"] = info[fmt.Sprint(cp["key"])]
  950. }
  951. }
  952. //log.Println(cp)
  953. if info[preKey+fmt.Sprint(cp["key"])] == nil {
  954. cp["status"] = "-1"
  955. } else {
  956. cp["status"] = "1"
  957. }
  958. other[k] = cp
  959. }
  960. }
  961. return common, timeplace, other
  962. }
  963. //标注基本字段
  964. func BzJBZD(content []interface{}, set, unset, errset map[string]interface{}) {
  965. info, _ := content[0].(map[string]interface{})
  966. if uInputs, ok := info["uInput"].([]interface{}); ok {
  967. for _, tmp := range uInputs {
  968. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  969. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  970. key := qu.ObjToString(tmpMap["key"]) //字段
  971. if key == "" {
  972. continue
  973. }
  974. if status == 2 || status == 3 { //新增、修改
  975. input := tmpMap["input"] //值
  976. if key == "attach_discern" || key == "attach_ext" { //附件识别、抽取select
  977. input = tmpMap["select"]
  978. } else if key == "budget" || key == "bidamount" {
  979. input = qu.Float64All(input)
  980. }
  981. set[key] = input
  982. errset[key] = status
  983. } else if status == 4 { //删除
  984. unset[key] = ""
  985. errset[key] = status
  986. }
  987. set[preKey+key] = status
  988. }
  989. }
  990. }
  991. }
  992. //qu.Debug("set---", set)
  993. // qu.Debug("unset---", unset)
  994. }
  995. //标注时间地点
  996. func BzSJDD(content []interface{}, set, unset, errset map[string]interface{}) {
  997. info, _ := content[0].(map[string]interface{})
  998. if uInputs, ok := info["uInput"].([]interface{}); ok {
  999. for _, tmp := range uInputs {
  1000. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  1001. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  1002. key := qu.ObjToString(tmpMap["key"]) //字段
  1003. if status == 2 || status == 3 { //新增、修改
  1004. input := tmpMap["input"] //值
  1005. if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" {
  1006. inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local)
  1007. input = inputTmp.Unix()
  1008. }
  1009. set[key] = input
  1010. errset[key] = status
  1011. } else if status == 4 { //删除
  1012. unset[key] = ""
  1013. errset[key] = status
  1014. }
  1015. set[preKey+key] = status
  1016. }
  1017. }
  1018. }
  1019. }
  1020. // qu.Debug("set---", set)
  1021. // qu.Debug("unset---", unset)
  1022. }
  1023. //标注标的信息
  1024. func BzBDXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) {
  1025. //qu.Debug("是否抽取:", status, isext, len(content), errset)
  1026. if status == -1 {
  1027. return
  1028. }
  1029. set["ck_pclisext"] = isext //标的信息是否抽取标记
  1030. purchasinglist := []interface{}{}
  1031. errList := []interface{}{}
  1032. delpclson := 0
  1033. for _, con := range content {
  1034. info, _ := con.(map[string]interface{})
  1035. isNew, _ := info["ck_isnew"].(bool) //是否是新增子包
  1036. pclSonStatus := qu.IntAll(info["status"])
  1037. if pclSonStatus == 4 {
  1038. delpclson++
  1039. }
  1040. if uInputs, ok := info["uInput"].([]interface{}); ok {
  1041. result := map[string]interface{}{
  1042. "ck_isnew": isNew,
  1043. }
  1044. errResult := map[string]interface{}{}
  1045. for _, tmp := range uInputs {
  1046. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  1047. key := qu.ObjToString(tmpMap["key"]) //字段
  1048. input := tmpMap["input"] //值
  1049. status := qu.IntAll(tmpMap["status"])
  1050. isNull := false
  1051. if key == "number" || key == "unitprice" || key == "totalprice" {
  1052. if input != "" { //有值
  1053. isNull = false
  1054. input = qu.Float64All(input)
  1055. } else {
  1056. isNull = true
  1057. }
  1058. }
  1059. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  1060. result[key] = input
  1061. }
  1062. result[preKey+key] = status
  1063. if !isNew && (status == 2 || status == 3 || status == 4) {
  1064. errResult[key] = status //记录哪个字段错误
  1065. }
  1066. }
  1067. }
  1068. if len(result) > 0 && pclSonStatus != 4 {
  1069. purchasinglist = append(purchasinglist, result)
  1070. }
  1071. errList = append(errList, errResult)
  1072. }
  1073. }
  1074. errset["purchasinglist"] = errList
  1075. if len(purchasinglist)+delpclson == len(content) {
  1076. set["purchasinglist"] = purchasinglist
  1077. set[preKey+"purchasinglist"] = status
  1078. }
  1079. }
  1080. //标注多包信息
  1081. func BzDBXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) {
  1082. //qu.Debug("是否抽取:", status, isext, len(content), errset)
  1083. if status == -1 {
  1084. return
  1085. }
  1086. set["ck_pkgisext"] = isext //多包是否抽取标记
  1087. pkgs := map[string]interface{}{}
  1088. errMap := map[string]interface{}{}
  1089. newNum := 1
  1090. delpkgson := 0 //记录子包删除个数
  1091. for _, con := range content {
  1092. info, _ := con.(map[string]interface{})
  1093. pkgSonStatus := qu.IntAll(info["status"])
  1094. if pkgSonStatus == 4 {
  1095. delpkgson++
  1096. }
  1097. num := fmt.Sprint(info["num"]) //包号
  1098. isNew, _ := info["ck_isnew"].(bool) //是否是新增子包
  1099. if isNew { //新增子包新建包名
  1100. num = "new" + fmt.Sprint(newNum)
  1101. newNum++
  1102. }
  1103. if uInputs, ok := info["uInput"].([]interface{}); ok {
  1104. result := map[string]interface{}{
  1105. "ck_isnew": isNew,
  1106. }
  1107. errResult := map[string]interface{}{}
  1108. for _, tmp := range uInputs {
  1109. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  1110. key := qu.ObjToString(tmpMap["key"]) //字段
  1111. input := tmpMap["input"] //值
  1112. status := qu.IntAll(tmpMap["status"])
  1113. isNull := false
  1114. if key == "bidamount" || key == "budget" {
  1115. if input != "" { //有值
  1116. isNull = false
  1117. input = qu.Float64All(input)
  1118. } else {
  1119. isNull = true
  1120. }
  1121. }
  1122. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  1123. result[key] = input
  1124. }
  1125. result[preKey+key] = status
  1126. if !isNew && (status == 2 || status == 3 || status == 4) {
  1127. errResult[key] = status //记录哪个字段错误
  1128. }
  1129. }
  1130. }
  1131. if len(errResult) > 0 {
  1132. errMap[num] = errResult
  1133. }
  1134. if len(result) > 0 && pkgSonStatus != 4 { //要删除的子包不再保存
  1135. pkgs[num] = result
  1136. }
  1137. }
  1138. }
  1139. if len(errMap) > 0 {
  1140. errset["package"] = errMap
  1141. }
  1142. if len(pkgs)+delpkgson == len(content) {
  1143. set["package"] = pkgs
  1144. set[preKey+"package"] = status
  1145. }
  1146. // qu.Debug("set---", set)
  1147. // qu.Debug("unset---", unset)
  1148. }
  1149. //标注中标候选人信息
  1150. func BzZBHXRXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) {
  1151. //qu.Debug("是否抽取:", status, isext, len(content), errset)
  1152. if status == -1 {
  1153. return
  1154. }
  1155. set["ck_wodrisext"] = isext //中标候选人是否抽取标记
  1156. winnerorder := []interface{}{}
  1157. errList := []interface{}{}
  1158. delwodrson := 0
  1159. for _, con := range content {
  1160. info, _ := con.(map[string]interface{})
  1161. isNew, _ := info["ck_isnew"].(bool) //是否是新增子包
  1162. wodrSonStatus := qu.IntAll(info["status"])
  1163. if wodrSonStatus == 4 {
  1164. delwodrson++
  1165. }
  1166. if uInputs, ok := info["uInput"].([]interface{}); ok {
  1167. result := map[string]interface{}{
  1168. "ck_isnew": isNew,
  1169. }
  1170. errResult := map[string]interface{}{}
  1171. for _, tmp := range uInputs {
  1172. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  1173. key := qu.ObjToString(tmpMap["key"]) //字段
  1174. input := tmpMap["input"] //值
  1175. status := qu.IntAll(tmpMap["status"])
  1176. isNull := false
  1177. if key == "price" {
  1178. if input != "" { //有值
  1179. isNull = false
  1180. input = qu.Float64All(input)
  1181. } else {
  1182. isNull = true
  1183. }
  1184. }
  1185. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  1186. result[key] = input
  1187. }
  1188. result[preKey+key] = status
  1189. if !isNew && (status == 2 || status == 3 || status == 4) {
  1190. errResult[key] = status //记录哪个字段错误
  1191. }
  1192. }
  1193. }
  1194. if len(result) > 0 && wodrSonStatus != 4 {
  1195. winnerorder = append(winnerorder, result)
  1196. }
  1197. errList = append(errList, errResult)
  1198. }
  1199. }
  1200. errset["winnerorder"] = errList
  1201. if len(winnerorder)+delwodrson == len(content) {
  1202. set["winnerorder"] = winnerorder
  1203. set[preKey+"winnerorder"] = status
  1204. }
  1205. // qu.Debug("set---", set)
  1206. // qu.Debug("unset---", unset)
  1207. // qu.Debug("errset---", errset)
  1208. }
  1209. //标注其余信息
  1210. func BzQYXX(content []interface{}, set, unset, errset map[string]interface{}) {
  1211. info, _ := content[0].(map[string]interface{})
  1212. if uInputs, ok := info["uInput"].([]interface{}); ok {
  1213. for _, tmp := range uInputs {
  1214. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  1215. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  1216. key := qu.ObjToString(tmpMap["key"]) //字段
  1217. if status == 2 || status == 3 { //新增、修改
  1218. input := tmpMap["input"] //值
  1219. if key == "isppp" || key == "contract_guarantee" || key == "bid_guarantee" {
  1220. input = tmpMap["select"]
  1221. } else if key == "signaturedate" { //
  1222. inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local)
  1223. input = inputTmp.Unix()
  1224. } else if key == "bid_bond" || key == "contract_bond" || key == "supervisorrate" || key == "agencyrate" || key == "docamount" || key == "agencyfee" {
  1225. input = qu.Float64All(input)
  1226. }
  1227. set[key] = input
  1228. errset[key] = status
  1229. } else if status == 4 { //删除
  1230. unset[key] = ""
  1231. errset[key] = status
  1232. }
  1233. set[preKey+key] = status
  1234. }
  1235. }
  1236. }
  1237. }
  1238. // qu.Debug("set---", set)
  1239. // qu.Debug("unset---", unset)
  1240. }
  1241. func mapIntAdd(k, val string, tmp map[string]map[string]int) map[string]map[string]int {
  1242. key := k[3:]
  1243. var keyct map[string]int
  1244. if tmp[key] == nil {
  1245. keyct = map[string]int{
  1246. "ok": 0,
  1247. "fail": 0,
  1248. "default": 0,
  1249. }
  1250. } else {
  1251. keyct = tmp[key]
  1252. }
  1253. if val == "1" {
  1254. keyct["ok"] += 1
  1255. } else if val == "0" {
  1256. keyct["fail"] += 1
  1257. } else {
  1258. keyct["default"] += 1
  1259. }
  1260. tmp[key] = keyct
  1261. return tmp
  1262. }
  1263. //通过id查询数据
  1264. func GetDataById(coll string, ids []string, stype string, tmp map[string]map[string]interface{}) (bool, string, int64) {
  1265. defer qu.Catch()
  1266. success := true
  1267. msg := ""
  1268. wg := &sync.WaitGroup{}
  1269. lock := &sync.Mutex{}
  1270. ch := make(chan bool, 5)
  1271. n := int64(0)
  1272. for i, id := range ids {
  1273. wg.Add(1)
  1274. ch <- true
  1275. go func(i int, id string, success *bool, msg *string) {
  1276. defer func() {
  1277. wg.Done()
  1278. <-ch
  1279. }()
  1280. /*
  1281. 1.查bidding
  1282. 2.查extract
  1283. 3.extract合并到bidding(删除item字段以为与客户需要的item不是一个含义)
  1284. 4.对比marked表,替换已标注过的字段值,补充标记
  1285. 5.合并客户所需字段信息,补充id字段
  1286. 6.若为同步时,删除原有id对应的信息,新增该id对应的_id信息
  1287. */
  1288. tmpBidColl := util.BidColl1 //bidding
  1289. //查询bidding
  1290. if id < util.BIDDINGSTARTID {
  1291. tmpBidColl = util.BidColl2 //bidding_back
  1292. }
  1293. bidData, _ := util.MgoB.FindById(tmpBidColl, id, nil)
  1294. if bidData != nil && len(*bidData) > 0 { //bidding表数据存在
  1295. //查询extract
  1296. extData, _ := util.MgoE.FindById(util.ExtColl1, id, nil)
  1297. if extData == nil || len(*extData) == 0 {
  1298. extData, _ = util.MgoE.FindById(util.ExtColl2, id, nil)
  1299. }
  1300. //抽取表字段合并到bidding
  1301. if extData != nil && len(*extData) > 0 {
  1302. for k, v := range *extData {
  1303. (*bidData)[k] = v
  1304. }
  1305. }
  1306. //删除item
  1307. delete((*bidData), "item")
  1308. //对比marked表是否已标注该数据
  1309. markData, _ := util.MgoM.FindById(util.Config.Fromtable, id, nil)
  1310. if markData != nil && len(*markData) > 0 {
  1311. UpdateMarkColl(bidData, markData) //比对更新数据
  1312. } else {
  1313. (*bidData)["ck_data"] = 0 //设置ck_data默认值0
  1314. //多包、中标候选人、标的信息是否抽取
  1315. if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 {
  1316. (*bidData)["ck_pkgisext"] = true
  1317. } else {
  1318. (*bidData)["ck_pkgisext"] = false
  1319. }
  1320. if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 {
  1321. (*bidData)["ck_wodrisext"] = true
  1322. } else {
  1323. (*bidData)["ck_wodrisext"] = false
  1324. }
  1325. if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 {
  1326. (*bidData)["ck_pclisext"] = true
  1327. } else {
  1328. (*bidData)["ck_pclisext"] = false
  1329. }
  1330. }
  1331. //合并导入表中客户所需的字段
  1332. if len(tmp) > 0 {
  1333. for k, v := range tmp[id] {
  1334. (*bidData)[k] = v
  1335. }
  1336. }
  1337. //补充id
  1338. (*bidData)["id"] = id
  1339. if stype == "syncoll" { //同步数据时删除原始数据
  1340. if util.MgoM.Delete(coll, `{"id":"`+id+`"}`) == 0 {
  1341. lock.Lock()
  1342. *msg += "同步未删除成功数据id:" + id + ";\n"
  1343. *success = false
  1344. lock.Unlock()
  1345. }
  1346. }
  1347. //保存数据
  1348. if util.MgoM.SaveByOriID(coll, bidData) {
  1349. atomic.AddInt64(&n, 1) //计数
  1350. } else {
  1351. lock.Lock()
  1352. *success = false
  1353. if stype == "excel" {
  1354. *msg += "第" + fmt.Sprint(i+2) + "行未保存成功数据_id:" + id + ";\n"
  1355. } else {
  1356. *msg += "未保存成功数据_id:" + id + ";\n"
  1357. }
  1358. lock.Unlock()
  1359. }
  1360. } else {
  1361. lock.Lock()
  1362. *success = false
  1363. if stype == "excel" {
  1364. *msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n"
  1365. } else {
  1366. *msg += "未查询到数据_id:" + id + ";\n"
  1367. }
  1368. lock.Unlock()
  1369. }
  1370. }(i, id, &success, &msg)
  1371. }
  1372. wg.Wait()
  1373. return success, msg, n
  1374. }
  1375. //更新数据
  1376. func UpdateMarkColl(bidData, markData *map[string]interface{}) {
  1377. defer qu.Catch()
  1378. ck_data := qu.IntAll((*markData)["ck_data"])
  1379. if ck_data == 2 { //某些字段已标注
  1380. for fk, fv := range *markData {
  1381. ckFieldArr := strings.Split(fk, preKey)
  1382. if len(ckFieldArr) == 2 {
  1383. field := ckFieldArr[1]
  1384. (*bidData)[fk] = fv //补充标记
  1385. if (*markData)[field] != nil {
  1386. (*bidData)[field] = (*markData)[field] //字段更新
  1387. }
  1388. }
  1389. }
  1390. (*bidData)["ck_data"] = 0 //marked表中该条数据如果为字段验证,临时表ck_data:0;若为数据验证ck_data:1
  1391. } else if ck_data == 1 {
  1392. *bidData = *markData
  1393. (*bidData)["ck_data"] = 1
  1394. }
  1395. }
  1396. //获取当前数据下一条的id
  1397. func GetNextDataId(id string) string {
  1398. nextIdQuery := map[string]interface{}{
  1399. "_id": map[string]interface{}{
  1400. "$gt": mgo.StringTOBsonId(id),
  1401. },
  1402. }
  1403. for k, v := range QueryFind {
  1404. nextIdQuery[k] = v
  1405. }
  1406. one, _ := util.MgoM.Find(util.Coll, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1)
  1407. if one != nil && len(*one) == 1 {
  1408. return mgo.BsonIdToSId((*one)[0]["_id"])
  1409. }
  1410. return id
  1411. }
  1412. //获取已标注和数据总数的信息
  1413. func GetCheckedAndAllDataInfo() (int, int) {
  1414. allCount := util.MgoM.Count(util.Coll, QueryFind)
  1415. ckDataQuery := map[string]interface{}{
  1416. "ck_data": map[string]interface{}{
  1417. "$gt": 0,
  1418. },
  1419. }
  1420. for k, v := range QueryFind {
  1421. ckDataQuery[k] = v
  1422. }
  1423. checkedCount := util.MgoM.Count(util.Coll, ckDataQuery)
  1424. return checkedCount, allCount
  1425. }
  1426. //统计抽查
  1427. func (i *Front) Tj() error {
  1428. comm := map[string]map[string]int{}
  1429. comm_win := map[string]map[string]int{}
  1430. pack := map[string]map[string]int{}
  1431. pack_win := map[string]map[string]int{}
  1432. list, _ := util.MgoM.Find(util.Config.Totablel, "{}", nil, nil, false, -1, -1)
  1433. for _, tmp := range *list {
  1434. for k, val := range tmp {
  1435. if len(k) > 3 && k[:3] == preKey {
  1436. comm = mapIntAdd(k, qu.ObjToString(val), comm)
  1437. }
  1438. }
  1439. if winnerorder, ok := tmp["winnerorder"].([]interface{}); ok {
  1440. for _, wd := range winnerorder {
  1441. if winner, ok := wd.(map[string]interface{}); ok {
  1442. for k, val := range winner {
  1443. if len(k) > 3 && k[:3] == preKey {
  1444. comm_win = mapIntAdd(k, qu.ObjToString(val), comm_win)
  1445. }
  1446. }
  1447. }
  1448. }
  1449. }
  1450. if ptmp, ok := tmp["package"].(map[string]interface{}); ok {
  1451. for _, pktmp := range ptmp {
  1452. if pkage, ok := pktmp.(map[string]interface{}); ok {
  1453. for k, val := range pkage {
  1454. if len(k) > 3 && k[:3] == preKey {
  1455. pack = mapIntAdd(k, qu.ObjToString(val), pack)
  1456. }
  1457. if k == "winnerorder" {
  1458. if wtmp, ok := val.([]interface{}); ok {
  1459. for _, winner := range wtmp {
  1460. if win, ok := winner.(map[string]interface{}); ok {
  1461. for wk, wval := range win {
  1462. if len(k) > 3 && k[:3] == preKey {
  1463. pack_win = mapIntAdd(wk, qu.ObjToString(wval), pack_win)
  1464. }
  1465. }
  1466. }
  1467. }
  1468. }
  1469. }
  1470. }
  1471. }
  1472. }
  1473. }
  1474. }
  1475. //data := map[string]interface{}{"total": len(list), "comm": comm, "pack": pack, "pack_win": pack_win}
  1476. //mongodb.Save("extcheck_tj", data)
  1477. i.T["comm"] = comm
  1478. i.T["pack"] = pack
  1479. i.T["comm_win"] = comm_win
  1480. i.T["pack_win"] = pack_win
  1481. i.T["total"] = len(*list)
  1482. return i.Render("tj.html", &i.T)
  1483. }