group.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. // Copyright 2019 gentensh.com. All rights reserved.
  2. // Use of this source code is governed by gentensh.com.
  3. package vehicle
  4. import (
  5. "context"
  6. "gd_vehicle/apis"
  7. gutils "gd_vehicle/common.in/utils"
  8. "gd_vehicle/errors"
  9. "gd_vehicle/impl/thirdparty_impl"
  10. "gd_vehicle/utils"
  11. dutils "gd_vehicle/utils"
  12. //"strings"
  13. )
  14. // 所有人验证组
  15. func ownerVerifyGroup(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply, reqData map[string]interface{}, respData map[string]interface{}, providerMap map[string]apis.MerchantProviderLimitInfo, group []string, rangeNo int)error {
  16. plateNo := dutils.GetStringParams(reqData,"plate_no")
  17. plateType := dutils.GetStringParams(reqData,"plate_type")
  18. owner := dutils.GetStringParams(reqData,"owner")
  19. for _, v := range group {
  20. tReq := &apis.ThirdpartRequest{
  21. Ctx: ctx,
  22. ProviderApiCode: v,
  23. ProviderMap: providerMap,
  24. RangeNo: rangeNo,
  25. Req: req,
  26. Reply: reply,
  27. }
  28. switch v {
  29. case utils.ADMV01:
  30. tReq.Params = map[string]interface{}{
  31. "owner": owner,
  32. "plate_no": plateNo,
  33. "plate_type":plateType,
  34. }
  35. err := thirdparty_impl.CallThirdparty(tReq,respData)
  36. if err != nil {
  37. continue
  38. }
  39. return nil
  40. /*case utils.ZRTWOELEMENTVERIFY:
  41. if !strings.HasPrefix(plateNo,"粤"){
  42. continue
  43. }
  44. tReq.Params = map[string]string{
  45. "name": owner,
  46. "plateNo": plateNo,
  47. "plateType":plateType,
  48. }
  49. ret, err := thirdparty_impl.CallThirdparty(tReq)
  50. if err != nil {
  51. continue
  52. }
  53. respData["is_match"] = ret
  54. return nil*/
  55. case utils.ZRTWOELEMENTVERIFYNATIONAL:
  56. tReq.Params = map[string]interface{}{
  57. "name": owner,
  58. "plateNum": plateNo,
  59. //"plateColor":plateType,
  60. }
  61. err := thirdparty_impl.CallThirdparty(tReq,respData)
  62. if err != nil {
  63. continue
  64. }
  65. return nil
  66. }
  67. }
  68. return errors.NoRecord
  69. }
  70. // 身份验证组
  71. func identityVerifyGroup(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply, reqData map[string]interface{}, respData map[string]interface{}, providerMap map[string]apis.MerchantProviderLimitInfo, group []string, rangeNo int) error {
  72. owner := dutils.GetStringParams(reqData,"owner")
  73. idCard := dutils.GetStringParams(reqData,"id_card")
  74. var err error
  75. for _, v := range group {
  76. tReq := &apis.ThirdpartRequest{
  77. Ctx: ctx,
  78. ProviderApiCode: v,
  79. ProviderMap: providerMap,
  80. RangeNo: rangeNo,
  81. Req: req,
  82. Reply: reply,
  83. }
  84. switch v {
  85. case utils.ADMV02:
  86. tReq.Params = map[string]interface{}{
  87. "name": owner,
  88. "id_card": idCard,
  89. }
  90. err = thirdparty_impl.CallThirdparty(tReq,respData)
  91. if err != nil {
  92. continue
  93. }
  94. return nil
  95. /*case utils.DYTWOELEMENTVERIFY:
  96. tReq.Params = map[string]string{
  97. "name": owner,
  98. "id_card": idCard,
  99. }
  100. ret, err = thirdparty_impl.CallThirdparty(tReq)
  101. if err != nil {
  102. continue
  103. }
  104. return nil*/
  105. default:
  106. continue
  107. }
  108. }
  109. return errors.NoRecord
  110. }
  111. // 所有人身份三要素核验
  112. /*func threeElemetVerifyGroup(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply, reqData map[string]interface{}, respData map[string]string, providerMap map[string]apis.MerchantProviderLimitInfo, group []string, rangeNo int) error {
  113. owner := dutils.GetStringParams(reqData,"owner")
  114. idCard := dutils.GetStringParams(reqData,"id_card")
  115. plateNo := dutils.GetStringParams(reqData,"plate_no")
  116. ret := ""
  117. var err error
  118. for _, v := range group {
  119. tReq := &apis.ThirdpartRequest{
  120. Ctx: ctx,
  121. ProviderApiCode: v,
  122. ProviderMap: providerMap,
  123. RangeNo: rangeNo,
  124. Req: req,
  125. Reply: reply,
  126. }
  127. switch v {
  128. case utils.CDBDTWOELEMENTVERIFY:
  129. sf, plateNum := gutils.ParsePlate(plateNo)
  130. if sf != "川"{
  131. continue
  132. }
  133. tReq.Params = map[string]string{
  134. "plate_num": plateNum,
  135. "id_card": idCard,
  136. "owner": owner,
  137. }
  138. ret, err = thirdparty_impl.CallThirdparty(tReq)
  139. if err != nil {
  140. continue
  141. }
  142. cdbd.GetCdbdTwoElementVerifyData(ret,respData)
  143. if respData["is_match"] == "-1"{
  144. return nil
  145. }
  146. default:
  147. continue
  148. }
  149. }
  150. return errors.NoRecord
  151. }
  152. */
  153. // 车牌查车档组
  154. func vehicleInfoByPlateGroup(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply, reqData map[string]interface{}, respData map[string]interface{}, providerMap map[string]apis.MerchantProviderLimitInfo, group []string, rangeNo int) error {
  155. plateNo := dutils.GetStringParams(reqData,"plate_no")
  156. plateType := dutils.GetStringParams(reqData,"plate_type")
  157. if plateNo == "" || plateType == ""{
  158. return errors.ArgsError
  159. }
  160. var err error
  161. for _, v := range group {
  162. tReq := &apis.ThirdpartRequest{
  163. Ctx: ctx,
  164. ProviderApiCode: v,
  165. ProviderMap: providerMap,
  166. RangeNo: rangeNo,
  167. Req: req,
  168. Reply: reply,
  169. }
  170. switch v {
  171. // 车牌查车辆信息
  172. case utils.ADMA04:
  173. tReq.Params = map[string]interface{}{
  174. "plate_no": plateNo,
  175. "plate_type":plateType,
  176. }
  177. err = thirdparty_impl.CallThirdparty(tReq,respData)
  178. if err != nil {
  179. continue
  180. }
  181. // 检查发动机号是否存在
  182. _, err := thirdparty_impl.CheckProviderApiIsAvaliable(utils.LOCALENGINENO, tReq.ProviderMap,rangeNo)
  183. if err == nil {
  184. engineNo := respData["engine_no"]
  185. if engineNo != ""{
  186. return nil
  187. }
  188. }else{
  189. return nil
  190. }
  191. // 车牌查vin
  192. case utils.ADMA01:
  193. tReq.Params = map[string]interface{}{
  194. "plate_no": plateNo,
  195. "plate_type":plateType,
  196. }
  197. err = thirdparty_impl.CallThirdparty(tReq,respData)
  198. if err != nil {
  199. continue
  200. }
  201. return nil
  202. // 车牌查车辆信息
  203. case utils.ZRVEHICLEINFO:
  204. tReq.Params = map[string]interface{}{
  205. "plateNumber": plateNo,
  206. }
  207. err = thirdparty_impl.CallThirdparty(tReq,respData)
  208. if err != nil {
  209. continue
  210. }
  211. return nil
  212. // 车牌查vin
  213. case utils.ZRVEHICLEVIN:
  214. tReq.Params = map[string]interface{}{
  215. "vinOrPlateNumber": plateNo,
  216. }
  217. err = thirdparty_impl.CallThirdparty(tReq,respData)
  218. if err != nil {
  219. continue
  220. }
  221. return nil
  222. case utils.ZRVEHICLEFIVE:
  223. tReq.Params = map[string]interface{}{
  224. "vinOrPlateNumber": plateNo,
  225. }
  226. err = thirdparty_impl.CallThirdparty(tReq,respData)
  227. if err != nil {
  228. continue
  229. }
  230. return nil
  231. default:
  232. continue
  233. }
  234. }
  235. return errors.NoRecord
  236. }
  237. // vin查车档组
  238. func vehicleInfoByVinGroup(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply, reqData map[string]interface{}, respData map[string]interface{}, providerMap map[string]apis.MerchantProviderLimitInfo, group []string, rangeNo int) error {
  239. vin := dutils.GetStringParams(reqData,"vin")
  240. if vin == "" {
  241. vin = dutils.GetStringParams(respData,"vin")
  242. }
  243. if vin == "" {
  244. return errors.ArgsError
  245. }
  246. var err error
  247. for _, v := range group {
  248. tReq := &apis.ThirdpartRequest{
  249. Ctx: ctx,
  250. ProviderApiCode: v,
  251. ProviderMap: providerMap,
  252. RangeNo: rangeNo,
  253. Req: req,
  254. Reply: reply,
  255. }
  256. switch v {
  257. // vin查车辆信息
  258. case utils.ADMA05:
  259. tReq.Params = map[string]interface{}{
  260. "vin": vin,
  261. }
  262. err = thirdparty_impl.CallThirdparty(tReq,respData)
  263. if err != nil {
  264. continue
  265. }
  266. plateNo := gutils.GetInterfaceString(respData,"plate_no")
  267. if plateNo == ""{
  268. continue
  269. }
  270. _, err := thirdparty_impl.CheckProviderApiIsAvaliable(utils.LOCALENGINENO, tReq.ProviderMap, rangeNo)
  271. if err == nil {
  272. engineNo := gutils.GetInterfaceString(respData,"engine_no")
  273. if engineNo != ""{
  274. return nil
  275. }
  276. }else{
  277. return nil
  278. }
  279. // vin 查车牌
  280. case utils.ADMA02:
  281. tReq.Params = map[string]interface{}{
  282. "vin": vin,
  283. }
  284. err = thirdparty_impl.CallThirdparty(tReq,respData)
  285. if err != nil {
  286. continue
  287. }
  288. plateNo := gutils.GetInterfaceString(respData,"plate_no")
  289. if plateNo != ""{
  290. return nil
  291. }
  292. case utils.ZRVININFO:
  293. tReq.Params = map[string]interface{}{
  294. "vin": vin,
  295. }
  296. err = thirdparty_impl.CallThirdparty(tReq,respData)
  297. if err != nil {
  298. continue
  299. }
  300. default:
  301. continue
  302. }
  303. }
  304. return errors.NoRecord
  305. }
  306. func getIsMatch(respData map[string]interface{}) string {
  307. return gutils.GetInterfaceString(respData,"is_match")
  308. return "0"
  309. }
  310. func group(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) error {
  311. reqData := req.Data.(map[string]interface{})
  312. respData := reply.Data.(map[string]interface{})
  313. defer func() {
  314. reply.Data = respData
  315. }()
  316. var err error
  317. //reply.Data = respData
  318. for groupNum, group := range req.ProviderGroup {
  319. rangeNo := groupNum + 1
  320. for _, v := range group {
  321. switch v {
  322. // 人车核验组
  323. case utils.ADMV01:
  324. if getIsMatch(respData) == "-1"{
  325. continue
  326. }
  327. err = ownerVerifyGroup(ctx,req,reply,reqData,respData,req.ProviderMap,group,rangeNo)
  328. if err != nil{
  329. return errors.NoRecord
  330. }
  331. // 人身核验组
  332. case utils.ADMV02:
  333. if getIsMatch(respData) == "-1"{
  334. continue
  335. }
  336. err = identityVerifyGroup(ctx,req,reply,reqData,respData,req.ProviderMap,group,rangeNo)
  337. if err != nil {
  338. return errors.NoRecord
  339. }
  340. // 车牌查车辆信息组
  341. case utils.ADMA01,utils.ADMA04:
  342. if req.NeedVehicleInfo || getIsMatch(respData) == "1"{
  343. err = vehicleInfoByPlateGroup(ctx,req,reply,reqData,respData,req.ProviderMap,group,rangeNo)
  344. if err != nil {
  345. return errors.NoRecord
  346. }
  347. }
  348. // vin查车辆信息组
  349. case utils.ADMA02,utils.ADMA05:
  350. if req.NeedVehicleInfo || getIsMatch(respData) == "1"{
  351. err = vehicleInfoByVinGroup(ctx,req,reply,reqData,respData,req.ProviderMap,group,rangeNo)
  352. if err != nil {
  353. return errors.NoRecord
  354. }
  355. }
  356. }
  357. }
  358. }
  359. return nil
  360. }