classificationTag.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. infoType := qu.ObjToMap(config.Seoconfig["infoTypeToLetter"])
  191. for _, v := range []string{"招标预告", "招标公告", "招标结果", "招标信用信息"} {
  192. wg.Add(1)
  193. go func(vst string) {
  194. defer wg.Done()
  195. var list []map[string]interface{}
  196. _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", vst, "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 8, "")
  197. if lists != nil {
  198. for _, v1 := range *lists {
  199. v1["_id"] = encrypt.CommonEncodeArticle("content", v1["_id"].(string))
  200. delete(v1, "toptype")
  201. delete(v1, "s_subscopeclass")
  202. tmpdate := v1["publishtime"]
  203. v1["publishtime"] = qu.Int64All(tmpdate.(float64))
  204. if v1["budget"] != nil {
  205. v1["budget"] = ConversionMoeny(v1["budget"])
  206. } else if v1["bidamount"] != nil {
  207. v1["budget"] = ConversionMoeny(v1["bidamount"])
  208. }
  209. }
  210. list = *lists
  211. }
  212. var d Signal
  213. d.Name = vst
  214. d.Url = fmt.Sprintf("/list/stype/%s.html", (*infoType)[vst])
  215. d.Data = list
  216. sy.Lock()
  217. dataArr = append(dataArr, d)
  218. sy.Unlock()
  219. }(v)
  220. }
  221. wg.Wait()
  222. for _, v := range []string{"招标预告", "招标公告", "招标结果", "招标信用信息"} {
  223. for _, v1 := range dataArr {
  224. if v == v1.Name {
  225. data = append(data, v1)
  226. }
  227. }
  228. }
  229. if bytes, err := json.Marshal(data); err == nil && bytes != nil {
  230. _ = redis.PutBytes(RedisNameNew, "recommendationBeacon", &bytes, 5*60)
  231. }
  232. return data
  233. }
  234. type BuyerList struct {
  235. Name string `json:"name"`
  236. Url string `json:"url"`
  237. }
  238. // 热门采购单位
  239. func HotBuyerList(entIsNew bool) []*BuyerList {
  240. // 取缓存
  241. cache, err := GetHotCache(config.HotBuyerConfig.CacheKey)
  242. if err == nil && cache != nil && len(cache) > 0 {
  243. return cache
  244. }
  245. // 查数据
  246. data := getEntBaseInfo(IdentityTypeBuyer, config.HotBuyerConfig.Limit)
  247. if data == nil || len(*data) == 0 {
  248. return nil
  249. }
  250. var buyerList []*BuyerList
  251. for _, b := range *data {
  252. name := qu.ObjToString(b["name"])
  253. buyerId := qu.ObjToString(b["name_id"])
  254. if name != "" && buyerId != "" {
  255. idEncode := encrypt.EncodeArticleId2ByCheck(buyerId)
  256. buyerList = append(buyerList, &BuyerList{
  257. Name: name,
  258. Url: qu.If(entIsNew, fmt.Sprintf("/entpc/unit_portrayal_id/%s", idEncode), fmt.Sprintf("/swordfish/page_big_pc/unit_portrayal_id/%s", idEncode)).(string),
  259. })
  260. }
  261. }
  262. //存缓存
  263. go PutHotCache(config.HotBuyerConfig.CacheKey, config.HotBuyerConfig.CacheTimeout, buyerList)
  264. return buyerList
  265. }
  266. func GetIncludedInfo() map[string]interface{} {
  267. if bytes, err := redis.GetBytes(RedisNameNew, "jyIncludedInfo"); err == nil && bytes != nil {
  268. rData := map[string]interface{}{}
  269. if err := json.Unmarshal(*bytes, &rData); err != nil {
  270. log.Printf("[MANAGER-ERR]jyIncludedInfo GetData Error %v \n", err)
  271. return nil
  272. }
  273. return rData
  274. }
  275. 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`)
  276. if data == nil || len(*data) <= 0 {
  277. return nil
  278. }
  279. info := (*data)[0]
  280. //招标信息的数值
  281. bid := qu.Int64All(info["bid"])
  282. Bid, BidUnit := formdataNum(bid)
  283. //招标采购项目的数值
  284. project := qu.Int64All(info["project"])
  285. Project, ProjectUnit := formdataNum(project)
  286. //企业数据库的数值
  287. ent := qu.Int64All(info["ent"])
  288. Ent, EntUnit := formdataNum(ent)
  289. //采购单位库的数值
  290. buyer := qu.Int64All(info["buyer"])
  291. Buyer, BuyerUnit := formdataNum(buyer)
  292. //每日更新招标信息的数值
  293. bid_day_update := qu.Int64All(info["bid_day_update"])
  294. BidDayUpdate, BidDayUpdateUnit := formdataNum(bid_day_update)
  295. mdata, ok := public.MQFW.Find("swordfish_index", map[string]interface{}{
  296. "i_push": map[string]interface{}{
  297. "$exists": true,
  298. },
  299. }, `{"_id":-1}`, `{"i_push":1}`, false, 0, 1)
  300. i_push := 0
  301. if mdata != nil && ok && len(*mdata) > 0 {
  302. swordData := (*mdata)[0]
  303. i_push = qu.IntAll(swordData["i_push"])
  304. }
  305. Push, PushUnit := formdataNum(int64(i_push))
  306. m := map[string]interface{}{
  307. "bid": Bid,
  308. "bidUnit": BidUnit,
  309. "project": Project,
  310. "projectUnit": ProjectUnit,
  311. "ent": Ent,
  312. "entUnit": EntUnit,
  313. "buyer": Buyer,
  314. "buyerUnit": BuyerUnit,
  315. "bidDayUpdate": BidDayUpdate,
  316. "bidDayUpdateUnit": BidDayUpdateUnit,
  317. "push": Push,
  318. "pushUnit": PushUnit,
  319. }
  320. if bytes, err := json.Marshal(m); err == nil && bytes != nil {
  321. _ = redis.PutBytes(RedisNameNew, "jyIncludedInfo", &bytes, 2*60*60)
  322. }
  323. return m
  324. }
  325. func NewIndexbids(session *httpsession.Session, r *http.Request) []map[string]interface{} {
  326. if bytes, err := redis.GetBytes(RedisNameNew, "jyNewIndexbids"); err == nil && bytes != nil {
  327. rData := []map[string]interface{}{}
  328. if err := json.Unmarshal(*bytes, &rData); err != nil {
  329. log.Printf("[MANAGER-ERR]jyNewIndexbids GetData Error %v \n", err)
  330. return rData
  331. }
  332. return rData
  333. }
  334. /*
  335. userInfo := jy.GetVipState(session, *config.Middleground, "")
  336. so := NewSearchOptimize("", "", "", "", "招标预告,招标公告,招标结果,招标信用信息", "", "", "title", "", "", "", "", "", "", "", "", "", "PC", "", 0, 50, 0, 0, 0, *userInfo, true, r)
  337. so.DefaultSearchParamsAuto()
  338. //缓存数据
  339. _, total, _ := so.GetBidSearchList(true)
  340. data.Count = total
  341. */
  342. _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", "拟建,招标预告,招标公告,招标结果,招标信用信息", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 10, "")
  343. if lists != nil {
  344. for _, v1 := range *lists {
  345. v1["_id"] = encrypt.CommonEncodeArticle("content", v1["_id"].(string))
  346. delete(v1, "toptype")
  347. delete(v1, "s_subscopeclass")
  348. tmpdate := v1["publishtime"]
  349. v1["publishtime"] = time.Unix(qu.Int64All(tmpdate.(float64)), 0).Format(date.Date_Short_Layout)
  350. if v1["budget"] != nil {
  351. v1["budget"] = ConversionMoeny(v1["budget"])
  352. } else if v1["bidamount"] != nil {
  353. v1["budget"] = ConversionMoeny(v1["bidamount"])
  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. return nil
  362. }
  363. // 格式输出数据
  364. // 亿亿、万亿、亿、万 只有一位的时候保留1位小数点 两位及以上不保留 1.1亿 11亿
  365. func formdataNum(num int64) (floatNum float64, unit string) {
  366. s_num := strconv.Itoa(int(num))
  367. len_m := len(s_num)
  368. m := ""
  369. indexArr := []int{17, 13, 9, 5}
  370. unitArr := []string{"亿亿", "万亿", "亿", "万"}
  371. for k, v := range indexArr {
  372. if len_m > v {
  373. if qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)]) >= 5 {
  374. if qu.IntAll(s_num[0:len_m-(v-1)])+1 == 10 {
  375. //满10 进 1
  376. m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)])
  377. m = strconv.Itoa(m1 + 1)
  378. } else {
  379. //满 万 进1 单位
  380. if qu.IntAll(s_num[0:len_m-(v-1)])+1 == 10000 {
  381. m = "1"
  382. unit = unitArr[k-1]
  383. } else {
  384. m = strconv.Itoa(qu.IntAll(s_num[0:len_m-(v-1)]) + 1)
  385. }
  386. }
  387. // log.Println("m1:", m)
  388. } else {
  389. m = s_num[0 : len_m-(v-1)]
  390. // log.Println("m2:", m)
  391. }
  392. } else if len_m == v { //
  393. if qu.IntAll(s_num[len_m-(v-2):len_m-(v-3)]) >= 5 {
  394. m = s_num[0 : len_m-(v-1)]
  395. //满10 进 1
  396. if qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1 == 10 {
  397. m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)])
  398. m = strconv.Itoa(m1 + 1)
  399. } else {
  400. m += "." + strconv.Itoa(qu.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1)
  401. }
  402. // log.Println("m3:", m)
  403. } else {
  404. m = s_num[0 : len_m-(v-1)]
  405. m += "." + s_num[len_m-(v-1):len_m-(v-2)]
  406. // log.Println("m4:", m)
  407. }
  408. }
  409. if m != "" {
  410. if unit == "" {
  411. unit = unitArr[k]
  412. }
  413. break
  414. }
  415. }
  416. if m == "" {
  417. m = s_num
  418. }
  419. //string 转float
  420. floatNum, _ = strconv.ParseFloat(m, 64)
  421. return floatNum, unit
  422. }