classificationTag.go 14 KB

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