included.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package model
  2. import (
  3. "errors"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. "app.yhyue.com/moapp/jybase/common"
  8. "app.yhyue.com/moapp/jybase/date"
  9. "app.yhyue.com/moapp/jybase/mongodb"
  10. "app.yhyue.com/moapp/jybase/mysql"
  11. )
  12. type Included struct {
  13. MysqlDb *mysql.Mysql
  14. Mgo mongodb.MongodbSim
  15. }
  16. const (
  17. IncludedInfoDbName = "included_info" //招录信息表
  18. )
  19. type IncludedData struct {
  20. Year int64 `json:"Year"` //年
  21. Month int64 `json:"Month"` //月
  22. Day int64 `json:"Day"` //日
  23. Bid float64 `json:"Bid"` //招标信息的数值
  24. BidUnit string `json:"BidUnit"` //招标信息的数值单位
  25. BidUnitAppend string `json:"BidUnitAppend"` //招标信息的数值单位后面的加号
  26. Project float64 `json:"Project"` //招标采购项目的数值
  27. ProjectUnit string `json:"ProjectUnit"` //招标采购项目的数值单位
  28. ProjectUnitAppend string `json:"ProjectUnitAppend"` //招标采购项目的数值单位后面的加号
  29. Ent float64 `json:"Ent"` //企业数据库的数值
  30. EntUnit string `json:"EntUnit"` //企业数据库的数值单位
  31. EntUnitAppend string `json:"EntUnitAppend"` //企业数据库的数值单位后面的加号
  32. Buyer float64 `json:"Buyer"` //采购单位库的数值
  33. BuyerUnit string `json:"BuyerUnit"` //采购单位库的数值单位
  34. BuyerUnitAppend string `json:"BuyerUnitAppend"` //采购单位库的数值单位后面的加号
  35. BidDayUpdate float64 `json:"BidDayUpdate"` //每日更新招标信息的数值
  36. BidDayUpdateUnit string `json:"BidDayUpdateUnit"` //每日更新招标信息的数值单位
  37. BidDayUpdateUnitAppend string `json:"BidDayUpdateUnitAppend"` //每日更新招标信息的数值单位后面的加号
  38. BidField float64 `json:"BidField"` //招标信息数据字段的数值
  39. BidFieldUnit string `json:"BidFieldUnit"` //招标信息数据字段的数值单位
  40. BidFieldUnitAppend string `json:"BidFieldUnitAppend"` //招标信息数据字段数值单位后面的加号
  41. FieldAccuracy float64 `json:"FieldAccuracy"` //数据字段准确率的数值
  42. FieldAccuracyUnit string `json:"FieldAccuracyUnit"` //数据字段准确率的数值单位
  43. FieldAccuracyUnitAppend string `json:"FieldAccuracyUnitAppend"` //数据字段准确率的数值单位后面的加号
  44. Push float64 `json:"Push"` //推送招标信息的数值
  45. PushUnit string `json:"PushUnit"` //推送招标信息的数值单位
  46. PushUnitAppend string `json:"PushUnitAppend"` //推送招标信息的数值单位后面的加号
  47. }
  48. //获取收录情况的一堆数据
  49. func (this *Included) GetIncludedData() (*IncludedData, error) {
  50. data := this.MysqlDb.SelectBySql(fmt.Sprintf(`select bid,project,ent,buyer,bid_day_update,bid_field,field_accuracy,create_time from %s order by create_time desc limit 1`, IncludedInfoDbName))
  51. if data == nil || len(*data) <= 0 {
  52. return nil, errors.New("暂无数据")
  53. }
  54. //
  55. info := (*data)[0]
  56. //招标信息的数值
  57. bid := common.Int64All(info["bid"])
  58. Bid, BidUnit := formdataNum(bid)
  59. //招标采购项目的数值
  60. project := common.Int64All(info["project"])
  61. Project, ProjectUnit := formdataNum(project)
  62. //企业数据库的数值
  63. ent := common.Int64All(info["ent"])
  64. Ent, EntUnit := formdataNum(ent)
  65. //采购单位库的数值
  66. buyer := common.Int64All(info["buyer"])
  67. Buyer, BuyerUnit := formdataNum(buyer)
  68. //每日更新招标信息的数值
  69. bid_day_update := common.Int64All(info["bid_day_update"])
  70. BidDayUpdate, BidDayUpdateUnit := formdataNum(bid_day_update)
  71. //每日更新招标信息的数值
  72. bid_field := common.Int64All(info["bid_field"])
  73. BidField, BidFieldUnit := formdataNum(bid_field)
  74. //每日更新招标信息的数值
  75. field_accuracy := common.Float64All(info["field_accuracy"])
  76. FieldAccuracy, FieldAccuracyUnit := field_accuracy, "%"
  77. mdata, ok := this.Mgo.Find("swordfish_index", map[string]interface{}{
  78. "i_push": map[string]interface{}{
  79. "$exists": true,
  80. },
  81. }, `{"_id":-1}`, `{"i_push":1}`, false, 0, 1)
  82. i_push := 0
  83. if mdata != nil && ok && len(*mdata) > 0 {
  84. swordData := (*mdata)[0]
  85. i_push = common.IntAll(swordData["i_push"])
  86. }
  87. Push, PushUnit := formdataNum(int64(i_push))
  88. createTime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(info["create_time"]), time.Local)
  89. includeData := &IncludedData{
  90. Year: int64(createTime.Year()),
  91. Month: int64(createTime.Month()),
  92. Day: int64(createTime.Day()),
  93. Bid: Bid,
  94. BidUnit: BidUnit,
  95. Project: Project,
  96. ProjectUnit: ProjectUnit,
  97. Ent: Ent,
  98. EntUnit: EntUnit,
  99. Buyer: Buyer,
  100. BuyerUnit: BuyerUnit,
  101. BidDayUpdate: BidDayUpdate,
  102. BidDayUpdateUnit: BidDayUpdateUnit,
  103. BidField: BidField,
  104. BidFieldUnit: BidFieldUnit,
  105. FieldAccuracy: FieldAccuracy,
  106. FieldAccuracyUnit: FieldAccuracyUnit,
  107. Push: Push,
  108. PushUnit: PushUnit,
  109. }
  110. return includeData, nil
  111. }
  112. //格式输出数据
  113. //万亿、亿、万 只有一位的时候保留1位小数点 两位及以上不保留 1.1亿 11亿
  114. func formdataNum(num int64) (floatNum float64, unit string) {
  115. s_num := strconv.Itoa(int(num))
  116. len_m := len(s_num)
  117. m := ""
  118. indexArr := []int{13, 9, 5}
  119. unitArr := []string{"万亿", "亿", "万"}
  120. for k, v := range indexArr {
  121. if len_m > v {
  122. if common.IntAll(s_num[len_m-(v-1):len_m-(v-2)]) >= 5 {
  123. if common.IntAll(s_num[0:len_m-(v-1)])+1 == 10 {
  124. //满10 进 1
  125. m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)])
  126. m = strconv.Itoa(m1 + 1)
  127. } else {
  128. //满 万 进1 单位
  129. if common.IntAll(s_num[0:len_m-(v-1)])+1 == 10000 {
  130. m = "1"
  131. unit = unitArr[k-1]
  132. } else {
  133. m = strconv.Itoa(common.IntAll(s_num[0:len_m-(v-1)]) + 1)
  134. }
  135. }
  136. // log.Println("m1:", m)
  137. } else {
  138. m = s_num[0 : len_m-(v-1)]
  139. // log.Println("m2:", m)
  140. }
  141. } else if len_m == v { //
  142. if common.IntAll(s_num[len_m-(v-2):len_m-(v-3)]) >= 5 {
  143. m = s_num[0 : len_m-(v-1)]
  144. //满10 进 1
  145. if common.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1 == 10 {
  146. m1, _ := strconv.Atoi(s_num[0 : len_m-(v-1)])
  147. m = strconv.Itoa(m1 + 1)
  148. } else {
  149. m += "." + strconv.Itoa(common.IntAll(s_num[len_m-(v-1):len_m-(v-2)])+1)
  150. }
  151. // log.Println("m3:", m)
  152. } else {
  153. m = s_num[0 : len_m-(v-1)]
  154. m += "." + s_num[len_m-(v-1):len_m-(v-2)]
  155. // log.Println("m4:", m)
  156. }
  157. }
  158. if m != "" {
  159. if unit == "" {
  160. unit = unitArr[k]
  161. }
  162. break
  163. }
  164. }
  165. if m == "" {
  166. m = s_num
  167. }
  168. //string 转float
  169. floatNum, _ = strconv.ParseFloat(m, 64)
  170. return floatNum, unit
  171. }