htfutures_account_controller.go 9.5 KB

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