wrapper=new LambdaQueryWrapper<>();
+ wrapper.eq(TbBorrower::getUserId,tbBorrower.getUserId());
+ wrapper.eq(TbBorrower::getProductId,tbBorrower.getProductId());
+ TbBorrower tbBorrower1 = tbBorrowerMapper.selectOne(wrapper);
+ if(tbBorrower1!=null){
+ return AjaxResult.error("请先还款");
+ }
+ Integer periodsId = tbBorrower.getPeriodsId();
+ long periodsid = periodsId.longValue();
+ //查询利率
+ TbBorrowerPeriods tbBorrowerPeriods = tbBorrowerPeriodsMapper.selectTbBorrowerPeriodsByPeriodsId(periodsid);
+
+ double perMonthPrincipalInterest = AverageCapitalPlusInterestUtils.
+ getPerMonthPrincipalInterest(tbBorrower.getBorrowerMoney(),
+ tbBorrowerPeriods.getRateInterest()/100,
+ tbBorrowerPeriods.getPeriodsName());
+
+
+ double principalInterestCount = AverageCapitalPlusInterestUtils.
+ getPrincipalInterestCount(tbBorrower.getBorrowerMoney(),
+ tbBorrowerPeriods.getRateInterest() / 100,
+ tbBorrowerPeriods.getPeriodsName());
+
+ log.info("---------"+principalInterestCount);
+ return AjaxResult.success("添加成功");
+ }
}
diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/utils/AverageCapitalPlusInterestUtils.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/utils/AverageCapitalPlusInterestUtils.java
new file mode 100644
index 00000000..d691ac8c
--- /dev/null
+++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/utils/AverageCapitalPlusInterestUtils.java
@@ -0,0 +1,141 @@
+package com.ruoyi.potenza.utils;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+ * @description: TODO
+ * @author 木子
+ * @date 2023/1/15 19:17
+ * @version 1.0
+ */
+public class AverageCapitalPlusInterestUtils {
+ /**
+ * 等额本息计算获取还款方式为等额本息的每月偿还本金和利息
+ *
+ * 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
+ *
+ * @param invest 总借款额(贷款本金)
+ * @param yearRate 年利率
+ * @param month 还款总月数
+ * @return 每月偿还本金和利息, 不四舍五入,直接截取小数点最后两位
+ */
+ public static double getPerMonthPrincipalInterest(double invest, double yearRate, int totalmonth) {
+ double monthRate = yearRate / 12;
+ BigDecimal monthIncome = new BigDecimal(invest)
+ .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
+ .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
+ return monthIncome.doubleValue();
+ }
+
+ /**
+ * 等额本息计算获取还款方式为等额本息的每月偿还利息
+ *
+ * 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕
+ *
+ * @param invest 总借款额(贷款本金)
+ * @param yearRate 年利率
+ * @param month 还款总月数
+ * @return 每月偿还利息
+ */
+ public static Map getPerMonthInterest(double invest, double yearRate, int totalmonth) {
+ Map map = new HashMap();
+ double monthRate = yearRate / 12;
+ BigDecimal monthInterest;
+ for (int i = 1; i < totalmonth + 1; i++) {
+ BigDecimal multiply = new BigDecimal(invest).multiply(new BigDecimal(monthRate));
+ BigDecimal sub = new BigDecimal(Math.pow(1 + monthRate, totalmonth)).subtract(new BigDecimal(Math.pow(1 + monthRate, i - 1)));
+ monthInterest = multiply.multiply(sub).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 6, BigDecimal.ROUND_DOWN);
+ monthInterest = monthInterest.setScale(2, BigDecimal.ROUND_DOWN);
+ map.put(i, monthInterest);
+ }
+ return map;
+ }
+
+ /**
+ * 等额本息计算获取还款方式为等额本息的每月偿还本金
+ *
+ * @param invest 总借款额(贷款本金)
+ * @param yearRate 年利率
+ * @param month 还款总月数
+ * @return 每月偿还本金
+ */
+ public static Map getPerMonthPrincipal(double invest, double yearRate, int totalmonth) {
+ double monthRate = yearRate / 12;
+ BigDecimal monthIncome = new BigDecimal(invest)
+ .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
+ .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
+ Map mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);
+ Map mapPrincipal = new HashMap();
+
+ for (Map.Entry entry : mapInterest.entrySet()) {
+ mapPrincipal.put(entry.getKey(), monthIncome.subtract(entry.getValue()));
+ }
+ return mapPrincipal;
+ }
+
+ /**
+ * 等额本息计算获取还款方式为等额本息的总利息
+ *
+ * @param invest 总借款额(贷款本金)
+ * @param yearRate 年利率
+ * @param month 还款总月数
+ * @return 总利息
+ */
+ public static double getInterestCount(double invest, double yearRate, int totalmonth) {
+ BigDecimal count = new BigDecimal(0);
+ Map mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);
+
+ for (Map.Entry entry : mapInterest.entrySet()) {
+ count = count.add(entry.getValue());
+ }
+ return count.doubleValue();
+ }
+
+ /**
+ * 应还本金总和
+ *
+ * @param invest 总借款额(贷款本金)
+ * @param yearRate 年利率
+ * @param month 还款总月数
+ * @return 应还本金总和
+ */
+ public static double getPrincipalInterestCount(double invest, double yearRate, int totalmonth) {
+ double monthRate = yearRate / 12;
+ BigDecimal perMonthInterest = new BigDecimal(invest)
+ .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
+ .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
+ BigDecimal count = perMonthInterest.multiply(new BigDecimal(totalmonth));
+ count = count.setScale(2, BigDecimal.ROUND_DOWN);
+ return count.doubleValue();
+ }
+
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ double invest = 20000; // 本金
+ int month = 12;
+ double yearRate = 0.15; // 年利率
+ double perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);
+ System.out.println("等额本息---每月还款本息:" + perMonthPrincipalInterest);
+ Map mapInterest = getPerMonthInterest(invest, yearRate, month);
+ System.out.println("等额本息---每月还款利息:" + mapInterest);
+ Map mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);
+ System.out.println("等额本息---每月还款本金:" + mapPrincipal);
+ double count = getInterestCount(invest, yearRate, month);
+ System.out.println("等额本息---总利息:" + count);
+ double principalInterestCount = getPrincipalInterestCount(invest, yearRate, month);
+ System.out.println("等额本息---应还本息总和:" + principalInterestCount);
+
+ }
+}
+
diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/utils/AverageCapitalUtils.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/utils/AverageCapitalUtils.java
new file mode 100644
index 00000000..35b3568b
--- /dev/null
+++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/utils/AverageCapitalUtils.java
@@ -0,0 +1,155 @@
+package com.ruoyi.potenza.utils;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+/**
+ * @author 木子
+ * @version 1.0
+ * @description: TODO
+ * @date 2023/1/15 20:49
+ */
+public class AverageCapitalUtils {
+ /**
+ * 等额本息计算获取还款方式为等额本息的每月偿还本金和利息
+ *
+ * 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕
+ *
+ * @param invest
+ * 总借款额(贷款本金)
+ * @param yearRate
+ * 年利率
+ * @param month
+ * 还款总月数
+ * @return 每月偿还本金和利息,不四舍五入,直接截取小数点最后两位
+ */
+ public static BigDecimal getPerMonthPrincipalInterest(double invest, double yearRate, int totalmonth) {
+ double monthRate = yearRate / 12;
+ BigDecimal monthIncome = new BigDecimal(invest)
+ .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
+ .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_UP);
+ //return monthIncome.doubleValue();
+ return monthIncome;
+ }
+
+ /**
+ * 等额本息计算获取还款方式为等额本息的每月偿还利息
+ *
+ * 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕
+ *
+ * @param invest
+ * 总借款额(贷款本金)
+ * @param yearRate
+ * 年利率
+ * @param month
+ * 还款总月数
+ * @return 每月偿还利息
+ */
+ public static Map getPerMonthInterest(double invest, double yearRate, int totalmonth) {
+ Map map = new HashMap();
+ double monthRate = yearRate / 12;
+ BigDecimal monthInterest;
+ for (int i = 1; i < totalmonth + 1; i++) {
+ BigDecimal multiply = new BigDecimal(invest).multiply(new BigDecimal(monthRate));
+ BigDecimal sub = new BigDecimal(Math.pow(1 + monthRate, totalmonth))
+ .subtract(new BigDecimal(Math.pow(1 + monthRate, i - 1)));
+ monthInterest = multiply.multiply(sub).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2,
+ BigDecimal.ROUND_DOWN);
+ monthInterest = monthInterest.setScale(2, BigDecimal.ROUND_DOWN);
+ map.put(i, monthInterest);
+ }
+ return map;
+ }
+
+ /**
+ * 等额本息计算获取还款方式为等额本息的每月偿还本金
+ *
+ * @param invest
+ * 总借款额(贷款本金)
+ * @param yearRate
+ * 年利率
+ * @param month
+ * 还款总月数
+ * @return 每月偿还本金
+ */
+ public static Map getPerMonthPrincipal(double invest, double yearRate, int totalmonth) {
+ double monthRate = yearRate / 12;
+ BigDecimal monthIncome = new BigDecimal(invest)
+ .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
+ .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
+ Map mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);
+ Map mapPrincipal = new HashMap();
+
+ for (Map.Entry entry : mapInterest.entrySet()) {
+ mapPrincipal.put(entry.getKey(), monthIncome.subtract(entry.getValue()));
+ }
+ return mapPrincipal;
+ }
+
+ /**
+ * 等额本息计算获取还款方式为等额本息的总利息
+ *
+ * @param invest
+ * 总借款额(贷款本金)
+ * @param yearRate
+ * 年利率
+ * @param month
+ * 还款总月数
+ * @return 总利息
+ */
+ public static double getInterestCount(double invest, double yearRate, int totalmonth) {
+ BigDecimal count = new BigDecimal(0);
+ Map mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);
+
+ for (Map.Entry entry : mapInterest.entrySet()) {
+ count = count.add(entry.getValue());
+ }
+ return count.doubleValue();
+ }
+
+ /**
+ * 应还本金总和
+ *
+ * @param invest
+ * 总借款额(贷款本金)
+ * @param yearRate
+ * 年利率
+ * @param month
+ * 还款总月数
+ * @return 应还本金总和
+ */
+ public static double getPrincipalInterestCount(double invest, double yearRate, int totalmonth) {
+ double monthRate = yearRate / 12;
+ BigDecimal perMonthInterest = new BigDecimal(invest)
+ .multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth)))
+ .divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_DOWN);
+ BigDecimal count = perMonthInterest.multiply(new BigDecimal(totalmonth));
+ count = count.setScale(2, BigDecimal.ROUND_DOWN);
+ return count.doubleValue();
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ double invest = 38988; // 本金
+ int month = 12;
+ double yearRate = 0.15; // 年利率
+ BigDecimal perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);
+ System.out.println("等额本息---每月还款本息:" + perMonthPrincipalInterest);
+ System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 3));
+ System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 6));
+ System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 9));
+ System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 12));
+ System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 15));
+ System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 18));
+ /*Map mapInterest = getPerMonthInterest(invest, yearRate, month);
+ System.out.println("等额本息---每月还款利息:" + mapInterest);
+ Map mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);
+ System.out.println("等额本息---每月还款本金:" + mapPrincipal);
+ double count = getInterestCount(invest, yearRate, month);
+ System.out.println("等额本息---总利息:" + count);
+ double principalInterestCount = getPrincipalInterestCount(invest, yearRate, month);
+ System.out.println("等额本息---应还本息总和:" + principalInterestCount);*/
+ }
+}
diff --git a/ruoyi-modules/ruoyi-potenza/src/main/resources/mapper/TbBorrowerPeriodsMapper.xml b/ruoyi-modules/ruoyi-potenza/src/main/resources/mapper/TbBorrowerPeriodsMapper.xml
index c8760ec7..e603adea 100644
--- a/ruoyi-modules/ruoyi-potenza/src/main/resources/mapper/TbBorrowerPeriodsMapper.xml
+++ b/ruoyi-modules/ruoyi-potenza/src/main/resources/mapper/TbBorrowerPeriodsMapper.xml
@@ -7,6 +7,7 @@
+
@@ -15,7 +16,7 @@
- select periods_id, periods_name, create_by, update_by, del_flag, create_time, update_time from tb_borrower_periods
+ select periods_id, periods_name,rate_interest, create_by, update_by, del_flag, create_time, update_time from tb_borrower_periods