classificationTag.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. package front
  2. import (
  3. qu "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. elastic "app.yhyue.com/moapp/jybase/es"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/bidsearch"
  8. "app.yhyue.com/moapp/jypkg/public"
  9. "encoding/json"
  10. "fmt"
  11. "jy/src/jfw/config"
  12. "log"
  13. "strconv"
  14. "sync"
  15. "time"
  16. "net/http"
  17. "app.yhyue.com/moapp/jybase/date"
  18. "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
  19. )
  20. const (
  21. //企业主体库身份类型区分 sql传值
  22. IdentityTypeBuyer = 0 // 采购单位
  23. IdentityTypeWinner = 1 // 中标单位
  24. )
  25. type KeyType struct {
  26. Name string `json:"name"`
  27. Url string `json:"url"`
  28. SeedData []KeyType `json:"seedData"`
  29. }
  30. // RegionAndInformationAndTender 1地域 2信息类型 3热门招标
  31. func RegionAndInformationAndTender() map[string]interface{} {
  32. if bytes, err := redis.GetBytes(RedisNameNew, "regionAndInformationAndTender"); err == nil && bytes != nil {
  33. rData := map[string]interface{}{}
  34. if err := json.Unmarshal(*bytes, &rData); err != nil {
  35. log.Printf("[MANAGER-ERR]RegionAndInformationAndTender GetData Error %v \n", err)
  36. return nil
  37. }
  38. return rData
  39. }
  40. data := make(map[string]interface{})
  41. for _, v := range []int{1, 2, 3} {
  42. data[fmt.Sprintf("labUrl_%d", v)] = GetLabUrl(v) //1地域 2信息类型 3热门招标
  43. }
  44. if bytes, err := json.Marshal(data); err == nil && bytes != nil {
  45. _ = redis.PutBytes(RedisNameNew, "regionAndInformationAndTender", &bytes, 2*60*60)
  46. }
  47. return data
  48. }
  49. // 最新更新的200中标企业
  50. func GetWinnerInfo() (data []*BuyerList) {
  51. // 取缓存
  52. cache, err := GetHotCache(config.HotWinnerConfig.CacheKey)
  53. if err == nil && cache != nil && len(cache) > 0 {
  54. return cache
  55. }
  56. // 没取到缓存查数据
  57. //rs := getEntBaseInfo(IdentityTypeWinner, config.HotWinnerConfig.Limit)
  58. rs := GetSeoId(IdentityTypeWinner, config.HotWinnerConfig.Limit)
  59. //关联中标企业
  60. if rs == nil || len(*rs) == 0 {
  61. return
  62. }
  63. for _, v := range *rs {
  64. var vs BuyerList
  65. id := qu.InterfaceToStr(v["nseo_id"])
  66. vs.Name = qu.InterfaceToStr(v["name"])
  67. vs.Url = fmt.Sprintf("/qy/%s.html", id)
  68. data = append(data, &vs)
  69. }
  70. // 存缓存
  71. go PutHotCache(config.HotWinnerConfig.CacheKey, config.HotWinnerConfig.CacheTimeout, data)
  72. return
  73. }
  74. // PutHotCache 热门采购单位、中标单位存缓存
  75. func PutHotCache(redisKey string, redisTimeout int, list []*BuyerList) {
  76. b, err := json.Marshal(list)
  77. if err != nil {
  78. log.Printf("保存缓存 序列化异常,data:%s,err:%s\n", list, err.Error())
  79. return
  80. }
  81. if err = redis.PutBytes("seoCache", redisKey, &b, redisTimeout); err != nil {
  82. log.Printf("保存缓存 redis 异常,key:%s,err:%s\n", redisKey, err.Error())
  83. }
  84. }
  85. // GetHotCache 热门采购单位、中标单位取缓存
  86. func GetHotCache(redisKey string) (list []*BuyerList, err error) {
  87. redisByte, err := redis.GetBytes("seoCache", redisKey)
  88. if err != nil || redisByte == nil || len(*redisByte) == 0 {
  89. return list, err
  90. }
  91. err = json.Unmarshal(*redisByte, &list)
  92. if err != nil {
  93. log.Println(fmt.Sprintf("读取缓存 序列化异常,err:%s", err.Error()))
  94. return nil, err
  95. }
  96. return list, nil
  97. }
  98. // 获取最新的中标单位
  99. // identityType : 0 采购单位 1-中标单位
  100. // limit: 数量
  101. func getEntBaseInfo(identityType, limit int) *[]map[string]interface{} {
  102. q := "SELECT company_id AS id,name,name_id FROM dws_f_ent_baseinfo WHERE company_id !='' and company_id is not null AND (identity_type &(1 << ?)) > 0 order by latest_time desc limit ?"
  103. return public.GlobalCommonMysql.SelectBySql(q, identityType, limit)
  104. }
  105. func GetSeoId(identityType, limit int) *[]map[string]interface{} {
  106. index := qu.If(identityType != 0, "qyxy", "buyer").(string)
  107. seo := qu.If(identityType != 0, "nseo_id", "seo_id").(string)
  108. q := fmt.Sprintf(`{"query": {"bool": {}},"sort": {"updatetime": "desc"},"from": 0,"size": %d,"_source": ["name","%s"]}`, limit, seo)
  109. return elastic.Get(index, index, q)
  110. }
  111. // ContentRecommendation 实用内容推荐
  112. func ContentRecommendation() []KeyType {
  113. if bytes, err := redis.GetBytes(RedisNameNew, "contentRecommendation"); err == nil && bytes != nil {
  114. var rData []KeyType
  115. log.Println()
  116. if err := json.Unmarshal(*bytes, &rData); err != nil {
  117. log.Printf("[MANAGER-ERR]contentRecommendation GetData Error %v \n", err)
  118. return nil
  119. }
  120. return rData
  121. }
  122. columnCode, _ := config.Sysconfig["columnCode"].(map[string]interface{})
  123. jySchoolCode := qu.InterfaceToStr(columnCode["招投标攻略"])
  124. industryInfoCode := qu.InterfaceToStr(columnCode["行业资讯"])
  125. industryInfoUrl, _ := config.Sysconfig["industryInfoUrl"].(map[string]interface{})
  126. jySchoolUrl, _ := config.Sysconfig["jySchoolUrl"].(map[string]interface{})
  127. column, ok := mongodb.Find("column", map[string]interface{}{"$or": []map[string]interface{}{
  128. {"pid": "ztbgl"}, {"pid": "hyzx"}, {"pid": "bzzx"},
  129. }}, `{"i_order":1}`, "", false, -1, -1)
  130. dataMap := make(map[string][]KeyType)
  131. if ok && column != nil && len(*column) > 0 {
  132. for _, v := range *column {
  133. pid := qu.InterfaceToStr(v["pid"])
  134. code := qu.InterfaceToStr(v["s_columncode"])
  135. var v1 KeyType
  136. v1.Name = qu.InterfaceToStr(v["s_columnname"])
  137. if pid == jySchoolCode {
  138. v1.Url = fmt.Sprintf(qu.InterfaceToStr(jySchoolUrl["towUrl"]), code)
  139. } else if pid == industryInfoCode {
  140. v1.Url = fmt.Sprintf(qu.InterfaceToStr(industryInfoUrl["towUrl"]), code)
  141. } else if pid == "bzzx" {
  142. v1.Url = fmt.Sprintf("/helpCenter/catalog/%s", code)
  143. }
  144. dataMap[pid] = append(dataMap[pid], v1)
  145. }
  146. }
  147. var data []KeyType
  148. for _, v := range []string{jySchoolCode, industryInfoCode, "bzzx"} {
  149. if v1, ok1 := dataMap[v]; ok1 && v1 != nil {
  150. var d KeyType
  151. switch v {
  152. case jySchoolCode:
  153. d.Name = "招投标攻略"
  154. d.Url = qu.InterfaceToStr(jySchoolUrl["homeUrl"])
  155. d.SeedData = v1
  156. case industryInfoCode:
  157. d.Name = "行业资讯"
  158. d.Url = qu.InterfaceToStr(industryInfoUrl["homeUrl"])
  159. d.SeedData = v1
  160. case "bzzx":
  161. d.Name = "帮助中心"
  162. d.Url = "/helpCenter/index"
  163. d.SeedData = v1
  164. }
  165. data = append(data, d)
  166. }
  167. }
  168. if bytes, err := json.Marshal(data); err == nil && bytes != nil {
  169. _ = redis.PutBytes(RedisNameNew, "contentRecommendation", &bytes, 12*60*60)
  170. }
  171. return data
  172. }
  173. type Signal struct {
  174. Name string `json:"name"`
  175. Url string `json:"url"`
  176. UnLoginUrl string `json:"unLoginUrl"`
  177. Data []map[string]interface{} `json:"data"`
  178. }
  179. // 推荐标讯
  180. func RecommendationBeacon() []Signal {
  181. if bytes, err := redis.GetBytes(RedisNameNew, "recommendationBeacon"); err == nil && bytes != nil {
  182. var rData []Signal
  183. if err := json.Unmarshal(*bytes, &rData); err != nil {
  184. log.Printf("[MANAGER-ERR]recommendationBeacon GetData Error %v \n", err)
  185. return nil
  186. }
  187. return rData
  188. }
  189. sy := sync.RWMutex{}
  190. wg := sync.WaitGroup{}
  191. var data, dataArr []Signal
  192. infoType := qu.ObjToMap(config.Seoconfig["infoTypeToLetter"])
  193. for _, v := range []string{"招标预告", "招标公告", "招标结果", "招标信用信息"} {
  194. wg.Add(1)
  195. go func(vst string) {
  196. defer wg.Done()
  197. var list []map[string]interface{}
  198. _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", vst, "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 8, "")
  199. if lists != nil {
  200. for _, v1 := range *lists {
  201. v1["_id"] = encrypt.CommonEncodeArticle("content", v1["_id"].(string))
  202. delete(v1, "toptype")
  203. delete(v1, "s_subscopeclass")
  204. tmpdate := v1["publishtime"]
  205. v1["publishtime"] = qu.Int64All(tmpdate.(float64))
  206. if v1["budget"] != nil {
  207. v1["budget"] = ConversionMoeny(v1["budget"])
  208. } else if v1["bidamount"] != nil {
  209. v1["budget"] = ConversionMoeny(v1["bidamount"])
  210. }
  211. }
  212. list = *lists
  213. }
  214. var d Signal
  215. d.Name = vst
  216. d.UnLoginUrl = fmt.Sprintf("/list/stype/%s.html", (*infoType)[vst])
  217. d.Url = fmt.Sprintf("/jylab/supsearch/index.html?subtype=%s", vst)
  218. d.Data = list
  219. sy.Lock()
  220. dataArr = append(dataArr, d)
  221. sy.Unlock()
  222. }(v)
  223. }
  224. wg.Wait()
  225. for _, v := range []string{"招标预告", "招标公告", "招标结果", "招标信用信息"} {
  226. for _, v1 := range dataArr {
  227. if v == v1.Name {
  228. data = append(data, v1)
  229. }
  230. }
  231. }
  232. if bytes, err := json.Marshal(data); err == nil && bytes != nil {
  233. _ = redis.PutBytes(RedisNameNew, "recommendationBeacon", &bytes, 5*60)
  234. }
  235. return data
  236. }
  237. type BuyerList struct {
  238. Name string `json:"name"`
  239. Url string `json:"url"`
  240. }
  241. // 热门采购单位
  242. func HotBuyerList() []*BuyerList {
  243. // 取缓存
  244. cache, err := GetHotCache(config.HotBuyerConfig.CacheKey)
  245. if err == nil && cache != nil && len(cache) > 0 {
  246. return cache
  247. }
  248. // 查数据
  249. //data := getEntBaseInfo(IdentityTypeBuyer, config.HotBuyerConfig.Limit)
  250. data := GetSeoId(IdentityTypeBuyer, config.HotBuyerConfig.Limit)
  251. if data == nil || len(*data) == 0 {
  252. return nil
  253. }
  254. var buyerList []*BuyerList
  255. for _, b := range *data {
  256. name := qu.ObjToString(b["name"])
  257. buyerId := qu.InterfaceToStr(b["seo_id"])
  258. if name != "" && buyerId != "" {
  259. //idEncode := encrypt.EncodeArticleId2ByCheck(buyerId)
  260. buyerList = append(buyerList, &BuyerList{
  261. Name: name,
  262. //Url: qu.If(entIsNew, fmt.Sprintf("/entpc/unit_portrayal_id/%s", idEncode), fmt.Sprintf("/swordfish/page_big_pc/unit_portrayal_id/%s", idEncode)).(string),
  263. Url: fmt.Sprintf("/dw/%s.html", buyerId),
  264. })
  265. }
  266. }
  267. //存缓存
  268. go PutHotCache(config.HotBuyerConfig.CacheKey, config.HotBuyerConfig.CacheTimeout, buyerList)
  269. return buyerList
  270. }
  271. func GetIncludedInfo() map[string]interface{} {
  272. if bytes, err := redis.GetBytes(RedisNameNew, "jyIncludedInfo"); err == nil && bytes != nil {
  273. rData := map[string]interface{}{}
  274. if err := json.Unmarshal(*bytes, &rData); err != nil {
  275. log.Printf("[MANAGER-ERR]jyIncludedInfo GetData Error %v \n", err)
  276. return nil
  277. }
  278. return rData
  279. }
  280. data := public.BaseMysql.SelectBySql(`select bid,project,ent,buyer,bid_day_update,bid_field,field_accuracy,create_time from included_info order by create_time desc limit 1`)
  281. if data == nil || len(*data) <= 0 {
  282. return nil
  283. }
  284. info := (*data)[0]
  285. //招标信息的数值
  286. bid := qu.Int64All(info["bid"])
  287. Bid, BidUnit := formdataNum(bid)
  288. //招标采购项目的数值
  289. project := qu.Int64All(info["project"])
  290. Project, ProjectUnit := formdataNum(project)
  291. //企业数据库的数值
  292. ent := qu.Int64All(info["ent"])
  293. Ent, EntUnit := formdataNum(ent)
  294. //采购单位库的数值
  295. buyer := qu.Int64All(info["buyer"])
  296. Buyer, BuyerUnit := formdataNum(buyer)
  297. //每日更新招标信息的数值
  298. bid_day_update := qu.Int64All(info["bid_day_update"])
  299. BidDayUpdate, BidDayUpdateUnit := formdataNum(bid_day_update)
  300. mdata, ok := public.MQFW.Find("swordfish_index", map[string]interface{}{
  301. "i_push": map[string]interface{}{
  302. "$exists": true,
  303. },
  304. }, `{"_id":-1}`, `{"i_push":1}`, false, 0, 1)
  305. i_push := 0
  306. if mdata != nil && ok && len(*mdata) > 0 {
  307. swordData := (*mdata)[0]
  308. i_push = qu.IntAll(swordData["i_push"])
  309. }
  310. Push, PushUnit := formdataNum(int64(i_push))
  311. m := map[string]interface{}{
  312. "bid": Bid,
  313. "bidUnit": BidUnit,
  314. "project": Project,
  315. "projectUnit": ProjectUnit,
  316. "ent": Ent,
  317. "entUnit": EntUnit,
  318. "buyer": Buyer,
  319. "buyerUnit": BuyerUnit,
  320. "bidDayUpdate": BidDayUpdate,
  321. "bidDayUpdateUnit": BidDayUpdateUnit,
  322. "push": Push,
  323. "pushUnit": PushUnit,
  324. }
  325. if bytes, err := json.Marshal(m); err == nil && bytes != nil {
  326. _ = redis.PutBytes(RedisNameNew, "jyIncludedInfo", &bytes, 2*60*60)
  327. }
  328. return m
  329. }
  330. func NewIndexbids(session *httpsession.Session, r *http.Request) []map[string]interface{} {
  331. if bytes, err := redis.GetBytes(RedisNameNew, "jyNewIndexbids"); err == nil && bytes != nil {
  332. rData := []map[string]interface{}{}
  333. if err := json.Unmarshal(*bytes, &rData); err != nil {
  334. log.Printf("[MANAGER-ERR]jyNewIndexbids GetData Error %v \n", err)
  335. return rData
  336. }
  337. return rData
  338. }
  339. /*
  340. userInfo := jy.GetVipState(session, *config.Middleground, "")
  341. so := NewSearchOptimize("", "", "", "", "招标预告,招标公告,招标结果,招标信用信息", "", "", "title", "", "", "", "", "", "", "", "", "", "PC", "", 0, 50, 0, 0, 0, *userInfo, true, r)
  342. so.DefaultSearchParamsAuto()
  343. //缓存数据
  344. _, total, _ := so.GetBidSearchList(true)
  345. data.Count = total
  346. */
  347. // p397 收回查看拟建权限
  348. _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", "招标预告,招标公告,招标结果,招标信用信息", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 10, "")
  349. if lists != nil {
  350. for _, v1 := range *lists {
  351. v1["_id"] = encrypt.CommonEncodeArticle("content", v1["_id"].(string))
  352. delete(v1, "toptype")
  353. delete(v1, "s_subscopeclass")
  354. tmpdate := v1["publishtime"]
  355. v1["publishtime"] = time.Unix(qu.Int64All(tmpdate.(float64)), 0).Format(date.Date_Short_Layout)
  356. if v1["budget"] != nil {
  357. v1["budget"] = ConversionMoeny(v1["budget"])
  358. } else if v1["bidamount"] != nil {
  359. v1["budget"] = ConversionMoeny(v1["bidamount"])
  360. }
  361. }
  362. if bytes, err := json.Marshal(*lists); err == nil && bytes != nil {
  363. _ = redis.PutBytes(RedisNameNew, "jyNewIndexbids", &bytes, 5*60)
  364. }
  365. return *lists
  366. }
  367. return nil
  368. }
  369. // 格式输出数据
  370. // 亿亿、万亿、亿、万 只有一位的时候保留1位小数点 两位及以上不保留 1.1亿 11亿
  371. func formdataNum(num int64) (floatNum float64, unit string) {
  372. s_num := strconv.Itoa(int(num))
  373. len_m := len(s_num)
  374. m := ""
  375. indexArr := []int{17, 13, 9, 5}
  376. unitArr := []string{"亿亿", "万亿", "亿", "万"}
  377. for k, v := range indexArr {
  378. if len_m > v {
  379. if qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)]) >= 5 {
  380. if qu.IntAll(s_num[0:len_m-(v-1)])+1 == 10 {
  381. //满10 进 1
  382. m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)])
  383. m = strconv.Itoa(m1 + 1)
  384. } else {
  385. //满 万 进1 单位
  386. if qu.IntAll(s_num[0:len_m-(v-1)])+1 == 10000 {
  387. m = "1"
  388. unit = unitArr[k-1]
  389. } else {
  390. m = strconv.Itoa(qu.IntAll(s_num[0:len_m-(v-1)]) + 1)
  391. }
  392. }
  393. // log.Println("m1:", m)
  394. } else {
  395. m = s_num[0 : len_m-(v-1)]
  396. // log.Println("m2:", m)
  397. }
  398. } else if len_m == v { //
  399. if qu.IntAll(s_num[len_m-(v-2):len_m-(v-3)]) >= 5 {
  400. m = s_num[0 : len_m-(v-1)]
  401. //满10 进 1
  402. if qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1 == 10 {
  403. m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)])
  404. m = strconv.Itoa(m1 + 1)
  405. } else {
  406. m += "." + strconv.Itoa(qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1)
  407. }
  408. // log.Println("m3:", m)
  409. } else {
  410. m = s_num[0 : len_m-(v-1)]
  411. m += "." + s_num[len_m-(v-1):len_m-(v-2)]
  412. // log.Println("m4:", m)
  413. }
  414. }
  415. if m != "" {
  416. if unit == "" {
  417. unit = unitArr[k]
  418. }
  419. break
  420. }
  421. }
  422. if m == "" {
  423. m = s_num
  424. }
  425. //string 转float
  426. floatNum, _ = strconv.ParseFloat(m, 64)
  427. return floatNum, unit
  428. }