Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into dev
	
		
		1 files added
	
		
		37 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Group; | 
|---|
|  |  |  | import com.moral.api.service.GroupService; | 
|---|
|  |  |  | import com.moral.api.service.UserGroupService; | 
|---|
|  |  |  | import com.moral.api.utils.OperationLogUtils; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.PageResult; | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "insert", method = RequestMethod.POST) | 
|---|
|  |  |  | private ResultMessage insert(@RequestBody Group group, HttpServletRequest request) { | 
|---|
|  |  |  | private ResultMessage insert(@RequestBody Group group) { | 
|---|
|  |  |  | if (group.getGroupName().isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> result = groupService.addGroup(group, token); | 
|---|
|  |  |  | Map<String, Object> result = groupService.addGroup(group); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "添加了组:" + group.getGroupName(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "delete", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage delete(@RequestBody Group group, HttpServletRequest request) { | 
|---|
|  |  |  | public ResultMessage delete(@RequestBody Group group) { | 
|---|
|  |  |  | if (group.getId() == null) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | groupService.deleteGroup(group); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "删除了组:" + group.getGroupName(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "update", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage update(@RequestBody Group group, HttpServletRequest request) { | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> result = groupService.updateGroup(group, token); | 
|---|
|  |  |  | Map<String, Object> result = groupService.updateGroup(group); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "修改了组:" + group.getGroupName(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupName", value = "组名模糊查询", required = false, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "select", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage select(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { | 
|---|
|  |  |  | parameters.put("token", request.getHeader("token")); | 
|---|
|  |  |  | public ResultMessage select(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | Page<Group> userPage = groupService.selectGroups(parameters); | 
|---|
|  |  |  | PageResult<Group> pageResult = new PageResult<>( | 
|---|
|  |  |  | userPage.getTotal(), userPage.getPages(), userPage.getRecords() | 
|---|
|  |  |  | 
|---|
|  |  |  | return ResultMessage.ok(pageResult); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取用户所属组", notes = "获取用户所属组") | 
|---|
|  |  |  | @ApiOperation(value = "获取用户所属组ids", notes = "获取用户所属组ids") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "allot", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage allot(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { | 
|---|
|  |  |  | public ResultMessage allot(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | if (!parameters.containsKey("userId")) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | userGroupService.allotGroups(parameters, token); | 
|---|
|  |  |  | userGroupService.allotGroups(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| New file | 
|  |  |  | 
|---|
|  |  |  | package com.moral.api.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParam; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParams; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.UserLog; | 
|---|
|  |  |  | import com.moral.api.service.UserLogService; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.PageResult; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/log") | 
|---|
|  |  |  | @Api(tags = "日志") | 
|---|
|  |  |  | public class LogController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserLogService userLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "分页查询日志", notes = "分页查询日志") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "Integer"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "Integer"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "type", value = "操作类型,0:登陆,1:添加,2:修改,3:删除", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "select", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage select(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | Page<UserLog> userLogPage = userLogService.selectLogs(parameters); | 
|---|
|  |  |  | PageResult pageResult = new PageResult<>( | 
|---|
|  |  |  | userLogPage.getTotal(), userLogPage.getPages(), userLogPage.getRecords() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return ResultMessage.ok(pageResult); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.SysConfig; | 
|---|
|  |  |  | import com.moral.api.entity.UserLog; | 
|---|
|  |  |  | import com.moral.api.service.SysConfigService; | 
|---|
|  |  |  | import com.moral.api.service.UserLogService; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.pojo.VerificationCode; | 
|---|
|  |  |  | import com.moral.util.KaptchaUtils; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"登陆"}) | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysConfigService sysConfigService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserLogService userLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "登陆", notes = "登陆") | 
|---|
|  |  |  | @RequestMapping(value = "login", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage login(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { | 
|---|
|  |  |  | public ResultMessage login(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), (String) result.get("msg")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String, Object> data = (Map<String, Object>) result.get("data"); | 
|---|
|  |  |  | Map<String, Object> userInfo = (Map<String, Object>) data.get("user"); | 
|---|
|  |  |  | UserLog userLog = new UserLog(); | 
|---|
|  |  |  | String ip = WebUtils.getIpAddr(request); | 
|---|
|  |  |  | userLog.setIp(ip); | 
|---|
|  |  |  | userLog.setOperateId((Integer) userInfo.get("userId")); | 
|---|
|  |  |  | Map<String, Object> organization = (Map<String, Object>) userInfo.get("organization"); | 
|---|
|  |  |  | userLog.setOrganizationId((Integer) organization.get("id")); | 
|---|
|  |  |  | userLog.setContent(userInfo.get("account") + "登陆了"); | 
|---|
|  |  |  | userLogService.save(userLog); | 
|---|
|  |  |  | return ResultMessage.ok(data); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Menu; | 
|---|
|  |  |  | import com.moral.api.service.GroupMenuService; | 
|---|
|  |  |  | import com.moral.api.service.MenuService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "allot", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage allot(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { | 
|---|
|  |  |  | public ResultMessage allot(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | if (!parameters.containsKey("groupId")) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | groupMenuService.allotMenus(parameters, token); | 
|---|
|  |  |  | groupMenuService.allotMenus(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询组织层级菜单", notes = "查询组织层级菜单") | 
|---|
|  |  |  | @ApiOperation(value = "菜单列表", notes = "菜单列表") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "menu-list", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage selectMenus(HttpServletRequest request) { | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | List<Menu> menus = menuService.getMenuList((Integer) orgInfo.get("id")); | 
|---|
|  |  |  | return ResultMessage.ok(menus); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "层级菜单", notes = "层级菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | 
|---|
|  |  |  | public ResultMessage select(HttpServletRequest request) { | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> result = menuService.selectMenusByOrgId((Integer) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | Map<String, Object> result = menuService.selectMenusByOrgId((Integer) orgInfo.get("id")); | 
|---|
|  |  |  | return ResultMessage.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取组菜单ids", notes = "获取组菜单ids") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "get-menu-ids", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getMenuIds(Integer groupId) { | 
|---|
|  |  |  | List<Integer> menusIds = groupMenuService.getMenusIds(groupId); | 
|---|
|  |  |  | return ResultMessage.ok(menusIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | import com.moral.api.utils.OperationLogUtils; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.PageResult; | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "addUser", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage addUser(@RequestBody User user, HttpServletRequest request) { | 
|---|
|  |  |  | @RequestMapping(value = "insert", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage insert(@RequestBody User user) { | 
|---|
|  |  |  | if (user.getAccount().isEmpty() || user.getPassword().isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> result = userService.addUser(user, token); | 
|---|
|  |  |  | Map<String, Object> result = userService.addUser(user); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "添加了账户:" + user.getAccount(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "deleteUser", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage deleteUser(@RequestBody User user, HttpServletRequest request) { | 
|---|
|  |  |  | @RequestMapping(value = "delete", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage delete(@RequestBody User user) { | 
|---|
|  |  |  | if (user.getId() == null) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | 
|---|
|  |  |  | ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userService.deleteUser(user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "删除了账户:" + user.getAccount(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "updateUser", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage updateUser(@RequestBody User user, HttpServletRequest request) { | 
|---|
|  |  |  | @RequestMapping(value = "update", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage update(@RequestBody User user) { | 
|---|
|  |  |  | if (user.getId() == null) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> result = userService.updateUser(user, token); | 
|---|
|  |  |  | Map<String, Object> result = userService.updateUser(user); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "修改了账户:" + user.getAccount(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "Integer"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "Integer"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", defaultValue = "0", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "account", value = "账号模糊查询", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "userName", value = "用户名模糊查询", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "wechat", value = "微信模糊查询", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "selectUsers", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage selectUsers(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { | 
|---|
|  |  |  | parameters.put("token", request.getHeader("token")); | 
|---|
|  |  |  | @RequestMapping(value = "select", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage select(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | Page<User> userPage = userService.selectUsers(parameters); | 
|---|
|  |  |  | PageResult<User> pageResult = new PageResult<>( | 
|---|
|  |  |  | userPage.getTotal(), userPage.getPages(), userPage.getRecords() | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableName; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  | import com.fasterxml.jackson.annotation.JsonFormat; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 创建时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | 
|---|
|  |  |  | private Date createTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 更新时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | 
|---|
|  |  |  | private Date updateTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import lombok.Data; | 
|---|
|  |  |  | import lombok.EqualsAndHashCode; | 
|---|
|  |  |  | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | * @since 2021-04-13 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | @EqualsAndHashCode(callSuper = false) | 
|---|
|  |  |  | 
|---|
|  |  |  | private Integer id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作人员id | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer accountId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作人员账号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String account; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作人员 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String userName; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作类型 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String type; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作描述 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String content; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 组织Id | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer organizationId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作人员id | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer operateId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Ip地址 | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Date createTime; | 
|---|
|  |  |  | private LocalDateTime createTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.entity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableField; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  | import com.fasterxml.jackson.annotation.JsonFormat; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 菜单名 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @TableField(value = "`name`") | 
|---|
|  |  |  | private String name; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 同一级别菜单的顺序 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @TableField(value = "`order`") | 
|---|
|  |  |  | private Integer order; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 创建时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | 
|---|
|  |  |  | private Date createTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 更新时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | 
|---|
|  |  |  | private Date updateTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  | import com.fasterxml.jackson.annotation.JsonFormat; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | * @since 2021-04-13 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | @EqualsAndHashCode(callSuper = false) | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @TableId(value = "id", type = IdType.AUTO) | 
|---|
|  |  |  | private Integer id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作类型 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String type; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作描述 | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 操作时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") | 
|---|
|  |  |  | private Date createTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | * @since 2021-04-13 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface ManageLogMapper extends BaseMapper<ManageLog> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.GroupMenu; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface GroupMenuService extends IService<GroupMenu> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void allotMenus(Map<String, Object> parameters, String token); | 
|---|
|  |  |  | void allotMenus(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> getMenusIds(Integer groupId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface GroupService extends IService<Group> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> addGroup(Group group, String token); | 
|---|
|  |  |  | Map<String, Object> addGroup(Group group); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void deleteGroup(Group group); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> updateGroup(Group group, String token); | 
|---|
|  |  |  | Map<String, Object> updateGroup(Group group); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Page<Group> selectGroups(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | * @since 2021-04-13 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface ManageLogService extends IService<ManageLog> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Menu; | 
|---|
|  |  |  | 
|---|
|  |  |  | public interface MenuService extends IService<Menu> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String,Object> selectMenusByOrgId(Integer orgId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Menu> getMenuList(Integer orgId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface UserGroupService extends IService<UserGroup> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void allotGroups(Map<String, Object> parameters, String token); | 
|---|
|  |  |  | void allotGroups(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> getGroupIds(Integer userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.UserLog; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface UserLogService extends IService<UserLog> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Page<UserLog> selectLogs(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> getMenus(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> addUser(User user, String token); | 
|---|
|  |  |  | Map<String, Object> addUser(User user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void deleteUser(User user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> updateUser(User user, String token); | 
|---|
|  |  |  | Map<String, Object> updateUser(User user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Page<User> selectUsers(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.GroupMenu; | 
|---|
|  |  |  | import com.moral.api.mapper.GroupMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.GroupMenuMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.MenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.GroupMenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.utils.OperationLogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupMenuMapper groupMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupMapper groupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MenuMapper menuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void allotMenus(Map<String, Object> parameters, String token) { | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void allotMenus(Map<String, Object> parameters) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer groupId = Integer.parseInt(parameters.get("groupId").toString()); | 
|---|
|  |  |  | List<Integer> menuIds = (ArrayList) parameters.get("menuIds"); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | UpdateWrapper<GroupMenu> deleteWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteWrapper.set("is_delete", Constants.DELETE) | 
|---|
|  |  |  | .eq("group_id", groupId) | 
|---|
|  |  |  | .eq("channel", Constants.WEB_CHANNEL); | 
|---|
|  |  |  | groupMenuMapper.update(null, deleteWrapper); | 
|---|
|  |  |  | if (!menuIds.isEmpty()) { | 
|---|
|  |  |  | for (Integer menuId : menuIds) { | 
|---|
|  |  |  | deleteWrapper.eq("group_id", groupId).eq("channel", Constants.WEB_CHANNEL); | 
|---|
|  |  |  | groupMenuMapper.delete(deleteWrapper); | 
|---|
|  |  |  | List<String> menus = new ArrayList<>(); | 
|---|
|  |  |  | if (menuIds != null && !menuIds.isEmpty()) { | 
|---|
|  |  |  | menuIds.forEach(menuId -> { | 
|---|
|  |  |  | menus.add(menuMapper.selectById(menuId).getName()); | 
|---|
|  |  |  | GroupMenu groupMenu = new GroupMenu(); | 
|---|
|  |  |  | groupMenu.setGroupId(groupId); | 
|---|
|  |  |  | groupMenu.setMenuId(menuId); | 
|---|
|  |  |  | groupMenu.setChannel(Constants.WEB_CHANNEL); | 
|---|
|  |  |  | groupMenu.setOrganizationId((Integer) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | groupMenu.setOrganizationId((Integer) orgInfo.get("id")); | 
|---|
|  |  |  | groupMenuMapper.insert(groupMenu); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String groupName = groupMapper.selectById((Integer) parameters.get("groupId")).getGroupName(); | 
|---|
|  |  |  | String content = "给组:" + groupName + "分配了菜单:" + menus.toString(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Integer> getMenusIds(Integer groupId) { | 
|---|
|  |  |  | QueryWrapper<GroupMenu> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("group_id", groupId).eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | List<GroupMenu> groupMenus = groupMenuMapper.selectList(queryWrapper); | 
|---|
|  |  |  | List<Integer> menuIds = new ArrayList<>(); | 
|---|
|  |  |  | groupMenus.forEach(groupMenu -> menuIds.add(groupMenu.getMenuId())); | 
|---|
|  |  |  | return menuIds; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.mapper.UserGroupMapper; | 
|---|
|  |  |  | import com.moral.api.service.GroupService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.utils.OperationLogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.util.ConvertUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | private UserGroupMapper userGroupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> addGroup(Group group, String token) { | 
|---|
|  |  |  | public Map<String, Object> addGroup(Group group) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<>(); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Integer orgId = (int) currentUserInfo.get("organizationId"); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | Integer orgId = (Integer) orgInfo.get("id"); | 
|---|
|  |  |  | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("group_name", group.getGroupName()) | 
|---|
|  |  |  | .eq("organization_id", orgId) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | group.setOrganizationId(orgId); | 
|---|
|  |  |  | groupMapper.insert(group); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "添加了组:" + group.getGroupName(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.INSERT_OPERATE_TYPE); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //逻辑删除group | 
|---|
|  |  |  | group.setIsDelete(Constants.DELETE); | 
|---|
|  |  |  | groupMapper.updateById(group); | 
|---|
|  |  |  | //逻辑删除group_menu | 
|---|
|  |  |  | //删除group_menu | 
|---|
|  |  |  | UpdateWrapper<GroupMenu> deleteGroupWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteGroupWrapper.set("is_delete", Constants.DELETE).eq("group_id", group.getId()); | 
|---|
|  |  |  | groupMenuMapper.update(null, deleteGroupWrapper); | 
|---|
|  |  |  | //逻辑删除user_group | 
|---|
|  |  |  | deleteGroupWrapper.eq("group_id", group.getId()); | 
|---|
|  |  |  | groupMenuMapper.delete(deleteGroupWrapper); | 
|---|
|  |  |  | //删除user_group | 
|---|
|  |  |  | UpdateWrapper<UserGroup> deleteUserGroupWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteUserGroupWrapper.set("is_delete", Constants.DELETE).eq("group_id", group.getId()); | 
|---|
|  |  |  | userGroupMapper.update(null, deleteUserGroupWrapper); | 
|---|
|  |  |  | deleteUserGroupWrapper.eq("group_id", group.getId()); | 
|---|
|  |  |  | userGroupMapper.delete(deleteUserGroupWrapper); | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String content = "删除了组:" + group.getGroupName(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.DELETE_OPERATE_TYPE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> updateGroup(Group group, String token) { | 
|---|
|  |  |  | public Map<String, Object> updateGroup(Group group) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String before = groupMapper.selectById(group.getId()).getGroupName(); | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<>(); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Object organizationId = currentUserInfo.get("organizationId"); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | Integer orgId = (Integer) orgInfo.get("id"); | 
|---|
|  |  |  | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.ne("id", group.getId()) | 
|---|
|  |  |  | .eq("group_name", group.getGroupName()) | 
|---|
|  |  |  | .eq("is_delete", Constants.NOT_DELETE) | 
|---|
|  |  |  | .eq("organization_id", organizationId); | 
|---|
|  |  |  | .eq("organization_id", orgId); | 
|---|
|  |  |  | if (groupMapper.selectOne(queryWrapper) != null) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.GROUP_EXIST.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.GROUP_EXIST.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | group.setOrganizationId((int) organizationId); | 
|---|
|  |  |  | group.setOrganizationId(orgId); | 
|---|
|  |  |  | groupMapper.updateById(group); | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "修改了组:" + before + "=>" + group.getGroupName(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Page<Group> selectGroups(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(parameters.get("token").toString()); | 
|---|
|  |  |  | Object organizationId = currentUserInfo.get("organizationId"); | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | Integer orgId = (Integer) orgInfo.get("id"); | 
|---|
|  |  |  | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("organization_id", organizationId) | 
|---|
|  |  |  | queryWrapper.eq("organization_id", orgId) | 
|---|
|  |  |  | .eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | Object order = parameters.get("order"); | 
|---|
|  |  |  | Object orderType = parameters.get("orderType"); | 
|---|
|  |  |  | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | * @since 2021-04-13 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class ManageLogServiceImpl extends ServiceImpl<ManageLogMapper, ManageLog> implements ManageLogService { | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Menu; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MenuMapper menuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> selectMenusByOrgId(Integer orgId) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("orgId",orgId); | 
|---|
|  |  |  | return userService.getMenus(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Menu> getMenuList(Integer orgId) { | 
|---|
|  |  |  | return menuMapper.selectOrganizationMenu(orgId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.UserGroup; | 
|---|
|  |  |  | import com.moral.api.mapper.GroupMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserGroupMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserMapper; | 
|---|
|  |  |  | import com.moral.api.service.UserGroupService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.utils.OperationLogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserGroupMapper userGroupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserMapper userMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupMapper groupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void allotGroups(Map<String, Object> parameters, String token) { | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void allotGroups(Map<String, Object> parameters) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer userId = Integer.parseInt(parameters.get("userId").toString()); | 
|---|
|  |  |  | List<Integer> groupIds = (ArrayList) parameters.get("groupIds"); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | UpdateWrapper<UserGroup> deleteWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteWrapper.set("is_delete", Constants.DELETE).eq("user_id", userId); | 
|---|
|  |  |  | userGroupMapper.update(null, deleteWrapper); | 
|---|
|  |  |  | if (!groupIds.isEmpty()) { | 
|---|
|  |  |  | for (Integer groupId : groupIds) { | 
|---|
|  |  |  | deleteWrapper.eq("user_id", userId); | 
|---|
|  |  |  | userGroupMapper.delete(deleteWrapper); | 
|---|
|  |  |  | List<String> groups = new ArrayList<>(); | 
|---|
|  |  |  | if (groupIds != null && !groupIds.isEmpty()) { | 
|---|
|  |  |  | groupIds.forEach(groupId -> { | 
|---|
|  |  |  | groups.add(groupMapper.selectById(groupId).getGroupName()); | 
|---|
|  |  |  | UserGroup userGroup = new UserGroup(); | 
|---|
|  |  |  | userGroup.setUserId(userId); | 
|---|
|  |  |  | userGroup.setGroupId(groupId); | 
|---|
|  |  |  | userGroup.setOrganizationId((Integer) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | userGroup.setOrganizationId((Integer) orgInfo.get("id")); | 
|---|
|  |  |  | userGroupMapper.insert(userGroup); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String account = userMapper.selectById((Integer) parameters.get("userId")).getAccount(); | 
|---|
|  |  |  | String content = "给用户:" + account + "分配了组:" + groups.toString(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.eq("user_id", userId).eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | List<UserGroup> userGroups = userGroupMapper.selectList(queryWrapper); | 
|---|
|  |  |  | List<Integer> groupIds = new ArrayList<>(); | 
|---|
|  |  |  | for (UserGroup userGroup : userGroups) { | 
|---|
|  |  |  | groupIds.add(userGroup.getGroupId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userGroups.forEach(userGroup -> groupIds.add(userGroup.getGroupId())); | 
|---|
|  |  |  | return groupIds; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.UserLog; | 
|---|
|  |  |  | import com.moral.api.mapper.UserLogMapper; | 
|---|
|  |  |  | import com.moral.api.service.UserLogService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class UserLogServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements UserLogService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserLogMapper userLogMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Page<UserLog> selectLogs(Map<String, Object> parameters) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | Object orgId = orgInfo.get("id"); | 
|---|
|  |  |  | QueryWrapper<UserLog> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("organization_id", orgId); | 
|---|
|  |  |  | Object type = parameters.get("type"); | 
|---|
|  |  |  | if (type != null) { | 
|---|
|  |  |  | queryWrapper.eq("type", type); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.orderByDesc("create_time"); | 
|---|
|  |  |  | Integer page = (Integer) parameters.get("page"); | 
|---|
|  |  |  | Integer size = (Integer) parameters.get("size"); | 
|---|
|  |  |  | Page<UserLog> userLogPage = new Page<>(page, size); | 
|---|
|  |  |  | userLogMapper.selectPage(userLogPage, queryWrapper); | 
|---|
|  |  |  | return userLogPage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Comparator; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Organization; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  | import com.moral.api.entity.UserGroup; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.UserLog; | 
|---|
|  |  |  | import com.moral.api.mapper.MenuMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserGroupMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserLogMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserMapper; | 
|---|
|  |  |  | import com.moral.api.pojo.bo.UserBO; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | import com.moral.api.utils.OperationLogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.util.AESUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.util.MD5Utils; | 
|---|
|  |  |  | import com.moral.util.RegexUtils; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserGroupMapper userGroupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserLogMapper userLogMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${AES.KEY}") | 
|---|
|  |  |  | private String AESKey; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public UserBO selectUserInfo(Map<String, Object> parameters) { | 
|---|
|  |  |  | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | UserLog userLog = new UserLog(); | 
|---|
|  |  |  | userLog.setType(Constants.LOGIN_OPERTATE_TYPE); | 
|---|
|  |  |  | userLog.setIp(WebUtils.getIpAddr(request)); | 
|---|
|  |  |  | userLog.setOperateId(userBo.getId()); | 
|---|
|  |  |  | userLog.setOrganizationId(userBo.getOrganizationId()); | 
|---|
|  |  |  | userLog.setContent("登陆了用户:" + userBo.getAccount()); | 
|---|
|  |  |  | userLogMapper.insert(userLog); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> addUser(User user, String token) { | 
|---|
|  |  |  | public Map<String, Object> addUser(User user) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<>(); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | user.setExpireTime(userExpireTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (orgExpireTime != null) { | 
|---|
|  |  |  | user.setExpireTime(orgExpireTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userMapper.insert(user); | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | String content = "添加了用户:" + user.getAccount(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.INSERT_OPERATE_TYPE); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //逻辑删除user | 
|---|
|  |  |  | user.setIsDelete(Constants.DELETE); | 
|---|
|  |  |  | userMapper.updateById(user); | 
|---|
|  |  |  | //逻辑删除user_group | 
|---|
|  |  |  | //删除user_group | 
|---|
|  |  |  | UpdateWrapper<UserGroup> deleteWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteWrapper.set("is_delete", Constants.DELETE).eq("user_id", userId); | 
|---|
|  |  |  | deleteWrapper.eq("user_id", userId); | 
|---|
|  |  |  | userGroupMapper.delete(deleteWrapper); | 
|---|
|  |  |  | //更新redis | 
|---|
|  |  |  | if (TokenUtils.hHasKey(userId)) { | 
|---|
|  |  |  | String token = TokenUtils.hget(userId).toString(); | 
|---|
|  |  |  | TokenUtils.destoryToken(userId, token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userGroupMapper.update(null, deleteWrapper); | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String content = "删除了用户:" + user.getAccount(); | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content, Constants.DELETE_OPERATE_TYPE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> updateUser(User user, String token) { | 
|---|
|  |  |  | public Map<String, Object> updateUser(User user) { | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新的属性 | 
|---|
|  |  |  | Map<String, Object> update = JSONObject.parseObject(JSON.toJSONString(user), Map.class); | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<>(); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | String account = userMapper.selectById(user.getId()).getAccount(); | 
|---|
|  |  |  | User beforeUser = userMapper.selectById(user.getId()); | 
|---|
|  |  |  | Map<String, Object> before = JSONObject.parseObject(JSON.toJSONString(beforeUser), Map.class); | 
|---|
|  |  |  | String account = beforeUser.getAccount(); | 
|---|
|  |  |  | //account不可修改 | 
|---|
|  |  |  | user.setAccount(account); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //密码校验 | 
|---|
|  |  |  | String password = user.getPassword(); | 
|---|
|  |  |  | if (password != null) { | 
|---|
|  |  |  | //密码解密 | 
|---|
|  |  |  | password = AESUtils.decrypt(password, AESKey); | 
|---|
|  |  |  | if (!RegexUtils.checkPassword(password)) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //正则校验手机号 | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | user.setExpireTime(userExpireTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (orgExpireTime != null) { | 
|---|
|  |  |  | user.setExpireTime(orgExpireTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新redis | 
|---|
|  |  |  | String userId = user.getId().toString(); | 
|---|
|  |  |  | 
|---|
|  |  |  | TokenUtils.destoryToken(userId, deleteToken); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userMapper.updateById(user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日志 | 
|---|
|  |  |  | StringBuilder content = new StringBuilder("修改了用户:" + user.getAccount() + "->"); | 
|---|
|  |  |  | for (String key : update.keySet()) { | 
|---|
|  |  |  | Object afterValue = update.get(key); | 
|---|
|  |  |  | if (!key.equals("id") && afterValue != null) { | 
|---|
|  |  |  | //修改前属性值 | 
|---|
|  |  |  | Object beforeValue = before.get(key); | 
|---|
|  |  |  | content.append(key).append(":").append(beforeValue).append("=>").append(afterValue).append(";"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OperationLogUtils.insertLog(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Page<User> selectUsers(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(parameters.get("token").toString()); | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("organization_id", orgInfo.get("id")) | 
|---|
|  |  |  | 
|---|
|  |  |  | queryWrapper.orderByDesc("create_time"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userMapper.selectPage(pageData, queryWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return pageData; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | this.userLogService = userLogService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void insertLog(HttpServletRequest request, String content) { | 
|---|
|  |  |  | public static void insertLog(HttpServletRequest request, String content, String type) { | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  | UserLog userLog = new UserLog(); | 
|---|
|  |  |  | userLog.setType(type); | 
|---|
|  |  |  | userLog.setIp(WebUtils.getIpAddr(request)); | 
|---|
|  |  |  | userLog.setOperateId((Integer) currentUserInfo.get("userId")); | 
|---|
|  |  |  | Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
|---|
|  |  |  | 
|---|
|  |  |  | <!-- 通用查询映射结果 --> | 
|---|
|  |  |  | <resultMap id="BaseResultMap" type="com.moral.api.entity.ManageLog"> | 
|---|
|  |  |  | <id column="id" property="id" /> | 
|---|
|  |  |  | <result column="account_id" property="accountId" /> | 
|---|
|  |  |  | <result column="account" property="account" /> | 
|---|
|  |  |  | <result column="user_name" property="userName" /> | 
|---|
|  |  |  | <result column="type" property="type" /> | 
|---|
|  |  |  | <result column="content" property="content" /> | 
|---|
|  |  |  | <result column="organization_id" property="organizationId" /> | 
|---|
|  |  |  | <result column="operate_id" property="operateId" /> | 
|---|
|  |  |  | <result column="ip" property="ip" /> | 
|---|
|  |  |  | <result column="create_time" property="createTime" /> | 
|---|
|  |  |  | </resultMap> | 
|---|
|  |  |  | 
|---|
|  |  |  | <result column="is_delete" property="isDelete"/> | 
|---|
|  |  |  | </resultMap> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <resultMap id="MenuResultMap" type="com.moral.api.entity.Menu"> | 
|---|
|  |  |  | <id column="id" property="id"/> | 
|---|
|  |  |  | <result column="name" property="name"/> | 
|---|
|  |  |  | <result column="url" property="url"/> | 
|---|
|  |  |  | <result column="icon" property="icon"/> | 
|---|
|  |  |  | <result column="parent_id" property="parentId"/> | 
|---|
|  |  |  | <result column="order" property="order" jdbcType="INTEGER"/> | 
|---|
|  |  |  | </resultMap> | 
|---|
|  |  |  | <sql id="Base_Column_List"> | 
|---|
|  |  |  | m.id, m.name, m.url, m.icon, m.parent_id, m.order, m.create_time, m.update_time | 
|---|
|  |  |  | </sql> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="selectUserMenu" resultMap="MenuResultMap"> | 
|---|
|  |  |  | SELECT DISTINCT m.id,m.name,m.url,m.icon,m.parent_id,m.order | 
|---|
|  |  |  | <select id="selectUserMenu" resultMap="BaseResultMap"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | FROM `user_group` ug,`group_menu` gm,`menu` m | 
|---|
|  |  |  | WHERE ug.user_id = #{userId} | 
|---|
|  |  |  | AND ug.group_id = gm.group_id | 
|---|
|  |  |  | 
|---|
|  |  |  | AND gm.is_delete = 0 | 
|---|
|  |  |  | AND gm.channel = 1 | 
|---|
|  |  |  | AND m.is_delete = 0 | 
|---|
|  |  |  | ORDER  by m.`order` | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="selectOrganizationMenu" resultMap="MenuResultMap"> | 
|---|
|  |  |  | SELECT m.id,m.name,m.url,m.icon,m.parent_id,m.order | 
|---|
|  |  |  | <select id="selectOrganizationMenu" resultMap="BaseResultMap"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | FROM `menu` m, `organization_menu` om | 
|---|
|  |  |  | WHERE om.organization_id = #{orgId} | 
|---|
|  |  |  | AND m.id = om.menu_id | 
|---|
|  |  |  | 
|---|
|  |  |  | AND om.menu_id = m.id | 
|---|
|  |  |  | AND om.is_delete = 0 | 
|---|
|  |  |  | AND m.is_delete = 0 | 
|---|
|  |  |  | ORDER  by m.`order` | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | </mapper> | 
|---|
|  |  |  | 
|---|
|  |  |  | <!-- 通用查询映射结果 --> | 
|---|
|  |  |  | <resultMap id="BaseResultMap" type="com.moral.api.entity.UserLog"> | 
|---|
|  |  |  | <id column="id" property="id" /> | 
|---|
|  |  |  | <result column="type" property="type" /> | 
|---|
|  |  |  | <result column="content" property="content" /> | 
|---|
|  |  |  | <result column="organization_id" property="organizationId" /> | 
|---|
|  |  |  | <result column="operate_id" property="operateId" /> | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "order", value = "同级菜单顺序", required = true, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "insertOneManageMenu", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage insertOneManageMenu(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | public ResultMessage insertOneManageMenu(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | ManageMenu manageMenu = JSON.parseObject(JSON.toJSONString(parameters), ManageMenu.class); | 
|---|
|  |  |  | Map<String,Object> resultMap = manageMenuService.insertManageMenu(manageMenu); | 
|---|
|  |  |  | String msg = resultMap.get("msg").toString(); | 
|---|
|  |  |  | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); | 
|---|
|  |  |  | if (flag){ | 
|---|
|  |  |  | int code = Integer.parseInt(resultMap.get("code").toString()); | 
|---|
|  |  |  | if (code == 0){ | 
|---|
|  |  |  | return ResultMessage.ok(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.fail(msg); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name = "url", value = "url地址", required = true, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "updateManageMenuById", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage updateManageMenuById(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | public ResultMessage updateManageMenuById(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | System.out.println("parameters:"+parameters); | 
|---|
|  |  |  | Map<String,Object> resultMap = manageMenuService.updateManageMenu(parameters); | 
|---|
|  |  |  | String msg = resultMap.get("msg").toString(); | 
|---|
|  |  |  | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); | 
|---|
|  |  |  | if (flag){ | 
|---|
|  |  |  | int code = Integer.parseInt(resultMap.get("code").toString()); | 
|---|
|  |  |  | if (code == 0){ | 
|---|
|  |  |  | return ResultMessage.ok(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.fail(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "删除角色", notes = "删除角色") | 
|---|
|  |  |  | @ApiOperation(value = "删除菜单", notes = "删除菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "deleteManageMenu", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage deleteManageMenu(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | public ResultMessage deleteManageMenu(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String,Object> resultMap = manageMenuService.deleteManageMenu(parameters); | 
|---|
|  |  |  | String msg = resultMap.get("msg").toString(); | 
|---|
|  |  |  | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); | 
|---|
|  |  |  | if (flag){ | 
|---|
|  |  |  | int code = Integer.parseInt(resultMap.get("code").toString()); | 
|---|
|  |  |  | if (code == 0){ | 
|---|
|  |  |  | return ResultMessage.ok(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.fail(msg); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询所有菜单", notes = "查询所有菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | /*@ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int")*/ | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getAllManageMenu", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getAllManageMenu(HttpServletRequest request) { | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_NOT_REQUIREMENT.getMsg()); | 
|---|
|  |  |  | return ResultMessage.fail(resultMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<ManageMenu> re = manageMenuService.getManageMenuByNameFuzzy(parameters); | 
|---|
|  |  |  | List<Map<String,Object>> re = manageMenuService.getManageMenuByNameFuzzy(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(re); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "通过roleId查询菜单", notes = "通过roleId查询菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "roleId", value = "角色id", required = true, paramType = "query", dataType = "int") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getManageMenuByRoleId", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getManageMenuByRoleId(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | List<ManageMenu> result = manageMenuService.getManageMenuByRoleId(Integer.parseInt(parameters.get("roleId").toString())); | 
|---|
|  |  |  | return ResultMessage.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询菜单列表", notes = "查询菜单列表") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页长度", required = true, paramType = "query", dataType = "int") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getManageMenuList", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getManageMenuList(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | List<Map<String,Object>> result = manageMenuService.getAllWithPagingQuery(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "通过父菜单查询子菜单", notes = "通过父菜单查询子菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "parent_id", value = "父菜单id", required = true, paramType = "query", dataType = "int"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getManageMenuByParentId", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getManageMenuByParentId(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String,Object> parameters = getParametersStartingWith(request,null); | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (parameters.get("parent_id") == null || parameters.get("current") == null || parameters.get("size") == null){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return ResultMessage.fail(resultMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Integer.parseInt(parameters.get("current").toString())<1 || Integer.parseInt(parameters.get("size").toString())<1){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_NOT_REQUIREMENT.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_NOT_REQUIREMENT.getMsg()); | 
|---|
|  |  |  | return ResultMessage.fail(resultMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String,Object>> re = manageMenuService.getManageMenuByParentId(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(re); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.moral.api.entity.ManageMenu; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.service.ManageMenuService; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.login.AccountInfoDTO; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleMenuService; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParam; | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManageRoleMenuService manageRoleMenuService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisTemplate redisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取所有角色", notes = "获取所有角色") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "insertOneManageRole", method = RequestMethod.POST) | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public ResultMessage insertOneManageRole(@RequestBody Map<String, Object> parameters) { | 
|---|
|  |  |  | public ResultMessage insertOneManageRole(@RequestBody Map<String, Object> parameters,HttpServletRequest request) { | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | if (parameters.get("menuIds") != null){ | 
|---|
|  |  |  | String menuIdsStr = parameters.get("menuIds").toString(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getManageRoleByNameFuzzy(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getManageMenuByCondition(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getManageMenuByRoleId(int roleId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | Map<String,Object> deleteManageMenu(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getAllWithPagingQuery(Map map); | 
|---|
|  |  |  | List<Map<String,Object>> getAllWithPagingQuery(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getAllMenus(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getManageMenuByNameFuzzy(Map map); | 
|---|
|  |  |  | List getManageMenuByRoleId(int roleId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String,Object>> getManageMenuByNameFuzzy(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String,Object>> getManageMenuByParentId(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getParentChildrenMenusByRoles(List<ManageRole> roles); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.ManageMenu; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.ManageMenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.util.LogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageRoleMenuMapper manageRoleMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | LogUtils logUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> insertManageMenu(ManageMenu manageMenu) { | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("msg", ResponseCodeEnum.MENU_IS_EXPIRE.getMsg()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | manageMenuMapper.insertOne(manageMenu); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "添加菜单:"+manageMenu.getName()+";"; | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.INSERT_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code", ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg", ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("code", ResponseCodeEnum.MENU_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg", ResponseCodeEnum.MENU_IS_NULL.getMsg()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //更新之前获取原来的菜单信息 | 
|---|
|  |  |  | ManageMenu manageMenuOld = manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | manageMenuMapper.updateManageMenuById(map); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "修改了菜单:"+manageMenuOld.getName()+";"; | 
|---|
|  |  |  | for (Object key:map.keySet()) { | 
|---|
|  |  |  | if (key.toString().equals("name")){ | 
|---|
|  |  |  | content = content+"菜单名:"+manageMenuOld.getName()+"->"+map.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("url")){ | 
|---|
|  |  |  | content = content+"url地址:"+manageMenuOld.getUrl()+"->"+map.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("icon")){ | 
|---|
|  |  |  | content = content+"图标地址:"+manageMenuOld.getIcon()+"->"+map.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("parent_id")){ | 
|---|
|  |  |  | content = content+"父菜单:"+manageMenuMapper.getManageMenuById(manageMenuOld.getId()).getName()+"->"+manageMenuMapper.getManageMenuById(Integer.parseInt(map.get(key).toString())).getName()+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("order")){ | 
|---|
|  |  |  | content = content+"同一级别菜单顺序:"+manageMenuOld.getOrder()+"->"+map.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code", ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg", ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("code", ResponseCodeEnum.MENU_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg", ResponseCodeEnum.MENU_IS_NULL.getMsg()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //删除之前获取数据信息 | 
|---|
|  |  |  | ManageMenu manageMenuDelete = manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | Map deleteMap = new HashMap(); | 
|---|
|  |  |  | int id = Integer.parseInt(map.get("id").toString()); | 
|---|
|  |  |  | deleteMap.put("id", id); | 
|---|
|  |  |  | 
|---|
|  |  |  | Map role_menuDeleteMap = new HashMap(); | 
|---|
|  |  |  | role_menuDeleteMap.put("menu_id", id); | 
|---|
|  |  |  | manageRoleMenuMapper.updateDeleteStateByMenu_id(role_menuDeleteMap); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "删除菜单:"+manageMenuDelete.getName()+";"; | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.DELETE_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code", ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg", ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ManageMenu> getAllWithPagingQuery(Map map) { | 
|---|
|  |  |  | public List<Map<String,Object>> getAllWithPagingQuery(Map map) { | 
|---|
|  |  |  | Map limitMap = new HashMap(); | 
|---|
|  |  |  | limitMap.put("start", (Integer.parseInt(map.get("current").toString()) - 1) * Integer.parseInt(map.get("size").toString())); | 
|---|
|  |  |  | limitMap.put("number", Integer.parseInt(map.get("size").toString())); | 
|---|
|  |  |  | List<ManageMenu> manageMenus = manageMenuMapper.getDataWithPage(limitMap); | 
|---|
|  |  |  | return manageMenus; | 
|---|
|  |  |  | SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | List<Map<String,Object>> resultList = new ArrayList<>(); | 
|---|
|  |  |  | for (ManageMenu manageMenu:manageMenus) { | 
|---|
|  |  |  | Map manegeMenuMap = JSON.parseObject(JSON.toJSONString(manageMenu)); | 
|---|
|  |  |  | if (manageMenu.getParentId().equals(0)){ | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",""); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | ManageMenu parentMenu = manageMenuMapper.getManageMenuById(manageMenu.getParentId()); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(parentMenu)){ | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",""); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String parent_name = parentMenu.getName(); | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",parent_name); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String createTime = SDF.format(manageMenu.getCreateTime()); | 
|---|
|  |  |  | String updateTime = SDF.format(manageMenu.getUpdateTime()); | 
|---|
|  |  |  | manegeMenuMap.put("createTime",createTime); | 
|---|
|  |  |  | manegeMenuMap.put("updateTime",updateTime); | 
|---|
|  |  |  | resultList.add(manegeMenuMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ManageMenu> getManageMenuByNameFuzzy(Map map) { | 
|---|
|  |  |  | public List getManageMenuByRoleId(int roleId) { | 
|---|
|  |  |  | List<ManageMenu> manageMenus = manageMenuMapper.getManageMenuByRoleId(roleId); | 
|---|
|  |  |  | List menuIdList = new ArrayList(); | 
|---|
|  |  |  | for (ManageMenu manageMenu:manageMenus) { | 
|---|
|  |  |  | menuIdList.add(manageMenu.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return menuIdList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Map<String,Object>> getManageMenuByNameFuzzy(Map map) { | 
|---|
|  |  |  | Map limitMap = new HashMap(); | 
|---|
|  |  |  | limitMap.put("name", map.get("name")); | 
|---|
|  |  |  | limitMap.put("start", (Integer.parseInt(map.get("current").toString()) - 1) * Integer.parseInt(map.get("size").toString())); | 
|---|
|  |  |  | limitMap.put("number", Integer.parseInt(map.get("size").toString())); | 
|---|
|  |  |  | List<ManageMenu> manageMenus = manageMenuMapper.getManageRoleByNameFuzzy(limitMap); | 
|---|
|  |  |  | return manageMenus; | 
|---|
|  |  |  | SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | List<Map<String,Object>> resultList = new ArrayList<>(); | 
|---|
|  |  |  | for (ManageMenu manageMenu:manageMenus) { | 
|---|
|  |  |  | Map manegeMenuMap = JSON.parseObject(JSON.toJSONString(manageMenu)); | 
|---|
|  |  |  | if (manageMenu.getParentId().equals(0)){ | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",""); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | ManageMenu parentMenu = manageMenuMapper.getManageMenuById(manageMenu.getParentId()); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(parentMenu)){ | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",""); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String parent_name = parentMenu.getName(); | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",parent_name); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String createTime = SDF.format(manageMenu.getCreateTime()); | 
|---|
|  |  |  | String updateTime = SDF.format(manageMenu.getUpdateTime()); | 
|---|
|  |  |  | manegeMenuMap.put("createTime",createTime); | 
|---|
|  |  |  | manegeMenuMap.put("updateTime",updateTime); | 
|---|
|  |  |  | resultList.add(manegeMenuMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Map<String, Object>> getManageMenuByParentId(Map map) { | 
|---|
|  |  |  | Map limitMap = new HashMap(); | 
|---|
|  |  |  | limitMap.put("parent_id", map.get("parent_id")); | 
|---|
|  |  |  | limitMap.put("start", (Integer.parseInt(map.get("current").toString()) - 1) * Integer.parseInt(map.get("size").toString())); | 
|---|
|  |  |  | limitMap.put("number", Integer.parseInt(map.get("size").toString())); | 
|---|
|  |  |  | List<ManageMenu> manageMenus = manageMenuMapper.getManageMenuByCondition(limitMap); | 
|---|
|  |  |  | SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | List<Map<String,Object>> resultList = new ArrayList<>(); | 
|---|
|  |  |  | for (ManageMenu manageMenu:manageMenus) { | 
|---|
|  |  |  | Map manegeMenuMap = JSON.parseObject(JSON.toJSONString(manageMenu)); | 
|---|
|  |  |  | if (manageMenu.getParentId().equals(0)){ | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",""); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | ManageMenu parentMenu = manageMenuMapper.getManageMenuById(manageMenu.getParentId()); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(parentMenu)){ | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",""); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String parent_name = parentMenu.getName(); | 
|---|
|  |  |  | manegeMenuMap.put("parent_name",parent_name); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String createTime = SDF.format(manageMenu.getCreateTime()); | 
|---|
|  |  |  | String updateTime = SDF.format(manageMenu.getUpdateTime()); | 
|---|
|  |  |  | manegeMenuMap.put("createTime",createTime); | 
|---|
|  |  |  | manegeMenuMap.put("updateTime",updateTime); | 
|---|
|  |  |  | resultList.add(manegeMenuMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.ManageMenu; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRoleMenu; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageMenuMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleMenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.util.LogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageRoleMenuMapper manageRoleMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageMenuMapper manageMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageRoleMapper manageRoleMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | LogUtils logUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> updateRoleMenu(List list, int id) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | List<ManageMenu> manageMenusOld = manageMenuMapper.getManageMenuByRoleId(id); | 
|---|
|  |  |  | if (list.size()==0){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manageRoleMenuMapper.insertBatch(mapList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<ManageMenu> manageMenusNew = manageMenuMapper.getManageMenuByRoleId(id); | 
|---|
|  |  |  | List manageMenuOldList = new ArrayList(); | 
|---|
|  |  |  | List manageMenuNewList = new ArrayList(); | 
|---|
|  |  |  | for (ManageMenu manageMenu:manageMenusOld) { | 
|---|
|  |  |  | manageMenuOldList.add(manageMenu.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (ManageMenu manageMenu:manageMenusNew) { | 
|---|
|  |  |  | manageMenuNewList.add(manageMenu.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取角色信息 | 
|---|
|  |  |  | ManageRole manageRole = manageRoleMapper.selectById(id); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "修改了角色:"+manageRole.getName()+";"; | 
|---|
|  |  |  | if (manageMenuOldList.size()==0){ | 
|---|
|  |  |  | manageMenuOldList.add("空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageMenuNewList.size()==0){ | 
|---|
|  |  |  | manageMenuNewList.add("空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | content = content+"菜单:"+manageMenuOldList+"->"+manageMenuNewList+";"; | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.ManageAccount; | 
|---|
|  |  |  | import com.moral.api.entity.ManageAccountRole; | 
|---|
|  |  |  | import com.moral.api.entity.ManageLog; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageAccountRoleMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageLogMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMenuMapper; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.login.AccountInfoDTO; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.util.LogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
|---|
|  |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageAccountRoleMapper manageAccountRoleMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | LogUtils logUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String,Object> getAllWithPagingQuery(Map map) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (manageRoleMapper.getManageRoleByName(manageRole.getName()) != null){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.ROLE_IS_EXPIRE.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.ROLE_IS_EXPIRE.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | manageRoleMapper.insertOne(manageRole); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer code = Integer.parseInt(resultMap.get("code").toString()); | 
|---|
|  |  |  | if (code.equals(ResponseCodeEnum.SUCCESS.getCode())){ | 
|---|
|  |  |  | manageRoleMapper.insertOne(manageRole); | 
|---|
|  |  |  | ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName()); | 
|---|
|  |  |  | int role_id = manageRoleIns.getId(); | 
|---|
|  |  |  | List insertList = new ArrayList(); | 
|---|
|  |  |  | 
|---|
|  |  |  | insertMap.put("menu_id",Integer.parseInt(temp.toString())); | 
|---|
|  |  |  | insertList.add(insertMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //判断在新建角色时,是否添加菜单 | 
|---|
|  |  |  | if (insertList.size()>0){ | 
|---|
|  |  |  | manageRoleMenuMapper.insertBatch(insertList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "添加角色:"+manageRole.getName()+";"; | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.INSERT_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | //在更新之前获取原来信息 | 
|---|
|  |  |  | ManageRole manageRoleOld = manageRoleMapper.selectById(Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | manageRoleMapper.updateManageRoleById(map); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "修改了角色:"+manageRoleOld.getName()+";"; | 
|---|
|  |  |  | for (Object key:map.keySet()) { | 
|---|
|  |  |  | if (key.toString().equals("name")){ | 
|---|
|  |  |  | content = content+"角色名:"+manageRoleOld.getName()+"->"+map.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("desc")){ | 
|---|
|  |  |  | content = content+"备注:"+manageRoleOld.getDesc()+"->"+map.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<ManageAccountRole> wrapper = new QueryWrapper(); | 
|---|
|  |  |  | wrapper.eq("role_id",Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | manageAccountRoleMapper.update(manageAccountRole,wrapper); | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | ManageRole manageRole1 = manageRoleMapper.selectById(Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | String content = "删除角色:"+manageRole1.getName()+";"; | 
|---|
|  |  |  | logUtils.saveOperationForManage(request,content,Constants.DELETE_OPERATE_TYPE); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | - /verificationCode/** | 
|---|
|  |  |  | - /manageLog/** | 
|---|
|  |  |  |  | 
|---|
|  |  |  | - /role/getAllManageRole | 
|---|
|  |  |  | - /role/getManageRoleByNameFuzzy | 
|---|
|  |  |  | - /role/insertOneManageRole | 
|---|
|  |  |  | - /role/updateManageRole | 
|---|
|  |  |  | - /role/updateRoleMenu | 
|---|
|  |  |  | - /role/deleteManageRole | 
|---|
|  |  |  | - /menu/getAllManageMenu | 
|---|
|  |  |  | - /menu/getManageMenuByNameFuzzy | 
|---|
|  |  |  | - /role/** | 
|---|
|  |  |  | - /menu/** | 
|---|
|  |  |  | - /api/** | 
|---|
|  |  |  | AES: | 
|---|
|  |  |  | KEY: | 
|---|
|  |  |  | 
|---|
|  |  |  | <if test="icon != null"> | 
|---|
|  |  |  | icon, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="parent_id != null"> | 
|---|
|  |  |  | <if test="parentId != null"> | 
|---|
|  |  |  | parent_id, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="order != null"> | 
|---|
|  |  |  | 
|---|
|  |  |  | <if test="icon != null"> | 
|---|
|  |  |  | #{icon}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="parent_id != null"> | 
|---|
|  |  |  | #{parent_id}, | 
|---|
|  |  |  | <if test="parentId != null"> | 
|---|
|  |  |  | #{parentId}, | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="order != null"> | 
|---|
|  |  |  | #{order}, | 
|---|
|  |  |  | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | from manage_menu mm | 
|---|
|  |  |  | where mm.is_delete = 0 | 
|---|
|  |  |  | ORDER BY parent_id ASC,`order` ASC | 
|---|
|  |  |  | limit #{start},#{number} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | limit #{start},#{number} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getManageMenuByRoleId" resultMap="BaseResultMap"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | FROM manage_menu mm | 
|---|
|  |  |  | JOIN manage_role_menu mrm | 
|---|
|  |  |  | ON mm.id = mrm.menu_id AND mrm.is_delete = 0 | 
|---|
|  |  |  | JOIN manage_role mr | 
|---|
|  |  |  | ON mr.id = mrm.role_id and mr.id = #{roleId} | 
|---|
|  |  |  | WHERE mm.is_delete = 0 | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getManageMenuByCondition" resultMap="BaseResultMap"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | from manage_menu mm | 
|---|
|  |  |  | where mm.is_delete = 0 | 
|---|
|  |  |  | <if test="name != null"> | 
|---|
|  |  |  | and mm.name = #{name} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="url != null"> | 
|---|
|  |  |  | and mm.url = #{url} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="icon != null"> | 
|---|
|  |  |  | and mm.icon = #{icon} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="parent_id != null"> | 
|---|
|  |  |  | and mm.parent_id = #{parent_id} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="order != null"> | 
|---|
|  |  |  | and mm.order = #{order} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | limit #{start},#{number} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </mapper> | 
|---|