| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.yami.trading.bean.loan.LoanParam; |
| | | import com.yami.trading.bean.loan.SimpleLoanOrder; |
| | | import com.yami.trading.bean.model.User; |
| | | import com.yami.trading.common.util.DateTimeTools; |
| | | import com.yami.trading.common.util.UUIDGenerator; |
| | | import com.yami.trading.common.web.ResultObject; |
| | | import com.yami.trading.security.common.util.SecurityUtils; |
| | | import com.yami.trading.service.syspara.SysparaService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.core.token.TokenService; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | |
| | | */ |
| | | @Autowired |
| | | private LoanService loanService; |
| | | |
| | | |
| | | @Autowired |
| | | UserService userService; |
| | | |
| | | @Autowired |
| | | SysparaService sysparaService; |
| | | |
| | | /** |
| | | * Token服务 |
| | | */ |
| | | // @Autowired |
| | | // private TokenService tokenService; |
| | | |
| | | |
| | | /** |
| | | * SLF4J日志组件 |
| | | */ |
| | | private static final Logger logger = LoggerFactory.getLogger(LoanController.class); |
| | | |
| | | |
| | | /** |
| | | * 借贷额度正则式 |
| | | */ |
| | | private static final Pattern QUOTA_REGEX=Pattern.compile("([A-Z]{2,8}):([1-9]{1}[0-9]{0,7})"); |
| | | |
| | | |
| | | /** |
| | | * 获取借贷参数 |
| | | * @param configId 配置ID |
| | |
| | | @RequestMapping("/api/loan!get.action") |
| | | public ResultObject getParams(String configId) { |
| | | ResultObject resultObject = new ResultObject(); |
| | | |
| | | |
| | | try { |
| | | HashMap<String,Object> paramMap=loanService.getLoanParams(configId); |
| | | if(null==paramMap) { |
| | |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | |
| | | |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取借贷参数 |
| | | * @param request 配置ID |
| | |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | } |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提交借贷申请 |
| | | * @param request 请求对象 |
| | |
| | | @RequestMapping("/api/loan!apply.action") |
| | | public ResultObject apply(HttpServletRequest request) { |
| | | ResultObject resultObject = new ResultObject(); |
| | | |
| | | |
| | | // String token=request.getParameter("token"); |
| | | // if(null==token || (token=token.trim()).isEmpty()) { |
| | | // resultObject.setCode("1"); |
| | | // resultObject.setMsg("从请求参数中获取Token为空!"); |
| | | // return resultObject; |
| | | // } |
| | | |
| | | |
| | | // String partyId=tokenService.cacheGet(token); |
| | | String partyId = SecurityUtils.getCurrentUserId(); |
| | | if(null==partyId) { |
| | |
| | | resultObject.setMsg("通过Token获取partyId为空!"); |
| | | return resultObject; |
| | | } |
| | | |
| | | String term=getParamValue(request,resultObject,"term"); |
| | | if(null==term) return resultObject; |
| | | |
| | | |
| | | /*String term=getParamValue(request,resultObject,"term"); |
| | | if(null==term) return resultObject;*/ |
| | | |
| | | String quota=getParamValue(request,resultObject,"quota"); |
| | | if(null==quota) return resultObject; |
| | | if (Integer.parseInt(quota) <= 0) { |
| | |
| | | resultObject.setMsg("请输入正确金额"); |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | User party = userService.getById(partyId); |
| | | if (party.getLoanLimit() == 0 || Integer.parseInt(quota) > party.getLoanLimit()) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("贷款额度不足"); |
| | | return resultObject; |
| | | } |
| | | |
| | | String symbol=getParamValue(request,resultObject,"symbol"); |
| | | if(null==symbol) return resultObject; |
| | | |
| | | String dailyRate=getParamValue(request,resultObject,"dailyRate"); |
| | | |
| | | /*String dailyRate=getParamValue(request,resultObject,"dailyRate"); |
| | | if(null==dailyRate) return resultObject; |
| | | |
| | | |
| | | String repayment=getParamValue(request,resultObject,"repayment"); |
| | | if(null==repayment) return resultObject; |
| | | |
| | | |
| | | String repayCycle=getParamValue(request,resultObject,"repayCycle"); |
| | | if(null==repayCycle) return resultObject; |
| | | |
| | | |
| | | String lendingInstitution=getParamValue(request,resultObject,"lendingInstitution"); |
| | | if(null==lendingInstitution) return resultObject; |
| | | |
| | | String lendingName = getParamValue(request,resultObject,"lendingName"); |
| | | |
| | | String lendingName = getParamValue(request,resultObject,"lendingName"); |
| | | if(null==lendingName) return resultObject; |
| | | |
| | | |
| | | String img_idimg_1=getParamValue(request,resultObject,"frontFile"); |
| | | if(null==img_idimg_1) return resultObject; |
| | | String img_idimg_2=getParamValue(request,resultObject,"reverseFile"); |
| | | if(null==img_idimg_2) return resultObject; |
| | | /*String img_idimg_3=getParamValue(request,resultObject,"fileList"); |
| | | if(null==img_idimg_3) return resultObject;*/ |
| | | String img_idimg_3=getParamValue(request,resultObject,"fileList"); |
| | | if(null==img_idimg_3) return resultObject; |
| | | String houseImgs=new StringBuilder(img_idimg_1).append(",").append(img_idimg_2).toString(); |
| | | |
| | | |
| | | String incomeImg=request.getParameter("incomeImg"); |
| | | if(null==incomeImg || (incomeImg=incomeImg.trim()).isEmpty()) { |
| | | incomeImg=null; |
| | | } |
| | | }*/ |
| | | |
| | | Date now = new Date(); |
| | | SimpleLoanOrder simpleLoanOrder=new SimpleLoanOrder(partyId,new BigDecimal(quota),symbol); |
| | | SimpleLoanOrder simpleLoanOrder=new SimpleLoanOrder(partyId,new BigDecimal(quota), symbol); |
| | | String uuid = UUIDGenerator.getUUID(); |
| | | simpleLoanOrder.setUuid(uuid); |
| | | simpleLoanOrder.setLendingInstitution(new Integer(lendingInstitution)); |
| | | simpleLoanOrder.setRepayCycle(new Integer(repayCycle)); |
| | | simpleLoanOrder.setRepayment(new Integer(repayment)); |
| | | simpleLoanOrder.setDailyRate(new BigDecimal(dailyRate)); |
| | | simpleLoanOrder.setTerm(new Integer(term)); |
| | | simpleLoanOrder.setHouseImgs(houseImgs); |
| | | simpleLoanOrder.setIncomeImg(incomeImg); |
| | | simpleLoanOrder.setLendingInstitution(null); |
| | | simpleLoanOrder.setRepayCycle(null); |
| | | simpleLoanOrder.setRepayment(null); |
| | | BigDecimal rate = new BigDecimal(sysparaService.find("loan_rate").getSvalue()); |
| | | simpleLoanOrder.setDailyRate(rate); |
| | | simpleLoanOrder.setTerm(null); |
| | | simpleLoanOrder.setHouseImgs(null); |
| | | simpleLoanOrder.setIncomeImg(null); |
| | | simpleLoanOrder.setState(1); |
| | | simpleLoanOrder.setLendingName(lendingName); |
| | | simpleLoanOrder.setLendingName(null); |
| | | simpleLoanOrder.setCreateTime(now); |
| | | try { |
| | | boolean flag = loanService.addLoanOrder(simpleLoanOrder); |
| | |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | |
| | | |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提交还款申请 |
| | | * @param request 请求对象 |
| | | * @return 申请结果 |
| | | */ |
| | | @GetMapping("/api/loan!refund.action") |
| | | public ResultObject refund(HttpServletRequest request) { |
| | | ResultObject resultObject = new ResultObject(); |
| | | |
| | | String partyId = SecurityUtils.getCurrentUserId(); |
| | | if(null==partyId) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("通过Token获取partyId为空!"); |
| | | return resultObject; |
| | | } |
| | | |
| | | String orderNo=getParamValue(request,resultObject,"orderNo"); |
| | | if(null==orderNo) return resultObject; |
| | | |
| | | try { |
| | | boolean flag = loanService.refundLoanOrder(orderNo, partyId); |
| | | if (flag) { |
| | | resultObject.setMsg("提交成功"); |
| | | } else { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("提交失败"); |
| | | } |
| | | } catch(Throwable e) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | |
| | | return resultObject; |
| | | } |
| | | |
| | | /** |
| | | * 查看借贷申请单列表 |
| | | * @param request 请求对象 |
| | |
| | | @RequestMapping("/api/loan!getOrders.action") |
| | | public ResultObject getOrders(HttpServletRequest request) { |
| | | ResultObject resultObject = new ResultObject(); |
| | | |
| | | |
| | | // String token=request.getParameter("token"); |
| | | // if(null==token || (token=token.trim()).isEmpty()) { |
| | | // resultObject.setCode("1"); |
| | | // resultObject.setMsg("从请求参数中获取Token为空!"); |
| | | // return resultObject; |
| | | // } |
| | | |
| | | |
| | | // String partyId=tokenService.cacheGet(token); |
| | | String partyId = SecurityUtils.getCurrentUserId(); |
| | | if(null==partyId) { |
| | |
| | | resultObject.setMsg("通过Token获取partyId为空!"); |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | HashMap<String,Object> paramMap=new HashMap<String,Object>(); |
| | | paramMap.put("partyId", partyId); |
| | | paramMap.put("state", request.getParameter("state")); |
| | |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | |
| | | |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查看借贷申请单 |
| | | * @param request 请求对象 |
| | |
| | | @RequestMapping("/api/loan!getOrderDetail.action") |
| | | public ResultObject getOrderDetail(HttpServletRequest request) { |
| | | ResultObject resultObject = new ResultObject(); |
| | | |
| | | |
| | | // String token=request.getParameter("token"); |
| | | // if(null==token || (token=token.trim()).isEmpty()) { |
| | | // resultObject.setCode("1"); |
| | |
| | | resultObject.setMsg("通过Token获取partyId为空!"); |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | String orderNo=getParamValue(request,resultObject,"orderNo"); |
| | | if(null==orderNo) return resultObject; |
| | | |
| | | |
| | | try { |
| | | SimpleLoanOrder loanOrder=loanService.getLoanOrder(partyId,orderNo); |
| | | if(null!=loanOrder) { |
| | |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | |
| | | |
| | | return resultObject; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取参数值 |
| | | * @param request 请求对象 |
| | |
| | | return paramValue; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 校验借贷额度是否有效 |
| | | * @param resultObject 结果对象 |