充值操做:
![](http://static.javashuo.com/static/loading.gif)
購買理財產品前端分析:
![](http://static.javashuo.com/static/loading.gif)
理財產品購買操做_設計到的表:
![](http://static.javashuo.com/static/loading.gif)
package cn.facebook.action.charge;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.facebook.action.common.BaseAction;
import cn.facebook.action.filter.GetHttpResponseHeader;
import cn.facebook.cache.BaseCacheService;
import cn.facebook.domain.Product;
import cn.facebook.domain.ProductAccount;
import cn.facebook.domain.accountLog.AccountLog;
import cn.facebook.domain.bankCardInfo.BankCardInfo;
import cn.facebook.domain.matchManagement.WeigthRule;
import cn.facebook.domain.productAcount.ExpectedReturn;
import cn.facebook.domain.productAcount.FundingNotMatchedModel;
import cn.facebook.domain.userAccount.UserAccountModel;
import cn.facebook.service.bankcardInfo.IBankCardInfoService;
import cn.facebook.service.charge.IChargeService;
import cn.facebook.service.expectedReturn.IExpectedReturnService;
import cn.facebook.service.product.IProductService;
import cn.facebook.service.productAccount.IProductAccountService;
import cn.facebook.service.userAccount.IUserAccountService;
import cn.facebook.service.weigthRule.IWeigthRuleService;
import cn.facebook.utils.BigDecimalUtil;
import cn.facebook.utils.FrontStatusConstants;
import cn.facebook.utils.FundsFlowType;
import cn.facebook.utils.InvestStatus;
import cn.facebook.utils.InvestTradeType;
import cn.facebook.utils.RandomNumberUtil;
import cn.facebook.utils.Response;
import cn.facebook.utils.TimestampUtils;
@Namespace("/charges")
@Controller
@Scope("prototype")
public class ChargesAction extends BaseAction {
@Autowired
private BaseCacheService baseCacheService;
@Autowired
private IBankCardInfoService bankCardInfoService;
@Autowired
private IChargeService chargeService;
@Autowired
private IUserAccountService userAccountService;
@Autowired
private IProductService productService;
@Autowired
private IWeigthRuleService weigthRuleService;
@Autowired
private IProductAccountService productAccountService;
@Autowired
private IExpectedReturnService expectedReturnService;
@Action("addMayTake")
public void addMayTake() {
//0、獲取token
String token = GetHttpResponseHeader.getHeadersInfo(this.getRequest());
Map<String, Object> hmap = baseCacheService.getHmap(token);
try {
if (hmap == null || hmap.size() == 0) {
this.getResponse().getWriter().write(Response.build().setStatus(FrontStatusConstants.NOT_LOGGED_IN).toJSON());
return;
}
int userid = (int)hmap.get("id");
String pProductId = this.getRequest().getParameter("pProductId");//購買產品id
String pAmount = this.getRequest().getParameter("pAmount");//購買金額
String pDeadline = this.getRequest().getParameter("pDeadline");//投資期限
String pExpectedAnnualIncome = this.getRequest().getParameter("pExpectedAnnualIncome"); //年利率
String pMonthInterest = this.getRequest().getParameter("pMonthInterest"); //每個月贏取利息
String pMonthlyExtractInterest = this.getRequest().getParameter("pMonthlyExtractInterest"); //每個月提取利息
// 本次投資總本息
String endInvestTotalMoney = BigDecimalUtil.endInvestTotalMoney(pAmount, pDeadline, pExpectedAnnualIncome, pMonthlyExtractInterest);
// 本次投資總利息
BigDecimal mayInterrestIncome = BigDecimalUtil.sub(endInvestTotalMoney, pAmount);
//---------------用戶帳戶表--t_account-----執行更改操做----------信息封裝
UserAccountModel uam = userAccountService.findByUserId(userid);
BigDecimal _balance = BigDecimalUtil.sub(uam.getBalance(), Double.parseDouble(pAmount)); //帳戶可用餘額
BigDecimal _inverstmentW = BigDecimalUtil.add(uam.getInverstmentW(), Double.parseDouble(pAmount)); //總計待收本金
BigDecimal _interestTotal = BigDecimalUtil.add(uam.getInterestTotal(), mayInterrestIncome.doubleValue());//總計待收利息
BigDecimal _recyclingInterest = BigDecimalUtil.add(uam.getRecyclingInterest(), Double.parseDouble(pAmount));//月取總額
BigDecimal _inverstmentA = BigDecimalUtil.add(uam.getInverstmentA(), Double.parseDouble(pAmount));//已投資總額
UserAccountModel userAccountModel = new UserAccountModel();
userAccountModel.setId(uam.getId());
userAccountModel.setBalance(_balance.doubleValue());
userAccountModel.setInverstmentW(_inverstmentW.doubleValue());
userAccountModel.setInterestTotal(_interestTotal.doubleValue());
userAccountModel.setRecyclingInterest(_recyclingInterest.doubleValue());
userAccountModel.setInterestA(_inverstmentA.doubleValue());
//---------------用戶帳戶表--t_account------------信息封裝
//---------------用戶投資表---t_product_Account----執行插入操做--------------
//查詢到的產品
Product product = productService.findById(Integer.parseInt(pProductId));
//要封裝的產品
ProductAccount pa = new ProductAccount();
Date date = new Date();//開始時間
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, Integer.parseInt(pDeadline));//結束日期
String randomNum = RandomNumberUtil.randomNumber(date);//隨機id
pa.setpProductId(product.getProId());
pa.setpProductName(product.getProductName());
pa.setpUid((long)uam.getId());
pa.setpSerialNo("TZNO"+randomNum);//投資編號
pa.setpBeginDate(date);
pa.setpEndDate(c.getTime());
pa.setpAmount(Double.parseDouble(pAmount));
pa.setpDeadline(Integer.parseInt(pDeadline));
pa.setpExpectedAnnualIncome(Double.parseDouble(pExpectedAnnualIncome));
pa.setpMonthInterest(Double.parseDouble(pMonthInterest));
pa.setpMonthlyExtractInterest(Double.parseDouble(pMonthlyExtractInterest));
pa.setpAvailableBalance(_balance.doubleValue());
pa.setpEndInvestTotalMoney(_inverstmentW.doubleValue());
pa.setpStatus(InvestStatus.WAIT_TO_MATCH);
pa.setaCurrentPeriod(1);
//---------------用戶投資表---t_product_Account------------------
//-----------------交易流水記錄日誌表 t_account_log-------插入數據-----------------
AccountLog accountlog = new AccountLog();
accountlog.setaUserId(userid);
accountlog.setaMainAccountId(userid);
accountlog.setaCurrentPeriod(1);
accountlog.setaReceiveOrPay(InvestTradeType.PAY);
accountlog.setaTransferSerialNo("LSNO"+randomNum);
accountlog.setaDate(date);
accountlog.setaType(FundsFlowType.INVEST_TYPE);
accountlog.setaTransferStatus(FundsFlowType.INVEST_SUCCESS);
accountlog.setaBeforeTradingMoney(uam.getBalance());
accountlog.setaAmount(Double.parseDouble(pAmount));
accountlog.setaAfterTradingMoney(_balance.doubleValue());
accountlog.setaDescreption("月取計劃TZNO"+randomNum);
//-----------------交易流水記錄日誌表 t_account_log------------------------
//----------------------權重表----t_weighrule-------------------------
WeigthRule wr = weigthRuleService.findByWeigthType(124);
//----------------------權重表----t_weighrule-------------------------
//------------------匹配資金錶---------t_funding_not_matched-------------------插入操做-------------------
FundingNotMatchedModel fnmm = new FundingNotMatchedModel();
fnmm.setUserId(userid);
fnmm.setfNotMatchedMoney(Double.parseDouble(pAmount));// fNotMatchedMoney 待匹配金額
fnmm.setfFoundingType(124);// fFoundingType 資金類型
fnmm.setfFoundingWeight(wr.getWeigthValue());// fFoundingWeight 資金
fnmm.setfIsLocked(FundsFlowType.FUND_NOT_LOCK);// fIsLocked 是否鎖定
//------------------匹配資金錶---------t_funding_not_matched--------------------------------------
//----------操做----------------
productAccountService.addProductAccount(userAccountModel, pa, accountlog, fnmm);
// 8.預期收益操做
for (int i = 0; i < Integer.parseInt(pDeadline); i++) {
ExpectedReturn er = new ExpectedReturn();
// 封裝數據
// 1. 用戶id
er.setUserId(uam.getId());
// 2. 產品id
er.setProductId((int) (product.getProId()));
// 3. 投資記錄id
er.setInvestRcord(pa.getpId());
// 4. 收益日期 當前月份+1
er.setExpectedDate(TimestampUtils.nextMonth(date.getYear(), date.getMonth(), i));
// 5. 收益金額、-----從請求參數中獲取
er.setExpectedMoney(Double.parseDouble(pMonthInterest));
// 6. 建立日期 new Date()
er.setCreateDate(date);
expectedReturnService.add(er);
}
// 發送短信,發送郵件
System.out.println("完成理財產品購買操做");
this.getResponse().getWriter().write(Response.build().setStatus(FrontStatusConstants.SUCCESS).toJSON());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//充值操做
@Action("charge")
public void charge() {
//0、獲取token
String token = GetHttpResponseHeader.getHeadersInfo(this.getRequest());
Map<String, Object> hmap = baseCacheService.getHmap(token);
try {
if (hmap == null || hmap.size() == 0) {
this.getResponse().getWriter().write(Response.build().setStatus(FrontStatusConstants.NOT_LOGGED_IN).toJSON());
return;
}
// 1. 在action中獲取請求參數---充值金額
String chargeMoney = this.getRequest().getParameter("chargeMoney");
double money = Double.parseDouble(chargeMoney);
// 2. 獲取銀行賬戶信息
int userid = (int) hmap.get("id");
BankCardInfo bankCardInfo = bankCardInfoService.findByUserId(userid);
String bankCardNum = bankCardInfo.getBankCardNum();
// 3. 向銀行服務器發送請求
boolean falg = chargeService.charge(money, bankCardNum, userid);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
相關代碼連接:
https://github.com/lqingfang/p2p前端
https://github.com/lqingfang/p2p_bankjava