classificationTag.go 15 KB

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