diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerController.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerController.java index 633d59bd..a65f6ff4 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerController.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerController.java @@ -111,6 +111,22 @@ public class BorrowerController extends BaseController { return toAjax(tbBorrowerService.updateTbBorrower(tbBorrower)); } + @PostMapping("/borrowerInserts") + public AjaxResult borrowerInserts(@RequestBody TbBorrower tbBorrower) + { + return toAjax(tbBorrowerService.borrowerInserts(tbBorrower)); + } + + + @PostMapping("/loans") + public AjaxResult loans(@RequestBody TbBorrower tbBorrower) + { + return tbBorrowerService.loans(tbBorrower); + } + + + + } diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerPeriodsController.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerPeriodsController.java index 7925c981..3602e258 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerPeriodsController.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/controller/BorrowerPeriodsController.java @@ -4,6 +4,7 @@ import java.util.List; import java.io.IOException; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.potenza.domain.vo.PeriodDetailVo; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -64,7 +65,6 @@ public class BorrowerPeriodsController extends BaseController{ /** * 获取贷款周期详细信息 */ - @RequiresPermissions("potenza:periods:query") @GetMapping(value = "/{periodsById}") public AjaxResult getInfo(@PathVariable("periodsId") Long periodsId) { @@ -74,7 +74,6 @@ public class BorrowerPeriodsController extends BaseController{ /** * 新增贷款周期 */ - @RequiresPermissions("potenza:periods:add") @Log(title = "贷款周期", businessType = BusinessType.INSERT) @PostMapping("periodsInsert") public AjaxResult add(@RequestBody TbBorrowerPeriods tbBorrowerPeriods) @@ -85,7 +84,6 @@ public class BorrowerPeriodsController extends BaseController{ /** * 修改贷款周期 */ - @RequiresPermissions("potenza:periods:edit") @Log(title = "贷款周期", businessType = BusinessType.UPDATE) @PutMapping("/periodsUpdate") public AjaxResult edit(@RequestBody TbBorrowerPeriods tbBorrowerPeriods) @@ -96,11 +94,18 @@ public class BorrowerPeriodsController extends BaseController{ /** * 删除贷款周期 */ - @RequiresPermissions("potenza:periods:remove") @Log(title = "贷款周期", businessType = BusinessType.DELETE) @DeleteMapping("/{periodsIds}") public AjaxResult remove(@PathVariable Long[] periodsIds) { return toAjax(tbBorrowerPeriodsService.deleteTbBorrowerPeriodsByPeriodsIds(periodsIds)); } + + + @Log(title = "周期详细", businessType = BusinessType.UPDATE) + @PostMapping("/detail") + public AjaxResult detail(@RequestBody PeriodDetailVo periodDetailVo) + { + return tbBorrowerPeriodsService.detail(periodDetailVo); + } } diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/TbBorrowerPeriods.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/TbBorrowerPeriods.java index 4e0162bb..d3387ce5 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/TbBorrowerPeriods.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/TbBorrowerPeriods.java @@ -36,6 +36,8 @@ public class TbBorrowerPeriods implements Serializable { */ private String updateBy; + private Double rateInterest; + /** * 删除状态0:存在,2:删除 */ diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/vo/PeriodDetailVo.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/vo/PeriodDetailVo.java new file mode 100644 index 00000000..da289bc5 --- /dev/null +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/vo/PeriodDetailVo.java @@ -0,0 +1,20 @@ +package com.ruoyi.potenza.domain.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author 木子 + * @version 1.0 + * @description: TODO + * @date 2023/1/15 20:39 + */ +@Data +public class PeriodDetailVo implements Serializable { + private Double borrowerMoney; + + private Integer wayId; + + private Integer periodsId; +} diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/vo/TbBorrowerVo.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/vo/TbBorrowerVo.java new file mode 100644 index 00000000..9abbee05 --- /dev/null +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/domain/vo/TbBorrowerVo.java @@ -0,0 +1,94 @@ +package com.ruoyi.potenza.domain.vo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author 木子 + * @version 1.0 + * @description: TODO + * @date 2023/1/15 19:26 + */ +@Data +public class TbBorrowerVo implements Serializable { + + private Integer borrowerId; + + /** + * 用户ID + */ + private Integer userId; + + /** + * 用户名称 + */ + private String userName; + + /** + * 产品ID + */ + private Integer productId; + + /** + * 默认为最高可以借款金额 + */ + private Double borrowerMoney; + + /** + * 贷款周期ID + */ + private Integer periodsId; + + /** + * 贷款方式ID 0:等额本息 6000 1:等额本金 6000 1000 第一个月60000*利率 第二个月 5000*利率 + */ + private Integer wayId; + + /** + * 借款用途 + */ + private String borrowerPurpose; + + /** + * 1: 待审核 2:贷款成功 3:贷款失败 + */ + private Integer borrowerState; + + /** + * 放款人 + */ + private Integer loanerId; + + /** + * 创建者 + */ + private String createBy; + + /** + * 更新者 + */ + private String updateBy; + + /** + * 删除状态0:存在,2:删除 + */ + private Integer delFlag; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + + +} diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerPeriodsService.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerPeriodsService.java index 7e3a82b3..9c1dcec0 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerPeriodsService.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerPeriodsService.java @@ -1,7 +1,9 @@ package com.ruoyi.potenza.service; +import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.potenza.domain.TbBorrowerPeriods; import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.potenza.domain.vo.PeriodDetailVo; import java.util.List; @@ -58,4 +60,6 @@ public interface TbBorrowerPeriodsService extends IService { * @return 结果 */ public int deleteTbBorrowerPeriodsByPeriodsId(Long periodsId); + + AjaxResult detail(PeriodDetailVo periodDetailVo); } diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerService.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerService.java index ab007948..567c0789 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerService.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/TbBorrowerService.java @@ -51,5 +51,7 @@ public interface TbBorrowerService extends IService { public int updateTbBorrower(TbBorrower tbBorrower); + int borrowerInserts(TbBorrower tbBorrower); + AjaxResult loans(TbBorrower tbBorrower); } diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerPeriodsServiceImpl.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerPeriodsServiceImpl.java index 0bddb453..0757d77f 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerPeriodsServiceImpl.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerPeriodsServiceImpl.java @@ -2,25 +2,31 @@ package com.ruoyi.potenza.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.potenza.domain.TbBorrowerPeriods; +import com.ruoyi.potenza.domain.vo.PeriodDetailVo; import com.ruoyi.potenza.service.TbBorrowerPeriodsService; import com.ruoyi.potenza.mapper.TbBorrowerPeriodsMapper; +import com.ruoyi.potenza.utils.AverageCapitalPlusInterestUtils; +import com.ruoyi.potenza.utils.AverageCapitalUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** -* @author 86155 -* @description 针对表【tb_borrower_periods(贷款周期表)】的数据库操作Service实现 -* @createDate 2023-01-13 15:56:37 -*/ + * @author 86155 + * @description 针对表【tb_borrower_periods(贷款周期表)】的数据库操作Service实现 + * @createDate 2023-01-13 15:56:37 + */ @Service public class TbBorrowerPeriodsServiceImpl extends ServiceImpl - implements TbBorrowerPeriodsService{ + implements TbBorrowerPeriodsService{ + @Autowired private TbBorrowerPeriodsMapper tbBorrowerPeriodsMapper; + /** * 查询贷款周期 * @@ -95,6 +101,33 @@ public class TbBorrowerPeriodsServiceImpl extends ServiceImpl implements TbBorrowerPlanService{ + @Autowired private TbBorrowerPlanMapper tbBorrowerPlanMapper; diff --git a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerServiceImpl.java b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerServiceImpl.java index 6a4b4e92..ee9a9bbd 100644 --- a/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerServiceImpl.java +++ b/ruoyi-modules/ruoyi-potenza/src/main/java/com/ruoyi/potenza/service/impl/TbBorrowerServiceImpl.java @@ -1,12 +1,19 @@ package com.ruoyi.potenza.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.potenza.domain.TbBorrower; +import com.ruoyi.potenza.domain.TbBorrowerPeriods; import com.ruoyi.potenza.domain.vo.IdVo; +import com.ruoyi.potenza.domain.vo.TbBorrowerVo; +import com.ruoyi.potenza.mapper.TbBorrowerPeriodsMapper; import com.ruoyi.potenza.service.TbBorrowerService; import com.ruoyi.potenza.mapper.TbBorrowerMapper; +import com.ruoyi.potenza.utils.AverageCapitalPlusInterestUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,12 +25,16 @@ import java.util.List; * @createDate 2023-01-13 15:56:37 */ @Service +@Slf4j public class TbBorrowerServiceImpl extends ServiceImpl implements TbBorrowerService{ @Autowired private TbBorrowerMapper tbBorrowerMapper; + @Autowired + private TbBorrowerPeriodsMapper tbBorrowerPeriodsMapper; + @Override public List pageList(TbBorrower tbBorrower) { List list= tbBorrowerMapper.pageList(); @@ -36,14 +47,6 @@ public class TbBorrowerServiceImpl extends ServiceImpl 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