发表于: 2018-01-30 18:32:33

1 711


今天完成的事

投资模块完成了

package com.ptteng.com.ptteng.serviceImpl;

import HomeInterface.InvestService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ptteng.POJO.InvestProduct;
import com.ptteng.dao.*;
import com.ptteng.utils.NumberUtil;
import com.ptteng.utils.ReplayScheduleUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import pojo.*;

import java.math.BigDecimal;
import java.util.*;

/**
* Created by gaomi on 2018/1/26.
*/
@RestController
public class InvestServiceImpl implements InvestService {
Logger logger = Logger.getLogger(InvestServiceImpl.class);

   @Autowired
   private TUserMapper tUserMapper;
   @Autowired
   private TTradeMapper tTradeMapper;
   @Autowired
   private TUserBankMapper tUserBankMapper;
   @Autowired
   private TProductMapper tProductMapper;
   @Autowired
   private TIdentityMapper tIdentityMapper;
   @Autowired
   private TBankMapper tBankMapper;
   @Autowired
   private TInvestmentMapper tInvestmentMapper;
   @Autowired
   private ReplayScheduleUtil replayScheduleUtil;
   @Autowired
   private TMessageMapper tMessageMapper;
   @Autowired
   private TConstantMapper tConstantMapper;


   @Autowired
   private NumberUtil numberUtil;
   @Autowired
   private TSalesMapper tSalesMapper;

   Map<StringObject> map new HashMap<StringObject>();
   ObjectMapper mapper new ObjectMapper();

   @Override
   public List<TTrade> selectTradeByUidPid(Long uidLong pid) {
return tTradeMapper.selectTradeByUidPid(uidpid);
   }

@Override
   public String getInvestOrder(Long uidLong pid) {
try {
TProduct product = tProductMapper.getTProductById(pid);
           if (product == null || Objects.equals(product.getStatus()0)) {
logger.info("Product is not exist.");
               logger.info("product is no exist, productId:" + pid);
               map.put("message""该产品不存在");
               String json = mapper.writeValueAsString(map);
               return json;
           }


TUser user = tUserMapper.selectByPrimaryKey(uid);
           TIdentity tIdentity = tIdentityMapper.getTIdentityByUserId(uid);
           logger.info("Get user's information by uid from session success: user = " + user + "Identity = " + tIdentity + pid);

           Integer verifyStatus = tIdentity.getIdentityStatus();
           if (Objects.equals(verifyStatus1)) {
map.put("message""您还未进行实名认证");
               String json = mapper.writeValueAsString(map);
               return json;
           }

//限购产品还要判断该用户是否已经购买过该产品
           Integer isLimit = product.getBuyLimit();
           List<TTrade> tTrades = tTradeMapper.selectTradeByUidPid(uidpid);

           if (Objects.equals(isLimit1) && tTrades.size() != 0) {
logger.info("Invest failure, product is restricted and this user has buy it.");
               map.put("message""该产品限购,您已购买过,不能继续购买。");
               String json = mapper.writeValueAsString(map);
               return json;
           }

map.put("code"0);
           map.put("product"product);


           int status = 1;
           TUserBank tUserBank = tUserBankMapper.getUserBankByUidAndDefault(uidstatus);

           if (tUserBank != null) {
logger.info("User's default UserBank = " + tUserBank);

               TBank tBank = tBankMapper.selectByPrimaryKey(tUserBank.getBankId());

               logger.info("用户的银行卡为+ tBank);
               map.put("tUserBank"tUserBank);
               map.put("bank"tBank);
               map.put("product"product);
               logger.info("User's default UserBank = " + tUserBank + tBank + product);
           }

String json = mapper.writeValueAsString(map);
           return json;

       catch (Throwable t) {
t.printStackTrace();
           logger.error(t.getMessage());
           logger.error("Server false, try again later.");

       }
map.put("message""服务器故障");
       String json = null;
       try {
json = mapper.writeValueAsString(map);
       catch (JsonProcessingException e) {
e.printStackTrace();
       }
return json;
   }

@Override
   public String payInvestOrder(Long uidLong pidLong cidBigDecimal principalString imgUrl) {
try {
if (cid == null || principal == null || imgUrl == null) {
logger.info("Params ard null: cid = " + cid + ", principal = " + principal + ", imgUrl = " + imgUrl);
               map.put("message""参数为空");
               String json = mapper.writeValueAsString(map);
               return json;
           }
logger.info("Pay success: pid = " + pid + ", cid = " + cid + ", principal = " + principal + ", imgUrl = " + imgUrl);

           TProduct product = tProductMapper.getTProductById(pid);
           if (product == null) {
map.put("message""产品不存在");
               String json = mapper.writeValueAsString(map);
               return json;
           }
/* 投资本金小于起投金额 或者不是10000的整数倍时,返回错误 */
           BigDecimal minAmount = product.getMinAmount();
           if (principal.compareTo(minAmount) == -|| !Objects.equals(principal.divideAndRemainder(BigDecimal.valueOf(10000))[1]BigDecimal.valueOf(0))) {
map.put("message""投资金额必须为起投金额整数倍,请重新输入。");
               String json = mapper.writeValueAsString(map);
               return json;
           }
//第一次投资时,返回投资的起息日期和到期日期
           List<Long> beginAtAndEndAt = replayScheduleUtil.getBeginAtAndEndAt(product.getInterestBeginWay()product.getLimit()product.getTimeLimitType());
           Long beginAt = beginAtAndEndAt.get(0);//list第一条数据为beginAt
           Long endAt = beginAtAndEndAt.get(1);//list第二条数据为endAt
           logger.info("This invest: beginAt = " + beginAt + ", endAt = " + endAt);

           String tradetNnm = numberUtil.createTransactNo();
           logger.info("Create new data: tradetNnm = " + tradetNnm);

           TUserBank tUserBank = tUserBankMapper.selectByPrimaryKey(cid);
           TBank tBank = tBankMapper.selectByPrimaryKey(tUserBank.getBankId());

           TTrade tTrade = new TTrade();
           int longUid = uid.intValue();
           tTrade.setUserId(longUid);
           int longPid = pid.intValue();
           tTrade.setProductId(longPid);
           tTrade.setTradeSerialNumber(tradetNnm);
           tTrade.setCardNum(tUserBank.getCardNum());
           tTrade.setBankName(tBank.getName());
           tTrade.setAmount(principal);
           //交易状态默认都是成功的,即为1
           tTrade.setStatus(1);
           //交易默认是付款,即为1
           tTrade.setScene(1);
           tTrade.setCreateAt(System.currentTimeMillis());
           tTrade.setCreateAt(uid);
           tTrade.setUpdateAt(uid);
           tTradeMapper.insert(tTrade);

           logger.info("插入的交易记录ID+ tTrade.getId());

           String loanAgreementNo = numberUtil.createLoanAgreementNo(pid);
           String debtAgreementNo = numberUtil.createDebtAgreementNo();

           logger.info("Create new data: loanAgreementNo = " + loanAgreementNo + ", debtAgreementNo = " + debtAgreementNo +
", imgUrl = " + imgUrl);

           BigDecimal expectInterest = replayScheduleUtil.expectInterest(principalproduct);

           TInvestment tInvestment = new TInvestment();

           tInvestment.setTradeId(tTrade.getId());
           tInvestment.setCreditId(null);
           //默认为不续投
           tInvestment.setInvestmentAgainId((long0);
           tInvestment.setSignatureImgUrl(imgUrl);
           tInvestment.setContractIda(loanAgreementNo);
           tInvestment.setContractIdb(debtAgreementNo);
           tInvestment.setContractIdc(null);
           tInvestment.setContractIdd(null);
           tInvestment.setContractIde(null);
           tInvestment.setCardNum(tUserBank.getCardNum());
           tInvestment.setBankName(tBank.getName());
           tInvestment.setInterestBeginAt(beginAt);
           tInvestment.setInterestEndAt(endAt);

           tInvestment.setAlreadyInterest(BigDecimal.valueOf(0.0000));
           tInvestment.setNotYetInterest(expectInterest);
           //默认直接为投资中
           tInvestment.setStatus(2);
           tInvestment.setCreateAt(System.currentTimeMillis());
           tInvestment.setCreateBy(Math.toIntExact(uid));
         // tInvestment.setUpdateBy(Math.toIntExact(pid));
           logger.info("投资记录表生成的记录为+ tInvestment);

           tInvestmentMapper.insert(tInvestment);

           logger.info("New Investment record insert success: id = " + tInvestment.getId());

           //新增还款计划
           Integer payBackType = product.getPayBackType();
           //1是到期直接还款
           if (Objects.equals(payBackType1)) {
Long rid = replayScheduleUtil.generatorByFinalPayments(productproduct.getInterestBeginWay()tInvestment.getId()uidcidpidprincipal);
               logger.info("New final-payments's replay-schedule record insert success: id = " + rid);
           else {
List<TRepayment> replayScheduleList = replayScheduleUtil.generatorByMonthlyPayments(productproduct.getInterestBeginWay()tInvestment.getId()uidcidpidprincipal);
               logger.info("New monthly-payments's replay-schedule records insert success: id's size = " + replayScheduleList.size());
           }

TSales sales = tSalesMapper.selectByProductId(pid);
           //更新产品总销量
           if (sales == null) {
TSales tSales = new TSales();
               logger.info("我就不信pid能为空?+ pid);
               int longpid = pid.intValue();
               tSales.setProductId(longpid);
               tSales.setBuyPersonSum(1);
               tSales.setBuyCount(1);
               tSales.setBuySumAmount(principal);
               tSales.setCreateAt(System.currentTimeMillis());
               tSalesMapper.insert(tSales);
           else {
TSales newSales = new TSales();
               newSales.setBuyPersonSum(sales.getBuyPersonSum() + 1);
               BigDecimal buySumAmount = sales.getBuySumAmount().add(principal);
               newSales.setBuySumAmount(buySumAmount);
               newSales.setBuyCount(sales.getBuyCount() + 1);
               newSales.setUpdateAt(System.currentTimeMillis());
               tSalesMapper.updateByPrimaryKey(newSales);
           }

//更新消息
           TMessage tMessage = new TMessage();
           tMessage.setUserId(uid);
           tMessage.setTradeId(tTrade.getId());
           tMessage.setType(0);
           tMessage.setPersonType(2);
           tMessage.setSendType(1);
           tMessage.setPaper("您已成功投资");
           tMessage.setSynchronization(1);
           tMessage.setStatus(0);
           tMessage.setCreateAt(System.currentTimeMillis());

           tMessageMapper.insert(tMessage);

           //更新用户资产
           TUser tUser = tUserMapper.selectByPrimaryKey(uid);
           BigDecimal totalPrincipal = tUser.getTotalPrincipal().add(principal);
           tUser.setTotalPrincipal(totalPrincipal);
           tUser.setUnread(tUser.getUnread() + 1);
           //未读消息+1
           tUserMapper.updateByPrimaryKey(tUser);
           logger.info("User asset increase success: uid = " + uid + ", new totalPrincipal = " + totalPrincipal);


           map.put("message""投资成功");
           String json = mapper.writeValueAsString(map);
           return json;
       catch (Throwable t) {
t.printStackTrace();
           map.put("message""服务器故障,投资失败");
           String json = null;
           try {
json = mapper.writeValueAsString(map);
           catch (JsonProcessingException e1) {
e1.printStackTrace();
           }
return json;
       }


}

@Override
   public String getInvestRecordList(Long uidInteger statusInteger pageInteger size) {
logger.info("Display user's invest records, uid = " + uid + ", status = " + status + ", page = " + page + ", size = " + size);
       if (status == null || status < -|| status > 3) {
map.put("message""参数不可以为空");
           String json = null;
           try {
json = mapper.writeValueAsString(map);
           catch (JsonProcessingException e) {
e.printStackTrace();
           }
return json;
       }
if (page == null) {
page = 1;
       }

if (size == null) {
size = 10;
       }

int start = (page - 1) * size;
       if (start < 0) {
start = 0;
       }

try {
List<TInvestment> tInvestments = tInvestmentMapper.selectInvestmenteByUidandStatus(Math.toIntExact(uid)status);
           List<InvestProduct> investProducts = new ArrayList();

           for (TInvestment invest : tInvestments) {

TTrade tTrade=tTradeMapper.selectByPrimaryKey(invest.getTradeId());

               TProduct product=tProductMapper.getTProductById(Long.valueOf(tTrade.getProductId()));
               logger.info("取到的关联产品为+ product);
               //map.put(""+pid, product);
               InvestProduct investProduct = new InvestProduct();
               investProduct.setInvestId(invest.getId());
               investProduct.setProductName(product.getName());
               investProduct.setYearRate(product.getYearRate());
               investProduct.setStatus(invest.getStatus());
               investProduct.setTag(product.getTag());
               BigDecimal P = invest.getAlreadyInterest().add(invest.getNotYetInterest());
               investProduct.setPrincipal(P);
               investProduct.setBeginAt(invest.getInterestBeginAt());
               investProduct.setEndAt(invest.getInterestEndAt());
               logger.info("理财记录为+ investProduct);

               investProducts.add(investProduct);
           }
//map.put("investList",tInvestments);

           map.put("investList"investProducts);
           String json = mapper.writeValueAsString(map);
           return json;


       catch (Exception e) {
map.put("message""服务器故障,查看失败");
           String json = null;
           try {
json = mapper.writeValueAsString(map);
           catch (JsonProcessingException e1) {
e1.printStackTrace();
           }
return json;
       }

}

@Override
   public String getInvestRecordDetail(Long investId,Long uid) {
logger.info("Display user's invest record detail: id = " + investId+"uid"+uid);

       try {
TInvestment investment=tInvestmentMapper.selectByPrimaryKey(investId);
           if (investment==null) {
map.put("message""您未投资此产品");
               String json = mapper.writeValueAsString(map);
               return json;
           }
//防止越权查看他人的投资详情
           logger.info("投资详情为"+investment);
           if (!Objects.equals((long)investment.getCreateBy()uid)) {
map.put("message""您无权进行这个操作");
               String json = mapper.writeValueAsString(map);
               return json;
           }

TUserBank tUserBank=tUserBankMapper.getUserBankByUidAndDefault(uid,1);

           TProduct tProduct=tProductMapper.getTProductById(Long.valueOf(investment.getUpdateBy()));

           TBank tBank=tBankMapper.selectByPrimaryKey(tUserBank.getBankId());

           TTrade tTrade=tTradeMapper.selectByPrimaryKey(investment.getTradeId());

           map.put("message""成功");
           map.put("tTrade"tTrade);
           map.put("investList"investment);
           map.put("tProduct"tProduct);
           map.put("tUserBank"tUserBank);
           map.put("tBank"tBank);


           String json = mapper.writeValueAsString(map);
           return json;

       catch (Exception e) {
e.printStackTrace();
           map.put("message""服务器故障,查看失败");
           String json = null;
           try {
json = mapper.writeValueAsString(map);
           catch (JsonProcessingException e1) {
e1.printStackTrace();
           }
return json;
       }
}

@Override
   public String getContinueList(Long uidInteger status) {
logger.info("Display user's continuable invest record: uid= " + uid + ", status = " + status);

       List<TInvestment> tInvestments=tInvestmentMapper.selectInvestmenteByUidandStatus(Math.toIntExact(uid),status);
       try{
if (tInvestments.isEmpty()){
map.put("message""您无可投资产");
           String json = mapper.writeValueAsString(map);
           return json;
       }
TConstant tConstant=tConstantMapper.selectLastConstantByPrimaryKey();

           if (tConstant==null) {
map.put("message""后台参数未设置,请联系管理员");
               String json = mapper.writeValueAsString(map);
               return json;
           }
int investDeadlineDays=tConstant.getInvestDeadlineDays();

           List<InvestProduct> continuableInvestProductList=new ArrayList<>();

           InvestProduct investProduct=new InvestProduct();

           Long today = replayScheduleUtil.getCalendar(new Date()).getTimeInMillis();
           for(TInvestment tInvestment:tInvestments ){
Long endAt=tInvestment.getInterestEndAt();
               TTrade tTrade=tTradeMapper.selectByPrimaryKey(tInvestment.getTradeId());
               TProduct tProduct=tProductMapper.getTProductById(Long.valueOf(tTrade.getProductId()));
               Long result = endAt - today;
               Long investmentAgainId =tInvestment.getInvestmentAgainId();
               Long continueInvestdays=investDeadlineDays* 60000L 60L 24L;
               logger.info("investmentAgainId:"+investmentAgainId+"距离到其剩余"+result+"产品是否限购"+tProduct.getBuyLimit()+"在多少天内提醒"+ continueInvestdays);
               //除了时间满足条件外,还要求该投资记录满足可续投未续投两个条件

               if (investmentAgainId==0    &&tProduct.getBuyLimit()==&&result<=(investDeadlineDays* 60000L 60L 24L)){
investProduct.setInvestId(tInvestment.getId());
                   investProduct.setProductName(tProduct.getName());
                   investProduct.setTag(tProduct.getTag());
                   investProduct.setBeginAt(tInvestment.getInterestBeginAt());
                   investProduct.setEndAt(tInvestment.getInterestEndAt());
                   investProduct.setStatus(2);
                   investProduct.setYearRate(tProduct.getYearRate());
                   investProduct.setPrincipal(tTrade.getAmount());

                   continuableInvestProductList.add(investProduct);
               }

}
map.put("continuableInvestList"continuableInvestProductList);


           String json = mapper.writeValueAsString(map);
           return json;





       catch (Exception e) {
e.printStackTrace();
           map.put("message""服务器故障,查看可续投失败");
           String json = null;
           try {
json = mapper.writeValueAsString(map);
           catch (JsonProcessingException e1) {
e1.printStackTrace();
           }
return json;
       }




}

@Override
   public String prepareContinue(Long uidLong investId) {
try{
logger.info("准备续投的用户ID"+uid+"准备续投的投资记录id"+investId);

          TInvestment tInvestment=tInvestmentMapper.selectByPrimaryKey(investId);

          if (tInvestment==null){
logger.info("Invest record is not exist: id = " + investId);
              map.put("message""投资记录为空");
              String json = mapper.writeValueAsString(map);
              return json;
          }
long userid=tInvestment.getCreateBy();
          if (userid!=uid){
logger.info("No permission: uid = " + uid + ", investId = " + investId);
              map.put("message""您没有此权限");
              String json = mapper.writeValueAsString(map);
              return json;
          }
TTrade tTrade=tTradeMapper.selectByPrimaryKey(tInvestment.getTradeId());
          TProduct tProduct=tProductMapper.getTProductById(Long.valueOf(tTrade.getProductId()));

           if (tProduct.getStatus()==0){
map.put("message""该产品已经停购。");
               String json = mapper.writeValueAsString(map);
               return json;
           }

//续投的起始日期,到期日期
          List<Long> beginAtAndEndAt = replayScheduleUtil.getBeginAtAndEndAt(tInvestment,tProduct);
          Long beginAt = beginAtAndEndAt.get(0);//list第一条数据为beginAt
          Long endAt = beginAtAndEndAt.get(1);//list第二条数据为endAt
          logger.info("This invest: beginAt = " + beginAt + ", endAt = " + endAt);
           tInvestment.setInterestBeginAt(beginAt);
           tInvestment.setInterestEndAt(endAt);

          //预期收益
          BigDecimal expectInterest = replayScheduleUtil.expectInterest(tTrade.getAmount(),tProduct);
          logger.info("Expect interest = " + expectInterest);

          tInvestment.setNotYetInterest(expectInterest);
          TUserBank tUserBank=tUserBankMapper.getUserBankByUidAndDefault(uid,1);

          TBank tBank=tBankMapper.selectByPrimaryKey(tUserBank.getBankId());


          map.put("message""成功");
          map.put("tTrade"tTrade);
          map.put("investList"tInvestment);
          map.put("tProduct"tProduct);
          map.put("tUserBank"tUserBank);
          map.put("tBank"tBank);

          String json = mapper.writeValueAsString(map);
          return json;


      }
catch (Exception e){
e.printStackTrace();
          map.put("message""服务器故障,续投失败");
          String json = null;
          try {
json = mapper.writeValueAsString(map);
          catch (JsonProcessingException e1) {
e1.printStackTrace();
          }
return json;

      }
}

@Override
   public String comfirmContinueInvest(Long uidLong investIdLong cidString signImgLong beginAtLong endAt) {
logger.info("POST /a/u/invest/continue/{investId}, "+"uid"+uid+"investId:" + investId + ", cardId:" + cid + ", signImg:"
               + signImg + ", beginAt:" + beginAt + ", endAt:" + endAt);
       try{
TInvestment oldInvest=tInvestmentMapper.selectByPrimaryKey(investId);
           if (oldInvest==null){
logger.info("Invest record is not exist: id = " + investId);
               map.put("message""投资记录不存在");
               String json = mapper.writeValueAsString(map);
               return json;
           }
long userid=oldInvest.getCreateBy();
           if (userid!=uid){
logger.info("No permission: uid = " + uid + ", investId = " + investId);
               map.put("message""您没有权限执行这个操作");
               String json = mapper.writeValueAsString(map);
               return json;
           }
TTrade tTrade=tTradeMapper.selectByPrimaryKey(oldInvest.getTradeId());
           TProduct tProduct=tProductMapper.getTProductById(Long.valueOf(tTrade.getProductId()));

           if (tProduct.getStatus()==0){
map.put("message""该产品已经停售。");
               String json = mapper.writeValueAsString(map);
               return json;
           }
if (tProduct.getBuyLimit()==1){
map.put("message""该产品限购,不可重复购买");
               String json = mapper.writeValueAsString(map);
               return json;
           }
if (oldInvest.getStatus()==3){
map.put("message""您已续投过,不可再次续投。");
               String json = mapper.writeValueAsString(map);
               return json;
           }
if(oldInvest.getInvestmentAgainId()!=0){
map.put("message""您已续投过,不可再次续投。");
               String json = mapper.writeValueAsString(map);
               return json;
           }
/* 获取当天凌晨0点的时间戳 */
           Long today = replayScheduleUtil.getCalendar(new Date()).getTimeInMillis();

           TConstant tConstant=tConstantMapper.selectLastConstantByPrimaryKey();

           if (tConstant==null) {
map.put("message""后台参数未设置,请联系管理员");
               String json = mapper.writeValueAsString(map);
               return json;
           }
int investDeadlineDays=tConstant.getInvestDeadlineDays();

           if((oldInvest.getInterestEndAt()-today)>investDeadlineDays * 86400000L){
map.put("message""还未到可续投时间,你花什么钱");
               String json = mapper.writeValueAsString(map);
               return json;
           }

logger.info("User comfirm to continue invest: uid = " + uid + ", investId = " + investId);

           //新增投资记录
           String loanAgreementNo = numberUtil.createLoanAgreementNo(tProduct.getId());
           String debtAgreementNo = numberUtil.createDebtAgreementNo();
           logger.info("Create new data: loanAgreementNo = " + loanAgreementNo + ", debtAgreementNo = " + debtAgreementNo +
", signImgUrl = " + signImg);

           BigDecimal principal=tTrade.getAmount();
           BigDecimal expectInterest = replayScheduleUtil.expectInterest(principaltProduct);

           logger.info("续投本金为"+principal+"续投收益为"+expectInterest);


           //取到用户的默认银行卡。
           TUserBank tUserBank=tUserBankMapper.getUserBankByUidAndDefault(uid,1);

           TBank tBank=tBankMapper.selectByPrimaryKey(tUserBank.getBankId());

           TInvestment tInvestment = new TInvestment();



           //不生成新的交易记录。
           tInvestment.setTradeId(tTrade.getId());
           tInvestment.setCreditId(null);
           //默认为续投前的投资ID
           tInvestment.setInvestmentAgainId(oldInvest.getId());
           tInvestment.setSignatureImgUrl(signImg);
           tInvestment.setContractIda(loanAgreementNo);
           tInvestment.setContractIdb(debtAgreementNo);
           tInvestment.setContractIdc(null);
           tInvestment.setContractIdd(null);
           tInvestment.setContractIde(null);
           tInvestment.setCardNum(tUserBank.getCardNum());
           tInvestment.setBankName(tBank.getName());
           tInvestment.setInterestBeginAt(beginAt);
           tInvestment.setInterestEndAt(endAt);

           tInvestment.setAlreadyInterest(BigDecimal.valueOf(0.0000));
           tInvestment.setNotYetInterest(expectInterest);

           //默认未生效
           //因为是双重判定,只要有续投ID和状态为已续投都不可续投。
           tInvestment.setStatus(4);
           tInvestment.setCreateAt(System.currentTimeMillis());
           tInvestment.setCreateBy(Math.toIntExact(uid));

           logger.info("投资记录表生成的记录为+ tInvestment);

           tInvestmentMapper.insert(tInvestment);

           logger.info("New Investment record insert success: id = " + tInvestment.getId());

           //修改以前投资状态为已续投。
           oldInvest.setStatus(3);
           tInvestmentMapper.updateByPrimaryKey(oldInvest);

           //新的还款计划 ==> 还款计划Util不可复用,需要重构
           Integer repaymentMode = tProduct.getPayBackType();
           //1是到期直接还款
           if (Objects.equals(repaymentMode1)) {
Long rid = replayScheduleUtil.continueByFinalPayments(tProducttInvestment.getId()uidcidtProduct.getId()principalbeginAtendAtexpectInterest);
               logger.info("New final-payments's replay-schedule record insert success: id = " + rid);
           else {
List<TRepayment> replayScheduleList = replayScheduleUtil.continueByMonthlyPayments(tProducttInvestment.getId()uidcidtProduct.getId()principalbeginAtendAtexpectInterest);
               logger.info("New monthly-payments's replay-schedule records insert success: id's size = " + replayScheduleList.size());
           }
TSales sales = tSalesMapper.selectByProductId(tProduct.getId());
           //更新产品总销量
           if (sales == null) {
TSales tSales = new TSales();
               logger.info("产品ID+ tProduct.getId());
               int longpid = tProduct.getId().intValue();
               tSales.setProductId(longpid);
               tSales.setBuyPersonSum(1);
               tSales.setBuyCount(1);
               tSales.setBuySumAmount(principal);
               tSales.setCreateAt(System.currentTimeMillis());
               tSalesMapper.insert(tSales);
           else {
TSales newSales = new TSales();
               newSales.setBuyPersonSum(sales.getBuyPersonSum() + 1);
               BigDecimal buySumAmount = sales.getBuySumAmount().add(principal);
               newSales.setBuySumAmount(buySumAmount);
               newSales.setBuyCount(sales.getBuyCount() + 1);
               newSales.setUpdateAt(System.currentTimeMillis());
               tSalesMapper.updateByPrimaryKey(newSales);
           }

return null;














       }catch (Exception e){
e.printStackTrace();
           map.put("message""服务器故障,稍后再试");
           String json = null;
           try {
json = mapper.writeValueAsString(map);
           catch (JsonProcessingException e1) {
e1.printStackTrace();
           }
return json;

       }





}


}

遇到的问题

参数精度丢失 

明天的计划

小课堂


返回列表 返回列表
评论

    分享到