程序运行能走完直到返回ok和success,不能保存的原因可能是什么
此处可以保存
public String saveBindBox(Integer userId, String barcode) throws Exception {
// TODO Auto-generated method stub
List boxList = boxDao.findByBarcode(barcode);
Box box = null;
if(boxList.size()!=0){
box = boxList.get(0);}
if (null == box){
return null;
}
if(box.getUseStatus()==3){
return "areadyBind";
}
if (box.getUseStatus() == 2){
UserBox userBox = new UserBox();
User user = userDao.findById(userId);
userBox.setUser(user);
userBox.setBox(box);
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = df.format(date);
Calendar c1 = Calendar. getInstance();
c1.setTime(date);
userBox.setStartDate(Timestamp.valueOf(dateStr));
Double amount = 0.0;
List paymentList = paymentDao.findByUserId(userId);
if (paymentList.size()==0){
return "nomoney";
}
for (Payment payment : paymentList) {
PayPackage paypackage = payment.getPayPackage();
if(paypackage.getTermType()==2){
c1.add(Calendar.MONTH, paypackage.getTermCount());
}else{
c1.add(Calendar.YEAR, paypackage.getTermCount());
}
Double b = paypackage.getAmount();
double a = amount.doubleValue();
a = a + b;
amount = a;
payment.setBox(box);
paymentDao.save(payment);
}
Timestamp ts = new Timestamp(System.currentTimeMillis());
ts = Timestamp.valueOf(df.format(c1.getTime()));
userBox.setEndDate(ts);
userBox.setArrears(amount);
userBox.setSchool(user.getSchool());
// todo 此处涉及到押金是否录入
userBox.setStatus(0);
userBoxDao.save(userBox);
user.setSchool(box.getSchool());
userDao.save(user);
box.setUseStatus(3);
box.setUser(user);
box.setSchool(user.getSchool());
boxDao.save(box);
return "ok";
}
return "error";
}
此处不能保存
public String removeBindBox(Integer userId, String barcode)
throws Exception {
List boxList = boxDao.findByBarcode(barcode);
Box box = null;
UserBox userBox = null;
if (boxList.size() != 0) {
box = boxList.get(0);
}
List userBoxList = userBoxDao.findByUserIdAndBoxId(userId, box.getId());
if (userBoxList.size() != 0) {
userBox = userBoxList.get(0);
}
if(null==userBox){
return "nobind";
}else{
userBoxDao.delete(userBox);
box.setUser(null);
box.setUseStatus(2);
boxDao.save(box);
return "success";
}
}
自己断点跟踪下就知道了。