12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970 |
- package main
- import (
- "encoding/json"
- "fmt"
- "github.com/goinggo/mapstructure"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "go.uber.org/zap"
- util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
- "math"
- "project/config"
- "reflect"
- "sort"
- "strings"
- "time"
- )
- /*
- *
- 直接修改保存项目字段信息
- */
- func (p *ProjectTask) modifyUpdate(pid string, index, position int, tmpPro, modifyProMap map[string]interface{}) {
- // 1-0 备份
- tmpPro["reason"] = "直接在原有项目上修改字段信息"
- backupPro(tmpPro)
- delete(tmpPro, "reason")
- // 1-1 修改字段信息
- updateSet := UpdateValue(tmpPro, index, position, modifyProMap)
- updateSet["list"] = tmpPro["list"]
- // 1-2 修改mgo
- bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": updateSet})
- if bol {
- // 1-3 修改es
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pid,
- "$lte": pid,
- }},
- "stype": "project",
- })
- log.Info(string(by))
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- // 修改内存
- p.modifyMem(tmpPro)
- }
- func (p *ProjectTask) mergeAndModify(pInfoId string, index, position int, tmp map[string]interface{}, tmpPro map[string]interface{}, modifyMap map[string]interface{}) {
- proList := tmpPro["list"].([]interface{})
- info := ParseInfo(tmp)
- //项目中list大小等于1
- if len(proList) == 1 {
- log.Info("list大小等于1 合并" + "------1------")
- // 2.1 重新合并
- merge := p.ReMerge(info, tmp, tmpPro)
- if merge {
- //合并到新项目中
- //删除老项目
- p.AllIdsMapLock.Lock()
- delete(p.AllIdsMap, pInfoId)
- p.AllIdsMapLock.Unlock()
- delOldPro(pInfoId)
- // 2.2 备份
- tmpPro["reason"] = "删除原有项目,修改合并到新的项目中"
- backupPro(tmpPro)
- } else {
- //没有合并到新项目中
- p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
- // 修改内存
- p.modifyMem(tmpPro)
- }
- } else if index == 0 {
- // 招标公告信息在原有项目中位于第1个
- merge := p.ReMerge(info, tmp, tmpPro)
- if merge {
- // 合并到新项目中
- // 该条招标公告信息重新参与合并,该项目的其它招标公告信息逐条参与合并
- tmpPro["reason"] = "修改list中第一个条招标公告信息"
- backupPro(tmpPro)
- delete(tmpPro, "reason")
- proList = deleteSlice1(proList, proList[0])
- p.AllIdsMapLock.Lock()
- Id := p.AllIdsMap[pInfoId]
- p.AllIdsMapLock.Unlock()
- proMem := Id.P
- flag := true // 标记是否需要删除原有项目信息
- for _, v := range proList {
- v1 := v.(map[string]interface{})
- temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(v1["infoid"]), nil)
- if len(*temp) == 0 {
- temp, _ = MgoB.FindById("bidding_back", util.ObjToString(v1["infoid"]), nil)
- if len(*temp) == 0 {
- log.Info("extract not find id...", zap.Any("id", v1["infoid"]))
- continue
- }
- }
- tempInfo := ParseInfo(*temp)
- if flag {
- merge := p.ReMerge(tempInfo, *temp, tmpPro)
- if !merge {
- flag = false
- break
- }
- }
- }
- if flag {
- delOldPro(pInfoId)
- } else {
- //合并到原有项目中, 不用继续重新合并, 原有项目内部合并即可
- p.innerMerge(proList, tmpPro)
- bol := MgoP.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pInfoId,
- "$lte": pInfoId,
- }},
- "stype": "project",
- })
- log.Info(string(by))
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- // 修改内存
- p.AllIdsMapLock.Lock()
- if v, ok := p.AllIdsMap[pInfoId]; ok {
- v.P = proMem
- }
- p.AllIdsMapLock.Unlock()
- }
- } else {
- //没有合并到新项目中,更新list字段,有条件更新项目外围字段
- p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
- // 修改内存
- p.modifyMem(tmpPro)
- }
- } else if index == 1 {
- // 招标公告信息在原有项目中处于中间某一条
- merge := p.ReMerge(info, tmp, tmpPro)
- if merge {
- tmpPro["reason"] = "修改list中位于中间某一条招标公告信息"
- backupPro(tmpPro)
- delete(tmpPro, "reason")
- p.innerMerge1(proList, util.ObjToString(tmp["infoid"]), tmpPro)
- bol := MgoP.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pInfoId,
- "$lte": pInfoId,
- }},
- "stype": "project",
- })
- log.Info(string(by))
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- } else {
- // 未合并到新项目中
- p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
- // 修改内存
- p.modifyMem(tmpPro)
- }
- } else if index == 2 {
- // 招标公告信息在原有项目中位于最后一条
- merge := p.ReMerge(info, tmp, tmpPro)
- if merge {
- // 合并到新项目中
- tmpPro["reason"] = "修改list中最后一条招标公告信息"
- backupPro(tmpPro)
- w := len(proList) - 1
- proList = deleteSlice1(proList, proList[w])
- p.innerMerge(proList, tmpPro)
- bol := MgoP.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pInfoId,
- "$lte": pInfoId,
- }},
- "stype": "project",
- })
- log.Info(string(by))
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- } else {
- // 未合并到新项目中
- p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
- // 修改内存
- p.modifyMem(tmpPro)
- }
- }
- }
- // 删除
- func (p *ProjectTask) delJudge(infoid, pid string) {
- tmpPro, _ := MgoP.FindById(ProjectColl, pid, nil)
- if tmpPro != nil || len(*tmpPro) == 0 {
- return
- }
- ids := (*tmpPro)["ids"].([]interface{})
- proList := (*tmpPro)["list"].([]interface{})
- if len(ids) == 1 {
- (*tmpPro)["reason"] = "删除项目信息"
- backupPro(*tmpPro)
- c := MgoP.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
- if c > 0 {
- client := Es.GetEsConn()
- defer Es.DestoryEsConn(client)
- Es.DelById(config.Conf.DB.Es.Index, pid)
- }
- return
- }
- var index = -1 //0:第一个,1:中间,2:最后一个
- for i, v := range ids {
- if util.ObjToString(v) == infoid {
- if i == 0 {
- index = 0
- } else if i == len(ids)-1 {
- index = 2
- } else {
- index = 1
- }
- }
- }
- if index == 0 {
- (*tmpPro)["reason"] = "删除list中第一个条招标公告信息"
- backupPro(*tmpPro)
- delete(*tmpPro, "reason")
- proList = deleteSlice1(proList, proList[0])
- var pro *ProjectCache
- flag := true // 标记是否需要删除原有项目信息
- for _, v := range proList {
- v1 := v.(map[string]interface{})
- temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(v1["infoid"]), nil)
- if len(*temp) == 0 {
- temp, _ = MgoB.FindById("bidding_back", util.ObjToString(v1["infoid"]), nil)
- if len(*temp) == 0 {
- log.Info("extract not find id...", zap.Any("id", v1["infoid"]))
- continue
- }
- }
- tempInfo := ParseInfo(*temp)
- if flag {
- merge := p.ReMerge(tempInfo, *temp, *tmpPro)
- if !merge {
- flag = false
- break
- }
- }
- }
- if flag {
- delOldPro(pid)
- } else {
- *tmpPro, pro = p.innerMerge(proList, *tmpPro)
- bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pid,
- "$lte": pid,
- }},
- "stype": "project",
- })
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- // 修改内存
- p.AllIdsMapLock.Lock()
- if v, ok := p.AllIdsMap[pid]; ok {
- v.P = pro
- }
- p.AllIdsMapLock.Unlock()
- }
- } else if index == 1 {
- (*tmpPro)["reason"] = "删除list中间某一条招标公告信息"
- backupPro(*tmpPro)
- delete(*tmpPro, "reason")
- var pro *ProjectCache
- *tmpPro, pro = p.innerMerge1(proList, infoid, *tmpPro)
- bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pid,
- "$lte": pid,
- }},
- "stype": "project",
- })
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- // 内存
- p.AllIdsMapLock.Lock()
- if v, ok := p.AllIdsMap[pid]; ok {
- v.P = pro
- }
- p.AllIdsMapLock.Unlock()
- } else if index == 2 {
- (*tmpPro)["reason"] = "删除list中最后一条招标公告信息"
- backupPro(*tmpPro)
- delete(*tmpPro, "reason")
- w := len(proList) - 1
- proList = deleteSlice1(proList, proList[w])
- var pro *ProjectCache
- *tmpPro, pro = p.innerMerge(proList, *tmpPro)
- bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pid,
- "$lte": pid,
- }},
- "stype": "project",
- })
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- // 内存
- p.AllIdsMapLock.Lock()
- if v, ok := p.AllIdsMap[pid]; ok {
- v.P = pro
- }
- p.AllIdsMapLock.Unlock()
- }
- }
- // 合并
- func (p *ProjectTask) ReMerge(info *Info, tmp map[string]interface{}, tmpPro map[string]interface{}) bool {
- bpn, bpc, bptc, bpb, pids, _, IDArr := p.getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer)
- defer p.wg.Done()
- for _, m := range pids {
- defer m.Lock.Unlock()
- }
- for _, id := range IDArr {
- defer id.Lock.Unlock()
- }
- bFindProject := false
- findPid := ""
- comRes1 := []*ProjectCache{}
- comRes2 := []*ProjectCache{}
- comRes3 := []*ProjectCache{}
- for _, v := range IDArr {
- comStr := ""
- compareProject := v.P
- compareProject.score = 0
- diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
- if diffTime <= p.validTime {
- if CheckContain(compareProject.Agency, info.Agency) == 3 {
- continue
- }
- if ComparePlace(compareProject, info) {
- continue
- }
- info.PNBH = 0
- info.PCBH = 0
- info.PTCBH = 0
- compareStr, score := comparePNC(info, compareProject)
- resVal, pjVal := Select(compareStr, info, compareProject)
- if resVal > 0 {
- compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
- comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
- compareProject.comStr = comStr
- compareProject.pjVal = pjVal
- compareProject.resVal = resVal
- eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
- if eqV == 1 {
- comRes1 = append(comRes1, compareProject)
- } else if eqV == 2 {
- comRes2 = append(comRes2, compareProject)
- } else if eqV == 3 {
- comRes3 = append(comRes3, compareProject)
- }
- }
- }
- }
- //--------------------------------对比完成-----------------------
- for kv, resN := range [][]*ProjectCache{comRes1, comRes2, comRes3} {
- if len(resN) > 0 {
- if len(resN) > 1 {
- sort.Slice(resN, func(i, j int) bool {
- return resN[i].score > resN[j].score
- })
- }
- ex := 0
- resArr := []*ProjectCache{}
- for i, res := range resN {
- choose, e := p.CompareStatus(resN[i], info)
- if !choose {
- ex = e
- resArr = append(resArr, res)
- }
- }
- if len(resArr) > 0 {
- bFindProject = true
- findPid = resArr[0].Id.Hex()
- if findPid == mongodb.BsonIdToSId(tmpPro["_id"]) {
- return false
- }
- p.updateProFiled(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
- for k2, bv := range []int{bpn, bpc, bptc, bpb} {
- if bv > -1 {
- pids[bv].Arr = append(pids[bv].Arr, findPid)
- if k2 == 0 {
- if resArr[0].ProjectName == "" {
- resArr[0].ProjectName = info.ProjectName
- } else {
- if resArr[0].MPN == nil {
- resArr[0].MPN = []string{info.ProjectName}
- } else {
- resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
- }
- }
- } else if k2 < 3 {
- if resArr[0].ProjectCode == "" {
- resArr[0].ProjectCode = util.If(k2 == 1, info.ProjectCode, info.PTC).(string)
- } else {
- if resArr[0].MPC == nil {
- resArr[0].MPC = []string{util.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
- } else {
- resArr[0].MPC = append(resArr[0].MPC, util.If(k2 == 1, info.ProjectCode, info.PTC).(string))
- }
- }
- } else {
- if resArr[0].Buyer == "" {
- resArr[0].Buyer = info.Buyer
- }
- }
- }
- }
- } else {
- bFindProject = false
- findPid = ""
- }
- break
- }
- }
- if !bFindProject {
- id, p1 := p.NewProject(tmp, info)
- p.AllIdsMapLock.Lock()
- p.AllIdsMap[id] = &ID{Id: id, P: p1}
- p.AllIdsMapLock.Unlock()
- for _, m := range pids {
- m.Arr = append(m.Arr, id)
- }
- return false
- }
- return true
- }
- // 内部合并
- func (p *ProjectTask) innerMerge(infoList []interface{}, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectCache) {
- newP := make(map[string]interface{})
- newP["_id"] = tmpPro["_id"]
- var p1 *ProjectCache
- for k, m := range infoList {
- m1 := m.(map[string]interface{})
- temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(m1["infoid"]), nil)
- if len(*temp) == 0 {
- temp, _ = MgoB.FindById("bidding_back", util.ObjToString(m1["infoid"]), nil)
- if len(*temp) == 0 {
- continue
- }
- }
- tempInfo := ParseInfo(*temp)
- if k == 0 {
- p1 = p.newPro(*temp, newP, tempInfo)
- } else {
- p.updateOldProField(p1, tempInfo, newP, *temp, m1)
- }
- }
- return newP, p1
- }
- func (p *ProjectTask) innerMerge1(infoList []interface{}, infoid string, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectCache) {
- newP := make(map[string]interface{})
- newP["_id"] = tmpPro["_id"]
- var p1 *ProjectCache
- for k, m := range infoList {
- m1 := m.(map[string]interface{})
- if m1["infoid"] == infoid {
- continue
- }
- temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(m1["infoid"]), nil)
- if len(*temp) == 0 {
- temp, _ = MgoB.FindById("bidding_back", util.ObjToString(m1["infoid"]), nil)
- if len(*temp) == 0 {
- log.Info("extract not find id...", zap.Any("id", m1["infoid"]))
- continue
- }
- }
- tempInfo := ParseInfo(*temp)
- if k == 0 {
- p1 = p.newPro(*temp, newP, tempInfo)
- } else {
- p.updateOldProField(p1, tempInfo, newP, *temp, m1)
- }
- }
- return newP, p1
- }
- // 更新招标公告到新的项目中
- func (p *ProjectTask) updateProFiled(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectCache, weight int, comStr string, ex int) {
- pdata := redis.Get("project", pInfo.Id.Hex())
- projectMap := pdata.(map[string]interface{})
- bys, _ := json.Marshal(projectMap)
- var project *Project
- err := json.Unmarshal(bys, &project)
- if err != nil {
- log.Info("project Unmarshal err," + err.Error())
- return
- }
- set := map[string]interface{}{}
- pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
- project.Ids = append(project.Ids, thisinfo.Id)
- if len(pInfo.Ids) > 30 {
- //异常标记
- set["listtag"] = 1
- }
- if thisinfo.Publishtime > pInfo.LastTime {
- pInfo.LastTime = thisinfo.Publishtime
- project.LastTime = thisinfo.Publishtime
- set["lasttime"] = thisinfo.Publishtime
- }
- if thisinfo.TopType == "招标" {
- if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && project.Zbtime <= 0 {
- set["zbtime"] = tmp["publishtime"]
- }
- } else if thisinfo.TopType == "结果" {
- if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
- if project.Jgtime > 0 {
- jg1 := int64(math.Abs(float64(project.Jgtime - thisinfo.Publishtime)))
- //公告状态和项目状态同样都是中标或者成交,
- if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
- if jg1 > p.jgTime {
- set["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
- //公告状态和项目状态同样是流标或者废标
- if jg1 > p.jgTime {
- set["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- }
- } else {
- set["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- }
- } else if thisinfo.SubType == "合同" {
- if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
- //中标、成交不更新jgtime
- } else {
- set["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- }
- if thisinfo.BidOpenTime > project.BidOpenTime {
- project.BidOpenTime = thisinfo.BidOpenTime
- set["bidopentime"] = thisinfo.BidOpenTime
- }
- if thisinfo.BidEndTime > 0 {
- project.BidEndTime = thisinfo.BidEndTime
- set["bidendtime"] = project.BidEndTime
- }
- // bidtype、bidstatus
- pInfo.Bidtype, pInfo.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
- project.Bidtype, project.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
- set["bidtype"] = pInfo.Bidtype
- set["bidstatus"] = pInfo.Bidstatus
- //异常标记
- if ex > 0 {
- set["exception"] = ex
- }
- //相同城市的公告才会合并到一起(全国列外)
- if thisinfo.Area != "全国" {
- pInfo.Area = thisinfo.Area
- project.Area = thisinfo.Area
- set["area"] = thisinfo.Area
- pInfo.City = thisinfo.City
- project.City = thisinfo.City
- set["city"] = thisinfo.City
- if thisinfo.District != "" {
- pInfo.District = thisinfo.District
- project.District = thisinfo.District
- set["district"] = thisinfo.District
- }
- }
- // 项目名称
- if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
- pInfo.ProjectName = thisinfo.ProjectName
- project.ProjectName = thisinfo.ProjectName
- set["projectname"] = thisinfo.ProjectName
- }
- // 项目编号
- if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
- pInfo.ProjectCode = thisinfo.ProjectCode
- project.ProjectCode = thisinfo.ProjectCode
- set["projectcode"] = thisinfo.ProjectCode
- }
- // 采购单位
- if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
- pInfo.Buyer = thisinfo.Buyer
- set["buyer"] = thisinfo.Buyer
- project.Buyerclass = thisinfo.Buyerclass
- set["buyerclass"] = thisinfo.Buyerclass
- }
- if pInfo.Buyer == "" {
- project.Buyerclass = ""
- set["buyerclass"] = ""
- }
- // 采购单位联系人
- if thisinfo.Buyerperson != "" {
- project.Buyerperson = thisinfo.Buyerperson
- set["buyerperson"] = thisinfo.Buyerperson
- } else {
- project.Buyerperson = ""
- set["buyerperson"] = ""
- }
- // 采购单位電話
- if thisinfo.Buyertel != "" {
- project.Buyertel = thisinfo.Buyertel
- set["buyertel"] = thisinfo.Buyertel
- } else {
- project.Buyertel = ""
- set["buyertel"] = ""
- }
- if thisinfo.ContractCode != "" {
- set["contractcode"] = project.ContractCode + "," + thisinfo.ContractCode
- }
- // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
- //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
- // pInfo.Agency = thisinfo.Agency
- // set["agency"] = thisinfo.Agency
- //}
- if len(thisinfo.Topscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
- sort.Strings(project.Topscopeclass)
- for _, k := range thisinfo.Topscopeclass {
- if BinarySearch(project.Topscopeclass, k) == -1 {
- project.Topscopeclass = append(project.Topscopeclass, k)
- sort.Strings(project.Topscopeclass)
- }
- }
- set["topscopeclass"] = project.Topscopeclass
- }
- // 项目评审专家
- if len(thisinfo.ReviewExperts) > 0 && thisinfo.Publishtime > pInfo.LastTime {
- set["review_experts"] = thisinfo.ReviewExperts
- project.ReviewExperts = thisinfo.ReviewExperts
- }
- if thisinfo.Purchasing != "" && thisinfo.Publishtime > pInfo.LastTime {
- if project.Purchasing == "" {
- project.Purchasing = thisinfo.Purchasing
- set["purchasing"] = thisinfo.Purchasing
- } else {
- list := strings.Split(project.Purchasing, ",")
- for _, k := range list {
- if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
- list = append(list, k)
- sort.Strings(list)
- }
- }
- set["purchasing"] = strings.Join(list, ",")
- }
- }
- //中标候选人
- if len(thisinfo.WinnerOrder) > 0 && thisinfo.Publishtime > pInfo.LastTime {
- var list = []string{}
- for _, v := range thisinfo.WinnerOrder {
- if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
- list = append(list, util.ObjToString(v["entname"]))
- }
- }
- set["winnerorder"] = list
- project.Winnerorder = list
- }
- if len(thisinfo.Subscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
- sort.Strings(project.Subscopeclass)
- for _, k := range thisinfo.Subscopeclass {
- if BinarySearch(project.Subscopeclass, k) == -1 {
- project.Subscopeclass = append(project.Subscopeclass, k)
- sort.Strings(project.Subscopeclass)
- }
- }
- set["subscopeclass"] = project.Subscopeclass
- set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
- }
- if len(thisinfo.Winners) > 0 && thisinfo.Publishtime > pInfo.LastTime {
- winners := strings.Split(project.Winners, ",")
- if len(winners) <= 0 {
- set["winner"] = util.ObjToString(tmp["winner"])
- }
- for _, k := range thisinfo.Winners {
- if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
- if BinarySearch(winners, k) != -1 {
- deleteSlice(winners, k, "")
- sort.Strings(winners)
- }
- } else {
- if BinarySearch(winners, k) == -1 {
- winners = append(winners, k)
- sort.Strings(winners)
- }
- }
- }
- set["s_winner"] = strings.Join(winners, ",")
- }
- if thisinfo.HasPackage { //多包处理
- set["multipackage"] = 1
- pkg := PackageFormat(thisinfo, project)
- project.Package = pkg
- set["package"] = project.Package
- }
- //处理多包后,计算预算金额、中标金额
- //CountAmount(project, thisinfo, tmp)
- //if project.Budget >= 0 && project.Budgettag != 1 {
- // pInfo.Budget = project.Budget
- // set["budget"] = pInfo.Budget
- // set["budgettag"] = 0
- //}
- //if pInfo.Bidamount >= 0 && project.Bidamounttag != 1 {
- // pInfo.Bidamount = project.Bidamount
- // set["bidamount"] = pInfo.Bidamount
- // set["bidamounttag"] = 0
- //}
- //if pInfo.Bidamount > 0 {
- // set["sortprice"] = pInfo.Bidamount
- //} else {
- // if pInfo.Budget > 0 {
- // set["sortprice"] = pInfo.Budget
- // }
- //}
- if thisinfo.Budget > 0 {
- pInfo.Budget = thisinfo.Budget
- project.Budget = thisinfo.Budget
- set["budget"] = thisinfo.Budget
- }
- if thisinfo.Bidamount > 0 {
- pInfo.Bidamount = thisinfo.Bidamount
- project.Bidamount = thisinfo.Bidamount
- set["bidamount"] = thisinfo.Bidamount
- }
- if pInfo.Bidamount > 0 {
- set["sortprice"] = pInfo.Bidamount
- } else {
- if pInfo.Budget > 0 {
- set["sortprice"] = pInfo.Budget
- }
- }
- //infofield := InfoField{
- // Budget: thisinfo.Budget,
- // Bidamount: thisinfo.Bidamount,
- // ContractCode: thisinfo.ContractCode,
- // ProjectName: thisinfo.ProjectName,
- // ProjectCode: thisinfo.ProjectCode,
- // Bidstatus: pInfo.Bidstatus,
- //}
- //copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
- //copyMap[thisinfo.Id] = infofield
- //tmpMap := make(map[string]interface{})
- //for k, v := range copyMap {
- // tmpMap[k] = StructToMap(v)
- //}
- //tmpMap[thisinfo.Id] = StructToMap(infofield)
- //project.InfoFiled = copyMap
- //set["infofield"] = tmpMap
- set["mpn"] = pInfo.MPN
- set["mpc"] = pInfo.MPC
- set["updatetime"] = p.pici
- redis.PutCKV("project", project.Id.Hex(), set)
- update := map[string]interface{}{}
- if len(set) > 0 {
- update["$set"] = set
- }
- push := p.PushListInfo(tmp, thisinfo.Id)
- push["s_winner"] = strings.Join(thisinfo.Winners, ",")
- push["compareStr"] = comStr
- push["resVal"] = pInfo.resVal
- push["pjVal"] = pInfo.pjVal
- update["$push"] = map[string]interface{}{
- "list": push,
- "ids": thisinfo.Id,
- }
- bol := MgoP.UpdateById(ProjectColl, pInfo.Id.Hex(), update)
- if bol {
- by, _ := json.Marshal(map[string]interface{}{
- "query": map[string]interface{}{
- "_id": bson.M{
- "$gte": pInfo.Id.Hex(),
- "$lte": pInfo.Id.Hex(),
- }},
- "stype": "project",
- })
- log.Info(string(by))
- _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
- }
- }
- // 内部合并时,原有项目id基础上新建项目
- func (p *ProjectTask) newPro(tmp, tmpPro map[string]interface{}, thisinfo *Info) *ProjectCache {
- for _, f := range FIELDS {
- if tmp[f] != nil && tmp[f] != "" {
- tmpPro[f] = tmp[f]
- }
- }
- bidopentime := util.Int64All(tmp["bidopentime"])
- if bidopentime > 0 {
- tmpPro["bidopentime"] = bidopentime
- }
- //异常标记
- if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
- tmpPro["exception"] = 1
- }
- //projecthref保存
- if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
- if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
- tmpPro["projecthref"] = jsonData["projecthref"]
- }
- }
- //合同编号
- if thisinfo.ContractCode != "" {
- tmpPro["contractcode"] = thisinfo.ContractCode
- }
- bs, bt := p.GetBidTypeAndBidStatus(thisinfo)
- tmpPro["bidtype"] = bs
- tmpPro["bidstatus"] = bt
- pkg := PackageFormat(thisinfo, nil)
- p1 := p.NewCachePinfo(tmpPro["_id"].(primitive.ObjectID), thisinfo, bs, bt)
- now := time.Now().Unix()
- tmpPro["createtime"] = now
- tmpPro["sourceinfoid"] = thisinfo.Id
- tmpPro["sourceinfourl"] = tmp["href"]
- tmpPro["firsttime"] = tmp["publishtime"]
- tmpPro["lasttime"] = tmp["publishtime"]
- tmpPro["pici"] = tmp["comeintime"]
- tmpPro["ids"] = []string{thisinfo.Id}
- if thisinfo.TopType == "招标" {
- if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
- tmpPro["zbtime"] = tmp["publishtime"]
- }
- } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
- tmpPro["jgtime"] = tmp["publishtime"]
- }
- if len(thisinfo.Subscopeclass) > 0 {
- tmpPro["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
- }
- if len(thisinfo.Winners) > 0 {
- tmpPro["s_winner"] = strings.Join(thisinfo.Winners, ",")
- }
- if thisinfo.HasPackage {
- tmpPro["multipackage"] = 1
- tmpPro["package"] = pkg
- } else {
- tmpPro["multipackage"] = 0
- }
- //项目评审专家
- if len(thisinfo.ReviewExperts) > 0 {
- tmpPro["review_experts"] = thisinfo.ReviewExperts
- }
- //标的物
- if thisinfo.Purchasing != "" {
- tmpPro["purchasing"] = thisinfo.Purchasing
- }
- //中标候选人
- if len(thisinfo.WinnerOrder) > 0 {
- var list = []string{}
- for _, v := range thisinfo.WinnerOrder {
- if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
- list = append(list, util.ObjToString(v["entname"]))
- }
- }
- tmpPro["winnerorder"] = list
- }
- //infofield := InfoField{
- // Budget: thisinfo.Budget,
- // Bidamount: thisinfo.Bidamount,
- // ContractCode: thisinfo.ContractCode,
- // ProjectName: thisinfo.ProjectName,
- // ProjectCode: thisinfo.ProjectCode,
- // Bidstatus: bs,
- //}
- //res := StructToMap(infofield)
- //tmpPro["infofield"] = map[string]interface{}{
- // thisinfo.Id: res,
- //}
- if tmp["budget"] != nil {
- tmpPro["budget"] = thisinfo.Budget
- tmpPro["budgettag"] = 0
- } else {
- tmpPro["budgettag"] = 1
- }
- if tmp["bidamount"] != nil {
- tmpPro["bidamount"] = thisinfo.Bidamount
- tmpPro["bidamounttag"] = 0
- } else {
- tmpPro["bidamounttag"] = 1
- }
- if p1.Bidamount > 0 {
- tmpPro["sortprice"] = p1.Bidamount
- } else if p1.Budget > 0 {
- tmpPro["sortprice"] = p1.Budget
- }
- push := p.PushListInfo(tmp, thisinfo.Id)
- push["s_winner"] = strings.Join(thisinfo.Winners, ",")
- tmpPro["list"] = []map[string]interface{}{
- push,
- }
- return &p1
- }
- // 合并字段到老项目中
- func (p *ProjectTask) updateOldProField(pInfo *ProjectCache, thisinfo *Info, tmpPro, tmp, m1 map[string]interface{}) {
- pdata := redis.Get("project", pInfo.Id.Hex())
- projectMap := pdata.(map[string]interface{})
- bys, _ := json.Marshal(projectMap)
- var project *Project
- err := json.Unmarshal(bys, &project)
- if err != nil {
- log.Error("project Unmarshal err," + err.Error())
- return
- }
- if len(pInfo.Ids) > 30 {
- //异常标记
- tmpPro["listtag"] = 1
- }
- if thisinfo.Publishtime > pInfo.LastTime {
- pInfo.LastTime = thisinfo.Publishtime
- project.LastTime = thisinfo.Publishtime
- tmpPro["lasttime"] = thisinfo.Publishtime
- }
- if thisinfo.TopType == "招标" {
- if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && project.Zbtime <= 0 {
- tmpPro["zbtime"] = tmp["publishtime"]
- }
- } else if thisinfo.TopType == "结果" {
- if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
- if project.Jgtime > 0 {
- jg1 := int64(math.Abs(float64(project.Jgtime - thisinfo.Publishtime)))
- //公告状态和项目状态同样都是中标或者成交,
- if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
- if jg1 > p.jgTime {
- tmpPro["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
- //公告状态和项目状态同样是流标或者废标
- if jg1 > p.jgTime {
- tmpPro["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- }
- } else {
- tmpPro["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- }
- } else if thisinfo.SubType == "合同" {
- if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
- //中标、成交不更新jgtime
- } else {
- tmpPro["jgtime"] = tmp["publishtime"]
- project.Jgtime = thisinfo.Publishtime
- }
- }
- if thisinfo.BidOpenTime > project.BidOpenTime {
- project.BidOpenTime = thisinfo.BidOpenTime
- tmpPro["bidopentime"] = thisinfo.BidOpenTime
- }
- if thisinfo.BidEndTime > 0 {
- project.BidEndTime = thisinfo.BidEndTime
- tmpPro["bidendtime"] = thisinfo.BidEndTime
- }
- // bidtype、bidstatus
- pInfo.Bidtype, pInfo.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
- project.Bidtype, project.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
- tmpPro["bidtype"] = pInfo.Bidtype
- tmpPro["bidstatus"] = pInfo.Bidstatus
- //相同城市的公告才会合并到一起(全国列外)
- if thisinfo.Area != "全国" {
- pInfo.Area = thisinfo.Area
- project.Area = thisinfo.Area
- tmpPro["area"] = thisinfo.Area
- pInfo.City = thisinfo.City
- project.City = thisinfo.City
- tmpPro["city"] = thisinfo.City
- if thisinfo.District != "" {
- pInfo.District = thisinfo.District
- project.District = thisinfo.District
- tmpPro["district"] = thisinfo.District
- }
- }
- // 项目名称
- if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
- pInfo.ProjectName = thisinfo.ProjectName
- project.ProjectName = thisinfo.ProjectName
- tmpPro["projectname"] = thisinfo.ProjectName
- }
- // 项目编号
- if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
- pInfo.ProjectCode = thisinfo.ProjectCode
- project.ProjectCode = thisinfo.ProjectCode
- tmpPro["projectcode"] = thisinfo.ProjectCode
- }
- // 采购单位
- if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
- pInfo.Buyer = thisinfo.Buyer
- tmpPro["buyer"] = thisinfo.Buyer
- project.Buyerclass = thisinfo.Buyerclass
- tmpPro["buyerclass"] = thisinfo.Buyerclass
- }
- if pInfo.Buyer == "" {
- project.Buyerclass = ""
- tmpPro["buyerclass"] = ""
- }
- // 采购单位联系人
- if thisinfo.Buyerperson != "" {
- project.Buyerperson = thisinfo.Buyerperson
- tmpPro["buyerperson"] = thisinfo.Buyerperson
- } else {
- project.Buyerperson = ""
- tmpPro["buyerperson"] = ""
- }
- // 采购单位電話
- if thisinfo.Buyertel != "" {
- project.Buyertel = thisinfo.Buyertel
- tmpPro["buyertel"] = thisinfo.Buyertel
- } else {
- project.Buyertel = ""
- tmpPro["buyertel"] = ""
- }
- if thisinfo.ContractCode != "" {
- tmpPro["contractcode"] = project.ContractCode + "," + thisinfo.ContractCode
- }
- // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
- //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
- // pInfo.Agency = thisinfo.Agency
- // set["agency"] = thisinfo.Agency
- //}
- if len(thisinfo.Topscopeclass) > 0 {
- sort.Strings(project.Topscopeclass)
- for _, k := range thisinfo.Topscopeclass {
- if BinarySearch(project.Topscopeclass, k) == -1 {
- project.Topscopeclass = append(project.Topscopeclass, k)
- sort.Strings(project.Topscopeclass)
- }
- }
- tmpPro["topscopeclass"] = project.Topscopeclass
- }
- // 项目评审专家
- if len(thisinfo.ReviewExperts) > 0 {
- tmpPro["review_experts"] = thisinfo.ReviewExperts
- project.ReviewExperts = thisinfo.ReviewExperts
- }
- if thisinfo.Purchasing != "" {
- if project.Purchasing == "" {
- project.Purchasing = thisinfo.Purchasing
- tmpPro["purchasing"] = thisinfo.Purchasing
- } else {
- list := strings.Split(project.Purchasing, ",")
- for _, k := range list {
- if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
- list = append(list, k)
- sort.Strings(list)
- }
- }
- tmpPro["purchasing"] = strings.Join(list, ",")
- }
- }
- //中标候选人
- if len(thisinfo.WinnerOrder) > 0 {
- var list = []string{}
- for _, v := range thisinfo.WinnerOrder {
- if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
- list = append(list, util.ObjToString(v["entname"]))
- }
- }
- tmpPro["winnerorder"] = list
- project.Winnerorder = list
- }
- if len(thisinfo.Subscopeclass) > 0 {
- sort.Strings(project.Subscopeclass)
- for _, k := range thisinfo.Subscopeclass {
- if BinarySearch(project.Subscopeclass, k) == -1 {
- project.Subscopeclass = append(project.Subscopeclass, k)
- sort.Strings(project.Subscopeclass)
- }
- }
- tmpPro["subscopeclass"] = project.Subscopeclass
- tmpPro["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
- }
- if len(thisinfo.Winners) > 0 {
- if len(project.Winners) <= 0 {
- tmpPro["winner"] = util.ObjToString(tmp["winner"])
- }
- winners := strings.Split(project.Winners, ",")
- for _, k := range thisinfo.Winners {
- if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
- if BinarySearch(winners, k) != -1 {
- deleteSlice(winners, k, "")
- }
- } else {
- if BinarySearch(winners, k) == -1 {
- winners = append(winners, k)
- }
- }
- }
- tmpPro["s_winner"] = strings.Join(winners, ",")
- }
- if thisinfo.HasPackage { //多包处理
- tmpPro["multipackage"] = 1
- pkg := PackageFormat(thisinfo, project)
- project.Package = pkg
- tmpPro["package"] = project.Package
- }
- //处理多包后,计算预算金额、中标金额
- //CountAmount(project, thisinfo, tmp)
- //if project.Budget >= 0 && project.Budgettag != 1 {
- // pInfo.Budget = project.Budget
- // tmpPro["budget"] = pInfo.Budget
- // tmpPro["budgettag"] = 0
- //}
- //if project.Bidamount >= 0 && project.Bidamounttag != 1 {
- // pInfo.Bidamount = project.Bidamount
- // tmpPro["bidamount"] = pInfo.Bidamount
- // tmpPro["bidamounttag"] = 0
- //}
- //if pInfo.Bidamount >= pInfo.Budget {
- // tmpPro["sortprice"] = pInfo.Bidamount
- //} else if pInfo.Budget >= pInfo.Bidamount {
- // tmpPro["sortprice"] = pInfo.Budget
- //}
- if thisinfo.Budget > 0 {
- pInfo.Budget = thisinfo.Budget
- project.Budget = thisinfo.Budget
- tmpPro["budget"] = thisinfo.Budget
- }
- if thisinfo.Bidamount > 0 {
- pInfo.Bidamount = thisinfo.Bidamount
- project.Bidamount = thisinfo.Bidamount
- tmpPro["bidamount"] = thisinfo.Bidamount
- }
- if pInfo.Bidamount > 0 {
- tmpPro["sortprice"] = pInfo.Bidamount
- } else {
- if pInfo.Budget > 0 {
- tmpPro["sortprice"] = pInfo.Budget
- }
- }
- //infofield := InfoField{
- // Budget: thisinfo.Budget,
- // Bidamount: thisinfo.Bidamount,
- // ContractCode: thisinfo.ContractCode,
- // ProjectName: thisinfo.ProjectName,
- // ProjectCode: thisinfo.ProjectCode,
- // Bidstatus: pInfo.Bidstatus,
- //}
- //copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
- //copyMap[thisinfo.Id] = infofield
- //tmpMap := make(map[string]interface{})
- //for k, v := range copyMap {
- // tmpMap[k] = StructToMap(v)
- //}
- //tmpMap[thisinfo.Id] = StructToMap(infofield)
- //project.InfoFiled = copyMap
- //tmpPro["infofield"] = tmpMap
- tmpPro["mpn"] = pInfo.MPN
- tmpPro["mpc"] = pInfo.MPC
- tmpPro["updatetime"] = p.pici
- push := p.PushListInfo(tmp, thisinfo.Id)
- push["s_winner"] = strings.Join(thisinfo.Winners, ",")
- push["compareStr"] = m1["compareStr"]
- push["resVal"] = m1["resVal"]
- push["pjVal"] = m1["pjVal"]
- list := tmpPro["list"].([]map[string]interface{})
- tmpPro["list"] = append(list, push)
- tmpPro["ids"] = append(tmpPro["ids"].([]string), thisinfo.Id)
- }
- func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
- for k, v1 := range arr {
- if reflect.DeepEqual(v1, v) {
- return append(arr[:k], arr[k+1:]...)
- }
- }
- return arr
- }
- // 修改字段值
- func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
- updataSet := make(map[string]interface{})
- infoList := proMap["list"].([]interface{})
- tempMap := infoList[position].(map[string]interface{})
- for k := range modifyMap {
- //项目中lsit大小等于1 或者 修改的招标公告处于项目的list中最后一个
- if len(infoList) == 1 || index == 2 {
- if k == "budget" || k == "bidamount" {
- if proMap["sortprice"] == proMap[k] {
- updataSet["sortprice"] = modifyMap[k]
- }
- updataSet[k] = modifyMap[k]
- proMap[k] = modifyMap[k]
- tempMap[k] = modifyMap[k]
- } else {
- updataSet[k] = modifyMap[k]
- proMap[k] = modifyMap[k]
- tempMap[k] = modifyMap[k]
- }
- } else {
- tempMap[k] = modifyMap[k]
- if k == "budget" || k == "bidamount" {
- if proMap["sortprice"] == proMap[k] {
- proMap["sortprice"] = modifyMap[k]
- }
- updataSet[k] = modifyMap[k]
- proMap[k] = modifyMap[k]
- }
- // 有条件更新项目外围字段值(非空)
- if proMap[k] == nil || util.ObjToString(k) == "" {
- updataSet[k] = modifyMap[k]
- proMap[k] = modifyMap[k]
- }
- }
- }
- return updataSet
- }
- // 备份(快照)
- func backupPro(tmp map[string]interface{}) {
- tmp1 := make(map[string]interface{})
- for k, v := range tmp {
- tmp1[k] = v
- }
- if config.Conf.Serve.BackupFlag {
- tmp1["sourceprojectid"] = mongodb.BsonIdToSId(tmp1["_id"])
- delete(tmp1, "_id")
- MgoP.Save(BackupColl, tmp1)
- }
- }
- // 删除原有项目数据
- func delOldPro(pid string) {
- t := MgoP.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
- if t >= 0 {
- Es.DelById(config.Conf.DB.Es.Index, pid)
- }
- }
- // 修改内存中的数据
- func (p *ProjectTask) modifyMem(tmpPro map[string]interface{}) {
- pid := util.ObjToString(tmpPro["_id"])
- var pro ProjectCache
- err := mapstructure.Decode(tmpPro, &pro)
- if err != nil {
- log.Info(err.Error())
- }
- pro.Id = mongodb.StringTOBsonId(pid)
- tmpMap := make(map[string]InfoField)
- infoMap := tmpPro["infofield"].(map[string]interface{})
- for _, v := range infoMap {
- var field InfoField
- b, _ := json.Marshal(v)
- _ = json.Unmarshal(b, &field)
- tmpMap[pid] = field
- }
- p.AllIdsMapLock.Lock()
- if v, ok := p.AllIdsMap[pid]; ok {
- v.P = &pro
- }
- p.AllIdsMapLock.Unlock()
- p.printMemPro(pid)
- }
- // 打印内存中的项目信息
- func (p *ProjectTask) printMemPro(pid string) {
- p.AllIdsMapLock.Lock()
- if v, ok := p.AllIdsMap[pid]; ok {
- log.Info("mem pro ----------", zap.Any("pro", *v.P))
- }
- p.AllIdsMapLock.Unlock()
- }
- // @Description id不变,内容变化 重新进行项目合并
- // @Author J 2022/8/10 14:51
- func (p *ProjectTask) taskinfo(id string) {
- tmpPro, _ := MgoP.FindOneByField(ProjectColl, map[string]interface{}{"ids": id}, nil)
- if tmpPro == nil || len(*tmpPro) == 0 {
- log.Info(fmt.Sprintf("taskinfo bidding id=%s 未查询到项目数据", id))
- return
- }
- pid := mongodb.BsonIdToSId((*tmpPro)["_id"])
- ids := util.ObjArrToStringArr((*tmpPro)["ids"].([]interface{}))
- list := (*tmpPro)["list"].([]interface{})
- var newP map[string]interface{}
- var p1 *ProjectCache
- for i, s := range ids {
- temp, _ := MgoB.FindById(BiddingColl, s, nil)
- if temp == nil || len(*temp) == 0 {
- temp, _ = MgoB.FindById("bidding_back", s, nil)
- if temp == nil || len(*temp) == 0 {
- log.Info("extract not find id..." + s)
- return
- }
- }
- push := p.PushListInfo(*temp, id)
- if s == id {
- list[i] = push
- }
- info := ParseInfo(*temp)
- if i == 0 {
- newP, p1 = p.createPro(*temp, info, pid)
- } else {
- p.updatePro(newP, *temp, p1, info)
- }
- }
- newP["ids"] = ids
- newP["pici"] = p.pici
- p.AllIdsMapLock.Lock()
- _, ok := p.AllIdsMap[pid]
- if ok {
- redis.PutCKV("project", pid, newP)
- p.AllIdsMap[id] = &ID{Id: id, P: p1}
- }
- p.AllIdsMapLock.Unlock()
- newP["list"] = list
- if len(newP) > 0 {
- updateInfo := []map[string]interface{}{
- {
- "_id": mongodb.StringTOBsonId(pid),
- },
- {"$set": newP},
- }
- p.updatePool <- updateInfo
- }
- }
- // @Description 创建项目
- // @Author J 2022/8/11 09:17
- func (p *ProjectTask) createPro(tmp map[string]interface{}, thisinfo *Info, pid string) (map[string]interface{}, *ProjectCache) {
- set := map[string]interface{}{}
- set["_id"] = mongodb.StringTOBsonId(pid)
- for _, f := range FIELDS {
- if tmp[f] != nil && tmp[f] != "" {
- set[f] = tmp[f]
- }
- }
- bidopentime := util.Int64All(tmp["bidopentime"])
- if bidopentime > 0 {
- set["bidopentime"] = bidopentime
- }
- //异常标记
- if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
- set["exception"] = 1
- }
- //projecthref保存
- if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
- if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
- set["projecthref"] = jsonData["projecthref"]
- }
- }
- //合同编号
- if thisinfo.ContractCode != "" {
- set["contractcode"] = thisinfo.ContractCode
- }
- bt := util.ObjToString(tmp["toptype"])
- bs := util.ObjToString(tmp["subtype"])
- p.mapBidLock.Lock()
- if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
- set["bidstatus"] = "拟建"
- bt = "拟建"
- } else {
- if bidtype[bs] != "" {
- set["bidtype"] = bidtype[bs]
- } else {
- set["bidtype"] = "招标"
- }
- if bt == "招标" {
- set["projectscope"] = util.ObjToString(tmp["projectscope"])
- set["bidstatus"] = bt
- } else {
- if bidstatus[bs] != "" {
- set["bidstatus"] = thisinfo.SubType
- bt = thisinfo.SubType
- } else if bs == "" {
- set["bidstatus"] = ""
- bt = ""
- } else {
- set["bidstatus"] = "其它"
- bt = "其它"
- }
- }
- }
- p.mapBidLock.Unlock()
- pkg := PackageFormat(thisinfo, nil)
- p1 := p.NewCachePinfo(mongodb.StringTOBsonId(pid), thisinfo, bs, bt)
- now := time.Now().Unix()
- set["createtime"] = now
- set["sourceinfoid"] = thisinfo.Id
- set["sourceinfourl"] = tmp["href"]
- set["firsttime"] = tmp["publishtime"]
- set["lasttime"] = tmp["publishtime"]
- //增量用系统时间,全量(历史)入库时间
- if p.currentType == "pl" {
- set["pici"] = tmp["comeintime"]
- } else {
- set["pici"] = p.pici
- }
- set["ids"] = []string{thisinfo.Id}
- if thisinfo.TopType == "招标" {
- //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
- set["zbtime"] = tmp["publishtime"]
- //}
- } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
- set["jgtime"] = tmp["publishtime"]
- }
- if len(thisinfo.Subscopeclass) > 0 {
- set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
- }
- if len(thisinfo.Winners) > 0 {
- set["s_winner"] = strings.Join(thisinfo.Winners, ",")
- }
- if thisinfo.HasPackage {
- set["multipackage"] = 1
- set["package"] = pkg
- } else {
- set["multipackage"] = 0
- }
- //项目评审专家
- if len(thisinfo.ReviewExperts) > 0 {
- set["review_experts"] = thisinfo.ReviewExperts
- }
- //标的物
- if thisinfo.Purchasing != "" {
- list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
- p := strings.Join(util.ObjArrToStringArr(list), ",")
- set["purchasing"] = p
- }
- //中标候选人
- if len(thisinfo.WinnerOrder) > 0 {
- var list = []string{}
- for _, v := range thisinfo.WinnerOrder {
- if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
- list = append(list, util.ObjToString(v["entname"]))
- }
- }
- set["winnerorder"] = list
- }
- //项目规模
- if len(thisinfo.ProjectScale) > 0 {
- set["project_scale"] = thisinfo.ProjectScale
- }
- //工期时长
- if thisinfo.ProjectDuration > 0 {
- set["project_duration"] = thisinfo.ProjectDuration
- }
- // 工期单位
- if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
- set["project_timeunit"] = thisinfo.ProjectTimeUnit
- }
- //开工日期
- if thisinfo.ProjectStartDate > 0 {
- set["project_startdate"] = thisinfo.ProjectStartDate
- }
- //竣工日期
- if thisinfo.ProjectCompleteDate > 0 {
- set["project_completedate"] = thisinfo.ProjectCompleteDate
- }
- //付款方式
- if len(thisinfo.Payway) > 0 {
- set["payway"] = thisinfo.Payway
- }
- // 履约保证金
- if tmp["contract_guarantee"] != nil {
- set["contract_guarantee"] = thisinfo.ContractGuarantee
- }
- // 投标保证金
- if tmp["bid_guarantee"] != nil {
- set["bid_guarantee"] = thisinfo.BidGuarantee
- }
- // 资质条件
- if len(thisinfo.Qualifies) > 0 {
- var str []string
- for _, v := range thisinfo.Qualifies {
- if len(util.ObjToString(v["key"])) > 0 {
- if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
- str = append(str, util.ObjToString(v["key"]))
- }
- }
- }
- if len(str) > 0 {
- set["qualifies"] = strings.Join(str, ",")
- }
- }
- if len(thisinfo.EntIdList) > 0 {
- set["entidlist"] = thisinfo.EntIdList
- }
- // first_cooperation
- if p1.Buyer != "" && len(thisinfo.Winners) > 0 {
- FirstCooperation(set, p1.Buyer, thisinfo.Winners, thisinfo.EntIdList)
- }
- //infofield := InfoField{
- // Budget: thisinfo.Budget,
- // Bidamount: thisinfo.Bidamount,
- // ContractCode: thisinfo.ContractCode,
- // ProjectName: thisinfo.ProjectName,
- // ProjectCode: thisinfo.ProjectCode,
- // Bidstatus: bs,
- //}
- //res := StructToMap(infofield)
- //set["infofield"] = map[string]interface{}{
- // thisinfo.Id: res,
- //}
- if tmp["budget"] != nil && tmp["budget"] != "" {
- set["budget"] = thisinfo.Budget
- set["budgettag"] = 0
- } else {
- set["budgettag"] = 1
- }
- if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
- set["bidamount"] = thisinfo.Bidamount
- set["bidamounttag"] = 0
- } else {
- set["bidamounttag"] = 1
- }
- if p1.Bidamount > 0 {
- set["sortprice"] = p1.Bidamount
- } else {
- if p1.Budget > 0 {
- set["sortprice"] = p1.Budget
- }
- }
- return set, &p1
- }
- // @Description id不变,内容覆盖 修改项目
- // @Author J 2022/8/10 17:00
- func (p *ProjectTask) updatePro(set, tmp map[string]interface{}, pInfo *ProjectCache, thisinfo *Info) {
- bys, _ := json.Marshal(set)
- var project *Project
- err := json.Unmarshal(bys, &project)
- if err != nil {
- log.Info("project Unmarshal err," + err.Error())
- return
- }
- //zbtime、lasttime、jgtime
- pInfo.LastTime = thisinfo.Publishtime
- set["lasttime"] = thisinfo.Publishtime
- if thisinfo.TopType == "招标" {
- if project.Zbtime <= 0 {
- project.Zbtime = thisinfo.Publishtime
- set["zbtime"] = tmp["publishtime"]
- }
- if project.Jgtime > 0 {
- project.Jgtime = int64(0)
- set["jgtime"] = int64(0)
- }
- } else if thisinfo.TopType == "结果" {
- if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
- if project.Jgtime > 0 {
- //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
- //公告状态和项目状态同样都是中标或者成交,
- if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
- if p.jgTime < thisinfo.Publishtime {
- project.Jgtime = thisinfo.Publishtime
- set["jgtime"] = tmp["publishtime"]
- }
- //公告状态和项目状态同样是流标或者废标
- } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
- if p.jgTime < thisinfo.Publishtime {
- project.Jgtime = thisinfo.Publishtime
- set["jgtime"] = tmp["publishtime"]
- }
- }
- } else {
- project.Jgtime = thisinfo.Publishtime
- set["jgtime"] = tmp["publishtime"]
- }
- }
- } else if thisinfo.SubType == "合同" {
- if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
- //中标、成交不更新jgtime
- } else {
- project.Jgtime = thisinfo.Publishtime
- set["jgtime"] = tmp["publishtime"]
- }
- }
- if thisinfo.BidOpenTime > project.BidOpenTime {
- project.BidOpenTime = thisinfo.BidOpenTime
- set["bidopentime"] = project.BidOpenTime
- }
- if thisinfo.BidEndTime > 0 {
- project.BidEndTime = thisinfo.BidEndTime
- set["bidendtime"] = project.BidEndTime
- }
- bt := util.ObjToString(tmp["toptype"])
- bs := util.ObjToString(tmp["subtype"])
- p.mapBidLock.Lock()
- if bt == "招标" {
- //招标状态,更新projectscope
- if tmp["projectscope"] != nil {
- set["projectscope"] = util.ObjToString(tmp["projectscope"])
- }
- set["bidstatus"] = bt
- project.Bidstatus = bt
- if bidtype[bs] != "" {
- set["bidtype"] = bidtype[bs]
- project.Bidtype = bidtype[bs]
- } else {
- set["bidtype"] = "招标"
- project.Bidtype = "招标"
- }
- } else {
- if bidstatus[bs] != "" {
- set["bidstatus"] = thisinfo.SubType
- project.Bidstatus = thisinfo.SubType
- } else if thisinfo.Infoformat == 2 {
- set["bidstatus"] = "拟建"
- project.Bidstatus = "拟建"
- } else if bs == "" && bt == "结果" {
- if project.Bidstatus == "招标" {
- set["bidstatus"] = ""
- project.Bidstatus = ""
- }
- } else {
- set["bidstatus"] = "其它"
- project.Bidstatus = "其它"
- }
- }
- p.mapBidLock.Unlock()
- //相同城市的公告才会合并到一起(全国列外)
- if thisinfo.Area != "全国" {
- pInfo.Area = thisinfo.Area
- project.Area = thisinfo.Area
- set["area"] = thisinfo.Area
- if thisinfo.City != "" {
- pInfo.City = thisinfo.City
- project.City = thisinfo.City
- set["city"] = thisinfo.City
- }
- if thisinfo.District != "" {
- pInfo.District = thisinfo.District
- project.District = thisinfo.District
- set["district"] = thisinfo.District
- }
- }
- //项目名称
- //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
- if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
- pInfo.ProjectName = thisinfo.ProjectName
- project.ProjectName = thisinfo.ProjectName
- set["projectname"] = thisinfo.ProjectName
- }
- //7--项目编号
- //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
- if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
- pInfo.ProjectCode = thisinfo.ProjectCode
- project.ProjectCode = thisinfo.ProjectCode
- set["projectcode"] = thisinfo.ProjectCode
- }
- //7--采购单位
- if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
- pInfo.Buyer = thisinfo.Buyer
- project.Buyer = thisinfo.Buyer
- set["buyer"] = thisinfo.Buyer
- project.Buyerclass = thisinfo.Buyerclass
- set["buyerclass"] = thisinfo.Buyerclass
- }
- if pInfo.Buyer == "" {
- project.Buyerclass = ""
- set["buyerclass"] = ""
- }
- //采购单位联系人
- if thisinfo.Buyerperson != "" {
- project.Buyerperson = thisinfo.Buyerperson
- set["buyerperson"] = thisinfo.Buyerperson
- } else {
- project.Buyerperson = ""
- set["buyerperson"] = ""
- }
- //采购单位電話
- if thisinfo.Buyertel != "" {
- project.Buyertel = thisinfo.Buyertel
- set["buyertel"] = project.Buyertel
- } else {
- project.Buyertel = ""
- set["buyertel"] = ""
- }
- if thisinfo.ContractCode != "" {
- if project.ContractCode == "" {
- set["contractcode"] = thisinfo.ContractCode
- } else {
- list := strings.Split(project.ContractCode, ",")
- if BinarySearch(list, thisinfo.ContractCode) == -1 {
- list = append(list, thisinfo.ContractCode)
- sort.Strings(list)
- }
- set["contractcode"] = strings.Join(list, ",")
- }
- }
- //8--代理机构
- if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
- pInfo.Agency = thisinfo.Agency
- project.Agency = thisinfo.Agency
- set["agency"] = thisinfo.Agency
- }
- if len(thisinfo.Topscopeclass) > 0 {
- sort.Strings(project.Topscopeclass)
- for _, k := range thisinfo.Topscopeclass {
- if BinarySearch(project.Topscopeclass, k) == -1 {
- project.Topscopeclass = append(project.Topscopeclass, k)
- sort.Strings(project.Topscopeclass)
- }
- }
- set["topscopeclass"] = project.Topscopeclass
- }
- //项目评审专家
- if len(thisinfo.ReviewExperts) > 0 {
- set["review_experts"] = thisinfo.ReviewExperts
- project.ReviewExperts = thisinfo.ReviewExperts
- }
- if thisinfo.Purchasing != "" {
- if project.Purchasing == "" {
- list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
- p := strings.Join(util.ObjArrToStringArr(list), ",")
- project.Purchasing = p
- set["purchasing"] = p
- } else {
- list := strings.Split(project.Purchasing, ",")
- list = util.ObjArrToStringArr(Duplicate(list))
- for _, k := range list {
- if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
- list = append(list, k)
- sort.Strings(list)
- }
- }
- set["purchasing"] = strings.Join(list, ",")
- }
- }
- //中标候选人
- if len(thisinfo.WinnerOrder) > 0 {
- var list = []string{}
- for _, v := range thisinfo.WinnerOrder {
- if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
- list = append(list, util.ObjToString(v["entname"]))
- }
- }
- set["winnerorder"] = list
- project.Winnerorder = list
- }
- if len(thisinfo.Subscopeclass) > 0 {
- sort.Strings(project.Subscopeclass)
- for _, k := range thisinfo.Subscopeclass {
- if BinarySearch(project.Subscopeclass, k) == -1 {
- project.Subscopeclass = append(project.Subscopeclass, k)
- sort.Strings(project.Subscopeclass)
- }
- }
- set["subscopeclass"] = project.Subscopeclass
- set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
- }
- if len(thisinfo.Winners) > 0 {
- if len(project.Winners) <= 0 {
- set["winner"] = util.ObjToString(tmp["winner"])
- }
- winners := strings.Split(project.Winners, ",")
- for _, k := range thisinfo.Winners {
- if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
- if BinarySearch(winners, k) != -1 {
- deleteSlice(winners, k, "")
- }
- } else {
- if BinarySearch(winners, k) == -1 {
- winners = append(winners, k)
- }
- }
- }
- set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
- }
- if len(thisinfo.EntIdList) > 0 {
- for _, v := range thisinfo.EntIdList {
- if BinarySearch(project.EntIdList, v) == -1 {
- project.EntIdList = append(project.EntIdList, v)
- }
- }
- set["entidlist"] = project.EntIdList
- }
- // first_cooperation
- if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
- FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
- }
- //项目规模
- if len(thisinfo.ProjectScale) > 0 {
- project.ProjectScale = thisinfo.ProjectScale
- set["project_scale"] = thisinfo.ProjectScale
- }
- //工期时长
- if thisinfo.ProjectDuration > 0 {
- project.ProjectDuration = thisinfo.ProjectDuration
- set["project_duration"] = thisinfo.ProjectDuration
- }
- // 工期单位
- if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
- project.ProjectTimeunit = thisinfo.ProjectTimeUnit
- set["project_timeunit"] = thisinfo.ProjectTimeUnit
- }
- //开工日期
- if thisinfo.ProjectStartDate > 0 {
- if project.ProjectStartDate > 0 {
- if project.ProjectStartDate < thisinfo.ProjectStartDate {
- project.ProjectStartDate = thisinfo.ProjectStartDate
- set["project_startdate"] = thisinfo.ProjectStartDate
- }
- } else {
- project.ProjectStartDate = thisinfo.ProjectStartDate
- set["project_startdate"] = thisinfo.ProjectStartDate
- }
- }
- //竣工日期
- if thisinfo.ProjectCompleteDate > 0 {
- if project.ProjctCompleteDate > 0 {
- if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
- project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
- set["project_completedate"] = thisinfo.ProjectCompleteDate
- }
- } else {
- project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
- set["project_completedate"] = thisinfo.ProjectCompleteDate
- }
- }
- // 付款方式
- if len(thisinfo.Payway) > 0 {
- project.Payway = thisinfo.Payway
- set["payway"] = thisinfo.Payway
- }
- // 履约保证金
- if tmp["contract_guarantee"] != nil {
- project.ContractGuarantee = thisinfo.ContractGuarantee
- set["contract_guarantee"] = thisinfo.ContractGuarantee
- }
- // 投标保证金
- if tmp["bid_guarantee"] != nil {
- project.BidGuarantee = thisinfo.BidGuarantee
- set["bid_guarantee"] = thisinfo.BidGuarantee
- }
- // 资质条件
- if len(thisinfo.Qualifies) > 0 {
- var str []string
- if len(project.Qualifies) > 0 {
- str = append(str, strings.Split(project.Qualifies, ",")...)
- }
- for _, v := range thisinfo.Qualifies {
- if len(util.ObjToString(v["key"])) > 0 {
- if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
- str = append(str, util.ObjToString(v["key"]))
- }
- }
- }
- if len(str) > 0 {
- project.Qualifies = strings.Join(str, ",")
- set["qualifies"] = strings.Join(str, ",")
- }
- }
- if thisinfo.HasPackage { //多包处理
- set["multipackage"] = 1
- pkg := PackageFormat(thisinfo, project)
- project.Package = pkg
- set["package"] = project.Package
- }
- //处理多包后,计算预算金额、中标金额
- //CountAmount(project, thisinfo, tmp)
- //if project.Budget >= 0 && project.Budgettag != 1 {
- // pInfo.Budget = project.Budget
- // set["budget"] = project.Budget
- // set["budgettag"] = 0
- //}
- //if project.Bidamount >= 0 && project.Bidamounttag != 1 {
- // pInfo.Bidamount = project.Bidamount
- // set["bidamount"] = pInfo.Bidamount
- // set["bidamounttag"] = 0
- //}
- //if pInfo.Bidamount > 0 {
- // set["sortprice"] = pInfo.Bidamount
- //} else {
- // if pInfo.Budget > 0 {
- // set["sortprice"] = pInfo.Budget
- // }
- //}
- if thisinfo.Budget > 0 {
- pInfo.Budget = thisinfo.Budget
- project.Budget = thisinfo.Budget
- set["budget"] = thisinfo.Budget
- }
- if thisinfo.Bidamount > 0 {
- pInfo.Bidamount = thisinfo.Bidamount
- project.Bidamount = thisinfo.Bidamount
- set["bidamount"] = thisinfo.Bidamount
- }
- if pInfo.Bidamount > 0 {
- set["sortprice"] = pInfo.Bidamount
- } else {
- if pInfo.Budget > 0 {
- set["sortprice"] = pInfo.Budget
- }
- }
- //infofield := InfoField{
- // Budget: thisinfo.Budget,
- // Bidamount: thisinfo.Bidamount,
- // ContractCode: thisinfo.ContractCode,
- // ProjectName: thisinfo.ProjectName,
- // ProjectCode: thisinfo.ProjectCode,
- // Bidstatus: bs,
- //}
- //tmpMap := set["infofield"].(map[string]interface{})
- //tmpMap[thisinfo.Id] = StructToMap(infofield)
- //set["infofield"] = tmpMap
- //copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
- //copyMap[thisinfo.Id] = infofield
- //project.InfoFiled = copyMap
- set["mpn"] = pInfo.MPN
- set["mpc"] = pInfo.MPC
- }
|