config.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. "context"
  6. "fmt"
  7. "github.com/ClickHouse/clickhouse-go/v2"
  8. "github.com/gogf/gf/v2/util/gconv"
  9. "gopkg.in/gomail.v2"
  10. "log"
  11. "time"
  12. )
  13. type (
  14. Config struct {
  15. LastOrderId int `json:"lastOrderId"`
  16. LastOrderClueId string `json:"lastOrderClueId"`
  17. LastUserId string `json:"lastUserId"`
  18. LastXcxUserId string `json:"lastXcxUserId"`
  19. LastId string `json:"lastId"`
  20. LastOrderTime string `json:"lastOrderTime"`
  21. LastUserTime string `json:"lastUserTime"`
  22. LastSubscribeId string `json:"lastSubscribeId"`
  23. LastMessageTime string `json:"lastMessageTime"`
  24. LastMessageButtonTime string `json:"lastMessageButtonTime"`
  25. LastkcTime string `json:"lastkcTime"`
  26. LastEverythingTime string `json:"lastEverythingTime"`
  27. LastEventRegTime string `json:"lastEventRegTime"`
  28. LastReadClueTime string `json:"lastReadClueTime"`
  29. BigSaleTime int64 `json:"bigSaleTime"`
  30. BigOrderTime string `json:"bigOrderTime"`
  31. MarketSaleTime int64 `json:"marketSaleTime"`
  32. AdvisoryCommitteeTime int64 `json:"advisoryCommitteeTime"`
  33. SelectionDepartmentTime int64 `json:"selectionDepartmentTime"`
  34. AllocationTime string `json:"allocationTime"`
  35. AllocationRatio float64 `json:"allocationRatio"`
  36. ActiveTime string `json:"activeTime"`
  37. RebindTime string `json:"rebindTime"`
  38. InviteTime string `json:"inviteTime"`
  39. ActivityTime string `json:"activityTime"`
  40. LastKcChangeTime string `json:"lastKcChangeTime"`
  41. LastUserBindingTime string `json:"lastUserBindingTime"`
  42. }
  43. DB struct {
  44. CornExp1 int64 `json:"cornexp1"`
  45. CornExp2 int64 `json:"cornexp2"`
  46. CornExp2Start string `json:"cornexp2Strat"`
  47. CornExp2End string `json:"cornexp2End"`
  48. CornExp3 string `json:"cornexp3"`
  49. CornExp4 string `json:"cornexp4"`
  50. CornExp5 int64 `json:"cornexp5"`
  51. CornExp6 int64 `json:"cornexp6"`
  52. CornExp7 string `json:"cornexp7"`
  53. CornExp8 int64 `json:"cornexp8"`
  54. CornExp9 string `json:"cornexp9"`
  55. TiDb MysqlConfig `json:"tiDb"`
  56. TiDbData MysqlConfig `json:"tiDbData"`
  57. TiDbPower MysqlConfig `json:"tiDbPower"`
  58. WorderOrder MysqlConfig `json:"workOrder"`
  59. BaseService MysqlConfig `json:"baseService"`
  60. BiService MysqlConfig `json:"biService"`
  61. ThirdParty MysqlConfig `json:"thirdParty"`
  62. Jyactivities MysqlConfig `json:"jyactivities"`
  63. DebrisProduct MysqlConfig `json:"debrisProduct"`
  64. Mysql MysqlConfig `json:"mysql"`
  65. DataAnalysis MysqlConfig `json:"dataAnalysis"`
  66. Mgo struct {
  67. Address string `json:"address"`
  68. DbName string `json:"dbName"`
  69. DbSize int `json:"dbSize"`
  70. } `json:"mgo"`
  71. MgoLog MongoConfig `json:"mgoLog"`
  72. MgoQyxy MongoConfig `json:"mgoQyxy"`
  73. Es struct {
  74. Address string `json:"address"`
  75. DbSize int `json:"dbSize"`
  76. Version string `json:"version"`
  77. UserName string `json:"user Name"`
  78. Password string `json:"password"`
  79. } `json:"es"`
  80. ProductArr []string `json:"productArr"`
  81. RedisServer string `json:"redisServer"`
  82. AllocationCap int64 `json:"allocationCap"`
  83. WarningValue int64 `json:"warningValue"`
  84. CornMail string `json:"corn_mail"`
  85. RegTimes int `json:"regTimes"`
  86. NameToMail map[string]string `json:"nameToMail"`
  87. ThawDay int64 `json:"thawDay"`
  88. LoopType int64 `json:"loopType"`
  89. Sourceid string `json:"sourceid"`
  90. AbhEmail string `json:"abhEmail"`
  91. AfEmail string `json:"afEmail"`
  92. NewRegistration int64 `json:"newRegistration"`
  93. OperationEmail []string `json:"operationEmail"`
  94. ExpirationPeriod int `json:"expirationPeriod"` //客成到期周期
  95. HandoverCycle int64 `json:"handoverCycle"` //移交周期
  96. CustomerTime int64 `json:"customerTime"` //客成时间
  97. KeCheng struct {
  98. DeptId int64 `json:"deptId"`
  99. Title string `json:"title"`
  100. Mail struct {
  101. Table string `json:"table"`
  102. Content string `json:"content"`
  103. ServiceList string `json:"serviceList"`
  104. ReturnMoney string `json:"returnMoney"`
  105. } `json:"mail"`
  106. Message string `json:"message"`
  107. MessageServiceList string `json:"messageServiceList"`
  108. MessageReturnMoney string `json:"messageReturnMoney"`
  109. Admin string `json:"admin"`
  110. } `json:"keCheng"`
  111. EntId int `json:"entId"`
  112. Mail GmailAuth `json:"mail"` //邮箱配置
  113. Clickhouse CHouseConfig `json:"clickhouse"`
  114. Crm MysqlConfig `json:"crmTiDb"`
  115. ApiPort string `json:"apiPort"`
  116. }
  117. LableJson struct {
  118. ConditionConfig []ConditionEntity `json:"conditionConfig"`
  119. }
  120. ConditionEntity struct {
  121. TopName string `json:"topName"`
  122. SubName string `json:"subName"`
  123. ConditionArr []Condition `json:"conditionArr"`
  124. }
  125. Condition struct {
  126. Code string `json:"code"`
  127. Fool bool `json:"fool"`
  128. }
  129. CHouseConfig struct {
  130. Addr string
  131. UserName string
  132. Password string
  133. DbName string
  134. MaxIdleConns int
  135. MaxOpenConns int
  136. }
  137. MysqlConfig struct {
  138. Host string `json:"host"`
  139. Port int `json:"port"`
  140. Database string `json:"database"`
  141. User string `json:"user"`
  142. Password string `json:"password"`
  143. PollSize int `json:"poolsize"`
  144. MaxIdle int `json:"maxidle"`
  145. MaxLeftTime int `json:"maxleft"`
  146. }
  147. MongoConfig struct {
  148. Address string `json:"address"`
  149. DbName string `json:"dbName"`
  150. DbSize int `json:"dbSize"`
  151. User string `json:"user"`
  152. Password string `json:"password"`
  153. }
  154. )
  155. type GmailAuth struct {
  156. SmtpHost string //邮箱服务器
  157. SmtpPort int //邮箱端口
  158. User string //用户
  159. Pwd string //密码
  160. PoolChan chan *gomail.Dialer
  161. PoolSize int
  162. ReTry int
  163. }
  164. var AreaCode = map[string]string{}
  165. var CodeArea = map[string]string{}
  166. var CodeTrail = map[string]string{}
  167. var DateMap = map[string]int{}
  168. var ProductMap = map[string]string{}
  169. func InitArea() {
  170. info := TiDb.Find("d_area_code", nil, "", "", -1, -1)
  171. if info != nil && len(*info) > 0 {
  172. for _, m := range *info {
  173. AreaCode[common.ObjToString(m["name"])] = common.ObjToString(m["code"])
  174. CodeArea[common.ObjToString(m["code"])] = common.ObjToString(m["name"])
  175. }
  176. }
  177. log.Println("AreaCodeLen ", len(AreaCode))
  178. log.Println("CodeAreaLen ", len(CodeArea))
  179. trailData := TiDb.Find("dwd_d_crm_trailstatus_code", nil, "", "", -1, -1)
  180. if trailData != nil && len(*trailData) > 0 {
  181. for _, m := range *trailData {
  182. CodeTrail[common.ObjToString(m["code"])] = common.ObjToString(m["name"])
  183. }
  184. }
  185. holidayRecords := TiDb.Find("holiday_records", nil, "", "", -1, -1)
  186. if holidayRecords != nil && len(*holidayRecords) > 0 {
  187. for _, m := range *holidayRecords {
  188. DateMap[common.ObjToString(m["date"])] = common.IntAll(m["change"])
  189. }
  190. }
  191. }
  192. func InitProduct(product []string) {
  193. for _, v := range product {
  194. ProductMap[v] = "dk"
  195. }
  196. }
  197. func InitUserChannel() {
  198. data := TiDb.SelectBySql(`SELECT
  199. a.code,
  200. a.clue_code,
  201. b.name
  202. FROM
  203. jianyu.short_url a
  204. INNER JOIN dwd_d_userbase_belongto_rulecode b ON a.clue_code = b.CODE and a.clue = 1 `)
  205. if data != nil && len(*data) > 0 {
  206. for _, v := range *data {
  207. code := gconv.String(v["code"])
  208. UserChannel[code] = map[string]interface{}{
  209. "name": gconv.String(v["name"]),
  210. "clueCode": gconv.String(v["clue_code"]),
  211. }
  212. }
  213. }
  214. UserChannel["JyChCoopA"] = map[string]interface{}{
  215. "name": "一切都好",
  216. "clueCode": "0301",
  217. }
  218. log.Println(UserChannel)
  219. }
  220. func ConnectClickhouse(cHouseConfig *CHouseConfig) error {
  221. var (
  222. ctx = context.Background()
  223. err error
  224. )
  225. ClickhouseConn, err = clickhouse.Open(&clickhouse.Options{
  226. Addr: []string{cHouseConfig.Addr},
  227. DialTimeout: 10 * time.Second,
  228. MaxIdleConns: cHouseConfig.MaxIdleConns,
  229. MaxOpenConns: cHouseConfig.MaxOpenConns,
  230. Auth: clickhouse.Auth{
  231. Database: cHouseConfig.DbName,
  232. Username: cHouseConfig.UserName,
  233. Password: cHouseConfig.Password,
  234. },
  235. Debugf: func(format string, v ...interface{}) {
  236. fmt.Printf(format, v)
  237. },
  238. })
  239. if err != nil {
  240. return err
  241. }
  242. if err := ClickhouseConn.Ping(ctx); err != nil {
  243. if exception, ok := err.(*clickhouse.Exception); ok {
  244. fmt.Printf("Exception [%d] %s \n%s\n", exception.Code, exception.Message, exception.StackTrace)
  245. }
  246. return err
  247. }
  248. return nil
  249. }
  250. func MysqlTidbInit(data MysqlConfig) *mysql.Mysql {
  251. return &mysql.Mysql{
  252. Address: data.Host + ":" + fmt.Sprint(data.Port),
  253. UserName: data.User,
  254. PassWord: data.Password,
  255. DBName: data.Database,
  256. MaxOpenConns: data.PollSize,
  257. MaxIdleConns: data.MaxIdle,
  258. }
  259. }