From 530db31b6e8c64f655f000bea1b5665ff044eb0a Mon Sep 17 00:00:00 2001 From: zxm <154040976@qq.com> Date: Sat, 21 Apr 2018 23:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8F=9C=E5=8D=95=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E3=80=81=E9=80=89=E6=8B=A9=E5=9B=BE=E6=A0=87=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=89=8D=E7=AB=AFjs=E5=B0=81=E8=A3=85?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=B7=A5=E4=BD=9C=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E7=8E=B0=E5=AD=98bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/checkstyle-idea.xml | 16 + .idea/codeStyleSettings.xml | 9 + .idea/compiler.xml | 3 + .idea/encodings.xml | 3 +- .idea/inspectionProfiles/Project_Default.xml | 36 + .idea/libraries/Maven__junit_junit_3_8_1.xml | 13 + .idea/misc.xml | 2 +- len-activiti/pom.xml | 4 +- .../com/len/actlistener/ListenUserRole.java | 10 +- .../java/com/len/config/ActivitiConfig.java | 2 + .../len/controller/ActivitiController.java | 4 - .../len/controller/UserLeaveController.java | 74 +- .../resources/ftl/act/deploy/act-node.ftl | 2 +- .../resources/ftl/act/leave/add-leave.ftl | 5 +- .../resources/ftl/act/leave/leaveDetail.ftl | 2 +- .../resources/ftl/act/leave/leaveList.ftl | 2 +- .../resources/ftl/act/leave/update-leave.ftl | 2 +- .../resources/ftl/act/task/task-agent.ftl | 2 +- .../main/resources/ftl/act/task/taskList.ftl | 15 +- .../src/main/resources/ftl/actList.ftl | 6 +- .../src/main/resources/ftl/actModelList.ftl | 4 +- .../main/resources/mapper/UserLeaveMapper.xml | 1 + len-core/pom.xml | 9 +- .../src/main/java/com/len/util/JsonUtil.java | 1 - len-sys/pom.xml | 3 +- .../com/len/controller/ErrorController.java | 23 +- .../com/len/controller/JobController.java | 304 ++++---- .../com/len/controller/LogController.java | 47 +- .../com/len/controller/LoginController.java | 222 +++--- .../com/len/controller/MenuController.java | 29 +- .../com/len/controller/RoleController.java | 244 ++++--- .../com/len/controller/UserController.java | 450 ++++++------ .../BootListener/DataSourceJobThread.java | 58 +- .../BootListener/MyApplicationListener.java | 29 +- .../MyServletContextListener.java | 17 +- .../java/com/len/core/annotation/Log.java | 16 +- .../com/len/core/annotation/LogAspect.java | 49 +- .../core/quartz/CustomQuartz/DataSchdule.java | 30 + .../core/quartz/CustomQuartz/JobDemo2.java | 11 +- .../src/main/java/com/len/entity/SysJob.java | 1 + .../java/com/len/mapper/SysJobMapper.java | 2 +- len-sys/src/main/resources/ftl/main/main.ftl | 2 +- .../main/resources/ftl/system/job/add-job.ftl | 25 +- .../main/resources/ftl/system/job/jobList.ftl | 2 +- .../resources/ftl/system/job/update-job.ftl | 25 +- .../main/resources/ftl/system/log/logList.ftl | 2 +- .../resources/ftl/system/menu/add-menu.ftl | 30 +- .../resources/ftl/system/menu/menuList.ftl | 9 +- .../resources/ftl/system/menu/update-menu.ftl | 269 +++++++ .../resources/ftl/system/role/add-role.ftl | 26 +- .../resources/ftl/system/role/roleList.ftl | 8 +- .../resources/ftl/system/role/update-role.ftl | 217 +++--- .../resources/ftl/system/user/add-user.ftl | 24 +- .../resources/ftl/system/user/re-pass.ftl | 2 +- .../resources/ftl/system/user/update-user.ftl | 21 +- .../resources/ftl/system/user/userList.ftl | 2 +- .../src/main/resources/plugin/html/icon.html | 688 ++++++++++++++++++ len-web/pom.xml | 9 +- .../src/main/java/com/len/Application.java | 3 +- .../java/com/len/config/BeanFactoryImpl.java | 23 + .../main/java/com/len/config/BeanName.java | 18 + .../java/com/len/config/SwaggerConfig.java | 2 +- pom.xml | 28 +- 63 files changed, 2177 insertions(+), 1020 deletions(-) create mode 100644 .idea/checkstyle-idea.xml create mode 100644 .idea/codeStyleSettings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/libraries/Maven__junit_junit_3_8_1.xml create mode 100644 len-sys/src/main/java/com/len/core/quartz/CustomQuartz/DataSchdule.java create mode 100644 len-sys/src/main/resources/ftl/system/menu/update-menu.ftl create mode 100644 len-sys/src/main/resources/plugin/html/icon.html create mode 100644 len-web/src/main/java/com/len/config/BeanFactoryImpl.java create mode 100644 len-web/src/main/java/com/len/config/BeanName.java diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000..f75a1f8 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..5555dd2 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 14dbaf6..49d4afa 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,9 @@ + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index faab52c..eb5b13e 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,10 +1,11 @@ - + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_3_8_1.xml b/.idea/libraries/Maven__junit_junit_3_8_1.xml new file mode 100644 index 0000000..71b2993 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_3_8_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 11d6f5f..b235c78 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + diff --git a/len-core/src/main/java/com/len/util/JsonUtil.java b/len-core/src/main/java/com/len/util/JsonUtil.java index 925ec8a..2365499 100644 --- a/len-core/src/main/java/com/len/util/JsonUtil.java +++ b/len-core/src/main/java/com/len/util/JsonUtil.java @@ -2,7 +2,6 @@ package com.len.util; import com.alibaba.fastjson.JSONObject; -import net.minidev.json.JSONUtil; /** * @author zhuxiaomeng diff --git a/len-sys/pom.xml b/len-sys/pom.xml index 978a0ad..88dc8e1 100644 --- a/len-sys/pom.xml +++ b/len-sys/pom.xml @@ -5,14 +5,15 @@ lenosp com.len 1.0-SNAPSHOT + ../pom.xml 4.0.0 len-sys - jar len-sys http://maven.apache.org + war UTF-8 diff --git a/len-sys/src/main/java/com/len/controller/ErrorController.java b/len-sys/src/main/java/com/len/controller/ErrorController.java index 565dc24..98e9699 100644 --- a/len-sys/src/main/java/com/len/controller/ErrorController.java +++ b/len-sys/src/main/java/com/len/controller/ErrorController.java @@ -1,6 +1,7 @@ package com.len.controller; import java.io.UnsupportedEncodingException; + import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -17,17 +18,17 @@ import org.springframework.web.bind.annotation.RequestMapping; @RequestMapping(value = "/error") public class ErrorController { - @GetMapping(value = "404") - public String pageNotFound(){ - return "error/404"; -} - - @GetMapping(value = "403") - public String NotFound(String message,Model model){ - if(!StringUtils.isEmpty(message)){ - model.addAttribute("message",message); + @GetMapping(value = "404") + public String pageNotFound() { + return "error/404"; + } + + @GetMapping(value = "403") + public String NotFound(String message, Model model) { + if (!StringUtils.isEmpty(message)) { + model.addAttribute("message", message); + } + return "error/403"; } - return "error/403"; -} } diff --git a/len-sys/src/main/java/com/len/controller/JobController.java b/len-sys/src/main/java/com/len/controller/JobController.java index 69e6549..1aa29a0 100644 --- a/len-sys/src/main/java/com/len/controller/JobController.java +++ b/len-sys/src/main/java/com/len/controller/JobController.java @@ -12,7 +12,9 @@ import com.len.util.BeanUtil; import com.len.util.Checkbox; import com.len.util.JsonUtil; import io.swagger.annotations.ApiOperation; + import java.util.List; + import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -27,177 +29,177 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author zhuxiaomeng * @date 2018/1/6. * @email 154040976@qq.com - * + *

* 定时任务 controller */ @Controller @RequestMapping("/job") public class JobController extends BaseController { - @Autowired - JobService jobService; + @Autowired + JobService jobService; - @Autowired - JobTask jobTask; + @Autowired + JobTask jobTask; - @GetMapping(value = "showJob") - @RequiresPermissions("job:show") - public String showUser(Model model) { - return "/system/job/jobList"; - } - - @GetMapping(value = "showJobList") - @ResponseBody - @RequiresPermissions("job:show") - public String showUser(Model model, SysJob job, String page, String limit) { - return jobService.show(job,Integer.valueOf(page),Integer.valueOf(limit)); - } - - @GetMapping(value = "showAddJob") - public String addJob(Model model) { - return "/system/job/add-job"; - } - - @ApiOperation(value = "/addJob", httpMethod = "POST", notes = "添加任务类") - @Log(desc = "添加任务") - @PostMapping(value = "addJob") - @ResponseBody - public JsonUtil addJob(SysJob job) { - JsonUtil j=new JsonUtil(); - String msg="保存成功"; - job.setStatus(false); - try { - jobService.insertSelective(job); - }catch (MyException e){ - msg="保存失败"; - j.setFlag(false); - e.printStackTrace(); + @GetMapping(value = "showJob") + @RequiresPermissions("job:show") + public String showUser(Model model) { + return "/system/job/jobList"; } - j.setMsg(msg); - return j; - } - @GetMapping(value = "updateJob") - public String updateJob(String id, Model model, boolean detail) { - if (StringUtils.isNotEmpty(id)) { - SysJob job = jobService.selectByPrimaryKey(id); - model.addAttribute("job", job); + @GetMapping(value = "showJobList") + @ResponseBody + @RequiresPermissions("job:show") + public String showUser(Model model, SysJob job, String page, String limit) { + return jobService.show(job, Integer.valueOf(page), Integer.valueOf(limit)); } - model.addAttribute("detail", detail); - return "system/job/update-job"; - } + @GetMapping(value = "showAddJob") + public String addJob(Model model) { + return "/system/job/add-job"; + } - @ApiOperation(value = "/updateJob", httpMethod = "POST", notes = "更新任务") - @Log(desc = "更新任务",type = LOG_TYPE.UPDATE) - @PostMapping(value = "updateJob") - @ResponseBody - public JsonUtil updateJob(SysJob job){ - JsonUtil j=new JsonUtil(); - j.setFlag(false); - if (job == null) { - j.setMsg("获取数据失败"); - return j; - } - if(jobTask.checkJob(job)){ - j.setMsg("已经启动任务无法更新,请停止后更新"); - return j; - } - try{ - SysJob oldJob=jobService.selectByPrimaryKey(job.getId()); - BeanUtil.copyNotNullBean(job, oldJob); - jobService.updateByPrimaryKey(oldJob); - j.setFlag(true); - j.setMsg("修改成功"); - }catch (MyException e){ - j.setMsg("更新失败"); - e.printStackTrace(); - } - return j; - } - - @Log(desc = "删除任务",type = LOG_TYPE.DEL) - @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除任务") - @PostMapping(value = "del") - @ResponseBody - @RequiresPermissions("job:del") - public JsonUtil del(String id){ - JsonUtil j=new JsonUtil(); - j.setFlag(false); - if (StringUtils.isEmpty(id)) { - j.setMsg("获取数据失败"); - return j; - } - try{ - SysJob job=jobService.selectByPrimaryKey(id); - boolean flag=jobTask.checkJob(job); - if((flag&&!job.getStatus())||!flag&&job.getStatus()){ - j.setMsg("您任务表状态和web任务状态不一致,无法删除"); + @ApiOperation(value = "/addJob", httpMethod = "POST", notes = "添加任务类") + @Log(desc = "添加任务") + @PostMapping(value = "addJob") + @ResponseBody + public JsonUtil addJob(SysJob job) { + JsonUtil j = new JsonUtil(); + String msg = "保存成功"; + job.setStatus(false); + try { + jobService.insertSelective(job); + } catch (MyException e) { + msg = "保存失败"; + j.setFlag(false); + e.printStackTrace(); + } + j.setMsg(msg); return j; - } - if(flag){ - j.setMsg("该任务处于启动中,无法删除"); + } + + @GetMapping(value = "updateJob") + public String updateJob(String id, Model model, boolean detail) { + if (StringUtils.isNotEmpty(id)) { + SysJob job = jobService.selectByPrimaryKey(id); + model.addAttribute("job", job); + } + model.addAttribute("detail", detail); + return "system/job/update-job"; + } + + + @ApiOperation(value = "/updateJob", httpMethod = "POST", notes = "更新任务") + @Log(desc = "更新任务", type = LOG_TYPE.UPDATE) + @PostMapping(value = "updateJob") + @ResponseBody + public JsonUtil updateJob(SysJob job) { + JsonUtil j = new JsonUtil(); + j.setFlag(false); + if (job == null) { + j.setMsg("获取数据失败"); + return j; + } + if (jobTask.checkJob(job)) { + j.setMsg("已经启动任务无法更新,请停止后更新"); + return j; + } + try { + SysJob oldJob = jobService.selectByPrimaryKey(job.getId()); + BeanUtil.copyNotNullBean(job, oldJob); + jobService.updateByPrimaryKey(oldJob); + j.setFlag(true); + j.setMsg("修改成功"); + } catch (MyException e) { + j.setMsg("更新失败"); + e.printStackTrace(); + } + return j; + } + + @Log(desc = "删除任务", type = LOG_TYPE.DEL) + @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除任务") + @PostMapping(value = "del") + @ResponseBody + @RequiresPermissions("job:del") + public JsonUtil del(String id) { + JsonUtil j = new JsonUtil(); + j.setFlag(false); + if (StringUtils.isEmpty(id)) { + j.setMsg("获取数据失败"); + return j; + } + try { + SysJob job = jobService.selectByPrimaryKey(id); + boolean flag = jobTask.checkJob(job); + if ((flag && !job.getStatus()) || !flag && job.getStatus()) { + j.setMsg("您任务表状态和web任务状态不一致,无法删除"); + return j; + } + if (flag) { + j.setMsg("该任务处于启动中,无法删除"); + return j; + } + jobService.deleteByPrimaryKey(id); + j.setFlag(true); + j.setMsg("任务删除成功"); + } catch (MyException e) { + j.setMsg("任务删除异常"); + e.printStackTrace(); + } return j; - } - jobService.deleteByPrimaryKey(id); - j.setFlag(true); - j.setMsg("任务删除成功"); - }catch (MyException e){ - j.setMsg("任务删除异常"); - e.printStackTrace(); } - return j; - } - @Log(desc = "启动任务") - @PostMapping(value = "startJob") - @ResponseBody - @RequiresPermissions("job:start") - public JsonUtil startJob(String id){ - JsonUtil j=new JsonUtil(); - String msg=null; - if(StringUtils.isEmpty(id)){ - j.setMsg("获取数据失败"); - j.setFlag(false); - return j; + @Log(desc = "启动任务") + @PostMapping(value = "startJob") + @ResponseBody + @RequiresPermissions("job:start") + public JsonUtil startJob(String id) { + JsonUtil j = new JsonUtil(); + String msg = null; + if (StringUtils.isEmpty(id)) { + j.setMsg("获取数据失败"); + j.setFlag(false); + return j; + } + try { + SysJob job = jobService.selectByPrimaryKey(id); + jobTask.startJob(job); + job.setStatus(true); + jobService.updateByPrimaryKey(job); + msg = "启动成功"; + } catch (MyException e) { + e.printStackTrace(); + } + j.setMsg(msg); + return j; } - try { - SysJob job = jobService.selectByPrimaryKey(id); - jobTask.startJob(job); - job.setStatus(true); - jobService.updateByPrimaryKey(job); - msg="启动成功"; - }catch (MyException e){ - e.printStackTrace(); - } - j.setMsg(msg); - return j; - } - @Log(desc = "停止任务") - @PostMapping(value = "endJob") - @ResponseBody - @RequiresPermissions("job:end") - public JsonUtil endJob(String id){ - JsonUtil j=new JsonUtil(); - String msg=null; - if(StringUtils.isEmpty(id)){ - j.setMsg("获取数据失败"); - j.setFlag(false); - return j; + @Log(desc = "停止任务") + @PostMapping(value = "endJob") + @ResponseBody + @RequiresPermissions("job:end") + public JsonUtil endJob(String id) { + JsonUtil j = new JsonUtil(); + String msg = null; + if (StringUtils.isEmpty(id)) { + j.setMsg("获取数据失败"); + j.setFlag(false); + return j; + } + try { + SysJob job = jobService.selectByPrimaryKey(id); + jobTask.remove(job); + job.setStatus(false); + jobService.updateByPrimaryKey(job); + msg = "停止成功"; + } catch (MyException e) { + e.printStackTrace(); + } + j.setMsg(msg); + return j; } - try { - SysJob job = jobService.selectByPrimaryKey(id); - jobTask.remove(job); - job.setStatus(false); - jobService.updateByPrimaryKey(job); - msg="停止成功"; - }catch (MyException e){ - e.printStackTrace(); - } - j.setMsg(msg); - return j; - } } diff --git a/len-sys/src/main/java/com/len/controller/LogController.java b/len-sys/src/main/java/com/len/controller/LogController.java index edf818b..5093032 100644 --- a/len-sys/src/main/java/com/len/controller/LogController.java +++ b/len-sys/src/main/java/com/len/controller/LogController.java @@ -9,7 +9,9 @@ import com.len.exception.MyException; import com.len.mapper.SysLogMapper; import com.len.util.JsonUtil; import com.len.util.ReType; + import java.util.List; + import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -23,23 +25,24 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author zhuxiaomeng * @date 2017/12/29. * @email 154040976@qq.com - * + *

* 日志监控 */ @Controller @RequestMapping(value = "/log") -public class LogController extends BaseController{ - private static final Logger logger= Logger.getLogger(LogController.class); +public class LogController extends BaseController { + private static final Logger logger = Logger.getLogger(LogController.class); @Autowired private SysLogMapper logMapper; @GetMapping(value = "showLog") - public String showMenu(Model model){ + public String showMenu(Model model) { return "/system/log/logList"; } /** * 日志监控 + * * @param sysLog * @param page * @param limit @@ -47,35 +50,37 @@ public class LogController extends BaseController{ */ @GetMapping(value = "showLogList") @ResponseBody - public String showLog(SysLog sysLog, String page, String limit){ - List tList=null; - Page tPage= PageHelper.startPage(Integer.valueOf(page),Integer.valueOf(limit)); - try{ - tList=logMapper.selectListByPage(sysLog); - }catch (MyException e){ - logger.error("class:LogController ->method:showLog->message:"+e.getMessage()); + public String showLog(SysLog sysLog, String page, String limit) { + List tList = null; + Page tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit)); + try { + tList = logMapper.selectListByPage(sysLog); + } catch (MyException e) { + logger.error("class:LogController ->method:showLog->message:" + e.getMessage()); e.printStackTrace(); } - ReType reType=new ReType(tPage.getTotal(),tList); + ReType reType = new ReType(tPage.getTotal(), tList); return JSON.toJSONString(reType); } /** * 删除log + * * @param * @return */ @PostMapping(value = "del") @ResponseBody - public JsonUtil del(String[] ids){ - JsonUtil j=new JsonUtil(); - String msg="删除成功"; - try{ - for(String id:ids) - logMapper.deleteByPrimaryKey(Integer.valueOf(id)); - }catch (MyException e){ - msg="删除失败"; - logger.error(msg+e.getMessage()); + public JsonUtil del(String[] ids) { + JsonUtil j = new JsonUtil(); + String msg = "删除成功"; + try { + for (String id : ids) { + logMapper.deleteByPrimaryKey(Integer.valueOf(id)); + } + } catch (MyException e) { + msg = "删除失败"; + logger.error(msg + e.getMessage()); } j.setMsg(msg); return j; diff --git a/len-sys/src/main/java/com/len/controller/LoginController.java b/len-sys/src/main/java/com/len/controller/LoginController.java index 00e5eba..c346a8a 100644 --- a/len-sys/src/main/java/com/len/controller/LoginController.java +++ b/len-sys/src/main/java/com/len/controller/LoginController.java @@ -12,12 +12,14 @@ import com.len.service.MenuService; import com.len.service.SysUserService; import com.len.util.VerifyCodeUtils; import io.swagger.annotations.ApiOperation; + import java.util.List; import java.util.Map; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; + import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.ExcessiveAttemptsException; import org.apache.shiro.authc.IncorrectCredentialsException; @@ -46,130 +48,132 @@ import org.springframework.web.bind.annotation.ResponseStatus; @Controller public class LoginController { - @Autowired - private SysUserService userService; + @Autowired + private SysUserService userService; - @Autowired - private MenuService menuService; + @Autowired + private MenuService menuService; - @GetMapping(value = "") - public String loginInit(){ - return loginCheck(); - } - @GetMapping(value = "goLogin") - public String goLogin(Model model,ServletRequest request){ - Subject sub=SecurityUtils.getSubject(); - if(sub.isAuthenticated()){ - return "/main/main"; - }else{ - model.addAttribute("message","请重新登录"); - return "/login"; + @GetMapping(value = "") + public String loginInit() { + return loginCheck(); } - } - @GetMapping(value = "/login") - public String loginCheck(){ - Subject sub=SecurityUtils.getSubject(); - Boolean flag2=sub.isRemembered(); - boolean flag=sub.isAuthenticated()||flag2; - Session session=sub.getSession(); - if(flag){ - return "/main/main"; + @GetMapping(value = "goLogin") + public String goLogin(Model model, ServletRequest request) { + Subject sub = SecurityUtils.getSubject(); + if (sub.isAuthenticated()) { + return "/main/main"; + } else { + model.addAttribute("message", "请重新登录"); + return "/login"; + } } - return "/login"; - } - /** - * 登录动作 - * @param user - * @param model - * @param rememberMe - * @return - */ - @ApiOperation(value = "/login", httpMethod = "POST", notes = "登录method") - @PostMapping(value = "/login") - public String login(SysUser user,Model model,String rememberMe,HttpServletRequest request){ - String codeMsg = (String)request.getAttribute("shiroLoginFailure"); - if("code.error".equals(codeMsg)){ - model.addAttribute("message","验证码错误"); - return "/login"; + @GetMapping(value = "/login") + public String loginCheck() { + Subject sub = SecurityUtils.getSubject(); + Boolean flag2 = sub.isRemembered(); + boolean flag = sub.isAuthenticated() || flag2; + Session session = sub.getSession(); + if (flag) { + return "/main/main"; + } + return "/login"; } - UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername().trim(), - user.getPassword()); - Subject subject = ShiroUtil.getSubject(); - String msg=null; - try{ - subject.login(token); - //subject.hasRole("admin"); - if(subject.isAuthenticated()){ - return "/main/main"; - } - }catch (UnknownAccountException e) { - msg = "用户名/密码错误"; - } catch (IncorrectCredentialsException e) { - msg = "用户名/密码错误"; - } catch (ExcessiveAttemptsException e) { - msg = "登录失败多次,账户锁定10分钟"; + + /** + * 登录动作 + * + * @param user + * @param model + * @param rememberMe + * @return + */ + @ApiOperation(value = "/login", httpMethod = "POST", notes = "登录method") + @PostMapping(value = "/login") + public String login(SysUser user, Model model, String rememberMe, HttpServletRequest request) { + String codeMsg = (String) request.getAttribute("shiroLoginFailure"); + if ("code.error".equals(codeMsg)) { + model.addAttribute("message", "验证码错误"); + return "/login"; + } + UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername().trim(), + user.getPassword()); + Subject subject = ShiroUtil.getSubject(); + String msg = null; + try { + subject.login(token); + //subject.hasRole("admin"); + if (subject.isAuthenticated()) { + return "/main/main"; + } + } catch (UnknownAccountException e) { + msg = "用户名/密码错误"; + } catch (IncorrectCredentialsException e) { + msg = "用户名/密码错误"; + } catch (ExcessiveAttemptsException e) { + msg = "登录失败多次,账户锁定10分钟"; + } + if (msg != null) { + model.addAttribute("message", msg); + } + return "/login"; } - if(msg!=null){ - model.addAttribute("message",msg); + + @Log(desc = "用户退出平台") + @GetMapping(value = "/logout") + public String logout() { + Subject sub = SecurityUtils.getSubject(); + sub.logout(); + return "/login"; } - return "/login"; - } - @Log(desc = "用户退出平台") - @GetMapping(value = "/logout") - public String logout(){ - Subject sub=SecurityUtils.getSubject(); - sub.logout(); - return "/login"; - } - - /** - * 组装菜单json格式 - * update by 17/12/13 - * @return - */ - public JSONArray getMenuJson(){ - List mList=menuService.getMenuNotSuper(); - JSONArray jsonArr=new JSONArray(); - for(SysMenu sysMenu:mList){ - SysMenu menu=getChild(sysMenu.getId()); - jsonArr.add(menu); + /** + * 组装菜单json格式 + * update by 17/12/13 + * + * @return + */ + public JSONArray getMenuJson() { + List mList = menuService.getMenuNotSuper(); + JSONArray jsonArr = new JSONArray(); + for (SysMenu sysMenu : mList) { + SysMenu menu = getChild(sysMenu.getId()); + jsonArr.add(menu); + } + return jsonArr; } - return jsonArr; - } - public SysMenu getChild(String id){ - SysMenu sysMenu=menuService.selectByPrimaryKey(id); - List mList=menuService.getMenuChildren(id); - for(SysMenu menu:mList){ - SysMenu m=getChild(menu.getId()); - sysMenu.addChild(m); + public SysMenu getChild(String id) { + SysMenu sysMenu = menuService.selectByPrimaryKey(id); + List mList = menuService.getMenuChildren(id); + for (SysMenu menu : mList) { + SysMenu m = getChild(menu.getId()); + sysMenu.addChild(m); + } + return sysMenu; } - return sysMenu; - } + @GetMapping(value = "/getCode") + public void getYzm(HttpServletResponse response, HttpServletRequest request) { + try { + response.setHeader("Pragma", "No-cache"); + response.setHeader("Cache-Control", "no-cache"); + response.setDateHeader("Expires", 0); + response.setContentType("image/jpg"); - @GetMapping(value="/getCode") - public void getYzm(HttpServletResponse response, HttpServletRequest request){ - try { - response.setHeader("Pragma", "No-cache"); - response.setHeader("Cache-Control", "no-cache"); - response.setDateHeader("Expires", 0); - response.setContentType("image/jpg"); - - //生成随机字串 - String verifyCode = VerifyCodeUtils.generateVerifyCode(4); - //存入会话session - HttpSession session = request.getSession(true); - session.setAttribute("_code", verifyCode.toLowerCase()); - //生成图片 - int w = 146, h = 33; - VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode); - } catch (Exception e) { - e.printStackTrace(); + //生成随机字串 + String verifyCode = VerifyCodeUtils.generateVerifyCode(4); + //存入会话session + HttpSession session = request.getSession(true); + session.setAttribute("_code", verifyCode.toLowerCase()); + //生成图片 + int w = 146, h = 33; + VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode); + } catch (Exception e) { + e.printStackTrace(); + } } - } } diff --git a/len-sys/src/main/java/com/len/controller/MenuController.java b/len-sys/src/main/java/com/len/controller/MenuController.java index 2351ec5..8fc71f6 100644 --- a/len-sys/src/main/java/com/len/controller/MenuController.java +++ b/len-sys/src/main/java/com/len/controller/MenuController.java @@ -3,9 +3,11 @@ package com.len.controller; import com.alibaba.fastjson.JSONArray; import com.len.base.BaseController; import com.len.core.annotation.Log; +import com.len.core.annotation.Log.LOG_TYPE; import com.len.entity.SysMenu; import com.len.exception.MyException; import com.len.service.MenuService; +import com.len.util.BeanUtil; import com.len.util.JsonUtil; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -24,8 +26,8 @@ import org.springframework.web.bind.annotation.ResponseBody; * @email 154040976@qq.com * 菜单 */ +@RequestMapping("/menu") @Controller -@RequestMapping(value = "/menu") public class MenuController extends BaseController{ @Autowired @@ -54,6 +56,7 @@ public class MenuController extends BaseController{ return "/system/menu/add-menu"; } + @Log(desc = "添加菜单",type = LOG_TYPE.UPDATE) @ApiOperation(value = "/addMenu", httpMethod = "POST", notes = "添加菜单") @PostMapping(value = "addMenu") @ResponseBody @@ -86,4 +89,28 @@ public class MenuController extends BaseController{ return jsonUtil; } + @GetMapping(value = "showUpdateMenu") + public String showUpdateMenu(Model model,String id){ + SysMenu sysMenu = menuService.selectByPrimaryKey(id); + JSONArray ja=menuService.getMenuJsonList(); + model.addAttribute("menus", ja.toJSONString()); + model.addAttribute("sysMenu", sysMenu); + if(null!=sysMenu.getPId()){ + SysMenu pSysMenu=menuService.selectByPrimaryKey(sysMenu.getPId()); + model.addAttribute("pName", pSysMenu.getName()); + } + return "/system/menu/update-menu"; + } + + + @Log(desc = "更新菜单",type = LOG_TYPE.ADD) + @PostMapping(value = "updateMenu") + @ResponseBody + public JsonUtil updateMenu(SysMenu sysMenu){ + SysMenu oldMenu = menuService.selectByPrimaryKey(sysMenu.getId()); + BeanUtil.copyNotNullBean(sysMenu,oldMenu); + menuService.updateByPrimaryKeySelective(oldMenu); + return JsonUtil.sucess("保存成功"); + } + } diff --git a/len-sys/src/main/java/com/len/controller/RoleController.java b/len-sys/src/main/java/com/len/controller/RoleController.java index 3bf4182..80486fc 100644 --- a/len-sys/src/main/java/com/len/controller/RoleController.java +++ b/len-sys/src/main/java/com/len/controller/RoleController.java @@ -15,7 +15,9 @@ import com.len.service.RoleUserService; import com.len.util.BeanUtil; import com.len.util.JsonUtil; import io.swagger.annotations.ApiOperation; + import java.util.List; + import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -36,141 +38,141 @@ import org.springframework.web.bind.annotation.ResponseBody; @RequestMapping(value = "/role") public class RoleController extends BaseController { - @Autowired - private RoleService roleService; + @Autowired + private RoleService roleService; - @Autowired - private RoleUserService roleUserService; + @Autowired + private RoleUserService roleUserService; - @Autowired - private MenuService menuService; + @Autowired + private MenuService menuService; - @Autowired - private RoleMenuService roleMenuService; + @Autowired + private RoleMenuService roleMenuService; - @GetMapping(value = "showRole") - @RequiresPermissions(value = "role:show") - public String showRole(Model model){ - return "/system/role/roleList"; - } - - @ApiOperation(value = "/showRoleList", httpMethod = "GET", notes = "展示角色") - @GetMapping(value = "showRoleList") - @ResponseBody - @RequiresPermissions("role:show") - public String showRoleList(SysRole role,Model model,String page,String limit){ - return roleService.show(role,Integer.valueOf(page),Integer.valueOf(limit)); - } - - @GetMapping(value = "showAddRole") - public String addRole(Model model) { - JSONArray jsonArray=menuService.getTreeUtil(null); - model.addAttribute("menus",jsonArray.toJSONString()); - return "/system/role/add-role"; - } - - @ApiOperation(value = "/addRole", httpMethod = "POST", notes = "添加角色") - @Log(desc = "添加角色") - @PostMapping(value = "addRole") - @ResponseBody - public JsonUtil addRole(SysRole sysRole,String[] menus){ - if(StringUtils.isEmpty(sysRole.getRoleName())){ - JsonUtil.error("角色名称不能为空"); + @GetMapping(value = "showRole") + @RequiresPermissions(value = "role:show") + public String showRole(Model model) { + return "/system/role/roleList"; } - JsonUtil j=new JsonUtil(); - try{ - roleService.insertSelective(sysRole); - //操作role-menu data - SysRoleMenu sysRoleMenu=new SysRoleMenu(); - sysRoleMenu.setRoleId(sysRole.getId()); - if(menus!=null) - for(String menu:menus){ - sysRoleMenu.setMenuId(menu); - roleMenuService.insert(sysRoleMenu); - } - j.setMsg("保存成功"); - }catch (MyException e){ - j.setMsg("保存失败"); - j.setFlag(false); - e.printStackTrace(); + @ApiOperation(value = "/showRoleList", httpMethod = "GET", notes = "展示角色") + @GetMapping(value = "showRoleList") + @ResponseBody + @RequiresPermissions("role:show") + public String showRoleList(SysRole role, Model model, String page, String limit) { + return roleService.show(role, Integer.valueOf(page), Integer.valueOf(limit)); } - return j; - } - @GetMapping(value = "updateRole") - public String updateRole(String id,Model model,boolean detail){ - if (StringUtils.isNotEmpty(id)) { - SysRole role = roleService.selectByPrimaryKey(id); - model.addAttribute("role", role); - JSONArray jsonArray=menuService.getTreeUtil(id); - model.addAttribute("menus",jsonArray.toJSONString()); + @GetMapping(value = "showAddRole") + public String goAddRole(Model model) { + JSONArray jsonArray = menuService.getTreeUtil(null); + model.addAttribute("menus", jsonArray.toJSONString()); + return "/system/role/add-role"; } - model.addAttribute("detail", detail); - return "system/role/update-role"; - } - @ApiOperation(value = "/updateRole", httpMethod = "POST", notes = "更新角色") - @Log(desc = "更新角色") - @PostMapping(value = "updateRole") - @ResponseBody - public JsonUtil updateUser(SysRole role,String[] menus) { - JsonUtil jsonUtil = new JsonUtil(); - jsonUtil.setFlag(false); - if (role == null) { - jsonUtil.setMsg("获取数据失败"); - return jsonUtil; - } - try { - SysRole oldRole = roleService.selectByPrimaryKey(role.getId()); - BeanUtil.copyNotNullBean(role, oldRole); - roleService.updateByPrimaryKeySelective(oldRole); + @ApiOperation(value = "/addRole", httpMethod = "POST", notes = "添加角色") + @Log(desc = "添加角色") + @PostMapping(value = "addRole") + @ResponseBody + public JsonUtil addRole(SysRole sysRole, String[] menus) { + if (StringUtils.isEmpty(sysRole.getRoleName())) { + JsonUtil.error("角色名称不能为空"); + } + JsonUtil j = new JsonUtil(); + try { + roleService.insertSelective(sysRole); + //操作role-menu data + SysRoleMenu sysRoleMenu = new SysRoleMenu(); + sysRoleMenu.setRoleId(sysRole.getId()); - SysRoleMenu sysRoleMenu=new SysRoleMenu(); - sysRoleMenu.setRoleId(role.getId()); - List menuList=roleMenuService.selectByCondition(sysRoleMenu); - for(SysRoleMenu sysRoleMenu1:menuList){ - roleMenuService.deleteByPrimaryKey(sysRoleMenu1); - } - if(menus!=null) - for(String menu:menus){ - sysRoleMenu.setMenuId(menu); - roleMenuService.insert(sysRoleMenu); - } - jsonUtil.setFlag(true); - jsonUtil.setMsg("修改成功"); - } catch (MyException e) { - jsonUtil.setMsg("修改失败"); - e.printStackTrace(); + if (menus != null) + for (String menu : menus) { + sysRoleMenu.setMenuId(menu); + roleMenuService.insert(sysRoleMenu); + } + j.setMsg("保存成功"); + } catch (MyException e) { + j.setMsg("保存失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; } - return jsonUtil; - } - @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除角色") - @Log(desc = "删除角色",type = LOG_TYPE.DEL) - @PostMapping(value = "del") - @ResponseBody - @RequiresPermissions("role:del") - public JsonUtil del(String id) { - if (StringUtils.isEmpty(id)) { - return JsonUtil.error("获取数据失败"); + @GetMapping(value = "updateRole") + public String updateRole(String id, Model model, boolean detail) { + if (StringUtils.isNotEmpty(id)) { + SysRole role = roleService.selectByPrimaryKey(id); + model.addAttribute("role", role); + JSONArray jsonArray = menuService.getTreeUtil(id); + model.addAttribute("menus", jsonArray.toJSONString()); + } + model.addAttribute("detail", detail); + return "system/role/update-role"; } - SysRoleUser sysRoleUser=new SysRoleUser(); - sysRoleUser.setRoleId(id); - JsonUtil j=new JsonUtil(); - try { - int count= roleUserService.selectCountByCondition(sysRoleUser); - if(count>0){ - return JsonUtil.error("已分配给用户,删除失败"); - } - roleService.deleteByPrimaryKey(id); - j.setMsg("删除成功"); - } catch (MyException e) { - j.setMsg("删除失败"); - j.setFlag(false); - e.printStackTrace(); + + @ApiOperation(value = "/updateRole", httpMethod = "POST", notes = "更新角色") + @Log(desc = "更新角色") + @PostMapping(value = "updateRole") + @ResponseBody + public JsonUtil updateUser(SysRole role, String[] menus) { + JsonUtil jsonUtil = new JsonUtil(); + jsonUtil.setFlag(false); + if (role == null) { + jsonUtil.setMsg("获取数据失败"); + return jsonUtil; + } + try { + SysRole oldRole = roleService.selectByPrimaryKey(role.getId()); + BeanUtil.copyNotNullBean(role, oldRole); + roleService.updateByPrimaryKeySelective(oldRole); + + SysRoleMenu sysRoleMenu = new SysRoleMenu(); + sysRoleMenu.setRoleId(role.getId()); + List menuList = roleMenuService.selectByCondition(sysRoleMenu); + for (SysRoleMenu sysRoleMenu1 : menuList) { + roleMenuService.deleteByPrimaryKey(sysRoleMenu1); + } + if (menus != null) + for (String menu : menus) { + sysRoleMenu.setMenuId(menu); + roleMenuService.insert(sysRoleMenu); + } + jsonUtil.setFlag(true); + jsonUtil.setMsg("修改成功"); + } catch (MyException e) { + jsonUtil.setMsg("修改失败"); + e.printStackTrace(); + } + return jsonUtil; + } + + @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除角色") + @Log(desc = "删除角色", type = LOG_TYPE.DEL) + @PostMapping(value = "del") + @ResponseBody + @RequiresPermissions("role:del") + public JsonUtil del(String id) { + if (StringUtils.isEmpty(id)) { + return JsonUtil.error("获取数据失败"); + } + SysRoleUser sysRoleUser = new SysRoleUser(); + sysRoleUser.setRoleId(id); + JsonUtil j = new JsonUtil(); + try { + int count = roleUserService.selectCountByCondition(sysRoleUser); + if (count > 0) { + return JsonUtil.error("已分配给用户,删除失败"); + } + roleService.deleteByPrimaryKey(id); + j.setMsg("删除成功"); + } catch (MyException e) { + j.setMsg("删除失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; } - return j; - } } diff --git a/len-sys/src/main/java/com/len/controller/UserController.java b/len-sys/src/main/java/com/len/controller/UserController.java index 5039cbf..7276b85 100644 --- a/len-sys/src/main/java/com/len/controller/UserController.java +++ b/len-sys/src/main/java/com/len/controller/UserController.java @@ -14,11 +14,13 @@ import com.len.util.Checkbox; import com.len.util.JsonUtil; import com.len.util.Md5Util; import io.swagger.annotations.ApiOperation; + import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; + import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -41,249 +43,251 @@ import org.springframework.web.multipart.MultipartFile; //@Api(value="user") @Controller @RequestMapping(value = "/user") -public class UserController extends BaseController{ +public class UserController extends BaseController { - //private static final Logger + //private static final Logger - @Autowired - SysUserService userService; + @Autowired + SysUserService userService; - @Autowired - RoleUserService roleUserService; + @Autowired + RoleUserService roleUserService; - @Autowired - JobTask task; + @Autowired + JobTask task; - @GetMapping(value = "mainTest") - @RequiresPermissions("user:show") - public String showTest() { - return "system/user/mainTest"; - } - - @GetMapping(value = "showUser") - @RequiresPermissions("user:show") - public String showUser(Model model) { - return "/system/user/userList"; - } - - @GetMapping(value = "showUserList") - @ResponseBody - @RequiresPermissions("user:show") - public String showUser(Model model, SysUser user, String page, String limit) { - return userService.show(user,Integer.valueOf(page),Integer.valueOf(limit)); - } - - @GetMapping(value = "showAddUser") - public String addUser(Model model) { - List checkboxList=userService.getUserRoleByJson(null); - model.addAttribute("boxJson",checkboxList); - return "/system/user/add-user"; - } - - @ApiOperation(value = "/addUser", httpMethod = "POST", notes = "添加用户") - @Log(desc = "添加用户") - @PostMapping(value = "addUser") - @ResponseBody - public JsonUtil addUser(SysUser user,String[] role) { - if (user == null) { - return JsonUtil.error("获取数据失败"); + @GetMapping(value = "mainTest") + @RequiresPermissions("user:show") + public String showTest() { + return "system/user/mainTest"; } - if (StringUtils.isBlank(user.getUsername())) { - return JsonUtil.error("用户名不能为空"); - } - if (StringUtils.isBlank(user.getPassword())) { - return JsonUtil.error("密码不能为空"); - } - if(role==null){ - return JsonUtil.error("请选择角色"); - } - int result = userService.checkUser(user.getUsername()); - if (result > 0) { - return JsonUtil.error("用户名已存在"); - } - JsonUtil j=new JsonUtil(); - try { - userService.insertSelective(user); - SysRoleUser sysRoleUser=new SysRoleUser(); - sysRoleUser.setUserId(user.getId()); - for(String r:role){ - sysRoleUser.setRoleId(r); - roleUserService.insertSelective(sysRoleUser); - } - j.setMsg("保存成功"); - } catch (MyException e) { - j.setMsg("保存失败"); - j.setFlag(false); - e.printStackTrace(); - } - return j; - } - @GetMapping(value = "updateUser") - public String updateUser(String id, Model model, boolean detail) { - if (StringUtils.isNotEmpty(id)) { - //用户-角色 - List checkboxList=userService.getUserRoleByJson(id); - SysUser user = userService.selectByPrimaryKey(id); - model.addAttribute("user", user); - model.addAttribute("boxJson", checkboxList); + @GetMapping(value = "showUser") + @RequiresPermissions("user:show") + public String showUser(Model model) { + return "/system/user/userList"; } - model.addAttribute("detail", detail); - return "system/user/update-user"; - } - @ApiOperation(value = "/updateUser", httpMethod = "POST", notes = "更新用户") - @Log(desc = "更新用户",type = LOG_TYPE.UPDATE) - @PostMapping(value = "updateUser") - @ResponseBody - public JsonUtil updateUser(SysUser user,String role[]) { - JsonUtil jsonUtil = new JsonUtil(); - jsonUtil.setFlag(false); - if (user == null) { - jsonUtil.setMsg("获取数据失败"); - return jsonUtil; + @GetMapping(value = "showUserList") + @ResponseBody + @RequiresPermissions("user:show") + public String showUser(Model model, SysUser user, String page, String limit) { + return userService.show(user, Integer.valueOf(page), Integer.valueOf(limit)); } - try { - SysUser oldUser = userService.selectByPrimaryKey(user.getId()); - BeanUtil.copyNotNullBean(user, oldUser); - userService.updateByPrimaryKeySelective(oldUser); - SysRoleUser sysRoleUser =new SysRoleUser(); - sysRoleUser.setUserId(oldUser.getId()); - List keyList=userService.selectByCondition(sysRoleUser); - for(SysRoleUser sysRoleUser1 :keyList){ - roleUserService.deleteByPrimaryKey(sysRoleUser1); - } - if(role!=null){ - for(String r:role){ - sysRoleUser.setRoleId(r); - roleUserService.insert(sysRoleUser); + @GetMapping(value = "showAddUser") + public String goAddUser(Model model) { + List checkboxList = userService.getUserRoleByJson(null); + model.addAttribute("boxJson", checkboxList); + return "/system/user/add-user"; + } + + @ApiOperation(value = "/addUser", httpMethod = "POST", notes = "添加用户") + @Log(desc = "添加用户") + @PostMapping(value = "addUser") + @ResponseBody + public JsonUtil addUser(SysUser user, String[] role) { + if (user == null) { + return JsonUtil.error("获取数据失败"); + } + if (StringUtils.isBlank(user.getUsername())) { + return JsonUtil.error("用户名不能为空"); + } + if (StringUtils.isBlank(user.getPassword())) { + return JsonUtil.error("密码不能为空"); + } + if (role == null) { + return JsonUtil.error("请选择角色"); + } + int result = userService.checkUser(user.getUsername()); + if (result > 0) { + return JsonUtil.error("用户名已存在"); + } + JsonUtil j = new JsonUtil(); + try { + userService.insertSelective(user); + SysRoleUser sysRoleUser = new SysRoleUser(); + sysRoleUser.setUserId(user.getId()); + for (String r : role) { + sysRoleUser.setRoleId(r); + roleUserService.insertSelective(sysRoleUser); + } + j.setMsg("保存成功"); + } catch (MyException e) { + j.setMsg("保存失败"); + j.setFlag(false); + e.printStackTrace(); } - } - jsonUtil.setFlag(true); - jsonUtil.setMsg("修改成功"); - } catch (MyException e) { - e.printStackTrace(); - } - return jsonUtil; - } - - @Log(desc = "删除用户",type = LOG_TYPE.DEL) - @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除用户") - @PostMapping(value = "/del") - @ResponseBody - @RequiresPermissions("user:del") - public JsonUtil del(String id, boolean flag) { - return userService.delById(id,flag); - } - - @GetMapping(value = "goRePass") - public String goRePass(String id,Model model){ - if(StringUtils.isEmpty(id)){ - return "获取账户信息失败"; - } - SysUser user=userService.selectByPrimaryKey(id); - model.addAttribute("user",user); - return "/system/user/re-pass"; - } - - /** - * 修改密码 - * @param id - * @param pass - * @param newPwd - * @return - */ - @Log(desc = "修改密码",type = LOG_TYPE.UPDATE) - @PostMapping(value = "rePass") - @ResponseBody - @RequiresPermissions("user:repass") - public JsonUtil rePass(String id,String pass,String newPwd){ - boolean flag=StringUtils.isEmpty(id)||StringUtils.isEmpty(pass)||StringUtils.isEmpty(newPwd); - JsonUtil j=new JsonUtil(); - j.setFlag(false); - if(flag){ - j.setMsg("获取数据失败,修改失败"); - return j; - } - SysUser user=userService.selectByPrimaryKey(id); - newPwd=Md5Util.getMD5(newPwd,user.getUsername()); - pass=Md5Util.getMD5(pass,user.getUsername()); - if(!pass.equals(user.getPassword())){ - j.setMsg("密码不正确"); return j; } - if(newPwd.equals(user.getPassword())){ - j.setMsg("新密码不能与旧密码相同"); - return j; - } - user.setPassword(newPwd); - try { - userService.rePass(user); - j.setMsg("修改成功"); - j.setFlag(true); - }catch (MyException e){ - e.printStackTrace(); - } - return j; - } - /** - * 头像上传 目前首先相对路径 - */ - @PostMapping(value = "upload") - @ResponseBody - public JsonUtil imgUpload(HttpServletRequest req, @RequestParam("file") MultipartFile file, - ModelMap model) { - JsonUtil j = new JsonUtil(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat sdf1 = new SimpleDateFormat("hhmmss"); - - String fileName = sdf1.format(new Date()) + file.getOriginalFilename(); - String objPath = - req.getSession().getServletContext().getRealPath("image/") + sdf.format(new Date()) - .toString(); - File targetFile1 = new File(objPath, fileName); - File file2 = new File(objPath); - if (!file2.exists()) { - file2.mkdirs(); - } - if (!targetFile1.exists()) { - targetFile1.mkdirs(); + @GetMapping(value = "updateUser") + public String goUpdateUser(String id, Model model, boolean detail) { + if (StringUtils.isNotEmpty(id)) { + //用户-角色 + List checkboxList = userService.getUserRoleByJson(id); + SysUser user = userService.selectByPrimaryKey(id); + model.addAttribute("user", user); + model.addAttribute("boxJson", checkboxList); + } + model.addAttribute("detail", detail); + return "system/user/update-user"; } - try { - file.transferTo(targetFile1); - } catch (Exception e) { - j.setFlag(false); - j.setMsg("上传失败"); - e.printStackTrace(); - } - j.setMsg("image/" + sdf.format(new Date()).toString() + "/" + req.getContextPath() + fileName); - return j; - } + @ApiOperation(value = "/updateUser", httpMethod = "POST", notes = "更新用户") + @Log(desc = "更新用户", type = LOG_TYPE.UPDATE) + @PostMapping(value = "updateUser") + @ResponseBody + public JsonUtil updateUser(SysUser user, String role[]) { + JsonUtil jsonUtil = new JsonUtil(); + jsonUtil.setFlag(false); + if (user == null) { + jsonUtil.setMsg("获取数据失败"); + return jsonUtil; + } + try { + SysUser oldUser = userService.selectByPrimaryKey(user.getId()); + BeanUtil.copyNotNullBean(user, oldUser); + userService.updateByPrimaryKeySelective(oldUser); - /** - * 验证用户名是否存在 - */ - @GetMapping(value = "checkUser") - @ResponseBody - public JsonUtil checkUser(String uname, HttpServletRequest req) { - JsonUtil j = new JsonUtil(); - j.setFlag(Boolean.FALSE); - if (StringUtils.isEmpty(uname)) { - j.setMsg("获取数据失败"); - return j; + SysRoleUser sysRoleUser = new SysRoleUser(); + sysRoleUser.setUserId(oldUser.getId()); + List keyList = userService.selectByCondition(sysRoleUser); + for (SysRoleUser sysRoleUser1 : keyList) { + roleUserService.deleteByPrimaryKey(sysRoleUser1); + } + if (role != null) { + for (String r : role) { + sysRoleUser.setRoleId(r); + roleUserService.insert(sysRoleUser); + } + } + jsonUtil.setFlag(true); + jsonUtil.setMsg("修改成功"); + } catch (MyException e) { + e.printStackTrace(); + } + return jsonUtil; } - int result = userService.checkUser(uname); - if (result > 0) { - j.setMsg("用户名已存在"); - return j; - } - j.setFlag(true); - return j; - } + @Log(desc = "删除用户", type = LOG_TYPE.DEL) + @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除用户") + @PostMapping(value = "/del") + @ResponseBody + @RequiresPermissions("user:del") + public JsonUtil del(String id, boolean flag) { + return userService.delById(id, flag); + } + + @GetMapping(value = "goRePass") + public String goRePass(String id, Model model) { + if (StringUtils.isEmpty(id)) { + return "获取账户信息失败"; + } + SysUser user = userService.selectByPrimaryKey(id); + model.addAttribute("user", user); + return "/system/user/re-pass"; + } + + /** + * 修改密码 + * + * @param id + * @param pass + * @param newPwd + * @return + */ + @Log(desc = "修改密码", type = LOG_TYPE.UPDATE) + @PostMapping(value = "rePass") + @ResponseBody + @RequiresPermissions("user:repass") + public JsonUtil rePass(String id, String pass, String newPwd) { + boolean flag = StringUtils.isEmpty(id) || StringUtils.isEmpty(pass) || StringUtils.isEmpty(newPwd); + JsonUtil j = new JsonUtil(); + j.setFlag(false); + if (flag) { + j.setMsg("获取数据失败,修改失败"); + return j; + } + SysUser user = userService.selectByPrimaryKey(id); + newPwd = Md5Util.getMD5(newPwd, user.getUsername()); + pass = Md5Util.getMD5(pass, user.getUsername()); + if (!pass.equals(user.getPassword())) { + j.setMsg("密码不正确"); + return j; + } + if (newPwd.equals(user.getPassword())) { + j.setMsg("新密码不能与旧密码相同"); + + return j; + } + user.setPassword(newPwd); + try { + userService.rePass(user); + j.setMsg("修改成功"); + j.setFlag(true); + } catch (MyException e) { + e.printStackTrace(); + } + return j; + } + + /** + * 头像上传 目前首先相对路径 + */ + @PostMapping(value = "upload") + @ResponseBody + public JsonUtil imgUpload(HttpServletRequest req, @RequestParam("file") MultipartFile file, + ModelMap model) { + JsonUtil j = new JsonUtil(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdf1 = new SimpleDateFormat("hhmmss"); + + String fileName = sdf1.format(new Date()) + file.getOriginalFilename(); + String objPath = + req.getSession().getServletContext().getRealPath("image/") + sdf.format(new Date()) + .toString(); + File targetFile1 = new File(objPath, fileName); + File file2 = new File(objPath); + if (!file2.exists()) { + file2.mkdirs(); + } + if (!targetFile1.exists()) { + targetFile1.mkdirs(); + } + + try { + file.transferTo(targetFile1); + } catch (Exception e) { + j.setFlag(false); + j.setMsg("上传失败"); + e.printStackTrace(); + } + j.setMsg("image/" + sdf.format(new Date()).toString() + "/" + req.getContextPath() + fileName); + return j; + } + + /** + * 验证用户名是否存在 + */ + @GetMapping(value = "checkUser") + @ResponseBody + public JsonUtil checkUser(String uname, HttpServletRequest req) { + JsonUtil j = new JsonUtil(); + j.setFlag(Boolean.FALSE); + if (StringUtils.isEmpty(uname)) { + j.setMsg("获取数据失败"); + return j; + } + int result = userService.checkUser(uname); + if (result > 0) { + j.setMsg("用户名已存在"); + return j; + } + j.setFlag(true); + return j; + + } } diff --git a/len-sys/src/main/java/com/len/core/BootListener/DataSourceJobThread.java b/len-sys/src/main/java/com/len/core/BootListener/DataSourceJobThread.java index a733bc2..91b9f4a 100644 --- a/len-sys/src/main/java/com/len/core/BootListener/DataSourceJobThread.java +++ b/len-sys/src/main/java/com/len/core/BootListener/DataSourceJobThread.java @@ -5,7 +5,9 @@ import com.len.entity.SysJob; import com.len.service.JobService; import com.len.util.SpringUtil; import com.len.service.RoleService; + import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -15,40 +17,40 @@ import org.springframework.context.annotation.Configuration; * @author zhuxiaomeng * @date 2018/1/6. * @email 154040976@qq.com - * + *

* 启动数据库中已经设定为 启动状态(status:true)的任务 项目启动时init */ @Configuration public class DataSourceJobThread extends Thread { - private static final Logger log = LoggerFactory.getLogger(DataSourceJobThread.class); - @Autowired - RoleService roleService; + private static final Logger log = LoggerFactory.getLogger(DataSourceJobThread.class); + @Autowired + RoleService roleService; - @Autowired - JobService jobService; + @Autowired + JobService jobService; - @Override - public void run() { - try { - Thread.sleep(1000); - log.info("---------线程启动---------"); - JobTask jobTask = SpringUtil.getBean("jobTask"); - SysJob job = new SysJob(); - job.setStatus(true); - List jobList = jobService.selectListByPage(job); - //开启任务 - jobList.forEach(jobs -> { - log.info("---任务["+jobs.getId()+"]系统 init--开始启动---------"); - jobTask.startJob(jobs); - } - ); - if(jobList.size()==0){ - log.info("---数据库暂无启动的任务---------"); - }else - System.out.println("---任务启动完毕---------"); - } catch (InterruptedException e) { - e.printStackTrace(); + @Override + public void run() { + try { + Thread.sleep(1000); + log.info("---------线程启动---------"); + JobTask jobTask = SpringUtil.getBean("jobTask"); + SysJob job = new SysJob(); + job.setStatus(true); + List jobList = jobService.selectListByPage(job); + //开启任务 + jobList.forEach(jobs -> { + log.info("---任务[" + jobs.getId() + "]系统 init--开始启动---------"); + jobTask.startJob(jobs); + } + ); + if (jobList.size() == 0) { + log.info("---数据库暂无启动的任务---------"); + } else + System.out.println("---任务启动完毕---------"); + } catch (InterruptedException e) { + e.printStackTrace(); + } } - } } diff --git a/len-sys/src/main/java/com/len/core/BootListener/MyApplicationListener.java b/len-sys/src/main/java/com/len/core/BootListener/MyApplicationListener.java index 299da93..f51121a 100644 --- a/len-sys/src/main/java/com/len/core/BootListener/MyApplicationListener.java +++ b/len-sys/src/main/java/com/len/core/BootListener/MyApplicationListener.java @@ -10,26 +10,25 @@ import org.springframework.stereotype.Component; * @author zhuxiaomeng * @date 2018/1/6. * @email 154040976@qq.com - * + *

* 通过监听,开辟线程,执行定时任务 当然 也可以执行其他 */ @Component -public class MyApplicationListener implements ApplicationListener { +public class MyApplicationListener implements ApplicationListener { - Logger logger= LoggerFactory.getLogger(MyApplicationListener.class); + Logger logger = LoggerFactory.getLogger(MyApplicationListener.class); - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - logger.info("-------------bean初始化完毕-------------"); - /** - * 通过线程开启数据库中已经开启的定时任务 灵感来自spring - * spring boot继续执行 mythread开辟线程,延迟后执行 - */ - DataSourceJobThread myThread= (DataSourceJobThread) event.getApplicationContext().getBean( - "dataSourceJobThread"); - myThread.start(); - } + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + logger.info("-------------bean初始化完毕-------------"); + /** + * 通过线程开启数据库中已经开启的定时任务 灵感来自spring + * spring boot继续执行 mythread开辟线程,延迟后执行 + */ + DataSourceJobThread myThread = (DataSourceJobThread) event.getApplicationContext().getBean( + "dataSourceJobThread"); + myThread.start(); + } } diff --git a/len-sys/src/main/java/com/len/core/BootListener/MyServletContextListener.java b/len-sys/src/main/java/com/len/core/BootListener/MyServletContextListener.java index 34a24fe..8fcf5a1 100644 --- a/len-sys/src/main/java/com/len/core/BootListener/MyServletContextListener.java +++ b/len-sys/src/main/java/com/len/core/BootListener/MyServletContextListener.java @@ -2,6 +2,7 @@ package com.len.core.BootListener; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; + import org.springframework.stereotype.Component; /** @@ -12,13 +13,13 @@ import org.springframework.stereotype.Component; @Component public class MyServletContextListener implements ServletContextListener { - @Override - public void contextInitialized(ServletContextEvent sce) { - System.out.println("-------contextInitialized-----------"); - } + @Override + public void contextInitialized(ServletContextEvent sce) { + System.out.println("-------contextInitialized-----------"); + } - @Override - public void contextDestroyed(ServletContextEvent sce) { - System.out.println("------------contextDestroyed-------------"); - } + @Override + public void contextDestroyed(ServletContextEvent sce) { + System.out.println("------------contextDestroyed-------------"); + } } diff --git a/len-sys/src/main/java/com/len/core/annotation/Log.java b/len-sys/src/main/java/com/len/core/annotation/Log.java index c62a8c7..1a4af00 100644 --- a/len-sys/src/main/java/com/len/core/annotation/Log.java +++ b/len-sys/src/main/java/com/len/core/annotation/Log.java @@ -11,7 +11,7 @@ import java.lang.annotation.Target; * @author zhuxiaomeng * @date 2017/12/28. * @email 154040976@qq.com - * + *

* 记录日志 */ @Retention(RetentionPolicy.RUNTIME) @@ -19,9 +19,17 @@ import java.lang.annotation.Target; @Documented @Inherited public @interface Log { - public enum LOG_TYPE{ADD,UPDATE,DEL,SELECT,ATHOR}; - /**内容*/ + public enum LOG_TYPE {ADD, UPDATE, DEL, SELECT, ATHOR} + + ; + + /** + * 内容 + */ String desc(); - /**类型 curd*/ + + /** + * 类型 curd + */ LOG_TYPE type() default LOG_TYPE.ATHOR; } diff --git a/len-sys/src/main/java/com/len/core/annotation/LogAspect.java b/len-sys/src/main/java/com/len/core/annotation/LogAspect.java index 30c5ae2..84f3fc3 100644 --- a/len-sys/src/main/java/com/len/core/annotation/LogAspect.java +++ b/len-sys/src/main/java/com/len/core/annotation/LogAspect.java @@ -6,9 +6,11 @@ import com.len.core.shiro.ShiroUtil; import com.len.entity.SysLog; import com.len.mapper.SysLogMapper; import com.len.util.IpUtil; + import java.lang.reflect.Method; import java.util.Date; import javax.servlet.http.HttpServletRequest; + import org.apache.shiro.SecurityUtils; import org.apache.shiro.UnavailableSecurityManagerException; import org.apache.shiro.mgt.SecurityManager; @@ -29,7 +31,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; * @author zhuxiaomeng * @date 2017/12/28. * @email 154040976@qq.com - * + *

* 为增删改添加监控 */ @Aspect @@ -45,29 +47,29 @@ public class LogAspect { } @After("pointcut()") - public void insertLogSuccess(JoinPoint jp){ - addLog(jp,getDesc(jp)); + public void insertLogSuccess(JoinPoint jp) { + addLog(jp, getDesc(jp)); } - private void addLog(JoinPoint jp,String text){ - Log.LOG_TYPE type=getType(jp); - SysLog log=new SysLog(); - RequestAttributes requestAttributes=RequestContextHolder.getRequestAttributes(); + private void addLog(JoinPoint jp, String text) { + Log.LOG_TYPE type = getType(jp); + SysLog log = new SysLog(); + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); //一些系统监控 - if(requestAttributes!=null){ + if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - String ip= IpUtil.getIp(request); + String ip = IpUtil.getIp(request); log.setIp(ip); } log.setCreateTime(new Date()); log.setType(type.toString()); log.setText(text); - Object[] obj= jp.getArgs(); - StringBuffer buffer=new StringBuffer(); - if(obj!=null){ - for(int i=0;i userList=sys.selectListByPage(new SysUser()); - System.out.println(userList.get(0).getUsername());; - System.out.println("JobDemo2:执行完毕======================="); - + logger.info(userList.get(0).getUsername()); + logger.info("JobDemo2:执行完毕======================="); } } diff --git a/len-sys/src/main/java/com/len/entity/SysJob.java b/len-sys/src/main/java/com/len/entity/SysJob.java index e842637..f709750 100644 --- a/len-sys/src/main/java/com/len/entity/SysJob.java +++ b/len-sys/src/main/java/com/len/entity/SysJob.java @@ -2,6 +2,7 @@ package com.len.entity; import java.io.Serializable; import java.util.Date; + import lombok.Getter; import lombok.Setter; import lombok.ToString; diff --git a/len-sys/src/main/java/com/len/mapper/SysJobMapper.java b/len-sys/src/main/java/com/len/mapper/SysJobMapper.java index 1043e98..27f3c16 100644 --- a/len-sys/src/main/java/com/len/mapper/SysJobMapper.java +++ b/len-sys/src/main/java/com/len/mapper/SysJobMapper.java @@ -3,7 +3,7 @@ package com.len.mapper; import com.len.base.BaseMapper; import com.len.entity.SysJob; -public interface SysJobMapper extends BaseMapper { +public interface SysJobMapper extends BaseMapper { int deleteByPrimaryKey(String id); int insert(SysJob record); diff --git a/len-sys/src/main/resources/ftl/main/main.ftl b/len-sys/src/main/resources/ftl/main/main.ftl index 776c23a..848602d 100644 --- a/len-sys/src/main/resources/ftl/main/main.ftl +++ b/len-sys/src/main/resources/ftl/main/main.ftl @@ -101,7 +101,7 @@

diff --git a/len-sys/src/main/resources/ftl/system/job/add-job.ftl b/len-sys/src/main/resources/ftl/system/job/add-job.ftl index 04b1827..60175e7 100644 --- a/len-sys/src/main/resources/ftl/system/job/add-job.ftl +++ b/len-sys/src/main/resources/ftl/system/job/add-job.ftl @@ -15,8 +15,9 @@ To change this template use File | Settings | File Templates.--> - + + @@ -125,27 +126,7 @@ To change this template use File | Settings | File Templates.--> }); //监听提交 form.on('submit(add)', function(data){ - $.ajax({ - url:'addJob', - type:'post', - data:data.field, - async:false, traditional: true, - success:function(d){ - var index = parent.layer.getFrameIndex(window.name); - if(d.flag){ - parent.layer.close(index); - window.parent.layui.table.reload('jobList'); - window.top.layer.msg(d.msg,{icon:6,offset: 'rb',area:['120px','80px'],anim:2}); - }else{ - layer.msg(d.msg,{icon:5}); - } - },error:function(){ - layer.alert("请求失败", {icon: 6},function () { - var index = parent.layer.getFrameIndex(window.name); - parent.layer.close(index); - }); - } - }); + layerAjax('addJob', data.field, 'jobList'); return false; }); }); diff --git a/len-sys/src/main/resources/ftl/system/job/jobList.ftl b/len-sys/src/main/resources/ftl/system/job/jobList.ftl index 97750f1..ee6de9d 100644 --- a/len-sys/src/main/resources/ftl/system/job/jobList.ftl +++ b/len-sys/src/main/resources/ftl/system/job/jobList.ftl @@ -14,7 +14,7 @@ content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/> - + diff --git a/len-sys/src/main/resources/ftl/system/job/update-job.ftl b/len-sys/src/main/resources/ftl/system/job/update-job.ftl index cf2b991..66c124c 100644 --- a/len-sys/src/main/resources/ftl/system/job/update-job.ftl +++ b/len-sys/src/main/resources/ftl/system/job/update-job.ftl @@ -15,8 +15,9 @@ To change this template use File | Settings | File Templates.--> - + + + diff --git a/len-sys/src/main/resources/ftl/system/menu/add-menu.ftl b/len-sys/src/main/resources/ftl/system/menu/add-menu.ftl index 0181acd..537ec9a 100644 --- a/len-sys/src/main/resources/ftl/system/menu/add-menu.ftl +++ b/len-sys/src/main/resources/ftl/system/menu/add-menu.ftl @@ -14,14 +14,14 @@ To change this template use File | Settings | File Templates.--> - +
-
+
基础信息 @@ -84,15 +84,19 @@ To change this template use File | Settings | File Templates.--> autocomplete="off" class="layui-input">
-
+
- +
+
    + +
  • 选择图标
  • +
+
-
+