AppBankController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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.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( @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( @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( @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 String json) {
  165. JSONObject jsonObj = JSONObject.parseObject(json);
  166. String phone = jsonObj.getString("phone");
  167. String status = jsonObj.getString("status");
  168. String contractNo = jsonObj.getString("contractNo");
  169. Integer startIndex = 1;
  170. Integer size = Integer.MAX_VALUE;
  171. List<OrderEntity> list = borrowerService.getOrderList(contractNo,phone, status, startIndex, size);
  172. return ResponseDTO.success(list);
  173. }
  174. /**
  175. * 提交订单
  176. *
  177. * @param json
  178. * @return
  179. */
  180. @RequestMapping("/submit")
  181. public AppBaseResponse submit(@RequestBody String json) {
  182. JSONObject jsonObj = JSONObject.parseObject(json);
  183. String businessNo = jsonObj.getString("businessNo");
  184. return orderService.submitOrder(businessNo, getCurrentUser());
  185. }
  186. /**
  187. * 文件和图片
  188. *
  189. * @return
  190. */
  191. @RequestMapping("/uploadFiles")
  192. public ResponseDTO<List<FileInfoDto>> uploadFiles(@Valid FileUploadVo file) {
  193. log.info("文件上传参数:" + file);
  194. String value = StepStatusEnum.getValue(Integer.valueOf(file.getStep()));
  195. if (StringUtils.isEmpty(value)) {
  196. return ResponseDTO.error(ResultCode.BUSINESS_PROCESS_ERROR);
  197. }
  198. List<MultipartFile> fileUpload = file.getFileUpload();
  199. if (CollectionUtils.isEmpty(fileUpload)) {
  200. return ResponseDTO.error(ResultCode.FILE_DOES_NOT_EXIST);
  201. }
  202. List<FileInfoDto> fileDtos = new ArrayList<>();
  203. // 顺序
  204. Integer order = 1;
  205. for (MultipartFile partFile : fileUpload) {
  206. FileInfoDto filedto = new FileInfoDto();
  207. file.setOrder(order++);
  208. String filePath = FileUploadUtil.uploadFile(file, partFile);
  209. if (StringUtils.isEmpty(filePath)) {
  210. return ResponseDTO.error(ResultCode.BUSINESS_IMAGE_UPLOAD_ERROR);
  211. }
  212. JSONObject json = fileInfoService.saveFile(file, filePath);
  213. filedto.setImageId(json.getString("imageId"));
  214. filedto.setUrl(json.getString("url"));
  215. fileDtos.add(filedto);
  216. }
  217. log.info("文件上传结果返回:" + fileDtos);
  218. return ResponseDTO.success(fileDtos);
  219. }
  220. /**
  221. * 获取借款人信息
  222. *
  223. * @param json
  224. * @return
  225. */
  226. @RequestMapping("/getBorrower")
  227. public ResponseDTO<OrderDetailDto> getBorrower(@RequestBody String json) {
  228. JSONObject jsonObj = JSONObject.parseObject(json);
  229. String id = jsonObj.getString("id");
  230. if (StringUtils.isEmpty(id)) {
  231. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  232. }
  233. Map<String, String> map = new HashMap<String, String>();
  234. map.put("id", id);
  235. AppBaseResponse response = borrowerService.borrowerInfo(map);
  236. OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult();
  237. return ResponseDTO.success(detailDto);
  238. }
  239. /**
  240. * 上传身份证,现在是base64位,这里需要业务流水号
  241. *
  242. * @return
  243. */
  244. @RequestMapping("/uploadCard")
  245. public ResponseDTO<JSONObject> uploadCard(@Valid @RequestBody ImageUploadVo image) {
  246. String value = StepStatusEnum.getValue(Integer.valueOf(image.getStep()));
  247. if (StringUtils.isEmpty(value)) {
  248. return ResponseDTO.error(ResultCode.BUSINESS_PROCESS_ERROR);
  249. }
  250. // FIL
  251. if (StringUtils.isBlank(image.getOrder())) {
  252. image.setOrder("1");
  253. }
  254. String filePath = FileUploadUtil.saveImage(image);
  255. if (StringUtils.isEmpty(filePath)) {
  256. return ResponseDTO.error(ResultCode.BUSINESS_IMAGE_UPLOAD_ERROR);
  257. }
  258. JSONObject json = fileInfoService.saveCard(image, filePath);
  259. return ResponseDTO.success(json);
  260. }
  261. /**
  262. * 订单列表
  263. *
  264. * @param json
  265. * @return
  266. */
  267. @RequestMapping("/order/list")
  268. public ResponseDTO<?> getOrderList(@RequestBody String json) {
  269. JSONObject jsonObj = JSONObject.parseObject(json);
  270. String phone = jsonObj.getString("phone");
  271. String status = jsonObj.getString("status");
  272. String contractNo = jsonObj.getString("contractNo");
  273. Integer startIndex = 1;
  274. Integer size = Integer.MAX_VALUE;
  275. List<OrderEntity> list = borrowerService.getOrderList(contractNo,phone, status, startIndex, size);
  276. return ResponseDTO.success(list);
  277. }
  278. /**
  279. * 得到抵押人,借款人,担保人订单
  280. *
  281. * @param json
  282. * @return
  283. */
  284. @RequestMapping("/sub/order/list")
  285. public ResponseDTO<?> getSubOrderList(@RequestBody String json) {
  286. JSONObject jsonObj = JSONObject.parseObject(json);
  287. String businessNo = jsonObj.getString("businessNo");
  288. String status = jsonObj.getString("status");
  289. Integer startIndex = 1;
  290. Integer size = Integer.MAX_VALUE;
  291. List<OrderDto> list = borrowerService.getSubOrderList(businessNo, status, startIndex, size);
  292. return ResponseDTO.success(list);
  293. }
  294. @RequestMapping("/order/detail")
  295. public ResponseDTO<?> getDetail(@RequestBody String json) {
  296. JSONObject jsonObj = JSONObject.parseObject(json);
  297. String orderId = jsonObj.getString("orderId");
  298. if (StringUtils.isEmpty(orderId)) {
  299. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  300. }
  301. OrderDto order = this.orderService.getOrderById(orderId);
  302. if (order == null) {
  303. return ResponseDTO.error(ResultCode.ORDER_DATA_NOT_EXIST);
  304. }
  305. return ResponseDTO.success(order);
  306. }
  307. // 得到公证书
  308. @RequestMapping("/getNotarization")
  309. public ResponseDTO<?> getNotarization(@RequestBody String json) {
  310. JSONObject jsonObj = JSONObject.parseObject(json);
  311. String orderId = jsonObj.getString("orderId");
  312. OrderFileEntity orderFile = orderFileRepository.getOrderNotarization(orderId);
  313. return ResponseDTO.success(orderFile.getSignedPdfUrl());
  314. }
  315. // ocr解析
  316. @RequestMapping("/orderOCRParser")
  317. public ResponseDTO<?> orderOCRParser(MultipartFile file, String orderType) {
  318. Object object = orderService.parseOrder(orderType, file, getCurrentUser());
  319. if (object == null) {
  320. return ResponseDTO.error(ResultCode.ORDER_OCR_SERVICE_UNAVAILABLE);
  321. }
  322. return ResponseDTO.success(object);
  323. }
  324. @RequestMapping("/axqRegister")
  325. public ResponseDTO<?> axqRegister(@RequestBody String json) {
  326. JSONObject jsonObj = JSONObject.parseObject(json);
  327. String idCard = jsonObj.getString("idCard");
  328. String phone = jsonObj.getString("phone");
  329. String name = jsonObj.getString("name");
  330. if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(phone) || StringUtils.isEmpty(name)) {
  331. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  332. }
  333. return userAXQInfoService.registAXQUser(idCard, phone, name);
  334. }
  335. // 人脸核身
  336. @RequestMapping("/order/getFaceId")
  337. public ResponseDTO<?> getFaceId(@RequestBody String json) throws Exception {
  338. JSONObject jsonObj = JSONObject.parseObject(json);
  339. String orderId = jsonObj.getString("orderId");
  340. if (StringUtils.isEmpty(orderId)) {
  341. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  342. }
  343. OrderDto order = this.apiBankService.getOrderDetail(orderId);
  344. JSONObject str = SdkTest.getFaceId(faceVerify.getBankWebankAppId(), faceVerify.getBankSecret(),
  345. faceVerify.getBankKeyLicence(), order.getUsername(), order.getIdCard(), orderId);
  346. return ResponseDTO.success(str);
  347. }
  348. @AnonymousPostMapping("/video/call")
  349. public ResponseDTO<?> videoCall(@RequestBody String json) {
  350. return this.apiBankService.videoCall(json);
  351. }
  352. @RequestMapping("/order/pdf")
  353. public ResponseDTO<?> getOrderPDF(@RequestBody String json) {
  354. JSONObject jsonObj = JSONObject.parseObject(json);
  355. String orderId = jsonObj.getString("orderId");
  356. if (StringUtils.isEmpty(orderId)) {
  357. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  358. }
  359. ResponseDTO<?> order = this.apiBankService.getOrderPDF(orderId);
  360. return order;
  361. }
  362. @AnonymousPostMapping("/order/note")
  363. public ResponseDTO<?> note(@RequestBody String json) {
  364. JSONObject jsonObj = JSONObject.parseObject(json);
  365. String orderId = jsonObj.getString("orderId");
  366. if (StringUtils.isEmpty(orderId)) {
  367. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  368. }
  369. //
  370. OrderFileEntity orderFile = orderFileRepository.getOrderNote(orderId);
  371. // pdf的地址预览
  372. String noteUrl = FileUploadUtil.getPreviewUrl(orderFile.getHtmlUrl());
  373. return ResponseDTO.success(noteUrl);
  374. }
  375. @RequestMapping("/sendAuthMessage")
  376. public ResponseDTO<?> sendAuthMessage(@RequestBody String json) {
  377. JSONObject jsonObj = JSONObject.parseObject(json);
  378. String idCard = jsonObj.getString("idCard");
  379. if (StringUtils.isEmpty(idCard)) {
  380. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  381. }
  382. return userAXQInfoService.sendAuthMessage(idCard);
  383. }
  384. @RequestMapping("/verifyAuthMessage")
  385. public ResponseDTO<?> verifyAuthMessage(@RequestBody String json) {
  386. JSONObject jsonObj = JSONObject.parseObject(json);
  387. String idCard = jsonObj.getString("idCard");
  388. String checkCode = jsonObj.getString("checkCode");
  389. if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(checkCode)) {
  390. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  391. }
  392. return userAXQInfoService.verifyAuthMessage(idCard, checkCode);
  393. }
  394. @RequestMapping("/order/updateStatus")
  395. public ResponseDTO<?> updateOrderStatus(@RequestBody String json) throws Exception {
  396. JSONObject jsonObj = JSONObject.parseObject(json);
  397. String orderId = jsonObj.getString("orderId");
  398. if (StringUtils.isEmpty(orderId)) {
  399. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  400. }
  401. orderService.updateOrderStatus(orderId);
  402. return ResponseDTO.success();
  403. }
  404. @RequestMapping("/getAuthStatus")
  405. public ResponseDTO<?> getAuthStatus(@RequestBody String json) {
  406. JSONObject jsonObj = JSONObject.parseObject(json);
  407. String idCard = jsonObj.getString("idCard");
  408. if (StringUtils.isEmpty(idCard)) {
  409. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  410. }
  411. return userAXQInfoService.getAuthStatus(idCard);
  412. }
  413. @AnonymousPostMapping("/uploadSeal")
  414. public ResponseDTO<?> uploadSeal(@RequestBody String json) {
  415. JSONObject jsonObj = JSONObject.parseObject(json);
  416. String idCard = jsonObj.getString("idCard");
  417. String contractId = jsonObj.getString("contractId");
  418. String content = jsonObj.getString("content");
  419. if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(contractId) || StringUtils.isEmpty(content)) {
  420. return ResponseDTO.error(ResultCode.PARAM_IS_BLANK);
  421. }
  422. return userAXQInfoService.uploadSeal(idCard, contractId, content);
  423. }
  424. }