public boolean creditExchange(int creditNum, User u) { int toAdd = creditNum / 10; u.setBalance(u.getBalance() + toAdd); u.setCredit(u.getCredit() - toAdd * 10); dao.update(u); return true; }
public boolean cost(User u, int cost) { cost = (int) (cost * getDiscount(u)); if (u.getBalance() >= cost) { System.out.println("Óà¶î×ã¹»¿Û¿î"); u.setBalance(u.getBalance() - cost); u.setCredit(u.getCredit() + cost); dao.update(u); ApplicationContext appliationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); ConsumeRecService crs = (ConsumeRecService) appliationContext.getBean("consumeservice"); crs.createRecord(u.getId(), cost); ActionContext.getContext().getSession().put("user", u); return true; } else { return false; } }
public void dailyCheck() { List<User> list = getAllUsers(); for (User u : list) { if (u.getActivate() == 1) { if (u.getBalance() < 200) { Date old = new Date(); old = u.getActivatetime(); Date now = new Date(); long diff = now.getTime() - old.getTime(); long day = diff / (24 * 60 * 60 * 1000); if (day >= 365) { u.setActivate(0); dao.update(u); } } } } }
public boolean recharge(User u, int money) { System.out.println("OldBalance=" + u.getBalance()); u.setBalance(u.getBalance() + money); u.setSum(u.getSum() + money); System.out.println("NewBalance=" + u.getBalance()); checkGrade(u); if (u.getActivate() == 0 && money > 200) { u.setActivate(1); Timestamp d = new Timestamp(System.currentTimeMillis()); u.setActivatetime(d); } dao.update(u); ApplicationContext appliationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); RechargeRecService rrs = (RechargeRecService) appliationContext.getBean("rechargeservice"); rrs.createRecord(u.getId(), money); ActionContext.getContext().getSession().put("user", u); return true; }
public List getAllRoom() { return dao.getAllList(Room.class); }
public int getRoomId(String roomName) { List list = dao.find(Room.class, "name", roomName); System.out.println("ÕÒµ½ÁËroom"); Room r = (Room) list.get(0); return r.getId(); }
public Room getRoom(String id) { List list = dao.find(Room.class, "id", id); Room r = (Room) list.get(0); return r; }
public boolean updateInfo(User u) { dao.update(u); return true; }
public User getUserById(String userid) { List list = dao.find(User.class, "id", userid); User u = (User) list.get(0); return u; }
public User getUser(String username) { List list = dao.find(User.class, "username", username); User u = (User) list.get(0); return u; }
public void addCredit(String userid, int num) { User u = getUserById(userid); u.setCredit(u.getCredit() + num); dao.update(u); }
public List getAllUsers() { return dao.getAllList(User.class); }
public boolean inactivate(User u) { u.setActivate(0); dao.update(u); return true; }