RoleDao.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.yihu.hos.system.dao;
  2. import com.yihu.hos.system.model.SystemRole;
  3. import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
  4. import com.yihu.hos.web.framework.model.Result;
  5. import org.springframework.stereotype.Repository;
  6. import org.springframework.util.StringUtils;
  7. import java.util.List;
  8. import java.util.Map;
  9. /**
  10. * Created by chenweida on 2016/1/19.
  11. */
  12. @Repository("roleDao")
  13. public class RoleDao extends SQLGeneralDAO {
  14. public static final String BEAN_ID = "roleDao";
  15. public Result getRoleList(Map<String, Object> params) throws Exception {
  16. StringBuilder sb = new StringBuilder("from SystemRole s where 1=1 ");
  17. if (!StringUtils.isEmpty(params.get("name"))) {
  18. sb.append(" and s.name like '%" + params.get("name") + "%' ");
  19. }
  20. return super.getDataGridResult(sb.toString(), Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
  21. }
  22. public void activityRole(String roleid, String activityFlag) throws Exception {
  23. String sql = "update System_role set valid='" + activityFlag + "' where Id='" + roleid + "'";
  24. super.execute(sql);
  25. }
  26. public SystemRole getRoleByName(String name) throws Exception {
  27. List<SystemRole> srs = (List<SystemRole>) super.hibernateTemplate.find("from SystemRole s where s.name=? ", name);
  28. if (srs != null && srs.size() > 0) {
  29. return srs.get(0);
  30. }
  31. return null;
  32. }
  33. public SystemRole getRoleByNameWithOutId(String name, String id) throws Exception {
  34. List<SystemRole> srs = (List<SystemRole>) super.hibernateTemplate.find("from SystemRole s where s.name=? and s.id!=?", name, id);
  35. if (srs != null && srs.size() > 0) {
  36. return srs.get(0);
  37. }
  38. return null;
  39. }
  40. }