| | |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | |
| | | import com.yami.trading.bean.model.MoneyLog; |
| | | import com.yami.trading.bean.model.User; |
| | | import com.yami.trading.bean.model.Wallet; |
| | | import com.yami.trading.bean.rate.domain.ExchangeRate; |
| | | import com.yami.trading.common.constants.Constants; |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.BusinessException; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.dao.loan.LoanParamMapper; |
| | | import com.yami.trading.service.MoneyLogService; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.rate.ExchangeRateService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import lombok.Getter; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | * @author JORGE |
| | | * @description 借贷服务接口实现类 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @Transactional |
| | | public class LoanServiceImpl implements LoanService { |
| | |
| | | |
| | | @Autowired |
| | | MoneyLogService moneyLogService; |
| | | |
| | | @Autowired |
| | | LoanParamMapper loanParamMapper; |
| | | |
| | | @Autowired |
| | | ExchangeRateService exchangeRateService; |
| | | |
| | | @Getter |
| | | HashMap<String,Object> paramMap = new HashMap<>(); |
| | |
| | | transferMap.put("lendingInstitution", new Object[] {led,order.getLendingName()}); |
| | | |
| | | |
| | | Long starTimel = order.getCreateTime().getTime(); |
| | | /*Long starTimel = order.getCreateTime().getTime(); |
| | | Long num = endTimel - starTimel; |
| | | Long remainQuota = num/24/60/60/1000; |
| | | Long remainQuota = num/24/60/60/1000;*/ |
| | | order.setTotalInterest(BigDecimal.ZERO); |
| | | order.setRemainQuota(0); |
| | | if(order.getState().intValue()==2||order.getState().intValue()==4) { |
| | | /*if(order.getState().intValue()==2||order.getState().intValue()==4) { |
| | | BigDecimal totalInterest = order.getDailyRate().multiply(new BigDecimal(remainQuota)).multiply(order.getQuota()); |
| | | order.setTotalInterest(totalInterest); |
| | | order.setRemainQuota(order.getTerm() - remainQuota.intValue()); |
| | | transferMap.put("totalInterest", totalInterest); |
| | | } |
| | | } */ |
| | | |
| | | return transferMap; |
| | | }).collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public boolean updateLoanOrderState(String orderId, String status,String reason) { |
| | | if(null==orderId || (orderId=orderId.trim()).isEmpty()) { |
| | | throw new BusinessException("申请单ID不能为空!"); |
| | |
| | | } |
| | | //到账金额 |
| | | double amt = loanOrder.getQuota().doubleValue(); |
| | | if (!loanOrder.getSymbol().equalsIgnoreCase("usdt")) { |
| | | ExchangeRate exchangeRate = exchangeRateService.findBy(ExchangeRate.IN, loanOrder.getSymbol().toUpperCase()); |
| | | if (exchangeRate == null) { |
| | | throw new YamiShopBindException("汇率未设置!"); |
| | | } |
| | | BigDecimal money = BigDecimal.valueOf(amt).divide(exchangeRate.getRata(), 8, RoundingMode.HALF_UP); |
| | | amt = money.doubleValue(); |
| | | } |
| | | |
| | | User user = userService.getById(loanOrder.getPartyId()); |
| | | double remainLoanLimit = user.getLoanLimit() - amt < 0 ? 0 : user.getLoanLimit() - amt; |
| | | BigDecimal loanLimit = BigDecimal.valueOf(remainLoanLimit).setScale(2, RoundingMode.HALF_UP); |
| | | user.setLoanLimit(loanLimit.doubleValue()); |
| | | userService.updateById(user); |
| | | |
| | | //通过 |
| | | Wallet wallet = this.walletService.saveWalletByPartyId(loanOrder.getPartyId()); |
| | | double amountBefore = wallet.getMoney().doubleValue(); |
| | |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_LOAN); |
| | | log.setAmountBefore(new BigDecimal(amountBefore)); |
| | | log.setAmount(new BigDecimal(amt)); |
| | | log.setAmountAfter(wallet.getMoney().add(BigDecimal.valueOf(amt))); |
| | | log.setAmount(loanOrder.getQuota()); |
| | | log.setAmountAfter(BigDecimal.valueOf(amountBefore + amt)); |
| | | log.setLog("借贷放款,订单号[" + loanOrder.getUuid() + "]"); |
| | | log.setUserId(loanOrder.getPartyId()); |
| | | log.setWalletType(Constants.WALLET); |
| | | log.setWalletType(loanOrder.getSymbol().toUpperCase()); |
| | | log.setContentType(Constants.MONEYLOG_CONTENT_LOAN_ADD); |
| | | moneyLogService.save(log); |
| | | } |
| | |
| | | SimpleLoanOrder loanOrder=loanOrders.get(0); |
| | | String houseImgs=(String)loanOrder.getHouseImgs(); |
| | | loanOrder.setHouseImgs(null==houseImgs?new String[0]:commaPattern.split(houseImgs)); |
| | | Date endDay = new Date(); |
| | | /*Date endDay = new Date(); |
| | | Long endTimel = endDay.getTime(); |
| | | Long starTimel = loanOrder.getCreateTime().getTime(); |
| | | Long num = endTimel - starTimel; |
| | | Long remainQuota = num/24/60/60/1000; |
| | | Long remainQuota = num/24/60/60/1000;*/ |
| | | loanOrder.setTotalInterest(BigDecimal.ZERO); |
| | | loanOrder.setRemainQuota(0); |
| | | if(loanOrder.getState().intValue()==2||loanOrder.getState().intValue()==4) { |
| | | /*if(loanOrder.getState().intValue()==2||loanOrder.getState().intValue()==4) { |
| | | BigDecimal totalInterest = loanOrder.getDailyRate().multiply(new BigDecimal(remainQuota)).multiply(loanOrder.getQuota()); |
| | | loanOrder.setTotalInterest(totalInterest); |
| | | loanOrder.setRemainQuota(loanOrder.getTerm() - remainQuota.intValue()); |
| | | } |
| | | }*/ |
| | | return loanOrder; |
| | | } |
| | | |
| | |
| | | List<SimpleLoanOrder> simpleLoanOrderList = jdbcTemplate.query(whereStatement.toString(), rowMapper); |
| | | //DateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); |
| | | |
| | | Date endDay = new Date(); |
| | | /*Date endDay = new Date(); |
| | | Long endTimel = endDay.getTime(); |
| | | for(SimpleLoanOrder simpleLoanOrder : simpleLoanOrderList) { |
| | | Long starTimel = simpleLoanOrder.getCreateTime().getTime(); |
| | |
| | | simpleLoanOrder.setTotalInterest(totalInterest); |
| | | simpleLoanOrder.setRemainQuota(simpleLoanOrder.getTerm() - remainQuota.intValue()); |
| | | } |
| | | } |
| | | }*/ |
| | | return simpleLoanOrderList; |
| | | } |
| | | |
| | |
| | | this.paramMap = params; |
| | | } |
| | | |
| | | @Override |
| | | public Result getLoanParamList(int pageNum, int pageSize) { |
| | | try { |
| | | Page page = new Page(pageNum, pageSize); |
| | | page = loanParamMapper.getLoanParamList(page); |
| | | return Result.succeed(page); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | return Result.failed("获取失败"); |
| | | } |
| | | |
| | | @Override |
| | | public Result saveLoanParam(LoanParam model) { |
| | | try { |
| | | if (model.getLending_institution() == null || model.getLending_institution().isEmpty()) { |
| | | model.setLending_institution("1"); |
| | | } |
| | | if (model.getUuid() != 0) { |
| | | System.out.println(model); |
| | | if (loanParamMapper.updateById(model) > 0) { |
| | | return Result.succeed("修改成功"); |
| | | } |
| | | } else { |
| | | if (loanParamMapper.insert(model) > 0) { |
| | | return Result.succeed("添加成功"); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | return Result.failed("操作失败"); |
| | | } |
| | | |
| | | @Override |
| | | public Result delLoanParam(String id) { |
| | | try { |
| | | if (loanParamMapper.deleteById(id) > 0) { |
| | | return Result.succeed("删除成功"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | return Result.failed("操作失败"); |
| | | } |
| | | |
| | | } |