config.go 6.9 KB

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