mark.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. package front
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. qu "qfw/util"
  6. "strings"
  7. "time"
  8. "util"
  9. )
  10. // DataMark 数据标注
  11. func (f *Front) DataMark() {
  12. defer qu.Catch()
  13. success := false
  14. msg := ""
  15. //user := f.GetSession("user").(map[string]interface{})
  16. //username := qu.ObjToString(user["s_login"]) //当前登录用户
  17. obj := []map[string]interface{}{}
  18. infoId := f.GetString("s_infoid")
  19. userTaskId := f.GetString("s_usertaskid")
  20. data := f.GetString("data")
  21. err := json.Unmarshal([]byte(data), &obj)
  22. if err != nil {
  23. f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"})
  24. return
  25. }
  26. tagSet := map[string]interface{}{} //被标注字段状态
  27. baseSet := map[string]interface{}{} //要修改的字段信息
  28. baseUnset := map[string]interface{}{} //要删除的字段信息
  29. //isSaveMarked := false
  30. if len(obj) == 1 { //单独保存某个一级
  31. content, ok := obj[0]["content"].([]interface{})
  32. if !ok || len(content) == 0 {
  33. f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"})
  34. return
  35. }
  36. title := qu.ObjToString(obj[0]["title"])
  37. istag, _ := obj[0]["checkAllTag"].(bool)
  38. status := qu.IntAll(obj[0]["status"])
  39. switch title {
  40. case "基本字段":
  41. BzJBZD_New(content, tagSet, baseSet, baseUnset)
  42. case "时间地点":
  43. BzSJDD_New(content, tagSet, baseSet, baseUnset)
  44. case "标的信息":
  45. BzBDXX_New(content, tagSet, baseSet, baseUnset, istag, status)
  46. case "多包信息":
  47. BzDBXX_New(content, tagSet, baseSet, baseUnset, status)
  48. case "中标候选人信息":
  49. BzZBHXRXX_New(content, tagSet, baseSet, baseUnset, status)
  50. case "其余信息":
  51. BzQYXX_New(content, tagSet, baseSet, baseUnset)
  52. }
  53. } else {
  54. for j, val := range obj {
  55. content, ok := val["content"].([]interface{})
  56. status := qu.IntAll(val["status"])
  57. if !ok {
  58. qu.Debug("Content Error")
  59. continue
  60. }
  61. istag, _ := val["checkAllTag"].(bool)
  62. if j == 0 { //基本信息
  63. BzJBZD_New(content, tagSet, baseSet, baseUnset)
  64. } else if j == 1 { //时间地点
  65. BzSJDD_New(content, tagSet, baseSet, baseUnset)
  66. } else if j == 2 { //标的物
  67. BzBDXX_New(content, tagSet, baseSet, baseUnset, istag, status)
  68. } else if j == 3 { //多包
  69. BzDBXX_New(content, tagSet, baseSet, baseUnset, status)
  70. } else if j == 4 { //候选人
  71. BzZBHXRXX_New(content, tagSet, baseSet, baseUnset, status)
  72. } else { //其余信息
  73. BzQYXX_New(content, tagSet, baseSet, baseUnset)
  74. }
  75. }
  76. }
  77. userTask, _ := util.Mgo.FindById(util.TASKCOLLNAME, userTaskId, map[string]interface{}{"s_personid": 1, "s_personname": 1, "s_projectname": 1, "s_sourceinfo": 1})
  78. if sourceInfo := qu.ObjToString((*userTask)["s_sourceinfo"]); sourceInfo != "" { //数据源表
  79. dataInfo, _ := util.Mgo.FindById(sourceInfo, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1}) //查询标注保存前的原始信息
  80. if tagInfo, ok := (*dataInfo)["v_taginfo"].(map[string]interface{}); ok && len(tagInfo) > 0 {
  81. for field, tmpStatus := range tagSet { //比对本次标注信息和历史标注信息
  82. status := qu.IntAll(tmpStatus) //此次被标注字段的状态
  83. markedStatus := qu.IntAll(tagInfo[field]) //历史标注状态
  84. if status == 1 && markedStatus != 0 { //此次标注结果为正确,且有历史标注记录,不做修改
  85. qu.Debug("已标注字段field---", field)
  86. delete(tagSet, field)
  87. delete(baseSet, field)
  88. continue
  89. } else {
  90. qu.Debug("未标注字段field---", field, status)
  91. }
  92. }
  93. }
  94. if len(tagSet) > 0 {
  95. //1、更新数据源信息
  96. setResult := map[string]interface{}{ //更新字段集
  97. "i_updatetime": time.Now().Unix(),
  98. "i_ckdata": 2,
  99. "b_istag": true,
  100. }
  101. for field, val := range tagSet { //更新标注字段
  102. setResult["v_taginfo."+field] = val
  103. }
  104. for field, val := range baseSet { //更新基本字段
  105. setResult["v_baseinfo."+field] = val
  106. }
  107. baseUnsetResult := map[string]interface{}{} //删除字段集
  108. for field, _ := range baseUnset { //删除基本字段
  109. baseUnsetResult["v_baseinfo."+field] = ""
  110. }
  111. set := map[string]interface{}{
  112. "$set": setResult,
  113. }
  114. if len(baseUnsetResult) > 0 {
  115. set["$unset"] = baseUnsetResult
  116. }
  117. qu.Debug("set---", set)
  118. //success = util.Mgo.UpdateById(sourceInfo, infoId, set)
  119. //2、更新marked表
  120. //3、保存标注记录
  121. }
  122. }
  123. f.ServeJson(map[string]interface{}{"success": success, "msg": msg})
  124. }
  125. func BzJBZD_New(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}) {
  126. defer qu.Catch()
  127. info, _ := content[0].(map[string]interface{})
  128. if uInputs, ok := info["uInput"].([]interface{}); ok {
  129. for _, tmp := range uInputs {
  130. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  131. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  132. key := qu.ObjToString(tmpMap["key"]) //字段
  133. if key == "" {
  134. continue
  135. }
  136. if status == 2 { //新增、修改、删除
  137. input := tmpMap["input"] //值
  138. if key == "bidamounttype" || key == "subtype" || key == "attach_discern" || key == "attach_ext" || key == "isrepeat" { //附件识别、抽取select
  139. input = tmpMap["select"]
  140. }
  141. if input == "" { //删除原字段
  142. baseUnset[key] = ""
  143. } else { //修改原字段
  144. if key == "budget" || key == "bidamount" || key == "biddiscount" {
  145. input = qu.Float64All(input)
  146. //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32)
  147. }
  148. if key == "subtype" {
  149. if topsubtype := strings.Split(qu.ObjToString(input), "-"); len(topsubtype) == 2 {
  150. baseSet["toptype"] = topsubtype[0]
  151. baseSet[key] = topsubtype[1]
  152. }
  153. } else {
  154. baseSet[key] = input
  155. }
  156. }
  157. }
  158. tagSet[key] = status //记录被标注状态
  159. }
  160. }
  161. }
  162. }
  163. qu.Debug("tagSet===", tagSet)
  164. qu.Debug("baseSet===", baseSet)
  165. qu.Debug("baseUnset===", baseUnset)
  166. }
  167. func BzSJDD_New(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}) {
  168. info, _ := content[0].(map[string]interface{})
  169. if uInputs, ok := info["uInput"].([]interface{}); ok {
  170. for _, tmp := range uInputs {
  171. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  172. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  173. key := qu.ObjToString(tmpMap["key"]) //字段
  174. if key == "" {
  175. continue
  176. }
  177. if status == 2 { //新增、修改、删除
  178. input := tmpMap["input"] //值
  179. if input == "" {
  180. baseUnset[key] = ""
  181. } else {
  182. if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" {
  183. inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local)
  184. input = inputTmp.Unix()
  185. } else if key == "project_duration" {
  186. input = qu.IntAll(input)
  187. }
  188. baseSet[key] = input
  189. }
  190. }
  191. tagSet[key] = status
  192. }
  193. }
  194. }
  195. }
  196. qu.Debug("tagSet===", tagSet)
  197. qu.Debug("baseSet===", baseSet)
  198. qu.Debug("baseUnset===", baseUnset)
  199. }
  200. func BzBDXX_New(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, istag bool, status int) {
  201. if status == -1 {
  202. return
  203. }
  204. baseSet["purchasinglist_alltag"] = istag //标的信息是否标注完全
  205. purchasinglist := []interface{}{}
  206. delpclson := 0
  207. for _, con := range content {
  208. info, _ := con.(map[string]interface{})
  209. isNew, _ := info["isnew"].(bool) //是否是新增子包
  210. pclSonStatus := qu.IntAll(info["status"])
  211. if pclSonStatus == 4 {
  212. delpclson++
  213. }
  214. if uInputs, ok := info["uInput"].([]interface{}); ok {
  215. result := map[string]interface{}{
  216. "isnew": isNew,
  217. }
  218. for _, tmp := range uInputs {
  219. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  220. key := qu.ObjToString(tmpMap["key"]) //字段
  221. input := tmpMap["input"] //值
  222. //status := qu.IntAll(tmpMap["status"])
  223. isNull := false
  224. if input == "" { //判断前台页面是否填值,无值不进行字段存储
  225. isNull = true
  226. } else if key == "number" || key == "unitprice" || key == "totalprice" {
  227. input = qu.Float64All(input)
  228. }
  229. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  230. result[key] = input
  231. }
  232. }
  233. }
  234. if pclSonStatus != -1 { //没有标注的标的信息不打标记
  235. result["purchasinglist_son"] = pclSonStatus
  236. }
  237. if len(result) > 0 && pclSonStatus != 4 {
  238. purchasinglist = append(purchasinglist, result)
  239. }
  240. }
  241. }
  242. qu.Debug("purchasinglist", len(purchasinglist))
  243. if len(purchasinglist)+delpclson == len(content) {
  244. if len(purchasinglist) > 0 {
  245. baseSet["purchasinglist"] = purchasinglist
  246. }
  247. if len(content) > 0 && delpclson == len(content) { //只有删除
  248. baseUnset["purchasinglist"] = ""
  249. }
  250. tagSet["purchasinglist"] = status
  251. } else {
  252. qu.Debug("Purchasinglist Tag Error")
  253. }
  254. qu.Debug("tagSet===", tagSet)
  255. qu.Debug("baseSet===", baseSet)
  256. qu.Debug("baseUnset===", baseUnset)
  257. }
  258. func BzDBXX_New(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, status int) {
  259. if status == -1 {
  260. return
  261. }
  262. pkgs := map[string]interface{}{}
  263. newNum := 1
  264. delpkgson := 0 //记录子包删除个数
  265. for _, con := range content {
  266. info, _ := con.(map[string]interface{})
  267. pkgSonStatus := qu.IntAll(info["status"])
  268. if pkgSonStatus == 4 {
  269. delpkgson++
  270. }
  271. num := fmt.Sprint(info["num"]) //包号
  272. isNew, _ := info["isnew"].(bool) //是否是新增子包
  273. if isNew { //新增子包新建包名
  274. num = "new" + fmt.Sprint(newNum)
  275. newNum++
  276. }
  277. if uInputs, ok := info["uInput"].([]interface{}); ok {
  278. result := map[string]interface{}{
  279. "isnew": isNew,
  280. }
  281. winnerArr := []interface{}{}
  282. bidamountArr := []interface{}{}
  283. for _, tmp := range uInputs {
  284. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  285. key := qu.ObjToString(tmpMap["key"]) //字段
  286. input := tmpMap["input"] //值
  287. isNull := false //记录字段是否有值
  288. if key == "bidamounttype" {
  289. input = tmpMap["select"]
  290. } else {
  291. if input == "" { //判断前台页面是否填值,无值不进行字段存储
  292. isNull = true
  293. } else if key == "bidamount" || key == "budget" {
  294. input = qu.Float64All(input)
  295. //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32)
  296. }
  297. }
  298. if key == "winner" {
  299. if isNull {
  300. winnerArr = append(winnerArr, nil)
  301. } else {
  302. winnerArr = append(winnerArr, input)
  303. }
  304. continue
  305. } else if key == "bidamount" {
  306. if isNull {
  307. bidamountArr = append(bidamountArr, nil)
  308. } else {
  309. bidamountArr = append(bidamountArr, input)
  310. }
  311. continue
  312. }
  313. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  314. result[key] = input
  315. }
  316. }
  317. }
  318. winner_all := []interface{}{}
  319. if len(winnerArr) == len(bidamountArr) {
  320. for i, w := range winnerArr {
  321. b := bidamountArr[i]
  322. wbMap := map[string]interface{}{}
  323. if w != nil {
  324. wbMap["winner"] = w
  325. }
  326. if b != nil {
  327. wbMap["bidamount"] = b
  328. }
  329. if len(wbMap) > 0 {
  330. winner_all = append(winner_all, wbMap)
  331. }
  332. }
  333. }
  334. if len(winner_all) > 0 {
  335. result["winner_all"] = winner_all
  336. }
  337. result["package_son"] = pkgSonStatus
  338. if len(result) > 0 && pkgSonStatus != 4 { //要删除的子包不再保存
  339. pkgs[num] = result
  340. }
  341. }
  342. }
  343. qu.Debug("pkgs", len(pkgs))
  344. if len(pkgs)+delpkgson == len(content) {
  345. if len(pkgs) > 0 {
  346. baseSet["package"] = pkgs
  347. }
  348. if len(content) > 0 && delpkgson == len(content) { //只有删除
  349. baseUnset["package"] = ""
  350. }
  351. tagSet["package"] = status
  352. } else {
  353. qu.Debug("Package Tag Error")
  354. }
  355. qu.Debug("tagSet===", tagSet)
  356. qu.Debug("baseSet===", baseSet)
  357. qu.Debug("baseUnset===", baseUnset)
  358. }
  359. func BzZBHXRXX_New(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, status int) {
  360. if status == -1 {
  361. return
  362. }
  363. winnerorder := []interface{}{}
  364. delwodrson := 0
  365. for _, con := range content {
  366. info, _ := con.(map[string]interface{})
  367. isNew, _ := info["isnew"].(bool) //是否是新增子包
  368. wodrSonStatus := qu.IntAll(info["status"])
  369. if wodrSonStatus == 4 {
  370. delwodrson++
  371. }
  372. if uInputs, ok := info["uInput"].([]interface{}); ok {
  373. result := map[string]interface{}{
  374. "isnew": isNew,
  375. }
  376. for _, tmp := range uInputs {
  377. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  378. key := qu.ObjToString(tmpMap["key"]) //字段
  379. input := tmpMap["input"] //值
  380. isNull := false
  381. if input == "" { //判断前台页面是否填值,无值不进行字段存储
  382. isNull = true
  383. } else if key == "price" {
  384. input = qu.Float64All(input)
  385. //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32)
  386. }
  387. if !isNull { //避免数字类型的字段在没有填写值的情况默认给0
  388. result[key] = input
  389. }
  390. result["winnerorder_son"] = wodrSonStatus
  391. }
  392. }
  393. if len(result) > 0 && wodrSonStatus != 4 {
  394. winnerorder = append(winnerorder, result)
  395. }
  396. }
  397. }
  398. qu.Debug("winnerorder", len(winnerorder))
  399. if len(winnerorder)+delwodrson == len(content) {
  400. if len(winnerorder) > 0 {
  401. baseSet["winnerorder"] = winnerorder
  402. }
  403. if len(content) > 0 && delwodrson == len(content) { //只有删除
  404. baseUnset["winnerorder"] = ""
  405. }
  406. tagSet["winnerorder"] = status
  407. } else {
  408. qu.Debug("Winnerorder Tag Error")
  409. }
  410. qu.Debug("tagSet===", tagSet)
  411. qu.Debug("baseSet===", baseSet)
  412. qu.Debug("baseUnset===", baseUnset)
  413. }
  414. func BzQYXX_New(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}) {
  415. info, _ := content[0].(map[string]interface{})
  416. if uInputs, ok := info["uInput"].([]interface{}); ok {
  417. for _, tmp := range uInputs {
  418. if tmpMap, ok := tmp.(map[string]interface{}); ok {
  419. if status := qu.IntAll(tmpMap["status"]); status != -1 {
  420. key := qu.ObjToString(tmpMap["key"]) //字段
  421. if key == "" {
  422. continue
  423. }
  424. if status == 2 { //新增、修改、删除
  425. input := tmpMap["input"] //值
  426. if key == "isppp" || key == "contract_guarantee" || key == "bid_guarantee" {
  427. input = tmpMap["select"]
  428. }
  429. if input == "" {
  430. baseUnset[key] = ""
  431. } else {
  432. if key == "signaturedate" {
  433. inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local)
  434. input = inputTmp.Unix()
  435. } else if key == "bid_bond" || key == "contract_bond" || key == "supervisorrate" || key == "agencyrate" || key == "docamount" || key == "agencyfee" {
  436. input = qu.Float64All(input)
  437. //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32)
  438. }
  439. baseSet[key] = input
  440. }
  441. }
  442. tagSet[key] = status
  443. }
  444. }
  445. }
  446. }
  447. qu.Debug("tagSet===", tagSet)
  448. qu.Debug("baseSet===", baseSet)
  449. qu.Debug("baseUnset===", baseUnset)
  450. }