config.go 11 KB

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