三、admin包
--web包
-----controller包
-----------common包
CommonController.java------通用请求处理
package com.ruoyi.web.controller.common; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.ruoyi.common.config.Global; import com.ruoyi.common.utils.file.FileUtils; /** * 通用请求处理 * * @author ruoyi */ @Controller public class CommonController { private static final Logger log = LoggerFactory.getLogger(CommonController.class); @RequestMapping("common/download") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); try { String filePath = Global.getDownloadPath() + fileName; response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + setFileDownloadHeader(request, realFileName)); FileUtils.writeBytes(filePath, response.getOutputStream()); if (delete) { FileUtils.deleteFile(filePath); } } catch (Exception e) { log.error("下载文件失败", e); } } public String setFileDownloadHeader(HttpServletRequest request, String fileName) throws UnsupportedEncodingException { final String agent = request.getHeader("USER-AGENT"); String filename = fileName; if (agent.contains("MSIE")) { // IE浏览器 filename = URLEncoder.encode(filename, "utf-8"); filename = filename.replace("+", " "); } else if (agent.contains("Firefox")) { // 火狐浏览器 filename = new String(fileName.getBytes(), "ISO8859-1"); } else if (agent.contains("Chrome")) { // google浏览器 filename = URLEncoder.encode(filename, "utf-8"); } else { // 其它浏览器 filename = URLEncoder.encode(filename, "utf-8"); } return filename; } }
-----------monitor包
DruidController.java-------druid监控(是阿里创建的一种连接池)
package com.ruoyi.web.controller.monitor; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import com.ruoyi.web.core.base.BaseController; /** * druid 监控 * * @author ruoyi */ @Controller @RequestMapping("/monitor/data") public class DruidController extends BaseController { private String prefix = "/monitor/druid"; @RequiresPermissions("monitor:data:view") @GetMapping() public String index() { return redirect(prefix + "/index"); } }
SysJobController.java-------调度任务信息操作处理
package com.ruoyi.web.controller.monitor; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.quartz.domain.SysJob; import com.ruoyi.quartz.service.ISysJobService; import com.ruoyi.web.core.base.BaseController; /** * 调度任务信息操作处理 * * @author ruoyi */ @Controller @RequestMapping("/monitor/job") public class SysJobController extends BaseController { private String prefix = "monitor/job"; @Autowired private ISysJobService jobService; @RequiresPermissions("monitor:job:view") @GetMapping() public String job() { return prefix + "/job"; } @RequiresPermissions("monitor:job:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysJob job) { startPage(); Listlist = jobService.selectJobList(job); return getDataTable(list); } @Log(title = "定时任务", businessType = BusinessType.EXPORT) @RequiresPermissions("monitor:job:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysJob job) { List list = jobService.selectJobList(job); ExcelUtil util = new ExcelUtil (SysJob.class); return util.exportExcel(list, "job"); } @Log(title = "定时任务", businessType = BusinessType.DELETE) @RequiresPermissions("monitor:job:remove") @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { try { jobService.deleteJobByIds(ids); return success(); } catch (Exception e) { e.printStackTrace(); return error(e.getMessage()); } } /** * 任务调度状态修改 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/changeStatus") @ResponseBody public AjaxResult changeStatus(SysJob job) { job.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(jobService.changeStatus(job)); } /** * 任务调度立即执行一次 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:changeStatus") @PostMapping("/run") @ResponseBody public AjaxResult run(SysJob job) { return toAjax(jobService.run(job)); } /** * 新增调度 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存调度 */ @Log(title = "定时任务", businessType = BusinessType.INSERT) @RequiresPermissions("monitor:job:add") @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysJob job) { job.setCreateBy(ShiroUtils.getLoginName()); return toAjax(jobService.insertJobCron(job)); } /** * 修改调度 */ @GetMapping("/edit/{jobId}") public String edit(@PathVariable("jobId") Long jobId, ModelMap mmap) { mmap.put("job", jobService.selectJobById(jobId)); return prefix + "/edit"; } /** * 修改保存调度 */ @Log(title = "定时任务", businessType = BusinessType.UPDATE) @RequiresPermissions("monitor:job:edit") @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysJob job) { job.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(jobService.updateJobCron(job)); } }
SysJobLogController.java-------调度日志操作处理
package com.ruoyi.web.controller.monitor; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.quartz.domain.SysJobLog; import com.ruoyi.quartz.service.ISysJobLogService; import com.ruoyi.web.core.base.BaseController; /** * 调度日志操作处理 * * @author ruoyi */ @Controller @RequestMapping("/monitor/jobLog") public class SysJobLogController extends BaseController { private String prefix = "monitor/job"; @Autowired private ISysJobLogService jobLogService; @RequiresPermissions("monitor:job:view") @GetMapping() public String jobLog() { return prefix + "/jobLog"; } @RequiresPermissions("monitor:job:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysJobLog jobLog) { startPage(); Listlist = jobLogService.selectJobLogList(jobLog); return getDataTable(list); } @Log(title = "调度日志", businessType = BusinessType.EXPORT) @RequiresPermissions("monitor:job:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysJobLog jobLog) { List list = jobLogService.selectJobLogList(jobLog); ExcelUtil util = new ExcelUtil (SysJobLog.class); return util.exportExcel(list, "jobLog"); } @Log(title = "调度日志", businessType = BusinessType.DELETE) @RequiresPermissions("monitor:job:remove") @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(jobLogService.deleteJobLogByIds(ids)); } @Log(title = "调度日志", businessType = BusinessType.CLEAN) @RequiresPermissions("monitor:job:remove") @PostMapping("/clean") @ResponseBody public AjaxResult clean() { jobLogService.cleanJobLog(); return success(); } }
SysLogininforController.java---------系统访问记录
package com.ruoyi.web.controller.monitor; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysLogininfor; import com.ruoyi.system.service.ISysLogininforService; import com.ruoyi.web.core.base.BaseController; /** * 系统访问记录 * * @author ruoyi */ @Controller @RequestMapping("/monitor/logininfor") public class SysLogininforController extends BaseController { private String prefix = "monitor/logininfor"; @Autowired private ISysLogininforService logininforService; @RequiresPermissions("monitor:logininfor:view") @GetMapping() public String logininfor() { return prefix + "/logininfor"; } @RequiresPermissions("monitor:logininfor:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysLogininfor logininfor) { startPage(); Listlist = logininforService.selectLogininforList(logininfor); return getDataTable(list); } @Log(title = "登陆日志", businessType = BusinessType.EXPORT) @RequiresPermissions("monitor:logininfor:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysLogininfor logininfor) { List list = logininforService.selectLogininforList(logininfor); ExcelUtil util = new ExcelUtil (SysLogininfor.class); return util.exportExcel(list, "logininfor"); } @RequiresPermissions("monitor:logininfor:remove") @Log(title = "登陆日志", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(logininforService.deleteLogininforByIds(ids)); } @RequiresPermissions("monitor:logininfor:remove") /** * 例如: @RequiresPermissions({"file:read", "write:aFile.txt"} ) * void someMethod(); * 要求subject中必须同时含有file:read和write:aFile.txt的权限才能执行方法someMethod()。否则抛出异常AuthorizationException。 */ @Log(title = "登陆日志", businessType = BusinessType.CLEAN) @PostMapping("/clean") @ResponseBody /** * @responseBody注解的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML * * 数据 */ public AjaxResult clean() { logininforService.cleanLogininfor(); return success(); } }
SysOperlogController.java---------操作日志记录
package com.ruoyi.web.controller.monitor; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysOperLog; import com.ruoyi.system.service.ISysOperLogService; import com.ruoyi.web.core.base.BaseController; /** * 操作日志记录 * * @author ruoyi */ @Controller @RequestMapping("/monitor/operlog") public class SysOperlogController extends BaseController { private String prefix = "monitor/operlog"; @Autowired private ISysOperLogService operLogService; @RequiresPermissions("monitor:operlog:view") @GetMapping() public String operlog() { return prefix + "/operlog"; } @RequiresPermissions("monitor:operlog:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysOperLog operLog) { startPage(); Listlist = operLogService.selectOperLogList(operLog); return getDataTable(list); } @Log(title = "操作日志", businessType = BusinessType.EXPORT) @RequiresPermissions("monitor:operlog:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysOperLog operLog) { List list = operLogService.selectOperLogList(operLog); ExcelUtil util = new ExcelUtil (SysOperLog.class); return util.exportExcel(list, "operLog"); } @RequiresPermissions("monitor:operlog:remove") @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(operLogService.deleteOperLogByIds(ids)); } @RequiresPermissions("monitor:operlog:detail") @GetMapping("/detail/{operId}") public String detail(@PathVariable("operId") Long deptId, ModelMap mmap) { mmap.put("operLog", operLogService.selectOperLogById(deptId)); return prefix + "/detail"; } @Log(title = "操作日志", businessType = BusinessType.CLEAN) @RequiresPermissions("monitor:operlog:remove") @PostMapping("/clean") @ResponseBody public AjaxResult clean() { operLogService.cleanOperLog(); return success(); } }
SysUserOnlineController.java--------在线用户监控
package com.ruoyi.web.controller.monitor; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.OnlineStatus; import com.ruoyi.framework.shiro.session.OnlineSession; import com.ruoyi.framework.shiro.session.OnlineSessionDAO; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysUserOnline; import com.ruoyi.system.service.impl.SysUserOnlineServiceImpl; import com.ruoyi.web.core.base.BaseController; /** * 在线用户监控 * * @author ruoyi */ @Controller @RequestMapping("/monitor/online") public class SysUserOnlineController extends BaseController { private String prefix = "monitor/online"; @Autowired private SysUserOnlineServiceImpl userOnlineService; @Autowired private OnlineSessionDAO onlineSessionDAO; @RequiresPermissions("monitor:online:view") @GetMapping() public String online() { return prefix + "/online"; } @RequiresPermissions("monitor:online:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysUserOnline userOnline) { startPage(); Listlist = userOnlineService.selectUserOnlineList(userOnline); return getDataTable(list); } @RequiresPermissions("monitor:online:batchForceLogout") @Log(title = "在线用户", businessType = BusinessType.FORCE) @PostMapping("/batchForceLogout") @ResponseBody public AjaxResult batchForceLogout(@RequestParam("ids[]") String[] ids) { for (String sessionId : ids) { SysUserOnline online = userOnlineService.selectOnlineById(sessionId); if (online == null) { return error("用户已下线"); } OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId()); if (onlineSession == null) { return error("用户已下线"); } if (sessionId.equals(ShiroUtils.getSessionId())) { return error("当前登陆用户无法强退"); } onlineSession.setStatus(OnlineStatus.off_line); online.setStatus(OnlineStatus.off_line); userOnlineService.saveOnline(online); } return success(); } @RequiresPermissions("monitor:online:forceLogout") @Log(title = "在线用户", businessType = BusinessType.FORCE) @PostMapping("/forceLogout") @ResponseBody public AjaxResult forceLogout(String sessionId) { SysUserOnline online = userOnlineService.selectOnlineById(sessionId); if (sessionId.equals(ShiroUtils.getSessionId())) { return error("当前登陆用户无法强退"); } if (online == null) { return error("用户已下线"); } OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getSessionId()); if (onlineSession == null) { return error("用户已下线"); } onlineSession.setStatus(OnlineStatus.off_line); online.setStatus(OnlineStatus.off_line); userOnlineService.saveOnline(online); return success(); } }
-----------system包
SysCaptchaController.java---------图片验证码
package com.ruoyi.web.controller.system; import java.awt.image.BufferedImage; import java.io.IOException; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.google.code.kaptcha.Constants; import com.google.code.kaptcha.Producer; import com.ruoyi.web.core.base.BaseController; /** * 图片验证码(支持算术形式) * * @author ruoyi */ @Controller @RequestMapping("/captcha") public class SysCaptchaController extends BaseController { @Resource(name = "captchaProducer") private Producer captchaProducer; @Resource(name = "captchaProducerMath") private Producer captchaProducerMath; /** * 验证码生成 */ @GetMapping(value = "/captchaImage") public ModelAndView getKaptchaImage(HttpServletRequest request, HttpServletResponse response) { ServletOutputStream out = null; try { HttpSession session = request.getSession(); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); response.addHeader("Cache-Control", "post-check=0, pre-check=0"); response.setHeader("Pragma", "no-cache"); response.setContentType("image/jpeg"); String type = request.getParameter("type"); String capStr = null; String code = null; BufferedImage bi = null; if ("math".equals(type)) { String capText = captchaProducerMath.createText(); capStr = capText.substring(0, capText.lastIndexOf("@")); code = capText.substring(capText.lastIndexOf("@") + 1); bi = captchaProducerMath.createImage(capStr); } else if ("char".equals(type)) { capStr = code = captchaProducer.createText(); bi = captchaProducer.createImage(capStr); } session.setAttribute(Constants.KAPTCHA_SESSION_KEY, code); out = response.getOutputStream(); ImageIO.write(bi, "jpg", out); out.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } return null; } }
SysConfigController.java-------参数配置信息操作处理
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysConfig; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.web.core.base.BaseController; /** * 参数配置 信息操作处理 * * @author ruoyi */ @Controller @RequestMapping("/system/config") public class SysConfigController extends BaseController { private String prefix = "system/config"; @Autowired private ISysConfigService configService; @RequiresPermissions("system:config:view") @GetMapping() public String config() { return prefix + "/config"; } /** * 查询参数配置列表 */ @RequiresPermissions("system:config:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysConfig config) { startPage(); Listlist = configService.selectConfigList(config); return getDataTable(list); } @Log(title = "参数管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:config:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysConfig config) { List list = configService.selectConfigList(config); ExcelUtil util = new ExcelUtil (SysConfig.class); return util.exportExcel(list, "config"); } /** * 新增参数配置 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存参数配置 */ @RequiresPermissions("system:config:add") @Log(title = "参数管理", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysConfig config) { config.setCreateBy(ShiroUtils.getLoginName()); return toAjax(configService.insertConfig(config)); } /** * 修改参数配置 */ @GetMapping("/edit/{configId}") public String edit(@PathVariable("configId") Long configId, ModelMap mmap) { mmap.put("config", configService.selectConfigById(configId)); return prefix + "/edit"; } /** * 修改保存参数配置 */ @RequiresPermissions("system:config:edit") @Log(title = "参数管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysConfig config) { config.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(configService.updateConfig(config)); } /** * 删除参数配置 */ @RequiresPermissions("system:config:remove") @Log(title = "参数管理", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(configService.deleteConfigByIds(ids)); } /** * 校验参数键名 */ @PostMapping("/checkConfigKeyUnique") @ResponseBody public String checkConfigKeyUnique(SysConfig config) { return configService.checkConfigKeyUnique(config); } }
SysDeptController。java---------部门信息增删改
package com.ruoyi.web.controller.system; import java.util.List; import java.util.Map; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.system.domain.SysDept; import com.ruoyi.system.domain.SysRole; import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.web.core.base.BaseController; /** * 部门信息 * * @author ruoyi */ @Controller @RequestMapping("/system/dept") public class SysDeptController extends BaseController { private String prefix = "system/dept"; @Autowired private ISysDeptService deptService; @RequiresPermissions("system:dept:view") @GetMapping() public String dept() { return prefix + "/dept"; } @RequiresPermissions("system:dept:list") @GetMapping("/list") @ResponseBody public Listlist(SysDept dept) { List deptList = deptService.selectDeptList(dept); return deptList; } /** * 新增部门 */ @GetMapping("/add/{parentId}") public String add(@PathVariable("parentId") Long parentId, ModelMap mmap) { mmap.put("dept", deptService.selectDeptById(parentId)); return prefix + "/add"; } /** * 新增保存部门 */ @Log(title = "部门管理", businessType = BusinessType.INSERT) @RequiresPermissions("system:dept:add") @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysDept dept) { dept.setCreateBy(ShiroUtils.getLoginName()); return toAjax(deptService.insertDept(dept)); } /** * 修改 */ @GetMapping("/edit/{deptId}") public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap) { SysDept dept = deptService.selectDeptById(deptId); if (StringUtils.isNotNull(dept) && 100L == deptId) { dept.setParentName("无"); } mmap.put("dept", dept); return prefix + "/edit"; } /** * 保存 */ @Log(title = "部门管理", businessType = BusinessType.UPDATE) @RequiresPermissions("system:dept:edit") @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysDept dept) { dept.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(deptService.updateDept(dept)); } /** * 删除 */ @Log(title = "部门管理", businessType = BusinessType.DELETE) @RequiresPermissions("system:dept:remove") @PostMapping("/remove/{deptId}") @ResponseBody public AjaxResult remove(@PathVariable("deptId") Long deptId) { if (deptService.selectDeptCount(deptId) > 0) { return error(1, "存在下级部门,不允许删除"); } if (deptService.checkDeptExistUser(deptId)) { return error(1, "部门存在用户,不允许删除"); } return toAjax(deptService.deleteDeptById(deptId)); } /** * 校验部门名称 */ @PostMapping("/checkDeptNameUnique") @ResponseBody public String checkDeptNameUnique(SysDept dept) { return deptService.checkDeptNameUnique(dept); } /** * 选择部门树 */ @GetMapping("/selectDeptTree/{deptId}") public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap) { mmap.put("dept", deptService.selectDeptById(deptId)); return prefix + "/tree"; } /** * 加载部门列表树 */ @GetMapping("/treeData") @ResponseBody public List
SysDictDataController.java--------数据字典数据增删改
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysDictData; import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.web.core.base.BaseController; /** * 数据字典信息 * * @author ruoyi */ @Controller @RequestMapping("/system/dict/data") public class SysDictDataController extends BaseController { private String prefix = "system/dict/data"; @Autowired private ISysDictDataService dictDataService; @RequiresPermissions("system:dict:view") @GetMapping() public String dictData() { return prefix + "/data"; } @PostMapping("/list") @RequiresPermissions("system:dict:list") @ResponseBody public TableDataInfo list(SysDictData dictData) { startPage(); Listlist = dictDataService.selectDictDataList(dictData); return getDataTable(list); } @Log(title = "字典数据", businessType = BusinessType.EXPORT) @RequiresPermissions("system:dict:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysDictData dictData) { List list = dictDataService.selectDictDataList(dictData); ExcelUtil util = new ExcelUtil (SysDictData.class); return util.exportExcel(list, "dictData"); } /** * 新增字典类型 */ @GetMapping("/add/{dictType}") public String add(@PathVariable("dictType") String dictType, ModelMap mmap) { mmap.put("dictType", dictType); return prefix + "/add"; } /** * 新增保存字典类型 */ @Log(title = "字典数据", businessType = BusinessType.INSERT) @RequiresPermissions("system:dict:add") @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysDictData dict) { dict.setCreateBy(ShiroUtils.getLoginName()); return toAjax(dictDataService.insertDictData(dict)); } /** * 修改字典类型 */ @GetMapping("/edit/{dictCode}") public String edit(@PathVariable("dictCode") Long dictCode, ModelMap mmap) { mmap.put("dict", dictDataService.selectDictDataById(dictCode)); return prefix + "/edit"; } /** * 修改保存字典类型 */ @Log(title = "字典数据", businessType = BusinessType.UPDATE) @RequiresPermissions("system:dict:edit") @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysDictData dict) { dict.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(dictDataService.updateDictData(dict)); } @Log(title = "字典数据", businessType = BusinessType.DELETE) @RequiresPermissions("system:dict:remove") @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(dictDataService.deleteDictDataByIds(ids)); } }
SysDictTypeController.java--------数据字典类型增删改
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysDictType; import com.ruoyi.system.service.ISysDictTypeService; import com.ruoyi.web.core.base.BaseController; /** * 数据字典类型信息 * * @author ruoyi */ @Controller @RequestMapping("/system/dict") public class SysDictTypeController extends BaseController { private String prefix = "system/dict/type"; @Autowired private ISysDictTypeService dictTypeService; @RequiresPermissions("system:dict:view") @GetMapping() public String dictType() { return prefix + "/type"; } @PostMapping("/list") @RequiresPermissions("system:dict:list") @ResponseBody public TableDataInfo list(SysDictType dictType) { startPage(); Listlist = dictTypeService.selectDictTypeList(dictType); return getDataTable(list); } @Log(title = "字典类型", businessType = BusinessType.EXPORT) @RequiresPermissions("system:dict:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysDictType dictType) { List list = dictTypeService.selectDictTypeList(dictType); ExcelUtil util = new ExcelUtil (SysDictType.class); return util.exportExcel(list, "dictType"); } /** * 新增字典类型 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存字典类型 */ @Log(title = "字典类型", businessType = BusinessType.INSERT) @RequiresPermissions("system:dict:add") @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysDictType dict) { dict.setCreateBy(ShiroUtils.getLoginName()); return toAjax(dictTypeService.insertDictType(dict)); } /** * 修改字典类型 */ @GetMapping("/edit/{dictId}") public String edit(@PathVariable("dictId") Long dictId, ModelMap mmap) { mmap.put("dict", dictTypeService.selectDictTypeById(dictId)); return prefix + "/edit"; } /** * 修改保存字典类型 */ @Log(title = "字典类型", businessType = BusinessType.UPDATE) @RequiresPermissions("system:dict:edit") @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysDictType dict) { dict.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(dictTypeService.updateDictType(dict)); } @Log(title = "字典类型", businessType = BusinessType.DELETE) @RequiresPermissions("system:dict:remove") @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { try { return toAjax(dictTypeService.deleteDictTypeByIds(ids)); } catch (Exception e) { return error(e.getMessage()); } } /** * 查询字典详细 */ @RequiresPermissions("system:dict:list") @GetMapping("/detail/{dictId}") public String detail(@PathVariable("dictId") Long dictId, ModelMap mmap) { mmap.put("dict", dictTypeService.selectDictTypeById(dictId)); mmap.put("dictList", dictTypeService.selectDictTypeAll()); return "system/dict/data/data"; } /** * 校验字典类型 */ @PostMapping("/checkDictTypeUnique") @ResponseBody public String checkDictTypeUnique(SysDictType dictType) { return dictTypeService.checkDictTypeUnique(dictType); } }
SysIndexController.java--------首页的业务处理
package com.ruoyi.web.controller.system; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import com.ruoyi.common.config.Global; import com.ruoyi.system.domain.SysMenu; import com.ruoyi.system.domain.SysUser; import com.ruoyi.system.service.ISysMenuService; import com.ruoyi.web.core.base.BaseController; /** * 首页 业务处理 * * @author ruoyi */ @Controller public class SysIndexController extends BaseController { @Autowired private ISysMenuService menuService; // 系统首页 @GetMapping("/index") public String index(ModelMap mmap) { // 取身份信息 SysUser user = getUser(); // 根据用户id取出菜单 Listmenus = menuService.selectMenusByUser(user); mmap.put("menus", menus); mmap.put("user", user); mmap.put("copyrightYear", Global.getCopyrightYear()); return "index"; } // 系统介绍 @GetMapping("/system/main") public String main(ModelMap mmap) { mmap.put("version", Global.getVersion()); return "main"; } }
SysLoginController.java-------用户登陆验证
package com.ruoyi.web.controller.system; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.subject.Subject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.util.ServletUtils; import com.ruoyi.web.core.base.BaseController; /** * 登录验证 * * @author ruoyi */ @Controller public class SysLoginController extends BaseController { @GetMapping("/login") public String login(HttpServletRequest request, HttpServletResponse response) { // 如果是Ajax请求,返回Json字符串。 if (ServletUtils.isAjaxRequest(request)) { return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}"); } return "login"; } @PostMapping("/login") @ResponseBody public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe) { UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe); Subject subject = SecurityUtils.getSubject(); try { subject.login(token); return success(); } catch (AuthenticationException e) { String msg = "用户或密码错误"; if (StringUtils.isNotEmpty(e.getMessage())) { msg = e.getMessage(); } return error(msg); } } @GetMapping("/unauth") public String unauth() { return "/error/unauth"; } }
SysMenuController.java----------菜单信息
package com.ruoyi.web.controller.system; import java.util.List; import java.util.Map; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.system.domain.SysMenu; import com.ruoyi.system.domain.SysRole; import com.ruoyi.system.service.ISysMenuService; import com.ruoyi.web.core.base.BaseController; /** * 菜单信息 * * @author ruoyi */ @Controller @RequestMapping("/system/menu") public class SysMenuController extends BaseController { private String prefix = "system/menu"; @Autowired private ISysMenuService menuService; @RequiresPermissions("system:menu:view") @GetMapping() public String menu() { return prefix + "/menu"; } @RequiresPermissions("system:menu:list") @GetMapping("/list") @ResponseBody public Listlist(SysMenu menu) { List menuList = menuService.selectMenuList(menu); return menuList; } /** * 删除菜单 */ @Log(title = "菜单管理", businessType = BusinessType.DELETE) @RequiresPermissions("system:menu:remove") @PostMapping("/remove/{menuId}") @ResponseBody public AjaxResult remove(@PathVariable("menuId") Long menuId) { if (menuService.selectCountMenuByParentId(menuId) > 0) { return error(1, "存在子菜单,不允许删除"); } if (menuService.selectCountRoleMenuByMenuId(menuId) > 0) { return error(1, "菜单已分配,不允许删除"); } ShiroUtils.clearCachedAuthorizationInfo(); return toAjax(menuService.deleteMenuById(menuId)); } /** * 新增 */ @GetMapping("/add/{parentId}") public String add(@PathVariable("parentId") Long parentId, ModelMap mmap) { SysMenu menu = null; if (0L != parentId) { menu = menuService.selectMenuById(parentId); } else { menu = new SysMenu(); menu.setMenuId(0L); menu.setMenuName("主目录"); } mmap.put("menu", menu); return prefix + "/add"; } /** * 新增保存菜单 */ @Log(title = "菜单管理", businessType = BusinessType.INSERT) @RequiresPermissions("system:menu:add") @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysMenu menu) { menu.setCreateBy(ShiroUtils.getLoginName()); ShiroUtils.clearCachedAuthorizationInfo(); return toAjax(menuService.insertMenu(menu)); } /** * 修改菜单 */ @GetMapping("/edit/{menuId}") public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap) { mmap.put("menu", menuService.selectMenuById(menuId)); return prefix + "/edit"; } /** * 修改保存菜单 */ @Log(title = "菜单管理", businessType = BusinessType.UPDATE) @RequiresPermissions("system:menu:edit") @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysMenu menu) { menu.setUpdateBy(ShiroUtils.getLoginName()); ShiroUtils.clearCachedAuthorizationInfo(); return toAjax(menuService.updateMenu(menu)); } /** * 选择菜单图标 */ @GetMapping("/icon") public String icon() { return prefix + "/icon"; } /** * 校验菜单名称 */ @PostMapping("/checkMenuNameUnique") @ResponseBody public String checkMenuNameUnique(SysMenu menu) { return menuService.checkMenuNameUnique(menu); } /** * 加载角色菜单列表树 */ @GetMapping("/roleMenuTreeData") @ResponseBody public List > roleMenuTreeData(SysRole role) { List > tree = menuService.roleMenuTreeData(role); return tree; } /** * 加载所有菜单列表树 */ @GetMapping("/menuTreeData") @ResponseBody public List > menuTreeData(SysRole role) { List > tree = menuService.menuTreeData(); return tree; } /** * 选择菜单树 */ @GetMapping("/selectMenuTree/{menuId}") public String selectMenuTree(@PathVariable("menuId") Long menuId, ModelMap mmap) { mmap.put("menu", menuService.selectMenuById(menuId)); return prefix + "/tree"; } }
SysNoticeController.java---------公告信息操作处理
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysNotice; import com.ruoyi.system.service.ISysNoticeService; import com.ruoyi.web.core.base.BaseController; /** * 公告 信息操作处理 * * @author ruoyi */ @Controller @RequestMapping("/system/notice") public class SysNoticeController extends BaseController { private String prefix = "system/notice"; @Autowired private ISysNoticeService noticeService; @RequiresPermissions("system:notice:view") @GetMapping() public String notice() { return prefix + "/notice"; } /** * 查询公告列表 */ @RequiresPermissions("system:notice:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysNotice notice) { startPage(); Listlist = noticeService.selectNoticeList(notice); return getDataTable(list); } /** * 新增公告 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存公告 */ @RequiresPermissions("system:notice:add") @Log(title = "通知公告", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysNotice notice) { notice.setCreateBy(ShiroUtils.getLoginName()); return toAjax(noticeService.insertNotice(notice)); } /** * 修改公告 */ @GetMapping("/edit/{noticeId}") public String edit(@PathVariable("noticeId") Long noticeId, ModelMap mmap) { mmap.put("notice", noticeService.selectNoticeById(noticeId)); return prefix + "/edit"; } /** * 修改保存公告 */ @RequiresPermissions("system:notice:edit") @Log(title = "通知公告", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysNotice notice) { notice.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(noticeService.updateNotice(notice)); } /** * 删除公告 */ @RequiresPermissions("system:notice:remove") @Log(title = "通知公告", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(noticeService.deleteNoticeByIds(ids)); } }
SysPostController.java-----岗位信息操作处理
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysPost; import com.ruoyi.system.service.ISysPostService; import com.ruoyi.web.core.base.BaseController; /** * 岗位信息操作处理 * * @author ruoyi */ @Controller @RequestMapping("/system/post") public class SysPostController extends BaseController { private String prefix = "system/post"; @Autowired private ISysPostService postService; @RequiresPermissions("system:post:view") @GetMapping() public String operlog() { return prefix + "/post"; } @RequiresPermissions("system:post:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysPost post) { startPage(); Listlist = postService.selectPostList(post); return getDataTable(list); } @Log(title = "岗位管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:post:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysPost post) { List list = postService.selectPostList(post); ExcelUtil util = new ExcelUtil (SysPost.class); return util.exportExcel(list, "post"); } @RequiresPermissions("system:post:remove") @Log(title = "岗位管理", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { try { return toAjax(postService.deletePostByIds(ids)); } catch (Exception e) { return error(e.getMessage()); } } /** * 新增岗位 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存岗位 */ @RequiresPermissions("system:post:add") @Log(title = "岗位管理", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(SysPost post) { post.setCreateBy(ShiroUtils.getLoginName()); return toAjax(postService.insertPost(post)); } /** * 修改岗位 */ @GetMapping("/edit/{postId}") public String edit(@PathVariable("postId") Long postId, ModelMap mmap) { mmap.put("post", postService.selectPostById(postId)); return prefix + "/edit"; } /** * 修改保存岗位 */ @RequiresPermissions("system:post:edit") @Log(title = "岗位管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(SysPost post) { post.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(postService.updatePost(post)); } /** * 校验岗位名称 */ @PostMapping("/checkPostNameUnique") @ResponseBody public String checkPostNameUnique(SysPost post) { return postService.checkPostNameUnique(post); } /** * 校验岗位编码 */ @PostMapping("/checkPostCodeUnique") @ResponseBody public String checkPostCodeUnique(SysPost post) { return postService.checkPostCodeUnique(post); } }
SysProfileController.java------个人信息业务处理
package com.ruoyi.web.controller.system; import org.apache.shiro.crypto.hash.Md5Hash; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.config.Global; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.framework.util.FileUploadUtils; import com.ruoyi.system.domain.SysUser; import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.system.service.ISysUserService; import com.ruoyi.web.core.base.BaseController; /** * 个人信息 业务处理 * * @author ruoyi */ @Controller @RequestMapping("/system/user/profile") public class SysProfileController extends BaseController { private static final Logger log = LoggerFactory.getLogger(SysProfileController.class); private String prefix = "system/user/profile"; @Autowired private ISysUserService userService; @Autowired private ISysDictDataService dictDataService; /** * 个人信息 */ @GetMapping() public String profile(ModelMap mmap) { SysUser user = getUser(); user.setSex(dictDataService.selectDictLabel("sys_user_sex", user.getSex())); mmap.put("user", user); mmap.put("roleGroup", userService.selectUserRoleGroup(user.getUserId())); mmap.put("postGroup", userService.selectUserPostGroup(user.getUserId())); return prefix + "/profile"; } @GetMapping("/checkPassword") @ResponseBody public boolean checkPassword(String password) { SysUser user = getUser(); String encrypt = new Md5Hash(user.getLoginName() + password + user.getSalt()).toHex().toString(); if (user.getPassword().equals(encrypt)) { return true; } return false; } @GetMapping("/resetPwd/{userId}") public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); return prefix + "/resetPwd"; } @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwd(SysUser user) { int rows = userService.resetUserPwd(user); if (rows > 0) { setUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } /** * 修改用户 */ @GetMapping("/edit/{userId}") public String edit(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); return prefix + "/edit"; } /** * 修改头像 */ @GetMapping("/avatar/{userId}") public String avatar(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); return prefix + "/avatar"; } /** * 修改用户 */ @Log(title = "个人信息", businessType = BusinessType.UPDATE) @PostMapping("/update") @ResponseBody public AjaxResult update(SysUser user) { if (userService.updateUserInfo(user) > 0) { setUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } /** * 保存头像 */ @Log(title = "个人信息", businessType = BusinessType.UPDATE) @PostMapping("/updateAvatar") @ResponseBody public AjaxResult updateAvatar(SysUser user, @RequestParam("avatarfile") MultipartFile file) { try { if (!file.isEmpty()) { String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); user.setAvatar(avatar); if (userService.updateUserInfo(user) > 0) { setUser(userService.selectUserById(user.getUserId())); return success(); } } return error(); } catch (Exception e) { log.error("修改头像失败!", e); return error(e.getMessage()); } } }
SysRoleController.java------角色信息
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysRole; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.web.core.base.BaseController; /** * 角色信息 * * @author ruoyi */ @Controller @RequestMapping("/system/role") public class SysRoleController extends BaseController { private String prefix = "system/role"; @Autowired private ISysRoleService roleService; @RequiresPermissions("system:role:view") @GetMapping() public String role() { return prefix + "/role"; } @RequiresPermissions("system:role:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysRole role) { startPage(); Listlist = roleService.selectRoleList(role); return getDataTable(list); } @Log(title = "角色管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:role:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysRole role) { List list = roleService.selectRoleList(role); ExcelUtil util = new ExcelUtil (SysRole.class); return util.exportExcel(list, "role"); } /** * 新增角色 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存角色 */ @RequiresPermissions("system:role:add") @Log(title = "角色管理", businessType = BusinessType.INSERT) @PostMapping("/add") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult addSave(SysRole role) { role.setCreateBy(ShiroUtils.getLoginName()); ShiroUtils.clearCachedAuthorizationInfo(); return toAjax(roleService.insertRole(role)); } /** * 修改角色 */ @GetMapping("/edit/{roleId}") public String edit(@PathVariable("roleId") Long roleId, ModelMap mmap) { mmap.put("role", roleService.selectRoleById(roleId)); return prefix + "/edit"; } /** * 修改保存角色 */ @RequiresPermissions("system:role:edit") @Log(title = "角色管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult editSave(SysRole role) { role.setUpdateBy(ShiroUtils.getLoginName()); ShiroUtils.clearCachedAuthorizationInfo(); return toAjax(roleService.updateRole(role)); } /** * 新增数据权限 */ @GetMapping("/rule/{roleId}") public String rule(@PathVariable("roleId") Long roleId, ModelMap mmap) { mmap.put("role", roleService.selectRoleById(roleId)); return prefix + "/rule"; } /** * 修改保存数据权限 */ @RequiresPermissions("system:role:edit") @Log(title = "角色管理", businessType = BusinessType.UPDATE) @PostMapping("/rule") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult ruleSave(SysRole role) { role.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(roleService.updateRule(role)); } @RequiresPermissions("system:role:remove") @Log(title = "角色管理", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { try { return toAjax(roleService.deleteRoleByIds(ids)); } catch (Exception e) { return error(e.getMessage()); } } /** * 校验角色名称 */ @PostMapping("/checkRoleNameUnique") @ResponseBody public String checkRoleNameUnique(SysRole role) { return roleService.checkRoleNameUnique(role); } /** * 校验角色权限 */ @PostMapping("/checkRoleKeyUnique") @ResponseBody public String checkRoleKeyUnique(SysRole role) { return roleService.checkRoleKeyUnique(role); } /** * 选择菜单树 */ @GetMapping("/selectMenuTree") public String selectMenuTree() { return prefix + "/tree"; } }
SysUserController.java------用户信息
package com.ruoyi.web.controller.system; import java.util.List; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.ExcelUtil; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.shiro.service.PasswordService; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.system.domain.SysUser; import com.ruoyi.system.service.ISysPostService; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; import com.ruoyi.web.core.base.BaseController; /** * 用户信息 * * @author ruoyi */ @Controller @RequestMapping("/system/user") public class SysUserController extends BaseController { private String prefix = "system/user"; @Autowired private ISysUserService userService; @Autowired private ISysRoleService roleService; @Autowired private ISysPostService postService; @Autowired private PasswordService passwordService; @RequiresPermissions("system:user:view") @GetMapping() public String user() { return prefix + "/user"; } @RequiresPermissions("system:user:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(SysUser user) { startPage(); Listlist = userService.selectUserList(user); return getDataTable(list); } @Log(title = "用户管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:user:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysUser user) { List list = userService.selectUserList(user); ExcelUtil util = new ExcelUtil (SysUser.class); return util.exportExcel(list, "user"); } /** * 新增用户 */ @GetMapping("/add") public String add(ModelMap mmap) { mmap.put("roles", roleService.selectRoleAll()); mmap.put("posts", postService.selectPostAll()); return prefix + "/add"; } /** * 新增保存用户 */ @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult addSave(SysUser user) { if (StringUtils.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) { return error("不允许修改超级管理员用户"); } user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); return toAjax(userService.insertUser(user)); } /** * 修改用户 */ @GetMapping("/edit/{userId}") public String edit(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); mmap.put("roles", roleService.selectRolesByUserId(userId)); mmap.put("posts", postService.selectPostsByUserId(userId)); return prefix + "/edit"; } /** * 修改保存用户 */ @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult editSave(SysUser user) { if (StringUtils.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) { return error("不允许修改超级管理员用户"); } user.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(userService.updateUser(user)); } @RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @GetMapping("/resetPwd/{userId}") public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); return prefix + "/resetPwd"; } @RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwdSave(SysUser user) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); return toAjax(userService.resetUserPwd(user)); } @RequiresPermissions("system:user:remove") @Log(title = "用户管理", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(String ids) { try { return toAjax(userService.deleteUserByIds(ids)); } catch (Exception e) { return error(e.getMessage()); } } /** * 校验用户名 */ @PostMapping("/checkLoginNameUnique") @ResponseBody public String checkLoginNameUnique(SysUser user) { return userService.checkLoginNameUnique(user.getLoginName()); } /** * 校验手机号码 */ @PostMapping("/checkPhoneUnique") @ResponseBody public String checkPhoneUnique(SysUser user) { return userService.checkPhoneUnique(user); } /** * 校验email邮箱 */ @PostMapping("/checkEmailUnique") @ResponseBody public String checkEmailUnique(SysUser user) { return userService.checkEmailUnique(user); } }
-----------tool包
BuildController.java-----表单构建
package com.ruoyi.web.controller.tool; import com.ruoyi.system.dto.LeiPiDto; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import com.ruoyi.web.core.base.BaseController; import java.util.Map; /** * build 表单构建 * * @author ruoyi */ @Controller @RequestMapping("/tool") public class BuildController extends BaseController { private String prefix = "tool/build"; @RequiresPermissions("tool:build:view") @GetMapping("/build") public String build() { return prefix + "/build"; } @GetMapping("leipi") @RequiresPermissions("tool:leipi:view") public String leipi() { return "tool/build/leipi"; } @PostMapping("testGetLeiPiHtml") @ResponseBody public String testGetLeiPiHtml(@RequestBody LeiPiDto dto) { System.out.println("Received parametes: " + dto.getHtmlStr()); return dto.getHtmlStr(); } }
GenController.java------代码生成操作
package com.ruoyi.web.controller.tool; import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.support.Convert; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.generator.domain.TableInfo; import com.ruoyi.generator.service.IGenService; import com.ruoyi.web.core.base.BaseController; /** * 代码生成 操作处理 * * @author ruoyi */ @Controller @RequestMapping("/tool/gen") public class GenController extends BaseController { private String prefix = "tool/gen"; @Autowired private IGenService genService; @RequiresPermissions("tool:gen:view") @GetMapping() public String gen() { return prefix + "/gen"; } @RequiresPermissions("tool:gen:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(TableInfo tableInfo) { startPage(); Listlist = genService.selectTableList(tableInfo); return getDataTable(list); } /** * 生成代码 */ @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) @GetMapping("/genCode/{tableName}") public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { byte[] data = genService.generatorCode(tableName); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); } /** * 批量生成代码 */ @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) @GetMapping("/batchGenCode") @ResponseBody public void batchGenCode(HttpServletResponse response, String tables) throws IOException { String[] tableNames = Convert.toStrArray(tables); byte[] data = genService.generatorCode(tableNames); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); } }
SwaggerController.java------swagger接口
package com.ruoyi.web.controller.tool; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import com.ruoyi.web.core.base.BaseController; /** * swagger 接口 * 一种可以写API文档的工具 * * @author ruoyi */ @Controller @RequestMapping("/tool/swagger") public class SwaggerController extends BaseController { @RequiresPermissions("tool:swagger:view") @GetMapping() public String index() { return redirect("/swagger-ui.html"); } }
TestController.java-----swagger测试方法
package com.ruoyi.web.controller.tool; import java.util.ArrayList; import java.util.List; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.web.core.base.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; /** * swagger 测试方法 * * @author ruoyi */ @Api("用户信息管理") @RestController @RequestMapping("/test/*") public class TestController extends BaseController { private final static ListtestList = new ArrayList<>(); { testList.add(new Test("1", "admin", "admin123")); testList.add(new Test("2", "ry", "admin123")); } @ApiOperation("获取列表") @GetMapping("list") public List testList() { return testList; } @ApiOperation("新增用户") @PostMapping("save") public AjaxResult save(Test test) { return testList.add(test) ? success() : error(); } @ApiOperation("更新用户") @ApiImplicitParam(name = "Test", value = "单个用户信息", dataType = "Test") @PutMapping("update") public AjaxResult update(Test test) { return testList.remove(test) && testList.add(test) ? success() : error(); } @ApiOperation("删除用户") @ApiImplicitParam(name = "Tests", value = "单个用户信息", dataType = "Test") @DeleteMapping("delete") public AjaxResult delete(Test test) { return testList.remove(test) ? success() : error(); } } class Test { private String userId; private String username; private String password; public Test() { } public Test(String userId, String username, String password) { this.userId = userId; this.username = username; this.password = password; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Test test = (Test) o; return userId != null ? userId.equals(test.userId) : test.userId == null; } @Override public int hashCode() { int result = userId != null ? userId.hashCode() : 0; result = 31 * result + (username != null ? username.hashCode() : 0); result = 31 * result + (password != null ? password.hashCode() : 0); return result; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
-----core包
-----------base包
BaseController.java------web层通用数据业务处理
package com.ruoyi.web.core.base; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.ruoyi.common.base.AjaxResult; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.util.ShiroUtils; import com.ruoyi.framework.web.page.PageDomain; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.framework.web.page.TableSupport; import com.ruoyi.system.domain.SysUser; /** * web层通用数据处理 * * @author ruoyi */ public class BaseController { /** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 */ @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); } /** * 设置请求分页数据 */ protected void startPage() { PageDomain pageDomain = TableSupport.buildPageRequest(); Integer pageNum = pageDomain.getPageNum(); Integer pageSize = pageDomain.getPageSize(); if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) { String orderBy = pageDomain.getOrderBy(); PageHelper.startPage(pageNum, pageSize, orderBy); } } /** * 响应请求分页数据 */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected TableDataInfo getDataTable(List> list) { TableDataInfo rspData = new TableDataInfo(); rspData.setCode(0); rspData.setRows(list); rspData.setTotal(new PageInfo(list).getTotal()); return rspData; } /** * 响应返回结果 * * @param rows 影响行数 * @return 操作结果 */ protected AjaxResult toAjax(int rows) { return rows > 0 ? success() : error(); } /** * 返回成功 */ public AjaxResult success() { return AjaxResult.success(); } /** * 返回失败消息 */ public AjaxResult error() { return AjaxResult.error(); } /** * 返回成功消息 */ public AjaxResult success(String message) { return AjaxResult.success(message); } /** * 返回失败消息 */ public AjaxResult error(String message) { return AjaxResult.error(message); } /** * 返回错误码消息 */ public AjaxResult error(int code, String message) { return AjaxResult.error(code, message); } /** * 页面跳转 */ public String redirect(String url) { return StringUtils.format("redirect:{}", url); } public SysUser getUser() { return ShiroUtils.getUser(); } public void setUser(SysUser user) { ShiroUtils.setUser(user); } public Long getUserId() { return getUser().getUserId(); } public String getLoginName() { return getUser().getLoginName(); } }
三,一、resources包
--ehcache包
ehcache-shiro.xml--------
一个纯Java的进程内缓存框架的配置
<defaultCache maxEntriesLocalHeap="1000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="false"> maxEntriesLocalHeap="2000" eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="0" overflowToDisk="false" statistics="true">
--i18n包
messages-properties-------
提示错误消息
#错误消息 not.null=* 必须填写 user.jcaptcha.error=验证码错误 user.not.exists=用户不存在/密码错误 user.password.not.match=用户不存在/密码错误 user.password.retry.limit.count=密码输入错误{0}次 user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定10分钟 user.password.delete=对不起,您的账号已被删除 user.blocked=用户已封禁,原因:{0} role.blocked=角色已封禁,原因:{0} user.logout.success=退出成功 length.not.valid=长度必须在{min}到{max}个字符之间 user.username.not.valid=* 2到20个汉字、字母、数字或下划线组成,且必须以非数字开头 user.password.not.valid=* 5-50个字符 user.email.not.valid=邮箱格式错误 user.mobile.phone.number.not.valid=手机号格式错误 user.login.success=登录成功 user.notfound=请重新登录 user.forcelogout=管理员强制退出,请重新登录 user.unknown.error=未知错误,请重新登录 #批量插入用户错误信息 user.import.excel.null=Excel数据为空,请按照导入模板填写数据 user.import.excel.data.null=Excel数据为空,只有标题行,请按照导入模板填写数据 user.import.excel.filetype.error=文件不是Excel文件 user.import.excel.file.error=文件名为空,文件为空 user.import.excel.fileinput.error=获取Excel2003流错误 user.import.excel.fileinputx.error=获取Excel2007流错误 ##权限 no.permission=您没有数据的权限,请联系管理员添加权限 [{0}] no.create.permission=您没有创建数据的权限,请联系管理员添加权限 [{0}] no.update.permission=您没有修改数据的权限,请联系管理员添加权限 [{0}] no.delete.permission=您没有删除数据的权限,请联系管理员添加权限 [{0}] no.export.permission=您没有导出数据的权限,请联系管理员添加权限 [{0}] no.view.permission=您没有查看数据的权限,请联系管理员添加权限 [{0}]
--static包
本包装了
ajax.libs包-----ajax框架
css包-----页面样式
font包----字体字号
img包----图标
js包-----事件驱动
ruoyi包------网页事件驱动和样式
--tenplates包----------系统的全部静态页面html