parent
94bd4de5ca
commit
ebf4ba56d3
@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.Dao;
|
||||||
|
|
||||||
|
import com.example.demo.bean.Repayment;
|
||||||
|
import com.example.demo.bean.Transaction;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface paymentMapper {
|
||||||
|
@Select("select * from repayment where checkNum ={#checkNum}")
|
||||||
|
public Repayment selectPepaymentBycheckNum(long checkNum);
|
||||||
|
|
||||||
|
@Update("update repayment set repAmount = {#repAmount} ,repSum = {#repSum} where checkNum = {#checkNum}")
|
||||||
|
public void updateRepayment(Repayment repayment);
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.example.demo.bean;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
public class Repayment {
|
||||||
|
private long checkNum;
|
||||||
|
private double repAmount;
|
||||||
|
private double repSum;
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.example.demo.circulator.service;
|
||||||
|
|
||||||
|
import com.example.demo.Dao.paymentMapper;
|
||||||
|
import com.example.demo.Dao.transMapper;
|
||||||
|
import com.example.demo.Dao.usageDateMapper;
|
||||||
|
import com.example.demo.bean.Repayment;
|
||||||
|
import com.example.demo.bean.Transaction;
|
||||||
|
import com.example.demo.bean.UsageDate;
|
||||||
|
|
||||||
|
public class PayCirService {
|
||||||
|
private usageDateMapper usageDateMapper;
|
||||||
|
private paymentMapper paymentMapper;
|
||||||
|
private transMapper transMapper;
|
||||||
|
|
||||||
|
public int payAmountCirculator(long checkNum,double pay){
|
||||||
|
try{
|
||||||
|
Repayment repayment = paymentMapper.selectPepaymentBycheckNum(checkNum);
|
||||||
|
UsageDate usageDate= usageDateMapper.selectUsageDateByCheckNum(checkNum);
|
||||||
|
double rep_amount = repayment.getRepAmount();
|
||||||
|
long userNum = usageDate.getUserNum();
|
||||||
|
int bankNum = usageDate.getBankNum();
|
||||||
|
double amount = usageDate.getAmount();
|
||||||
|
int year = usageDate.getYear();
|
||||||
|
|
||||||
|
Transaction transaction = new Transaction(checkNum,userNum,bankNum,pay);
|
||||||
|
transMapper.addTransaction(transaction);
|
||||||
|
|
||||||
|
rep_amount = pay - amount/(year*12);
|
||||||
|
repayment.setRepAmount(rep_amount);
|
||||||
|
repayment.setRepSum(pay);
|
||||||
|
paymentMapper.updateRepayment(repayment);
|
||||||
|
return 1;
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.example.demo.circulator.service.controller;
|
||||||
|
|
||||||
|
import com.example.demo.circulator.service.PayCirService;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class PayCirController {
|
||||||
|
PayCirService payCirService;
|
||||||
|
|
||||||
|
@PostMapping("/pay")
|
||||||
|
public String payAmountCir(long checkNum,double pay){
|
||||||
|
int result = payCirService.payAmountCirculator(checkNum,pay);
|
||||||
|
if(result==1){
|
||||||
|
return "/还款成功";
|
||||||
|
}else{
|
||||||
|
return"/还款失败";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue