package front import ( "encoding/json" "fmt" "github.com/shopspring/decimal" "go.mongodb.org/mongo-driver/bson" "math" mgo "mongodb" qu "qfw/util" "regexp" "sort" "strconv" "strings" "sync" "time" "util" ) var ( purchasingField = map[string]string{"itemname": "名称", "brandname": "品牌", "modal": "型号", "unitprice": "单价", "number": "数量"} ) func (f *Front) RemarkList() { qu.Catch() pid := qu.ObjToString(f.GetString("pid")) tid := qu.ObjToString(f.GetString("tid")) if f.Method() == "POST" { //user := f.GetSession("user").(map[string]interface{}) start, _ := f.GetInteger("start") limit, _ := f.GetInteger("length") draw, _ := f.GetInteger("draw") searchStr := f.GetString("search[value]") search := strings.TrimSpace(searchStr) query := map[string]interface{}{"s_usertaskid": tid} ckdata, err := f.GetInteger("i_ckdata") if err != nil { ckdata = -1 } if ckdata == 0 { query["b_istag"] = false } else if ckdata == 1 { query["b_istag"] = true } if search != "" { query["$or"] = []interface{}{ bson.M{"v_baseinfo.title": bson.M{"$regex": search}}, } } field := map[string]interface{}{"v_baseinfo.title": 1, "b_istag": 1, "i_ckdata": 1} info, _ := util.Mgo.Find(util.DATACOLLNAME, query, `{"_id": 1}`, field, false, start, limit) count := util.Mgo.Count(util.DATACOLLNAME, query) f.ServeJson(map[string]interface{}{ "draw": draw, "data": *info, "recordsFiltered": count, "recordsTotal": count, }) } else { f.T["pid"] = pid f.T["tid"] = tid _ = f.Render("project/remark_list.html", &f.T) } } func (f *Front) RemarkDetail() { pid := f.GetString("pid") tid := f.GetString("tid") did := f.GetString("did") project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, `{"v_fields": 1}`) fs, _ := (*project)["v_fields"].([]interface{}) rep := getDetail(did, "remark", qu.ObjArrToMapArr(fs)) //获取本条公告的信息 f.T["otherInfo"] = rep["otherInfo"] //展示关联公告信息 f.T["moreInfo"] = rep["moreInfo"] //更多关联公告信息 f.T["pid"] = pid f.T["tid"] = tid f.T["did"] = did f.T["info"] = rep["info"] f.T["common"] = rep["common"] f.T["other"] = rep["other"] f.T["ck_pclistag"] = rep["purchasingTag"] f.T["enbArr"] = rep["enbArr"] if rep["pru"] != nil { m := rep["pru"].(map[string]interface{}) f.T["purchasinglist"] = m["purchasinglist"] f.T["pcl_new"] = m["pcl_new"] f.T["PurchasinglistField"] = m["field"] } if rep["proc"] != nil { m := rep["proc"].(map[string]interface{}) f.T["procurementlist"] = m["procurementlist"] f.T["pcl_new_1"] = m["pcl_new_1"] f.T["ProcurementlistField"] = m["field"] } if rep["pkg"] != nil { m := rep["pkg"].(map[string]interface{}) f.T["packs"] = m["packs"] f.T["packskey"] = m["packskey"] f.T["pkg_new"] = m["pkg_new"] f.T["PackageField"] = m["field"] } if rep["wino"] != nil { m := rep["wino"].(map[string]interface{}) f.T["worder"] = m["worder"] f.T["worder_new"] = m["worder_new"] f.T["WinnerorderField"] = m["field"] } f.T["topsubtype"] = util.TopSubStypeArr2 f.T["ck_purchasinglist"] = rep["ck_purchasinglist"] f.T["ck_package"] = rep["ck_package"] f.T["ck_winnerorder"] = rep["ck_winnerorder"] f.T["keyword"] = rep["matchkey"] f.T["nextid"] = GetNextDataId(did, tid) //下一条id f.T["lastid"] = GetLastDataId(did, tid) //上一条id _ = f.Render("project/remark_detail.html", &f.T) } func getDetail(id, stype string, fs []map[string]interface{}) map[string]interface{} { rep := map[string]interface{}{} infoTmp, _ := util.Mgo.FindById(util.DATACOLLNAME, id, ``) rep["s_excp_info"] = (*infoTmp)["s_excp_info"] baseInfo := (*infoTmp)["v_baseinfo"].(map[string]interface{}) //字段值 var bzInfo map[string]interface{} //标注信息 if (*infoTmp)["v_taginfo"] != nil { bzInfo = (*infoTmp)["v_taginfo"].(map[string]interface{}) } else { bzInfo = make(map[string]interface{}) } baseInfo["detail"] = qu.ObjToString(baseInfo["title"]) + "
" + qu.ObjToString(baseInfo["detail"]) baseInfo["_id"] = mgo.BsonIdToSId(baseInfo["_id"]) purchasingTag, _ := baseInfo["purchasinglist_alltag"].(bool) rep["purchasingTag"] = purchasingTag href := qu.ObjToString(baseInfo["href"]) if !strings.HasPrefix(href, "http") { baseInfo["href"] = "https://" + href } rep["matchkey"] = baseInfo["matchkey"] rep["info"] = baseInfo common, other, pruM, proM, pkgM, winM, enbArr := setExtComMap(baseInfo, bzInfo, fs, stype) rep["common"] = common rep["other"] = other rep["pkg"] = pkgM // 多包信息 rep["pru"] = pruM //标的物 rep["proc"] = proM //采购意向 rep["wino"] = winM //中标候选人 otherInfo, moreInfo := setOtherInfo(baseInfo) //处理公告关联信息 rep["enbArr"] = enbArr rep["otherInfo"] = otherInfo rep["moreInfo"] = moreInfo // if bzInfo["purchasinglist"] != nil { rep["ck_purchasinglist"] = "1" } else { rep["ck_purchasinglist"] = "-1" } if bzInfo["package"] != nil { rep["ck_package"] = "1" } else { rep["ck_package"] = "-1" } if bzInfo["winnerorder"] != nil { rep["ck_winnerorder"] = "1" } else { rep["ck_winnerorder"] = "-1" } return rep } // 拼装抽取common值 func setExtComMap(info, bzInfo map[string]interface{}, fs []map[string]interface{}, stype string) ([]interface{}, []interface{}, map[string]interface{}, map[string]interface{}, map[string]interface{}, map[string]interface{}, []string) { var common []interface{} // 基本字段信息 var other []interface{} //自定义字段信息 purM := make(map[string]interface{}) // 标的物信息 proM := make(map[string]interface{}) // 采购意向信息 pkgM := make(map[string]interface{}) // 多包信息 winM := make(map[string]interface{}) // 中标候选 var enbArr []string //标的物信息、采购意向信息、多包信息、中标候选字段隐藏 //基本参数 for _, v := range fs { key := qu.ObjToString(v["key"]) if key == "purchasinglist" { if v["child"] != nil { enbArr = append(enbArr, key) child := qu.ObjArrToMapArr(v["child"].([]interface{})) purchasinglist, isNewStatus := setPurchasingMap(info, child, stype) purM["purchasinglist"] = purchasinglist purM["pcl_new"] = isNewStatus var m []map[string]string for _, v := range child { key := qu.ObjToString(v["key"]) descript := qu.ObjToString(v["descript"]) m = append(m, map[string]string{key: descript}) } purM["field"] = m } } else if key == "procurementlist" { if v["child"] != nil { enbArr = append(enbArr, key) child := qu.ObjArrToMapArr(v["child"].([]interface{})) purchasinglist_1, isNewStatus1 := setPurchasingMap1(info, child, stype) proM["procurementlist"] = purchasinglist_1 proM["pcl_new_1"] = isNewStatus1 var m []map[string]string for _, v := range child { key := qu.ObjToString(v["key"]) descript := qu.ObjToString(v["descript"]) m = append(m, map[string]string{key: descript}) } proM["field"] = m } } else if key == "package" { if v["child"] != nil { enbArr = append(enbArr, key) child := qu.ObjArrToMapArr(v["child"].([]interface{})) packs, packskey, pkg_new := setPaceMap(info, child, stype) pkgM["packs"] = packs pkgM["packskey"] = packskey pkgM["pkg_new"] = pkg_new var m []map[string]string for _, v := range child { key := qu.ObjToString(v["key"]) descript := qu.ObjToString(v["descript"]) m = append(m, map[string]string{key: descript}) } pkgM["field"] = m } } else if key == "winnerorder" { if v["child"] != nil { enbArr = append(enbArr, key) child := qu.ObjArrToMapArr(v["child"].([]interface{})) worder, worderNew := setWorderMap(info, child, stype) winM["worder"] = worder winM["worder_new"] = worderNew var m []map[string]string for _, v := range child { key := qu.ObjToString(v["key"]) descript := qu.ObjToString(v["descript"]) m = append(m, map[string]string{key: descript}) } winM["field"] = m } } else if key == "extend" { if v["child"] != nil { enbArr = append(enbArr, key) for _, tm := range qu.ObjArrToMapArr(v["child"].([]interface{})) { if stype == "remark" { tm["status"] = "1" } else { tm["status"] = "-1" } tm["value"] = info[qu.ObjToString(tm["key"])] other = append(other, tm) } } } else { if key == "bidopentime" || key == "publishtime" || key == "bidendtime" || key == "project_startdate" || key == "project_completedate" || key == "signaturedate" { tmpTime := qu.Int64All(info[key]) if tmpTime > 0 { v["value"] = qu.FormatDateByInt64(&tmpTime, qu.Date_Full_Layout) } else { v["value"] = info[key] } } else if key == "subtype" { if info["toptype"] != nil && info["subtype"] != nil { v["value"] = qu.ObjToString(info["toptype"]) + "-" + qu.ObjToString(info[fmt.Sprint(v["key"])]) } else { v["value"] = "" } } else { v["value"] = info[key] } if stype == "remark" { v["status"] = "1" } else { v["status"] = "-1" } common = append(common, v) } } if len(common) > 0 { enbArr = append(enbArr, "common") } return common, other, purM, proM, pkgM, winM, enbArr } var mm = map[string]string{ "itemname": "产品名称", "brandname": "品牌", "madel": "型号", "unitname": "计量单位", "unitprice": "单价", "number": "数量", "totalprice": "总价", "departroom": "科室", } // 拼装子包信息 func setPaceMap(info map[string]interface{}, confpack []map[string]interface{}, stype string) ([]map[string]interface{}, []string, []bool) { //bzpack := bzInfo["package"].(map[string]interface{}) packs := map[string]map[string]interface{}{} var 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["isnew"].(bool) status := "-1" if stype == "remark" && tmppack["package_son"] != nil { status = "1" } isNewPkg[k] = isNew sortpackskey = append(sortpackskey, k) var pack []interface{} for _, cpack := range confpack { key := qu.ObjToString(cpack["key"]) if key == "winner" || key == "bidamount" { //中标单位和中标金额winner_all特殊处理 continue } tp := map[string]interface{}{ "key": key, "descript": cpack["descript"], } if tmppack[key] != nil { tp["value"] = tmppack[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 = strconv.FormatFloat(qu.Float64All(tmpMap["bidamount"]), 'f', -1, 64) } 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": "", }) } // 子包 标的物 var p_inputs []interface{} if plist, o1 := tmppack["purchasinglist"].([]interface{}); o1 { for _, v := range plist { var inputs []interface{} v1 := v.(map[string]interface{}) for key, value := range v1 { tp := map[string]interface{}{ "key": key, "descript": mm[key], } tp["value"] = value tp["status"] = status inputs = append(inputs, tp) } p_inputs = append(p_inputs, inputs) } } packs[k] = map[string]interface{}{ "pack": pack, "packstatus": status, "winnerall": winnerall, "purchasinglist": p_inputs, } } } } sort.Strings(sortpackskey) var packages []map[string]interface{} var isNewPkgArr []bool for _, v := range sortpackskey { packages = append(packages, packs[v]) isNewPkgArr = append(isNewPkgArr, isNewPkg[v]) } return packages, sortpackskey, isNewPkgArr } // 拼装标的物 func setPurchasingMap(info map[string]interface{}, pur []map[string]interface{}, stype string) ([]interface{}, []map[string]interface{}) { var purchasinglists []interface{} //isNewPcl := []bool{} //记录子包是否是新增的 var 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["isnew"].(bool) isNew := false status := "-1" if stype == "remark" && pcl["purchasinglist_son"] != nil { status = "1" } //isNewPcl = append(isNewPcl, isNew) isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status}) var pcls []interface{} for _, ps := range pur { 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 setPurchasingMap1(info map[string]interface{}, pro []map[string]interface{}, stype string) ([]interface{}, []map[string]interface{}) { var procurementlists []interface{} //isNewPcl := []bool{} //记录子包是否是新增的 var isNewAndStatus []map[string]interface{} if tmpcls, ok := info["procurementlist"].([]interface{}); ok { for _, v := range tmpcls { if pcl, ok := v.(map[string]interface{}); ok { //isNew, _ := pcl["isnew"].(bool) isNew := false status := "-1" if stype == "remark" && pcl["purchasinglist_son"] != nil { status = "1" } //isNewPcl = append(isNewPcl, isNew) isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status}) var pcls []interface{} for _, ps := range pro { 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) } procurementlists = append(procurementlists, pcls) } } } return procurementlists, isNewAndStatus } // 拼装中标候选人 func setWorderMap(info map[string]interface{}, winnerorder []map[string]interface{}, stype string) ([]interface{}, []map[string]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["isnew"].(bool) isNew := false status := "-1" if stype == "remark" && wd["winnerorder_son"] != nil { status = "1" } isNewAndStatus = append(isNewAndStatus, map[string]interface{}{"isnew": isNew, "status": status}) wds := []interface{}{} for _, cp := range winnerorder { 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 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{}) tmpInfo["detail"] = qu.ObjToString(tmpInfo["title"]) + "
" + qu.ObjToString(tmpInfo["title"]) 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 } // GetNextDataId 获取当前数据下一条的id func GetNextDataId(id, tid string) string { nextIdQuery := map[string]interface{}{ //"b_istag": false, "_id": map[string]interface{}{ "$gt": mgo.StringTOBsonId(id), }, } if tid != "" { nextIdQuery["s_usertaskid"] = tid } else { } one, _ := util.Mgo.Find(util.DATACOLLNAME, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1) if len(*one) == 1 && len((*one)[0]) > 0 { return mgo.BsonIdToSId((*one)[0]["_id"]) } else { //delete(nextIdQuery, "_id") //one, _ = util.Mgo.Find(coll, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1) //if len(*one) == 1 && len((*one)[0]) > 0 { // if mgo.BsonIdToSId((*one)[0]["_id"]) == id { // return "" // } // return mgo.BsonIdToSId((*one)[0]["_id"]) //} } return "" } func GetLastDataId(id, tid string) string { nextIdQuery := map[string]interface{}{ //"b_istag": false, "_id": map[string]interface{}{ "$lt": mgo.StringTOBsonId(id), }, } if tid != "" { nextIdQuery["s_usertaskid"] = tid } one, _ := util.Mgo.Find(util.DATACOLLNAME, nextIdQuery, `{"_id":-1}`, `{"_id":1}`, true, 0, 1) if len(*one) == 1 && len((*one)[0]) > 0 { return mgo.BsonIdToSId((*one)[0]["_id"]) } else { //delete(nextIdQuery, "_id") //one, _ = util.Mgo.Find(coll, nextIdQuery, `{"_id":-1}`, `{"_id":-1}`, true, 0, 1) //if len(*one) == 1 && len((*one)[0]) > 0 { // if mgo.BsonIdToSId((*one)[0]["_id"]) == id { // return "" // } // return mgo.BsonIdToSId((*one)[0]["_id"]) //} } return "" } // GetNextDataId1 质检下一条 func GetNextDataId1(id, tid, tag string) string { nextIdQuery := map[string]interface{}{ "_id": map[string]interface{}{ "$gt": mgo.StringTOBsonId(id), }, //"b_check": false, } if tid != "" { // 数据有任务 查询带上标注标记 nextIdQuery["i_ckdata"] = 2 if tag == "group" { nextIdQuery["s_grouptaskid"] = tid } else { nextIdQuery["s_usertaskid"] = tid } } else { nextIdQuery["i_ckdata"] = 2 } one, _ := util.Mgo.Find(util.DATACOLLNAME, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1) if len(*one) == 1 && len((*one)[0]) > 0 { return mgo.BsonIdToSId((*one)[0]["_id"]) } else { //delete(nextIdQuery, "_id") //one, _ = util.Mgo.Find(coll, nextIdQuery, `{"_id":1}`, `{"_id":1}`, true, 0, 1) //if len(*one) == 1 && len((*one)[0]) > 0 { // if mgo.BsonIdToSId((*one)[0]["_id"]) == id { // return "" // } // return mgo.BsonIdToSId((*one)[0]["_id"]) //} } return "" } func GetLastDataId1(id, tid, tag string) string { nextIdQuery := map[string]interface{}{ "_id": map[string]interface{}{ "$lt": mgo.StringTOBsonId(id), }, //"b_check": false, } if tid != "" { // 数据有任务 查询带上标注标记 nextIdQuery["i_ckdata"] = 2 if tag == "group" { nextIdQuery["s_grouptaskid"] = tid } else { nextIdQuery["s_usertaskid"] = tid } } else { nextIdQuery["i_ckdata"] = 2 } one, _ := util.Mgo.Find(util.DATACOLLNAME, nextIdQuery, `{"_id":-1}`, `{"_id":1}`, true, 0, 1) if len(*one) == 1 && len((*one)[0]) > 0 { return mgo.BsonIdToSId((*one)[0]["_id"]) } else { //delete(nextIdQuery, "_id") //one, _ = util.Mgo.Find(coll, nextIdQuery, `{"_id":-1}`, `{"_id":1}`, true, 0, 1) //if len(*one) == 1 && len((*one)[0]) > 0 { // if mgo.BsonIdToSId((*one)[0]["_id"]) == id { // return "" // } // return mgo.BsonIdToSId((*one)[0]["_id"]) //} } return "" } func (f *Front) CheckList() { qu.Catch() if f.Method() == "POST" { user := f.GetSession("user").(map[string]interface{}) iRole := qu.ObjToString(user["i_role"]) gid := qu.ObjToString(user["s_groupid"]) start, _ := f.GetInteger("start") limit, _ := f.GetInteger("length") draw, _ := f.GetInteger("draw") status := f.GetString("s_status") searchStr := f.GetString("search[value]") search := strings.TrimSpace(searchStr) query := map[string]interface{}{ "s_stype": "user", } if iRole != "0" { query["s_groupid"] = gid } if status != "-1" { //任务状态 query["s_status"] = status } else { query["s_status"] = map[string]interface{}{ "$in": []string{"未开始", "进行中", "已完成"}, } } if search != "" { query["$or"] = []interface{}{ map[string]interface{}{"s_projectname": map[string]interface{}{"$regex": search}}, } } count := util.Mgo.Count(util.TASKCOLLNAME, query) list, _ := util.Mgo.Find(util.TASKCOLLNAME, query, bson.M{"_id": -1}, nil, false, start, limit) for _, l := range *list { if status := qu.ObjToString(l["s_status"]); status == "进行中" { //更新任务进度 giveNum := qu.IntAll(l["i_givenum"]) tagNum := util.Mgo.Count(util.TASKCOLLNAME, map[string]interface{}{"s_usertaskid": mgo.BsonIdToSId(l["_id"]), "b_istag": true}) progressFloat := float64(tagNum) / float64(giveNum) value, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", progressFloat), 64) decimalValue := decimal.NewFromFloat(value) decimalValue = decimalValue.Mul(decimal.NewFromInt(100)) value, _ = decimalValue.Float64() progress := fmt.Sprint(value) + "%" l["s_progress"] = progress } } f.ServeJson(map[string]interface{}{"draw": draw, "data": *list, "recordsFiltered": count, "recordsTotal": count}) } else { _ = f.Render("project/check_task_list.html") } } func (f *Front) CheckData() { qu.Catch() pid := f.GetString("pid") gid := f.GetString("gid") tid := f.GetString("tid") if f.Method() == "POST" { start, _ := f.GetInteger("start") limit, _ := f.GetInteger("length") draw, _ := f.GetInteger("draw") query := make(map[string]interface{}) query["b_istag"] = true query["s_usertaskid"] = tid status := f.GetString("s_status") s_excp := f.GetString("s_excp") if status == "1" { query["b_check"] = true } else if status == "-1" { query["b_check"] = false } else { query["b_istag"] = true // 默认查询 已标注数据 } if s_excp == "1" { query["s_excp"] = nil } else if s_excp == "-1" { query["s_excp"] = map[string]interface{}{"$exists": true} } count := util.Mgo.Count(util.DATACOLLNAME, query) fields := map[string]interface{}{"v_baseinfo.title": 1, "b_check": 1, "i_ckdata": 1, "s_login": 1, "b_istag": 1, "s_excp": 1, "s_excp_info": 1} info, _ := util.Mgo.Find(util.DATACOLLNAME, query, `{"_id": 1}`, fields, false, start, limit) f.ServeJson(map[string]interface{}{ "draw": draw, "data": *info, "recordsFiltered": count, "recordsTotal": count, }) } else { task, _ := util.Mgo.FindById(util.TASKCOLLNAME, tid, map[string]interface{}{"i_givenum": 1}) f.T["taskNum"] = (*task)["i_givenum"] tagCount, checkCount := 0, 0 tagCount = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"s_usertaskid": tid, "b_istag": true}) checkCount = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"s_usertaskid": tid, "b_check": true}) f.T["taskTagNum"] = tagCount f.T["taskCheckNum"] = checkCount f.T["pid"] = pid f.T["tid"] = tid f.T["gid"] = gid f.T["topsubtype"] = util.TopSubStypeArr f.T["allfield"] = util.AllFieldArr _ = f.Render("project/check_user_data_list.html", &f.T) } } func (f *Front) CheckJyData() { qu.Catch() pid := f.GetString("pid") gid := f.GetString("gid") tid := f.GetString("tid") stype := f.GetString("stype") datatype, _ := f.GetInteger("datatype") if f.Method() == "POST" { start, _ := f.GetInteger("start") limit, _ := f.GetInteger("length") draw, _ := f.GetInteger("draw") query := make(map[string]interface{}) if tid != "" { // 任务数据质检 query["b_istag"] = true if stype == "group" { query["s_grouptaskid"] = tid f.SetSession("check", "group") } else { f.SetSession("check", "user") query["s_usertaskid"] = tid } } else { if stype == "notag" { query["b_istagging"] = false if datatype == 1 { // 待分发数据 query["b_isgivegroup"] = false } else { // 已分发 标注数据 query["b_istag"] = true query["b_isgivegroup"] = true } } else if stype == "tag" { //未达标 query["b_istagging"] = true query["i_ckdata"] = 2 } else { query["i_ckdata"] = 2 } } status := f.GetString("s_status") s_excp := f.GetString("s_excp") s_isEff := f.GetString("isEff") field := f.GetString("field") //字段 dataType1 := f.GetString("datatype1") //信息类型 min := f.GetString("minval") //min max不用int类型接收,以免有默认值0 max := f.GetString("maxval") hasno, _ := f.GetBool("hasno") //是否存在 notag, _ := f.GetBool("notag") //是否标注 searchStr := f.GetString("search[value]") searchStr = strings.TrimSpace(searchStr) if searchStr != "" { query["$or"] = []interface{}{ map[string]interface{}{"v_baseinfo.projectname": map[string]interface{}{"$regex": searchStr}}, map[string]interface{}{"v_baseinfo.title": map[string]interface{}{"$regex": searchStr}}, } } if status == "1" { query["b_check"] = true } else if status == "-1" { query["b_check"] = false } if s_isEff == "1" { query["b_isEff"] = true } else if s_isEff == "-1" { query["b_isEff"] = false } if s_excp == "1" { query["s_excp"] = nil } else if s_excp == "-1" { query["s_excp"] = map[string]interface{}{"$exists": true} } if dataType1 != "-1" && dataType1 != "" { //类型 if dataType1 == util.SPECIALTYPE { query["v_baseinfo.subtype"] = map[string]interface{}{ "$exists": false, } } else { subtype := strings.Split(dataType1, "-")[1] query["v_baseinfo.subtype"] = subtype } } fieldScreen := false if field != "-1" && field != "" { //字段 fieldScreen = true queryfield := map[string]interface{}{ "$exists": !hasno, } numMap := map[string]interface{}{} if field == "budget" || field == "bidamount" { //金额区间 if min != "" { minint := qu.IntAll(min) numMap["$gte"] = minint } if max != "" { maxint := qu.IntAll(max) numMap["$lte"] = maxint } } if len(numMap) > 0 { if !hasno { query["v_baseinfo."+field] = numMap } else { query["$or"] = []map[string]interface{}{ {"v_baseinfo." + field: queryfield}, {"v_baseinfo." + field: numMap}, } } } else { if hasno { query["$or"] = []interface{}{ map[string]interface{}{ "v_baseinfo." + field: queryfield, }, map[string]interface{}{ "v_baseinfo." + field: map[string]interface{}{ "$eq": "", }, }, } } else { query["$and"] = []interface{}{ map[string]interface{}{ "v_baseinfo." + field: queryfield, }, map[string]interface{}{ "v_baseinfo." + field: map[string]interface{}{ "$ne": "", }, }, } } } } if fieldScreen && notag { query["v_taginfo."+field] = map[string]interface{}{ "$exists": false, } } else if !fieldScreen && notag { query["i_ckdata"] = 0 } count := util.Mgo.Count(util.DATACOLLNAME, query) fields := map[string]interface{}{"v_baseinfo.title": 1, "b_check": 1, "i_ckdata": 1, "s_login": 1, "b_istag": 1, "s_excp": 1, "s_excp_info": 1, "b_isEff": 1} info, _ := util.Mgo.Find(util.DATACOLLNAME, query, `{"_id": 1}`, fields, false, start, limit) f.ServeJson(map[string]interface{}{ "draw": draw, "data": *info, "recordsFiltered": count, "recordsTotal": count, }) } else { if tid == "" { query1 := make(map[string]interface{}) if stype == "all" { project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"i_importnum": 1}) f.T["taskNum"] = (*project)["i_importnum"] query1["i_ckdata"] = 2 } else if stype == "notag" { f.T["taskNum"] = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"b_istagging": false}) query1["b_istagging"] = false if datatype == 1 { // 待分发数据 query1["b_isgivegroup"] = false //query1["b_istagging"] = false } else { // 标注数据 query1["b_istag"] = true query1["b_isgivegroup"] = true } } else if stype == "tag" { f.T["taskNum"] = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"b_istagging": false}) query1["b_istagging"] = true //未达标 query1["i_ckdata"] = 2 } else { project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"i_importnum": 1}) f.T["taskNum"] = (*project)["i_importnum"] query1["i_ckdata"] = 2 } count := util.Mgo.Count(util.DATACOLLNAME, query1) //f.T["taskNum"] = count f.T["taskTagNum"] = count query1["b_check"] = true // 已质检 checkCount := util.Mgo.Count(util.DATACOLLNAME, query1) f.T["taskCheckNum"] = checkCount } else { task, _ := util.Mgo.FindById(util.TASKCOLLNAME, tid, map[string]interface{}{"i_givenum": 1}) f.T["taskNum"] = (*task)["i_givenum"] tagCount, checkCount := 0, 0 if stype == "group" { tagCount = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"s_grouptaskid": tid, "b_istag": true}) checkCount = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"s_grouptaskid": tid, "b_check": true}) } else { tagCount = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"s_usertaskid": tid, "b_istag": true}) checkCount = util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"s_usertaskid": tid, "b_check": true}) } f.T["taskTagNum"] = tagCount f.T["taskCheckNum"] = checkCount } project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"purchasinglist_key": 1}) f.T["pid"] = pid f.T["tid"] = tid f.T["gid"] = gid f.T["stype"] = stype f.T["datatype"] = datatype f.T["topsubtype"] = util.TopSubStypeArr f.T["allfield"] = util.AllFieldArr f.T["purchasinglist_key"] = (*project)["purchasinglist_key"] _ = f.Render("project/check_data_list.html", &f.T) } } func (f *Front) CheckDetail() { qu.Catch() tid := f.GetString("tid") pid := f.GetString("pid") did := f.GetString("did") project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, `{"v_fields": 1}`) fs, _ := (*project)["v_fields"].([]interface{}) rep := getDetail(did, "check", qu.ObjArrToMapArr(fs)) //获取本条公告的信息 f.T["otherInfo"] = rep["otherInfo"] //展示关联公告信息 f.T["moreInfo"] = rep["moreInfo"] //更多关联公告信息 f.T["s_excp_info"] = rep["s_excp_info"] f.T["pid"] = pid f.T["tid"] = tid f.T["did"] = did f.T["info"] = rep["info"] f.T["common"] = rep["common"] f.T["other"] = rep["other"] f.T["ck_pclistag"] = rep["purchasingTag"] f.T["enbArr"] = rep["enbArr"] if rep["pru"] != nil { m := rep["pru"].(map[string]interface{}) f.T["purchasinglist"] = m["purchasinglist"] f.T["pcl_new"] = m["pcl_new"] f.T["PurchasinglistField"] = m["field"] } if rep["proc"] != nil { m := rep["proc"].(map[string]interface{}) f.T["procurementlist"] = m["procurementlist"] f.T["pcl_new_1"] = m["pcl_new_1"] f.T["ProcurementlistField"] = m["field"] } if rep["pkg"] != nil { m := rep["pkg"].(map[string]interface{}) f.T["packs"] = m["packs"] f.T["packskey"] = m["packskey"] f.T["pkg_new"] = m["pkg_new"] f.T["PackageField"] = m["field"] } if rep["wino"] != nil { m := rep["wino"].(map[string]interface{}) f.T["worder"] = m["worder"] f.T["worder_new"] = m["worder_new"] f.T["WinnerorderField"] = m["field"] } f.T["topsubtype"] = util.TopSubStypeArr2 f.T["ck_purchasinglist"] = rep["ck_purchasinglist"] f.T["ck_package"] = rep["ck_package"] f.T["ck_winnerorder"] = rep["ck_winnerorder"] f.T["topsubtype"] = util.TopSubStypeArr2 f.T["nextid"] = GetNextDataId1(did, tid, qu.ObjToString(f.GetSession("check"))) //下一条id f.T["lastid"] = GetLastDataId1(did, tid, qu.ObjToString(f.GetSession("check"))) //下一条id _ = f.Render("project/check_detail.html", &f.T) } func (f *Front) CheckSave() { defer qu.Catch() success := false msg := "" user := f.GetSession("user").(map[string]interface{}) username := qu.ObjToString(user["s_login"]) //当前登录用户 userId := qu.ObjToString(user["id"]) //当前登录用户标识 userRole := qu.ObjToString(user["i_role"]) //当前登录用户权限 var obj []map[string]interface{} infoId := f.GetString("s_infoid") pid := f.GetString("pid") project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"s_name": 1, "v_fields": 1}) data := f.GetString("data") err := json.Unmarshal([]byte(data), &obj) if err != nil { qu.Debug("Json Unmarshal Error") f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"}) return } tagSet := map[string]interface{}{} //被标注字段状态 baseSet := map[string]interface{}{} //要修改的字段信息 baseUnset := map[string]interface{}{} //要删除的字段信息 if len(obj) == 1 { //单独保存某个一级 content, ok := obj[0]["content"].([]interface{}) if !ok || len(content) == 0 { f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"}) return } title := qu.ObjToString(obj[0]["title"]) istag, _ := obj[0]["checkAllTag"].(bool) status := qu.IntAll(obj[0]["status"]) switch title { case "基本字段": MarkBase(content, tagSet, baseSet, baseUnset) case "标的信息": MarkPurchasinglist(content, tagSet, baseSet, baseUnset, istag, status) case "采购意向信息": MarkProcurementList(content, tagSet, baseSet, baseUnset, istag, status) case "多包信息": MarkPackage(content, tagSet, baseSet, baseUnset, status) case "中标候选人信息": MarkWonderorder(content, tagSet, baseSet, baseUnset, status) case "自定义字段": MarkOther(content, tagSet, baseSet, baseUnset) } } else { for _, val := range obj { title := qu.ObjToString(val["title"]) content, ok := val["content"].([]interface{}) status := qu.IntAll(val["status"]) if !ok && len(content) > 0 { qu.Debug("Content Error") continue } istag, _ := val["checkAllTag"].(bool) switch title { case "基本字段": MarkBase(content, tagSet, baseSet, baseUnset) case "标的信息": MarkPurchasinglist(content, tagSet, baseSet, baseUnset, istag, status) case "采购意向信息": MarkProcurementList(content, tagSet, baseSet, baseUnset, istag, status) case "多包信息": MarkPackage(content, tagSet, baseSet, baseUnset, status) case "中标候选人信息": MarkWonderorder(content, tagSet, baseSet, baseUnset, status) case "自定义字段": MarkOther(content, tagSet, baseSet, baseUnset) } } } dataInfo, _ := util.Mgo.FindById(util.DATACOLLNAME, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1}) //查询标注保存前的原始信息 tagInfo, _ := (*dataInfo)["v_taginfo"].(map[string]interface{}) baseInfo, _ := (*dataInfo)["v_baseinfo"].(map[string]interface{}) if tagInfo != nil && len(tagInfo) > 0 { for field, tmpStatus := range tagSet { //比对本次标注信息和历史标注信息 status := qu.IntAll(tmpStatus) //此次被标注字段的状态 markedStatus := qu.IntAll(tagInfo[field]) //历史标注状态 if status == 1 && markedStatus != 0 { //此次标注结果为正确,且有历史标注记录,不做修改 //qu.Debug("已标注字段field---", field) //delete(tagSet, field) delete(baseSet, field) //continue } } } allTagFields := map[string]interface{}{} //记录此此标注所有标注信息,用于日志记录 for k, _ := range tagSet { allTagFields[k] = true } for k, v := range baseSet { allTagFields[k] = v } for k, _ := range baseUnset { allTagFields[k] = nil } // 质检时,标注标记变成质检标记 checkFields := qu.ObjArrToMapArr((*project)["v_fields"].([]interface{})) //datatype := qu.ObjToString((*project)["s_datatype"]) checkSet := make(map[string]interface{}) for _, v := range checkFields { key := qu.ObjToString(v["key"]) if key == "extend" && v["child"] != nil { for _, v1 := range qu.ObjArrToMapArr(v["child"].([]interface{})) { key1 := qu.ObjToString(v1["key"]) checkSet[key1] = tagSet[key1] } } else { checkSet[key] = tagSet[key] } } if len(tagSet) > 0 || baseInfo["purchasinglist_alltag"] != nil { //purchasinglist_alltag特殊处理 //1、更新数据源信息 setResult := map[string]interface{}{ //更新字段集 "i_updatetime": time.Now().Unix(), "b_check": true, "s_checkid": userId, "b_istag": true, //"b_isgivegroup": true, //"b_isgiveuser": true, "s_userid": userId, } for field, val := range checkSet { //更新质检字段 setResult["v_taginfo."+field] = val } setResult["v_checkinfo"] = checkSet for field, val := range baseSet { //更新基本字段 setResult["v_baseinfo."+field] = val //baseInfo[field] = val } baseUnsetResult := map[string]interface{}{} //删除字段集 for field, _ := range baseUnset { //删除基本字段 baseUnsetResult["v_baseinfo."+field] = "" //delete(baseInfo, field) } ex, exp := DataException(baseInfo) if ex != "" { setResult["s_excp"] = ex setResult["s_excp_info"] = exp } else { baseUnsetResult["s_excp"] = "" baseUnsetResult["s_excp_info"] = "" } set := map[string]interface{}{ "$set": setResult, } if len(baseUnsetResult) > 0 { set["$unset"] = baseUnsetResult } qu.Debug(infoId) qu.Debug(set) success = util.Mgo.UpdateById(util.DATACOLLNAME, infoId, set) //2、更新marked表 tmp, _ := util.Mgo.FindById(util.DATACOLLNAME, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1, "i_ckdata": 1}) delete(*tmp, "_id") (*tmp)["updatetime"] = time.Now().Unix() _ = util.Mgo.Update(util.AllToColl, map[string]interface{}{"_id": mgo.StringTOBsonId(infoId)}, map[string]interface{}{"$set": tmp}, true, false) } //3、保存标注日志 _ = SaveLog(infoId, "", username, userId, userRole, qu.ObjToString((*project)["s_name"]), "质检", baseInfo, allTagFields) f.ServeJson(map[string]interface{}{"success": success, "msg": msg}) } func (f *Front) CheckResult() { pid := f.GetString("pid") tid := f.GetString("tid") stype := f.GetString("stype") datatype, _ := f.GetInteger("datatype") var allNum int projcet, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"v_fields": 1, "appid": 1}) appid := qu.ObjToString((*projcet)["appid"]) markNum, checkNum, checkNumR := 0, 0, 0 // 标注数量, 审核数据量, 审核数据完全正确的数据量 cmaps := make(map[string]int) // 标注字段整体准确率 cmaps_m := make(map[string]string) umaps := make(map[string]interface{}) // 按人员 字段准确率 for _, v := range qu.ObjArrToMapArr((*projcet)["v_fields"].([]interface{})) { key := qu.ObjToString(v["key"]) if key == "extend" && v["child"] != nil { for _, v1 := range qu.ObjArrToMapArr(v["child"].([]interface{})) { key1 := qu.ObjToString(v1["key"]) cmaps[key1] = 0 cmaps_m[key1] = qu.ObjToString(v1["descript"]) } } else { cmaps[key] = 0 cmaps_m[key] = qu.ObjToString(v["descript"]) } } qu.Debug(cmaps) sess := util.Mgo.GetMgoConn() defer util.Mgo.DestoryMongoConn(sess) query := make(map[string]interface{}) if tid == "" { query1 := make(map[string]interface{}) if stype == "all" { query1["appid"] = appid query1["i_ckdata"] = 2 } else if stype == "notag" { if datatype == 1 { // 待分发数据 query1["b_isgivegroup"] = false query1["b_istagging"] = false } else { // 标注数据 query1["i_ckdata"] = 2 query1["b_isgivegroup"] = false } } else if stype == "tag" { query1["b_istagging"] = true //未达标 query1["i_ckdata"] = 2 } allNum = util.Mgo.Count(util.DATACOLLNAME, query1) } else { task, _ := util.Mgo.FindById(util.TASKCOLLNAME, tid, map[string]interface{}{"i_givenum": 1}) allNum = qu.IntAll((*task)["i_givenum"]) //任务数据量 if stype == "group" { query["s_grouptaskid"] = tid } else { query["s_usertaskid"] = tid } } query["appid"] = appid query["b_check"] = true checkNum = util.Mgo.Count(util.DATACOLLNAME, query) result := sess.DB(util.Mgo.DbName).C(util.DATACOLLNAME).Find(query).Iter() if checkNum == 0 { f.ServeJson(map[string]interface{}{"rep": false, "msg": "无质检审核数据!"}) return } // 排序 purchasingTag := false // 标的物统计标识 var strs []string if cmaps["purchasinglist"] != 0 { purchasingTag = true delete(cmaps, "purchasinglist") } for k := range cmaps { strs = append(strs, k) } pNum, pEffNum := 0, 0 // 标的物数量, 标的物有效数量 fieldNumMap := make(map[string]int) //字段总标注量, tagNumMap := make(map[string]int) //字段标注数据量(标的物有效) rightNumMap := make(map[string]int) //正确数据(标的物有效) for tmp := make(map[string]interface{}); result.Next(&tmp); markNum++ { user := qu.ObjToString(tmp["s_login"]) var up map[string]int if umaps[user] == nil { up = make(map[string]int) } else { up = umaps[user].(map[string]int) } up["ck_count"] += 1 umaps[user] = up if tmp["b_check"].(bool) { if f, ok := tmp["v_checkinfo"].(map[string]interface{}); ok { flag := true // 数据整体准确率 // 按人员统计字段准备率 var up map[string]int if umaps[user] == nil { up = make(map[string]int) } else { up = umaps[user].(map[string]int) } for k1 := range cmaps { if qu.IntAll(f[k1]) == 1 { cmaps[k1] += 1 // 字段整体正确率 up[k1] += 1 } else { flag = false } } up["re_count"] += 1 umaps[user] = up if flag { checkNumR++ up["re_rg_count"] += 1 } } } if tmp["b_check"].(bool) && purchasingTag { info := tmp["v_baseinfo"].(map[string]interface{}) checkInfo := tmp["v_checkinfo"].(map[string]interface{}) if pList, o := info["purchasinglist"].([]interface{}); o { pNum += len(pList) if tmp["b_isEff"].(bool) { pEffNum += 1 } for _, p := range pList { p1 := p.(map[string]interface{}) for f := range purchasingField { if qu.ObjToString(p1[f]) != "" { fieldNumMap[f] += 1 if b, o := p1["b_isEff"].(bool); b && o { tagNumMap[f] += 1 } } } } } if cList, o := checkInfo["purchasinglist"].([]interface{}); o { for _, c := range cList { c1 := c.(map[string]interface{}) for f := range purchasingField { if qu.IntAll(c1[f]) == 1 { rightNumMap[f] += 1 } } } } } } pResult := method(fieldNumMap, tagNumMap, rightNumMap) // 前台页面数据 dataSource := make(map[string]interface{}) var userSelect []string var dataSelect []map[string]interface{} userSelect = append(userSelect, "全部") tmp := make(map[string]interface{}) tmp["name"] = "全部" tmp["num1"] = allNum tmp["num2"] = checkNum tmp["num3"] = checkNumR tmp["num4"] = CountPr(checkNumR, checkNum) dataSelect = append(dataSelect, tmp) sort.Strings(strs) for _, v := range strs { tmp1 := make(map[string]interface{}) tmp1["name"] = cmaps_m[v] tmp1["num1"] = markNum tmp1["num2"] = checkNum tmp1["num3"] = cmaps[v] tmp1["num4"] = CountPr(cmaps[v], checkNum) dataSelect = append(dataSelect, tmp1) } dataSource["全部"] = dataSelect for k1, v1 := range umaps { if v2, o := v1.(map[string]int); o { userSelect = append(userSelect, k1) var dataSelect1 []map[string]interface{} tmp2 := make(map[string]interface{}) tmp2["name"] = "全部" tmp2["num1"] = v2["ck_count"] tmp2["num2"] = v2["re_count"] tmp2["num3"] = v2["re_rg_count"] tmp2["num4"] = CountPr(v2["re_rg_count"], v2["re_count"]) dataSelect1 = append(dataSelect1, tmp2) for k, v := range cmaps_m { tmp1 := make(map[string]interface{}) tmp1["name"] = v tmp1["num1"] = v2["ck_count"] tmp1["num2"] = v2["re_count"] tmp1["num3"] = v2[k] tmp1["num4"] = CountPr(v2[k], v2["re_count"]) dataSelect1 = append(dataSelect1, tmp1) } dataSource[k1] = dataSelect1 } } f.T["pid"] = pid f.T["tid"] = tid f.T["taskNum"] = allNum f.T["taskTagNum"] = markNum f.T["taskCheckNum"] = checkNum f.T["taskCheckRight"] = checkNumR f.T["pNum"] = pNum // 标的物数量 f.T["pEffNum"] = pEffNum //标的物有效数据量 f.T["tableData"] = dataSource f.T["pResult"] = pResult f.T["userSelect"] = userSelect _ = f.Render("project/check_result.html", &f.T) } // @Description 标的物统计结果 // @Author J 2022/4/25 2:20 PM func method(m1, m2, m3 map[string]int) []map[string]interface{} { var result []map[string]interface{} for f, v := range purchasingField { m := make(map[string]interface{}) m["name"] = v m["num"] = m1[f] m["num1"] = m2[f] m["num2"] = m3[f] m["num3"] = CountPr(m2[f], m3[f]) result = append(result, m) } return result } // CountPr 计算百分比 func CountPr(c1, c2 int) string { decimal.DivisionPrecision = 2 if c1 == 0 || c2 == 0 { return "0" } d := decimal.NewFromInt32(int32(c1)).Div(decimal.NewFromInt32(int32(c2))).Mul(decimal.NewFromInt32(100)) return d.String() + "%" } func (f *Front) CheckExcpResult() { pid := f.GetString("pid") tid := f.GetString("tid") stype := f.GetString("stype") query := make(map[string]interface{}) var dataSource []map[string]interface{} if tid != "" { if stype == "group" { query["s_grouptaskid"] = tid } else { query["s_usertaskid"] = tid } query["s_excp"] = map[string]interface{}{"$exists": true} } else { pinfo, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, bson.M{"appid": 1}) query["appid"] = qu.ObjToString((*pinfo)["appid"]) query["s_excp"] = map[string]interface{}{"$exists": true} excpNum := util.Mgo.Count(util.DATACOLLNAME, query) tagNum := util.Mgo.Count(util.DATACOLLNAME, map[string]interface{}{"i_ckdata": 2}) dataSource = append(dataSource, map[string]interface{}{"name": "达标数据", "num1": excpNum, "num2": tagNum, "num3": CountPr(excpNum, tagNum)}) } f.T["tableData"] = dataSource f.T["pid"] = pid f.T["tid"] = tid _ = f.Render("project/check_excp_result.html", &f.T) } func (f *Front) CheckExcpData() { appid := f.GetString("appid") // 达标,待分发数据 query := map[string]interface{}{ "appid": appid, "b_istagging": false, //"b_isgivegroup": false, } pool := make(chan bool, 3) wg := &sync.WaitGroup{} sess := util.Mgo.GetMgoConn() defer util.Mgo.DestoryMongoConn(sess) count := 0 it := sess.DB(util.Mgo.DbName).C(util.DATACOLLNAME).Find(query).Select(nil).Iter() for tmp := make(map[string]interface{}); it.Next(&tmp); count++ { if tmp["s_excp"] != nil { f.ServeJson(map[string]interface{}{"success": true}) break } pool <- true wg.Add(1) go func(tmp map[string]interface{}) { defer func() { <-pool wg.Done() info := tmp["v_baseinfo"].(map[string]interface{}) ex, exp := DataException(info) if ex != "" { util.Mgo.UpdateById(util.DATACOLLNAME, tmp["_id"], map[string]interface{}{"$set": map[string]interface{}{"s_excp": ex, "s_excp_info": exp}}) } }() }(tmp) } f.ServeJson(map[string]interface{}{"success": true}) } var regReplAllSymbol = regexp.MustCompile("[<《【\\[{{〔>》】\\]}}〕,,;;::'\"“”。.??/+=\\-_—*&…^%$¥@#!!`~·]") func DataException(tmp map[string]interface{}) (string, string) { var tag []string var exp string if tmp["buyer"] != nil && tmp["buyer"] == tmp["s_winner"] { tag = append(tag, "1") exp += "采购单位与中标单位相等," } if tmp["agency"] != nil && tmp["buyer"] == tmp["agency"] { tag = append(tag, "2") exp += "采购单位与代理机构相等," } if tmp["s_winner"] != nil && tmp["s_winner"] == tmp["agency"] { tag = append(tag, "3") exp += "中标单位与代理机构相等," } if tmp["bidamount"] != nil && tmp["budget"] != nil { if qu.Float64All(tmp["bidamount"]) > qu.Float64All(tmp["budget"]) { tag = append(tag, "4") exp += "中标金额大于预算," } if qu.Float64All(tmp["bidamount"]) < (qu.Float64All(tmp["budget"]) / 2) { tag = append(tag, "5") exp += "中标金额小于预算的一半," } if tmp["budget"] == 0 && qu.Float64All(tmp["bidamount"]) != 0 { tag = append(tag, "6") exp += "预算为0,中标金额不为0," } if qu.Float64All(tmp["budget"]) != 0 && tmp["bidamount"] == 0 { tag = append(tag, "7") exp += "预算不为0,中标金额为0," } } if b := qu.ObjToString(tmp["buyer"]); b != "" { if regReplAllSymbol.MatchString(b) { tag = append(tag, "8") exp += "采购单位含有特殊符号," } } if a := qu.ObjToString(tmp["agency"]); a != "" { if regReplAllSymbol.MatchString(a) { tag = append(tag, "9") exp += "中标单位含有特殊符号," } } if a := qu.ObjToString(tmp["s_winner"]); a != "" { if regReplAllSymbol.MatchString(a) { tag = append(tag, "10") exp += "代理机构含有特殊符号," } } return strings.Join(tag, ","), exp } // JyMarkList 剑鱼管理员标注信息列表 func (f *Front) JyMarkList() { defer qu.Catch() stype := f.GetString("stype") //all:全量标注;notag:达标数据标注;tag:未达标数据标注 if f.Method() == "POST" { start, _ := f.GetInteger("start") limit, _ := f.GetInteger("length") draw, _ := f.GetInteger("draw") appid := f.GetString("appid") istag := f.GetString("b_istag") // field := f.GetString("field") //字段 dataType := f.GetString("datatype") //信息类型 min := f.GetString("minval") //min max不用int类型接收,以免有默认值0 max := f.GetString("maxval") hasno, _ := f.GetBool("hasno") //是否存在 notag, _ := f.GetBool("notag") //是否标注 query := map[string]interface{}{ //剑鱼自用的标注页面, 查询待分发的数据量 "appid": appid, "b_isgivegroup": false, //"b_isgiveuser": false, } if istag == "true" { query["b_istag"] = true } else if istag == "false" { query["b_istag"] = false } if stype == "notag" { //查询达标 query["b_istagging"] = false } else if stype == "tag" { //查询未达标 query["b_istagging"] = true } if dataType != "-1" && dataType != "" { //类型 if dataType == util.SPECIALTYPE { query["v_baseinfo.subtype"] = map[string]interface{}{ "$exists": false, } } else { subtype := strings.Split(dataType, "-")[1] query["v_baseinfo.subtype"] = subtype } } fieldScreen := false if field != "-1" && field != "" { //字段 fieldScreen = true queryfield := map[string]interface{}{ "$exists": !hasno, } numMap := map[string]interface{}{} if field == "budget" || field == "bidamount" { //金额区间 if min != "" { minint := qu.IntAll(min) numMap["$gte"] = minint } if max != "" { maxint := qu.IntAll(max) numMap["$lte"] = maxint } } if len(numMap) > 0 { if !hasno { query["v_baseinfo."+field] = numMap } else { query["$or"] = []map[string]interface{}{ {"v_baseinfo." + field: queryfield}, {"v_baseinfo." + field: numMap}, } } } else { if hasno { query["$or"] = []interface{}{ map[string]interface{}{ "v_baseinfo." + field: queryfield, }, map[string]interface{}{ "v_baseinfo." + field: map[string]interface{}{ "$eq": "", }, }, } } else { query["$and"] = []interface{}{ map[string]interface{}{ "v_baseinfo." + field: queryfield, }, map[string]interface{}{ "v_baseinfo." + field: map[string]interface{}{ "$ne": "", }, }, } } //query["v_baseinfo."+field] = queryfield } } if fieldScreen && notag { query["v_taginfo."+field] = map[string]interface{}{ "$exists": false, } } else if !fieldScreen && notag { query["i_ckdata"] = 0 } count := util.Mgo.Count(util.DATACOLLNAME, query) fields := map[string]interface{}{"v_baseinfo.title": 1, "b_istag": 1, "i_ckdata": 1} qu.Debug(query) list, _ := util.Mgo.Find(util.DATACOLLNAME, query, map[string]interface{}{"_id": 1}, fields, false, start, limit) f.ServeJson(map[string]interface{}{"draw": draw, "data": *list, "recordsFiltered": count, "recordsTotal": count}) } else { appid := f.GetString("appid") f.T["pid"] = f.GetString("pid") f.T["stype"] = stype f.T["appid"] = appid f.T["topsubtype"] = util.TopSubStypeArr f.T["allfield"] = util.AllFieldArr _ = f.Render("project/remark_jy_list.html", &f.T) } } // JyUserDataMark 剑鱼管理人员数据标注 func (f *Front) JyUserDataMark() { defer qu.Catch() success := false msg := "" user := f.GetSession("user").(map[string]interface{}) username := qu.ObjToString(user["s_login"]) //当前登录用户 groupId := qu.ObjToString(user["s_groupid"]) userId := qu.ObjToString(user["id"]) //当前登录用户标识 userRole := qu.ObjToString(user["i_role"]) //当前登录用户权限 obj := []map[string]interface{}{} infoId := f.GetString("s_infoid") isEff, _ := f.GetBool("isEff") pid := f.GetString("pid") data := f.GetString("data") err := json.Unmarshal([]byte(data), &obj) if err != nil { qu.Debug("Json Unmarshal Error") f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"}) return } tagSet := map[string]interface{}{} //被标注字段状态 baseSet := map[string]interface{}{} //要修改的字段信息 baseUnset := map[string]interface{}{} //要删除的字段信息 if len(obj) == 1 { //单独保存某个一级 content, ok := obj[0]["content"].([]interface{}) if !ok || len(content) == 0 { f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"}) return } title := qu.ObjToString(obj[0]["title"]) istag, _ := obj[0]["checkAllTag"].(bool) status := qu.IntAll(obj[0]["status"]) switch title { case "基本字段": MarkBase(content, tagSet, baseSet, baseUnset) case "标的信息": MarkPurchasinglist(content, tagSet, baseSet, baseUnset, istag, status) case "采购意向信息": MarkProcurementList(content, tagSet, baseSet, baseUnset, istag, status) case "多包信息": MarkPackage(content, tagSet, baseSet, baseUnset, status) case "中标候选人信息": MarkWonderorder(content, tagSet, baseSet, baseUnset, status) case "自定义字段": MarkOther(content, tagSet, baseSet, baseUnset) } } else { for _, val := range obj { title := qu.ObjToString(val["title"]) content, ok := val["content"].([]interface{}) status := qu.IntAll(val["status"]) if !ok { qu.Debug("Content Error") continue } istag, _ := val["checkAllTag"].(bool) switch title { case "基本字段": MarkBase(content, tagSet, baseSet, baseUnset) case "标的信息": MarkPurchasinglist(content, tagSet, baseSet, baseUnset, istag, status) case "采购意向信息": MarkProcurementList(content, tagSet, baseSet, baseUnset, istag, status) case "多包信息": MarkPackage(content, tagSet, baseSet, baseUnset, status) case "中标候选人信息": MarkWonderorder(content, tagSet, baseSet, baseUnset, status) case "自定义字段": MarkOther(content, tagSet, baseSet, baseUnset) } } } qu.Debug("baseUnset===", baseUnset) dataInfo, _ := util.Mgo.FindById(util.DATACOLLNAME, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1}) //查询标注保存前的原始信息 //tagInfo, _ := (*dataInfo)["v_taginfo"].(map[string]interface{}) baseInfo, _ := (*dataInfo)["v_baseinfo"].(map[string]interface{}) //if tagInfo != nil && len(tagInfo) > 0 { // for field, tmpStatus := range tagSet { //比对本次标注信息和历史标注信息 // status := qu.IntAll(tmpStatus) //此次被标注字段的状态 // markedStatus := qu.IntAll(tagInfo[field]) //历史标注状态 // if status == 1 && markedStatus != 0 { //此次标注结果为正确,且有历史标注记录,不做修改 // delete(tagSet, field) // delete(baseSet, field) // //continue // } // //else { // // qu.Debug("未标注字段field---", field, status) // //} // } //} // qu.Debug("baseSet===", baseSet) allTagFields := map[string]interface{}{} //记录此此标注所有标注信息,用于日志记录 for k, _ := range tagSet { allTagFields[k] = true } for k, v := range baseSet { allTagFields[k] = v } for k, _ := range baseUnset { allTagFields[k] = nil } if len(tagSet) >= 0 || baseInfo["purchasinglist_alltag"] != nil { //purchasinglist_alltag特殊处理 //1、更新数据源信息 setResult := map[string]interface{}{ //更新字段集 "i_updatetime": time.Now().Unix(), "i_ckdata": 2, "b_istag": true, "s_userid": userId, "s_groupid": groupId, //"b_isgiveuser": true, //"b_isgivegroup": true, "s_login": username, } for field, val := range tagSet { //更新标注字段 setResult["v_taginfo."+field] = val } for field, val := range baseSet { //更新基本字段 setResult["v_baseinfo."+field] = val } baseUnsetResult := map[string]interface{}{} //删除字段集 for field, _ := range baseUnset { //删除基本字段 baseUnsetResult["v_baseinfo."+field] = "" } setResult["isEff"] = isEff set := map[string]interface{}{ "$set": setResult, } if len(baseUnsetResult) > 0 { set["$unset"] = baseUnsetResult } qu.Debug(infoId) qu.Debug(set) success = util.Mgo.UpdateById(util.DATACOLLNAME, infoId, set) //2、更新marked表 tmp, _ := util.Mgo.FindById(util.DATACOLLNAME, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1, "i_ckdata": 1}) delete((*tmp), "_id") (*tmp)["updatetime"] = time.Now().Unix() _ = util.Mgo.Update(util.AllToColl, map[string]interface{}{"_id": mgo.StringTOBsonId(infoId)}, map[string]interface{}{"$set": tmp}, true, false) } /* } else { 表示页面标注时未做修改标注 } */ //3、保存标注日志 project, _ := util.Mgo.FindById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"s_name": 1}) _ = SaveLog(infoId, "", username, userId, userRole, qu.ObjToString((*project)["s_name"]), "标注", baseInfo, allTagFields) f.ServeJson(map[string]interface{}{"success": success, "msg": msg}) } // UserDataMark 标注人员数据标注(基于任务的标注) func (f *Front) UserDataMark() { defer qu.Catch() success := false msg := "" user := f.GetSession("user").(map[string]interface{}) username := qu.ObjToString(user["s_login"]) //当前登录用户 userId := qu.ObjToString(user["id"]) //当前登录用户标识 userRole := qu.ObjToString(user["i_role"]) //当前登录用户权限 isEff, _ := f.GetBool("isEff") obj := []map[string]interface{}{} infoId := f.GetString("s_infoid") userTaskId := f.GetString("s_usertaskid") data := f.GetString("data") err := json.Unmarshal([]byte(data), &obj) if err != nil { qu.Debug("Json Unmarshal Error") f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"}) return } tagSet := map[string]interface{}{} //被标注字段状态 baseSet := map[string]interface{}{} //要修改的字段信息 baseUnset := map[string]interface{}{} //要删除的字段信息 //isSaveMarked := false if len(obj) == 1 { //单独保存某个一级 content, ok := obj[0]["content"].([]interface{}) if !ok || len(content) == 0 { f.ServeJson(map[string]interface{}{"success": success, "msg": "解析数据失败"}) return } title := qu.ObjToString(obj[0]["title"]) istag, _ := obj[0]["checkAllTag"].(bool) status := qu.IntAll(obj[0]["status"]) switch title { case "基本字段": MarkBase(content, tagSet, baseSet, baseUnset) case "标的信息": MarkPurchasinglist(content, tagSet, baseSet, baseUnset, istag, status) case "采购意向信息": MarkProcurementList(content, tagSet, baseSet, baseUnset, istag, status) case "多包信息": MarkPackage(content, tagSet, baseSet, baseUnset, status) case "中标候选人信息": MarkWonderorder(content, tagSet, baseSet, baseUnset, status) case "自定义字段": MarkOther(content, tagSet, baseSet, baseUnset) } } else { for _, val := range obj { title := qu.ObjToString(val["title"]) content, ok := val["content"].([]interface{}) status := qu.IntAll(val["status"]) if !ok { qu.Debug("Content Error") continue } istag, _ := val["checkAllTag"].(bool) switch title { case "基本字段": MarkBase(content, tagSet, baseSet, baseUnset) case "标的信息": MarkPurchasinglist(content, tagSet, baseSet, baseUnset, istag, status) case "采购意向信息": MarkProcurementList(content, tagSet, baseSet, baseUnset, istag, status) case "多包信息": MarkPackage(content, tagSet, baseSet, baseUnset, status) case "中标候选人信息": MarkWonderorder(content, tagSet, baseSet, baseUnset, status) case "自定义字段": MarkOther(content, tagSet, baseSet, baseUnset) } } } // userTask, _ := util.Mgo.FindById(util.TASKCOLLNAME, userTaskId, map[string]interface{}{"s_personid": 1, "s_personname": 1, "s_projectname": 1}) if userTask == nil || len(*userTask) == 0 { f.ServeJson(map[string]interface{}{"success": success, "msg": "查询用户任务失败"}) return } //数据源表 dataInfo, _ := util.Mgo.FindById(util.DATACOLLNAME, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1}) //查询标注保存前的原始信息 //tagInfo, _ := (*dataInfo)["v_taginfo"].(map[string]interface{}) baseInfo, _ := (*dataInfo)["v_baseinfo"].(map[string]interface{}) //if tagInfo != nil && len(tagInfo) > 0 { // for field, tmpStatus := range tagSet { //比对本次标注信息和历史标注信息 // status := qu.IntAll(tmpStatus) //此次被标注字段的状态 // markedStatus := qu.IntAll(tagInfo[field]) //历史标注状态 // if status == 1 && markedStatus != 0 { //此次标注结果为正确,且有历史标注记录,不做修改 // qu.Debug("已标注字段field---", field) // delete(tagSet, field) // delete(baseSet, field) // //continue // } // //else { // // qu.Debug("未标注字段field---", field, status) // //} // } //} allTagFields := map[string]interface{}{} //记录此此标注所有标注信息,用于日志记录 for k, _ := range tagSet { allTagFields[k] = true } for k, v := range baseSet { allTagFields[k] = v } for k, _ := range baseUnset { allTagFields[k] = nil } if len(tagSet) >= 0 || baseInfo["purchasinglist_alltag"] != nil { //purchasinglist_alltag特殊处理 //1、更新数据源信息 setResult := map[string]interface{}{ //更新字段集 "i_updatetime": time.Now().Unix(), "i_ckdata": 2, "b_istag": true, } for field, val := range tagSet { //更新标注字段 setResult["v_taginfo."+field] = val } for field, val := range baseSet { //更新基本字段 setResult["v_baseinfo."+field] = val //baseInfo[field] = val } baseUnsetResult := map[string]interface{}{} //删除字段集 for field, _ := range baseUnset { //删除基本字段 baseUnsetResult["v_baseinfo."+field] = "" //delete(baseInfo, field) } ex, exp := DataException(baseInfo) if ex != "" { setResult["s_excp"] = ex setResult["s_excp_info"] = exp } setResult["isEff"] = isEff set := map[string]interface{}{ "$set": setResult, } if len(baseUnsetResult) > 0 { set["$unset"] = baseUnsetResult } qu.Debug(set) success = util.Mgo.UpdateById(util.DATACOLLNAME, infoId, set) //2、更新marked表 tmp, _ := util.Mgo.FindById(util.DATACOLLNAME, infoId, map[string]interface{}{"v_baseinfo": 1, "v_taginfo": 1, "i_ckdata": 1}) delete((*tmp), "_id") (*tmp)["updatetime"] = time.Now().Unix() _ = util.Mgo.Update(util.AllToColl, map[string]interface{}{"_id": mgo.StringTOBsonId(infoId)}, map[string]interface{}{"$set": tmp}, true, false) } /* } else { 表示页面标注时未做修改标注 } */ //3、修改任务状态 _ = util.Mgo.Update(util.TASKCOLLNAME, map[string]interface{}{"_id": (*userTask)["_id"], "s_status": "未开始"}, map[string]interface{}{ "$set": map[string]interface{}{ "i_starttime": time.Now().Unix(), "i_updatetime": time.Now().Unix(), "s_updateperson": username, "s_status": "进行中", }, }, false, false) //4、保存标注日志 _ = SaveLog(infoId, userTaskId, username, userId, userRole, qu.ObjToString((*userTask)["s_projectname"]), "标注", baseInfo, allTagFields) f.ServeJson(map[string]interface{}{"success": success, "msg": msg}) } // MarkBase 标注基本信息 func MarkBase(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}) { defer qu.Catch() 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 { //新增、修改、删除 input := tmpMap["input"] //值 if key == "bidamounttype" || key == "subtype" || key == "attach_discern" || key == "attach_ext" || key == "isrepeat" { //附件识别、抽取select input = tmpMap["select"] } if input == "" { //删除原字段 baseUnset[key] = "" } else { //修改原字段 if key == "budget" || key == "bidamount" || key == "biddiscount" { input = qu.Float64All(input) //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32) } if key == "subtype" { if topsubtype := strings.Split(qu.ObjToString(input), "-"); len(topsubtype) == 2 { baseSet["toptype"] = topsubtype[0] baseSet[key] = topsubtype[1] } } else if key == "s_winner" { if strings.Contains(qu.ObjToString(input), ",") { baseSet[key] = strings.ReplaceAll(qu.ObjToString(input), ",", ",") } else { baseSet[key] = input } } else { baseSet[key] = input } } } tagSet[key] = status //记录被标注状态 } } } } } // MarkTimePlace 标注时间地点 func MarkTimePlace(content []interface{}, tagSet, baseSet, baseUnset 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 { //新增、修改、删除 input := tmpMap["input"] //值 if input == "" { baseUnset[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) } baseSet[key] = input } } tagSet[key] = status } } } } } func MarkPurchasinglist(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, istag bool, status int) { if status == -1 { return } baseSet["purchasinglist_alltag"] = istag //标的信息是否标注完全 purchasinglist := []interface{}{} purchasinglistStatus := []interface{}{} delpclson := 0 for _, con := range content { info, _ := con.(map[string]interface{}) //isNew, _ := info["isnew"].(bool) //是否是新增子包 pclSonStatus := qu.IntAll(info["status"]) if pclSonStatus == 4 { delpclson++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ //"isnew": isNew, } statusMap := make(map[string]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"]) statusMap[key] = 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 } } } if pclSonStatus != -1 { //没有标注的标的信息不打标记 result["purchasinglist_son"] = pclSonStatus } if len(result) > 0 && pclSonStatus != 4 { purchasinglist = append(purchasinglist, result) purchasinglistStatus = append(purchasinglistStatus, statusMap) } } } if len(purchasinglist)+delpclson == len(content) { if len(purchasinglist) > 0 { baseSet["purchasinglist"] = purchasinglist } else if len(content) > 0 && delpclson == len(content) { //只有删除 baseUnset["purchasinglist"] = "" } //tagSet["purchasinglist"] = status tagSet["purchasinglist"] = purchasinglistStatus } else { qu.Debug("Purchasinglist Tag Error") } } func MarkProcurementList(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, istag bool, status int) { if status == -1 { return } baseSet["procurementlist_alltag"] = istag //是否标注完全 procurementlist := []interface{}{} procurementlistStatus := []interface{}{} delpclson := 0 for _, con := range content { info, _ := con.(map[string]interface{}) //isNew, _ := info["isnew"].(bool) //是否是新增子包 pclSonStatus := qu.IntAll(info["status"]) if pclSonStatus == 4 { delpclson++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ //"isnew": isNew, } statusMap := make(map[string]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"]) statusMap[key] = 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 } } } if pclSonStatus != -1 { //没有标注的标的信息不打标记 result["procurementlist_son"] = pclSonStatus } if len(result) > 0 && pclSonStatus != 4 { procurementlist = append(procurementlist, result) procurementlistStatus = append(procurementlistStatus, statusMap) } } } if len(procurementlist)+delpclson == len(content) { if len(procurementlist) > 0 { baseSet["procurementlist"] = procurementlist } else if len(content) > 0 && delpclson == len(content) { //只有删除 baseUnset["procurementlist"] = "" } //tagSet["purchasinglist"] = status tagSet["procurementlist"] = status } else { qu.Debug("ProcurementList Tag Error") } } // MarkPackage 标注多包信息 func MarkPackage(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, status int) { if status == -1 { return } pkgs := map[string]interface{}{} total := 0.0 newNum := 1 delpkgson := 0 //记录子包删除个数 var sw []string 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["isnew"].(bool) //是否是新增子包 if isNew { //新增子包新建包名 num = "new" + fmt.Sprint(newNum) newNum++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ "isnew": isNew, } winnerArr := []interface{}{} bidamountArr := []interface{}{} for _, tmp := range uInputs { if tmpMap, ok := tmp.(map[string]interface{}); ok { key := qu.ObjToString(tmpMap["key"]) //字段 input := tmpMap["input"] //值 isNull := false //记录字段是否有值 if key == "bidamounttype" { input = tmpMap["select"] } else { if input == "" { //判断前台页面是否填值,无值不进行字段存储 isNull = true } else if key == "bidamount" || key == "budget" { input = qu.Float64All(input) //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32) } } 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 } } } 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 sw = append(sw, qu.ObjToString(w)) } if b != nil { total += qu.Float64All(b) wbMap["bidamount"] = b } if len(wbMap) > 0 { winner_all = append(winner_all, wbMap) } } } if len(winner_all) > 0 { result["winner_all"] = winner_all } result["package_son"] = pkgSonStatus if len(result) > 0 && pkgSonStatus != 4 { //要删除的子包不再保存 pkgs[num] = result } var purList []map[string]interface{} // 处理包的标的物 if plist, ok := info["content"].([]interface{}); ok { for _, v := range plist { if v1, o1 := v.(map[string]interface{}); o1 { if uts, o2 := v1["uInput"].([]interface{}); o2 { m1 := make(map[string]interface{}) for _, tmp := range uts { if temp, o3 := tmp.(map[string]interface{}); o3 { if qu.ObjToString(temp["key"]) != "" && qu.ObjToString(temp["input"]) != "" { m1[qu.ObjToString(temp["key"])] = qu.ObjToString(temp["input"]) } } } if len(m1) > 0 { purList = append(purList, m1) } } } } if len(purList) > 0 { result["purchasinglist"] = purList } qu.Debug(purList) } } } if len(pkgs)+delpkgson == len(content) { if len(pkgs) > 0 { baseSet["package"] = pkgs baseSet["s_winner"] = strings.Join(sw, ",") baseSet["bidamount"] = total } else if len(content) == 0 { //只有删除 baseUnset["package"] = "" } tagSet["package"] = status } else { qu.Debug("Package Tag Error") } } // 标注中标候选人信息 func MarkWonderorder(content []interface{}, tagSet, baseSet, baseUnset map[string]interface{}, status int) { if status == -1 { return } winnerorder := []interface{}{} delwodrson := 0 for _, con := range content { info, _ := con.(map[string]interface{}) isNew, _ := info["isnew"].(bool) //是否是新增子包 wodrSonStatus := qu.IntAll(info["status"]) if wodrSonStatus == 4 { delwodrson++ } if uInputs, ok := info["uInput"].([]interface{}); ok { result := map[string]interface{}{ "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) //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32) } if !isNull { //避免数字类型的字段在没有填写值的情况默认给0 result[key] = input } result["winnerorder_son"] = wodrSonStatus } } if len(result) > 0 && wodrSonStatus != 4 { winnerorder = append(winnerorder, result) } } } if len(winnerorder)+delwodrson == len(content) { if len(winnerorder) > 0 { baseSet["winnerorder"] = winnerorder } else if len(content) > 0 && delwodrson == len(content) { //只有删除 baseUnset["winnerorder"] = "" } tagSet["winnerorder"] = status } else { qu.Debug("Winnerorder Tag Error") } } // 标注其他信息 func MarkOther(content []interface{}, tagSet, baseSet, baseUnset 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 { //新增、修改、删除 input := tmpMap["input"] //值 if tmpMap["selectArr"] != nil && tmpMap["select"] != nil { input = tmpMap["select"] } if input == "" { baseUnset[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" || key == "biddiscount" { input = qu.Float64All(input) //input, _ = strconv.ParseFloat(qu.ObjToString(input), 32) } baseSet[key] = input } } tagSet[key] = status } } } } } // SaveLog 标注日志保存 func SaveLog(s_infoid, s_usertaskid, username, userid, role, projectname, s_stype string, baseInfo, allTagFields map[string]interface{}) (success bool) { defer qu.Catch() v_before := map[string]interface{}{} for f, v := range allTagFields { if _, ok := v.(bool); ok && f != "purchasinglist_alltag" { //表示此次标注status=1的字段 allTagFields[f] = baseInfo[f] } v_before[f] = baseInfo[f] } save := map[string]interface{}{ "s_projectname": projectname, "s_taskid": s_usertaskid, "s_infoid": s_infoid, "s_stype": s_stype, "s_userid": userid, "s_role": role, "s_username": username, "i_createtime": time.Now().Unix(), "v_before": v_before, "v_after": allTagFields, } id := util.Mgo.Save(util.LOGCOLLNAME, save) if id != "" { success = true } return } func (f *Front) CheckDataPurchase() { defer qu.Catch() if f.Method() == "POST" { datatype, _ := f.GetInteger("datatype") stype := f.GetString("stype") tid := f.GetString("taskid") pid := f.GetString("pid") appid := f.GetString("appid") keyword := f.GetString("keyword") keyword = strings.ReplaceAll(keyword, ",", ",") keyArr := strings.Split(keyword, ",") query := make(map[string]interface{}) if tid != "" { query["b_istag"] = true if stype == "group" { query["s_grouptaskid"] = tid } else { query["s_usertaskid"] = tid } } else { query["appid"] = appid if stype == "notag" { query["b_istagging"] = false if datatype == 1 { // 待分发数据 query["b_isgivegroup"] = false } else { // 已分发 标注数据 query["b_istag"] = true query["b_isgivegroup"] = true } } else if stype == "tag" { //未达标 query["b_istagging"] = true query["i_ckdata"] = 2 } else { query["i_ckdata"] = 2 } } util.Mgo.UpdateById(util.PROJECTCOLLNAME, pid, map[string]interface{}{"$set": map[string]interface{}{"purchasinglist_key": keyword}}) query["v_baseinfo.purchasinglist"] = map[string]interface{}{"$exists": true} info, _ := util.Mgo.Find(util.DATACOLLNAME, query, `{"_id": 1}`, `{"v_baseinfo": 1, "b_isEff": 1, "v_checkinfo": 1, "v_taginfo": 1}`, false, -1, -1) var updateArr [][]map[string]interface{} for _, m := range *info { baseinfo := m["v_baseinfo"].(map[string]interface{}) //taginfo := m["v_taginfo"].(map[string]interface{}) //checkinfo := m["v_checkinfo"].(map[string]interface{}) //var pursTag, pursCheck []interface{} purs := baseinfo["purchasinglist"].([]interface{}) //if taginfo["purchasinglist"] != nil { // pursTag = taginfo["purchasinglist"].([]interface{}) //} //if checkinfo["purchasinglist"] != nil { // pursCheck = checkinfo["purchasinglist"].([]interface{}) //} if len(purs) > 0 { //arr1 := []map[string]interface{}{} //检验通过 //arr2 := []map[string]interface{}{} //检验未通过 for _, m2 := range qu.ObjArrToMapArr(purs) { if validPurchase(keyArr, qu.ObjToString(m2["itemname"])) { m2["b_isEff"] = true if m["b_isEff"] != nil && !m["b_isEff"].(bool) { m["b_isEff"] = true } //arr1 = append(arr1, m2) } else { m2["b_isEff"] = false //arr2 = append(arr2, m2) } } //baseinfo["purchasinglist"] = append(arr1, arr2...) var update []map[string]interface{} update = append(update, map[string]interface{}{"_id": m["_id"]}) update = append(update, map[string]interface{}{"$set": m}) updateArr = append(updateArr, update) } if len(updateArr) > 500 { tmps := updateArr util.Mgo.UpdateBulk(util.DATACOLLNAME, tmps...) updateArr = [][]map[string]interface{}{} } } if len(updateArr) > 0 { util.Mgo.UpSertBulk(util.DATACOLLNAME, updateArr...) } f.ServeJson(map[string]interface{}{"success": true, "msg": ""}) } } func validPurchase(arr []string, str string) bool { for _, s := range arr { if strings.Contains(str, s) { return true } } return false }