public ResultObject addCharge(String customerName, int productId, int amount, float price) { AcountBeanDao acountDao = new AcountBeanDao(); AcountBean acount = acountDao.getAcountByIdAndCustomer(productId, customerName); if (acount == null) { acount = new AcountBean(); acount.setProductId(productId); acount.setAmount(amount); acount.setCustomerName(customerName); } else { acount.setAmount(acount.getAmount() + amount); } ChargeBeanDao chargeDao = new ChargeBeanDao(); ChargeBean charge = new ChargeBean(); charge.setAmount(amount); charge.setIntime(new Date()); charge.setProductId(productId); charge.setCustomerName(customerName); if (price >= 0) { // 负数侧自动计算 charge.setPrice(price); } else { ProductBeanDao productDao = new ProductBeanDao(); ProductBean product = productDao.getProductById(productId); charge.setPrice(product.getPrice() * amount); } acountDao.saveOrUpdateAcount(acount); chargeDao.saveCharge(charge); return new ResultObject(ResultObject.SUCCESS, null); }
public ResultObject getCustomerAcounts(String customerName) { AcountBeanDao acountDao = new AcountBeanDao(); List<Object> list = acountDao.getCustomerAcounts(customerName); return new ResultObject(ResultObject.SUCCESS, list); }