接口描述

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

View File

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

View File

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

View File

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

View File

@ -5,19 +5,21 @@ 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.entity.SysRoleMenu;
import com.len.exception.MyException;
import com.len.service.MenuService;
import com.len.service.RoleMenuService;
import com.len.util.BeanUtil;
import com.len.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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
@ -27,14 +29,12 @@ import org.springframework.web.bind.annotation.*;
*/
@RequestMapping("/menu")
@Controller
@Api(value = "菜单管理",description="菜单业务处理")
public class MenuController extends BaseController {
@Autowired
private MenuService menuService;
@Autowired
private RoleMenuService roleMenuService;
/**
* 展示tree
*
@ -119,36 +119,7 @@ public class MenuController extends BaseController {
@PostMapping("/menu-del")
@ResponseBody
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 (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;
return menuService.del(id);
}
}

View File

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

View File

@ -5,16 +5,12 @@ import com.len.base.BaseController;
import com.len.core.annotation.Log;
import com.len.core.annotation.Log.LOG_TYPE;
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.RoleMenuService;
import com.len.service.RoleService;
import com.len.service.RoleUserService;
import com.len.util.BeanUtil;
import com.len.util.JsonUtil;
import com.len.util.ReType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
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.ResponseBody;
import java.util.List;
/**
* @author zhuxiaomeng
* @date 2017/12/19.
@ -36,14 +30,12 @@ import java.util.List;
*/
@Controller
@RequestMapping(value = "/role")
@Api(value = "用户角色管理",description="角色业务处理")
public class RoleController extends BaseController {
@Autowired
private RoleService roleService;
@Autowired
private RoleUserService roleUserService;
@Autowired
private MenuService menuService;
@ -88,25 +80,7 @@ public class RoleController extends BaseController {
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());
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 roleService.addRole(sysRole, menus);
}
@GetMapping(value = "updateRole")
@ -126,35 +100,10 @@ public class RoleController extends BaseController {
@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;
return JsonUtil.error("获取数据失败");
}
try {
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;
return roleService.updateUser(role, menus);
}
@ApiOperation(value = "/del", httpMethod = "POST", notes = "删除角色")
@ -166,22 +115,7 @@ public class RoleController extends BaseController {
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 roleService.del(id);
}
}

View File

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

View File

@ -3,6 +3,8 @@ package com.len.service;
import com.alibaba.fastjson.JSONArray;
import com.len.base.BaseService;
import com.len.entity.SysMenu;
import com.len.util.JsonUtil;
import java.util.List;
/**
@ -29,4 +31,7 @@ public interface MenuService extends BaseService<SysMenu,String> {
List<SysMenu> getUserMenu(String id);
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.entity.SysRole;
import com.len.util.JsonUtil;
import java.util.List;
/**
@ -32,4 +34,10 @@ public interface RoleService extends BaseService<SysRole,String> {
@Override
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.SysRoleMenuMapper;
import com.len.service.MenuService;
import com.len.service.RoleMenuService;
import com.len.util.JsonUtil;
import com.len.util.TreeUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -32,6 +34,9 @@ public class MenuServiceImpl extends BaseServiceImpl<SysMenu, String> implements
@Autowired
private SysRoleMenuMapper roleMenuMapper;
@Autowired
private RoleMenuService roleMenuService;
@Override
public BaseMapper<SysMenu, String> getMappser() {
return menuDao;
@ -108,6 +113,39 @@ public class MenuServiceImpl extends BaseServiceImpl<SysMenu, String> implements
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) {
for (SysMenu menus : menuList) {
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.impl.BaseServiceImpl;
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.service.RoleMenuService;
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.stereotype.Service;
import java.util.List;
/**
* @author zhuxiaomeng
* @date 2017/12/19.
* @email 154040976@qq.com
*/
@Service
public class RoleServiceImpl extends BaseServiceImpl<SysRole,String> implements RoleService {
public class RoleServiceImpl extends BaseServiceImpl<SysRole, String> implements RoleService {
@Autowired
private SysRoleMapper roleMapper;
@Autowired
private SysRoleMapper roleMapper;
@Override
public BaseMapper<SysRole, String> getMappser() {
return roleMapper;
}
@Autowired
private RoleMenuService roleMenuService;
@Override
public int deleteByPrimaryKey(String id) {
return roleMapper.deleteByPrimaryKey(id);
}
@Autowired
private RoleUserService roleUserService;
@Override
public int insert(SysRole record) {
record=super.addValue(record,true);
return roleMapper.insert(record);
}
@Override
public SysRole selectByPrimaryKey(String id) {
return roleMapper.selectByPrimaryKey(id);
}
@Override
public BaseMapper<SysRole, String> getMappser() {
return roleMapper;
}
@Override
public int updateByPrimaryKeySelective(SysRole record) {
return roleMapper.updateByPrimaryKeySelective(record);
}
@Override
public int deleteByPrimaryKey(String id) {
return roleMapper.deleteByPrimaryKey(id);
}
@Override
public int updateByPrimaryKey(SysRole record) {
return roleMapper.updateByPrimaryKey(record);
}
@Override
public int insert(SysRole record) {
record = super.addValue(record, true);
return roleMapper.insert(record);
}
@Override
public List<SysRole> selectListByPage(SysRole sysRole) {
return roleMapper.selectListByPage(sysRole);
}
@Override
public SysRole selectByPrimaryKey(String id) {
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;
}
}