config.go 11 KB

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