package front import ( "math" //"container/list" "fmt" qu "qfw/util" "qfw/util/redis" "sync/atomic" mgo "mongodb" "sort" "strings" "sync" "time" "util" ) //查找未被标注的数据id func GetNoCheckedId(id, coll string) (string, bool) { defer qu.Catch() q := map[string]interface{}{ "_id": map[string]interface{}{ "$gt": mgo.StringTOBsonId(id), }, } sess := util.MgoM.GetMgoConn() defer util.MgoM.DestoryMongoConn(sess) it := sess.DB(util.MgoM.DbName).C(coll).Find(q).Sort("_id").Select(map[string]interface{}{"_id": 1}).Iter() for tmp := make(map[string]interface{}); it.Next(&tmp); { id = mgo.BsonIdToSId(tmp["_id"]) exists, err := redis.Exists("extcheck", coll+"_"+id) if err == nil && !exists { return id, exists } tmp = map[string]interface{}{} } return id, true } //查询列表数据 func getListInfo(coll string, query map[string]interface{}, currentpage int) []map[string]interface{} { start := (currentpage - 1) * 50 infoList, _ := util.MgoM.Find(coll, query, `{"_id":1}`, `{"_id":1,"title":1,"detail":1,"site":1,"href":1,"ck_data":1}`, false, start, 50) for k, v := range *infoList { ck_data := qu.IntAll(v["ck_data"]) if ck_data > 0 { v["checked"] = true } else { v["checked"] = false } href := fmt.Sprint(v["href"]) if !strings.HasPrefix(href, "http") { v["href"] = "http://" + href } v["_id"] = mgo.BsonIdToSId(v["_id"]) (*infoList)[k] = v v["num"] = k + 1 + start } return *infoList } func getDetail(id, coll string) map[string]interface{} { rep := map[string]interface{}{} infoTmp, _ := util.MgoM.FindById(coll, id, ``) info := *infoTmp // if qu.ObjToString(info["check"]) == "ok" && flag != "y" { // bz_info, _ := util.MgoM.FindById(util.Config.Totablel, id, ``) // for k, v := range *bz_info { // info[k] = v // } // } info["_id"] = mgo.BsonIdToSId(info["_id"]) //ck_pclisext, _ := info["ck_pclisext"].(bool) ck_pclistag, _ := info["ck_pclistag"].(bool) //ck_wodrisext, _ := info["ck_wodrisext"].(bool) //ck_pkgisext, _ := info["ck_pkgisext"].(bool) //rep["ck_pclisext"] = ck_pclisext rep["ck_pclistag"] = ck_pclistag //rep["ck_wodrisext"] = ck_wodrisext //rep["ck_pkgisext"] = ck_pkgisext href := qu.ObjToString(info["href"]) if !strings.HasPrefix(href, "http") { info["href"] = "http://" + href } //info["filetext"] = util.GetFileText(info) //获取附件信息 //rep["type"] = ftype rep["info"] = info common, timeplace, other := setExtComMap(info) //拼装抽取common值 rep["common"] = common rep["timeplace"] = timeplace rep["other"] = other packs, packskey, pkg_new := setPaceMap(info) //拼装子包信息 rep["packs"] = packs rep["packskey"] = packskey rep["pkg_new"] = pkg_new purchasinglist, isNewStatus := setPurchasingMap(info) //标的物 rep["purchasinglist"] = purchasinglist rep["pcl_new"] = isNewStatus worder, worder_new := setWorderMap(info) //中标候选人 rep["worder"] = worder rep["worder_new"] = worder_new otherInfo, moreInfo := setOtherInfo(info) //处理公告关联信息 rep["otherInfo"] = otherInfo rep["moreInfo"] = moreInfo // if info[preKey+"purchasinglist"] != nil { rep[preKey+"purchasinglist"] = "1" } else { rep[preKey+"purchasinglist"] = "-1" } if info[preKey+"package"] != nil { rep[preKey+"package"] = "1" } else { rep[preKey+"package"] = "-1" } if info[preKey+"winnerorder"] != nil { rep[preKey+"winnerorder"] = "1" } else { rep[preKey+"winnerorder"] = "-1" } return rep } //获取公告关联信息 func setOtherInfo(info map[string]interface{}) (result, moreArr []map[string]interface{}) { if otherInfo, ok := info["info"].([]interface{}); ok && len(otherInfo) > 0 { //中标,成交、合同、招标(不含变更) /* [ {}, {}, ] */ zbArr := []map[string]interface{}{} cjArr := []map[string]interface{}{} htArr := []map[string]interface{}{} zbbArr := []map[string]interface{}{} for _, tmp := range otherInfo { tmpInfo := tmp.(map[string]interface{}) toptype := tmpInfo["toptype"] subtype := tmpInfo["subtype"] ptime := "" tmpPtime := qu.Int64All(tmpInfo["publishtime"]) if tmpPtime > 0 { ptime = qu.FormatDateByInt64(&tmpPtime, qu.Date_Full_Layout) } tmpInfo["publishtime_str"] = ptime if subtype == "中标" { zbArr = append(zbArr, tmpInfo) } else if subtype == "成交" { cjArr = append(cjArr, tmpInfo) } else if subtype == "合同" { htArr = append(htArr, tmpInfo) } else if toptype == "招标" && subtype != "变更" { zbbArr = append(zbbArr, tmpInfo) } else { //标注页不展示的信息,更多中展示 moreArr = append(moreArr, map[string]interface{}{ "publishtime": tmpInfo["publishtime_str"], "subtype": subtype, "title": tmpInfo["title"], "href": util.GetJyHref(qu.ObjToString(tmpInfo["id"])), }) } } publishtime := qu.Float64All(info["publishtime"]) //中标信息 if zbLen := len(zbArr); zbLen > 0 { rzb := DealData(zbLen, publishtime, zbArr, &moreArr) result = append(result, rzb) } //成交 if cjLen := len(cjArr); cjLen > 0 { rcj := DealData(cjLen, publishtime, cjArr, &moreArr) result = append(result, rcj) } //合同 if htLen := len(htArr); htLen > 0 { rht := DealData(htLen, publishtime, htArr, &moreArr) result = append(result, rht) } result = append(result, zbbArr...) } return } func DealData(tmpLen int, publishtime float64, tmp []map[string]interface{}, moreArr *[]map[string]interface{}) (resultTmp map[string]interface{}) { if tmpLen == 1 || publishtime <= 0 { //相同类型只有一条或者原公告发布时间异常取第一条公告 resultTmp = tmp[0] for _, t := range tmp[1:] { //将过滤掉的数据加入到更多中 *moreArr = append(*moreArr, map[string]interface{}{ "publishtime": t["publishtime_str"], "subtype": t["subtype"], "title": t["title"], "href": util.GetJyHref(qu.ObjToString(t["id"])), }) } return } else { diff := float64(0) //记录差值 index := 0 for i, zb := range tmp { pTmp := qu.Float64All(zb["publishtime"]) diffTmp := math.Abs(publishtime - pTmp) //绝对值 if i == 0 { diff = diffTmp } else if diffTmp < diff { //记录较小差值的数据索引位置 diff = diffTmp index = i } else { //将过滤掉的数据加入到更多中 *moreArr = append(*moreArr, map[string]interface{}{ "publishtime": zb["publishtime_str"], "subtype": zb["subtype"], "title": zb["title"], "href": util.GetJyHref(qu.ObjToString(zb["id"])), }) } } resultTmp = tmp[index] } return } //拼装中标候选人 func setWorderMap(info map[string]interface{}) ([]interface{}, []map[string]interface{}) { //基本参数--中标候选人 winnerorder, _ := util.Config.Biaozhu["winnerorder"].([]interface{}) worders := []interface{}{} isNewAndStatus := []map[string]interface{}{} if tmpwds, ok := info["winnerorder"].([]interface{}); ok { for _, v := range tmpwds { if wd, ok := v.(map[string]interface{}); ok { //isNew, _ := wd["ck_isnew"].(bool) isNew := false status := "-1" if wd["ck_winnerorder"] != nil { status = "1" } isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status}) wds := []interface{}{} for _, cp := range winnerorder { cp, _ := cp.(map[string]interface{}) value := wd[qu.ObjToString(cp["key"])] if value == nil { value = "" } tp := map[string]interface{}{ "key": cp["key"], "descript": cp["descript"], "value": value, "status": status, } wds = append(wds, tp) } worders = append(worders, wds) } } } return worders, isNewAndStatus } //拼装标的物 func setPurchasingMap(info map[string]interface{}) ([]interface{}, []map[string]interface{}) { purchasinglist, _ := util.Config.Biaozhu["purchasinglist"].([]interface{}) purchasinglists := []interface{}{} //isNewPcl := []bool{} //记录子包是否是新增的 isNewAndStatus := []map[string]interface{}{} if tmpcls, ok := info["purchasinglist"].([]interface{}); ok { for _, v := range tmpcls { if pcl, ok := v.(map[string]interface{}); ok { //isNew, _ := pcl["ck_isnew"].(bool) isNew := false status := "-1" if pcl["ck_purchasinglist"] != nil { status = "1" } //isNewPcl = append(isNewPcl, isNew) isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status}) pcls := []interface{}{} for _, ps := range purchasinglist { ps, _ := ps.(map[string]interface{}) value := pcl[qu.ObjToString(ps["key"])] if value == nil { value = "" } tp := map[string]interface{}{ "key": ps["key"], "descript": ps["descript"], "value": value, "status": status, } // if pcl[preKey+fmt.Sprint(tp["key"])] == nil { // tp["status"] = "-1" // } else { // tp["status"] = "1" // } pcls = append(pcls, tp) } purchasinglists = append(purchasinglists, pcls) } } } return purchasinglists, isNewAndStatus } //拼装子包信息 func setPaceMap(info map[string]interface{}) ([]map[string]interface{}, []string, []bool) { var confpack []interface{} confpack, _ = util.Config.Biaozhu["package"].([]interface{}) packs := map[string]map[string]interface{}{} sortpackskey := []string{} isNewPkg := map[string]bool{} //记录子包是否是新增的 if packages, ok := info["package"].(map[string]interface{}); ok && len(packages) > 0 { for k, tmpackage := range packages { //遍历分包 if tmppack, ok := tmpackage.(map[string]interface{}); ok { //isNew, _ := tmppack["ck_isnew"].(bool) isNew := false status := "-1" if tmppack["ck_package"] != nil { status = "1" } isNewPkg[k] = isNew sortpackskey = append(sortpackskey, k) pack := []interface{}{} for _, cpack := range confpack { cpack, _ := cpack.(map[string]interface{}) key := qu.ObjToString(cpack["key"]) if key == "winner" || key == "bidamount" { //中标单位和中标金额winner_all特殊处理 continue } tp := map[string]interface{}{ "key": key, "descript": cpack["descript"], } if tmppack[fmt.Sprint(tp["key"])] != nil { tp["value"] = tmppack[qu.ObjToString(tp["key"])] } else { tp["value"] = "" } tp["status"] = status pack = append(pack, tp) } //特殊处理中标单位和中标金额 winnerall := []interface{}{} if tmpWinnerAll, ok := tmppack["winner_all"].([]interface{}); ok && len(tmpWinnerAll) > 0 { for _, tmp := range tmpWinnerAll { tmpMap := tmp.(map[string]interface{}) win := map[string]interface{}{ "descript": "标段(包)中标单位", "key": "winner", "status": status, "value": qu.ObjToString(tmpMap["winner"]), } winnerall = append(winnerall, win) var bidamount interface{} if tmpMap["bidamount"] == nil { bidamount = "" } else { bidamount = fmt.Sprint(tmpMap["bidamount"]) } bid := map[string]interface{}{ "descript": "标段(包)中标金额", "key": "bidamount", "status": status, "value": bidamount, } winnerall = append(winnerall, bid) } } else { winnerall = append(winnerall, map[string]interface{}{ "descript": "标段(包)中标单位", "key": "winner", "status": "-1", "value": "", }) winnerall = append(winnerall, map[string]interface{}{ "descript": "标段(包)中标金额", "key": "bidamount", "status": "-1", "value": "", }) } packs[k] = map[string]interface{}{ "pack": pack, "packstatus": status, "winnerall": winnerall, } } } } sort.Strings(sortpackskey) packages := []map[string]interface{}{} isNewPkgArr := []bool{} for _, v := range sortpackskey { packages = append(packages, packs[v]) isNewPkgArr = append(isNewPkgArr, isNewPkg[v]) } return packages, sortpackskey, isNewPkgArr } //拼装抽取common值 func setExtComMap(info map[string]interface{}) ([]interface{}, []interface{}, []interface{}) { //基本参数 common, _ := util.Config.Biaozhu["common"].([]interface{}) for k, tmp := range common { if cp, ok := tmp.(map[string]interface{}); ok { if info[fmt.Sprint(cp["key"])] == nil { cp["value"] = "" } else { if cp["key"] == "subtype" { if info["toptype"] != nil && info["subtype"] != nil { cp["value"] = qu.ObjToString(info["toptype"]) + "-" + qu.ObjToString(info[fmt.Sprint(cp["key"])]) } else { cp["value"] = "" } } else { cp["value"] = info[fmt.Sprint(cp["key"])] } } if info[preKey+fmt.Sprint(cp["key"])] == nil { cp["status"] = "-1" } else { cp["status"] = "1" } common[k] = cp } } //时间地点信息 timeplace, _ := util.Config.Biaozhu["timeplace"].([]interface{}) for k, tmp := range timeplace { if tp, ok := tmp.(map[string]interface{}); ok { if info[fmt.Sprint(tp["key"])] == nil { tp["value"] = "" } else { key := tp["key"] if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" { tmpTime := qu.Int64All(info[fmt.Sprint(tp["key"])]) if tmpTime > 0 { tp["value"] = qu.FormatDateByInt64(&tmpTime, qu.Date_Full_Layout) } else { tp["value"] = info[qu.ObjToString(tp["key"])] } } else { tp["value"] = info[fmt.Sprint(tp["key"])] } } if info[preKey+fmt.Sprint(tp["key"])] == nil { tp["status"] = "-1" } else { tp["status"] = "1" } timeplace[k] = tp } } //other信息 other, _ := util.Config.Biaozhu["other"].([]interface{}) for k, tmp := range other { if cp, ok := tmp.(map[string]interface{}); ok { if info[fmt.Sprint(cp["key"])] == nil { cp["value"] = "" } else { if cp["key"] == "signaturedate" { bidopentime := qu.Int64All(info[fmt.Sprint(cp["key"])]) if bidopentime > 0 { cp["value"] = qu.FormatDateByInt64(&bidopentime, qu.Date_Full_Layout) } else { cp["value"] = info[qu.ObjToString(cp["key"])] } } else { cp["value"] = info[fmt.Sprint(cp["key"])] } } //log.Println(cp) if info[preKey+fmt.Sprint(cp["key"])] == nil { cp["status"] = "-1" } else { cp["status"] = "1" } other[k] = cp } } return common, timeplace, other } //标注基本字段 func BzJBZD(content []interface{}, set, unset, errset map[string]interface{}) { info, _ := content[0].(map[string]interface{}) if uInputs, ok := info["uInput"].([]interface{}); ok { for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { if status := qu.IntAll(tmpMap["status"]); status != -1 { key := qu.ObjToString(tmpMap["key"]) //字段 if key == "" { continue } if status == 2 || status == 3 { //新增、修改 input := tmpMap["input"] //值 if key == "bidamounttype" || key == "subtype" || key == "attach_discern" || key == "attach_ext" || key == "isrepeat" { //附件识别、抽取select input = tmpMap["select"] } if input == "" { unset[key] = "" //表示删除 } else { if key == "budget" || key == "bidamount" || key == "biddiscount" { input = qu.Float64All(input) } if key == "subtype" { if topsubtype := strings.Split(qu.ObjToString(input), "-"); len(topsubtype) == 2 { set["toptype"] = topsubtype[0] set[key] = topsubtype[1] } } else { set[key] = input } } errset[key] = status } else if status == 4 { //删除 unset[key] = "" errset[key] = status } set[preKey+key] = status //记录状态 } } } } //qu.Debug("set---", set) // qu.Debug("unset---", unset) } //标注时间地点 func BzSJDD(content []interface{}, set, unset, errset map[string]interface{}) { info, _ := content[0].(map[string]interface{}) if uInputs, ok := info["uInput"].([]interface{}); ok { for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { if status := qu.IntAll(tmpMap["status"]); status != -1 { key := qu.ObjToString(tmpMap["key"]) //字段 if status == 2 || status == 3 { //新增、修改 input := tmpMap["input"] //值 if input == "" { unset[key] = "" } else { if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" { inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local) input = inputTmp.Unix() } else if key == "project_duration" { input = qu.IntAll(input) } set[key] = input } errset[key] = status } else if status == 4 { //删除 unset[key] = "" errset[key] = status } set[preKey+key] = status } } } } // qu.Debug("set---", set) // qu.Debug("unset---", unset) } //标注标的信息 func BzBDXX(content []interface{}, set, unset, errset map[string]interface{}, isext, istag bool, status int) { //qu.Debug("是否抽取:", status, isext, len(content), errset) if status == -1 { return } //set["ck_pclisext"] = isext //标的信息是否抽取标记 set["ck_pclistag"] = istag //标的信息是否标注完全 purchasinglist := []interface{}{} delpclson := 0 for _, con := range content { info, _ := con.(map[string]interface{}) isNew, _ := info["ck_isnew"].(bool) //是否是新增子包 pclSonStatus := qu.IntAll(info["status"]) if pclSonStatus == 4 { delpclson++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ "ck_isnew": isNew, } for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { key := qu.ObjToString(tmpMap["key"]) //字段 input := tmpMap["input"] //值 //status := qu.IntAll(tmpMap["status"]) isNull := false if input == "" { //判断前台页面是否填值,无值不进行字段存储 isNull = true } else if key == "number" || key == "unitprice" || key == "totalprice" { input = qu.Float64All(input) } if !isNull { //避免数字类型的字段在没有填写值的情况默认给0 result[key] = input } //result[preKey+key] = status // if !isNew && (status == 2 || status == 3 || status == 4) { // errResult[key] = status //记录哪个字段错误 // } } } if pclSonStatus != -1 { //没有标注的标的信息不打标记 result["ck_purchasinglist"] = pclSonStatus } if len(result) > 0 && pclSonStatus != 4 { purchasinglist = append(purchasinglist, result) } } } if status != 1 { //如果purchasinglist状态不是1,errdata则记录原purchasinglist字段 errset["purchasinglist"] = true } qu.Debug("purchasinglist", len(purchasinglist)) if len(purchasinglist)+delpclson == len(content) { if len(purchasinglist) > 0 { set["purchasinglist"] = purchasinglist } set[preKey+"purchasinglist"] = status if len(content) > 0 && delpclson == len(content) { //只有删除 unset["purchasinglist"] = "" } } qu.Debug("set---", set) qu.Debug("errset---", errset) qu.Debug("unset---", unset) } //标注多包信息 func BzDBXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) { //qu.Debug("是否抽取:", status, isext, len(content), errset) if status == -1 { return } //set["ck_pkgisext"] = isext //多包是否抽取标记 pkgs := map[string]interface{}{} //errMap := map[string]interface{}{} newNum := 1 delpkgson := 0 //记录子包删除个数 for _, con := range content { info, _ := con.(map[string]interface{}) pkgSonStatus := qu.IntAll(info["status"]) if pkgSonStatus == 4 { delpkgson++ } num := fmt.Sprint(info["num"]) //包号 isNew, _ := info["ck_isnew"].(bool) //是否是新增子包 if isNew { //新增子包新建包名 num = "new" + fmt.Sprint(newNum) newNum++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ "ck_isnew": isNew, } //errResult := map[string]interface{}{} winnerArr := []interface{}{} bidamountArr := []interface{}{} for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { key := qu.ObjToString(tmpMap["key"]) //字段 input := tmpMap["input"] //值 //status := qu.IntAll(tmpMap["status"]) isNull := false //记录字段是否有值 if key == "bidamounttype" { input = tmpMap["select"] } else { if input == "" { //判断前台页面是否填值,无值不进行字段存储 isNull = true } else if key == "bidamount" || key == "budget" { input = qu.Float64All(input) } } if key == "winner" { if isNull { winnerArr = append(winnerArr, nil) } else { winnerArr = append(winnerArr, input) } continue } else if key == "bidamount" { if isNull { bidamountArr = append(bidamountArr, nil) } else { bidamountArr = append(bidamountArr, input) } continue } if !isNull { //避免数字类型的字段在没有填写值的情况默认给0 result[key] = input } //result[preKey+key] = status // if !isNew && status >= 2 { // errResult[key] = status //记录哪个字段错误 // } } } winner_all := []interface{}{} if len(winnerArr) == len(bidamountArr) { for i, w := range winnerArr { b := bidamountArr[i] wbMap := map[string]interface{}{} if w != nil { wbMap["winner"] = w } if b != nil { wbMap["bidamount"] = b } if len(wbMap) > 0 { winner_all = append(winner_all, wbMap) } } } if len(winner_all) > 0 { result["winner_all"] = winner_all } result["ck_package"] = pkgSonStatus // if len(errResult) > 0 { // errMap[num] = errResult // } if len(result) > 0 && pkgSonStatus != 4 { //要删除的子包不再保存 pkgs[num] = result } } } if status != 1 { //如果package状态不是1,errdata则记录原package字段 errset["package"] = true } // if len(errMap) > 0 { // errset["package"] = errMap // } qu.Debug("pkgs", len(pkgs)) if len(pkgs)+delpkgson == len(content) { if len(pkgs) > 0 { set["package"] = pkgs } set[preKey+"package"] = status if len(content) > 0 && delpkgson == len(content) { //只有删除 unset["package"] = "" } } // qu.Debug("set---", set) // qu.Debug("errset---", errset) } //标注中标候选人信息 func BzZBHXRXX(content []interface{}, set, unset, errset map[string]interface{}, isext bool, status int) { //qu.Debug("是否抽取:", status, isext, len(content), errset) if status == -1 { return } //set["ck_wodrisext"] = isext //中标候选人是否抽取标记 winnerorder := []interface{}{} delwodrson := 0 for _, con := range content { info, _ := con.(map[string]interface{}) isNew, _ := info["ck_isnew"].(bool) //是否是新增子包 wodrSonStatus := qu.IntAll(info["status"]) if wodrSonStatus == 4 { delwodrson++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ "ck_isnew": isNew, } for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { key := qu.ObjToString(tmpMap["key"]) //字段 input := tmpMap["input"] //值 isNull := false if input == "" { //判断前台页面是否填值,无值不进行字段存储 isNull = true } else if key == "price" { input = qu.Float64All(input) } if !isNull { //避免数字类型的字段在没有填写值的情况默认给0 result[key] = input } result["ck_winnerorder"] = wodrSonStatus // result[preKey+key] = status // if !isNew && (status == 2 || status == 3 || status == 4) { // errResult[key] = status //记录哪个字段错误 // } } } if len(result) > 0 && wodrSonStatus != 4 { winnerorder = append(winnerorder, result) } } } if status != 1 { //如果winnerorder状态不是1,errdata则记录原winnerorder字段 errset["winnerorder"] = true } qu.Debug("winnerorder", len(winnerorder)) if len(winnerorder)+delwodrson == len(content) { if len(winnerorder) > 0 { set["winnerorder"] = winnerorder } set[preKey+"winnerorder"] = status if len(content) > 0 && delwodrson == len(content) { //只有删除 unset["winnerorder"] = "" } } qu.Debug("set---", set) qu.Debug("unset---", unset) qu.Debug("errset---", errset) } //标注其余信息 func BzQYXX(content []interface{}, set, unset, errset map[string]interface{}) { info, _ := content[0].(map[string]interface{}) if uInputs, ok := info["uInput"].([]interface{}); ok { for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { if status := qu.IntAll(tmpMap["status"]); status != -1 { key := qu.ObjToString(tmpMap["key"]) //字段 qu.Debug(key, "-----", status) if status == 2 || status == 3 { //新增、修改 input := tmpMap["input"] //值 if key == "isppp" || key == "contract_guarantee" || key == "bid_guarantee" { input = tmpMap["select"] } if input == "" { unset[key] = "" } else { if key == "signaturedate" { // inputTmp, _ := time.ParseInLocation(qu.Date_Full_Layout, input.(string), time.Local) input = inputTmp.Unix() } else if key == "bid_bond" || key == "contract_bond" || key == "supervisorrate" || key == "agencyrate" || key == "docamount" || key == "agencyfee" { input = qu.Float64All(input) } set[key] = input } errset[key] = status } else if status == 4 { //删除 unset[key] = "" errset[key] = status } set[preKey+key] = status } } } } // qu.Debug("set---", set) // qu.Debug("unset---", unset) } func mapIntAdd(k, val string, tmp map[string]map[string]int) map[string]map[string]int { key := k[3:] var keyct map[string]int if tmp[key] == nil { keyct = map[string]int{ "ok": 0, "fail": 0, "default": 0, } } else { keyct = tmp[key] } if val == "1" { keyct["ok"] += 1 } else if val == "0" { keyct["fail"] += 1 } else { keyct["default"] += 1 } tmp[key] = keyct return tmp } //通过id查询数据 func GetDataById(coll string, ids []string, stype string, tmp map[string]map[string]interface{}) (bool, string, int64) { defer qu.Catch() success := true msg := "" wg := &sync.WaitGroup{} lock := &sync.Mutex{} ch := make(chan bool, 10) n := int64(0) for i, id := range ids { wg.Add(1) ch <- true go func(i int, id string, success *bool, msg *string) { defer func() { wg.Done() <-ch }() /* 1.查bidding 2.查extract 3.extract合并到bidding(删除item字段以为与客户需要的item不是一个含义) 4.对比marked表,替换已标注过的字段值,补充标记 5.合并客户所需字段信息,补充id字段 6.若为同步时,删除原有id对应的信息,新增该id对应的_id信息 */ tmpBidColl := util.BidColl1 //bidding //查询bidding if id < util.BIDDINGSTARTID { tmpBidColl = util.BidColl2 //bidding_back } bidData, _ := util.MgoB.FindById(tmpBidColl, id, nil) if bidData != nil && len(*bidData) > 0 { //bidding表数据存在 //查询extract extData, _ := util.MgoE.FindById(util.ExtColl1, id, nil) if extData == nil || len(*extData) == 0 { extData, _ = util.MgoE.FindById(util.ExtColl2, id, nil) } //抽取表字段合并到bidding if extData != nil && len(*extData) > 0 { for k, v := range *extData { (*bidData)[k] = v } } //删除item delete((*bidData), "item") //对比marked表是否已标注该数据 markData, _ := util.MgoM.FindById(util.Config.Fromtable, id, nil) if markData != nil && len(*markData) > 0 { UpdateMarkColl(bidData, markData) //比对更新数据 } else { (*bidData)["ck_data"] = 0 //设置ck_data默认值0 //多包、中标候选人、标的信息是否抽取 if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 { (*bidData)["ck_pkgisext"] = true } else { (*bidData)["ck_pkgisext"] = false } if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 { (*bidData)["ck_wodrisext"] = true } else { (*bidData)["ck_wodrisext"] = false } if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 { (*bidData)["ck_pclisext"] = true } else { (*bidData)["ck_pclisext"] = false } } //合并导入表中客户所需的字段 if len(tmp) > 0 { for k, v := range tmp[id] { (*bidData)[k] = v } } //补充id (*bidData)["id"] = id if stype == "syncoll" { //同步数据时删除原始数据 if util.MgoM.Delete(coll, `{"id":"`+id+`"}`) == 0 { lock.Lock() *msg += "同步未删除成功数据id:" + id + ";\n" *success = false lock.Unlock() } } //保存数据 if util.MgoM.SaveByOriID(coll, bidData) { atomic.AddInt64(&n, 1) //计数 } else { lock.Lock() *success = false if stype == "excel" { *msg += "第" + fmt.Sprint(i+2) + "行未保存成功数据_id:" + id + ";\n" } else { *msg += "未保存成功数据_id:" + id + ";\n" } lock.Unlock() } } else { lock.Lock() *success = false if stype == "excel" { *msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n" } else { *msg += "未查询到数据_id:" + id + ";\n" } lock.Unlock() } }(i, id, &success, &msg) } wg.Wait() return success, msg, n } //通过id查询数据 func GetDataById1(coll string, ids []string, stype string, tmp map[string]map[string]interface{}) (bool, string, int64) { defer qu.Catch() success := true msg := "" wg := &sync.WaitGroup{} lock := &sync.Mutex{} ch := make(chan bool, 10) n := int64(0) for i, id := range ids { wg.Add(1) ch <- true go func(i int, id string, success *bool, msg *string) { defer func() { wg.Done() <-ch }() /* 1.查bidding 2.查extract 3.extract合并到bidding(删除item字段以为与客户需要的item不是一个含义) 4.对比marked表,替换已标注过的字段值,补充标记 5.合并客户所需字段信息,补充id字段 6.若为同步时,删除原有id对应的信息,新增该id对应的_id信息 */ tmpBidColl := util.BidColl1 //bidding //查询bidding if id < util.BIDDINGSTARTID { tmpBidColl = util.BidColl2 //bidding_back } bidData, _ := util.MgoB.FindById(tmpBidColl, id, nil) if bidData != nil && len(*bidData) > 0 { //bidding表数据存在 //查询extract extData, _ := util.MgoE.FindById(util.ExtColl1, id, nil) if extData == nil || len(*extData) == 0 { extData, _ = util.MgoE.FindById(util.ExtColl2, id, nil) } //抽取表字段合并到bidding if extData != nil && len(*extData) > 0 { for k, v := range *extData { (*bidData)[k] = v } } //删除item delete((*bidData), "item") //对比marked表是否已标注该数据 markData, _ := util.MgoM.FindById(util.Config.Fromtable, id, nil) if markData != nil && len(*markData) > 0 { UpdateMarkColl(bidData, markData) //比对更新数据 } else { (*bidData)["ck_data"] = 0 //设置ck_data默认值0 //多包、中标候选人、标的信息是否抽取 if packageMap, ok := (*bidData)["package"].(map[string]interface{}); ok && len(packageMap) > 0 { (*bidData)["ck_pkgisext"] = true } else { (*bidData)["ck_pkgisext"] = false } if winorderArr, ok := (*bidData)["winnerorder"].([]interface{}); ok && len(winorderArr) > 0 { (*bidData)["ck_wodrisext"] = true } else { (*bidData)["ck_wodrisext"] = false } if purchArr, ok := (*bidData)["purchasinglist"].([]interface{}); ok && len(purchArr) > 0 { (*bidData)["ck_pclisext"] = true } else { (*bidData)["ck_pclisext"] = false } } //合并导入表中客户所需的字段 if len(tmp) > 0 { for k, v := range tmp[id] { (*bidData)[k] = v } } //补充id (*bidData)["id"] = id if stype == "syncoll" { //同步数据时删除原始数据 if util.MgoM.Delete(coll, `{"id":"`+id+`"}`) == 0 { lock.Lock() *msg += "同步未删除成功数据id:" + id + ";\n" *success = false lock.Unlock() } } // 处理 package winner_all if p, o1 := (*bidData)["package"].(map[string]interface{}); o1 { for _, v := range p { v1 := v.(map[string]interface{}) t := make(map[string]interface{}) if v1["winner"] != nil { t["winner"] = v1["winner"] } if v1["bidamount"] != nil { t["bidamount"] = v1["bidamount"] } if len(t) > 0 { v1["winner_all"] = append([]map[string]interface{}{}, t) } } } // 补充filetext (*bidData)["filetext"] = util.GetFileText(*bidData) qu.Debug("es find project") // es查询项目合并信息 esQ := `{"query":{"bool":{"must":[{"term":{"ids":"` + id + `"}}]}}}` info := util.Es.Get("projectset", "projectset", esQ) if len(*info) == 1 { ids := qu.ObjArrToStringArr((*info)[0]["ids"].([]interface{})) if len(ids) > 0 { var infolist []map[string]interface{} for _, v := range ids { if v == id { // 当前公告 continue } if v < util.BIDDINGSTARTID { tmpBidColl = util.BidColl2 //bidding_back } bid, b := util.MgoB.FindById(tmpBidColl, id, nil) if b && len(*bid) > 0 { tmp := make(map[string]interface{}) tmp["id"] = v tmp["title"] = (*bid)["title"] tmp["href"] = (*bid)["href"] tmp["toptype"] = (*bid)["toptype"] tmp["subtype"] = (*bid)["subtype"] tmp["publishtime"] = (*bid)["publishtime"] tmp["detail"] = (*bid)["detail"] tmp["filetext"] = util.GetFileText(*bid) infolist = append(infolist, tmp) } } (*bidData)["info"] = infolist } } else { qu.Debug("projectset find err", esQ) } //保存数据 if util.MgoM.SaveByOriID(coll, bidData) { atomic.AddInt64(&n, 1) //计数 } else { lock.Lock() *success = false if stype == "excel" { *msg += "第" + fmt.Sprint(i+2) + "行未保存成功数据_id:" + id + ";\n" } else { *msg += "未保存成功数据_id:" + id + ";\n" } lock.Unlock() } } else { lock.Lock() *success = false if stype == "excel" { *msg += "第" + fmt.Sprint(i+2) + "行未查询到数据:" + id + ";\n" } else { *msg += "未查询到数据_id:" + id + ";\n" } lock.Unlock() } }(i, id, &success, &msg) } wg.Wait() return success, msg, n } //更新数据 func UpdateMarkColl(bidData, markData *map[string]interface{}) { defer qu.Catch() ck_data := qu.IntAll((*markData)["ck_data"]) if ck_data == 2 { //某些字段已标注 for fk, fv := range *markData { ckFieldArr := strings.Split(fk, preKey) if len(ckFieldArr) == 2 { field := ckFieldArr[1] (*bidData)[fk] = fv //补充标记 if (*markData)[field] != nil { (*bidData)[field] = (*markData)[field] //字段更新 } } } (*bidData)["ck_data"] = 0 //marked表中该条数据如果为字段验证,临时表ck_data:0;若为数据验证ck_data:1 } else if ck_data == 1 { *bidData = *markData (*bidData)["ck_data"] = 1 } } //获取当前数据下一条的id func GetNextDataId(id, coll string, query map[string]interface{}) string { nextIdQuery := map[string]interface{}{ "_id": map[string]interface{}{ "$gt": mgo.StringTOBsonId(id), }, } for k, v := range query { nextIdQuery[k] = v } one, _ := util.MgoM.Find(coll, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1) if one != nil && len(*one) == 1 { return mgo.BsonIdToSId((*one)[0]["_id"]) } return id } //获取已标注和数据总数的信息 func GetCheckedAndAllDataInfo(query map[string]interface{}, coll string) (int, int) { allCount := util.MgoM.Count(coll, query) ckDataQuery := map[string]interface{}{ "ck_data": map[string]interface{}{ "$gt": 0, }, } for k, v := range query { ckDataQuery[k] = v } checkedCount := util.MgoM.Count(coll, ckDataQuery) return checkedCount, allCount } //查询表中已标数据的标注人 func GetLabeler(coll string) (labeler []string) { defer qu.Catch() sess := util.MgoM.GetMgoConn() defer util.MgoM.DestoryMongoConn(sess) it := sess.DB(util.MgoM.DbName).C(coll).Pipe([]map[string]interface{}{ // map[string]interface{}{ // "$match": map[string]interface{}{ // "s_province": "河南省", // }, // }, { "$group": map[string]interface{}{ "_id": "$modifyuser", }, }, }).Iter() for user := make(map[string]interface{}); it.Next(&user); { if name := qu.ObjToString(user["_id"]); name != "" { labeler = append(labeler, name) } } sort.Strings(labeler) qu.Debug("labeler:", labeler) return }