htfutures_account_controller.go 9.3 KB

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