# Conflicts: # src/main/java/com/yipin/liuwanr/controller/UserInfoController.java # src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java # src/main/java/com/yipin/liuwanr/service/UserInfoService.javamaster
commit
affc2a7e0b
28 changed files with 930 additions and 39 deletions
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.controller; |
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
import org.springframework.stereotype.Controller; |
||||
|
||||
/** |
||||
* <p> |
||||
* 菜单权限表 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("/sys-permission") |
||||
public class SysPermissionController { |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.controller; |
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
import org.springframework.stereotype.Controller; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色表 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("/sys-role") |
||||
public class SysRoleController { |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.controller; |
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
import org.springframework.stereotype.Controller; |
||||
|
||||
/** |
||||
* <p> |
||||
* 角色权限中间表 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("/sys-role-permission") |
||||
public class SysRolePermissionController { |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.controller; |
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
import org.springframework.stereotype.Controller; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色中间表 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Controller |
||||
@RequestMapping("/sys-user-role") |
||||
public class SysUserRoleController { |
||||
|
||||
} |
@ -0,0 +1,99 @@ |
||||
package com.yipin.liuwanr.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import java.util.Date; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.fasterxml.jackson.annotation.JsonInclude; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 菜单权限表 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Data |
||||
@TableName("sys_permission") |
||||
public class SysPermission implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 权限标识符 |
||||
*/ |
||||
private String code; |
||||
|
||||
/** |
||||
* 名称 |
||||
*/ |
||||
private String name; |
||||
|
||||
/** |
||||
* 父权限id |
||||
*/ |
||||
private Long parentId; |
||||
|
||||
/** |
||||
* 层级 |
||||
*/ |
||||
private Integer level; |
||||
|
||||
/** |
||||
* 是否是菜单:1、是,0、不是(0目前为按钮) |
||||
*/ |
||||
private Integer menuOrNot; |
||||
|
||||
/** |
||||
* 状态:0、启用,1、禁用 |
||||
*/ |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 路径 |
||||
*/ |
||||
private String url; |
||||
|
||||
/** |
||||
* 页面路径 |
||||
*/ |
||||
private String menuUrl; |
||||
|
||||
/** |
||||
* 排序 |
||||
*/ |
||||
private Integer sort; |
||||
|
||||
/** |
||||
* 图标 |
||||
*/ |
||||
private String icon; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 更新时间 |
||||
*/ |
||||
private Date motifyTime; |
||||
/** |
||||
* 子权限 |
||||
*/ |
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY) |
||||
@TableField(exist = false) |
||||
private List<SysPermission> children; |
||||
} |
@ -0,0 +1,120 @@ |
||||
package com.yipin.liuwanr.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import java.util.Date; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色表 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@TableName("sys_role") |
||||
public class SysRole implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 角色名称 |
||||
*/ |
||||
private String name; |
||||
|
||||
/** |
||||
* 角色描述 |
||||
*/ |
||||
private String description; |
||||
|
||||
/** |
||||
* 是否删除:0、未删除,1、删除 |
||||
*/ |
||||
private Integer delOrNot; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 更新时间 |
||||
*/ |
||||
private Date motifyTime; |
||||
|
||||
/** |
||||
* 编码 |
||||
*/ |
||||
private String code; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
public void setDescription(String description) { |
||||
this.description = description; |
||||
} |
||||
public Integer getDelOrNot() { |
||||
return delOrNot; |
||||
} |
||||
|
||||
public void setDelOrNot(Integer delOrNot) { |
||||
this.delOrNot = delOrNot; |
||||
} |
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
public Date getMotifyTime() { |
||||
return motifyTime; |
||||
} |
||||
|
||||
public void setMotifyTime(Date motifyTime) { |
||||
this.motifyTime = motifyTime; |
||||
} |
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "SysRole{" + |
||||
"id=" + id + |
||||
", name=" + name + |
||||
", description=" + description + |
||||
", delOrNot=" + delOrNot + |
||||
", createTime=" + createTime + |
||||
", motifyTime=" + motifyTime + |
||||
", code=" + code + |
||||
"}"; |
||||
} |
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.yipin.liuwanr.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* <p> |
||||
* 角色权限中间表 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@TableName("sys_role_permission") |
||||
public class SysRolePermission implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 角色id |
||||
*/ |
||||
private Long roleId; |
||||
|
||||
/** |
||||
* 权限id |
||||
*/ |
||||
private Long permissionId; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
public Long getRoleId() { |
||||
return roleId; |
||||
} |
||||
|
||||
public void setRoleId(Long roleId) { |
||||
this.roleId = roleId; |
||||
} |
||||
public Long getPermissionId() { |
||||
return permissionId; |
||||
} |
||||
|
||||
public void setPermissionId(Long permissionId) { |
||||
this.permissionId = permissionId; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "SysRolePermission{" + |
||||
"id=" + id + |
||||
", roleId=" + roleId + |
||||
", permissionId=" + permissionId + |
||||
"}"; |
||||
} |
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.yipin.liuwanr.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色中间表 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@TableName("sys_user_role") |
||||
public class SysUserRole implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Long id; |
||||
|
||||
/** |
||||
* 用户id |
||||
*/ |
||||
private Long userId; |
||||
|
||||
/** |
||||
* 角色id |
||||
*/ |
||||
private Long roleId; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
public Long getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(Long userId) { |
||||
this.userId = userId; |
||||
} |
||||
public Long getRoleId() { |
||||
return roleId; |
||||
} |
||||
|
||||
public void setRoleId(Long roleId) { |
||||
this.roleId = roleId; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "SysUserRole{" + |
||||
"id=" + id + |
||||
", userId=" + userId + |
||||
", roleId=" + roleId + |
||||
"}"; |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
package com.yipin.liuwanr.mapper; |
||||
|
||||
import com.yipin.liuwanr.entity.SysPermission; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 菜单权限表 Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
public interface SysPermissionMapper extends BaseMapper<SysPermission> { |
||||
@Select({"<script>", |
||||
" select id,code,name,parent_id as parentId,level,menu_or_not as menuOrNot," + |
||||
"status,url,menu_url as menuUrl,sort,icon,create_time as createTime,motify_time as motifyTime from sys_permission\n" + |
||||
" where id in\n" + |
||||
" <foreach collection=\"ids\" open=\"(\" separator=\",\" close=\")\" item=\"id\">\n" + |
||||
" #{id}\n" + |
||||
" </foreach>", |
||||
"</script> "}) |
||||
List<SysPermission> queryPermissionsByIds(@Param("ids")List<Long> ids); |
||||
} |
@ -0,0 +1,18 @@ |
||||
package com.yipin.liuwanr.mapper; |
||||
|
||||
import com.yipin.liuwanr.entity.SysRole; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色表 Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Mapper |
||||
public interface SysRoleMapper extends BaseMapper<SysRole> { |
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
package com.yipin.liuwanr.mapper; |
||||
|
||||
import com.yipin.liuwanr.entity.Project_Management; |
||||
import com.yipin.liuwanr.entity.SysRolePermission; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 角色权限中间表 Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> { |
||||
|
||||
@Select({"<script>", |
||||
" select permission_id as permissionId from sys_role_permission\n" + |
||||
" where role_id in\n" + |
||||
" <foreach collection=\"ids\" open=\"(\" separator=\",\" close=\")\" item=\"id\">\n" + |
||||
" #{id}\n" + |
||||
" </foreach>", |
||||
"</script> "}) |
||||
List<SysRolePermission> queryPermissionsByRoleIds(@Param("ids") List<Long> ids); |
||||
} |
@ -0,0 +1,18 @@ |
||||
package com.yipin.liuwanr.mapper; |
||||
|
||||
import com.yipin.liuwanr.entity.SysUserRole; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色中间表 Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Mapper |
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> { |
||||
|
||||
} |
@ -0,0 +1,18 @@ |
||||
package com.yipin.liuwanr.service; |
||||
|
||||
import com.yipin.liuwanr.entity.SysPermission; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <p> |
||||
* 菜单权限表 服务类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
public interface ISysPermissionService extends IService<SysPermission> { |
||||
List getPermission(String roleIds); |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.yipin.liuwanr.service; |
||||
|
||||
import com.yipin.liuwanr.entity.SysRolePermission; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
/** |
||||
* <p> |
||||
* 角色权限中间表 服务类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
public interface ISysRolePermissionService extends IService<SysRolePermission> { |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.yipin.liuwanr.service; |
||||
|
||||
import com.yipin.liuwanr.entity.SysRole; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色表 服务类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
public interface ISysRoleService extends IService<SysRole> { |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.yipin.liuwanr.service; |
||||
|
||||
import com.yipin.liuwanr.entity.SysUserRole; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色中间表 服务类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
public interface ISysUserRoleService extends IService<SysUserRole> { |
||||
|
||||
} |
@ -0,0 +1,72 @@ |
||||
package com.yipin.liuwanr.service.impl; |
||||
|
||||
import com.yipin.liuwanr.entity.SysPermission; |
||||
import com.yipin.liuwanr.entity.SysRolePermission; |
||||
import com.yipin.liuwanr.mapper.SysPermissionMapper; |
||||
import com.yipin.liuwanr.mapper.SysRolePermissionMapper; |
||||
import com.yipin.liuwanr.service.ISysPermissionService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.apache.commons.beanutils.ConvertUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* <p> |
||||
* 菜单权限表 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Service |
||||
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService { |
||||
@Resource |
||||
private SysRolePermissionMapper rolePermissionMapper; |
||||
|
||||
@Resource |
||||
private SysPermissionMapper permissionMapper; |
||||
|
||||
@Override |
||||
public List getPermission(String roleIds) { |
||||
//截取字符串
|
||||
String[] strArr = roleIds.split(","); |
||||
//转换long类型的数组
|
||||
Long[] strArrNum = (Long[]) ConvertUtils.convert(strArr,Long.class); |
||||
|
||||
//根据角色id查询对应的权限id
|
||||
List<SysRolePermission> rolePermissionList = rolePermissionMapper.queryPermissionsByRoleIds(Arrays.asList(strArrNum)); |
||||
List<Long> permissionList = new ArrayList(); |
||||
for(SysRolePermission res : rolePermissionList){ |
||||
permissionList.add(res.getPermissionId()); |
||||
} |
||||
|
||||
if(permissionList.size()>0){ |
||||
Long[] permissionIds = permissionList.toArray(new Long[permissionList.size()]); |
||||
//根据权限ids查询对应权限
|
||||
List<SysPermission> permissionEntityList = permissionMapper.queryPermissionsByIds(Arrays.asList(permissionIds)); |
||||
return getListDepartmentAndEmployeeTree(permissionEntityList, 0L); |
||||
}else{ |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
|
||||
private List<SysPermission> getListDepartmentAndEmployeeTree(List<SysPermission> list, Long parentId) { |
||||
return list.stream() |
||||
.filter(dept -> parentId.equals(dept.getParentId())) // 过滤出部门id为所选id的部门信息(也为递归的结果条件,找不到所对应的部门id)
|
||||
.peek(dept -> { |
||||
dept.setChildren(getListDepartmentAndEmployeeTree(list, dept.getId())); // 设置该部门的子部门:递归调用
|
||||
|
||||
//SysPermission permission = permissionService.getById(dept.getId());
|
||||
/*dept.setUserDept(employeeDao.employeeListByDeptId(dept.getId(),account));*/ |
||||
}) |
||||
.sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) // 根据所选排序信息进行排序
|
||||
.collect(Collectors.toList()); |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.service.impl; |
||||
|
||||
import com.yipin.liuwanr.entity.SysRolePermission; |
||||
import com.yipin.liuwanr.mapper.SysRolePermissionMapper; |
||||
import com.yipin.liuwanr.service.ISysRolePermissionService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* <p> |
||||
* 角色权限中间表 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Service |
||||
public class SysRolePermissionServiceImpl extends ServiceImpl<SysRolePermissionMapper, SysRolePermission> implements ISysRolePermissionService { |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.service.impl; |
||||
|
||||
import com.yipin.liuwanr.entity.SysRole; |
||||
import com.yipin.liuwanr.mapper.SysRoleMapper; |
||||
import com.yipin.liuwanr.service.ISysRoleService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色表 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Service |
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService { |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.yipin.liuwanr.service.impl; |
||||
|
||||
import com.yipin.liuwanr.entity.SysUserRole; |
||||
import com.yipin.liuwanr.mapper.SysUserRoleMapper; |
||||
import com.yipin.liuwanr.service.ISysUserRoleService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* <p> |
||||
* 用户角色中间表 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author Qyq |
||||
* @since 2021-02-26 |
||||
*/ |
||||
@Service |
||||
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService { |
||||
|
||||
} |
@ -0,0 +1,115 @@ |
||||
package com.yipin.liuwanr.util; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool; |
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
||||
import com.baomidou.mybatisplus.generator.AutoGenerator; |
||||
import com.baomidou.mybatisplus.generator.InjectionConfig; |
||||
import com.baomidou.mybatisplus.generator.config.*; |
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType; |
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; |
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: LvFang |
||||
* @Date: Created in 2019/6/11. |
||||
* @Description: |
||||
*/ |
||||
public class MyBatisPlusCodeGenerator { |
||||
|
||||
//包名
|
||||
public static final String PACKAGE_NAME = "com.yipin.liuwanr"; |
||||
|
||||
public static void main(String[] args) { |
||||
String[] tables = new String[] {"sys_permission","sys_role","sys_role_permission","sys_user_role"};//表名数组
|
||||
String[] tablePrefixs = new String[] {""};//去掉前缀
|
||||
executeCode(PACKAGE_NAME,tables,tablePrefixs); |
||||
} |
||||
|
||||
private static void executeCode(String pack, String[] tables, String[] tablePrefixs) { |
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator(); |
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig(); |
||||
// 是否覆盖已有文件
|
||||
gc.setFileOverride(false); |
||||
// 生成文件的输出目录
|
||||
String projectPath = System.getProperty("user.dir");//user.dir 表示当前工程路径无需替换
|
||||
gc.setOutputDir(projectPath + "/src/main/java"); |
||||
//设置bean命名规范
|
||||
gc.setEntityName("%s"); |
||||
// 开发人员
|
||||
gc.setAuthor("Qyq"); |
||||
// 是否打开输出目录
|
||||
gc.setOpen(false); |
||||
// 开启 BaseResultMap
|
||||
gc.setBaseResultMap(true); |
||||
// 指定生成的主键的ID类型
|
||||
gc.setIdType(IdType.ID_WORKER); |
||||
// 时间类型对应策略: 只使用 java.util.date 代替
|
||||
gc.setDateType(DateType.ONLY_DATE); |
||||
mpg.setGlobalConfig(gc); |
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig config= new DataSourceConfig(); |
||||
// 从试图获取
|
||||
config.setUrl("jdbc:mysql://localhost:3306/msdw_tms?serverTimezone=UTC"); |
||||
config.setDriverName("com.mysql.cj.jdbc.Driver"); |
||||
config.setUsername("root"); |
||||
config.setPassword("root"); |
||||
mpg.setDataSource(config); |
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig(); |
||||
// 父包名。如果为空,将下面子包名必须写全部, 否则就只需写子包名
|
||||
pc.setParent(pack); |
||||
// Entity包名
|
||||
pc.setEntity("entity"); |
||||
mpg.setPackageInfo(pc); |
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() { |
||||
@Override |
||||
public void initMap() { |
||||
// to do nothing
|
||||
} |
||||
}; |
||||
List<FileOutConfig> focList = new ArrayList<>(); |
||||
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") { |
||||
public String outputFile(TableInfo tableInfo) { |
||||
// 自定义输入文件名称
|
||||
if (StringUtils.isEmpty(pc.getModuleName())) { |
||||
return projectPath + "/src/main/resources/mapper/tms/" + tableInfo.getXmlName() + StringPool.DOT_XML; |
||||
}else { |
||||
return projectPath + "/src/main/resources/mapper/tms/" + pc.getModuleName() + "/" + tableInfo.getXmlName() + StringPool.DOT_XML; |
||||
} |
||||
} |
||||
}); |
||||
cfg.setFileOutConfigList(focList); |
||||
mpg.setCfg(cfg); |
||||
mpg.setTemplate(new TemplateConfig().setXml(null)); |
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig(); |
||||
// 数据库表映射到实体的命名策略: 下划线转驼峰命名
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel); |
||||
// 数据库表字段映射到实体的命名策略: 下划线转驼峰命名
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel); |
||||
// 【实体】是否为lombok模型(默认 false)
|
||||
strategy.setEntityLombokModel(false); |
||||
// 需要包含的表名,允许正则表达式(与exclude二选一配置)
|
||||
strategy.setInclude(tables); |
||||
// 驼峰转连字符
|
||||
strategy.setControllerMappingHyphenStyle(true); |
||||
// 表前缀
|
||||
strategy.setTablePrefix(tablePrefixs); |
||||
mpg.setStrategy(strategy); |
||||
mpg.setTemplateEngine(new FreemarkerTemplateEngine()); |
||||
mpg.execute(); |
||||
} |
||||
} |
Loading…
Reference in new issue