123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- package main
- import (
- "fmt"
- "log"
- qu "qfw/util"
- "time"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- //处理融合数据-返回,融合新数据数据-新增
- func (weight *weightDataMap) dealWithAddFusionStruct ()(map[string]interface{},map[string]interface{}){
- //指定模板数据dict-单条数据
- dict :=weight.data[weight.templateid].data
- //采用新增id
- delete(dict,"_id")
- //最早发布时间 (小)
- dict["early_publishtime"] = qu.IntAll(dict["publishtime"])
- //最近发布时间 (大)
- dict["lately_publishtime"] = qu.IntAll(dict["publishtime"])
- //最早入库时间 (小)
- dict["early_comeintime"] = qu.IntAll(dict["comeintime"])
- //最近入库时间 (大)
- dict["lately_comeintime"] = qu.IntAll(dict["comeintime"])
- //当前更新时间
- dict["current_updatetime"] = qu.IntAll(time.Now().Unix())
- //融合生成时间
- dict["current_updatetime"] = qu.IntAll(time.Now().Unix())
- //所有相关联ids
- dict["fusion_allids"] = weight.allids
- //融合保存相关联ids
- dict["fusion_saveids"] = weight.saveids
- return dict,dict
- }
- //处理多条融合数据-返回融合新数据,融合细节数据
- func (weight *weightDataMap) dealWithMultipleFusionStruct ()(map[string]interface{},map[string]interface{}){
- //指定模板数据dict
- dict :=weight.data[weight.templateid].data
- //最早|近发布时间
- dict["early_publishtime"],dict["lately_publishtime"] = weight.dealWithTimeData("publishtime")
- //最早|近入库时间
- dict["early_comeintime"],dict["lately_comeintime"] = weight.dealWithTimeData("comeintime")
- //当前更新时间
- dict["current_updatetime"] = qu.IntAll(time.Now().Unix())
- //融合生成时间-取融合表融合数据
- dict["current_updatetime"] = ""
- //所有相关联ids
- dict["fusion_allids"] = weight.allids
- //融合保存相关联ids
- dict["fusion_saveids"] = weight.saveids
- //日志记录-还有快照页面 等等
- recordDict := make(map[string]interface{},0)
- //结构体字段逻辑处理
- structData := weight.dealWithStructData(&recordDict)
- for k,v:=range structData {
- log.Println("key:",k,"value",v)
- dict["k"] = v
- }
- //非空新增字段
- otherFieldData := weight.dealWithOtherFieldData(&recordDict)
- for k,v:=range otherFieldData {
- //log.Println("key:",k,"value",v)
- dict[k] = v
- }
- dict["repeat"] = 0
- //log.Println("待更新数据:",dict)
- //log.Println("待更新日志:",recordDict)
- //返回,更新数据,日志记录数据
- return dict,recordDict
- }
- //处理其他字段数据
- func (weight *weightDataMap)dealWithOtherFieldData(recordDict *map[string]interface{}) map[string]interface{} {
- //模板id 数据
- templateid := weight.templateid
- templateTmp := weight.data[templateid].data
- modifyData := make(map[string]interface{}, 0) //返回修改的数据
- //找到非空数据
- arr := make([]string,0)
- for key,value:=range templateTmp {
- //判断是否为有效值-
- if !judgeIsEffectiveData(value,key) { //无效
- arr = append(arr,key)
- }
- }
- //第一步,替换模板,存在且空值
- if arr!=nil && len(arr)>0 {
- for _,key:=range arr {
- isRank := 2
- L: for {
- for _,v:=range weight.saveids {
- if v == templateid {
- continue
- }
- dataInfo:=weight.data[v]
- if dataInfo.ranking==isRank { //找到指定排名-字段数据
- value:=dataInfo.data[key]
- if value !=nil && judgeIsEffectiveData(value,key) {
- modifyData[key] = value
- templateTmp[key] = value
- (*recordDict)[key] = map[string]interface{}{
- "id":v,
- "value":value,
- }
- break L
- }
- break
- }
- }
- isRank++
- if isRank > len(weight.saveids) {
- break L
- }
- }
- }
- }
- log.Println("待替换key:",arr,"修改后:",modifyData)
- //第二步-集合最大化
- isRank := 2
- for { //不断遍历,找到其他排名数据
- for _,v:=range weight.saveids {
- if v == templateid {
- continue
- }
- dataInfo:=weight.data[v]
- if dataInfo.ranking==isRank { //找到指定排名数据
- for key,newValue:=range dataInfo.data{
- if key=="_id" || templateTmp[key]!=nil || NoNeedFusionKey[key]!=nil{
- continue
- }
- if judgeIsEffectiveData(newValue,key) {
- log.Println("最大化有效-",key)
- templateTmp[key] = newValue
- modifyData[key] = newValue
- (*recordDict)[key] = map[string]interface{}{
- "id":v,
- "value":newValue,
- }
- }
- }
- break
- }
- }
- isRank++
- if isRank > len(weight.saveids) {
- break
- }
- }
- log.Println("isRank:",isRank,len(modifyData))
- return modifyData
- }
- //处理结构数据
- func (weight *weightDataMap)dealWithStructData(recordDict *map[string]interface{}) map[string]interface{} {
- //模板id 数据
- templateid:=weight.templateid
- templateTmp:=weight.data[templateid].data
- modifyData :=make(map[string]interface{},0)
- //附件attach_text
- /*
- "attach_text" : {
- "1" : {
- "0" : {
- "file_name" : "政采贷融资.doc",
- "attach_url" : "d5ca0944-6af1-11eb-a8bb-0242ac120002"
- }
- },
- "0" : {
- "0" : {
- "file_name" : "01永嘉县人民医院发光免疫试剂采购及设备租赁项目公开招标文件(电子招标).doc",
- "attach_url" : "7827b2d4-6adb-11eb-bd40-0242ac120002"
- }
- }
- },
- */
- attach_text,isAttach:=make(map[string]interface{},0),false
- if tmp_arr,b := templateTmp["attach_text"].(map[string]interface{});b {
- //有值符合-
- attach_text = tmp_arr
- log.Println("默认初始:",attach_text)
- }
- //附件判重-并合并新增
- keyIndex := -1
- //找到当前最大keyIndex
- for k,_:=range attach_text {
- key:=qu.IntAll(k)
- if key>keyIndex {
- keyIndex = key
- }
- }
- log.Println("当前keyIndex",keyIndex)
- for _,value_id :=range weight.saveids {
- if templateid == value_id {
- continue
- }
- rankData := weight.data[value_id].data //具体其他排名数据
- if attachData,b := rankData["attach_text"].(map[string]interface{});b {
- if len(attachData)>0 { //有值
- for _,v:=range attachData { //子元素
- if attach,isOK := v.(map[string]interface{});isOK {
- log.Println(attach)
- if !dealWithRepeatAttachData(attach_text,attach) {
- //符合条件-不重复直接添加
- keyIndex++
- saveKey := fmt.Sprintf("%v",keyIndex)
- attach_text[saveKey] = attach //key累加
- log.Println(attach_text)
- isAttach = true
- //多条情况-融合
- if (*recordDict)["attach_text"]==nil {
- (*recordDict)["attach_text"] = []map[string]interface{}{
- map[string]interface{}{
- "id":value_id,
- "value":attach,
- },
- }
- }else {
- arr := (*recordDict)["attach_text"].([]map[string]interface{})
- arr = append(arr,map[string]interface{}{
- "id":value_id,
- "value":attach,
- })
- (*recordDict)["attach_text"] = arr
- }
- }
- }
- }
- }
- }
- }
- //联系人 winnerorder
- winnerCount:=qu.IntAll(0)
- winnerArr,b,isWinner,winnerid:=make(primitive.A,0),false,false,templateid
- if winnerArr,b = templateTmp["winnerorder"].([]interface{});b {
- winnerCount = qu.IntAll(len(winnerArr))
- }
- //分包 package
- packageCount:=qu.IntAll(0)
- packageArr,b,isPackage,packageid:=make(map[string]interface{},0),false,false,templateid
- if packageArr,b = templateTmp["package"].(map[string]interface{});b {
- packageCount = qu.IntAll(len(packageArr))
- }
- //遍历其他数据-
- for _,value:=range weight.saveids {
- if templateid == value {
- continue
- }
- //winnerorder
- tmp:=weight.data[value].data
- if arr_1,winner_b := tmp["winnerorder"].(primitive.A);winner_b {
- count:=qu.IntAll(len(arr_1))
- if count > winnerCount {
- winnerCount = count
- winnerArr = arr_1
- isWinner = true
- winnerid = value
- }
- }
- //package
- if arr_2,package_b := (tmp["package"]).(map[string]interface{});package_b {
- count:=qu.IntAll(len(arr_2))
- if count > packageCount {
- packageCount = count
- packageArr = arr_2
- isPackage = true
- packageid = value
- }
- }
- }
- //改变的值
- if len(winnerArr)>0 && winnerArr!=nil && isWinner {
- modifyData["winnerorder"] = winnerArr
- (*recordDict)["winnerorder"] = map[string]interface{}{
- "id":winnerid,
- "value":winnerArr,
- }
- }
- if len(packageArr)>0 && packageArr!=nil && isPackage {
- modifyData["package"] = packageArr
- (*recordDict)["package"] = map[string]interface{}{
- "id":packageid,
- "value":packageArr,
- }
- }
- if len(attach_text)>0 && attach_text!=nil && isAttach {
- modifyData["attach_text"] = attach_text
- }
- return modifyData
- }
|