@Transactional
public Map save(TradeInvestment tradeInvestment) {
Map map=new HashMap();
try{
Long userId=tradeInvestment.getBaseUserInfo().getBaseUserInfoId();//用户Id
//用户对象
user=userDao.getPojoById("com.gdpe.wsd.web.pojo.user.BaseUserInfo", userId);
String tradeInvestmentNumber=Financing.randomInvestNumber();
//输出ID(控制台输出了一次) System.out.println(tradeInvestment.getTradeFinancing().getTradeFinancingId());
TradeFinancing tradeFinancing=(TradeFinancing) tradeFinancingDao.getPojoById("com.gdpe.wsd.manage.pojo.trade.TradeFinancing", tradeInvestment.getTradeFinancing().getTradeFinancingId());
//账户对象
FinanceUserAccount financeUserAccount=user.getFinanceUserAccount();
Double amout=tradeInvestment.getTradeInvestmentAmount();
Double syamount=tradeFinancing.getFinancingAmount()-tradeFinancing.getInvestmentAmount();
Double abamount=financeUserAccount.getFinanceAvailableBalance();//账户可用余额
if(amout<=syamount){
if(amout<=abamount){
if(amout>=tradeFinancing.getMinmoney()){
String content1="普通标--------人名:"+user.getBaseLoginName()+"-----金额:"+tradeInvestment.getTradeInvestmentAmount();
Log.writeFileHQ(content1); //文件中写入日志多次
tradeInvestment.setTradeInvestmentNumber(tradeInvestmentNumber);//编码
tradeInvestment.setTradeInvestmentTime(tradeInvestment.getTradeInvestmentTime());//投资时间
tradeInvestment.setTradeInvestmentStatus("0");//已投状态
tradeInvestment.setTradeFinancing(tradeFinancing);
tradeInvestmentDao.save(tradeInvestment);//保存投资表(对象保存了多次)
user=userDao.getPojoById("com.gdpe.wsd.web.pojo.user.BaseUserInfo", userId);
map.put("user", user);
map.put("msg", "sucess");
}else{
map.put("user", user);
map.put("msg", "minmoney");
}
}else{
map.put("user", user);
map.put("msg", "amoney");
}
}else{
map.put("user", user);
map.put("msg", "fmoney");
}
}catch(Exception e){
map.put("user", user);
map.put("msg", "fail");
}
return map;
}
描述:方法加了事务管理
用户ID即(System.out.println(tradeInvestment.getTradeFinancing().getTradeFinancingId());)在控制台输出了一次,但是后面的文件写入日志 和 保存对象却执行了多次