import com.freeter.model.Calculator;
@RestController
@RequestMapping("app/calculator")
public class calculatorController {
@RequestMapping(value = "houseLoan", produces = "application/json;charset=UTF-8")
public String tradeCalculator(Calculator cal) {
double totalAmountMortgage = 0;
double reimbursemenAmount = 0
double interestPayment = 0
double interestPaymentMonth = 0;
double averageMonthlyAmount = 0;
double interestDurationLoan = 0;
double remainingLoan = 0;
double totalDueAmount = 0;
JSONObject result = new JSONObject();
int errCode = 1;
String desc = "成功";
if (cal.isLoanType() == true) {
if (cal.isComputeMode() == true) {
totalAmountMortgage = (cal.getArea() * cal.getUnitPrice());
reimbursemenAmount = totalAmountMortgage * cal.getPercentage() * 0.1;
} else {
totalAmountMortgage = cal.getTotalLoan();
reimbursemenAmount = totalAmountMortgage;
}
downPayment = (totalAmountMortgage - reimbursemenAmount);
if (cal.isRepayment() == true) {
averageMonthlyAmount = (reimbursemenAmount * cal.getInterestRates() / 12
* Math.pow(1 + cal.getInterestRates() / 12, +cal.getMonth())
/ (Math.pow(1 + cal.getInterestRates() / 12, cal.getMonth()) - 1));
remainingLoan = reimbursemenAmount;
for (int i = 0; i < cal.getMonth(); i++) {
interestPaymentMonth = remainingLoan * cal.getInterestRates() / 12;
interestDurationLoan = averageMonthlyAmount - interestPaymentMonth;
interestPayment = interestPayment + interestPaymentMonth;//
remainingLoan = remainingLoan - interestDurationLoan;/
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("totalAmountMortgage", totalAmountMortgage);
result.put("reimbursemenAmount", reimbursemenAmount);/
result.put("interestPayment", interestPayment);//
result.put("downPayment", downPayment);//
result.put("averageMonthlyAmount", averageMonthlyAmount);//
} else {
interestDurationLoan = reimbursemenAmount / cal.getMonth();
double reimbursemenAmount1 = reimbursemenAmount;
for (int i = 0; i < cal.getMonth(); i++) {
interestPaymentMonth = reimbursemenAmount1 * cal.getInterestRates() / 12;
System.out.println("第" + i + "期" + "本金:" + interestDurationLoan + "利息" + interestPaymentMonth
+ " 总额:" + (interestDurationLoan + interestPaymentMonth));
averageMonthlyAmount = interestDurationLoan + interestPaymentMonth;
interestPayment += interestPaymentMonth;
reimbursemenAmount1 -= interestDurationLoan;
}
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("totalAmountMortgage", totalAmountMortgage);
result.put("reimbursemenAmount", reimbursemenAmount);
result.put("interestPayment", interestPayment);
result.put("downPayment", downPayment);
result.put("month", cal.getMonth());
result.put("averageMonthlyAmount", averageMonthlyAmount);
}
} else {
reimbursemenAmount = cal.getTradeMoney() + cal.getReservedFound();
if (cal.isRepayment() == true) {
double tradeMoney = cal.getTradeMoney();
double ReservedFound = cal.getReservedFound();
for (int i = 0; i < cal.getMonth(); i++) {
interestPaymentMonth = ReservedFound * cal.getInterestRates() / 12
+ tradeMoney * cal.getTradeInterestRates() / 12;
interestPayment = interestPayment + interestPaymentMonth;
tradeMoney = tradeMoney - ((cal.getTradeMoney() * cal.getTradeInterestRates() / 12
* Math.pow(1 + cal.getTradeInterestRates() / 12, +cal.getMonth())
/ (Math.pow(1 + cal.getTradeInterestRates() / 12, cal.getMonth()) - 1))
- (tradeMoney * cal.getTradeInterestRates() / 12));
ReservedFound = ReservedFound - ((cal.getReservedFound() * cal.getInterestRates() / 12
* Math.pow(1 + cal.getInterestRates() / 12, +cal.getMonth())
/ (Math.pow(1 + cal.getInterestRates() / 12, cal.getMonth()) - 1))
- (ReservedFound * cal.getInterestRates() / 12));
}
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("reimbursemenAmount", reimbursemenAmount);
result.put("totalDueAmount", totalDueAmount);
result.put("interestPayment", interestPayment);
result.put("month", cal.getMonth());
result.put("averageMonthlyAmount", averageMonthlyAmount);
} else {
reimbursemenAmount = cal.getTradeMoney() + cal.getReservedFound();
interestDurationLoan = reimbursemenAmount / cal.getMonth();
double tradeMoney = cal.getTradeMoney();//
double ReservedFound = cal.getReservedFound();
tradeMoney = tradeMoney - (cal.getTradeMoney() / cal.getMonth());
ReservedFound = ReservedFound - (cal.getReservedFound() / cal.getMonth());
}
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("reimbursemenAmount", reimbursemenAmount);
result.put("totalDueAmount", totalDueAmount);
result.put("interestPayment", interestPayment);
result.put("averageMonthlyAmount", averageMonthlyAmount);
}
}
result.put("errCode", errCode);
result.put("desc", desc);
return result.toString();
}
}
@RestController
@RequestMapping("app/calculator")
public class calculatorController {
@RequestMapping(value = "houseLoan", produces = "application/json;charset=UTF-8")
public String tradeCalculator(Calculator cal) {
double totalAmountMortgage = 0;
double reimbursemenAmount = 0
double interestPayment = 0
double interestPaymentMonth = 0;
double averageMonthlyAmount = 0;
double interestDurationLoan = 0;
double remainingLoan = 0;
double totalDueAmount = 0;
JSONObject result = new JSONObject();
int errCode = 1;
String desc = "成功";
if (cal.isLoanType() == true) {
if (cal.isComputeMode() == true) {
totalAmountMortgage = (cal.getArea() * cal.getUnitPrice());
reimbursemenAmount = totalAmountMortgage * cal.getPercentage() * 0.1;
} else {
totalAmountMortgage = cal.getTotalLoan();
reimbursemenAmount = totalAmountMortgage;
}
downPayment = (totalAmountMortgage - reimbursemenAmount);
if (cal.isRepayment() == true) {
averageMonthlyAmount = (reimbursemenAmount * cal.getInterestRates() / 12
* Math.pow(1 + cal.getInterestRates() / 12, +cal.getMonth())
/ (Math.pow(1 + cal.getInterestRates() / 12, cal.getMonth()) - 1));
remainingLoan = reimbursemenAmount;
for (int i = 0; i < cal.getMonth(); i++) {
interestPaymentMonth = remainingLoan * cal.getInterestRates() / 12;
interestDurationLoan = averageMonthlyAmount - interestPaymentMonth;
interestPayment = interestPayment + interestPaymentMonth;//
remainingLoan = remainingLoan - interestDurationLoan;/
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("totalAmountMortgage", totalAmountMortgage);
result.put("reimbursemenAmount", reimbursemenAmount);/
result.put("interestPayment", interestPayment);//
result.put("downPayment", downPayment);//
result.put("averageMonthlyAmount", averageMonthlyAmount);//
} else {
interestDurationLoan = reimbursemenAmount / cal.getMonth();
double reimbursemenAmount1 = reimbursemenAmount;
for (int i = 0; i < cal.getMonth(); i++) {
interestPaymentMonth = reimbursemenAmount1 * cal.getInterestRates() / 12;
System.out.println("第" + i + "期" + "本金:" + interestDurationLoan + "利息" + interestPaymentMonth
+ " 总额:" + (interestDurationLoan + interestPaymentMonth));
averageMonthlyAmount = interestDurationLoan + interestPaymentMonth;
interestPayment += interestPaymentMonth;
reimbursemenAmount1 -= interestDurationLoan;
}
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("totalAmountMortgage", totalAmountMortgage);
result.put("reimbursemenAmount", reimbursemenAmount);
result.put("interestPayment", interestPayment);
result.put("downPayment", downPayment);
result.put("month", cal.getMonth());
result.put("averageMonthlyAmount", averageMonthlyAmount);
}
} else {
reimbursemenAmount = cal.getTradeMoney() + cal.getReservedFound();
if (cal.isRepayment() == true) {
double tradeMoney = cal.getTradeMoney();
double ReservedFound = cal.getReservedFound();
for (int i = 0; i < cal.getMonth(); i++) {
interestPaymentMonth = ReservedFound * cal.getInterestRates() / 12
+ tradeMoney * cal.getTradeInterestRates() / 12;
interestPayment = interestPayment + interestPaymentMonth;
tradeMoney = tradeMoney - ((cal.getTradeMoney() * cal.getTradeInterestRates() / 12
* Math.pow(1 + cal.getTradeInterestRates() / 12, +cal.getMonth())
/ (Math.pow(1 + cal.getTradeInterestRates() / 12, cal.getMonth()) - 1))
- (tradeMoney * cal.getTradeInterestRates() / 12));
ReservedFound = ReservedFound - ((cal.getReservedFound() * cal.getInterestRates() / 12
* Math.pow(1 + cal.getInterestRates() / 12, +cal.getMonth())
/ (Math.pow(1 + cal.getInterestRates() / 12, cal.getMonth()) - 1))
- (ReservedFound * cal.getInterestRates() / 12));
}
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("reimbursemenAmount", reimbursemenAmount);
result.put("totalDueAmount", totalDueAmount);
result.put("interestPayment", interestPayment);
result.put("month", cal.getMonth());
result.put("averageMonthlyAmount", averageMonthlyAmount);
} else {
reimbursemenAmount = cal.getTradeMoney() + cal.getReservedFound();
interestDurationLoan = reimbursemenAmount / cal.getMonth();
double tradeMoney = cal.getTradeMoney();//
double ReservedFound = cal.getReservedFound();
tradeMoney = tradeMoney - (cal.getTradeMoney() / cal.getMonth());
ReservedFound = ReservedFound - (cal.getReservedFound() / cal.getMonth());
}
totalDueAmount = reimbursemenAmount + interestPayment;
result.put("reimbursemenAmount", reimbursemenAmount);
result.put("totalDueAmount", totalDueAmount);
result.put("interestPayment", interestPayment);
result.put("averageMonthlyAmount", averageMonthlyAmount);
}
}
result.put("errCode", errCode);
result.put("desc", desc);
return result.toString();
}
}