classificationTag.go 14 KB

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