@Override protected List<User> find(UserInfo info) { String hql = "from User u where 1=1 "; Map<String, Object> parameters = new HashMap<String, Object>(); hql = this.addWhere(info, hql, parameters); if (info.getSort() != null && !info.getSort().trim().isEmpty()) { hql += " order by u." + info.getSort() + " " + info.getOrder(); } return this.userDao.find(hql, parameters, info.getPage(), info.getRows()); }
@Override protected String addWhere(UserInfo info, String hql, Map<String, Object> parameters) { if (info.getAccount() != null && !info.getAccount().trim().isEmpty()) { hql += " and (u.account like :account or u.id like :account) "; parameters.put("account", "%" + info.getAccount() + "%"); } if (info.getOpenId() != null && !info.getOpenId().trim().isEmpty()) { hql += " and (u.openId like :openId) "; parameters.put("openId", "%" + info.getOpenId() + "%"); } return hql; }
@Override public UserInfo update(UserInfo info) { if (info != null) { boolean isAdded = false; User data = (info.getId() == null || info.getId().trim().isEmpty()) ? null : this.userDao.load(User.class, info.getId()); if (isAdded = (data == null)) { if (info.getId() == null || info.getId().trim().isEmpty()) { info.setId(UUID.randomUUID().toString()); } data = new User(); } BeanUtils.copyProperties(info, data); if (isAdded) this.userDao.save(data); } return info; }