htfutures_account_controller.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package web_hook
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/exception"
  5. "eta/eta_mini_ht_api/controllers"
  6. userService "eta/eta_mini_ht_api/domian/user"
  7. )
  8. type HTFuturesAccountController struct {
  9. controllers.WebHookController
  10. }
  11. //
  12. //// SyncCustomerRiskLevel 风险测评同步接口
  13. //// @Summary 风险测评同步接口
  14. //// @Description 风险测评同步接口
  15. //// @Success 200 {object} controllers.BaseResponse
  16. //// @router /riskLevel [post]
  17. //func (h *UserController) SyncCustomerRiskLevel() {
  18. // controllers.Wrap(&h.BaseController, func() (result *controllers.WrapData, err error) {
  19. // result = h.InitWrapData("同步风险等级")
  20. // htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
  21. // webhookRequest := new(WebhookRequest)
  22. // h.GetPostParams(webhookRequest)
  23. // privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  24. // if err != nil {
  25. // err = exception.NewWithException(exception.SysError, err.Error())
  26. // logger.Error("解析私钥失败: %v", err)
  27. // h.FailedResult("解析私钥失败", result)
  28. // return
  29. // }
  30. // decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
  31. // if err != nil {
  32. // err = exception.NewWithException(exception.SysError, err.Error())
  33. // logger.Error("解密请求体失败: %v", err)
  34. // h.FailedResult("解密请求体失败", result)
  35. // return
  36. // }
  37. // syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  38. // err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
  39. // if err != nil {
  40. // err = exception.NewWithException(exception.SyncRiskError, err.Error())
  41. // logger.Error("解析请求体失败: %v", err)
  42. // h.FailedResult("解析请求体失败", result)
  43. // return
  44. // }
  45. // custInfo := syncCustomerRiskLevelReq.CustInfo
  46. // riskInfo := syncCustomerRiskLevelReq.RiskInfo
  47. // if custInfo.ClientName == "" {
  48. // err = exception.New(exception.SyncRiskError)
  49. // h.FailedResult("用户名字不能为空", result)
  50. // return
  51. // }
  52. // if custInfo.MobileTel == "" {
  53. // err = exception.New(exception.SyncRiskError)
  54. // h.FailedResult("手机号码不能为空", result)
  55. // return
  56. // }
  57. // if custInfo.IdNo == "" {
  58. // err = exception.New(exception.SyncRiskError)
  59. // h.FailedResult("身份证号不能为空", result)
  60. // return
  61. // }
  62. // //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  63. // // err = exception.New(exception.SyncRiskError)
  64. // // h.FailedResult("身份证号不合法", result)
  65. // // return
  66. // //}
  67. // if riskInfo.CorpRiskLevel == "" {
  68. // err = exception.New(exception.SyncRiskError)
  69. // h.FailedResult("风险等级不能为空", result)
  70. // return
  71. // }
  72. // if riskInfo.CorpEndDate == "" {
  73. // err = exception.New(exception.SyncRiskError)
  74. // h.FailedResult("风险测评有效结束日期不能为空", result)
  75. // return
  76. // }
  77. // err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  78. // Name: custInfo.ClientName,
  79. // PhoneNumber: custInfo.MobileTel,
  80. // RiskLevel: riskInfo.CorpRiskLevel,
  81. // RiskValidEndDate: riskInfo.CorpEndDate,
  82. // })
  83. // if err != nil {
  84. // logger.ErrorWithTraceId(h.Ctx, err.Error())
  85. // h.FailedResult(err.Error(), result)
  86. // err = exception.New(exception.SyncRiskError)
  87. // return
  88. // }
  89. // logger.InfoWithTraceId(h.Ctx, err.Error())
  90. // result = h.InitWrapData("同步风险等级成功")
  91. // h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  92. // return
  93. // })
  94. //}
  95. // SyncCustomerRiskLevel 风险测评同步接口
  96. // @Summary 风险测评同步接口
  97. // @Description 风险测评同步接口
  98. // @Success 200 {object} controllers.BaseResponse
  99. // @router /v1/syncRiskLevel/ [post]
  100. func (h *HTFuturesAccountController) SyncCustomerRiskLevel() {
  101. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  102. result = h.InitWrapData("同步风险等级")
  103. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  104. h.GetPostParams(syncCustomerRiskLevelReq)
  105. custInfo := syncCustomerRiskLevelReq.CustInfo
  106. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  107. if custInfo.ClientName == "" {
  108. err = exception.New(exception.SyncRiskError)
  109. h.FailedResult("用户名字不能为空", result)
  110. return
  111. }
  112. if custInfo.MobileTel == "" {
  113. err = exception.New(exception.SyncRiskError)
  114. h.FailedResult("手机号码不能为空", result)
  115. return
  116. }
  117. if custInfo.IdNo == "" {
  118. err = exception.New(exception.SyncRiskError)
  119. h.FailedResult("身份证号不能为空", result)
  120. return
  121. }
  122. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  123. // err = exception.New(exception.SyncRiskError)
  124. // h.FailedResult("身份证号不合法", result)
  125. // return
  126. //}
  127. if riskInfo.CorpRiskLevel == "" {
  128. err = exception.New(exception.SyncRiskError)
  129. h.FailedResult("风险等级不能为空", result)
  130. return
  131. }
  132. if riskInfo.CorpEndDate == "" {
  133. err = exception.New(exception.SyncRiskError)
  134. h.FailedResult("风险测评有效结束日期不能为空", result)
  135. return
  136. }
  137. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  138. Name: custInfo.ClientName,
  139. PhoneNumber: custInfo.MobileTel,
  140. RiskLevel: riskInfo.CorpRiskLevel,
  141. RiskValidEndDate: riskInfo.CorpEndDate,
  142. })
  143. if err != nil {
  144. logger.ErrorWithTraceId(h.Ctx, err.Error())
  145. h.FailedResult(err.Error(), result)
  146. err = exception.New(exception.SyncRiskError)
  147. return
  148. }
  149. logger.InfoWithTraceId(h.Ctx, err.Error())
  150. result = h.InitWrapData("同步风险等级成功")
  151. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  152. return
  153. })
  154. }
  155. // SyncCustomerAccountInfo 开户信息同步接口
  156. // @Summary 开户信息同步接口
  157. // @Description 开户信息同步接口
  158. // @Success 200 {object} controllers.BaseResponse
  159. // @router /v1/syncAccountInfo/ [post]
  160. func (h *HTFuturesAccountController) SyncCustomerAccountInfo() {
  161. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  162. result = h.InitWrapData("同步风险等级")
  163. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  164. h.GetPostParams(syncCustomerRiskLevelReq)
  165. custInfo := syncCustomerRiskLevelReq.CustInfo
  166. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  167. if custInfo.ClientName == "" {
  168. err = exception.New(exception.SyncRiskError)
  169. h.FailedResult("用户名字不能为空", result)
  170. return
  171. }
  172. if custInfo.MobileTel == "" {
  173. err = exception.New(exception.SyncRiskError)
  174. h.FailedResult("手机号码不能为空", result)
  175. return
  176. }
  177. if custInfo.IdNo == "" {
  178. err = exception.New(exception.SyncRiskError)
  179. h.FailedResult("身份证号不能为空", result)
  180. return
  181. }
  182. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  183. // err = exception.New(exception.SyncRiskError)
  184. // h.FailedResult("身份证号不合法", result)
  185. // return
  186. //}
  187. if riskInfo.CorpRiskLevel == "" {
  188. err = exception.New(exception.SyncRiskError)
  189. h.FailedResult("风险等级不能为空", result)
  190. return
  191. }
  192. if riskInfo.CorpEndDate == "" {
  193. err = exception.New(exception.SyncRiskError)
  194. h.FailedResult("风险测评有效结束日期不能为空", result)
  195. return
  196. }
  197. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  198. Name: custInfo.ClientName,
  199. PhoneNumber: custInfo.MobileTel,
  200. RiskLevel: riskInfo.CorpRiskLevel,
  201. RiskValidEndDate: riskInfo.CorpEndDate,
  202. })
  203. if err != nil {
  204. logger.ErrorWithTraceId(h.Ctx, err.Error())
  205. h.FailedResult(err.Error(), result)
  206. err = exception.New(exception.SyncRiskError)
  207. return
  208. }
  209. logger.InfoWithTraceId(h.Ctx, err.Error())
  210. result = h.InitWrapData("同步风险等级成功")
  211. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  212. return
  213. })
  214. }
  215. type SyncCustomerRiskLevelReq struct {
  216. CustInfo CustInfo `json:"custInfo"`
  217. RiskInfo RiskInfo `json:"riskInfo"`
  218. }
  219. type CustInfo struct {
  220. MobileTel string `json:"mobile_tel"`
  221. ClientName string `json:"client_name"`
  222. IdKind string `json:"id_kind"`
  223. IdNo string `json:"id_no"`
  224. }
  225. type RiskInfo struct {
  226. CorpBeginDate string `json:"corp_begin_date"`
  227. CorpEndDate string `json:"corp_end_date"`
  228. UserInvestTerm string `json:"user_invest_term"`
  229. UserInvestKind string `json:"user_invest_kind"`
  230. CorpRiskLevel string `json:"corp_risk_level"`
  231. }
  232. type SyncCustomerAccountInfoReq struct {
  233. CustInfo CustInfo `json:"custInfo"`
  234. RiskInfo RiskInfo `json:"riskInfo"`
  235. }