config.go 11 KB

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