| | |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.service.GroupService; |
| | | import com.moral.api.service.UserGroupService; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.api.utils.OperationLogUtils; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | |
| | | @Autowired |
| | | private UserGroupService userGroupService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @ApiOperation(value = "添加组", notes = "添加组") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | return ResultMessage.ok(pageResult); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户所属组", notes = "获取用户所属组") |
| | | @ApiOperation(value = "获取用户所属组ids", notes = "获取用户所属组ids") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | |
| | | } |
| | | String token = request.getHeader("token"); |
| | | userGroupService.allotGroups(parameters, token); |
| | | |
| | | String account = userService.getById((Integer) parameters.get("userId")).getAccount(); |
| | | String content = "给账户《" + account + "》分配了组"; |
| | | OperationLogUtils.insertLog(request, content); |
| | | return ResultMessage.ok(); |
| | | } |
| | | } |
| | |
| | | |
| | | 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 = {"登陆"}) |
| | |
| | | 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.GroupService; |
| | | import com.moral.api.service.MenuService; |
| | | import com.moral.api.utils.OperationLogUtils; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.TokenUtils; |
| | |
| | | @Autowired |
| | | private MenuService menuService; |
| | | |
| | | @Autowired |
| | | private GroupService groupService; |
| | | |
| | | @ApiOperation(value = "组分配菜单", notes = "组分配菜单") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | |
| | | } |
| | | String token = request.getHeader("token"); |
| | | groupMenuService.allotMenus(parameters, token); |
| | | |
| | | String groupName = groupService.getById((Integer) parameters.get("groupId")).getGroupName(); |
| | | String content = "给组<" + groupName + ">分配了菜单"; |
| | | OperationLogUtils.insertLog(request, content); |
| | | 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, HttpServletRequest request) { |
| | | if (user.getAccount().isEmpty() || user.getPassword().isEmpty()) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | |
| | | 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, HttpServletRequest request) { |
| | | 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, HttpServletRequest request) { |
| | | if (user.getId() == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | |
| | | 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) { |
| | | @RequestMapping(value = "select", method = RequestMethod.POST) |
| | | public ResultMessage select(@RequestBody Map<String, Object> parameters, HttpServletRequest request) { |
| | | parameters.put("token", request.getHeader("token")); |
| | | Page<User> userPage = userService.selectUsers(parameters); |
| | | PageResult<User> pageResult = new PageResult<>( |
| | |
| | | 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; |
| | | |
| | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @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; |
| | | |
| | | /** |
| | |
| | | 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); |
| | | |
| | | List<Integer> getMenusIds(Integer groupId); |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | 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.GroupMenuMapper; |
| | |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private GroupMenuMapper groupMenuMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void allotMenus(Map<String, Object> parameters, String 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()) { |
| | | if (menuIds != null && !menuIds.isEmpty()) { |
| | | for (Integer menuId : menuIds) { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @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<>(); |
| | | for (GroupMenu groupMenu : groupMenus) { |
| | | 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> |
| | |
| | | public Map<String, Object> addGroup(Group group, String 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); |
| | | //日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String content = "添加了组:" + group.getGroupName(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return result; |
| | | } |
| | | |
| | |
| | | UpdateWrapper<UserGroup> deleteUserGroupWrapper = new UpdateWrapper<>(); |
| | | deleteUserGroupWrapper.set("is_delete", Constants.DELETE).eq("group_id", group.getId()); |
| | | userGroupMapper.update(null, deleteUserGroupWrapper); |
| | | //日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String content = "删除了组:" + group.getGroupName(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> updateGroup(Group group, String token) { |
| | | 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); |
| | | //日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String content = "修改了组:" + group.getGroupName(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | 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"); |
| | | 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"); |
| | |
| | | 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 org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private UserGroupMapper userGroupMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void allotGroups(Map<String, Object> parameters, String 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); |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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 org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | 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.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.setIp(WebUtils.getIpAddr(request)); |
| | | userLog.setOperateId(userBo.getId()); |
| | | userLog.setOrganizationId(userBo.getOrganizationId()); |
| | | userLog.setContent("登陆了用户:" + userBo.getAccount()); |
| | | userLogMapper.insert(userLog); |
| | | return result; |
| | | } |
| | | |
| | |
| | | } else { |
| | | user.setExpireTime(userExpireTime); |
| | | } |
| | | } else { |
| | | if (orgExpireTime != null) { |
| | | user.setExpireTime(orgExpireTime); |
| | | } |
| | | } |
| | | userMapper.insert(user); |
| | | //日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String content = "添加了用户:" + user.getAccount(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | return result; |
| | | } |
| | | |
| | |
| | | TokenUtils.destoryToken(userId, token); |
| | | } |
| | | userGroupMapper.update(null, deleteWrapper); |
| | | //日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String content = "删除了用户:" + user.getAccount(); |
| | | OperationLogUtils.insertLog(request, content); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> updateUser(User user, String 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); |
| | | |
| | | //日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | 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()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | <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> |