Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	screen-common/src/main/java/com/moral/constant/Constants.java
#	screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java
#	screen-manage/src/main/resources/application-dev.yml
	
		
		2 files added
	
		
		34 files modified
	
	
 
	
	
	
	
	
	
	
	
|  |  |  | 
|---|
|  |  |  | <scope>test</scope> | 
|---|
|  |  |  | </dependency> | 
|---|
|  |  |  | <dependency> | 
|---|
|  |  |  | <groupId>com.github.penggle</groupId> | 
|---|
|  |  |  | <groupId>com.google.code.kaptcha</groupId> | 
|---|
|  |  |  | <artifactId>kaptcha</artifactId> | 
|---|
|  |  |  | <version>2.3.2</version> | 
|---|
|  |  |  | </dependency> | 
|---|
|  |  |  | 
|---|
|  |  |  | public void addInterceptors(InterceptorRegistry registry) { | 
|---|
|  |  |  | registry.addInterceptor(new AuthenticationInterceptor()) | 
|---|
|  |  |  | .addPathPatterns("/**") | 
|---|
|  |  |  | .excludePathPatterns("/**/login/**", "/**/logout/**", "/swagger-ui.html/**", "/swagger-resources/**"); | 
|---|
|  |  |  | .excludePathPatterns("/**/login/**", "/**/logout/**", "/swagger-ui.html/**", "/swagger-resources/**","/**/verificationCode/**","/**/user/**"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| 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 javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | 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 com.moral.api.entity.Group; | 
|---|
|  |  |  | import com.moral.api.service.GroupService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.SysConfig; | 
|---|
|  |  |  | import com.moral.api.service.SysConfigService; | 
|---|
|  |  |  | import com.moral.api.service.UserService; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"登陆"}) | 
|---|
|  |  |  | 
|---|
|  |  |  | 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") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "login", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage login(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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 = "注销") | 
|---|
|  |  |  | @ApiOperation(value = "退出", notes = "退出") | 
|---|
|  |  |  | @RequestMapping(value = "logout", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage logout(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | if (!parameters.containsKey("uid")) { | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "uid", value = "用户id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public ResultMessage logout(String uid, HttpServletRequest request) { | 
|---|
|  |  |  | if (uid == null) { | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String userId = parameters.get("uid").toString(); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | TokenUtils.destoryToken(userId, token); | 
|---|
|  |  |  | TokenUtils.destoryToken(uid, token); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 获取验证码是否开启 | 
|---|
|  |  |  | * @Param: [] | 
|---|
|  |  |  | * @return: com.moral.constant.ResultMessage | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/3/18 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取验证码是否开启", notes = "获取验证码是否开启") | 
|---|
|  |  |  | @RequestMapping(value = "verificationCode/config", method = RequestMethod.GET) | 
|---|
|  |  |  | public void verifyConfig(HttpServletResponse response) { | 
|---|
|  |  |  | QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("type", Constants.VERIFICATION_TYPE); | 
|---|
|  |  |  | SysConfig sysConfig = sysConfigService.getOne(queryWrapper); | 
|---|
|  |  |  | String code = sysConfig.getCode(); | 
|---|
|  |  |  | if (Constants.VERIFICATION_OPEN_CODE.equals(code)) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | response.sendRedirect("/verificationCode/get"); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultMessage.fail(msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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("groupId")) { | 
|---|
|  |  |  | 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(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 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 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "添加账户", notes = "添加账户") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "account", value = "账户,长度6-10", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "password", value = "密码,长度6-20", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "userName", value = "账户名称", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "email", value = "邮箱,格式123456@qq.com", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "mobile", value = "手机号,1开头11为数字", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "wechat", value = "微信", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "addUser", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage addUser(User user, HttpServletRequest request) { | 
|---|
|  |  |  | public ResultMessage addUser(@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()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "删除账户", notes = "删除账户") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "deleteUser", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage deleteUser(String userId) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "修改账户信息", notes = "修改账户信息") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "account", value = "账户,长度6-10", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "password", value = "密码,长度6-20", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "userName", value = "账户名称", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "email", value = "邮箱,格式123456@qq.com", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "mobile", value = "手机号,1开头11位数字", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "wechat", value = "微信", required = false, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "updateUser", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage updateUser(User user, HttpServletRequest request) { | 
|---|
|  |  |  | if (user.getAccount().isEmpty() || user.getPassword().isEmpty()) { | 
|---|
|  |  |  | public ResultMessage updateUser(@RequestBody User user, HttpServletRequest request) { | 
|---|
|  |  |  | 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.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> login(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> getMenus(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> addUser(User user, String token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void deleteUser(User user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.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")); | 
|---|
|  |  |  | groupMenuMapper.insert(groupMenu); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | group.setOrganizationId(orgId); | 
|---|
|  |  |  | groupMapper.insert(group); | 
|---|
|  |  |  | resultMap.put("flag", true); | 
|---|
|  |  |  | resultMap.put("msg", "添加成功"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | resultMap.put("flag", false); | 
|---|
|  |  |  | resultMap.put("msg", "添加失败,组已存在"); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | group.setOrganizationId(orgId); | 
|---|
|  |  |  | groupMapper.insert(group); | 
|---|
|  |  |  | 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 { | 
|---|
|  |  |  | queryWrapper.orderByAsc(order.toString(), "id"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Page<Group> groupPage = groupMapper.selectPage(pageData, queryWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | pageData.setRecords(groupPage.getRecords()); | 
|---|
|  |  |  | return groupPage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | 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 UserService userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> selectMenusByOrgId(Integer orgId) { | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("orgId",orgId); | 
|---|
|  |  |  | return userService.getMenus(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | //校验密码 | 
|---|
|  |  |  | String password = parameters.get("password").toString(); | 
|---|
|  |  |  | //密码解密 | 
|---|
|  |  |  | //password = AESUtils.decrypt(password, AESKey); | 
|---|
|  |  |  | password = AESUtils.decrypt(password, AESKey); | 
|---|
|  |  |  | if (!MD5Utils.saltMD5Verify(password, userBo.getPassword())) { | 
|---|
|  |  |  | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); | 
|---|
|  |  |  | 
|---|
|  |  |  | userInfo.put("organizationName", organization.getName()); | 
|---|
|  |  |  | userInfo.put("locationLevel", organization.getLocationLevel()); | 
|---|
|  |  |  | userInfo.put("groups", groups); | 
|---|
|  |  |  | userInfo.putAll(getMenus(userBo.getId())); | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("userId", userBo.getId()); | 
|---|
|  |  |  | userInfo.putAll(getMenus(map)); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //生成token,并存入redis | 
|---|
|  |  |  | String token = TokenUtils.getToken(userBo.getId().toString(), userInfo); | 
|---|
|  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //根据userId获取用户层级菜单 | 
|---|
|  |  |  | private Map<String, Object> getMenus(int userId) { | 
|---|
|  |  |  | List<Menu> allMenus = menuMapper.selectUserMenu(userId); | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, Object> getMenus(Map<String, Object> parameters) { | 
|---|
|  |  |  | List<Menu> allMenus; | 
|---|
|  |  |  | if (parameters.containsKey("userId")) { | 
|---|
|  |  |  | allMenus = menuMapper.selectUserMenu(Integer.parseInt(parameters.get("userId").toString())); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | allMenus = menuMapper.selectOrganizationMenu(Integer.parseInt(parameters.get("orgId").toString())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> resultMap = new LinkedHashMap<>(); | 
|---|
|  |  |  | //第一级菜单 | 
|---|
|  |  |  | List<Menu> oneMenu = allMenus.stream() | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取用户层级菜单递归方法 | 
|---|
|  |  |  | private 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()); | 
|---|
|  |  |  | //筛选出下一级菜单信息 | 
|---|
|  |  |  | 
|---|
|  |  |  | menuMap.put("menus", getMenusByRecursion(o, menus)); | 
|---|
|  |  |  | list.add(menuMap); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | resultList.add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //密码加密 | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | //逻辑删除用户 | 
|---|
|  |  |  | String userId = user.getId().toString(); | 
|---|
|  |  |  | //逻辑删除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", userId); | 
|---|
|  |  |  | //更新redis | 
|---|
|  |  |  | if (TokenUtils.hHasKey(userId)) { | 
|---|
|  |  |  | String token = TokenUtils.hget(userId).toString(); | 
|---|
|  |  |  | TokenUtils.destoryToken(userId, token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //正则校验密码 | 
|---|
|  |  |  | String password = user.getPassword(); | 
|---|
|  |  |  | //密码解密 | 
|---|
|  |  |  | //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; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //正则校验手机号 | 
|---|
|  |  |  | if (user.getMobile() != null && !RegexUtils.checkMobile(user.getMobile())) { | 
|---|
|  |  |  | 
|---|
|  |  |  | result.put("msg", ResponseCodeEnum.MOBILE_INVALID.getMsg()); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //密码加密 | 
|---|
|  |  |  | //密码MD5加密 | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | //当前账户的过期时间 | 
|---|
|  |  |  | Date currentUserExpireTime = (Date) currentUserInfo.get("expireTime"); | 
|---|
|  |  |  | if (userExpireTime == null || userExpireTime.getTime() > currentUserExpireTime.getTime()) { | 
|---|
|  |  |  | user.setExpireTime(currentUserExpireTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新redis | 
|---|
|  |  |  | String userId = user.getId().toString(); | 
|---|
|  |  |  | if (TokenUtils.hHasKey(userId)) { | 
|---|
|  |  |  | String deleterToken = TokenUtils.hget(userId).toString(); | 
|---|
|  |  |  | TokenUtils.destoryToken(userId, deleterToken); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userMapper.updateById(user); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 Integer DELETE_CHILDREN_ORG = 1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Integer WEB_CHANNEL = 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | ORGANIZATION_PARENT_NOT_EXIST(-16,"父组织不存在"), | 
|---|
|  |  |  | PHONE_INVALID(-17,"电话号无效"), | 
|---|
|  |  |  | TIME_FORMAT_INVALID(-18,"时间格式无效"), | 
|---|
|  |  |  | TIME_INVALID(-19,"时间无效") | 
|---|
|  |  |  | TIME_INVALID(-19,"时间无效"), | 
|---|
|  |  |  | GROUP_EXIST(-20, "组已存在"), | 
|---|
|  |  |  | ROLE_IS_EXPIRE(-21, "用户名无效"), | 
|---|
|  |  |  | ROLE_IS_NULL(-22, "密码无效"), | 
|---|
|  |  |  | MENU_IS_EXPIRE(-23, "用户已过期"), | 
|---|
|  |  |  | MENU_IS_NULL(-24, "组已存在"), | 
|---|
|  |  |  | PARAMETERS_NOT_REQUIREMENT(-25, "参数不符合要求") | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | private final Integer code; | 
|---|
|  |  |  | private final String  msg; | 
|---|
|  |  |  | 
|---|
|  |  |  | //token有效期 单位:秒 | 
|---|
|  |  |  | private static final int validity_time = 60*30; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断user_token里有没有用户的token | 
|---|
|  |  |  | public static boolean hHasKey(String uid){ | 
|---|
|  |  |  | return redisTemplate.opsForHash().hasKey("user_token",uid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //根据用户id获取token | 
|---|
|  |  |  | public static Object hget(String uid){ | 
|---|
|  |  |  | return redisTemplate.opsForHash().get("user_token",uid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 生成token,并且将用户信息存入缓存 | 
|---|
|  |  |  | * @Param: [uid] type: 后台取值:manage  前台取值:api | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.service.ManageMenuService; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"菜单"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/manage") | 
|---|
|  |  |  | @RequestMapping("/menu") | 
|---|
|  |  |  | public class ManageMenuController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (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<ManageMenu> result = manageMenuService.getAllWithPagingQuery(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "菜单模糊查询", notes = "菜单模糊查询") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getManageMenuByNameFuzzy", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getManageMenuByNameFuzzy(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (parameters.get("name") == 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<ManageMenu> re = manageMenuService.getManageMenuByNameFuzzy(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(re); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.ManageMenu; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.service.ManageMenuService; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleMenuService; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.moral.constant.ResultMessage; | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"角色"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/manage") | 
|---|
|  |  |  | @RequestMapping("/role") | 
|---|
|  |  |  | public class ManageRoleController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManageRoleService manageRoleService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ManageRoleMenuService manageRoleMenuService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取所有角色", notes = "获取所有角色") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "getManageRoleByNameFuzzy", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage getManageRoleByNameFuzzy(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = getParametersStartingWith(request, null); | 
|---|
|  |  |  | //ManageRole manageRole = JSON.parseObject(JSON.toJSONString(parameters), ManageRole.class); | 
|---|
|  |  |  | List<ManageRole> re = manageRoleService.getManageRoleByNameFuzzy(parameters); | 
|---|
|  |  |  | return ResultMessage.ok(re); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "更新角色菜单", notes = "更新角色菜单") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "updateRoleMenu", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage updateRoleMenu(HttpServletRequest request) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | int id = Integer.parseInt(parameters.get("id").toString()); | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | //list.add(1); | 
|---|
|  |  |  | //list.add(2); | 
|---|
|  |  |  | list.add(3); | 
|---|
|  |  |  | list.add(4); | 
|---|
|  |  |  | list.add(5); | 
|---|
|  |  |  | list.add(6); | 
|---|
|  |  |  | Map<String,Object> re = manageRoleMenuService.updateRoleMenu(list,id); | 
|---|
|  |  |  | return ResultMessage.ok(re); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void updateManageMenuById(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getDataWithPage(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageMenu> getManageRoleByNameFuzzy(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | void insertBatch(@Param("list")List<Map> list); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void updateDeleteStateByMenu_id(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map> getDataByMenuIds(@Param("list")List list,@Param("role_id")int role_id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map> getDataByRoleId(int role_id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | void updateDeleteStateByRoleIdMenuIds(@Param("list")List list,@Param("role_id")int role_id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | Map<String,Object> deleteManageMenu(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | List<ManageMenu> getAllWithPagingQuery(Map map); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | List<ManageMenu> getManageMenuByNameFuzzy(Map map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.entity.ManageRoleMenu; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.IService; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | * @author moral | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public interface ManageRoleMenuService extends IService<ManageRoleMenu> { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | Map<String,Object> updateRoleMenu(List list,int id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.ManageMenu; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageMenuMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.ManageMenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String,Object> insertManageMenu(ManageMenu manageMenu) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (manageMenu.getName()==null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","名称为空!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageMenuMapper.getManageMenuByName(manageMenu.getName()) != null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","该菜单已存在!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.MENU_IS_EXPIRE.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.MENU_IS_EXPIRE.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | manageMenuMapper.insertOne(manageMenu); | 
|---|
|  |  |  | resultMap.put("flag",true); | 
|---|
|  |  |  | resultMap.put("msg","添加成功!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String,Object> updateManageMenu(Map map) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (!map.containsKey("id")){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","未选择更新目标!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())) == null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","该菜单不存在!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.MENU_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.MENU_IS_NULL.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | manageMenuMapper.updateManageMenuById(map); | 
|---|
|  |  |  | resultMap.put("flag",true); | 
|---|
|  |  |  | resultMap.put("msg","更新成功!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String, Object> deleteManageMenu(Map map) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (!map.containsKey("id")){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","未选择删除目标!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageMenuMapper.getManageMenuById(Integer.parseInt(map.get("id").toString())) == null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","该角色不存在或已被删除!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.MENU_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.MENU_IS_NULL.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | Map deleteMap = new HashMap(); | 
|---|
|  |  |  | int id = Integer.parseInt(map.get("id").toString()); | 
|---|
|  |  |  | 
|---|
|  |  |  | Map role_menuDeleteMap = new HashMap(); | 
|---|
|  |  |  | role_menuDeleteMap.put("menu_id",id); | 
|---|
|  |  |  | manageRoleMenuMapper.updateDeleteStateByMenu_id(role_menuDeleteMap); | 
|---|
|  |  |  | resultMap.put("flag",true); | 
|---|
|  |  |  | resultMap.put("msg","删除成功!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ManageMenu> 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); | 
|---|
|  |  |  | System.out.println(manageMenus); | 
|---|
|  |  |  | return manageMenus; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ManageMenu> 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.ManageRoleMenu; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMenuMapper; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleMenuService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class ManageRoleMenuServiceImpl extends ServiceImpl<ManageRoleMenuMapper, ManageRoleMenu> implements ManageRoleMenuService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageRoleMenuMapper manageRoleMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> updateRoleMenu(List list, int id) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (list.size()==0){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<ManageRoleMenu> wrapper = new QueryWrapper(); | 
|---|
|  |  |  | wrapper.eq("role_id",id); | 
|---|
|  |  |  | wrapper.eq("is_delete",0); | 
|---|
|  |  |  | List<Map> result = manageRoleMenuMapper.getDataByMenuIds(list,id); | 
|---|
|  |  |  | List<Map> result1 = manageRoleMenuMapper.getDataByRoleId(id); | 
|---|
|  |  |  | if (manageRoleMenuMapper.selectCount(wrapper)==0 || result.size()==0){ | 
|---|
|  |  |  | List<Map> insertList = new ArrayList<>(); | 
|---|
|  |  |  | for (Object temp:list) { | 
|---|
|  |  |  | Map<String,Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("role_id",id); | 
|---|
|  |  |  | map.put("menu_id",Integer.parseInt(temp.toString())); | 
|---|
|  |  |  | insertList.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manageRoleMenuMapper.insertBatch(insertList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List updateList = new ArrayList(); | 
|---|
|  |  |  | for (Map manageRoleMenu:result1) { | 
|---|
|  |  |  | int have = 1; | 
|---|
|  |  |  | for (Object temp:list){ | 
|---|
|  |  |  | if (manageRoleMenu.get("menu_id").equals(Integer.parseInt(temp.toString()))){ | 
|---|
|  |  |  | have = 2; | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (have == 2){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | updateList.add(manageRoleMenu.get("menu_id")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List insertList = new ArrayList(); | 
|---|
|  |  |  | for (Object temp:list) { | 
|---|
|  |  |  | int have = 1; | 
|---|
|  |  |  | for (Map manageRoleMenu:result1){ | 
|---|
|  |  |  | if (manageRoleMenu.get("menu_id").equals(Integer.parseInt(temp.toString()))){ | 
|---|
|  |  |  | have = 2; | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (have == 2){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | insertList.add(temp); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (updateList.size()>0){ | 
|---|
|  |  |  | manageRoleMenuMapper.updateDeleteStateByRoleIdMenuIds(updateList,id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (insertList.size()>0){ | 
|---|
|  |  |  | List mapList = new ArrayList(); | 
|---|
|  |  |  | for (Object temp:insertList) { | 
|---|
|  |  |  | Map<String,Integer> insertMap = new HashMap<>(); | 
|---|
|  |  |  | insertMap.put("role_id",id); | 
|---|
|  |  |  | insertMap.put("menu_id",Integer.parseInt(temp.toString())); | 
|---|
|  |  |  | mapList.add(insertMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manageRoleMenuMapper.insertBatch(mapList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.domain.Page; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String,Object> insertOne(ManageRole manageRole,List list) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (manageRole.getName()==null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","名称为空!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageRoleMapper.getManageRoleByName(manageRole.getName()) != null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","该角色已存在!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.ROLE_IS_EXPIRE.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.ROLE_IS_EXPIRE.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | manageRoleMapper.insertOne(manageRole); | 
|---|
|  |  |  | resultMap.put("flag",true); | 
|---|
|  |  |  | resultMap.put("msg","添加成功!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); | 
|---|
|  |  |  | if (flag){ | 
|---|
|  |  |  | Integer code = Integer.parseInt(resultMap.get("code").toString()); | 
|---|
|  |  |  | if (code.equals(ResponseCodeEnum.SUCCESS.getCode())){ | 
|---|
|  |  |  | ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName()); | 
|---|
|  |  |  | int role_id = manageRoleIns.getId(); | 
|---|
|  |  |  | System.out.println(role_id); | 
|---|
|  |  |  | List insertList = new ArrayList(); | 
|---|
|  |  |  | for (Object temp: list) { | 
|---|
|  |  |  | Map<String,Integer> insertMap = new HashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | insertMap.put("menu_id",Integer.parseInt(temp.toString())); | 
|---|
|  |  |  | insertList.add(insertMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.out.println(insertList); | 
|---|
|  |  |  | manageRoleMenuMapper.insertBatch(insertList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String,Object> updateManageRole(Map map) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (!map.containsKey("id")){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","未选择更新目标!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","该角色不存在!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | manageRoleMapper.updateManageRoleById(map); | 
|---|
|  |  |  | resultMap.put("flag",true); | 
|---|
|  |  |  | resultMap.put("msg","更新成功!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String, Object> deleteManageRole(Map map) { | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | if (!map.containsKey("id")){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","未选择删除目标!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (manageRoleMapper.getManageRoleById(Integer.parseInt(map.get("id").toString())) == null){ | 
|---|
|  |  |  | resultMap.put("flag",false); | 
|---|
|  |  |  | resultMap.put("msg","该角色不存在或已被删除!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.ROLE_IS_NULL.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.ROLE_IS_NULL.getMsg()); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | ManageRole manageRole = new ManageRole(); | 
|---|
|  |  |  | manageRole.setId(Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<ManageAccountRole> wrapper = new QueryWrapper(); | 
|---|
|  |  |  | wrapper.eq("role_id",Integer.parseInt(map.get("id").toString())); | 
|---|
|  |  |  | manageAccountRoleMapper.update(manageAccountRole,wrapper); | 
|---|
|  |  |  | resultMap.put("flag",true); | 
|---|
|  |  |  | resultMap.put("msg","删除成功!"); | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | - /organization/update | 
|---|
|  |  |  | - /organization/delete | 
|---|
|  |  |  |  | 
|---|
|  |  |  | - /role/getAllManageRole | 
|---|
|  |  |  | - /role/getManageRoleByNameFuzzy | 
|---|
|  |  |  | - /role/updateRoleMenu | 
|---|
|  |  |  | - /menu/getAllManageMenu | 
|---|
|  |  |  | - /menu/getManageMenuByNameFuzzy | 
|---|
|  |  |  | AES: | 
|---|
|  |  |  | KEY: | 
|---|
|  |  |  | AD42F7787B035B7580000EF93BE20BAD | 
|---|
|  |  |  | 
|---|
|  |  |  | where id = #{id} | 
|---|
|  |  |  | </update> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getDataWithPage" parameterType="java.util.Map" resultMap="BaseResultMap"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | from manage_menu mm | 
|---|
|  |  |  | where mm.is_delete = 0 | 
|---|
|  |  |  | limit #{start},#{number} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getManageRoleByNameFuzzy" parameterType="java.util.Map" resultMap="BaseResultMap"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | from manage_menu mm | 
|---|
|  |  |  | where mm.name like concat('%',#{name},'%') | 
|---|
|  |  |  | and mm.is_delete = 0 | 
|---|
|  |  |  | limit #{start},#{number} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </mapper> | 
|---|
|  |  |  | 
|---|
|  |  |  | <result column="is_delete" property="isDelete" /> | 
|---|
|  |  |  | </resultMap> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <sql id="Base_Column_List"> | 
|---|
|  |  |  | mrm.id,mrm.role_id,mrm.menu_id,mrm.create_time,mrm.update_time,mrm.is_delete | 
|---|
|  |  |  | </sql> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <insert id="insertBatch" parameterType="java.util.List"> | 
|---|
|  |  |  | INSERT INTO manage_role_menu(role_id,menu_id) | 
|---|
|  |  |  | values | 
|---|
|  |  |  | 
|---|
|  |  |  | where menu_id = #{menu_id} | 
|---|
|  |  |  | </update> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getDataByMenuIds" parameterType="java.util.List" resultType="java.util.Map"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | from manage_role_menu mrm | 
|---|
|  |  |  | where mrm.menu_id in | 
|---|
|  |  |  | <foreach collection="list" item="item" index="index" open="(" separator="," close=")"> | 
|---|
|  |  |  | #{item} | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | and mrm.role_id = #{role_id} | 
|---|
|  |  |  | and mrm.is_delete = 0 | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getDataByRoleId" resultType="java.util.Map"> | 
|---|
|  |  |  | select | 
|---|
|  |  |  | <include refid="Base_Column_List"></include> | 
|---|
|  |  |  | from manage_role_menu mrm | 
|---|
|  |  |  | where mrm.role_id = #{role_id} | 
|---|
|  |  |  | and mrm.is_delete = 0 | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <update id="updateDeleteStateByRoleIdMenuIds" parameterType="java.util.List"> | 
|---|
|  |  |  | update manage_role_menu | 
|---|
|  |  |  | set is_delete = 1 | 
|---|
|  |  |  | where menu_id in | 
|---|
|  |  |  | <foreach collection="list" item="item" index="index" open="(" separator="," close=")"> | 
|---|
|  |  |  | #{item} | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | and role_id = #{role_id} | 
|---|
|  |  |  | and is_delete = 0 | 
|---|
|  |  |  | </update> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | </mapper> | 
|---|