config.go 6.4 KB

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