htfutures_account_controller.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. logger.InfoWithTraceId(h.Ctx, err.Error())
  151. result = h.InitWrapData("同步风险等级成功")
  152. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  153. return
  154. })
  155. }
  156. // SyncCustomerAccountInfo 开户信息同步接口
  157. // @Summary 开户信息同步接口
  158. // @Description 开户信息同步接口
  159. // @Success 200 {object} controllers.BaseResponse
  160. // @router /v1/syncAccountInfo/ [post]
  161. func (h *HTFuturesAccountController) SyncCustomerAccountInfo() {
  162. controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
  163. result = h.InitWrapData("同步风险等级")
  164. syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
  165. h.GetPostParams(syncCustomerRiskLevelReq)
  166. custInfo := syncCustomerRiskLevelReq.CustInfo
  167. riskInfo := syncCustomerRiskLevelReq.RiskInfo
  168. if custInfo.ClientName == "" {
  169. err = exception.New(exception.SyncRiskError)
  170. h.FailedResult("用户名字不能为空", result)
  171. return
  172. }
  173. if custInfo.MobileTel == "" {
  174. err = exception.New(exception.SyncRiskError)
  175. h.FailedResult("手机号码不能为空", result)
  176. return
  177. }
  178. if custInfo.IdNo == "" {
  179. err = exception.New(exception.SyncRiskError)
  180. h.FailedResult("身份证号不能为空", result)
  181. return
  182. }
  183. //if !utils.IsValidIDCard(custInfo.IdNo) && !utils.IsValidOldIDCard(custInfo.IdNo) {
  184. // err = exception.New(exception.SyncRiskError)
  185. // h.FailedResult("身份证号不合法", result)
  186. // return
  187. //}
  188. if riskInfo.CorpRiskLevel == "" {
  189. err = exception.New(exception.SyncRiskError)
  190. h.FailedResult("风险等级不能为空", result)
  191. return
  192. }
  193. if riskInfo.CorpEndDate == "" {
  194. err = exception.New(exception.SyncRiskError)
  195. h.FailedResult("风险测评有效结束日期不能为空", result)
  196. return
  197. }
  198. err = userService.UpdateRiskLevelInfo(userService.RiskLevelInfoDTO{
  199. Name: custInfo.ClientName,
  200. PhoneNumber: custInfo.MobileTel,
  201. RiskLevel: fmt.Sprintf("C%s", riskInfo.CorpRiskLevel),
  202. RiskValidEndDate: riskInfo.CorpEndDate,
  203. })
  204. if err != nil {
  205. logger.ErrorWithTraceId(h.Ctx, err.Error())
  206. h.FailedResult(err.Error(), result)
  207. err = exception.New(exception.SyncRiskError)
  208. return
  209. }
  210. logger.InfoWithTraceId(h.Ctx, err.Error())
  211. result = h.InitWrapData("同步风险等级成功")
  212. h.SuccessResult("success", syncCustomerRiskLevelReq, result)
  213. return
  214. })
  215. }
  216. type SyncCustomerRiskLevelReq struct {
  217. CustInfo CustInfo `json:"custInfo"`
  218. RiskInfo RiskInfo `json:"riskInfo"`
  219. }
  220. type CustInfo struct {
  221. MobileTel string `json:"mobile_tel"`
  222. ClientName string `json:"client_name"`
  223. IdKind string `json:"id_kind"`
  224. IdNo string `json:"id_no"`
  225. }
  226. type RiskInfo struct {
  227. CorpBeginDate string `json:"corp_begin_date"`
  228. CorpEndDate string `json:"corp_end_date"`
  229. UserInvestTerm string `json:"user_invest_term"`
  230. UserInvestKind string `json:"user_invest_kind"`
  231. CorpRiskLevel string `json:"corp_risk_level"`
  232. }
  233. type SyncCustomerAccountInfoReq struct {
  234. CustInfo CustInfo `json:"custInfo"`
  235. RiskInfo RiskInfo `json:"riskInfo"`
  236. }