package com.gx.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.fangjian.framework.common.vo.HttpResultVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gx.dao.BorrowmanagementtenderMapper;
import com.gx.dao.BorrowmarkMapper;
import com.gx.dao.BorrowrepaymentplanMapper;
import com.gx.dao.P2pfileresourceMapper;
import com.gx.dao.P2pusercashflowMapper;
import com.gx.dao.P2puserfundaccountMapper;
import com.gx.dao.RepaymentorderMapper;
import com.gx.dao.RepaymentrecordMapper;
import com.gx.dao.TenderorderMapper;
import com.gx.dao.TenderrecordMapper;
import com.gx.enums.money.AccountTypeEnum;
import com.gx.enums.money.TransactionTypeEnum;
import com.gx.po.Borrowmanagementtender;
import com.gx.po.Borrowmark;
import com.gx.po.Borrowrepaymentplan;
import com.gx.po.P2pusercashflow;
import com.gx.po.P2puserfundaccount;
import com.gx.po.Repaymentorder;
import com.gx.po.Repaymentrecord;
import com.gx.po.Tenderorder;
import com.gx.po.Tenderrecord;
import com.gx.service.TenderrecordService;
import com.gx.util.app.DateUtil;
import com.gx.util.bigdecimal.BigDecimalUtil;
import com.gx.vo.InvestmentInfo;
import com.gx.vo.P2puserfundaccountQuery;
import com.gx.vo.ReceivablesVo;
@Transactional
@Service("tenderrecordService")
public class TenderrecordServiceImpl implements TenderrecordService {
//资金账户
@Autowired
private P2puserfundaccountMapper p2puserfundaccountMapper;
//借款标
@Autowired
private BorrowmarkMapper borrowmarkMapper;
//投标记录
@Autowired
private TenderrecordMapper tenderrecordMapper;
//投标订单
@Autowired
private TenderorderMapper tenderorderMapper;
//资金流水
@Autowired
private P2pusercashflowMapper p2pusercashflowMapper;
//借款标明细
@Autowired
private BorrowmanagementtenderMapper borrowmanagementtenderMapper;
//还款计划
@Autowired
private BorrowrepaymentplanMapper borrowrepaymentplanMapper;
//还款记录
@Autowired
private RepaymentrecordMapper repaymentrecordMapper;
//还款订单
@Autowired
private RepaymentorderMapper repaymentorderMapper;
//投标
@Override
public HttpResultVo tender(int mid, BigDecimal money, int borrowid) {
HttpResultVo vo = new HttpResultVo();
Tenderrecord rendrecd = new Tenderrecord();
P2puserfundaccountQuery userAccount = new P2puserfundaccountQuery();
Date d = new Date();
Borrowmark borrow = this.borrowmarkMapper.selectByPrimaryKey(borrowid);
userAccount.setAccount_type(AccountTypeEnum.CASH.name());
userAccount.setM_id(mid);
P2puserfundaccount useraCASHccount = this.p2puserfundaccountMapper.getUserFundAccountForLock(userAccount);
userAccount.setAccount_type(AccountTypeEnum.LOCK.name());
P2puserfundaccount useraLOCKccount = this.p2puserfundaccountMapper.getUserFundAccountForLock(userAccount);
//获取融资方资金账户
userAccount.setM_id(borrow.getmId());
userAccount.setAccount_type(AccountTypeEnum.CASH.name());
P2puserfundaccount reciprocal_useraCASHccount = this.p2puserfundaccountMapper.getUserFundAccountForLock(userAccount);
userAccount.setAccount_type(AccountTypeEnum.LOCK.name());
P2puserfundaccount reciprocal_useraLOCKccount = this.p2puserfundaccountMapper.getUserFundAccountForLock(userAccount);
//投标中
System.out.println("==========="+borrow.getBorrowingstatus());
if(borrow.getBorrowingstatus().equals(1)){
if(BigDecimalUtil.AbiggerThanB(money, borrow.getTenderable_quota())){
vo.setStatus(0);
vo.setErrorInfo("投资金额大于可投金额");
return vo;
}else{
if(BigDecimalUtil.AbiggerThanB(useraCASHccount.getAmount(), money)){
//1、新增投标记录
int rendrecd_id = 0;
rendrecd.setBorrow_id(borrowid);
rendrecd.setTender_amount(money);
rendrecd.setTender_actual_amount(new BigDecimal(0));
rendrecd.setTender_date(d);
rendrecd.setM_id(mid);
rendrecd.setIs_cancel("N");
rendrecd.setIs_fangkuan("N");
rendrecd_id = this.tenderrecordMapper.insertReturnIdVlues(rendrecd);
//2、新增投标订单
int tendorder_id = 0;
Tenderorder tendorder = new Tenderorder();
tendorder.setBorrow_id(borrowid);
tendorder.setTender_amount(money);
tendorder.setTender_record_id(rendrecd_id);
tendorder.setM_id(mid);
this.tenderorderMapper.insertReturnIdVlues(tendorder);
//3、处理用户资金情况
useraCASHccount.setAmount(BigDecimalUtil.sub(useraCASHccount.getAmount(), money));
this.p2puserfundaccountMapper.updateByPrimaryKey(useraCASHccount);
useraLOCKccount.setAmount(BigDecimalUtil.add(useraLOCKccount.getAmount(), money));
this.p2puserfundaccountMapper.updateByPrimaryKey(useraLOCKccount);
//4、新增资金流水
P2pusercashflow usercashflow = new P2pusercashflow();
usercashflow.setApply_id(null);
usercashflow.setIncome(new BigDecimal(0));
usercashflow.setOutlay(money);
usercashflow.setOrder_id(tendorder_id);
usercashflow.setM_id(mid);
usercashflow.setCreatetime(d);
usercashflow.setFinancial_tran_type(TransactionTypeEnum.TB.name());
usercashflow.setReciprocal_fund_account_id(reciprocal_useraCASHccount.getId());
usercashflow.setRemarks("投标成功,现金账户 -" + money);
usercashflow.setUserfundaccountid(useraCASHccount.getId());
usercashflow.setUser_fund_account_amount(useraCASHccount.getAmount());
this.p2pusercashflowMapper.insertReturnIdVlues(usercashflow);
//5、新增用户冻结资金
P2pusercashflow lock_flow = new P2pusercashflow();
lock_flow.setApply_id(null);
lock_flow.setIncome(money);
lock_flow.setOutlay(new BigDecimal(0));
lock_flow.setOrder_id(tendorder_id);
lock_flow.setM_id(mid);
lock_flow.setCreatetime(d);
lock_flow.setFinancial_tran_type(TransactionTypeEnum.TB.name());
lock_flow.setReciprocal_fund_account_id(reciprocal_useraLOCKccount.getId());
lock_flow.setRemarks("投标成功,锁定账户 +" + money);
lock_flow.setUser_fund_account_amount(useraLOCKccount.getAmount());
lock_flow.setUserfundaccountid(useraLOCKccount.getId());
this.p2pusercashflowMapper.insertReturnIdVlues(lock_flow);
//处理标的可投金额
borrow.setTenderable_quota(BigDecimalUtil.sub(borrow.getTenderable_quota(), money));
this.borrowmarkMapper.updateByPrimaryKey(borrow);
vo.setStatus(1);
vo.setErrorInfo("投标成功");
return vo;
}else{
vo.setStatus(0);
vo.setErrorInfo("余额不足");
return vo;
}
}
}else{
vo.setStatus(0);
vo.setErrorInfo("该标目前不在投标中状态");
return vo;
}
}
@Override
public List<Tenderrecord> findByBorrowId(int borrow_id) {
return tenderrecordMapper.findByBorrowId(borrow_id);
}
//退款
@Override
public HttpResultVo tk(Integer borrow_id) {
HttpResultVo vo = new HttpResultVo();
Date d = new Date();
P2puserfundaccountQuery userAccount = new P2puserfundaccountQuery();
Borrowmark borrow = this.borrowmarkMapper.selectByPrimaryKey(borrow_id);
Borrowmanagementtender borrow_item = this.borrowmanagementtenderMapper.findbyborrowId(borrow_id);
P2puserfundaccount useraCASHccount = null;
P2puserfundaccount useraLOCKccount = null;
if(borrow.getBorrowingstatus().equals(2)){
List<Tenderrecord> records = this.tenderrecordMapper.findByBorrowId(borrow_id);
for(Tenderrecord t:records){
//投资人资金原路返回,投资人现金账户增加,冻结资金账户减少
userAccount.setAccount_type(AccountTypeEnum.CASH.name());
userAccount.setM_id(t.getM_id());
- 1
- 2
- 3
前往页