|
|
@ -1,35 +1,94 @@
|
|
|
|
package com.example.demo.circulator.service;
|
|
|
|
package com.example.demo.circulator.service;
|
|
|
|
|
|
|
|
|
|
|
|
import com.example.demo.Dao.paymentMapper;
|
|
|
|
import com.example.demo.Dao.paymentMapper;
|
|
|
|
|
|
|
|
import com.example.demo.Dao.productMapper;
|
|
|
|
import com.example.demo.Dao.transMapper;
|
|
|
|
import com.example.demo.Dao.transMapper;
|
|
|
|
import com.example.demo.Dao.usageDateMapper;
|
|
|
|
import com.example.demo.Dao.usageDateMapper;
|
|
|
|
|
|
|
|
import com.example.demo.bean.Product;
|
|
|
|
import com.example.demo.bean.Repayment;
|
|
|
|
import com.example.demo.bean.Repayment;
|
|
|
|
import com.example.demo.bean.Transaction;
|
|
|
|
import com.example.demo.bean.Transaction;
|
|
|
|
import com.example.demo.bean.UsageDate;
|
|
|
|
import com.example.demo.bean.UsageDate;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class PayCirService {
|
|
|
|
public class PayCirService {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private usageDateMapper usageDateMapper;
|
|
|
|
private usageDateMapper usageDateMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private paymentMapper paymentMapper;
|
|
|
|
private paymentMapper paymentMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private transMapper transMapper;
|
|
|
|
private transMapper transMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private productMapper productMapper;
|
|
|
|
|
|
|
|
|
|
|
|
public int payAmountCirculator(long checkNum,double pay){
|
|
|
|
|
|
|
|
try{
|
|
|
|
public int pay_EPR_AmountCirculator(long checkNum,double pay) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
Repayment repayment = paymentMapper.selectPepaymentBycheckNum(checkNum);
|
|
|
|
Repayment repayment = paymentMapper.selectPepaymentBycheckNum(checkNum);
|
|
|
|
UsageDate usageDate= usageDateMapper.selectUsageDateByCheckNum(checkNum);
|
|
|
|
UsageDate usageDate = usageDateMapper.selectUsageDateByCheckNum(checkNum);
|
|
|
|
if(usageDate==null)return -2;
|
|
|
|
double repamount = 0;
|
|
|
|
double repamount = repayment.getRepAmount();
|
|
|
|
long productNum = usageDate.getProductNum();
|
|
|
|
long userNum = usageDate.getUserNum();
|
|
|
|
long userNum = usageDate.getUserNum();
|
|
|
|
int bankNum = usageDate.getBankNum();
|
|
|
|
int bankNum = usageDate.getBankNum();
|
|
|
|
double amount = usageDate.getAmount();
|
|
|
|
double amount = usageDate.getAmount();
|
|
|
|
int year = usageDate.getYear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Transaction transaction = new Transaction(checkNum,userNum,bankNum,pay);
|
|
|
|
if (repayment != null)
|
|
|
|
|
|
|
|
repamount = repayment.getRepAmount();
|
|
|
|
|
|
|
|
Product product = productMapper.selectProductByProductNum(productNum);
|
|
|
|
|
|
|
|
if (product == null)
|
|
|
|
|
|
|
|
return -3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Transaction transaction = new Transaction(checkNum, userNum, bankNum, pay);
|
|
|
|
transMapper.addTransaction(transaction);
|
|
|
|
transMapper.addTransaction(transaction);
|
|
|
|
|
|
|
|
|
|
|
|
repamount = pay - amount/(year*12);
|
|
|
|
double intrate = product.getIntrate();
|
|
|
|
|
|
|
|
double rep_amount = repayment.getRepSum();
|
|
|
|
|
|
|
|
repamount = pay - (amount - repamount) * intrate;
|
|
|
|
repayment.setRepAmount(repamount);
|
|
|
|
repayment.setRepAmount(repamount);
|
|
|
|
repayment.setRepSum(pay);
|
|
|
|
repayment.setRepSum(pay + rep_amount);
|
|
|
|
|
|
|
|
if (repayment != null) {
|
|
|
|
|
|
|
|
paymentMapper.updateRepayment(repayment);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
paymentMapper.addRepayment(repayment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int pay_EPAIR_AmountCirculator(long checkNum,double pay){
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
UsageDate usageDate = usageDateMapper.selectUsageDateByCheckNum(checkNum);
|
|
|
|
|
|
|
|
int year = usageDate.getYear();
|
|
|
|
|
|
|
|
double amount = usageDate.getAmount();
|
|
|
|
|
|
|
|
long productNum = usageDate.getProductNum();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Product product = productMapper.selectProductByProductNum(productNum);
|
|
|
|
|
|
|
|
if(product==null)return -3;
|
|
|
|
|
|
|
|
float intrate = product.getIntrate();
|
|
|
|
|
|
|
|
double rep_amount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//double not_rep_amount = amount - rep_amount;
|
|
|
|
|
|
|
|
intrate /= 12;
|
|
|
|
|
|
|
|
int month = year*12;
|
|
|
|
|
|
|
|
double rep = Math.pow((1+intrate),month)/(Math.pow((1+intrate),month)-1);
|
|
|
|
|
|
|
|
double next_principal_and_interest = rep * intrate * amount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long userNum = usageDate.getUserNum();
|
|
|
|
|
|
|
|
long bankNum = usageDate.getBankNum();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Transaction transaction = new Transaction(checkNum,userNum,bankNum,next_principal_and_interest);
|
|
|
|
|
|
|
|
transMapper.addTransaction(transaction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Repayment repayment = paymentMapper.selectPepaymentBycheckNum(checkNum);
|
|
|
|
|
|
|
|
double repSum = next_principal_and_interest;
|
|
|
|
if(repayment!=null){
|
|
|
|
if(repayment!=null){
|
|
|
|
|
|
|
|
repSum += repayment.getRepSum();
|
|
|
|
|
|
|
|
repayment.setRepSum(repSum);
|
|
|
|
paymentMapper.updateRepayment(repayment);
|
|
|
|
paymentMapper.updateRepayment(repayment);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
paymentMapper.addRepayment(repayment);
|
|
|
|
paymentMapper.addRepayment(repayment);
|
|
|
@ -38,9 +97,27 @@ public class PayCirService {
|
|
|
|
}catch(Exception e){
|
|
|
|
}catch(Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}finally {
|
|
|
|
}finally {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int payAmountCirculator(long checkNum,double pay){
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
UsageDate usageDate = usageDateMapper.selectUsageDateByCheckNum(checkNum);
|
|
|
|
|
|
|
|
if(usageDate==null){return -2;}
|
|
|
|
|
|
|
|
int equation = usageDate.getEquation();
|
|
|
|
|
|
|
|
if(equation == 1){
|
|
|
|
|
|
|
|
return pay_EPAIR_AmountCirculator(checkNum,pay);
|
|
|
|
|
|
|
|
}else if(equation == 2){
|
|
|
|
|
|
|
|
return pay_EPR_AmountCirculator(checkNum,pay);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|