升级内容详见change log

This commit is contained in:
冷冷 2018-05-12 00:08:18 +08:00
parent 96657347b0
commit ed98813198
22 changed files with 269 additions and 104 deletions

View File

@ -16,6 +16,9 @@
### 项目官网
文档、视频https://pig4cloud.com
### ChangeLog
https://gitee.com/log4j/pig/wikis/Changelog
### 配套代码
<a href="https://gitee.com/log4j/pig-ui" target="_blank">pig-ui</a><a href="https://gitee.com/cqzqxq_lxh/pig-config" target="_blank">pig-config</a>

View File

@ -34,6 +34,8 @@ services:
context: ./
dockerfile: Dockerfile-auth
restart: always
ports:
- 3000:3000
pig-upms-service:
links:

View File

@ -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 {
/**
*

View File

@ -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);
}
}

View File

@ -46,7 +46,7 @@ public class UserVO implements Serializable {
/**
* 简介
*/
private String introduction;
private String phone;
/**
* 头像
*/

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="pig"/>
<property name="log.path" value="/Users/lengleng/work/temp/${spring.application.name}" />
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
@ -39,7 +39,7 @@
</appender>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="ERROR">
<root level="WARN">
<appender-ref ref="console" />
<appender-ref ref="debug" />
<appender-ref ref="error" />

View File

@ -39,7 +39,7 @@
</appender>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="ERROR">
<root level="WARN">
<appender-ref ref="console" />
<appender-ref ref="debug" />
<appender-ref ref="error" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="pig"/>
<property name="log.path" value="/Users/lengleng/work/temp/${spring.application.name}" />
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>

View File

@ -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<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http

View File

@ -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<String> 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;
}
}

View File

@ -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<String> 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<String> 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);
}
}

View File

@ -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<MenuVO> urls = new HashSet<>();
for (SimpleGrantedAuthority authority : grantedAuthorityList) {
if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) {
CollectionUtil.addAll(urls,menuService.findMenuByRole(authority.getAuthority()));
Set<MenuVO> menuVOSet = menuService.findMenuByRole(authority.getAuthority());
if (CollUtil.isNotEmpty(menuVOSet)) {
CollUtil.addAll(urls, menuVOSet);
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="pig"/>
<property name="log.path" value="/Users/lengleng/work/temp/${spring.application.name}" />
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>

View File

@ -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 successfalse
*/
@PostMapping
@CacheEvict(value = "dict_details", key = "#sysDict.type")
public R<Boolean> dict(@RequestBody SysDict sysDict) {
return new R<>(sysDictService.insert(sysDict));
}
/**
* 删除字典并且清除字典缓存
*
@ -81,4 +94,16 @@ public class DictController extends BaseController {
public R<Boolean> 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<Boolean> editDict(@RequestBody SysDict sysDict) {
return new R<>(sysDictService.updateById(sysDict));
}
}

View File

@ -26,14 +26,23 @@ public class MenuController extends BaseController {
private SysMenuService sysMenuService;
/**
* 通过用户名查询用户菜单
* 通过角色名称查询用户菜单
*
* @param role 角色名称
* @return 菜单列表
*/
@GetMapping("/findMenuByRole/{role}")
public List<MenuVO> findMenuByRole(@PathVariable String role) {
return sysMenuService.findMenuByRole(role);
return sysMenuService.findMenuByRoleName(role);
}
/**
* 返回当前用户的树形菜单集合
* @return 当前用户的树形菜单
*/
@GetMapping(value = "/userMenu")
public List<MenuTree> userMenu(){
return sysMenuService.findUserMenuTree(getRole());
}
/**
@ -41,22 +50,13 @@ public class MenuController extends BaseController {
*
* @return 树形菜单
*/
@GetMapping(value = "/tree")
@GetMapping(value = "/allTree")
public List<MenuTree> getTree() {
SysMenu condition = new SysMenu();
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
return getMenuTree(sysMenuService.selectList(new EntityWrapper<>(condition)), -1);
}
/**
* 返回当前用户的树形菜单集合
* @return 当前用户的树形菜单
*/
@GetMapping(value = "/getUserTree")
public List<MenuTree> getUserTree(){
return sysMenuService.findUserMenuTree(getRole().get(0));
}
/**
* 返回当前用户树形菜单集合
*
@ -64,7 +64,7 @@ public class MenuController extends BaseController {
*/
@GetMapping("/userTree")
public List<Integer> userTree() {
List<MenuVO> menus = sysMenuService.findMenuByRole(getRole().get(0));
List<MenuVO> menus = sysMenuService.findMenuByRoles(getRole());
List<Integer> 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<Integer> roleTree(@PathVariable String roleName) {
List<MenuVO> menus = sysMenuService.findMenuByRole(roleName);
List<MenuVO> menus = sysMenuService.findMenuByRoleName(roleName);
List<Integer> menuList = new ArrayList<>();
for (MenuVO menuVo : menus) {
menuList.add(menuVo.getMenuId());
@ -119,17 +119,17 @@ public class MenuController extends BaseController {
*/
@DeleteMapping("/{id}")
public R<Boolean> menuDel(@PathVariable Integer id) {
return new R<>(sysMenuService.deleteMenu(id,getRole().get(0)));
return new R<>(sysMenuService.deleteMenu(id));
}
@PutMapping
public R<Boolean> menuUpdate(@RequestBody SysMenu sysMenu) {
return new R<>(sysMenuService.updateMenuById(sysMenu,getRole().get(0)));
return new R<>(sysMenuService.updateMenuById(sysMenu));
}
private List<MenuTree> getMenuTree(List<SysMenu> menus, int root) {
List<MenuTree> trees = new ArrayList<MenuTree>();
MenuTree node = null;
MenuTree node;
for (SysMenu menu : menus) {
node = new MenuTree();
node.setId(menu.getMenuId());

View File

@ -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);
}
/**

View File

@ -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<Integer> role;
private Integer deptId;

View File

@ -58,7 +58,7 @@ public class SysUser extends Model<SysUser> {
/**
* 简介
*/
private String introduction;
private String phone;
/**
* 头像
*/
@ -86,7 +86,7 @@ public class SysUser extends Model<SysUser> {
", createTime=" + createTime +
", updateTime=" + updateTime +
", delFlag='" + delFlag + '\'' +
", introduction='" + introduction + '\'' +
", phone='" + phone + '\'' +
", avatar='" + avatar + '\'' +
", deptId=" + deptId +
'}';

View File

@ -23,7 +23,7 @@ public interface SysMenuService extends IService<SysMenu> {
* @param role 角色名称
* @return 菜单列表
*/
List<MenuVO> findMenuByRole(String role);
List<MenuVO> findMenuByRoleName(String role);
/**
* 通过角色获取菜单权限列表
@ -37,24 +37,31 @@ public interface SysMenuService extends IService<SysMenu> {
* 级联删除菜单
*
* @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<MenuTree> findUserMenuTree(String roleName);
List<MenuTree> findUserMenuTree(List<String> roleNames);
/**
* 返回多个角色的菜单
* @param roleList 角色列表
* @return 菜单列表
*/
List<MenuVO> findMenuByRoles(List<String> roleList);
}

View File

@ -36,7 +36,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
@Cacheable(value = "menu_details", key = "#role + '_menu'")
public List<MenuVO> findMenuByRole(String role) {
public List<MenuVO> findMenuByRoleName(String role) {
return sysMenuMapper.findMenuByRoleName(role);
}
@ -44,7 +44,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
public String[] findPermission(String[] roles) {
Set<MenuVO> menuVoSet = new HashSet<>();
for (String role : roles) {
List<MenuVO> menuVos = findMenuByRole(role);
List<MenuVO> menuVos = findMenuByRoleName(role);
menuVoSet.addAll(menuVos);
}
@ -60,8 +60,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> 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<SysMenuMapper, SysMenu> 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<MenuTree> findUserMenuTree(String roleName) {
public List<MenuTree> findUserMenuTree(List<String> roleNames) {
// 获取符合条件得菜单
List<MenuVO> all = findMenuByRole(roleName);
Set<MenuVO> all = new HashSet<>();
roleNames.forEach(roleName -> all.addAll(findMenuByRoleName(roleName)));
final List<MenuTree> menuTreeList = new ArrayList<>();
all.forEach(menuVo -> {
if (CommonConstant.MENU.equals(menuVo.getType())) {
@ -101,4 +102,17 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
});
return TreeUtil.bulid(menuTreeList, -1);
}
/**
* 返回多个角色的菜单
*
* @param roleNames 角色列表
* @return 菜单列表
*/
@Override
public List<MenuVO> findMenuByRoles(List<String> roleNames) {
List<MenuVO> all = new ArrayList<>();
roleNames.forEach(roleName -> all.addAll(findMenuByRoleName(roleName)));
return all;
}
}

View File

@ -172,7 +172,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
SysUser params = new SysUser();
params.setIntroduction(mobile);
params.setPhone(mobile);
List<SysUser> userList = this.selectList(new EntityWrapper<>(params));
if (CollectionUtil.isEmpty(userList)) {
@ -225,9 +225,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> 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;
}
/**

View File

@ -6,7 +6,7 @@
<id column="user_id" property="userId"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="introduction" property="introduction" />
<result column="phone" property="phone" />
<result column="avatar" property="avatar" />
<result column="salt" property="salt"/>
<result column="dept_id" property="deptId"/>
@ -21,7 +21,7 @@
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="salt" property="salt"/>
<result column="introduction" property="introduction" />
<result column="phone" property="phone" />
<result column="avatar" property="avatar" />
<result column="ucreate_time" property="createTime"/>
<result column="uupdate_time" property="updateTime"/>
@ -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 @@
<select id="selectUserVoByMobile" resultMap="userVoResultMap">
<include refid="selectUserVo"/>
WHERE `user`.introduction = #{mobile}
WHERE `user`.phone = #{mobile}
</select>
<select id="selectUserVoByOpenId" resultMap="userVoResultMap">
@ -84,7 +84,7 @@
`user`.username,
`user`.`password`,
`user`.salt,
`user`.introduction,
`user`.phone,
`user`.avatar,
`user`.create_time AS ucreate_time,
`user`.update_time AS uupdate_time,
@ -112,7 +112,7 @@
`user`.username,
`user`.`password`,
`user`.salt,
`user`.introduction,
`user`.phone,
`user`.avatar,
`user`.create_time AS ucreate_time,
`user`.update_time AS uupdate_time,