2 files added
	
		
		19 files modified
	
	
 
	
	
	
	
	
	
	
	
| 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 java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.Group; | 
|---|
|  |  |  | import com.moral.api.service.GroupService; | 
|---|
|  |  |  | import com.moral.api.service.UserGroupService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.PageResult; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"组"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/group") | 
|---|
|  |  |  | public class GroupController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupService groupService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserGroupService userGroupService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "添加组", notes = "添加组") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupName", value = "组名", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "addGroup", method = RequestMethod.POST) | 
|---|
|  |  |  | private ResultMessage addGroup(Group group, HttpServletRequest request) { | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "删除组", notes = "删除组") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "deleteGroup", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage deleteGroup(String groupId) { | 
|---|
|  |  |  | if (groupId == null) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("id", groupId); | 
|---|
|  |  |  | Group group = groupService.getOne(queryWrapper); | 
|---|
|  |  |  | if (group == null) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | groupService.deleteGroup(group); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "修改组信息", notes = "修改组信息") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupName", value = "组名", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "updateGroup", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage updateUser(Group group, HttpServletRequest request) { | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> result = groupService.updateGroup(group, token); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "分页查询组列表", notes = "分页查询组列表") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupName", value = "组名模糊查询", required = false, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "selectGroups", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage selectGroups(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | parameters.put("token", request.getHeader("token")); | 
|---|
|  |  |  | Page<Group> userPage = groupService.selectGroups(parameters); | 
|---|
|  |  |  | PageResult<Group> pageResult = new PageResult<>( | 
|---|
|  |  |  | userPage.getTotal(), userPage.getPages(), userPage.getRecords() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return ResultMessage.ok(pageResult); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "用户分配组", notes = "用户分配组") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupIds", value = "组id,多个逗号隔开", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "allotGroups", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage allotGroups(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | if (!parameters.containsKey("userId")) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | String[] groupIds = parameters.get("groupIds").toString().split(","); | 
|---|
|  |  |  | List<Integer> gIds = new ArrayList<>(); | 
|---|
|  |  |  | for (String groupId : groupIds) { | 
|---|
|  |  |  | gIds.add(Integer.parseInt(groupId)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | parameters.put("groupIds", gIds); | 
|---|
|  |  |  | userGroupService.allotGroups(parameters, token); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Group; | 
|---|
|  |  |  | import com.moral.api.service.GroupService; | 
|---|
|  |  |  | import com.moral.api.service.SysConfigService; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.pojo.VerificationCode; | 
|---|
|  |  |  | import com.moral.util.KaptchaUtils; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupService groupService; | 
|---|
|  |  |  | private SysConfigService sysConfigService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "登陆", notes = "登陆") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "account", value = "账户", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "password", value = "密码", required = false, paramType = "query", dataType = "String") | 
|---|
|  |  |  | @ApiImplicitParam(name = "account", value = "账户", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "login", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage login(HttpServletRequest request) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String, Object> result = userService.login(parameters); | 
|---|
|  |  |  | if (!result.containsKey("data")) { | 
|---|
|  |  |  | return ResultMessage.fail(Integer.parseInt(result.get("code").toString()), result.get("msg").toString()); | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), (String) result.get("msg")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.ok(result.get("data")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "注销", notes = "注销") | 
|---|
|  |  |  | @RequestMapping(value = "logout", method = RequestMethod.POST) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "uid", value = "账户", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public ResultMessage logout(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | if (!parameters.containsKey("uid")) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "添加组", notes = "添加组") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupName", value = "组名", required = true, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "addGroup", method = RequestMethod.POST) | 
|---|
|  |  |  | private ResultMessage addGroup(Group group, HttpServletRequest request) { | 
|---|
|  |  |  | String currentUserId = request.getHeader("uid"); | 
|---|
|  |  |  | Map<String, Object> map = groupService.addGroup(group, currentUserId); | 
|---|
|  |  |  | String msg = map.get("msg").toString(); | 
|---|
|  |  |  | boolean flag = Boolean.parseBoolean(map.get("flag").toString()); | 
|---|
|  |  |  | if (flag) { | 
|---|
|  |  |  | return ResultMessage.ok(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.fail(msg); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 获取验证码是否开启 | 
|---|
|  |  |  | * @Param: [] | 
|---|
|  |  |  | * @return: com.moral.constant.ResultMessage | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/3/18 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取验证码是否开启", notes = "获取验证码是否开启") | 
|---|
|  |  |  | @RequestMapping(value = "verificationCodeConfig", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage verifyConfig() { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取验证码", notes = "获取验证码") | 
|---|
|  |  |  | @RequestMapping(value = "verificationCode/get", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getVerificationCode() { | 
|---|
|  |  |  | VerificationCode verificationCode = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | verificationCode = KaptchaUtils.createVerificationCode(); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | log.error(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(verificationCode)) | 
|---|
|  |  |  | return ResultMessage.fail(); | 
|---|
|  |  |  | return ResultMessage.ok(verificationCode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "校验验证码", notes = "校验验证码") | 
|---|
|  |  |  | @RequestMapping(value = "verificationCode/verify", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage gverifyVerificationCode(VerificationCode verificationCode) { | 
|---|
|  |  |  | if (!verificationCode.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(); | 
|---|
|  |  |  | if (KaptchaUtils.verify(verificationCode)) | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | return ResultMessage.fail(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| 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 java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.service.GroupMenuService; | 
|---|
|  |  |  | import com.moral.api.service.MenuService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"菜单"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/menu") | 
|---|
|  |  |  | public class MenuController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupMenuService groupMenuService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MenuService menuService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "组分配菜单", notes = "组分配菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "menuIds", value = "菜单id,多个逗号隔开", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "allotMenus", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage allotMenus(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | if (!parameters.containsKey("userId")) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | String[] menuIds = parameters.get("menuIds").toString().split(","); | 
|---|
|  |  |  | List<Integer> mIds = new ArrayList<>(); | 
|---|
|  |  |  | for (String menuId : menuIds) { | 
|---|
|  |  |  | mIds.add(Integer.parseInt(menuId)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | parameters.put("menuIds", mIds); | 
|---|
|  |  |  | groupMenuService.allotMenus(parameters, token); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询组织层级菜单", notes = "查询组织层级菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "selectGroups", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage selectGroups(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")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.PageResult; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | Map<String, Object> result = userService.addUser(user, token); | 
|---|
|  |  |  | Map<String, Object> result = userService.updateUser(user, token); | 
|---|
|  |  |  | if (!result.isEmpty()) { | 
|---|
|  |  |  | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询账户信息", notes = "查询账户信息") | 
|---|
|  |  |  | @ApiOperation(value = "分页查询账户列表", notes = "分页查询账户列表") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "userId", value = "用户id", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "order", value = "排序字段", 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 = "header", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "mobile", value = "手机号模糊查询", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "email", value = "邮箱模糊查询", required = false, paramType = "header", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "wechat", value = "微信模糊查询", required = false, paramType = "header", dataType = "String"), | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getUserInfo", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage getUserInfo(HttpServletRequest request) { | 
|---|
|  |  |  | @RequestMapping(value = "selectUsers", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage selectUsers(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | parameters.put("token", request.getHeader("token")); | 
|---|
|  |  |  | Map<String, Object> users = userService.getUsers(parameters); | 
|---|
|  |  |  | if (users.containsKey("msg")) { | 
|---|
|  |  |  | return ResultMessage.fail(users.get("msg").toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.ok(users.get("users")); | 
|---|
|  |  |  | Page<User> userPage = userService.selectUsers(parameters); | 
|---|
|  |  |  | PageResult<User> pageResult = new PageResult<>( | 
|---|
|  |  |  | userPage.getTotal(), userPage.getPages(), userPage.getRecords() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | return ResultMessage.ok(pageResult); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.entity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableName; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | @EqualsAndHashCode(callSuper = false) | 
|---|
|  |  |  | @TableName("`group`") | 
|---|
|  |  |  | public class Group extends Model<Group> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final long serialVersionUID = 1L; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface MenuMapper extends BaseMapper<Menu> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Menu> selectUserMenu(int userId); | 
|---|
|  |  |  | List<Menu> selectUserMenu(Integer userId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Menu> selectOrganizationMenu(Integer orgId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.GroupMenu; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface GroupMenuService extends IService<GroupMenu> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void allotMenus(Map<String, Object> parameters, String token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.Group; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface GroupService extends IService<Group> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> addGroup(Group group, String currentUserId); | 
|---|
|  |  |  | Map<String, Object> addGroup(Group group, String token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void deleteGroup(Group group); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> updateGroup(Group group, String token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Page<Group> selectGroups(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Menu; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface MenuService extends IService<Menu> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String,Object> selectMenusByOrgId(Integer orgId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.UserGroup; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public interface UserGroupService extends IService<UserGroup> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void allotGroups(Map<String, Object> parameters, String token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  | import com.moral.api.pojo.UserBo; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> updateUser(User user, String token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> getUsers(Map<String, Object> parameters); | 
|---|
|  |  |  | Page<User> selectUsers(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UserBo selectUserInfo(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.GroupMenu; | 
|---|
|  |  |  | import com.moral.api.entity.UserGroup; | 
|---|
|  |  |  | import com.moral.api.mapper.GroupMenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.GroupMenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class GroupMenuServiceImpl extends ServiceImpl<GroupMenuMapper, GroupMenu> implements GroupMenuService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private GroupMenuMapper groupMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | GroupMenu groupMenu = new GroupMenu(); | 
|---|
|  |  |  | groupMenu.setGroupId(groupId); | 
|---|
|  |  |  | groupMenu.setMenuId(menuId); | 
|---|
|  |  |  | groupMenu.setChannel(Constants.WEB_CHANNEL); | 
|---|
|  |  |  | groupMenu.setOrganizationId((Integer) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.Wrapper; | 
|---|
|  |  |  | 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.Group; | 
|---|
|  |  |  | import com.moral.api.entity.GroupMenu; | 
|---|
|  |  |  | import com.moral.api.entity.User; | 
|---|
|  |  |  | import com.moral.api.entity.UserGroup; | 
|---|
|  |  |  | import com.moral.api.mapper.GroupMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.GroupMenuMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserGroupMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.UserMapper; | 
|---|
|  |  |  | import com.moral.api.service.GroupService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.util.RegexUtils; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | 
|---|
|  |  |  | private GroupMapper groupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserMapper userMapper; | 
|---|
|  |  |  | private GroupMenuMapper groupMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserGroupMapper userGroupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> addGroup(Group group, String currentUserId) { | 
|---|
|  |  |  | Map<String, Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | User currentUser = userMapper.selectById(currentUserId); | 
|---|
|  |  |  | if (!currentUser.getIsAdmin()) { | 
|---|
|  |  |  | resultMap.put("flag", false); | 
|---|
|  |  |  | resultMap.put("msg", "添加失败,没有权限"); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer orgId = currentUser.getOrganizationId(); | 
|---|
|  |  |  | 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"); | 
|---|
|  |  |  | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("group_name", group.getGroupName()).eq("organization_id", orgId); | 
|---|
|  |  |  | if (groupMapper.selectOne(queryWrapper) == null) { | 
|---|
|  |  |  | queryWrapper.eq("group_name", group.getGroupName()) | 
|---|
|  |  |  | .eq("organization_id", orgId) | 
|---|
|  |  |  | .eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | if (groupMapper.selectOne(queryWrapper) != null) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.GROUP_EXIST.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.GROUP_EXIST.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | group.setOrganizationId(orgId); | 
|---|
|  |  |  | groupMapper.insert(group); | 
|---|
|  |  |  | resultMap.put("flag", true); | 
|---|
|  |  |  | resultMap.put("msg", "添加成功"); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteGroup(Group group) { | 
|---|
|  |  |  | //逻辑删除group | 
|---|
|  |  |  | group.setIsDelete(Constants.DELETE); | 
|---|
|  |  |  | groupMapper.updateById(group); | 
|---|
|  |  |  | //逻辑删除group_menu | 
|---|
|  |  |  | UpdateWrapper<GroupMenu> deleteGroupWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteGroupWrapper.set("is_delete", Constants.DELETE).eq("group_id", group.getId()); | 
|---|
|  |  |  | groupMenuMapper.update(null, deleteGroupWrapper); | 
|---|
|  |  |  | //逻辑删除user_group | 
|---|
|  |  |  | UpdateWrapper<UserGroup> deleteUserGroupWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteUserGroupWrapper.set("is_delete", Constants.DELETE).eq("group_id", group.getId()); | 
|---|
|  |  |  | userGroupMapper.update(null, deleteUserGroupWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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"); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | groupMapper.updateById(group); | 
|---|
|  |  |  | 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"); | 
|---|
|  |  |  | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("organization_id", organizationId) | 
|---|
|  |  |  | .eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | Object order = parameters.get("order"); | 
|---|
|  |  |  | Object groupName = parameters.get("groupName"); | 
|---|
|  |  |  | //模糊查询参数 | 
|---|
|  |  |  | if (groupName != null) { | 
|---|
|  |  |  | queryWrapper.like("group_name", groupName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //分页参数 | 
|---|
|  |  |  | if (!parameters.containsKey("page")) { | 
|---|
|  |  |  | parameters.put("page", 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!parameters.containsKey("size")) { | 
|---|
|  |  |  | parameters.put("size", 10); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int page = Integer.parseInt(parameters.get("page").toString()); | 
|---|
|  |  |  | int size = Integer.parseInt(parameters.get("size").toString()); | 
|---|
|  |  |  | Page<Group> pageData = new Page<>(page, size); | 
|---|
|  |  |  | //排序参数,默认id升序 | 
|---|
|  |  |  | if (order == null) { | 
|---|
|  |  |  | queryWrapper.orderByAsc("id"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | resultMap.put("flag", false); | 
|---|
|  |  |  | resultMap.put("msg", "添加失败,组已存在"); | 
|---|
|  |  |  | queryWrapper.orderByAsc(order.toString(), "id"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | Page<Group> groupPage = groupMapper.selectPage(pageData, queryWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pageData.setRecords(groupPage.getRecords()); | 
|---|
|  |  |  | return groupPage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.Menu; | 
|---|
|  |  |  | import com.moral.api.mapper.MenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.MenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserServiceImpl userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> selectMenusByOrgId(Integer orgId) { | 
|---|
|  |  |  | userService.getMenus(-1, orgId); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.UserGroup; | 
|---|
|  |  |  | import com.moral.api.mapper.UserGroupMapper; | 
|---|
|  |  |  | import com.moral.api.service.UserGroupService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroup> implements UserGroupService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserGroupMapper userGroupMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | UserGroup userGroup = new UserGroup(); | 
|---|
|  |  |  | userGroup.setUserId(userId); | 
|---|
|  |  |  | userGroup.setGroupId(groupId); | 
|---|
|  |  |  | userGroup.setOrganizationId((Integer) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | userGroupMapper.insert(userGroup); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.Group; | 
|---|
|  |  |  | import com.moral.api.entity.Menu; | 
|---|
|  |  |  | import com.moral.api.entity.Organization; | 
|---|
|  |  |  | 
|---|
|  |  |  | userInfo.put("organizationName", organization.getName()); | 
|---|
|  |  |  | userInfo.put("locationLevel", organization.getLocationLevel()); | 
|---|
|  |  |  | userInfo.put("groups", groups); | 
|---|
|  |  |  | userInfo.putAll(getMenus(userBo.getId())); | 
|---|
|  |  |  | userInfo.putAll(getMenus(userBo.getId(), -1)); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //生成token,并存入redis | 
|---|
|  |  |  | String token = TokenUtils.getToken(userBo.getId().toString(), userInfo); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //根据userId获取用户层级菜单 | 
|---|
|  |  |  | private Map<String, Object> getMenus(int userId) { | 
|---|
|  |  |  | List<Menu> allMenus = menuMapper.selectUserMenu(userId); | 
|---|
|  |  |  | public Map<String, Object> getMenus(int userId, int orgId) { | 
|---|
|  |  |  | List<Menu> allMenus; | 
|---|
|  |  |  | if (orgId == -1) { | 
|---|
|  |  |  | allMenus = menuMapper.selectUserMenu(userId); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | allMenus = menuMapper.selectOrganizationMenu(orgId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> resultMap = new LinkedHashMap<>(); | 
|---|
|  |  |  | //第一级菜单 | 
|---|
|  |  |  | List<Menu> oneMenu = allMenus.stream() | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取用户层级菜单递归方法 | 
|---|
|  |  |  | private List<Map<String, Object>> getMenusByRecursion(Menu menu, List<Menu> menus) { | 
|---|
|  |  |  | public List<Map<String, Object>> getMenusByRecursion(Menu menu, List<Menu> menus) { | 
|---|
|  |  |  | List<List<Map<String, Object>>> resultList = new ArrayList(); | 
|---|
|  |  |  | Menu newMenu = new Menu(); | 
|---|
|  |  |  | newMenu.setParentId(menu.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //密码加密 | 
|---|
|  |  |  | user.setPassword(MD5Utils.saltMD5(password)); | 
|---|
|  |  |  | user.setOrganizationId(Integer.parseInt(currentUserInfo.get("organizationId").toString())); | 
|---|
|  |  |  | user.setOrganizationId((int) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | user.setIsAdmin(false); | 
|---|
|  |  |  | //新增账户的过期时间 | 
|---|
|  |  |  | Date userExpireTime = user.getExpireTime(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public void deleteUser(User user) { | 
|---|
|  |  |  | //逻辑删除用户 | 
|---|
|  |  |  | //逻辑删除user | 
|---|
|  |  |  | user.setIsDelete(Constants.DELETE); | 
|---|
|  |  |  | //逻辑删除用户角色配置 | 
|---|
|  |  |  | UpdateWrapper<UserGroup> updateWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | updateWrapper.set("is_delete", Constants.DELETE).eq("user_id", user.getId()); | 
|---|
|  |  |  | userGroupMapper.update(null, updateWrapper); | 
|---|
|  |  |  | userMapper.updateById(user); | 
|---|
|  |  |  | //逻辑删除user_group | 
|---|
|  |  |  | UpdateWrapper<UserGroup> deleteWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteWrapper.set("is_delete", Constants.DELETE).eq("user_id", user.getId()); | 
|---|
|  |  |  | userGroupMapper.update(null, deleteWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String, Object> updateUser(User user, String token) { | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<>(); | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("id", user.getId()).eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | if (userMapper.selectOne(queryWrapper) == null) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.ACCOUNT_IS_DELETE.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | queryWrapper.clear(); | 
|---|
|  |  |  | queryWrapper.eq("account", user.getAccount()).eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | queryWrapper.ne("id", user.getId()) | 
|---|
|  |  |  | .eq("account", user.getAccount()) | 
|---|
|  |  |  | .eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | //校验账户是否存在 | 
|---|
|  |  |  | if (userMapper.selectOne(queryWrapper) != null) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.ACCOUNT_EXIST.getCode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //密码加密 | 
|---|
|  |  |  | user.setPassword(MD5Utils.saltMD5(password)); | 
|---|
|  |  |  | user.setOrganizationId(Integer.parseInt(currentUserInfo.get("organizationId").toString())); | 
|---|
|  |  |  | user.setOrganizationId((int) currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | user.setIsAdmin(false); | 
|---|
|  |  |  | //新增账户的过期时间 | 
|---|
|  |  |  | Date userExpireTime = user.getExpireTime(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> getUsers(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | public Page<User> selectUsers(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(parameters.get("token").toString()); | 
|---|
|  |  |  | if (!(boolean) currentUserInfo.get("isAdmin")) { | 
|---|
|  |  |  | resultMap.put("msg", "没有权限"); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | Object organizationId = currentUserInfo.get("organizationId"); | 
|---|
|  |  |  | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("organization_id", organizationId) | 
|---|
|  |  |  | .eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  | Object order = parameters.get("order"); | 
|---|
|  |  |  | Object account = parameters.get("account"); | 
|---|
|  |  |  | Object userName = parameters.get("userName"); | 
|---|
|  |  |  | Object mobile = parameters.get("mobile"); | 
|---|
|  |  |  | Object email = parameters.get("mobile"); | 
|---|
|  |  |  | Object wechat = parameters.get("wechat"); | 
|---|
|  |  |  | //模糊查询参数 | 
|---|
|  |  |  | if (account != null) { | 
|---|
|  |  |  | queryWrapper.like("account", account); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!parameters.containsKey("userId")) { | 
|---|
|  |  |  | parameters.put("orgId", currentUserInfo.get("organizationId")); | 
|---|
|  |  |  | if (userName != null) { | 
|---|
|  |  |  | queryWrapper.like("user_name", userName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String, Object>> users = userMapper.selectUsers(parameters); | 
|---|
|  |  |  | resultMap.put("users", users); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | if (mobile != null) { | 
|---|
|  |  |  | queryWrapper.like("mobile", mobile); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (email != null) { | 
|---|
|  |  |  | queryWrapper.like("email", email); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (wechat != null) { | 
|---|
|  |  |  | queryWrapper.like("wechat", wechat); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //分页参数 | 
|---|
|  |  |  | if (!parameters.containsKey("page")) { | 
|---|
|  |  |  | parameters.put("page", 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!parameters.containsKey("size")) { | 
|---|
|  |  |  | parameters.put("size", 10); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int page = Integer.parseInt(parameters.get("page").toString()); | 
|---|
|  |  |  | int size = Integer.parseInt(parameters.get("size").toString()); | 
|---|
|  |  |  | Page<User> pageData = new Page<>(page, size); | 
|---|
|  |  |  | //排序参数,默认id升序 | 
|---|
|  |  |  | if (order == null) { | 
|---|
|  |  |  | queryWrapper.orderByAsc("id"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.orderByAsc(order.toString(), "id"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Page<User> userPage = userMapper.selectPage(pageData, queryWrapper); | 
|---|
|  |  |  | pageData.setRecords(userPage.getRecords()); | 
|---|
|  |  |  | return userPage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | AND gm.menu_id = m.id | 
|---|
|  |  |  | AND ug.is_delete = 0 | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | FROM `menu` m, `organization_menu` om | 
|---|
|  |  |  | WHERE om.organization_id = #{orgId} | 
|---|
|  |  |  | AND m.id = om.menu_id | 
|---|
|  |  |  | AND om.channel = 1 | 
|---|
|  |  |  | AND om.menu_id = m.id | 
|---|
|  |  |  | AND om.is_delete = 0 | 
|---|
|  |  |  | AND m.is_delete = 0 | 
|---|
|  |  |  | ORDER  by m.`order` | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | 
|---|
|  |  |  | WHERE u.account = #{account} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="selectUsers" resultType="java.util.Map"> | 
|---|
|  |  |  | SELECT id,account,user_name userName,email,mobile,wechat FROM `user` WHERE | 
|---|
|  |  |  | <if test="orgId!=null"> | 
|---|
|  |  |  | organization_id = #{orgId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | <if test="userId!=null"> | 
|---|
|  |  |  | id = #{userId} | 
|---|
|  |  |  | </if> | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | </mapper> | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String NOT_DELETE = "0"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Integer WEB_CHANNEL = 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | EMAIL_INVALID(-10,"邮箱无效"), | 
|---|
|  |  |  | ACCOUNT_INVALID(-11,"用户名无效"), | 
|---|
|  |  |  | PASSWORD_INVALID(-12,"密码无效"), | 
|---|
|  |  |  | ACCOUNT_IS_EXPIRE(-13,"用户已过期") | 
|---|
|  |  |  | ACCOUNT_IS_EXPIRE(-13, "用户已过期"), | 
|---|
|  |  |  | GROUP_EXIST(-14, "组已存在") | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | private final Integer code; | 
|---|
|  |  |  | private final String  msg; | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.entity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.IdType; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableName; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.activerecord.Model; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableId; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | @EqualsAndHashCode(callSuper = false) | 
|---|
|  |  |  | @TableName("`group`") | 
|---|
|  |  |  | public class Group extends Model<Group> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final long serialVersionUID = 1L; | 
|---|