mirror of https://github.com/elunez/eladmin
2.0 抢先版,主要更新了#71 | #IWYE2
parent
90c2bf906b
commit
784d670c54
|
@ -1,4 +1,4 @@
|
|||
### IntelliJ IDEA ###
|
||||
### IDEA ###
|
||||
.idea/*
|
||||
*.iml
|
||||
*/target/*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>eladmin</artifactId>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@ public class SwaggerConfig {
|
|||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("elune 接口文档")
|
||||
.version("1.7")
|
||||
.title("eladmin 接口文档")
|
||||
.version("2.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>eladmin</artifactId>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
|||
<dependency>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<artifactId>eladmin-common</artifactId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--模板引擎-->
|
||||
|
|
|
@ -34,6 +34,9 @@ public class GenConfig {
|
|||
/** 作者 **/
|
||||
private String author;
|
||||
|
||||
/** 表前缀 **/
|
||||
private String prefix;
|
||||
|
||||
/** 是否覆盖 **/
|
||||
private Boolean cover;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.template.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.domain.GenConfig;
|
||||
|
@ -75,9 +76,16 @@ public class GenUtil {
|
|||
map.put("date", LocalDate.now().toString());
|
||||
map.put("tableName",tableName);
|
||||
String className = StringUtils.toCapitalizeCamelCase(tableName);
|
||||
String changeClassName = StringUtils.toCamelCase(tableName);
|
||||
|
||||
// 判断是否去除表前缀
|
||||
if (StringUtils.isNotEmpty(genConfig.getPrefix())) {
|
||||
className = StringUtils.toCapitalizeCamelCase(StrUtil.removePrefix(tableName,genConfig.getPrefix()));
|
||||
changeClassName = StringUtils.toCamelCase(StrUtil.removePrefix(tableName,genConfig.getPrefix()));
|
||||
}
|
||||
map.put("className", className);
|
||||
map.put("upperCaseClassName", className.toUpperCase());
|
||||
map.put("changeClassName", StringUtils.toCamelCase(tableName));
|
||||
map.put("changeClassName", changeClassName);
|
||||
map.put("hasTimestamp",false);
|
||||
map.put("hasBigDecimal",false);
|
||||
map.put("hasQuery",false);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>eladmin</artifactId>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
|||
<dependency>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<artifactId>eladmin-common</artifactId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -4,6 +4,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +15,7 @@ import java.sql.Timestamp;
|
|||
@Data
|
||||
@Table(name = "log")
|
||||
@NoArgsConstructor
|
||||
public class Log {
|
||||
public class Log implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
|
|
@ -21,4 +21,7 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
|
|||
*/
|
||||
@Query(value = "select count(*) FROM (select request_ip FROM log where create_time between ?1 and ?2 GROUP BY request_ip) as s",nativeQuery = true)
|
||||
Long findIp(String date1, String date2);
|
||||
|
||||
@Query(value = "select exception_detail FROM log where id = ?1",nativeQuery = true)
|
||||
String findExceptionById(Long id);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package me.zhengjie.rest;
|
||||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.service.LogService;
|
||||
import me.zhengjie.service.query.LogQueryService;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -9,6 +10,7 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -23,6 +25,9 @@ public class LogController {
|
|||
@Autowired
|
||||
private LogQueryService logQueryService;
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
@GetMapping(value = "/logs")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getLogs(Log log, Pageable pageable){
|
||||
|
@ -43,4 +48,10 @@ public class LogController {
|
|||
log.setLogType("ERROR");
|
||||
return new ResponseEntity(logQueryService.queryAll(log,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logs/error/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN')")
|
||||
public ResponseEntity getErrorLogs(@PathVariable Long id){
|
||||
return new ResponseEntity(logService.findByErrDetail(id), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,11 @@ public interface LogService {
|
|||
*/
|
||||
@Async
|
||||
void save(ProceedingJoinPoint joinPoint, Log log);
|
||||
|
||||
/**
|
||||
* 查询异常详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Object findByErrDetail(Long id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
public class LogErrorDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 操作用户
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 方法名
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 请求ip
|
||||
*/
|
||||
private String requestIp;
|
||||
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private Timestamp createTime;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package me.zhengjie.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
public class LogSmallDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 请求ip
|
||||
*/
|
||||
private String requestIp;
|
||||
|
||||
/**
|
||||
* 请求耗时
|
||||
*/
|
||||
private Long time;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private Timestamp createTime;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package me.zhengjie.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.repository.LogRepository;
|
||||
|
@ -79,4 +80,9 @@ public class LogServiceImpl implements LogService {
|
|||
log.setParams(params + " }");
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findByErrDetail(Long id) {
|
||||
return Dict.create().set("exception",logRepository.findExceptionById(id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package me.zhengjie.service.mapper;
|
||||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.mapper.EntityMapper;
|
||||
import me.zhengjie.service.dto.LogErrorDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogErrorMapper extends EntityMapper<LogErrorDTO, Log> {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package me.zhengjie.service.mapper;
|
||||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.mapper.EntityMapper;
|
||||
import me.zhengjie.service.dto.LogSmallDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogSmallMapper extends EntityMapper<LogSmallDTO, Log> {
|
||||
|
||||
}
|
|
@ -2,6 +2,9 @@ package me.zhengjie.service.query;
|
|||
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.repository.LogRepository;
|
||||
import me.zhengjie.service.mapper.LogErrorMapper;
|
||||
import me.zhengjie.service.mapper.LogSmallMapper;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -16,6 +19,7 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.persistence.criteria.Root;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -28,7 +32,20 @@ public class LogQueryService {
|
|||
@Autowired
|
||||
private LogRepository logRepository;
|
||||
|
||||
public Page queryAll(Log log, Pageable pageable){
|
||||
@Autowired
|
||||
private LogErrorMapper logErrorMapper;
|
||||
|
||||
@Autowired
|
||||
private LogSmallMapper logSmallMapper;
|
||||
|
||||
public Object queryAll(Log log, Pageable pageable){
|
||||
Page<Log> page = logRepository.findAll(new Spec(log),pageable);
|
||||
if (!ObjectUtils.isEmpty(log.getUsername())) {
|
||||
return PageUtil.toPage(page.map(logSmallMapper::toDto));
|
||||
}
|
||||
if (log.getLogType().equals("ERROR")) {
|
||||
return PageUtil.toPage(page.map(logErrorMapper::toDto));
|
||||
}
|
||||
return logRepository.findAll(new Spec(log),pageable);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>eladmin</artifactId>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
|||
<dependency>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<artifactId>eladmin-generator</artifactId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<dependency>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<artifactId>eladmin-tools</artifactId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--jwt-->
|
||||
|
@ -53,6 +53,7 @@
|
|||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package me.zhengjie.config;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.service.DeptService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.DeptDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -35,15 +36,15 @@ public class DataScope {
|
|||
|
||||
public Set<Long> getDeptIds() {
|
||||
|
||||
User user = userService.findByName(SecurityUtils.getUsername());
|
||||
UserDTO user = userService.findByName(SecurityUtils.getUsername());
|
||||
|
||||
// 用于存储部门id
|
||||
Set<Long> deptIds = new HashSet<>();
|
||||
|
||||
// 查询用户角色
|
||||
List<Role> roleSet = roleService.findByUsers_Id(user.getId());
|
||||
List<RoleSmallDTO> roleSet = roleService.findByUsers_Id(user.getId());
|
||||
|
||||
for (Role role : roleSet) {
|
||||
for (RoleSmallDTO role : roleSet) {
|
||||
|
||||
if (scopeType[0].equals(role.getDataScope())) {
|
||||
return new HashSet<>() ;
|
||||
|
@ -56,8 +57,8 @@ public class DataScope {
|
|||
|
||||
// 存储自定义的数据权限
|
||||
if (scopeType[2].equals(role.getDataScope())) {
|
||||
Set<Dept> deptList = role.getDepts();
|
||||
for (Dept dept : deptList) {
|
||||
Set<Dept> depts = deptService.findByRoleIds(role.getId());
|
||||
for (Dept dept : depts) {
|
||||
deptIds.add(dept.getId());
|
||||
List<Dept> deptChildren = deptService.findByPid(dept.getId());
|
||||
if (deptChildren != null && deptChildren.size() != 0) {
|
||||
|
|
|
@ -52,14 +52,13 @@ public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
|
|||
|
||||
// It is not compelling necessary to load the use details from the database. You could also store the information
|
||||
// in the token and read it from it. It's up to you ;)
|
||||
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
|
||||
JwtUser userDetails = (JwtUser)this.userDetailsService.loadUserByUsername(username);
|
||||
|
||||
// For simple validation it is completely sufficient to just check the token integrity. You don't have to call
|
||||
// the database compellingly. Again it's up to you ;)
|
||||
if (jwtTokenUtil.validateToken(authToken, userDetails)) {
|
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
|
||||
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
||||
log.info("authorizated user '{}', setting security context", username);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package me.zhengjie.modules.security.service;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -26,7 +26,7 @@ public class JwtPermissionService {
|
|||
* @return
|
||||
*/
|
||||
@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||
public Collection<GrantedAuthority> mapToGrantedAuthorities(User user) {
|
||||
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDTO user) {
|
||||
|
||||
System.out.println("--------------------loadPermissionByUser:" + user.getUsername() + "---------------------");
|
||||
|
||||
|
|
|
@ -2,25 +2,18 @@ package me.zhengjie.modules.security.service;
|
|||
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.domain.*;
|
||||
import me.zhengjie.exception.EntityNotFoundException;
|
||||
import me.zhengjie.modules.system.repository.PermissionRepository;
|
||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
import me.zhengjie.modules.security.security.JwtUser;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.DeptDTO;
|
||||
import me.zhengjie.modules.system.service.dto.JobDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -39,7 +32,7 @@ public class JwtUserDetailsService implements UserDetailsService {
|
|||
@Override
|
||||
public UserDetails loadUserByUsername(String username){
|
||||
|
||||
User user = userService.findByName(username);
|
||||
UserDTO user = userService.findByName(username);
|
||||
if (user == null) {
|
||||
throw new BadRequestException("账号不存在");
|
||||
} else {
|
||||
|
@ -47,7 +40,7 @@ public class JwtUserDetailsService implements UserDetailsService {
|
|||
}
|
||||
}
|
||||
|
||||
public UserDetails createJwtUser(User user) {
|
||||
public UserDetails createJwtUser(UserDTO user) {
|
||||
return new JwtUser(
|
||||
user.getId(),
|
||||
user.getUsername(),
|
||||
|
@ -55,8 +48,8 @@ public class JwtUserDetailsService implements UserDetailsService {
|
|||
user.getAvatar(),
|
||||
user.getEmail(),
|
||||
user.getPhone(),
|
||||
Optional.ofNullable(user.getDept()).map(Dept::getName).orElse(null),
|
||||
Optional.ofNullable(user.getJob()).map(Job::getName).orElse(null),
|
||||
Optional.ofNullable(user.getDept()).map(DeptDTO::getName).orElse(null),
|
||||
Optional.ofNullable(user.getJob()).map(JobDTO::getName).orElse(null),
|
||||
permissionService.mapToGrantedAuthorities(user),
|
||||
user.getEnabled(),
|
||||
user.getCreateTime(),
|
||||
|
|
|
@ -45,6 +45,10 @@ public class Dept implements Serializable {
|
|||
@NotNull
|
||||
private Long pid;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToMany(mappedBy = "depts")
|
||||
private Set<Role> roles;
|
||||
|
||||
@Column(name = "create_time")
|
||||
@CreationTimestamp
|
||||
private Timestamp createTime;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.zhengjie.modules.system.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.zhengjie.modules.system.repository;
|
|||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -19,4 +20,9 @@ public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificat
|
|||
* @return
|
||||
*/
|
||||
List<Dept> findByPid(Long id);
|
||||
|
||||
@Query(value = "select name from dept where id = ?1",nativeQuery = true)
|
||||
String findNameById(Long id);
|
||||
|
||||
Set<Dept> findByRoles_Id(Long id);
|
||||
}
|
|
@ -8,6 +8,7 @@ import me.zhengjie.modules.system.service.MenuService;
|
|||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.UserService;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.UserDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.MenuMapper;
|
||||
import me.zhengjie.modules.system.service.query.MenuQueryService;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
|
@ -50,7 +51,7 @@ public class MenuController {
|
|||
*/
|
||||
@GetMapping(value = "/menus/build")
|
||||
public ResponseEntity buildMenus(){
|
||||
User user = userService.findByName(SecurityUtils.getUsername());
|
||||
UserDTO user = userService.findByName(SecurityUtils.getUsername());
|
||||
List<MenuDTO> menuDTOList = menuService.findByRoles(roleService.findByUsers_Id(user.getId()));
|
||||
List<MenuDTO> menuDTOTree = (List<MenuDTO>)menuService.buildTree(menuDTOList).get("content");
|
||||
return new ResponseEntity(menuService.buildMenus(menuDTOTree),HttpStatus.OK);
|
||||
|
|
|
@ -7,6 +7,7 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.modules.system.domain.User;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.query.RoleQueryService;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -71,7 +72,7 @@ public class RoleController {
|
|||
|
||||
@GetMapping(value = "/roles/level")
|
||||
public ResponseEntity getLevel(){
|
||||
List<Integer> levels = roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(Role::getLevel).collect(Collectors.toList());
|
||||
List<Integer> levels = roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList());
|
||||
return new ResponseEntity(Dict.create().set("level", Collections.min(levels)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import me.zhengjie.modules.system.domain.User;
|
|||
import me.zhengjie.exception.BadRequestException;
|
||||
import me.zhengjie.modules.system.service.DeptService;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.service.PictureService;
|
||||
import me.zhengjie.service.VerificationCodeService;
|
||||
import me.zhengjie.utils.*;
|
||||
|
@ -119,8 +120,8 @@ public class UserController {
|
|||
@DeleteMapping(value = "/users/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','USER_ALL','USER_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Long id){
|
||||
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||
Integer optLevel = Collections.min(roleService.findByUsers_Id(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
|
||||
Integer optLevel = Collections.min(roleService.findByUsers_Id(id).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
|
||||
|
||||
if (currentLevel > optLevel) {
|
||||
throw new BadRequestException("角色权限不足");
|
||||
|
@ -196,7 +197,7 @@ public class UserController {
|
|||
* @param resources
|
||||
*/
|
||||
private void checkLevel(User resources) {
|
||||
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
|
||||
Integer optLevel = roleService.findByRoles(resources.getRoles());
|
||||
if (currentLevel > optLevel) {
|
||||
throw new BadRequestException("角色权限不足");
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.cache.annotation.CacheEvict;
|
|||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
|
@ -60,4 +61,6 @@ public interface DeptService {
|
|||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
List<Dept> findByPid(long pid);
|
||||
|
||||
Set<Dept> findByRoleIds(Long id);
|
||||
}
|
|
@ -3,6 +3,7 @@ package me.zhengjie.modules.system.service;
|
|||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -74,7 +75,7 @@ public interface MenuService {
|
|||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
List<MenuDTO> findByRoles(List<Role> roles);
|
||||
List<MenuDTO> findByRoles(List<RoleSmallDTO> roles);
|
||||
|
||||
/**
|
||||
* buildMenus
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.zhengjie.modules.system.service;
|
|||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -54,7 +55,7 @@ public interface RoleService {
|
|||
* @return
|
||||
*/
|
||||
@Cacheable(key = "'findByUsers_Id:' + #p0")
|
||||
List<Role> findByUsers_Id(Long id);
|
||||
List<RoleSmallDTO> findByUsers_Id(Long id);
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
Integer findByRoles(Set<Role> roles);
|
||||
|
|
|
@ -50,7 +50,7 @@ public interface UserService {
|
|||
* @return
|
||||
*/
|
||||
@Cacheable(key = "'loadUserByUsername:'+#p0")
|
||||
User findByName(String userName);
|
||||
UserDTO findByName(String userName);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
|
|
|
@ -35,6 +35,11 @@ public class JobDTO implements Serializable {
|
|||
|
||||
private DeptDTO dept;
|
||||
|
||||
/**
|
||||
* 如果分公司存在相同部门,则显示上级部门名称
|
||||
*/
|
||||
private String deptSuperiorName;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package me.zhengjie.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Data
|
||||
public class RoleSmallDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer level;
|
||||
|
||||
private String dataScope;
|
||||
}
|
|
@ -36,7 +36,7 @@ public class UserDTO implements Serializable {
|
|||
private Date lastPasswordResetTime;
|
||||
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Set<RoleDTO> roles;
|
||||
private Set<RoleSmallDTO> roles;
|
||||
|
||||
@ApiModelProperty(hidden = true)
|
||||
private JobDTO job;
|
||||
|
|
|
@ -42,10 +42,16 @@ public class DeptServiceImpl implements DeptService {
|
|||
return deptRepository.findByPid(pid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Dept> findByRoleIds(Long id) {
|
||||
return deptRepository.findByRoles_Id(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object buildTree(List<DeptDTO> deptDTOS) {
|
||||
Set<DeptDTO> trees = new LinkedHashSet<>();
|
||||
Set<DeptDTO> depts= new LinkedHashSet<>();
|
||||
List<String> deptNames = deptDTOS.stream().map(DeptDTO::getName).collect(Collectors.toList());
|
||||
Boolean isChild;
|
||||
for (DeptDTO deptDTO : deptDTOS) {
|
||||
isChild = false;
|
||||
|
@ -61,9 +67,10 @@ public class DeptServiceImpl implements DeptService {
|
|||
deptDTO.getChildren().add(it);
|
||||
}
|
||||
}
|
||||
if(isChild) {
|
||||
if(isChild)
|
||||
depts.add(deptDTO);
|
||||
else if(!deptNames.contains(deptRepository.findNameById(deptDTO.getPid())))
|
||||
depts.add(deptDTO);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(trees)) {
|
||||
|
|
|
@ -2,7 +2,6 @@ package me.zhengjie.modules.system.service.impl;
|
|||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import me.zhengjie.modules.system.domain.Menu;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.domain.vo.MenuMetaVo;
|
||||
import me.zhengjie.modules.system.domain.vo.MenuVo;
|
||||
import me.zhengjie.exception.BadRequestException;
|
||||
|
@ -10,6 +9,7 @@ import me.zhengjie.exception.EntityExistException;
|
|||
import me.zhengjie.modules.system.repository.MenuRepository;
|
||||
import me.zhengjie.modules.system.service.MenuService;
|
||||
import me.zhengjie.modules.system.service.dto.MenuDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.MenuMapper;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -37,9 +37,9 @@ public class MenuServiceImpl implements MenuService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDTO> findByRoles(List<Role> roles) {
|
||||
public List<MenuDTO> findByRoles(List<RoleSmallDTO> roles) {
|
||||
Set<Menu> menus = new LinkedHashSet<>();
|
||||
for (Role role : roles) {
|
||||
for (RoleSmallDTO role : roles) {
|
||||
List<Menu> menus1 = menuRepository.findByRoles_IdOrderBySortAsc(role.getId()).stream().collect(Collectors.toList());
|
||||
menus.addAll(menus1);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ import me.zhengjie.exception.EntityExistException;
|
|||
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||
import me.zhengjie.modules.system.service.RoleService;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import me.zhengjie.modules.system.service.mapper.RoleMapper;
|
||||
import me.zhengjie.modules.system.service.mapper.RoleSmallMapper;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -30,6 +32,9 @@ public class RoleServiceImpl implements RoleService {
|
|||
@Autowired
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
@Autowired
|
||||
private RoleSmallMapper roleSmallMapper;
|
||||
|
||||
@Override
|
||||
public RoleDTO findById(long id) {
|
||||
Optional<Role> role = roleRepository.findById(id);
|
||||
|
@ -100,8 +105,8 @@ public class RoleServiceImpl implements RoleService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Role> findByUsers_Id(Long id) {
|
||||
return roleRepository.findByUsers_Id(id).stream().collect(Collectors.toList());
|
||||
public List<RoleSmallDTO> findByUsers_Id(Long id) {
|
||||
return roleSmallMapper.toDto(roleRepository.findByUsers_Id(id).stream().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -102,18 +102,17 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public User findByName(String userName) {
|
||||
public UserDTO findByName(String userName) {
|
||||
User user = null;
|
||||
if(ValidationUtil.isEmail(userName)){
|
||||
user = userRepository.findByEmail(userName);
|
||||
} else {
|
||||
user = userRepository.findByUsername(userName);
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
throw new EntityNotFoundException(User.class, "name", userName);
|
||||
} else {
|
||||
return user;
|
||||
return userMapper.toDto(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import me.zhengjie.mapper.EntityMapper;
|
|||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.service.dto.JobDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
|
@ -13,4 +14,6 @@ import org.mapstruct.ReportingPolicy;
|
|||
@Mapper(componentModel = "spring",uses = {DeptMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface JobMapper extends EntityMapper<JobDTO, Job> {
|
||||
|
||||
@Mapping(source = "deptSuperiorName", target = "deptSuperiorName")
|
||||
JobDTO toDto(Job job, String deptSuperiorName);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package me.zhengjie.modules.system.service.mapper;
|
||||
|
||||
import me.zhengjie.mapper.EntityMapper;
|
||||
import me.zhengjie.modules.system.domain.Role;
|
||||
import me.zhengjie.modules.system.service.dto.RoleDTO;
|
||||
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author jie
|
||||
* @date 2019-5-23
|
||||
*/
|
||||
@Mapper(componentModel = "spring", uses = {}, unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface RoleSmallMapper extends EntityMapper<RoleSmallDTO, Role> {
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package me.zhengjie.modules.system.service.query;
|
||||
|
||||
import me.zhengjie.modules.system.domain.Dept;
|
||||
import me.zhengjie.modules.system.repository.DeptRepository;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.modules.system.domain.Job;
|
||||
import me.zhengjie.modules.system.service.dto.JobDTO;
|
||||
|
@ -34,13 +35,21 @@ public class JobQueryService {
|
|||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private DeptRepository deptRepository;
|
||||
|
||||
@Autowired
|
||||
private JobMapper jobMapper;
|
||||
|
||||
@Cacheable(keyGenerator = "keyGenerator")
|
||||
public Object queryAll(String name , Boolean enabled, Set<Long> deptIds, Long deptId, Pageable pageable){
|
||||
Page<Job> page = jobRepository.findAll(new Spec(new JobDTO(name,enabled), deptIds, deptId),pageable);
|
||||
return PageUtil.toPage(page.map(jobMapper::toDto));
|
||||
|
||||
List<JobDTO> jobs = new ArrayList<>();
|
||||
for (Job job : page.getContent()) {
|
||||
jobs.add(jobMapper.toDto(job,deptRepository.findNameById(job.getDept().getPid())));
|
||||
}
|
||||
return PageUtil.toPage(jobs,page.getTotalElements());
|
||||
}
|
||||
|
||||
class Spec implements Specification<Job> {
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.springframework.transaction.annotation.Propagation;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.persistence.criteria.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -32,8 +32,6 @@ spring:
|
|||
stat-view-servlet:
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
login-username: admin
|
||||
login-password: 123456
|
||||
|
||||
web-stat-filter:
|
||||
url-pattern: /*
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
server:
|
||||
port: 8000
|
||||
|
||||
# actuator 配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
# env 环境属性
|
||||
# heapdump 应用的 JVM 堆信息
|
||||
# metrics 应用程序度量信息
|
||||
include: env,health,heapdump,metrics
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
|
@ -37,7 +47,6 @@ spring:
|
|||
#连接超时时间
|
||||
timeout: 5000
|
||||
|
||||
|
||||
#七牛云
|
||||
qiniu:
|
||||
# 文件大小 /M
|
||||
|
|
|
@ -74,13 +74,13 @@ public class ${className}QueryService {
|
|||
/**
|
||||
* 模糊
|
||||
*/
|
||||
list.add(cb.like(root.get("${column.columnName}").as(${column.columnType}.class),"%"+${changeClassName}.get${column.capitalColumnName}()+"%"));
|
||||
list.add(cb.like(root.get("${column.changeColumnName}").as(${column.columnType}.class),"%"+${changeClassName}.get${column.capitalColumnName}()+"%"));
|
||||
</#if>
|
||||
<#if column.columnQuery = '2'>
|
||||
/**
|
||||
* 精确
|
||||
*/
|
||||
list.add(cb.equal(root.get("${column.columnName}").as(${column.columnType}.class),${changeClassName}.get${column.capitalColumnName}()));
|
||||
list.add(cb.equal(root.get("${column.changeColumnName}").as(${column.columnType}.class),${changeClassName}.get${column.capitalColumnName}()));
|
||||
</#if>
|
||||
}
|
||||
</#list>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<#if columns??>
|
||||
<#list columns as column>
|
||||
<#if column.changeColumnName != '${pkChangeColName}'>
|
||||
<el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>">
|
||||
<el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnKey = 'UNI'>prop="${column.changeColumnName}"</#if>>
|
||||
<el-input v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
||||
</el-form-item>
|
||||
</#if>
|
||||
|
@ -40,6 +40,15 @@ export default {
|
|||
${column.changeColumnName}: ''<#if column_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
},
|
||||
rules: {
|
||||
<#list columns as column>
|
||||
<#if column.columnKey = 'UNI'>
|
||||
${column.changeColumnName}: [
|
||||
{ required: true, message: 'please enter', trigger: 'blur' }
|
||||
]<#if (column_has_next)>,</#if>
|
||||
</#if>
|
||||
</#list>
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>eladmin</artifactId>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
|||
<dependency>
|
||||
<groupId>me.zhengjie</groupId>
|
||||
<artifactId>eladmin-logging</artifactId>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--邮件依赖-->
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -7,7 +7,7 @@
|
|||
<groupId>me.zhengjie</groupId>
|
||||
<artifactId>eladmin</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.9</version>
|
||||
<version>2.0</version>
|
||||
|
||||
<modules>
|
||||
<module>eladmin-common</module>
|
||||
|
@ -48,10 +48,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.boot</groupId>-->
|
||||
<!--<artifactId>spring-boot-starter-actuator</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
|
Loading…
Reference in New Issue