htfutures_account_controller.go 8.3 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. "fmt"
  8. )
  9. type HTFuturesAccountController struct {
  10. controllers.WebHookController
  11. }
  12. //
  13. //// SyncCustomerRiskLevel 风险测评同步接口
  14. //// @Summary 风险测评同步接口
  15. //// @Description 风险测评同步接口
  16. //// @Success 200 {object} controllers.BaseResponse
  17. //// @router /riskLevel [post]
  18. //func (h *UserController) SyncCustomerRiskLevel() {
  19. // controllers.Wrap(&h.BaseController, func() (result *controllers.WrapData, err error) {
  20. // result = h.InitWrapData("同步风险等级")
  21. // htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
  22. // webhookRequest := new(WebhookRequest)
  23. // h.GetPostParams(webhookRequest)
  24. // privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
  25. // if err != nil {
  26. // err = exception.NewWithException(exception.SysError, err.Error())
  27. // logger.Error("解析私钥失败: %v", err)
  28. // h.FailedResult("解析私钥失败", result)
  29. // return
  30. // }
  31. // decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
  32. // if err != nil {
  33. // err = exception.NewWithException(exception.SysError, err.Error())
  34. // logger.Error("解密请求体失败: %v", err)
  35. // h.FailedResult("解密请求体失败", result)
  36. // return
  37. // }
  38. // syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  39. // err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
  40. // if err != nil {
  41. // err = exception.NewWithException(exception.SyncRiskError, err.Error())
  42. // logger.Error("解析请求体失败: %v", err)
  43. // h.FailedResult("解析请求体失败", result)
  44. // return
  45. // }
  46. // custInfo := syncCustomerRiskLevelReq.CustInfo
  47. // riskInfo := syncCustomerRiskLevelReq.RiskInfo
  48. // if custInfo.ClientName == "" {
  49. // err = exception.New(exception.SyncRiskError)
  50. // h.FailedResult("用户名字不能为空", result)
  51. // return
  52. // }
  53. // if custInfo.MobileTel == "" {
  54. // err = exception.New(exception.SyncRiskError)
  55. // h.FailedResult("手机号码不能为空", result)
  56. // return
  57. // }
  58. // if custInfo.IdNo == "" {
  59. // err = exception.New(exception.SyncRiskError)
  60. // h.FailedResult("身份证号不能为空", result)
  61. // return
  62. // }
  63. // //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  64. // // err = exception.New(exception.SyncRiskError)
  65. // // h.FailedResult("身份证号不合法", result)
  66. // // return
  67. // //}
  68. // if riskInfo.CorpRiskLevel == "" {
  69. // err = exception.New(exception.SyncRiskError)
  70. // h.FailedResult("风险等级不能为空", result)
  71. // return
  72. // }
  73. // if riskInfo.CorpEndDate == "" {
  74. // err = exception.New(exception.SyncRiskError)
  75. // h.FailedResult("风险测评有效结束日期不能为空", result)
  76. // return
  77. // }
  78. // err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  79. // Name: custInfo.ClientName,
  80. // PhoneNumber: custInfo.MobileTel,
  81. // RiskLevel: riskInfo.CorpRiskLevel,
  82. // RiskValidEndDate: riskInfo.CorpEndDate,
  83. // })
  84. // if err != nil {
  85. // logger.ErrorWithTraceId(h.Ctx, err.Error())
  86. // h.FailedResult(err.Error(), result)
  87. // err = exception.New(exception.SyncRiskError)
  88. // return
  89. // }
  90. // logger.InfoWithTraceId(h.Ctx, err.Error())
  91. // result = h.InitWrapData("同步风险等级成功")
  92. // h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  93. // return
  94. // })
  95. //}
  96. // SyncCustomerRiskLevel 风险测评同步接口
  97. // @Summary 风险测评同步接口
  98. // @Description 风险测评同步接口
  99. // @Success 200 {object} controllers.BaseResponse
  100. // @router /v1/syncRiskLevel/ [post]
  101. func (h *HTFuturesAccountController) SyncCustomerRiskLevel() {
  102. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  103. result = h.InitWrapData("同步风险等级")
  104. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  105. h.GetPostParams(syncCustomerRiskLevelReq)
  106. custInfo := syncCustomerRiskLevelReq.CustInfo
  107. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  108. if custInfo.ClientName == "" {
  109. err = exception.New(exception.SyncRiskError)
  110. h.FailedResult("用户名字不能为空", result)
  111. return
  112. }
  113. if custInfo.MobileTel == "" {
  114. err = exception.New(exception.SyncRiskError)
  115. h.FailedResult("手机号码不能为空", result)
  116. return
  117. }
  118. if custInfo.IdNo == "" {
  119. err = exception.New(exception.SyncRiskError)
  120. h.FailedResult("身份证号不能为空", result)
  121. return
  122. }
  123. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  124. // err = exception.New(exception.SyncRiskError)
  125. // h.FailedResult("身份证号不合法", result)
  126. // return
  127. //}
  128. if riskInfo.CorpRiskLevel == "" {
  129. err = exception.New(exception.SyncRiskError)
  130. h.FailedResult("风险等级不能为空", result)
  131. return
  132. }
  133. if riskInfo.CorpEndDate == "" {
  134. err = exception.New(exception.SyncRiskError)
  135. h.FailedResult("风险测评有效结束日期不能为空", result)
  136. return
  137. }
  138. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  139. Name: custInfo.ClientName,
  140. PhoneNumber: custInfo.MobileTel,
  141. RiskLevel: riskInfo.CorpRiskLevel,
  142. RiskValidEndDate: riskInfo.CorpEndDate,
  143. })
  144. if err != nil {
  145. logger.ErrorWithTraceId(h.Ctx, err.Error())
  146. h.FailedResult(err.Error(), result)
  147. err = exception.New(exception.SyncRiskError)
  148. return
  149. }
  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: fmt.Sprintf("C%s", 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. }