config.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/core/logs"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/cache"
  7. "github.com/rdlucklib/rdluck_tools/log"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_URL_RDDP string //数据库连接
  13. REDIS_CACHE string //缓存地址
  14. Rc *cache.Cache //redis缓存
  15. Re error //redis错误
  16. )
  17. var ApiLog *log.Log
  18. var (
  19. Bucketname string = "hongze"
  20. Endpoint string
  21. Imghost string = "https://hongze.oss-accelerate.aliyuncs.com/"
  22. Upload_dir string = "static/images/"
  23. Upload_Audio_Dir string = "static/audio/"
  24. AccessKeyId string = "LTAIFMZYQhS2BTvW"
  25. AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq"
  26. ResearchReportUrl = "" //全局加密KEY
  27. ReportAppid string
  28. ReportSecret string
  29. )
  30. //全时会议账号信息
  31. var (
  32. QsAppID string
  33. QsSecretKey string
  34. QsUserId int64
  35. QsUserName string
  36. )
  37. func init() {
  38. tmpRunMode, err := web.AppConfig.String("run_mode")
  39. if err != nil {
  40. panic("配置文件读取run_mode错误 " + err.Error())
  41. }
  42. RunMode = tmpRunMode
  43. fmt.Println("RunMode:", RunMode)
  44. if RunMode == "" {
  45. localIp, err := GetLocalIP()
  46. fmt.Println("localIp:", localIp)
  47. if localIp == "10.0.0.123" {
  48. RunMode = "debug"
  49. } else {
  50. RunMode = "release"
  51. }
  52. fmt.Println("RunMode:", RunMode)
  53. configPath := `/home/code/config/hongze_open_api/conf/app.conf`
  54. fmt.Println("configPath:", configPath)
  55. err = web.LoadAppConfig("ini", configPath)
  56. if err != nil {
  57. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  58. }
  59. }
  60. fmt.Println(RunMode, "模式")
  61. config, err := web.AppConfig.GetSection(RunMode)
  62. if err != nil {
  63. panic("配置文件读取错误 " + err.Error())
  64. }
  65. logs.Info(RunMode + " 模式")
  66. MYSQL_URL = config["mysql_url"]
  67. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  68. // 初始化redis
  69. REDIS_CACHE = config["beego_cache"]
  70. if len(REDIS_CACHE) <= 0 {
  71. panic("redis链接参数没有配置")
  72. }
  73. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  74. if Re != nil {
  75. fmt.Println(Re)
  76. panic(Re)
  77. }
  78. //日志类
  79. if RunMode == "release" {
  80. logDir := `/data/rdlucklog/hongze_open_api`
  81. ApiLog = log.Init("20060102.api", logDir)
  82. ResearchReportUrl = "https://details.hzinsights.com/"
  83. ReportAppid = "CQWx3EqDLNk7bVHo" //Appid
  84. ReportSecret = "vRVFCk182Hpv8CyrHsxaHhA3CgGhh4Uu" //AppSecret
  85. } else {
  86. ApiLog = log.Init("20060102.api")
  87. ResearchReportUrl = "http://advisoryadmin.brilliantstart.cn/xcx_h5/"
  88. ReportAppid = "VH2ou4EKlYZz58Uj" //Appid
  89. ReportSecret = "Q6Y5vwmx1IAA9OPkobl8qWvrnV7dGJ4k" //AppSecret
  90. }
  91. //初始化系统用户角色map集合
  92. initRoleType()
  93. //初始化全时开放api配置
  94. initQsOpenApiConfig()
  95. }
  96. type RoleType struct {
  97. RoleId int `json:"role_id"`
  98. RoleName string `json:"role_name"`
  99. RoleType string `json:"role_type"`
  100. RoleTypeCode string `json:"role_type_code"`
  101. Role string `json:"role"`
  102. DepartmentId int `json:"department_id"`
  103. DepartmentName string `json:"department_name"`
  104. GroupId int `json:"group_id"`
  105. GroupName string `json:"group_name"`
  106. }
  107. var RoleTypeMap = map[int]RoleType{}
  108. func initRoleType() {
  109. if RunMode == "release" {
  110. RoleTypeMap[1] = RoleType{
  111. RoleId: 6,
  112. RoleName: "ficc研究员",
  113. RoleType: "ficc研究员",
  114. RoleTypeCode: "researcher",
  115. Role: "researcher",
  116. DepartmentId: 1,
  117. DepartmentName: "FICC研究部",
  118. GroupId: 8,
  119. GroupName: "无",
  120. }
  121. RoleTypeMap[2] = RoleType{
  122. RoleId: 10,
  123. RoleName: "权益研究员",
  124. RoleType: "权益研究员",
  125. RoleTypeCode: "rai_researcher",
  126. Role: "researcher",
  127. DepartmentId: 5,
  128. DepartmentName: "权益销售部",
  129. GroupId: 17,
  130. GroupName: "无",
  131. }
  132. RoleTypeMap[3] = RoleType{
  133. RoleId: 4,
  134. RoleName: "ficc销售",
  135. RoleType: "ficc销售",
  136. RoleTypeCode: "ficc_seller",
  137. Role: "sales",
  138. DepartmentId: 2,
  139. DepartmentName: "ficc销售部",
  140. GroupId: 9,
  141. GroupName: "无",
  142. }
  143. RoleTypeMap[4] = RoleType{
  144. RoleId: 5,
  145. RoleName: "权益销售",
  146. RoleType: "权益销售",
  147. RoleTypeCode: "rai_seller",
  148. Role: "sales",
  149. DepartmentId: 5,
  150. DepartmentName: "权益销售部",
  151. GroupId: 17,
  152. GroupName: "无",
  153. }
  154. } else {
  155. RoleTypeMap[1] = RoleType{
  156. RoleId: 6,
  157. RoleName: "ficc研究员",
  158. RoleType: "ficc研究员",
  159. RoleTypeCode: "researcher",
  160. Role: "researcher",
  161. DepartmentId: 1,
  162. DepartmentName: "FICC研究部",
  163. GroupId: 8,
  164. GroupName: "无",
  165. }
  166. RoleTypeMap[2] = RoleType{
  167. RoleId: 10,
  168. RoleName: "权益研究员",
  169. RoleType: "权益研究员",
  170. RoleTypeCode: "rai_researcher",
  171. Role: "researcher",
  172. DepartmentId: 5,
  173. DepartmentName: "权益销售部-王芳",
  174. GroupId: 17,
  175. GroupName: "无",
  176. }
  177. RoleTypeMap[3] = RoleType{
  178. RoleId: 4,
  179. RoleName: "ficc销售",
  180. RoleType: "ficc销售",
  181. RoleTypeCode: "ficc_seller",
  182. Role: "sales",
  183. DepartmentId: 2,
  184. DepartmentName: "ficc销售部",
  185. GroupId: 9,
  186. GroupName: "无",
  187. }
  188. RoleTypeMap[4] = RoleType{
  189. RoleId: 5,
  190. RoleName: "权益销售",
  191. RoleType: "权益销售",
  192. RoleTypeCode: "rai_seller",
  193. Role: "sales",
  194. DepartmentId: 5,
  195. DepartmentName: "权益销售部-王芳",
  196. GroupId: 17,
  197. GroupName: "无",
  198. }
  199. }
  200. }
  201. // initQsOpenApiConfig 全时开放api配置
  202. func initQsOpenApiConfig() {
  203. QsAppID = "ed1cc7c87c97089263fc899fbab193b0"
  204. QsSecretKey = "d92b91265dbbc5e3af44edfb82503635"
  205. if RunMode == "release" {
  206. QsUserId = 22330940
  207. QsUserName = "1406228535@qq.com"
  208. } else {
  209. QsUserId = 19896481
  210. QsUserName = "pyan@hzinsights.com"
  211. }
  212. }