diff --git a/README.md b/README.md index d03d08ba..473f16c6 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ ### 项目官网 文档、视频:https://pig4cloud.com +### ChangeLog +https://gitee.com/log4j/pig/wikis/Changelog + ### 配套代码 pig-uipig-config diff --git a/doc/docker/docker-compose.yml b/doc/docker/docker-compose.yml index 4e26b3ce..e93bb964 100644 --- a/doc/docker/docker-compose.yml +++ b/doc/docker/docker-compose.yml @@ -34,6 +34,8 @@ services: context: ./ dockerfile: Dockerfile-auth restart: always + ports: + - 3000:3000 pig-upms-service: links: diff --git a/pig-common/src/main/java/com/github/pig/common/util/exception/ValidateCodeException.java b/pig-common/src/main/java/com/github/pig/common/util/exception/ValidateCodeException.java index d4b53d8c..5c8282a8 100644 --- a/pig-common/src/main/java/com/github/pig/common/util/exception/ValidateCodeException.java +++ b/pig-common/src/main/java/com/github/pig/common/util/exception/ValidateCodeException.java @@ -4,7 +4,7 @@ package com.github.pig.common.util.exception; * @author lengleng * @date 2017年12月21日20:45:38 */ -public class ValidateCodeException extends RuntimeException { +public class ValidateCodeException extends Exception { /** * diff --git a/pig-common/src/main/java/com/github/pig/common/vo/MenuVO.java b/pig-common/src/main/java/com/github/pig/common/vo/MenuVO.java index d1c60378..4e9a0840 100644 --- a/pig-common/src/main/java/com/github/pig/common/vo/MenuVO.java +++ b/pig-common/src/main/java/com/github/pig/common/vo/MenuVO.java @@ -78,11 +78,21 @@ public class MenuVO implements Serializable { @Override public int hashCode() { - return super.hashCode(); + return menuId.hashCode(); } + /** + * menuId 相同则相同 + * + * @param obj + * @return + */ @Override public boolean equals(Object obj) { + if (obj instanceof MenuVO) { + Integer targetMenuId = ((MenuVO) obj).getMenuId(); + return menuId.equals(targetMenuId); + } return super.equals(obj); } } diff --git a/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java b/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java index 8b3b1ece..a03cb571 100644 --- a/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java +++ b/pig-common/src/main/java/com/github/pig/common/vo/UserVO.java @@ -46,7 +46,7 @@ public class UserVO implements Serializable { /** * 简介 */ - private String introduction; + private String phone; /** * 头像 */ diff --git a/pig-common/src/main/resources/logback-spring.xml b/pig-common/src/main/resources/logback-spring.xml index 54f75e40..9dcc51b3 100644 --- a/pig-common/src/main/resources/logback-spring.xml +++ b/pig-common/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + @@ -39,7 +39,7 @@ - + diff --git a/pig-config/src/main/resources/logback-spring.xml b/pig-config/src/main/resources/logback-spring.xml index 54f75e40..62ed754b 100644 --- a/pig-config/src/main/resources/logback-spring.xml +++ b/pig-config/src/main/resources/logback-spring.xml @@ -39,7 +39,7 @@ - + diff --git a/pig-eureka/src/main/resources/logback-spring.xml b/pig-eureka/src/main/resources/logback-spring.xml index 54f75e40..f7a30086 100644 --- a/pig-eureka/src/main/resources/logback-spring.xml +++ b/pig-eureka/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/component/config/ResourceServerConfiguration.java b/pig-gateway/src/main/java/com/github/pig/gateway/component/config/ResourceServerConfiguration.java index d74e188a..9aa3967d 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/component/config/ResourceServerConfiguration.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/component/config/ResourceServerConfiguration.java @@ -34,7 +34,7 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter @Override public void configure(HttpSecurity http) throws Exception { - http.addFilterBefore(validateCodeFilter, UsernamePasswordAuthenticationFilter.class); + //http.addFilterBefore(validateCodeFilter, UsernamePasswordAuthenticationFilter.class); //允许使用iframe 嵌套,避免swagger-ui 不被加载的问题 http.headers().frameOptions().disable(); ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry = http diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java new file mode 100644 index 00000000..b360259c --- /dev/null +++ b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/PreviewFilter.java @@ -0,0 +1,76 @@ +package com.github.pig.gateway.component.filter; + +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.pig.common.constant.CommonConstant; +import com.github.pig.common.constant.SecurityConstants; +import com.github.pig.common.util.R; +import com.github.pig.common.util.exception.CheckedException; +import com.netflix.zuul.ZuulFilter; +import com.netflix.zuul.context.RequestContext; +import com.xiaoleilu.hutool.collection.CollectionUtil; +import com.xiaoleilu.hutool.io.IoUtil; +import com.xiaoleilu.hutool.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; +import org.springframework.http.HttpMethod; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; + +import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER; + +/** + * @author lengleng + * @date 2018年05月10日 + * 演示环境控制 + */ +@Slf4j +@Component +@RefreshScope +public class PreviewFilter extends ZuulFilter { + private static final String TOKEN = "token"; + @Value("${security.validate.preview:true}") + private boolean isPreview; + + @Override + public String filterType() { + return FilterConstants.PRE_TYPE; + } + + @Override + public int filterOrder() { + return Integer.MIN_VALUE; + } + + @Override + public boolean shouldFilter() { + HttpServletRequest request = RequestContext.getCurrentContext().getRequest(); + if (StrUtil.equals(request.getMethod(), HttpMethod.GET.name()) || + StrUtil.containsIgnoreCase(request.getRequestURI(), TOKEN)) { + isPreview = false; + } + return isPreview; + } + + @Override + public Object run() { + log.warn("演示环境,没有权限操作 -> {}", isPreview); + RequestContext ctx = RequestContext.getCurrentContext(); + R result = new R<>(); + result.setCode(479); + result.setMsg("演示环境,没有权限操作"); + + ctx.setResponseStatusCode(479); + ctx.setSendZuulResponse(false); + ctx.getResponse().setContentType("application/json;charset=UTF-8"); + ctx.setResponseBody(JSONObject.toJSONString(result)); + return null; + } +} diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/ValidateCodeFilter.java b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/ValidateCodeFilter.java index f26e88f3..3b349b55 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/ValidateCodeFilter.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/component/filter/ValidateCodeFilter.java @@ -1,77 +1,92 @@ package com.github.pig.gateway.component.filter; +import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.pig.common.constant.CommonConstant; import com.github.pig.common.constant.SecurityConstants; import com.github.pig.common.util.R; import com.github.pig.common.util.exception.ValidateCodeException; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.netflix.zuul.ZuulFilter; +import com.netflix.zuul.context.RequestContext; +import com.xiaoleilu.hutool.util.StrUtil; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; /** * @author lengleng - * @date 2017-12-18 + * @date 2018/5/10 * 验证码校验,true开启,false关闭校验 * 更细化可以 clientId 进行区分 */ +@Slf4j +@RefreshScope @Component("validateCodeFilter") -public class ValidateCodeFilter extends OncePerRequestFilter { - private static final Logger logger = LoggerFactory.getLogger(ValidateCodeFilter.class); - +public class ValidateCodeFilter extends ZuulFilter { private static final String EXPIRED_CAPTCHA_ERROR = "验证码已过期,请重新获取"; @Value("${security.validate.code:true}") private boolean isValidate; @Autowired private RedisTemplate redisTemplate; - @Autowired - private ObjectMapper objectMapper; @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - if (isValidate && (StringUtils.contains(request.getRequestURI(), SecurityConstants.OAUTH_TOKEN_URL) - || StringUtils.contains(request.getRequestURI(), SecurityConstants.MOBILE_TOKEN_URL))) { - PrintWriter printWriter = null; - try { - checkCode(request, response, filterChain); - } catch (ValidateCodeException e) { - logger.info("登录失败:{}", e.getMessage()); - response.setCharacterEncoding(CommonConstant.UTF8); - response.setContentType(CommonConstant.CONTENT_TYPE); - R result = new R<>(e); - response.setStatus(478); - printWriter = response.getWriter(); - printWriter.append(objectMapper.writeValueAsString(result)); - } finally { - IOUtils.closeQuietly(printWriter); - } - } else { - filterChain.doFilter(request, response); - } + public String filterType() { + return FilterConstants.PRE_TYPE; } - private void checkCode(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws IOException, ServletException { + @Override + public int filterOrder() { + return FilterConstants.SEND_ERROR_FILTER_ORDER + 1; + } + + @Override + public boolean shouldFilter() { + HttpServletRequest request = RequestContext.getCurrentContext().getRequest(); + if (isValidate && (StrUtil.containsIgnoreCase(request.getRequestURI(), SecurityConstants.OAUTH_TOKEN_URL) + || StrUtil.containsIgnoreCase(request.getRequestURI(), SecurityConstants.MOBILE_TOKEN_URL))) { + return true; + } + return false; + } + + @Override + public Object run() { + try { + checkCode(RequestContext.getCurrentContext().getRequest()); + } catch (ValidateCodeException e) { + RequestContext ctx = RequestContext.getCurrentContext(); + R result = new R<>(e); + result.setCode(478); + result.setMsg("演示环境,没有权限操作"); + + ctx.setResponseStatusCode(478); + ctx.setSendZuulResponse(false); + ctx.getResponse().setContentType("application/json;charset=UTF-8"); + ctx.setResponseBody(JSONObject.toJSONString(result)); + } + return null; + } + + /** + * 检查code + * + * @param httpServletRequest request + * @throws ValidateCodeException 验证码校验异常 + */ + private void checkCode(HttpServletRequest httpServletRequest) throws ValidateCodeException { String code = httpServletRequest.getParameter("code"); - if (StringUtils.isBlank(code)) { + if (StrUtil.isBlank(code)) { throw new ValidateCodeException("请输入验证码"); } String randomStr = httpServletRequest.getParameter("randomStr"); - if (StringUtils.isBlank(randomStr)) { + if (StrUtil.isBlank(randomStr)) { randomStr = httpServletRequest.getParameter("mobile"); } @@ -87,17 +102,16 @@ public class ValidateCodeFilter extends OncePerRequestFilter { } String saveCode = codeObj.toString(); - if (StringUtils.isBlank(saveCode)) { + if (StrUtil.isBlank(saveCode)) { redisTemplate.delete(key); throw new ValidateCodeException(EXPIRED_CAPTCHA_ERROR); } - if (!StringUtils.equals(saveCode, code)) { + if (!StrUtil.equals(saveCode, code)) { redisTemplate.delete(key); throw new ValidateCodeException("验证码错误,请重新输入"); } redisTemplate.delete(key); - filterChain.doFilter(httpServletRequest, httpServletResponse); } } diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java b/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java index f3d15c59..9f825eca 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/PermissionServiceImpl.java @@ -4,11 +4,11 @@ import com.baomidou.mybatisplus.toolkit.StringUtils; import com.github.pig.common.vo.MenuVO; import com.github.pig.gateway.feign.MenuService; import com.github.pig.gateway.service.PermissionService; +import com.xiaoleilu.hutool.collection.CollUtil; import com.xiaoleilu.hutool.collection.CollectionUtil; import com.xiaoleilu.hutool.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.stereotype.Service; @@ -50,7 +50,10 @@ public class PermissionServiceImpl implements PermissionService { Set urls = new HashSet<>(); for (SimpleGrantedAuthority authority : grantedAuthorityList) { if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) { - CollectionUtil.addAll(urls,menuService.findMenuByRole(authority.getAuthority())); + Set menuVOSet = menuService.findMenuByRole(authority.getAuthority()); + if (CollUtil.isNotEmpty(menuVOSet)) { + CollUtil.addAll(urls, menuVOSet); + } } } diff --git a/pig-modules/pig-sso-client-demo/src/main/resources/logback-spring.xml b/pig-modules/pig-sso-client-demo/src/main/resources/logback-spring.xml index 54f75e40..f7a30086 100644 --- a/pig-modules/pig-sso-client-demo/src/main/resources/logback-spring.xml +++ b/pig-modules/pig-sso-client-demo/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ - + diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java index 9a2f5554..653ef82d 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/DictController.java @@ -3,6 +3,7 @@ package com.github.pig.admin.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; +import com.github.pig.admin.model.dto.RoleDTO; import com.github.pig.admin.model.entity.SysDict; import com.github.pig.admin.service.SysDictService; import com.github.pig.common.constant.CommonConstant; @@ -69,6 +70,18 @@ public class DictController extends BaseController { return sysDictService.selectList(new EntityWrapper<>(condition)); } + /** + * 添加字典 + * + * @param sysDict 字典信息 + * @return success、false + */ + @PostMapping + @CacheEvict(value = "dict_details", key = "#sysDict.type") + public R dict(@RequestBody SysDict sysDict) { + return new R<>(sysDictService.insert(sysDict)); + } + /** * 删除字典,并且清除字典缓存 * @@ -81,4 +94,16 @@ public class DictController extends BaseController { public R deleteDict(@PathVariable Integer id, @PathVariable String type) { return new R<>(sysDictService.deleteById(id)); } + + /** + * 修改字典 + * + * @param sysDict 字典信息 + * @return success/false + */ + @PutMapping + @CacheEvict(value = "dict_details", key = "#sysDict.type") + public R editDict(@RequestBody SysDict sysDict) { + return new R<>(sysDictService.updateById(sysDict)); + } } diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java index 2659db21..59c75e4c 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/MenuController.java @@ -26,14 +26,23 @@ public class MenuController extends BaseController { private SysMenuService sysMenuService; /** - * 通过用户名查询用户菜单 + * 通过角色名称查询用户菜单 * * @param role 角色名称 * @return 菜单列表 */ @GetMapping("/findMenuByRole/{role}") public List findMenuByRole(@PathVariable String role) { - return sysMenuService.findMenuByRole(role); + return sysMenuService.findMenuByRoleName(role); + } + + /** + * 返回当前用户的树形菜单集合 + * @return 当前用户的树形菜单 + */ + @GetMapping(value = "/userMenu") + public List userMenu(){ + return sysMenuService.findUserMenuTree(getRole()); } /** @@ -41,22 +50,13 @@ public class MenuController extends BaseController { * * @return 树形菜单 */ - @GetMapping(value = "/tree") + @GetMapping(value = "/allTree") public List getTree() { SysMenu condition = new SysMenu(); condition.setDelFlag(CommonConstant.STATUS_NORMAL); return getMenuTree(sysMenuService.selectList(new EntityWrapper<>(condition)), -1); } - /** - * 返回当前用户的树形菜单集合 - * @return 当前用户的树形菜单 - */ - @GetMapping(value = "/getUserTree") - public List getUserTree(){ - return sysMenuService.findUserMenuTree(getRole().get(0)); - } - /** * 返回当前用户树形菜单集合 * @@ -64,7 +64,7 @@ public class MenuController extends BaseController { */ @GetMapping("/userTree") public List userTree() { - List menus = sysMenuService.findMenuByRole(getRole().get(0)); + List menus = sysMenuService.findMenuByRoles(getRole()); List menuList = new ArrayList<>(); for (MenuVO menuVo : menus) { menuList.add(menuVo.getMenuId()); @@ -80,7 +80,7 @@ public class MenuController extends BaseController { */ @GetMapping("/roleTree/{roleName}") public List roleTree(@PathVariable String roleName) { - List menus = sysMenuService.findMenuByRole(roleName); + List menus = sysMenuService.findMenuByRoleName(roleName); List menuList = new ArrayList<>(); for (MenuVO menuVo : menus) { menuList.add(menuVo.getMenuId()); @@ -119,17 +119,17 @@ public class MenuController extends BaseController { */ @DeleteMapping("/{id}") public R menuDel(@PathVariable Integer id) { - return new R<>(sysMenuService.deleteMenu(id,getRole().get(0))); + return new R<>(sysMenuService.deleteMenu(id)); } @PutMapping public R menuUpdate(@RequestBody SysMenu sysMenu) { - return new R<>(sysMenuService.updateMenuById(sysMenu,getRole().get(0))); + return new R<>(sysMenuService.updateMenuById(sysMenu)); } private List getMenuTree(List menus, int root) { List trees = new ArrayList(); - MenuTree node = null; + MenuTree node; for (SysMenu menu : menus) { node = new MenuTree(); node.setId(menu.getMenuId()); diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/UserController.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/UserController.java index 548f2530..b3686f3c 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/UserController.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/controller/UserController.java @@ -95,10 +95,14 @@ public class UserController extends BaseController { sysUser.setDelFlag(CommonConstant.STATUS_NORMAL); sysUser.setPassword(ENCODER.encode(userDto.getPassword())); userService.insert(sysUser); - SysUserRole userRole = new SysUserRole(); - userRole.setUserId(sysUser.getUserId()); - userRole.setRoleId(userDto.getRole()); - return new R<>(userRole.insert()); + + userDto.getRole().forEach(roleId -> { + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(sysUser.getUserId()); + userRole.setRoleId(roleId); + userRole.insert(); + }); + return new R<>(Boolean.TRUE); } /** diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/dto/UserDTO.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/dto/UserDTO.java index ce768a69..4c07b192 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/dto/UserDTO.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/dto/UserDTO.java @@ -3,6 +3,8 @@ package com.github.pig.admin.model.dto; import com.github.pig.admin.model.entity.SysUser; import lombok.Data; +import java.util.List; + /** * @author lengleng * @date 2017/11/5 @@ -12,7 +14,7 @@ public class UserDTO extends SysUser { /** * 角色ID */ - private Integer role; + private List role; private Integer deptId; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysUser.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysUser.java index 5e0aa302..bd868b99 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysUser.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/model/entity/SysUser.java @@ -58,7 +58,7 @@ public class SysUser extends Model { /** * 简介 */ - private String introduction; + private String phone; /** * 头像 */ @@ -86,7 +86,7 @@ public class SysUser extends Model { ", createTime=" + createTime + ", updateTime=" + updateTime + ", delFlag='" + delFlag + '\'' + - ", introduction='" + introduction + '\'' + + ", phone='" + phone + '\'' + ", avatar='" + avatar + '\'' + ", deptId=" + deptId + '}'; diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java index 0d61d6f3..348a11c8 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/SysMenuService.java @@ -23,7 +23,7 @@ public interface SysMenuService extends IService { * @param role 角色名称 * @return 菜单列表 */ - List findMenuByRole(String role); + List findMenuByRoleName(String role); /** * 通过角色获取菜单权限列表 @@ -37,24 +37,31 @@ public interface SysMenuService extends IService { * 级联删除菜单 * * @param id 菜单ID - * @param role 角色 + * @param roleList 角色 * @return 成功、失败 */ - Boolean deleteMenu(Integer id, String role); + Boolean deleteMenu(Integer id); /** * 更新菜单信息 * * @param sysMenu 菜单信息 - * @param role 角色 + * @param roleList 角色 * @return 成功、失败 */ - Boolean updateMenuById(SysMenu sysMenu, String role); + Boolean updateMenuById(SysMenu sysMenu); /** * 返回角色的菜单 - * @param roleName 角色 + * @param roleNames 角色 * @return 菜单列表 */ - List findUserMenuTree(String roleName); + List findUserMenuTree(List roleNames); + + /** + * 返回多个角色的菜单 + * @param roleList 角色列表 + * @return 菜单列表 + */ + List findMenuByRoles(List roleList); } diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java index 9fd7126b..9fb732a3 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysMenuServiceImpl.java @@ -36,7 +36,7 @@ public class SysMenuServiceImpl extends ServiceImpl impl @Override @Cacheable(value = "menu_details", key = "#role + '_menu'") - public List findMenuByRole(String role) { + public List findMenuByRoleName(String role) { return sysMenuMapper.findMenuByRoleName(role); } @@ -44,7 +44,7 @@ public class SysMenuServiceImpl extends ServiceImpl impl public String[] findPermission(String[] roles) { Set menuVoSet = new HashSet<>(); for (String role : roles) { - List menuVos = findMenuByRole(role); + List menuVos = findMenuByRoleName(role); menuVoSet.addAll(menuVos); } @@ -60,8 +60,8 @@ public class SysMenuServiceImpl extends ServiceImpl impl } @Override - @CacheEvict(value = "menu_details", key = "#role + '_menu'") - public Boolean deleteMenu(Integer id, String role) { + @CacheEvict(value = "menu_details", allEntries = true) + public Boolean deleteMenu(Integer id) { Assert.isNull(id, "菜单ID不能为空"); // 删除当前节点 SysMenu condition1 = new SysMenu(); @@ -78,21 +78,22 @@ public class SysMenuServiceImpl extends ServiceImpl impl } @Override - @CacheEvict(value = "menu_details", key = "#role + '_menu'") - public Boolean updateMenuById(SysMenu sysMenu, String role) { + @CacheEvict(value = "menu_details", allEntries = true) + public Boolean updateMenuById(SysMenu sysMenu) { return this.updateById(sysMenu); } /** * 返回角色的菜单 * - * @param roleName 角色 + * @param roleNames 角色 * @return 菜单列表 */ @Override - public List findUserMenuTree(String roleName) { + public List findUserMenuTree(List roleNames) { // 获取符合条件得菜单 - List all = findMenuByRole(roleName); + Set all = new HashSet<>(); + roleNames.forEach(roleName -> all.addAll(findMenuByRoleName(roleName))); final List menuTreeList = new ArrayList<>(); all.forEach(menuVo -> { if (CommonConstant.MENU.equals(menuVo.getType())) { @@ -101,4 +102,17 @@ public class SysMenuServiceImpl extends ServiceImpl impl }); return TreeUtil.bulid(menuTreeList, -1); } + + /** + * 返回多个角色的菜单 + * + * @param roleNames 角色列表 + * @return 菜单列表 + */ + @Override + public List findMenuByRoles(List roleNames) { + List all = new ArrayList<>(); + roleNames.forEach(roleName -> all.addAll(findMenuByRoleName(roleName))); + return all; + } } diff --git a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java index e8442ffe..7eb13bcc 100644 --- a/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java +++ b/pig-modules/pig-upms-service/src/main/java/com/github/pig/admin/service/impl/SysUserServiceImpl.java @@ -172,7 +172,7 @@ public class SysUserServiceImpl extends ServiceImpl impl } SysUser params = new SysUser(); - params.setIntroduction(mobile); + params.setPhone(mobile); List userList = this.selectList(new EntityWrapper<>(params)); if (CollectionUtil.isEmpty(userList)) { @@ -225,9 +225,14 @@ public class SysUserServiceImpl extends ServiceImpl impl SysUserRole condition = new SysUserRole(); condition.setUserId(userDto.getUserId()); - SysUserRole sysUserRole = sysUserRoleService.selectOne(new EntityWrapper<>(condition)); - sysUserRole.setRoleId(userDto.getRole()); - return sysUserRoleService.update(sysUserRole, new EntityWrapper<>(condition)); + sysUserRoleService.delete(new EntityWrapper<>(condition)); + userDto.getRole().forEach(roleId -> { + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(sysUser.getUserId()); + userRole.setRoleId(roleId); + userRole.insert(); + }); + return Boolean.TRUE; } /** diff --git a/pig-modules/pig-upms-service/src/main/resources/mapper/SysUserMapper.xml b/pig-modules/pig-upms-service/src/main/resources/mapper/SysUserMapper.xml index baac144f..1dccca5e 100644 --- a/pig-modules/pig-upms-service/src/main/resources/mapper/SysUserMapper.xml +++ b/pig-modules/pig-upms-service/src/main/resources/mapper/SysUserMapper.xml @@ -6,7 +6,7 @@ - + @@ -21,7 +21,7 @@ - + @@ -44,7 +44,7 @@ `user`.username, `user`.`password`, `user`.salt, - `user`.introduction, + `user`.phone, `user`.avatar, `user`.dept_id, `user`.create_time AS ucreate_time, @@ -70,7 +70,7 @@