接口描述

This commit is contained in:
meng 2019-04-30 21:57:15 +08:00
parent 3f64677ec5
commit 50d6b813c1
12 changed files with 198 additions and 145 deletions

View File

@ -1,7 +1,6 @@
package com.len.controller; package com.len.controller;
import java.io.UnsupportedEncodingException; import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -16,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
*/ */
@Controller @Controller
@RequestMapping(value = "/error") @RequestMapping(value = "/error")
@Api(value = "异常", description = "异常业务类")
public class ErrorController { public class ErrorController {
@GetMapping(value = "404") @GetMapping(value = "404")
@ -24,7 +24,7 @@ public class ErrorController {
} }
@GetMapping(value = "403") @GetMapping(value = "403")
public String NotFound(String message, Model model) { public String notFound(String message, Model model) {
if (!StringUtils.isEmpty(message)) { if (!StringUtils.isEmpty(message)) {
model.addAttribute("message", message); model.addAttribute("message", message);
} }

View File

@ -9,6 +9,7 @@ import com.len.exception.MyException;
import com.len.service.JobService; import com.len.service.JobService;
import com.len.util.JsonUtil; import com.len.util.JsonUtil;
import com.len.util.ReType; import com.len.util.ReType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/ */
@Controller @Controller
@RequestMapping("/job") @RequestMapping("/job")
@Api(value = "定时任务",description="定时任务")
public class JobController extends BaseController<SysJob> { public class JobController extends BaseController<SysJob> {
@Autowired @Autowired

View File

@ -12,6 +12,7 @@ import com.len.util.ReType;
import java.util.List; import java.util.List;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -32,6 +33,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@RequestMapping(value = "/log") @RequestMapping(value = "/log")
@Slf4j @Slf4j
@Api(value = "日志管理",description="操作日志记录")
public class LogController extends BaseController { public class LogController extends BaseController {
@Autowired @Autowired
private SysLogMapper logMapper; private SysLogMapper logMapper;

View File

@ -6,6 +6,7 @@ import com.len.entity.SysUser;
import com.len.service.SysUserService; import com.len.service.SysUserService;
import com.len.util.CustomUsernamePasswordToken; import com.len.util.CustomUsernamePasswordToken;
import com.len.util.VerifyCodeUtils; import com.len.util.VerifyCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@ -31,6 +32,7 @@ import javax.servlet.http.HttpSession;
*/ */
@Controller @Controller
@Slf4j @Slf4j
@Api(value = "登录业务",description="登录校验处理")
public class LoginController { public class LoginController {
@Autowired @Autowired

View File

@ -5,19 +5,21 @@ import com.len.base.BaseController;
import com.len.core.annotation.Log; import com.len.core.annotation.Log;
import com.len.core.annotation.Log.LOG_TYPE; import com.len.core.annotation.Log.LOG_TYPE;
import com.len.entity.SysMenu; import com.len.entity.SysMenu;
import com.len.entity.SysRoleMenu;
import com.len.exception.MyException; import com.len.exception.MyException;
import com.len.service.MenuService; import com.len.service.MenuService;
import com.len.service.RoleMenuService;
import com.len.util.BeanUtil; import com.len.util.BeanUtil;
import com.len.util.JsonUtil; import com.len.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; 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;
/** /**
* @author zhuxiaomeng * @author zhuxiaomeng
@ -27,14 +29,12 @@ import org.springframework.web.bind.annotation.*;
*/ */
@RequestMapping("/menu") @RequestMapping("/menu")
@Controller @Controller
@Api(value = "菜单管理",description="菜单业务处理")
public class MenuController extends BaseController { public class MenuController extends BaseController {
@Autowired @Autowired
private MenuService menuService; private MenuService menuService;
@Autowired
private RoleMenuService roleMenuService;
/** /**
* 展示tree * 展示tree
* *
@ -119,36 +119,7 @@ public class MenuController extends BaseController {
@PostMapping("/menu-del") @PostMapping("/menu-del")
@ResponseBody @ResponseBody
public JsonUtil del(String id) { public JsonUtil del(String id) {
JsonUtil json = new JsonUtil(); return menuService.del(id);
json.setFlag(false);
if (StringUtils.isEmpty(id)) {
json.setMsg("获取数据失败,请刷新重试!");
return json;
}
SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setMenuId(id);
int count = roleMenuService.selectCount(sysRoleMenu);
//存在角色绑定不能删除
if (count > 0) {
json.setMsg("本菜单存在绑定角色,请先解除绑定!");
return json;
}
//存在下级菜单 不能解除
SysMenu sysMenu = new SysMenu();
sysMenu.setPId(id);
if (menuService.selectCount(sysMenu) > 0) {
json.setMsg("存在子菜单,请先删除子菜单!");
return json;
}
boolean isDel = menuService.deleteByPrimaryKey(id) > 0;
if (isDel) {
json.setMsg("删除成功");
json.setFlag(true);
} else {
json.setMsg("删除失败");
}
return json;
} }
} }

View File

@ -8,6 +8,7 @@ import com.len.service.SysUserService;
import com.len.util.BeanUtil; import com.len.util.BeanUtil;
import com.len.util.Checkbox; import com.len.util.Checkbox;
import com.len.util.JsonUtil; import com.len.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -26,6 +27,7 @@ import java.util.List;
*/ */
@Controller @Controller
@RequestMapping("/person") @RequestMapping("/person")
@Api(value = "个人业务",description="个人业务处理")
public class PersonController { public class PersonController {
@Autowired @Autowired

View File

@ -5,16 +5,12 @@ import com.len.base.BaseController;
import com.len.core.annotation.Log; import com.len.core.annotation.Log;
import com.len.core.annotation.Log.LOG_TYPE; import com.len.core.annotation.Log.LOG_TYPE;
import com.len.entity.SysRole; import com.len.entity.SysRole;
import com.len.entity.SysRoleMenu;
import com.len.entity.SysRoleUser;
import com.len.exception.MyException;
import com.len.service.MenuService; import com.len.service.MenuService;
import com.len.service.RoleMenuService; import com.len.service.RoleMenuService;
import com.len.service.RoleService; import com.len.service.RoleService;
import com.len.service.RoleUserService;
import com.len.util.BeanUtil;
import com.len.util.JsonUtil; import com.len.util.JsonUtil;
import com.len.util.ReType; import com.len.util.ReType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -26,8 +22,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/** /**
* @author zhuxiaomeng * @author zhuxiaomeng
* @date 2017/12/19. * @date 2017/12/19.
@ -36,14 +30,12 @@ import java.util.List;
*/ */
@Controller @Controller
@RequestMapping(value = "/role") @RequestMapping(value = "/role")
@Api(value = "用户角色管理",description="角色业务处理")
public class RoleController extends BaseController { public class RoleController extends BaseController {
@Autowired @Autowired
private RoleService roleService; private RoleService roleService;
@Autowired
private RoleUserService roleUserService;
@Autowired @Autowired
private MenuService menuService; private MenuService menuService;
@ -88,25 +80,7 @@ public class RoleController extends BaseController {
if (StringUtils.isEmpty(sysRole.getRoleName())) { if (StringUtils.isEmpty(sysRole.getRoleName())) {
JsonUtil.error("角色名称不能为空"); JsonUtil.error("角色名称不能为空");
} }
JsonUtil j = new JsonUtil(); return roleService.addRole(sysRole, menus);
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();
}
return j;
} }
@GetMapping(value = "updateRole") @GetMapping(value = "updateRole")
@ -126,35 +100,10 @@ public class RoleController extends BaseController {
@PostMapping(value = "updateRole") @PostMapping(value = "updateRole")
@ResponseBody @ResponseBody
public JsonUtil updateUser(SysRole role, String[] menus) { public JsonUtil updateUser(SysRole role, String[] menus) {
JsonUtil jsonUtil = new JsonUtil();
jsonUtil.setFlag(false);
if (role == null) { if (role == null) {
jsonUtil.setMsg("获取数据失败"); return JsonUtil.error("获取数据失败");
return jsonUtil;
} }
try { return roleService.updateUser(role, menus);
SysRole oldRole = roleService.selectByPrimaryKey(role.getId());
BeanUtil.copyNotNullBean(role, oldRole);
roleService.updateByPrimaryKeySelective(oldRole);
SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setRoleId(role.getId());
List<SysRoleMenu> 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 = "删除角色") @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除角色")
@ -166,22 +115,7 @@ public class RoleController extends BaseController {
if (StringUtils.isEmpty(id)) { if (StringUtils.isEmpty(id)) {
return JsonUtil.error("获取数据失败"); return JsonUtil.error("获取数据失败");
} }
SysRoleUser sysRoleUser = new SysRoleUser(); return roleService.del(id);
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;
} }
} }

View File

@ -14,6 +14,7 @@ import com.len.exception.MyException;
import com.len.service.RoleUserService; import com.len.service.RoleUserService;
import com.len.service.SysUserService; import com.len.service.SysUserService;
import com.len.util.*; import com.len.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -36,6 +37,7 @@ import java.util.List;
//@Api(value="user") //@Api(value="user")
@Controller @Controller
@RequestMapping(value = "/user") @RequestMapping(value = "/user")
@Api(value = "用户管理",description="用户管理业务")
public class UserController extends BaseController { public class UserController extends BaseController {
//private static final Logger //private static final Logger

View File

@ -3,6 +3,8 @@ package com.len.service;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.len.base.BaseService; import com.len.base.BaseService;
import com.len.entity.SysMenu; import com.len.entity.SysMenu;
import com.len.util.JsonUtil;
import java.util.List; import java.util.List;
/** /**
@ -29,4 +31,7 @@ public interface MenuService extends BaseService<SysMenu,String> {
List<SysMenu> getUserMenu(String id); List<SysMenu> getUserMenu(String id);
public JSONArray getMenuJsonByUser(List<SysMenu> menuList); public JSONArray getMenuJsonByUser(List<SysMenu> menuList);
public JsonUtil del(String id);
} }

View File

@ -2,6 +2,8 @@ package com.len.service;
import com.len.base.BaseService; import com.len.base.BaseService;
import com.len.entity.SysRole; import com.len.entity.SysRole;
import com.len.util.JsonUtil;
import java.util.List; import java.util.List;
/** /**
@ -32,4 +34,10 @@ public interface RoleService extends BaseService<SysRole,String> {
@Override @Override
List<SysRole> selectListByPage(SysRole sysRole); List<SysRole> selectListByPage(SysRole sysRole);
public JsonUtil addRole(SysRole sysRole, String[] menus);
public JsonUtil updateUser(SysRole role, String[] menus);
public JsonUtil del(String id);
} }

View File

@ -8,6 +8,8 @@ import com.len.entity.SysRoleMenu;
import com.len.mapper.SysMenuMapper; import com.len.mapper.SysMenuMapper;
import com.len.mapper.SysRoleMenuMapper; import com.len.mapper.SysRoleMenuMapper;
import com.len.service.MenuService; import com.len.service.MenuService;
import com.len.service.RoleMenuService;
import com.len.util.JsonUtil;
import com.len.util.TreeUtil; import com.len.util.TreeUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -32,6 +34,9 @@ public class MenuServiceImpl extends BaseServiceImpl<SysMenu, String> implements
@Autowired @Autowired
private SysRoleMenuMapper roleMenuMapper; private SysRoleMenuMapper roleMenuMapper;
@Autowired
private RoleMenuService roleMenuService;
@Override @Override
public BaseMapper<SysMenu, String> getMappser() { public BaseMapper<SysMenu, String> getMappser() {
return menuDao; return menuDao;
@ -108,6 +113,39 @@ public class MenuServiceImpl extends BaseServiceImpl<SysMenu, String> implements
return jsonArr; return jsonArr;
} }
@Override
public JsonUtil del(String id) {
JsonUtil json = new JsonUtil();
json.setFlag(false);
if (StringUtils.isEmpty(id)) {
json.setMsg("获取数据失败,请刷新重试!");
return json;
}
SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setMenuId(id);
int count = roleMenuService.selectCount(sysRoleMenu);
//存在角色绑定不能删除
if (count > 0) {
json.setMsg("本菜单存在绑定角色,请先解除绑定!");
return json;
}
//存在下级菜单 不能解除
SysMenu sysMenu = new SysMenu();
sysMenu.setPId(id);
if (selectCount(sysMenu) > 0) {
json.setMsg("存在子菜单,请先删除子菜单!");
return json;
}
boolean isDel = deleteByPrimaryKey(id) > 0;
if (isDel) {
json.setMsg("删除成功");
json.setFlag(true);
} else {
json.setMsg("删除失败");
}
return json;
}
public SysMenu getChilds(SysMenu menu, int pNum, int num, List<SysMenu> menuList) { public SysMenu getChilds(SysMenu menu, int pNum, int num, List<SysMenu> menuList) {
for (SysMenu menus : menuList) { for (SysMenu menus : menuList) {
if (menu.getId().equals(menus.getPId()) && menus.getMenuType() == 0) { if (menu.getId().equals(menus.getPId()) && menus.getMenuType() == 0) {

View File

@ -3,56 +3,143 @@ package com.len.service.impl;
import com.len.base.BaseMapper; import com.len.base.BaseMapper;
import com.len.base.impl.BaseServiceImpl; import com.len.base.impl.BaseServiceImpl;
import com.len.entity.SysRole; import com.len.entity.SysRole;
import com.len.entity.SysRoleMenu;
import com.len.entity.SysRoleUser;
import com.len.exception.MyException;
import com.len.mapper.SysRoleMapper; import com.len.mapper.SysRoleMapper;
import com.len.service.RoleMenuService;
import com.len.service.RoleService; import com.len.service.RoleService;
import java.util.List; import com.len.service.RoleUserService;
import com.len.util.BeanUtil;
import com.len.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @author zhuxiaomeng * @author zhuxiaomeng
* @date 2017/12/19. * @date 2017/12/19.
* @email 154040976@qq.com * @email 154040976@qq.com
*/ */
@Service @Service
public class RoleServiceImpl extends BaseServiceImpl<SysRole,String> implements RoleService { public class RoleServiceImpl extends BaseServiceImpl<SysRole, String> implements RoleService {
@Autowired @Autowired
private SysRoleMapper roleMapper; private SysRoleMapper roleMapper;
@Override @Autowired
public BaseMapper<SysRole, String> getMappser() { private RoleMenuService roleMenuService;
return roleMapper;
}
@Override @Autowired
public int deleteByPrimaryKey(String id) { private RoleUserService roleUserService;
return roleMapper.deleteByPrimaryKey(id);
}
@Override @Override
public int insert(SysRole record) { public BaseMapper<SysRole, String> getMappser() {
record=super.addValue(record,true); return roleMapper;
return roleMapper.insert(record); }
}
@Override
public SysRole selectByPrimaryKey(String id) {
return roleMapper.selectByPrimaryKey(id);
}
@Override @Override
public int updateByPrimaryKeySelective(SysRole record) { public int deleteByPrimaryKey(String id) {
return roleMapper.updateByPrimaryKeySelective(record); return roleMapper.deleteByPrimaryKey(id);
} }
@Override @Override
public int updateByPrimaryKey(SysRole record) { public int insert(SysRole record) {
return roleMapper.updateByPrimaryKey(record); record = super.addValue(record, true);
} return roleMapper.insert(record);
}
@Override @Override
public List<SysRole> selectListByPage(SysRole sysRole) { public SysRole selectByPrimaryKey(String id) {
return roleMapper.selectListByPage(sysRole); return roleMapper.selectByPrimaryKey(id);
} }
@Override
public int updateByPrimaryKeySelective(SysRole record) {
return roleMapper.updateByPrimaryKeySelective(record);
}
@Override
public int updateByPrimaryKey(SysRole record) {
return roleMapper.updateByPrimaryKey(record);
}
@Override
public List<SysRole> selectListByPage(SysRole sysRole) {
return roleMapper.selectListByPage(sysRole);
}
@Override
public JsonUtil addRole(SysRole sysRole, String[] menus) {
JsonUtil j = new JsonUtil();
try {
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();
}
return j;
}
@Override
public JsonUtil updateUser(SysRole role, String[] menus) {
JsonUtil jsonUtil = new JsonUtil();
jsonUtil.setFlag(false);
try {
SysRole oldRole = selectByPrimaryKey(role.getId());
BeanUtil.copyNotNullBean(role, oldRole);
updateByPrimaryKeySelective(oldRole);
SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setRoleId(role.getId());
List<SysRoleMenu> 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;
}
@Override
public JsonUtil del(String id) {
SysRoleUser sysRoleUser = new SysRoleUser();
sysRoleUser.setRoleId(id);
JsonUtil j = new JsonUtil();
try {
int count = roleUserService.selectCountByCondition(sysRoleUser);
if (count > 0) {
return JsonUtil.error("已分配给用户,删除失败");
}
deleteByPrimaryKey(id);
j.setMsg("删除成功");
} catch (MyException e) {
j.setMsg("删除失败");
j.setFlag(false);
e.printStackTrace();
}
return j;
}
} }