private String addWhere(User user, String hql, Map<String, Object> params) { if (user.getName() != null && !user.getName().trim().equals("")) { hql += " where t.name like :name"; params.put("name", "%%" + user.getName().trim() + "%%"); } return hql; }
@Override public User login(User user) { Map<String, Object> params = new HashMap<String, Object>(); params.put("pwd", Encrypt.e(user.getPwd())); params.put("name", user.getName()); Tuser t = userDao.get("from Tuser t where t.name = :name and t.pwd = :pwd", params); if (t != null) { return user; } return null; }
@Override public DataGrid datagrid(User user) { DataGrid dg = new DataGrid(); String hql = "from Tuser t "; Map<String, Object> params = new HashMap<String, Object>(); hql = addWhere(user, hql, params); String totalHql = "select count(*) " + hql; hql = addOrder(user, hql); List<Tuser> l = userDao.find(hql, params, user.getPage(), user.getRows()); List<User> nl = new ArrayList<User>(); changeModel(l, nl); dg.setTotal(userDao.count(totalHql, params)); dg.setRows(nl); return dg; }
@Override public User save(User user) { Tuser t = new Tuser(); BeanUtils.copyProperties(user, t, new String[] {"pwd"}); t.setId(UUID.randomUUID().toString()); t.setCreatedatetime(new Date()); t.setPwd(Encrypt.e(user.getPwd())); userDao.save(t); BeanUtils.copyProperties(t, user); return user; }
private String addOrder(User user, String hql) { if (user.getSort() != null) { hql += " order by " + user.getSort() + " " + user.getOrder(); } return hql; }