public class AjaxResult {

	private boolean success;

	private String msg;

	private Object data;

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
 public class PageModel<E> implements Serializable {
	
	private static final long serialVersionUID = 3265524976080127173L;

	private int totalCount; //总记录数
	
	private int pageSize = 10; //每页显示的数量
	
	private int totalPage; //总页数
	
	private int currentPage = 1; //当前页数
	
	private List<E> list; //分页集合列表
	
	private String url; //分页跳转的URL
	
	public PageModel() {
	}
	
	public PageModel(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public List<E> getList() {
		return list;
	}

	public void setList(List<E> list) {
		this.list = list;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}


}
 public class ExcelUtils {
	
	/**
	 * 
	 * @param response
	 * @param fileName			文件名称
	 * @param headNameMap		表头
	 * @param list				DTO数据
	 */
	public static <T> void exportXlsxByBean(HttpServletResponse response, String fileName, 
			Map<String, String> headNameMap, List<T> list){
		
		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		
		try {
			for(T t: list){
				Map<String, Object> map = new HashMap<String, Object>();
				Field[] fields = t.getClass().getDeclaredFields();
				if(fields != null){
					for(Field field : fields){
						field.setAccessible(true);
						map.put(field.getName(), field.get(t));
					}
				}
				dataList.add(map);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		
		exportXlsx(response, fileName, headNameMap, dataList);
		
	}
	
	/**
	 * 
	 * @param response
	 * @param fileName
	 * @param headNameMap
	 * @param dataList
	 */
	public static void exportXlsx(HttpServletResponse response, String fileName, 
			Map<String, String> headNameMap, List<Map<String, Object>> dataList){
		
		Workbook workbook = exportXlsx(fileName, headNameMap, dataList);
		
		response.setContentType("application/binary;charset=ISO8859_1");
		
		OutputStream outputStream = null;
		
		try {
			outputStream = response.getOutputStream();
			String fn = new String(fileName.getBytes(), "ISO8859_1");
			response.setHeader("Content-disposition", "attachment; filename=" + fn  + ".xlsx");
			workbook.write(outputStream);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if(outputStream != null){
				try {
					outputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	
	/**
	 * 导出数据
	 * @param headNameMap
	 * @param dataList
	 */
	public static Workbook exportXlsx(String sheetName, Map<String, String> headNameMap, List<Map<String, Object>> dataList){
		
		Workbook workbook = new XSSFWorkbook();
		
		Sheet sheet = workbook.createSheet(sheetName);
		
		Set<String> keys = headNameMap.keySet();
		
		int i = 0, j = 0;
		Row row = sheet.createRow(i++);
		//表头
		for(String key : keys){
			Cell cell = row.createCell(j++);
			cell.setCellValue(headNameMap.get(key));
		}
		
		//内容
		if(dataList != null && !dataList.isEmpty()){
			for(Map<String, Object> map : dataList){
				row = sheet.createRow(i++);
				j = 0;
				for(String key : keys){
					Cell cell = row.createCell(j++);
					setCellValue(cell, map.get(key));
				}
			}
		}
		
		return workbook;
	}
	
	private static void setCellValue(Cell cell, Object obj){
		if(obj == null){
		}else if(obj instanceof String){
			cell.setCellValue((String) obj);
		}else if(obj instanceof Date){
			Date date = (Date) obj;
			if(date != null){
				cell.setCellValue(DateUtils.dfDateTime.format(date));
			}
		}else if(obj instanceof Calendar){
			Calendar calendar = (Calendar) obj;
			if(calendar != null){
				cell.setCellValue(DateUtils.dfDateTime.format(calendar.getTime()));
			}
		}else if(obj instanceof Timestamp){
			Timestamp timestamp = (Timestamp) obj;
			if(timestamp != null){
				cell.setCellValue(DateUtils.dfDateTime.format(new Date(timestamp.getTime())));	
			}
		}else if(obj instanceof Double){
			cell.setCellValue((Double) obj);
		}else{
			cell.setCellValue(obj.toString());
		}
	}
	
	/**
	 * 读取excel
	 * @param path
	 * @param startIdx
	 * @return
	 */
	public static List<List<String>> readXlsx(String path, int startIdx){
		
		try {
			InputStream is = new FileInputStream(path);
			
			return readXlsx(is, startIdx);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	@SuppressWarnings("resource")
	public static List<List<String>> readXlsx(InputStream is, int startIdx){
		
		List<List<String>> list = new ArrayList<List<String>>();
		
		try {
			
			XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
			
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
			if(xssfSheet == null){
				return list;
			}
			
			int endIdx = xssfSheet.getLastRowNum() + 1;
			if(endIdx > startIdx){
				for(; startIdx < endIdx; startIdx++){
					XSSFRow xssfRow = xssfSheet.getRow(startIdx);
					if(xssfRow != null){
						List<String> rowList = new ArrayList<String>();
						int colNum = xssfRow.getLastCellNum();
						boolean isAdd = false;
						for(int i=0; i<colNum; i++){
							XSSFCell cell = xssfRow.getCell(i);
							String str = getValue(cell);
							rowList.add(str);
							if(StringUtils.isNotBlank(str)){
								isAdd = true;
							}
						}
						if(isAdd){
							list.add(rowList);	
						}
					}
				}
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if(is != null){
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
		return list;
	}
	
	 private static String getValue(XSSFCell xssFCell) {
		 String str = null;
		 if(xssFCell == null){
			 return str;
		 }
		 if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
			 str = String.valueOf(xssFCell.getBooleanCellValue());
		 } else if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
			 str = String.valueOf(new DecimalFormat("#").format(xssFCell.getNumericCellValue()));
		 } else {
			 str = String.valueOf(xssFCell.getStringCellValue());
		 }
		 return StringUtils.trim(str);
	}

}
 public class Md5Util {
	
	//十六进制下数字到字符的映射数组  
    private final static String[] hexDigits = {"0", "1", "2", "3", "4",  
        "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};  
      
    /** * 把inputString加密     */  
    public static String generatePassword(String inputString){  
        return encodeByMD5(inputString);  
    }  
      
      /** 
       * 验证输入的密码是否正确 
     * @param password    加密后的密码 
     * @param inputString    输入的字符串 
     * @return    验证结果，TRUE:正确 FALSE:错误 
     */  
    public static boolean validatePassword(String password, String inputString){  
        if(password.equalsIgnoreCase(encodeByMD5(inputString))){  
            return true;  
        } else{  
            return false;  
        }  
    }  
    /**  对字符串进行MD5加密     */  
    private static String encodeByMD5(String originString){  
        if (originString != null){  
            try{  
                //创建具有指定算法名称的信息摘要  
                MessageDigest md = MessageDigest.getInstance("MD5");  
                //使用指定的字节数组对摘要进行最后更新，然后完成摘要计算  
                byte[] results = md.digest(originString.getBytes());  
                //将得到的字节数组变成字符串返回  
                String resultString = byteArrayToHexString(results);  
                return resultString.toUpperCase();  
            } catch(Exception ex){  
                ex.printStackTrace();  
            }  
        }  
        return null;  
    }  
      
    /**  
     * 转换字节数组为十六进制字符串 
     * @param     字节数组 
     * @return    十六进制字符串 
     */  
    private static String byteArrayToHexString(byte[] b){  
        StringBuffer resultSb = new StringBuffer();  
        for (int i = 0; i < b.length; i++){  
            resultSb.append(byteToHexString(b[i]));  
        }  
        return resultSb.toString();  
    }  
      
    /** 将一个字节转化成十六进制形式的字符串     */  
    private static String byteToHexString(byte b){  
        int n = b;  
        if (n < 0)  
            n = 256 + n;  
        int d1 = n / 16;  
        int d2 = n % 16;  
        return hexDigits[d1] + hexDigits[d2];  
    } 
    
    public static void main(String[] args){
    	System.out.println(Md5Util.validatePassword("454E908651395FB737E9B8048993C95D", "zhangdanfeng"));
    }

}
 public class RoleQueryDTO extends CommonQueryDTO{
	
	//名称
	private String name;
	
	//状
	private Integer status;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

}
 @Entity
@Table(name = "org_resource")
public class Resource extends BaseEntity{

	private static final long serialVersionUID = -8560521657225182602L;
	
	//模块资源
	public final static String RESOURCE_TYPE_MODULE = "module";
	
	//页面资源
	public final static String RESOURCE_TYPE_PAGE = "page";
	
	//按钮资源
	public final static String RESOURCE_TYPE_BUTTON = "button";
		
	private String name;
	
	private Resource parent;
	
	private String type;
	
	private String url;
	
	private String icon;				//菜单按钮
	
	private Integer orderNo;			//排序

	private List<Resource> children;	//子菜单
	
	@Column(length=50)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="parent_id")
	public Resource getParent() {
		return parent;
	}

	public void setParent(Resource parent) {
		this.parent = parent;
	}

	@Column(length=10)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(length=100)
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "icon", length = 512)
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@Column(name = "order_no")
	public Integer getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(Integer orderNo) {
		this.orderNo = orderNo;
	}

	@Transient
	public List<Resource> getChildren() {
		return children;
	}

	public void setChildren(List<Resource> children) {
		this.children = children;
	}
	
}
 @Entity
@Table(name = "org_role")
public class Role extends BaseEntity{
	
private static final long serialVersionUID = 8160747791143322423L;
	
	private Integer no;
	
	private String name;
	
	private String description;
	
	private Integer status;

	private String code;						
	
	private Set<Resource> resources;			//拥有资源 
	
	private String roleName;					//shiro中name
	
	@Column(length = 100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	

	@Column(name = "status")
	public Integer getStatus() {
		return status;
	}

	@Column(length = 500)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "org_role_resource_rel", 
		joinColumns = {@JoinColumn(name = "role_id")},
		inverseJoinColumns = {@JoinColumn(name = "resources_id")})
	public Set<Resource> getResources() {
		return resources;
	}

	public void setResources(Set<Resource> resources) {
		this.resources = resources;
	}

	@Column(name = "no")
	public Integer getNo() {
		return no;
	}

	public void setNo(Integer no) {
		this.no = no;
	}

	@Column(name = "code", length = 128)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name="role_name", length = 64)
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

}
 @Entity
@Table(name = "org_user")
@Inheritance(strategy = InheritanceType.JOINED)
public class User extends BaseEntity{

	private static final long serialVersionUID = -8821121831372299051L;
	
	public final static Integer STATUS_YES = 1; //可用
	
	public final static Integer STATUS_NO = 0; //不可用
	
	public final static Integer USER_TYPE_INS = 1; //机构用户
	
	private String username;					//用户名称
	
	private String password;					//密码
	
	private String realName;					//真实姓名
	
	private String email;						//邮箱
	
	private String mobile;						//电话
	
	private Integer status; 					//状态

	private Set<Role> roles;					//拥有角色
	
	private Integer type;						//0 为管理员
	
	private String currentSkin;                 //当前皮肤
	
	@Column(name = "username",length=50)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password",length=32)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "real_name",length=50)
	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}	

	@Column(length=30)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(length=20)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Column(name="status", precision = 1)
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "org_user_role_rel", 
			joinColumns = {@JoinColumn(name = "user_id")}, 
			inverseJoinColumns = {@JoinColumn(name = "role_id")})
	@Where(clause="delete_flag=0")
	@OrderBy("no")
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@Column(name = "type", precision = 1, columnDefinition = "int default 0", nullable = false)
	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@Column(name = "current_skin",length = 16)
	public String getCurrentSkin() {
		return currentSkin;
	}

	public void setCurrentSkin(String currentSkin) {
		this.currentSkin = currentSkin;
	}

} @Service
public class ResourceService extends CommonService<Resource,String>{

	@Autowired
	private ResourceDao resourceDao;

	@Autowired
	public void setResourceDao(ResourceDao resourceDao) {
		super.setCommonDao(resourceDao);
	}
	
	public List<Resource> getRootResourceList(){
		return resourceDao.getRootResourceList();
	}
	/**
	 * 根据类型取所有资源
	 * @param type
	 * @return
	 */
	public List<Resource> getSystemResourceList(){
		return this.resourceDao.getSystemResourceList();
	}
	
	public List<Map<String, Object>> getMap(){
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		
		List<Resource> resources = getSystemResourceList();
		if(resources != null && !resources.isEmpty()){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", "all");
			map.put("name", "所有菜单");
			map.put("pId", "0");
			map.put("open", true);
			list.add(map);
			
			for(Resource r : resources){
				map = new HashMap<String, Object>();
				map.put("id", r.getId());
				map.put("name", r.getName());
				String pId = "all";
				if(r.getParent() != null){
					pId = r.getParent().getId();
				}else{
				}
				map.put("pId", pId);
				list.add(map);
			}
		}
		
		return list;
	}
	
	//@Cacheable(value = "org_cache", key="'allMenu'")
	public List<Resource> findAllMenu(){
		List<Resource> resources = new ArrayList<Resource>();
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("deleteFlag", Resource.DELETE_FLAG_NORMAL);
		List<Resource> list = resourceDao.findMenuResource(params);
		if(list != null && !list.isEmpty()){
			Map<String, Resource> map = new HashMap<String, Resource>(); 
			for(Resource r : list){
				map.put(r.getId(), r);
			}
			
			for(Resource r : list){
				if(r.getParent() == null){
					resources.add(r);
				}else{
					Resource parentResource = map.get(r.getParent().getId());
					if(parentResource == null){
						resources.add(r);
					}else{
						if(parentResource.getChildren() == null){
							parentResource.setChildren(new ArrayList<Resource>());
						}
						parentResource.getChildren().add(r);
					}
				}
			}
			
		}
		
		return resources;
	}
	
	@CacheEvict(value="org_cache", key="'allMenu'")
	public void updateDeleteFlag(String[] ids, String deleteFlag){
		if(ids != null){
			for(String id : ids){
				Resource resource = this.find(id);
				resource.setDeleteFlag(deleteFlag);
				this.update(resource);
			}
		}
	}
	
	@CacheEvict(value="org_cache", key="'allMenu'")
	public void saveResource(Resource resource){
		if(StringUtils.isNotBlank(resource.getId())){
			this.update(resource);
		}else{
			this.save(resource);
		}
	}
	
	public List<Resource> findMenuResource(Map<String, Object> params) {
		return resourceDao.findMenuResource(params);
	}
	
}
 @Service
public class RoleService extends CommonService<Role,String>{

	@Autowired
	private RoleDao roleDao;

	@Autowired
	public void setRoleDao(RoleDao roleDao) {
		super.setCommonDao(roleDao);
	}
	
	public List<Role> findRoles(Map<String, Object> params) {
		return roleDao.findRoles(params);
	}
	
	public void updateDeleteFlag(String[] ids, String deleteFlag){
		if(ids != null){
			for(String id : ids){
				Role role = this.find(id);
				role.setDeleteFlag(deleteFlag);
				this.update(role);
			}
		}
	}
	
	public Role findByRoleName(String roleName) {
		return roleDao.findByRoleName(roleName);
	}
	
	/**
	 * 根据查询条件查询角色分页信息
	 * @param userQueryDTO
	 * @return
	 */
	public PageModel<Role> queryRolePage(RoleQueryDTO roleQueryDTO){
		return this.roleDao.queryRolePage(roleQueryDTO);
	}
}
 @Service
public class UserService extends CommonService<User,String>{

	@Autowired
	private UserDao userDao;
	
	@Autowired
	public void setUserDao(UserDao userDao) {
		super.setCommonDao(userDao);
	}
	
	public User findUserByName(String userName){
		User user = null;
		List<User> userList = this.userDao.findUserByName(userName);
		if(userList != null && userList.size() > 0){
			user = userList.get(0);
		}
		return user;
	}

	public List<User> findUsers(Map<String, Object> params) {
		return userDao.findUsers(params);
	}
	
	public List<User> updateStatus(String[] ids, Integer status){
		List<User> users = new ArrayList<User>();
		if(ids != null){
			for(String id : ids){
				User user = this.find(id);
				user.setStatus(status);
				this.update(user);
				users.add(user);
			}
		}
		return users;
	}
	
	public List<Resource> findResourcesByUserId(String userId) {
		return userDao.findResourcesByUserId(userId);
	}
	
	public Map<String, Object> findResourceMap(String userId){
		Map<String, Object> map = new HashMap<String, Object>();
		
		List<Resource> resources = findResourcesByUserId(userId);
		if(resources != null && !resources.isEmpty()){
			for(Resource r : resources){
				map.put(r.getId(), r.getName());
			}
		}
		
		return map;
	}
	
	/**
	 * 根据用户信息查询分页信息
	 * @param userQueryDTO
	 * @return
	 */
	public PageModel<User> queryUserPage(UserQueryDTO userQueryDTO){
		return this.userDao.queryUserPage(userQueryDTO);
	}
	
}
 public class Constants {
	
	public static final String HEAD_NAME = "head_name";
	public static final String MENU_NAME = "menu_name";
	
	public static final String ROLE_INSTITUTION = "role_institution";
	
	public static final String MENU_ROLE_LIST = "角色列表";
	public static final String MENU_USER_LIST = "用户列表";
	public static final String MENU_NAME_LIST = "菜单列表";
	public static final String MENU_COLUMN_LIST = "栏目列表";
	public static final String MENU_ARTICLE_LIST = "文章列表";
	
	public static final String MENU_UPDATE_PWD = "修改密码";
	public static final String MENU_UPDATE_SKIN = "换肤管理";

}
 public class WebHelper {
	
	public static final String SESSION_LOGIN_USER = "session_login_user";

	public static final String SESSION_MENU_RESOURCE = "session_menu_resource";

	public static final String SESSION_NO_IMPORT_SCORE = "session_no_import_score";

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static Integer getCurrentPage(HttpServletRequest request) {

		String currentPage = request.getParameter("currentPage");
		if (StringUtils.isNotBlank(currentPage)
				&& StringUtils.isNumeric(currentPage)) {
			return Integer.parseInt(currentPage);
		}

		return null;
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static Integer getPageSize(HttpServletRequest request) {

		String pageSize = request.getParameter("pageSize");
		if (StringUtils.isNotBlank(pageSize) && StringUtils.isNumeric(pageSize)) {
			return Integer.parseInt(pageSize);
		}

		return null;
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static User getUser(HttpServletRequest request) {
		return (User) request.getSession().getAttribute(SESSION_LOGIN_USER);
	}

	public static String getRemoteHost(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
	}

	public static void setGoBackUrl(HttpServletRequest request, Model model) {
		String fromUrl = request.getHeader("referer");
		model.addAttribute("goBackUrl", fromUrl);
	}

}

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.PageModel;
import com.jeff.tianti.common.util.ExcelUtils;
import com.jeff.tianti.common.util.Md5Util;
import com.jeff.tianti.org.dto.RoleQueryDTO;
import com.jeff.tianti.org.dto.UserQueryDTO;
import com.jeff.tianti.org.entity.Resource;
import com.jeff.tianti.org.entity.Role;
import com.jeff.tianti.org.entity.User;
import com.jeff.tianti.org.service.ResourceService;
import com.jeff.tianti.org.service.RoleService;
import com.jeff.tianti.org.service.UserService;
import com.jeff.tianti.util.Constants;
import com.jeff.tianti.util.WebHelper;

package com.jeff.tianti.controller;




/**
 * 用户管理Controller
 * @author Jeff Xu
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private ResourceService resourceService;
	
	@Autowired
	private RoleService roleService;
	
	@Autowired
	private UserService userService;
	
	/**
	 * 获取用户列表
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/list")
	public String list(HttpServletRequest request, Model model){
		String userName = request.getParameter("userName");
		String currentPageStr = request.getParameter("currentPage");
		String pageSizeStr = request.getParameter("pageSize");
		
		int currentPage = 1;
		int pageSize = 10;
		if(StringUtils.isNotBlank(currentPageStr)){
			currentPage = Integer.parseInt(currentPageStr);
		}
		if(StringUtils.isNotBlank(pageSizeStr)){
			pageSize = Integer.parseInt(pageSizeStr);
		}
		
		UserQueryDTO userQueryDTO = new UserQueryDTO();
		userQueryDTO.setUserName(userName);
		userQueryDTO.setCurrentPage(currentPage);
		userQueryDTO.setPageSize(pageSize);
		

		PageModel<User> page = userService.queryUserPage(userQueryDTO);
