AppBankController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. package me.zhengjie.application.bank.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import lombok.RequiredArgsConstructor;
  5. import lombok.extern.slf4j.Slf4j;
  6. import me.zhengjie.annotation.rest.AnonymousPostMapping;
  7. import me.zhengjie.application.bank.controller.vo.*;
  8. import me.zhengjie.application.bank.service.*;
  9. import me.zhengjie.base.config.TencentHumanFaceVerify;
  10. import me.zhengjie.dao.mybatis.entity.OrderEntity;
  11. import me.zhengjie.dao.mybatis.entity.SysUserEntity;
  12. import me.zhengjie.base.AppBaseResponse;
  13. import me.zhengjie.base.util.tencent.h5face.SdkTest;
  14. import me.zhengjie.base.util.DateUtils;
  15. import me.zhengjie.base.util.FileUploadUtil;
  16. import me.zhengjie.base.util.StatusEnum.StepStatusEnum;
  17. import me.zhengjie.base.ResponseDTO;
  18. import me.zhengjie.base.ResultCode;
  19. import me.zhengjie.base.BaseController;
  20. import me.zhengjie.dao.mybatis.OrderFileRepository;
  21. import me.zhengjie.dao.mybatis.entity.OrderFileEntity;
  22. import me.zhengjie.modules.security.security.TokenProvider;
  23. import org.apache.commons.collections.CollectionUtils;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.validation.annotation.Validated;
  26. import org.springframework.web.bind.annotation.RequestBody;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import javax.validation.Valid;
  31. import java.util.ArrayList;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.Map;
  35. /**
  36. * 银行端的登录接口
  37. *
  38. * @author auas
  39. *
  40. */
  41. @Validated
  42. @RestController
  43. @RequestMapping("/app/bank")
  44. @Slf4j
  45. @RequiredArgsConstructor
  46. public class AppBankController extends BaseController {
  47. private final ApiBankService apiBankService;
  48. private final FileInfoService fileInfoService;
  49. private final BorrowerService borrowerService;
  50. private final MortgageService mortgageService;
  51. private final GuaranteeService guaranteeService;
  52. private final TokenProvider tokenProvider;
  53. private final OrderService orderService;
  54. private final OrderFileRepository orderFileRepository;
  55. private final TencentHumanFaceVerify faceVerify;
  56. private final UserAXQInfoService userAXQInfoService;
  57. /**
  58. * 登录接口
  59. *
  60. * @param loginVo
  61. * @return
  62. */
  63. @AnonymousPostMapping("/login")
  64. public ResponseDTO<String> login(@Valid @RequestBody BankLoginVo loginVo) {
  65. return apiBankService.login(loginVo);
  66. }
  67. /**
  68. * 得到业务编号
  69. *
  70. * @return
  71. */
  72. @AnonymousPostMapping("/businessNo")
  73. public ResponseDTO<String> businessNo() {
  74. // String str;
  75. String no = "100" + DateUtils.getNo();
  76. return ResponseDTO.success(no);
  77. }
  78. /**
  79. * 保存借款人
  80. *
  81. * @return
  82. */
  83. @RequestMapping("/saveBorrower")
  84. public AppBaseResponse saveBorrower(@Valid @RequestBody BorrowerVo vo) {
  85. log.info("借款人保存请求的参数:" + vo);
  86. String auth = getAuthorization();
  87. String sysUser = (String) tokenProvider.getAppToken(auth);
  88. System.out.println(sysUser);
  89. SysUserEntity entity = new SysUserEntity();
  90. if (StringUtils.isNotBlank(sysUser)) {
  91. entity = JSON.parseObject(sysUser, SysUserEntity.class);
  92. }
  93. return borrowerService.saveBorrowerOrder(vo, entity);
  94. }
  95. /**
  96. * 保存担保人
  97. *
  98. * @return
  99. */
  100. @RequestMapping("/saveGuarantee")
  101. public ResponseDTO<String> saveGuarantee(@Valid @RequestBody GuaranteeVo vo) {
  102. String auth = getAuthorization();
  103. String sysUser = (String) tokenProvider.getAppToken(auth);
  104. SysUserEntity entity = new SysUserEntity();
  105. if (StringUtils.isNotBlank(sysUser)) {
  106. entity = JSON.parseObject(sysUser, SysUserEntity.class);
  107. }
  108. guaranteeService.saveGuarantee(vo, entity);
  109. return ResponseDTO.success();
  110. }
  111. /**
  112. * 保存抵押人
  113. *
  114. * @return
  115. */
  116. @RequestMapping("/saveMortgage")
  117. public ResponseDTO<String> saveMortgage(@Valid @RequestBody MortgageVo vo) {
  118. String auth = getAuthorization();
  119. String sysUser = (String) tokenProvider.getAppToken(auth);
  120. SysUserEntity entity = new SysUserEntity();
  121. if (StringUtils.isNotBlank(sysUser)) {
  122. entity = JSON.parseObject(sysUser, SysUserEntity.class);
  123. }
  124. mortgageService.saveMortgage(vo, entity);
  125. return ResponseDTO.success();
  126. }
  127. /**
  128. * 得到抵押人详细信息
  129. *
  130. * @return
  131. */
  132. @RequestMapping("/getMortgage")
  133. public ResponseDTO<OrderDetailDto> getMortgage(@RequestBody String json) {
  134. JSONObject jsonObj = JSONObject.parseObject(json);
  135. String id = jsonObj.getString("id");
  136. if (StringUtils.isEmpty(id)) {
  137. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  138. }
  139. Map<String, String> map = new HashMap<String, String>();
  140. map.put("id", id);
  141. AppBaseResponse response = mortgageService.mortgageInfo(map);
  142. OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult();
  143. return ResponseDTO.success(detailDto);
  144. }
  145. /**
  146. * 得到担保人详细信息
  147. *
  148. * @return
  149. */
  150. @RequestMapping("/getGuarantee")
  151. public ResponseDTO<OrderDetailDto> getGuarantee(@RequestBody String json) {
  152. JSONObject jsonObj = JSONObject.parseObject(json);
  153. String id = jsonObj.getString("id");
  154. if (StringUtils.isEmpty(id)) {
  155. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  156. }
  157. Map<String, String> map = new HashMap<String, String>();
  158. map.put("id", id);
  159. AppBaseResponse response = guaranteeService.guaranteeInfo(map);
  160. OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult();
  161. return ResponseDTO.success(detailDto);
  162. }
  163. @RequestMapping("/order/search")
  164. public ResponseDTO<?> orderSearch( @RequestBody OrderVo order ) {
  165. if (order == null) {
  166. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  167. }
  168. List<OrderDto> orders = this.orderService.getOrderByContion(order);
  169. return ResponseDTO.success(orders);
  170. }
  171. /**
  172. * 提交订单
  173. *
  174. * @param json
  175. * @return
  176. */
  177. @RequestMapping("/submit")
  178. public AppBaseResponse submit(@RequestBody String json) {
  179. JSONObject jsonObj = JSONObject.parseObject(json);
  180. String businessNo = jsonObj.getString("businessNo");
  181. return orderService.submitOrder(businessNo, getCurrentUser());
  182. }
  183. /**
  184. * 文件和图片
  185. *
  186. * @return
  187. */
  188. @RequestMapping("/uploadFiles")
  189. public ResponseDTO<List<FileInfoDto>> uploadFiles(@Valid FileUploadVo file) {
  190. log.info("文件上传参数:" + file);
  191. String value = StepStatusEnum.getValue(Integer.valueOf(file.getStep()));
  192. if (StringUtils.isEmpty(value)) {
  193. return ResponseDTO.error(ResultCode.BUSINESS_PROCESS_ERROR);
  194. }
  195. List<MultipartFile> fileUpload = file.getFileUpload();
  196. if (CollectionUtils.isEmpty(fileUpload)) {
  197. return ResponseDTO.error(ResultCode.FILE_DOES_NOT_EXIST);
  198. }
  199. List<FileInfoDto> fileDtos = new ArrayList<>();
  200. // 顺序
  201. Integer order = 1;
  202. for (MultipartFile partFile : fileUpload) {
  203. FileInfoDto filedto = new FileInfoDto();
  204. file.setOrder(order++);
  205. String filePath = FileUploadUtil.uploadFile(file, partFile);
  206. if (StringUtils.isEmpty(filePath)) {
  207. return ResponseDTO.error(ResultCode.BUSINESS_IMAGE_UPLOAD_ERROR);
  208. }
  209. JSONObject json = fileInfoService.saveFile(file, filePath);
  210. filedto.setImageId(json.getString("imageId"));
  211. filedto.setUrl(json.getString("url"));
  212. fileDtos.add(filedto);
  213. }
  214. log.info("文件上传结果返回:" + fileDtos);
  215. return ResponseDTO.success(fileDtos);
  216. }
  217. /**
  218. * 获取借款人信息
  219. *
  220. * @param json
  221. * @return
  222. */
  223. @RequestMapping("/getBorrower")
  224. public ResponseDTO<OrderDetailDto> getBorrower(@RequestBody String json) {
  225. JSONObject jsonObj = JSONObject.parseObject(json);
  226. String id = jsonObj.getString("id");
  227. if (StringUtils.isEmpty(id)) {
  228. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  229. }
  230. Map<String, String> map = new HashMap<String, String>();
  231. map.put("id", id);
  232. AppBaseResponse response = borrowerService.borrowerInfo(map);
  233. OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult();
  234. return ResponseDTO.success(detailDto);
  235. }
  236. /**
  237. * 上传身份证,现在是base64位,这里需要业务流水号
  238. *
  239. * @return
  240. */
  241. @RequestMapping("/uploadCard")
  242. public ResponseDTO<JSONObject> uploadCard(@Valid @RequestBody ImageUploadVo image) {
  243. String value = StepStatusEnum.getValue(Integer.valueOf(image.getStep()));
  244. if (StringUtils.isEmpty(value)) {
  245. return ResponseDTO.error(ResultCode.BUSINESS_PROCESS_ERROR);
  246. }
  247. // FIL
  248. if (StringUtils.isBlank(image.getOrder())) {
  249. image.setOrder("1");
  250. }
  251. String filePath = FileUploadUtil.saveImage(image);
  252. if (StringUtils.isEmpty(filePath)) {
  253. return ResponseDTO.error(ResultCode.BUSINESS_IMAGE_UPLOAD_ERROR);
  254. }
  255. JSONObject json = fileInfoService.saveCard(image, filePath);
  256. return ResponseDTO.success(json);
  257. }
  258. /**
  259. * 订单列表
  260. *
  261. * @param json
  262. * @return
  263. */
  264. @RequestMapping("/order/list")
  265. public ResponseDTO<?> getOrderList(@RequestBody String json) {
  266. JSONObject jsonObj = JSONObject.parseObject(json);
  267. String phone = jsonObj.getString("phone");
  268. String status = jsonObj.getString("status");
  269. Integer startIndex = 1;
  270. Integer size = Integer.MAX_VALUE;
  271. List<OrderEntity> list = borrowerService.getOrderList(phone, status, startIndex, size);
  272. return ResponseDTO.success(list);
  273. }
  274. /**
  275. * 得到抵押人,借款人,担保人订单
  276. *
  277. * @param json
  278. * @return
  279. */
  280. @RequestMapping("/sub/order/list")
  281. public ResponseDTO<?> getSubOrderList(@RequestBody String json) {
  282. JSONObject jsonObj = JSONObject.parseObject(json);
  283. String phone = jsonObj.getString("businessNo");
  284. String status = jsonObj.getString("status");
  285. Integer startIndex = 1;
  286. Integer size = Integer.MAX_VALUE;
  287. List<OrderDto> list = borrowerService.getSubOrderList(phone, status, startIndex, size);
  288. return ResponseDTO.success(list);
  289. }
  290. @RequestMapping("/order/detail")
  291. public ResponseDTO<?> getDetail(@RequestBody String json) {
  292. JSONObject jsonObj = JSONObject.parseObject(json);
  293. String orderId = jsonObj.getString("orderId");
  294. if (StringUtils.isEmpty(orderId)) {
  295. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  296. }
  297. OrderDto order = this.orderService.getOrderById(orderId);
  298. if (order == null) {
  299. return ResponseDTO.error(ResultCode.ORDER_DATA_NOT_EXIST);
  300. }
  301. return ResponseDTO.success(order);
  302. }
  303. // 得到公证书
  304. @RequestMapping("/getNotarization")
  305. public ResponseDTO<?> getNotarization(@RequestBody String json) {
  306. JSONObject jsonObj = JSONObject.parseObject(json);
  307. String orderId = jsonObj.getString("orderId");
  308. OrderFileEntity orderFile = orderFileRepository.getOrderNotarization(orderId);
  309. return ResponseDTO.success(orderFile.getSignedPdfUrl());
  310. }
  311. // ocr解析
  312. @RequestMapping("/orderOCRParser")
  313. public ResponseDTO<?> orderOCRParser(@RequestBody String json) {
  314. JSONObject jsonObj = JSONObject.parseObject(json);
  315. String orderType = jsonObj.getString("orderType");
  316. String content = jsonObj.getString("content");
  317. Object object = orderService.parseOrder(orderType, content, getCurrentUser());
  318. if (object == null) {
  319. return ResponseDTO.error(ResultCode.ORDER_OCR_SERVICE_UNAVAILABLE);
  320. }
  321. return ResponseDTO.success(object);
  322. }
  323. @RequestMapping("/axqRegister")
  324. public ResponseDTO<?> axqRegister(@RequestBody String json) {
  325. JSONObject jsonObj = JSONObject.parseObject(json);
  326. String idCard = jsonObj.getString("idCard");
  327. String phone = jsonObj.getString("phone");
  328. String name = jsonObj.getString("name");
  329. if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(phone) || StringUtils.isEmpty(name)) {
  330. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  331. }
  332. return userAXQInfoService.registAXQUser(idCard, phone, name);
  333. }
  334. // 人脸核身
  335. @RequestMapping("/order/getFaceId")
  336. public ResponseDTO<?> getFaceId(@RequestBody String json) throws Exception {
  337. JSONObject jsonObj = JSONObject.parseObject(json);
  338. String orderId = jsonObj.getString("orderId");
  339. if (StringUtils.isEmpty(orderId)) {
  340. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  341. }
  342. OrderDto order = this.apiBankService.getOrderDetail(orderId);
  343. JSONObject str = SdkTest.getFaceId(faceVerify.getBankWebankAppId(), faceVerify.getBankSecret(),
  344. faceVerify.getBankKeyLicence(), order.getUsername(), order.getIdCard(), orderId);
  345. return ResponseDTO.success(str);
  346. }
  347. @AnonymousPostMapping("/video/call")
  348. public ResponseDTO<?> videoCall(@RequestBody String json) {
  349. return this.apiBankService.videoCall(json);
  350. }
  351. @RequestMapping("/order/pdf")
  352. public ResponseDTO<?> getOrderPDF(@RequestBody String json) {
  353. JSONObject jsonObj = JSONObject.parseObject(json);
  354. String orderId = jsonObj.getString("orderId");
  355. if (StringUtils.isEmpty(orderId)) {
  356. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  357. }
  358. ResponseDTO<?> order = this.apiBankService.getOrderPDF(orderId);
  359. return order;
  360. }
  361. @AnonymousPostMapping("/order/note")
  362. public ResponseDTO<?> note(@RequestBody String json) {
  363. JSONObject jsonObj = JSONObject.parseObject(json);
  364. String orderId = jsonObj.getString("orderId");
  365. if (StringUtils.isEmpty(orderId)) {
  366. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  367. }
  368. //
  369. OrderFileEntity orderFile = orderFileRepository.getOrderNote(orderId);
  370. // pdf的地址预览
  371. String noteUrl = FileUploadUtil.getPreviewUrl(orderFile.getHtmlUrl());
  372. return ResponseDTO.success(noteUrl);
  373. }
  374. @RequestMapping("/sendAuthMessage")
  375. public ResponseDTO<?> sendAuthMessage(@RequestBody String json) {
  376. JSONObject jsonObj = JSONObject.parseObject(json);
  377. String idCard = jsonObj.getString("idCard");
  378. if (StringUtils.isEmpty(idCard)) {
  379. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  380. }
  381. return userAXQInfoService.sendAuthMessage(idCard);
  382. }
  383. @RequestMapping("/verifyAuthMessage")
  384. public ResponseDTO<?> verifyAuthMessage(@RequestBody String json) {
  385. JSONObject jsonObj = JSONObject.parseObject(json);
  386. String idCard = jsonObj.getString("idCard");
  387. String checkCode = jsonObj.getString("checkCode");
  388. if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(checkCode)) {
  389. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  390. }
  391. return userAXQInfoService.verifyAuthMessage(idCard, checkCode);
  392. }
  393. @RequestMapping("/order/updateStatus")
  394. public ResponseDTO<?> updateOrderStatus(@RequestBody String json) throws Exception {
  395. JSONObject jsonObj = JSONObject.parseObject(json);
  396. String orderId = jsonObj.getString("orderId");
  397. if (StringUtils.isEmpty(orderId)) {
  398. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  399. }
  400. orderService.updateOrderStatus(orderId);
  401. return ResponseDTO.success();
  402. }
  403. @RequestMapping("/getAuthStatus")
  404. public ResponseDTO<?> getAuthStatus(@RequestBody String json) {
  405. JSONObject jsonObj = JSONObject.parseObject(json);
  406. String idCard = jsonObj.getString("idCard");
  407. if (StringUtils.isEmpty(idCard)) {
  408. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  409. }
  410. return userAXQInfoService.getAuthStatus(idCard);
  411. }
  412. @AnonymousPostMapping("/uploadSeal")
  413. public ResponseDTO<?> uploadSeal(@RequestBody String json) {
  414. JSONObject jsonObj = JSONObject.parseObject(json);
  415. String idCard = jsonObj.getString("idCard");
  416. String contractId = jsonObj.getString("contractId");
  417. String content = jsonObj.getString("content");
  418. if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(contractId) || StringUtils.isEmpty(content)) {
  419. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  420. }
  421. return userAXQInfoService.uploadSeal(idCard, contractId, content);
  422. }
  423. }