package me.zhengjie.application.bank.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.rest.AnonymousPostMapping; import me.zhengjie.application.bank.controller.vo.*; import me.zhengjie.application.bank.service.*; import me.zhengjie.base.config.TencentHumanFaceVerify; import me.zhengjie.dao.mybatis.entity.OrderEntity; import me.zhengjie.dao.mybatis.entity.SysUserEntity; import me.zhengjie.base.AppBaseResponse; import me.zhengjie.base.util.tencent.h5face.SdkTest; import me.zhengjie.base.util.DateUtils; import me.zhengjie.base.util.FileUploadUtil; import me.zhengjie.base.util.StatusEnum.StepStatusEnum; import me.zhengjie.base.ResponseDTO; import me.zhengjie.base.ResultCode; import me.zhengjie.base.BaseController; import me.zhengjie.dao.mybatis.OrderFileRepository; import me.zhengjie.dao.mybatis.entity.OrderFileEntity; import me.zhengjie.security.security.TokenProvider; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 银行端的登录接口 * * @author auas * */ @Validated @RestController @RequestMapping("/app/bank") @Slf4j @RequiredArgsConstructor public class AppBankController extends BaseController { private final ApiBankService apiBankService; private final FileInfoService fileInfoService; private final BorrowerService borrowerService; private final MortgageService mortgageService; private final GuaranteeService guaranteeService; private final TokenProvider tokenProvider; private final OrderService orderService; private final OrderFileRepository orderFileRepository; private final TencentHumanFaceVerify faceVerify; private final UserAXQInfoService userAXQInfoService; /** * 登录接口 * * @param loginVo * @return */ @AnonymousPostMapping("/login") public ResponseDTO login(@Valid @RequestBody BankLoginVo loginVo) { return apiBankService.login(loginVo); } /** * 得到业务编号 * * @return */ @AnonymousPostMapping("/businessNo") public ResponseDTO businessNo() { // String str; String no = "100" + DateUtils.getNo(); return ResponseDTO.success(no); } /** * 保存借款人 * * @return */ @RequestMapping("/saveBorrower") public AppBaseResponse saveBorrower( @RequestBody BorrowerVo vo) { log.info("借款人保存请求的参数:" + vo); String auth = getAuthorization(); String sysUser = (String) tokenProvider.getAppToken(auth); System.out.println(sysUser); SysUserEntity entity = new SysUserEntity(); if (StringUtils.isNotBlank(sysUser)) { entity = JSON.parseObject(sysUser, SysUserEntity.class); } return borrowerService.saveBorrowerOrder(vo, entity); } /** * 保存担保人 * * @return */ @RequestMapping("/saveGuarantee") public ResponseDTO saveGuarantee( @RequestBody GuaranteeVo vo) { String auth = getAuthorization(); String sysUser = (String) tokenProvider.getAppToken(auth); SysUserEntity entity = new SysUserEntity(); if (StringUtils.isNotBlank(sysUser)) { entity = JSON.parseObject(sysUser, SysUserEntity.class); } guaranteeService.saveGuarantee(vo, entity); return ResponseDTO.success(); } /** * 保存抵押人 * * @return */ @RequestMapping("/saveMortgage") public ResponseDTO saveMortgage( @RequestBody MortgageVo vo) { String auth = getAuthorization(); String sysUser = (String) tokenProvider.getAppToken(auth); SysUserEntity entity = new SysUserEntity(); if (StringUtils.isNotBlank(sysUser)) { entity = JSON.parseObject(sysUser, SysUserEntity.class); } mortgageService.saveMortgage(vo, entity); return ResponseDTO.success(); } /** * 得到抵押人详细信息 * * @return */ @RequestMapping("/getMortgage") public ResponseDTO getMortgage(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String id = jsonObj.getString("id"); if (StringUtils.isEmpty(id)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } Map map = new HashMap(); map.put("id", id); AppBaseResponse response = mortgageService.mortgageInfo(map); OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult(); return ResponseDTO.success(detailDto); } /** * 得到担保人详细信息 * * @return */ @RequestMapping("/getGuarantee") public ResponseDTO getGuarantee(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String id = jsonObj.getString("id"); if (StringUtils.isEmpty(id)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } Map map = new HashMap(); map.put("id", id); AppBaseResponse response = guaranteeService.guaranteeInfo(map); OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult(); return ResponseDTO.success(detailDto); } @RequestMapping("/order/search") public ResponseDTO orderSearch(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String phone = jsonObj.getString("phone"); String status = jsonObj.getString("status"); String contractNo = jsonObj.getString("contractNo"); Integer startIndex = 1; Integer size = Integer.MAX_VALUE; List list = borrowerService.getOrderList(contractNo,phone, status, startIndex, size); return ResponseDTO.success(list); } /** * 提交订单 * * @param json * @return */ @RequestMapping("/submit") public AppBaseResponse submit(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); return orderService.submitOrder(businessNo, getCurrentUser()); } /** * 文件和图片 * * @return */ @RequestMapping("/uploadFiles") public ResponseDTO> uploadFiles(@Valid FileUploadVo file) { log.info("文件上传参数:" + file); String value = StepStatusEnum.getValue(Integer.valueOf(file.getStep())); if (StringUtils.isEmpty(value)) { return ResponseDTO.error(ResultCode.BUSINESS_PROCESS_ERROR); } List fileUpload = file.getFileUpload(); if (CollectionUtils.isEmpty(fileUpload)) { return ResponseDTO.error(ResultCode.FILE_DOES_NOT_EXIST); } List fileDtos = new ArrayList<>(); // 顺序 Integer order = 1; for (MultipartFile partFile : fileUpload) { FileInfoDto filedto = new FileInfoDto(); file.setOrder(order++); String filePath = FileUploadUtil.uploadFile(file, partFile); if (StringUtils.isEmpty(filePath)) { return ResponseDTO.error(ResultCode.BUSINESS_IMAGE_UPLOAD_ERROR); } JSONObject json = fileInfoService.saveFile(file, filePath); filedto.setImageId(json.getString("imageId")); filedto.setUrl(json.getString("url")); fileDtos.add(filedto); } log.info("文件上传结果返回:" + fileDtos); return ResponseDTO.success(fileDtos); } /** * 获取借款人信息 * * @param json * @return */ @RequestMapping("/getBorrower") public ResponseDTO getBorrower(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String id = jsonObj.getString("id"); if (StringUtils.isEmpty(id)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } Map map = new HashMap(); map.put("id", id); AppBaseResponse response = borrowerService.borrowerInfo(map); OrderDetailDto detailDto = (OrderDetailDto) response.getData().getResult(); return ResponseDTO.success(detailDto); } /** * 上传身份证,现在是base64位,这里需要业务流水号 * * @return */ @RequestMapping("/uploadCard") public ResponseDTO uploadCard(@Valid @RequestBody ImageUploadVo image) { String value = StepStatusEnum.getValue(Integer.valueOf(image.getStep())); if (StringUtils.isEmpty(value)) { return ResponseDTO.error(ResultCode.BUSINESS_PROCESS_ERROR); } // FIL if (StringUtils.isBlank(image.getOrder())) { image.setOrder("1"); } String filePath = FileUploadUtil.saveImage(image); if (StringUtils.isEmpty(filePath)) { return ResponseDTO.error(ResultCode.BUSINESS_IMAGE_UPLOAD_ERROR); } JSONObject json = fileInfoService.saveCard(image, filePath); return ResponseDTO.success(json); } /** * 订单列表 * * @param json * @return */ @RequestMapping("/order/list") public ResponseDTO getOrderList(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String phone = jsonObj.getString("phone"); String status = jsonObj.getString("status"); String contractNo = jsonObj.getString("contractNo"); Integer startIndex = 1; Integer size = Integer.MAX_VALUE; List list = borrowerService.getOrderList(contractNo,phone, status, startIndex, size); return ResponseDTO.success(list); } /** * 得到抵押人,借款人,担保人订单 * * @param json * @return */ @RequestMapping("/sub/order/list") public ResponseDTO getSubOrderList(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); String status = jsonObj.getString("status"); Integer startIndex = 1; Integer size = Integer.MAX_VALUE; List list = borrowerService.getSubOrderList(businessNo, status, startIndex, size); return ResponseDTO.success(list); } @RequestMapping("/order/detail") public ResponseDTO getDetail(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String orderId = jsonObj.getString("orderId"); if (StringUtils.isEmpty(orderId)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } OrderDto order = this.orderService.getOrderById(orderId); if (order == null) { return ResponseDTO.error(ResultCode.ORDER_DATA_NOT_EXIST); } return ResponseDTO.success(order); } // 得到公证书 @RequestMapping("/getNotarization") public ResponseDTO getNotarization(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String orderId = jsonObj.getString("orderId"); OrderFileEntity orderFile = orderFileRepository.getOrderNotarization(orderId); return ResponseDTO.success(orderFile.getSignedPdfUrl()); } // ocr解析 @RequestMapping("/orderOCRParser") public ResponseDTO orderOCRParser(MultipartFile file, String orderType) { Object object = orderService.parseOrder(orderType, file, getCurrentUser()); if (object == null) { return ResponseDTO.error(ResultCode.ORDER_OCR_SERVICE_UNAVAILABLE); } return ResponseDTO.success(object); } @RequestMapping("/axqRegister") public ResponseDTO axqRegister(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); String phone = jsonObj.getString("phone"); String name = jsonObj.getString("name"); if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(phone) || StringUtils.isEmpty(name)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.registAXQUser(idCard, phone, name); } // 人脸核身 @RequestMapping("/order/getFaceId") public ResponseDTO getFaceId(@RequestBody String json) throws Exception { JSONObject jsonObj = JSONObject.parseObject(json); String orderId = jsonObj.getString("orderId"); if (StringUtils.isEmpty(orderId)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } OrderDto order = this.apiBankService.getOrderDetail(orderId); JSONObject str = SdkTest.getFaceId(faceVerify.getBankWebankAppId(), faceVerify.getBankSecret(), faceVerify.getBankKeyLicence(), order.getUsername(), order.getIdCard(), orderId); return ResponseDTO.success(str); } @AnonymousPostMapping("/video/call") public ResponseDTO videoCall(@RequestBody String json) { return this.apiBankService.videoCall(json); } @RequestMapping("/order/pdf") public ResponseDTO getOrderPDF(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String orderId = jsonObj.getString("orderId"); if (StringUtils.isEmpty(orderId)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } ResponseDTO order = this.apiBankService.getOrderPDF(orderId); return order; } @AnonymousPostMapping("/order/note") public ResponseDTO note(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String orderId = jsonObj.getString("orderId"); if (StringUtils.isEmpty(orderId)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } // OrderFileEntity orderFile = orderFileRepository.getOrderNote(orderId); // pdf的地址预览 String noteUrl = FileUploadUtil.getPreviewUrl(orderFile.getHtmlUrl()); return ResponseDTO.success(noteUrl); } @RequestMapping("/sendAuthMessage") public ResponseDTO sendAuthMessage(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); if (StringUtils.isEmpty(idCard)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.sendAuthMessage(idCard); } @RequestMapping("/verifyAuthMessage") public ResponseDTO verifyAuthMessage(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); String checkCode = jsonObj.getString("checkCode"); if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(checkCode)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.verifyAuthMessage(idCard, checkCode); } @RequestMapping("/order/updateStatus") public ResponseDTO updateOrderStatus(@RequestBody String json) throws Exception { JSONObject jsonObj = JSONObject.parseObject(json); String orderId = jsonObj.getString("orderId"); if (StringUtils.isEmpty(orderId)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } orderService.updateOrderStatus(orderId); return ResponseDTO.success(); } @RequestMapping("/getAuthStatus") public ResponseDTO getAuthStatus(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); if (StringUtils.isEmpty(idCard)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.getAuthStatus(idCard); } @AnonymousPostMapping("/uploadSeal") public ResponseDTO uploadSeal(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String idCard = jsonObj.getString("idCard"); String contractId = jsonObj.getString("contractId"); String content = jsonObj.getString("content"); if (StringUtils.isEmpty(idCard) || StringUtils.isEmpty(contractId) || StringUtils.isEmpty(content)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } return userAXQInfoService.uploadSeal(idCard, contractId, content); } }