阿里巴巴代码规范

pull/214/head
dqjdda 2019-11-25 16:43:11 +08:00
parent 6d941c09ef
commit e4ca7afc70
160 changed files with 1588 additions and 726 deletions

View File

@ -8,7 +8,19 @@
<version>2.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<hutool.version>[4.1.12,)</hutool.version>
</properties>
<artifactId>eladmin-common</artifactId>
<name>公共模块</name>
<dependencies>
<!--工具包-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -19,6 +19,9 @@ import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
/**
* @author /
*/
@Aspect
@Component
public class LimitAspect {

View File

@ -18,4 +18,13 @@ public class BaseDTO implements Serializable {
private Timestamp createTime;
private Timestamp updateTime;
@Override
public String toString() {
return "BaseDTO{" +
"isDelete=" + isDelete +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}

View File

@ -19,7 +19,7 @@ import java.lang.reflect.Field;
@MappedSuperclass
public class BaseEntity implements Serializable {
// 删除标识
/** 删除标识 **/
@Column(name = "is_delete", columnDefinition = "bit default 0")
private Boolean isDelete = false;

View File

@ -10,21 +10,29 @@ public interface BaseMapper<D, E> {
/**
* DTOEntity
* @param dto /
* @return /
*/
E toEntity(D dto);
/**
* EntityDTO
* @param entity /
* @return /
*/
D toDto(E entity);
/**
* DTOEntity
* @param dtoList /
* @return /
*/
List <E> toEntity(List<D> dtoList);
/**
* EntityDTO
* @param entityList /
* @return /
*/
List <D> toDto(List<E> entityList);
}

View File

@ -7,6 +7,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Zheng Jie
*/
@Service(value = "el")
public class ElPermissionConfig {

View File

@ -53,6 +53,7 @@ public class RedisConfig extends CachingConfigurerSupport {
return configuration;
}
@SuppressWarnings("all")
@Bean(name = "redisTemplate")
@ConditionalOnMissingBean(name = "redisTemplate")
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
@ -65,13 +66,7 @@ public class RedisConfig extends CachingConfigurerSupport {
// 全局开启AutoType这里方便开发使用全局的方式
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
// 建议使用这种方式,小范围指定白名单
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.domain");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.service.dto");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.service.dto");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.domain");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.quartz.domain");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.monitor.domain");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.security.security");
// ParserConfig.getGlobalInstance().addAccept("me.zhengjie.domain");
// key的序列化采用StringRedisSerializer
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
@ -86,7 +81,7 @@ public class RedisConfig extends CachingConfigurerSupport {
@Override
public KeyGenerator keyGenerator() {
return (target, method, params) -> {
Map<String,Object> container = new HashMap<>();
Map<String,Object> container = new HashMap<>(3);
Class<?> targetClassClass = target.getClass();
// 类地址
container.put("class",targetClassClass.toGenericString());

View File

@ -81,7 +81,8 @@ public class GlobalExceptionHandler {
log.error(ThrowableUtil.getStackTrace(e));
String[] str = Objects.requireNonNull(e.getBindingResult().getAllErrors().get(0).getCodes())[1].split("\\.");
String message = e.getBindingResult().getAllErrors().get(0).getDefaultMessage();
if("不能为空".equals(message)){
String msg = "不能为空";
if(msg.equals(message)){
message = str[1] + ":" + message;
}
return buildResponseEntity(ApiError.error(message));

View File

@ -15,25 +15,46 @@ import java.nio.charset.StandardCharsets;
*/
public class EncryptUtils {
private static String strKey = "Passw0rd", strParam = "Passw0rd";
private static String strParam = "Passw0rd";
private static Cipher cipher;
private static IvParameterSpec iv = new IvParameterSpec(strParam.getBytes(StandardCharsets.UTF_8));
private static DESKeySpec getDesKeySpec(String source) throws Exception {
if (source == null || source.length() == 0){
return null;
}
cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
String strKey = "Passw0rd";
return new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8));
}
/**
*
*/
public static String desEncrypt(String source) throws Exception {
if (source == null || source.length() == 0){
return null;
}
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8));
DESKeySpec desKeySpec = getDesKeySpec(source);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(strParam.getBytes(StandardCharsets.UTF_8));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
return byte2hex(
cipher.doFinal(source.getBytes(StandardCharsets.UTF_8))).toUpperCase();
}
/**
*
*/
public static String desDecrypt(String source) throws Exception {
byte[] src = hex2byte(source.getBytes());
DESKeySpec desKeySpec = getDesKeySpec(source);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] retByte = cipher.doFinal(src);
return new String(retByte);
}
private static String byte2hex(byte[] inStr) {
String stmp;
StringBuilder out = new StringBuilder(inStr.length * 2);
@ -50,35 +71,18 @@ public class EncryptUtils {
}
private static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0){
int size = 2;
if ((b.length % size) != 0){
throw new IllegalArgumentException("长度不是偶数");
}
byte[] b2 = new byte[b.length / 2];
for (int n = 0; n < b.length; n += 2) {
for (int n = 0; n < b.length; n += size) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}
/**
*
*/
public static String desDecrypt(String source) throws Exception {
if (source == null || source.length() == 0){
return null;
}
byte[] src = hex2byte(source.getBytes());
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(strKey.getBytes(StandardCharsets.UTF_8));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(strParam.getBytes(StandardCharsets.UTF_8));
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] retByte = cipher.doFinal(src);
return new String(retByte);
}
/**
*
*/

View File

@ -119,8 +119,9 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
}
OutputStream os = new FileOutputStream(file);
int bytesRead;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
int len = 8192;
byte[] buffer = new byte[len];
while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
@ -210,7 +211,9 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
}
public static void checkSize(long maxSize, long size) {
if(size > (maxSize * 1024 * 1024)){
// 1M
int len = 1024 * 1024;
if(size > (maxSize * len)){
throw new BadRequestException("文件超出规定大小");
}
}

View File

@ -15,7 +15,7 @@ import java.util.*;
@Slf4j
public class QueryHelp {
@SuppressWarnings("unchecked")
@SuppressWarnings("all")
public static <R, Q> Predicate getPredicate(Root<R> root, Q query, CriteriaBuilder cb) {
List<Predicate> list = new ArrayList<>();

View File

@ -15,12 +15,15 @@ import java.util.Calendar;
import java.util.Date;
/**
* @author Zheng Jie
* , org.apache.commons.lang3.StringUtils
*/
public class StringUtils extends org.apache.commons.lang3.StringUtils {
private static final char SEPARATOR = '_';
private static final String UNKNOWN = "unknown";
/**
*
*
@ -111,19 +114,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
*/
public static String getIp(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
if (ip.contains(",")) {
String comma = ",";
String localhost = "127.0.0.1";
if (ip.contains(comma)) {
ip = ip.split(",")[0];
}
if ("127.0.0.1".equals(ip)) {
if (localhost.equals(ip)) {
// 获取本机真正的ip地址
try {
ip = InetAddress.getLocalHost().getHostAddress();
@ -149,7 +154,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
DataBlock dataBlock;
dataBlock = (DataBlock) method.invoke(searcher, ip);
String address = dataBlock.getRegion().replace("0|","");
if(address.charAt(address.length()-1) == '|'){
char symbol = '|';
if(address.charAt(address.length()-1) == symbol){
address = address.substring(0,address.length() - 1);
}
return address.equals(ElAdminConstant.REGION)?"内网IP":address;

View File

@ -7,6 +7,10 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
/**
* @author Zheng Jie
*
*/
public class TranslatorUtil {
public static String translate(String word){

View File

@ -23,40 +23,40 @@ public class ColumnInfo {
private String tableName;
// 数据库字段名称
/** 数据库字段名称 */
private String columnName;
// 数据库字段类型
/** 数据库字段类型 */
private String columnType;
// 数据库字段键类型
/** 数据库字段键类型 */
private String keyType;
// 字段额外的参数
/** 字段额外的参数 */
private String extra;
// 数据库字段描述
/** 数据库字段描述 */
private String remark;
// 必填
/** 必填 */
private Boolean notNull;
// 是否在列表显示
/** 是否在列表显示 */
private Boolean listShow;
// 是否表单显示
/** 是否表单显示 */
private Boolean formShow;
// 表单类型
/** 表单类型 */
private String formType;
// 查询 1:模糊 2精确
/** 查询 1:模糊 2精确 */
private String queryType;
// 字典名称
/** 字典名称 */
private String dictName;
// 日期注解
/** 日期注解 */
private String dateAnnotation;
public ColumnInfo(String tableName, String columnName, Boolean notNull, String columnType, String remark, String keyType, String extra) {

View File

@ -30,29 +30,29 @@ public class GenConfig {
@NotBlank
private String tableName;
// 包路径
/** 包路径 */
@NotBlank
private String pack;
// 模块名
/** 模块名 */
@Column(name = "module_name")
@NotBlank
private String moduleName;
// 前端文件路径
/** 前端文件路径 */
@NotBlank
private String path;
// 前端文件路径
/** 前端文件路径 */
@Column(name = "api_path")
private String apiPath;
// 作者
/** 作者 */
private String author;
// 表前缀
/** 表前缀 */
private String prefix;
// 是否覆盖
/** 是否覆盖 */
private Boolean cover;
}

View File

@ -14,19 +14,19 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class TableInfo {
// 表名称
/** 表名称 */
private Object tableName;
// 创建日期
/** 创建日期 */
private Object createTime;
// 数据库引擎
/** 数据库引擎 */
private Object engine;
// 编码集
/** 编码集 */
private Object coding;
// 备注
/** 备注 */
private Object remark;

View File

@ -10,5 +10,10 @@ import java.util.List;
*/
public interface ColumnInfoRepository extends JpaRepository<ColumnInfo,Long> {
/**
*
* @param tableName
* @return
*/
List<ColumnInfo> findByTableNameOrderByIdAsc(String tableName);
}

View File

@ -9,5 +9,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
*/
public interface GenConfigRepository extends JpaRepository<GenConfig,Long> {
/**
*
* @param tableName
* @return /
*/
GenConfig findByTableName(String tableName);
}

View File

@ -8,7 +8,18 @@ import me.zhengjie.domain.GenConfig;
*/
public interface GenConfigService {
/**
*
* @param tableName
* @return
*/
GenConfig find(String tableName);
/**
*
* @param tableName
* @param genConfig
* @return
*/
GenConfig update(String tableName, GenConfig genConfig);
}

View File

@ -39,14 +39,17 @@ public class GenConfigServiceImpl implements GenConfigService {
// 自动设置Api路径注释掉前需要同步取消前端的注释
String separator = File.separator;
String[] paths;
if (separator.equals("\\")) {
String symbol = "\\";
if (symbol.equals(separator)) {
paths = genConfig.getPath().split("\\\\");
} else paths = genConfig.getPath().split(File.separator);
} else {
paths = genConfig.getPath().split(File.separator);
}
StringBuilder api = new StringBuilder();
for (String path : paths) {
api.append(path);
api.append(separator);
if (path.equals("src")) {
if ("src".equals(path)) {
api.append("api");
break;
}

View File

@ -92,7 +92,7 @@ public class GeneratorServiceImpl implements GeneratorService {
new ColumnInfo(
tableName,
arr[0].toString(),
arr[1].equals("NO"),
"NO".equals(arr[1]),
arr[2].toString(),
ObjectUtil.isNotNull(arr[3]) ? arr[3].toString() : null,
ObjectUtil.isNotNull(arr[4]) ? arr[4].toString() : null,

View File

@ -22,6 +22,7 @@ import java.util.Map;
* @date 2019-01-02
*/
@Slf4j
@SuppressWarnings("all")
public class GenUtil {
private static final String TIMESTAMP = "Timestamp";
@ -63,7 +64,7 @@ public class GenUtil {
public static void generatorCode(List<ColumnInfo> columnInfos, GenConfig genConfig) throws IOException {
// 存储模版字段数据
Map<String,Object> genMap = new HashMap<>();
Map<String,Object> genMap = new HashMap<>(16);
// 包名称
genMap.put("package",genConfig.getPack());
// 模块名称
@ -115,7 +116,7 @@ public class GenUtil {
List<Map<String,Object>> isNotNullColumns = new ArrayList<>();
for (ColumnInfo column : columnInfos) {
Map<String,Object> listMap = new HashMap<>();
Map<String,Object> listMap = new HashMap<>(16);
// 字段描述
listMap.put("remark",column.getRemark());
// 字段类型

View File

@ -21,40 +21,42 @@ public class Log implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// 操作用户
/** 操作用户 */
private String username;
// 描述
/** 描述 */
private String description;
// 方法名
/** 方法名 */
private String method;
// 参数
/** 参数 */
@Column(columnDefinition = "text")
private String params;
// 日志类型
/** 日志类型 */
@Column(name = "log_type")
private String logType;
// 请求ip
/** 请求ip */
@Column(name = "request_ip")
private String requestIp;
/** 地址 */
@Column(name = "address")
private String address;
/** 浏览器 */
private String browser;
// 请求耗时
/** 请求耗时 */
private Long time;
// 异常详细
/** 异常详细 */
@Column(name = "exception_detail", columnDefinition = "text")
private byte[] exceptionDetail;
// 创建日期
/** 创建日期 */
@CreationTimestamp
@Column(name = "create_time")
private Timestamp createTime;

View File

@ -15,10 +15,10 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
/**
* IP
* @param date1 startTime
* @param date2 entTime
* @return IP
*/
@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 l FROM Log l where l.id = ?1")
Log findExceptionById(Long id);
}

View File

@ -16,12 +16,37 @@ import java.util.List;
*/
public interface LogService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(LogQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
List<Log> queryAll(LogQueryCriteria criteria);
/**
*
* @param criteria
* @param pageable
* @return -
*/
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
/**
*
* @param username
* @param browser
* @param ip IP
* @param joinPoint /
* @param log
*/
@Async
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log);
@ -32,5 +57,11 @@ public interface LogService {
*/
Object findByErrDetail(Long id);
void download(List<Log> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param logs
* @param response /
* @throws IOException /
*/
void download(List<Log> logs, HttpServletResponse response) throws IOException;
}

View File

@ -13,26 +13,19 @@ public class LogErrorDTO implements Serializable {
private Long id;
// 操作用户
private String username;
// 描述
private String description;
// 方法名
private String method;
// 参数
private String params;
private String browser;
// 请求ip
private String requestIp;
private String address;
// 创建日期
private Timestamp createTime;
}

View File

@ -13,7 +13,6 @@ import java.util.List;
@Data
public class LogQueryCriteria {
// 多字段模糊
@Query(blurry = "username,description,address,requestIp,method,params")
private String blurry;

View File

@ -11,19 +11,15 @@ import java.sql.Timestamp;
@Data
public class LogSmallDTO implements Serializable {
// 描述
private String description;
// 请求ip
private String requestIp;
// 请求耗时
private Long time;
private String address;
private String browser;
// 创建日期
private Timestamp createTime;
}

View File

@ -9,10 +9,7 @@ import me.zhengjie.service.LogService;
import me.zhengjie.service.dto.LogQueryCriteria;
import me.zhengjie.service.mapper.LogErrorMapper;
import me.zhengjie.service.mapper.LogSmallMapper;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.StringUtils;
import me.zhengjie.utils.*;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.data.domain.Page;
@ -52,7 +49,8 @@ public class LogServiceImpl implements LogService {
@Override
public Object queryAll(LogQueryCriteria criteria, Pageable pageable){
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)),pageable);
if ("ERROR".equals(criteria.getLogType())) {
String status = "ERROR";
if (status.equals(criteria.getLogType())) {
return PageUtil.toPage(page.map(logErrorMapper::toDto));
}
return page;
@ -97,8 +95,8 @@ public class LogServiceImpl implements LogService {
assert log != null;
log.setRequestIp(ip);
String LOGINPATH = "login";
if(LOGINPATH.equals(signature.getName())){
String loginPath = "login";
if(loginPath.equals(signature.getName())){
try {
assert argValues != null;
username = new JSONObject(argValues[0]).get("username").toString();
@ -116,7 +114,9 @@ public class LogServiceImpl implements LogService {
@Override
public Object findByErrDetail(Long id) {
byte[] details = logRepository.findExceptionById(id).getExceptionDetail();
Log log = logRepository.findById(id).orElseGet(Log::new);
ValidationUtil.isNull( log.getId(),"Log","id", id);
byte[] details = log.getExceptionDetail();
return Dict.create().set("exception",new String(ObjectUtil.isNotNull(details) ? details : "".getBytes()));
}

View File

@ -36,19 +36,17 @@ public class ServerMonitorController {
FileSystem[] fsArray = sigar.getFileSystemList();
double diskTotal = 0;
double diskUsed = 0;
for (int i = 0; i < fsArray.length; i++) {
for (FileSystem fileSystem : fsArray) {
try {
FileSystem fs = fsArray[i];
FileSystemUsage usage = null;
usage = sigar.getFileSystemUsage(fs.getDirName());
switch (fs.getType()) {
case 2:
//本地硬盘
diskTotal += usage.getTotal()/GB*1024;
diskUsed += usage.getUsed()/GB*1024;
break;
usage = sigar.getFileSystemUsage(fileSystem.getDirName());
// 本地硬盘
if (fileSystem.getType() == 2) {
diskTotal += usage.getTotal() / GB * 1024;
diskUsed += usage.getUsed() / GB * 1024;
}
} catch (Exception e) {}
} catch (Exception ignored) {
}
}
resultMap.put("diskTotal",diskTotal);
resultMap.put("diskUsed",diskUsed);

View File

@ -1,15 +1,14 @@
package me.zhengjie.utils;
import org.hyperic.sigar.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Properties;
/**
* @author: ZhangHouYing
* @date: 2019-11-03 15:04
* @author ZhangHouYing
* @date 2019-11-03 15:04
*/
public class SigarUtil {
@ -51,9 +50,12 @@ public class SigarUtil {
addr = InetAddress.getLocalHost();
String ip = addr.getHostAddress();
Map<String, String> map = System.getenv();
String userName = map.get("USERNAME");// 获取用户名
String computerName = map.get("COMPUTERNAME");// 获取计算机名
String userDomain = map.get("USERDOMAIN");// 获取计算机域名
// 获取用户名
String userName = map.get("USERNAME");
// 获取计算机名
String computerName = map.get("COMPUTERNAME");
// 获取计算机域名
String userDomain = map.get("USERDOMAIN");
System.out.println("用户名: " + userName);
System.out.println("计算机名: " + computerName);
System.out.println("计算机域名: " + userDomain);
@ -111,97 +113,100 @@ public class SigarUtil {
private static void cpu() throws SigarException {
Sigar sigar = new Sigar();
CpuInfo infos[] = sigar.getCpuInfoList();
CpuPerc cpuList[] = null;
CpuInfo[] infos = sigar.getCpuInfoList();
CpuPerc[] cpuList;
System.out.println("cpu 总量参数情况:" + sigar.getCpu());
System.out.println("cpu 总百分比情况:" + sigar.getCpuPerc());
cpuList = sigar.getCpuPercList();
for (int i = 0; i < infos.length; i++) {// 不管是单块CPU还是多CPU都适用
// 不管是单块CPU还是多CPU都适用
for (int i = 0; i < infos.length; i++) {
CpuInfo info = infos[i];
System.out.println("第" + (i + 1) + "块CPU信息");
System.out.println("CPU的总量MHz: " + info.getMhz());// CPU的总量MHz
System.out.println("CPU生产商: " + info.getVendor());// 获得CPU的卖主Intel
System.out.println("CPU类别: " + info.getModel());// 获得CPU的类别Celeron
System.out.println("CPU缓存数量: " + info.getCacheSize());// 缓冲存储器数量
// CPU的总量MHz
System.out.println("CPU的总量MHz: " + info.getMhz());
// 获得CPU的卖主Intel
System.out.println("CPU生产商: " + info.getVendor());
// 获得CPU的类别
System.out.println("CPU类别: " + info.getModel());
// 缓冲存储器数量
System.out.println("CPU缓存数量: " + info.getCacheSize());
printCpuPerc(cpuList[i]);
}
}
private static void printCpuPerc(CpuPerc cpu) {
System.out.println("CPU用户使用率: " + CpuPerc.format(cpu.getUser()));// 用户使用率
System.out.println("CPU系统使用率: " + CpuPerc.format(cpu.getSys()));// 系统使用率
System.out.println("CPU当前等待率: " + CpuPerc.format(cpu.getWait()));// 当前等待率
System.out.println("CPU当前错误率: " + CpuPerc.format(cpu.getNice()));//
System.out.println("CPU当前空闲率: " + CpuPerc.format(cpu.getIdle()));// 当前空闲率
System.out.println("CPU总的使用率: " + CpuPerc.format(cpu.getCombined()));// 总的使用率
System.out.println("CPU用户使用率: " + CpuPerc.format(cpu.getUser()));
System.out.println("CPU系统使用率: " + CpuPerc.format(cpu.getSys()));
System.out.println("CPU当前等待率: " + CpuPerc.format(cpu.getWait()));
System.out.println("CPU当前错误率: " + CpuPerc.format(cpu.getNice()));
System.out.println("CPU当前空闲率: " + CpuPerc.format(cpu.getIdle()));
System.out.println("CPU总的使用率: " + CpuPerc.format(cpu.getCombined()));
}
private static void os() {
OperatingSystem OS = OperatingSystem.getInstance();
OperatingSystem os = OperatingSystem.getInstance();
// 操作系统内核类型如: 386、486、586等x86
System.out.println("操作系统: " + OS.getArch());
System.out.println("操作系统CpuEndian(): " + OS.getCpuEndian());//
System.out.println("操作系统DataModel(): " + OS.getDataModel());//
System.out.println("操作系统: " + os.getArch());
System.out.println("操作系统CpuEndian(): " + os.getCpuEndian());
System.out.println("操作系统DataModel(): " + os.getDataModel());
// 系统描述
System.out.println("操作系统的描述: " + OS.getDescription());
System.out.println("操作系统的描述: " + os.getDescription());
// 操作系统类型
// System.out.println("OS.getName(): " + OS.getName());
// System.out.println("OS.getPatchLevel(): " + OS.getPatchLevel());//
System.out.println("OS.getName(): " + os.getName());
System.out.println("OS.getPatchLevel(): " + os.getPatchLevel());
// 操作系统的卖主
System.out.println("操作系统的卖主: " + OS.getVendor());
System.out.println("操作系统的卖主: " + os.getVendor());
// 卖主名称
System.out.println("操作系统的卖主名: " + OS.getVendorCodeName());
System.out.println("操作系统的卖主名: " + os.getVendorCodeName());
// 操作系统名称
System.out.println("操作系统名称: " + OS.getVendorName());
System.out.println("操作系统名称: " + os.getVendorName());
// 操作系统卖主类型
System.out.println("操作系统卖主类型: " + OS.getVendorVersion());
System.out.println("操作系统卖主类型: " + os.getVendorVersion());
// 操作系统的版本号
System.out.println("操作系统的版本号: " + OS.getVersion());
System.out.println("操作系统的版本号: " + os.getVersion());
}
private static void who() throws SigarException {
Sigar sigar = new Sigar();
Who who[] = sigar.getWhoList();
if (who != null && who.length > 0) {
for (int i = 0; i < who.length; i++) {
// System.out.println("当前系统进程表中的用户名" + String.valueOf(i));
Who _who = who[i];
System.out.println("用户控制台: " + _who.getDevice());
System.out.println("用户host: " + _who.getHost());
// System.out.println("getTime(): " + _who.getTime());
Who[] whos = sigar.getWhoList();
if (whos != null && whos.length > 0) {
for (Who who : whos) {
System.out.println("用户控制台: " + who.getDevice());
System.out.println("用户host: " + who.getHost());
// 当前系统进程表中的用户名
System.out.println("当前系统进程表中的用户名: " + _who.getUser());
System.out.println("当前系统进程表中的用户名: " + who.getUser());
}
}
}
private static void file() throws Exception {
Sigar sigar = new Sigar();
FileSystem fslist[] = sigar.getFileSystemList();
for (int i = 0; i < fslist.length; i++) {
FileSystem[] fsList = sigar.getFileSystemList();
for (int i = 0; i < fsList.length; i++) {
System.out.println("分区的盘符名称" + i);
FileSystem fs = fslist[i];
FileSystem fs = fsList[i];
// 分区的盘符名称
System.out.println("盘符名称: " + fs.getDevName());
// 分区的盘符名称
System.out.println("盘符路径: " + fs.getDirName());
System.out.println("盘符标志: " + fs.getFlags());//
System.out.println("盘符标志: " + fs.getFlags());
// 文件系统类型,比如 FAT32、NTFS
System.out.println("盘符类型: " + fs.getSysTypeName());
// 文件系统类型名,比如本地硬盘、光驱、网络文件系统等
System.out.println("盘符类型名: " + fs.getTypeName());
// 文件系统类型
System.out.println("盘符文件系统类型: " + fs.getType());
FileSystemUsage usage = null;
FileSystemUsage usage;
usage = sigar.getFileSystemUsage(fs.getDirName());
switch (fs.getType()) {
case 0: // TYPE_UNKNOWN :未知
break;
case 1: // TYPE_NONE
break;
case 2: // TYPE_LOCAL_DISK : 本地硬盘
// TYPE_UNKNOWN :未知
case 0: break;
// TYPE_NONE
case 1: break;
// TYPE_LOCAL_DISK : 本地硬盘
case 2:
// 文件系统总大小
System.out.println(fs.getDevName() + "总大小: " + usage.getTotal() + "KB");
// 文件系统剩余大小
@ -214,62 +219,61 @@ public class SigarUtil {
// 文件系统资源的利用率
System.out.println(fs.getDevName() + "资源的利用率: " + usePercent + "%");
break;
case 3:// TYPE_NETWORK :网络
break;
case 4:// TYPE_RAM_DISK :闪存
break;
case 5:// TYPE_CDROM :光驱
break;
case 6:// TYPE_SWAP :页面交换
break;
// TYPE_NETWORK :网络
case 3: break;
// TYPE_RAM_DISK :闪存
case 4: break;
// TYPE_CD_ROM :光驱
case 5: break;
// TYPE_SWAP :页面交换
case 6: break;
default: break;
}
System.out.println(fs.getDevName() + "读出: " + usage.getDiskReads());
System.out.println(fs.getDevName() + "写入: " + usage.getDiskWrites());
System.out.println(fs.getDevName() + "读出:" + usage.getDiskReads());
System.out.println(fs.getDevName() + "写入:" + usage.getDiskWrites());
}
return;
}
private static void net() throws Exception {
Sigar sigar = new Sigar();
String ifNames[] = sigar.getNetInterfaceList();
for (int i = 0; i < ifNames.length; i++) {
String name = ifNames[i];
String[] ifNames = sigar.getNetInterfaceList();
for (String name : ifNames) {
NetInterfaceConfig ifconfig = sigar.getNetInterfaceConfig(name);
System.out.println("网络设备名: " + name);// 网络设备名
System.out.println("IP地址: " + ifconfig.getAddress());// IP地址
System.out.println("子网掩码: " + ifconfig.getNetmask());// 子网掩码
System.out.println("网络设备名: " + name);
System.out.println("IP地址: " + ifconfig.getAddress());
System.out.println("子网掩码: " + ifconfig.getNetmask());
if ((ifconfig.getFlags() & 1L) <= 0L) {
System.out.println("!IFF_UP...skipping getNetInterfaceStat");
continue;
}
NetInterfaceStat ifstat = sigar.getNetInterfaceStat(name);
System.out.println(name + "接收的总包裹数:" + ifstat.getRxPackets());// 接收的总包裹数
System.out.println(name + "发送的总包裹数:" + ifstat.getTxPackets());// 发送的总包裹数
System.out.println(name + "接收到的总字节数:" + ifstat.getRxBytes());// 接收到的总字节数
System.out.println(name + "发送的总字节数:" + ifstat.getTxBytes());// 发送的总字节数
System.out.println(name + "接收到的错误包数:" + ifstat.getRxErrors());// 接收到的错误包数
System.out.println(name + "发送数据包时的错误数:" + ifstat.getTxErrors());// 发送数据包时的错误数
System.out.println(name + "接收时丢弃的包数:" + ifstat.getRxDropped());// 接收时丢弃的包数
System.out.println(name + "发送时丢弃的包数:" + ifstat.getTxDropped());// 发送时丢弃的包数
System.out.println(name + "接收的总包裹数:" + ifstat.getRxPackets());
System.out.println(name + "发送的总包裹数:" + ifstat.getTxPackets());
System.out.println(name + "接收到的总字节数:" + ifstat.getRxBytes());
System.out.println(name + "发送的总字节数:" + ifstat.getTxBytes());
System.out.println(name + "接收到的错误包数:" + ifstat.getRxErrors());
System.out.println(name + "发送数据包时的错误数:" + ifstat.getTxErrors());
System.out.println(name + "接收时丢弃的包数:" + ifstat.getRxDropped());
System.out.println(name + "发送时丢弃的包数:" + ifstat.getTxDropped());
}
}
private static void ethernet() throws SigarException {
Sigar sigar = null;
Sigar sigar;
sigar = new Sigar();
String[] ifaces = sigar.getNetInterfaceList();
for (int i = 0; i < ifaces.length; i++) {
NetInterfaceConfig cfg = sigar.getNetInterfaceConfig(ifaces[i]);
String[] ifAces = sigar.getNetInterfaceList();
for (String ifAce : ifAces) {
NetInterfaceConfig cfg = sigar.getNetInterfaceConfig(ifAce);
if (NetFlags.LOOPBACK_ADDRESS.equals(cfg.getAddress()) || (cfg.getFlags() & NetFlags.IFF_LOOPBACK) != 0
|| NetFlags.NULL_HWADDR.equals(cfg.getHwaddr())) {
continue;
}
System.out.println(cfg.getName() + "IP地址:" + cfg.getAddress());// IP地址
System.out.println(cfg.getName() + "网关广播地址:" + cfg.getBroadcast());// 网关广播地址
System.out.println(cfg.getName() + "网卡MAC地址:" + cfg.getHwaddr());// 网卡MAC地址
System.out.println(cfg.getName() + "子网掩码:" + cfg.getNetmask());// 子网掩码
System.out.println(cfg.getName() + "网卡描述信息:" + cfg.getDescription());// 网卡描述信息
System.out.println(cfg.getName() + "网卡类型" + cfg.getType());//
System.out.println(cfg.getName() + "IP地址:" + cfg.getAddress());
System.out.println(cfg.getName() + "网关广播地址:" + cfg.getBroadcast());
System.out.println(cfg.getName() + "网卡MAC地址:" + cfg.getHwaddr());
System.out.println(cfg.getName() + "子网掩码:" + cfg.getNetmask());
System.out.println(cfg.getName() + "网卡描述信息:" + cfg.getDescription());
System.out.println(cfg.getName() + "网卡类型" + cfg.getType());
}
}
}

View File

@ -4,11 +4,9 @@ import me.zhengjie.modules.system.domain.Dept;
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.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;
import java.util.ArrayList;
import java.util.HashSet;
@ -39,15 +37,15 @@ public class DataScope {
public Set<Long> getDeptIds() {
UserDTO user = userService.findByName(SecurityUtils.getUsername());
UserDto user = userService.findByName(SecurityUtils.getUsername());
// 用于存储部门id
Set<Long> deptIds = new HashSet<>();
// 查询用户角色
List<RoleSmallDTO> roleSet = roleService.findByUsers_Id(user.getId());
List<RoleSmallDto> roleSet = roleService.findByUsersId(user.getId());
for (RoleSmallDTO role : roleSet) {
for (RoleSmallDto role : roleSet) {
if (scopeType[0].equals(role.getDataScope())) {
return new HashSet<>() ;

View File

@ -17,7 +17,7 @@ import java.util.concurrent.ThreadPoolExecutor;
@Configuration
public class AsyncTaskExecutePool implements AsyncConfigurer {
//注入配置类
/** 注入配置类 */
private final AsyncTaskProperties config;
public AsyncTaskExecutePool(AsyncTaskProperties config) {

View File

@ -13,7 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Component
public class TheadFactoryName implements ThreadFactory {
private static final AtomicInteger poolNumber = new AtomicInteger(1);
private static final AtomicInteger POOL_NUMBER = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
@ -28,7 +28,7 @@ public class TheadFactoryName implements ThreadFactory {
Thread.currentThread().getThreadGroup();
//此时namePrefix就是 name + 第几个用这个工厂创建线程池的
this.namePrefix = name +
poolNumber.getAndIncrement();
POOL_NUMBER.getAndIncrement();
}
@Override

View File

@ -18,9 +18,6 @@ import java.sql.Timestamp;
@Table(name="mnt_server")
public class ServerDeploy implements Serializable {
/**
* IP
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

View File

@ -12,5 +12,10 @@ import org.springframework.data.jpa.repository.Query;
*/
public interface ServerDeployRepository extends JpaRepository<ServerDeploy, Long>, JpaSpecificationExecutor<ServerDeploy> {
/**
* IP
* @param ip /
* @return /
*/
ServerDeploy findByIp(String ip);
}

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.mnt.service;
import me.zhengjie.modules.mnt.domain.App;
import me.zhengjie.modules.mnt.service.dto.AppDTO;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria;
import org.springframework.data.domain.Pageable;
@ -11,15 +11,44 @@ import org.springframework.data.domain.Pageable;
*/
public interface AppService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(AppQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
Object queryAll(AppQueryCriteria criteria);
AppDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
AppDto findById(Long id);
AppDTO create(App resources);
/**
*
* @param resources /
* @return /
*/
AppDto create(App resources);
/**
*
* @param resources /
*/
void update(App resources);
/**
*
* @param id /
*/
void delete(Long id);
}

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.mnt.service;
import me.zhengjie.modules.mnt.domain.Database;
import me.zhengjie.modules.mnt.service.dto.DatabaseDTO;
import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import org.springframework.data.domain.Pageable;
@ -11,15 +11,44 @@ import org.springframework.data.domain.Pageable;
*/
public interface DatabaseService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(DatabaseQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
Object queryAll(DatabaseQueryCriteria criteria);
DatabaseDTO findById(String id);
/**
* ID
* @param id /
* @return /
*/
DatabaseDto findById(String id);
DatabaseDTO create(Database resources);
/**
*
* @param resources /
* @return /
*/
DatabaseDto create(Database resources);
/**
*
* @param resources /
*/
void update(Database resources);
/**
*
* @param id /
*/
void delete(String id);
}

View File

@ -1,19 +1,47 @@
package me.zhengjie.modules.mnt.service;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDTO;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import org.springframework.data.domain.Pageable;
/**
* @author zhanghouying
*/
public interface DeployHistoryService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(DeployHistoryQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
Object queryAll(DeployHistoryQueryCriteria criteria);
DeployHistoryDTO findById(String id);
/**
* ID
* @param id /
* @return /
*/
DeployHistoryDto findById(String id);
DeployHistoryDTO create(DeployHistory resources);
/**
*
* @param resources /
* @return /
*/
DeployHistoryDto create(DeployHistory resources);
/**
*
* @param id /
*/
void delete(String id);
}

View File

@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service;
import me.zhengjie.modules.mnt.domain.Deploy;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.service.dto.DeployDTO;
import me.zhengjie.modules.mnt.service.dto.DeployDto;
import me.zhengjie.modules.mnt.service.dto.DeployQueryCriteria;
import org.springframework.data.domain.Pageable;
@ -12,25 +12,54 @@ import org.springframework.data.domain.Pageable;
*/
public interface DeployService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(DeployQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
Object queryAll(DeployQueryCriteria criteria);
DeployDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
DeployDto findById(Long id);
DeployDTO create(Deploy resources);
/**
*
* @param resources /
* @return /
*/
DeployDto create(Deploy resources);
/**
*
* @param resources /
*/
void update(Deploy resources);
/**
*
* @param id /
*/
void delete(Long id);
/**
*
* @param fileSavePath
* @param appId ID
* @return /
*/
String deploy(String fileSavePath, Long appId);
*/
void deploy(String fileSavePath, Long appId);
/**
*

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.mnt.service;
import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDTO;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import org.springframework.data.domain.Pageable;
@ -11,17 +11,51 @@ import org.springframework.data.domain.Pageable;
*/
public interface ServerDeployService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(ServerDeployQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
Object queryAll(ServerDeployQueryCriteria criteria);
ServerDeployDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
ServerDeployDto findById(Long id);
ServerDeployDTO create(ServerDeploy resources);
/**
*
* @param resources /
* @return /
*/
ServerDeployDto create(ServerDeploy resources);
/**
*
* @param resources /
*/
void update(ServerDeploy resources);
/**
*
* @param id /
*/
void delete(Long id);
ServerDeployDTO findByIp(String ip);
/**
* IP
* @param ip /
* @return /
*/
ServerDeployDto findByIp(String ip);
}

View File

@ -11,7 +11,7 @@ import java.sql.Timestamp;
* @date 2019-08-24
*/
@Data
public class AppDTO implements Serializable {
public class AppDto implements Serializable {
/**
*
@ -26,7 +26,7 @@ public class AppDTO implements Serializable {
/**
*
*/
private int port;
private Integer port;
/**
*

View File

@ -9,7 +9,7 @@ import java.io.Serializable;
* @date 2019-08-24
*/
@Data
public class DatabaseDTO implements Serializable {
public class DatabaseDto implements Serializable {
/**
* id

View File

@ -13,19 +13,19 @@ import java.util.stream.Collectors;
* @date 2019-08-24
*/
@Data
public class DeployDTO implements Serializable {
public class DeployDto implements Serializable {
/**
*
*/
private String id;
private AppDTO app;
private AppDto app;
/**
*
*/
private Set<ServerDeployDTO> deploys;
private Set<ServerDeployDto> deploys;
private String servers;
@ -38,7 +38,7 @@ public class DeployDTO implements Serializable {
public String getServers() {
if(CollectionUtil.isNotEmpty(deploys)){
return deploys.stream().map(ServerDeployDTO::getName).collect(Collectors.joining(","));
return deploys.stream().map(ServerDeployDto::getName).collect(Collectors.joining(","));
}
return servers;
}

View File

@ -10,7 +10,7 @@ import java.sql.Timestamp;
* @date 2019-08-24
*/
@Data
public class DeployHistoryDTO implements Serializable {
public class DeployHistoryDto implements Serializable {
/**
*

View File

@ -10,7 +10,7 @@ import java.sql.Timestamp;
* @date 2019-08-24
*/
@Data
public class ServerDeployDTO implements Serializable {
public class ServerDeployDto implements Serializable {
private Long id;

View File

@ -3,7 +3,7 @@ package me.zhengjie.modules.mnt.service.impl;
import me.zhengjie.modules.mnt.domain.App;
import me.zhengjie.modules.mnt.repository.AppRepository;
import me.zhengjie.modules.mnt.service.AppService;
import me.zhengjie.modules.mnt.service.dto.AppDTO;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import me.zhengjie.modules.mnt.service.dto.AppQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.AppMapper;
import me.zhengjie.utils.PageUtil;
@ -44,7 +44,7 @@ public class AppServiceImpl implements AppService {
}
@Override
public AppDTO findById(Long id) {
public AppDto findById(Long id) {
App app = appRepository.findById(id).orElseGet(App::new);
ValidationUtil.isNull(app.getId(),"App","id",id);
return appMapper.toDto(app);
@ -52,7 +52,7 @@ public class AppServiceImpl implements AppService {
@Override
@Transactional(rollbackFor = Exception.class)
public AppDTO create(App resources) {
public AppDto create(App resources) {
return appMapper.toDto(appRepository.save(resources));
}

View File

@ -4,7 +4,7 @@ import cn.hutool.core.util.IdUtil;
import me.zhengjie.modules.mnt.domain.Database;
import me.zhengjie.modules.mnt.repository.DatabaseRepository;
import me.zhengjie.modules.mnt.service.DatabaseService;
import me.zhengjie.modules.mnt.service.dto.DatabaseDTO;
import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import me.zhengjie.modules.mnt.service.dto.DatabaseQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.DatabaseMapper;
import me.zhengjie.utils.PageUtil;
@ -45,7 +45,7 @@ public class DatabaseServiceImpl implements DatabaseService {
}
@Override
public DatabaseDTO findById(String id) {
public DatabaseDto findById(String id) {
Database database = databaseRepository.findById(id).orElseGet(Database::new);
ValidationUtil.isNull(database.getId(),"Database","id",id);
return databaseMapper.toDto(database);
@ -53,7 +53,7 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
@Transactional(rollbackFor = Exception.class)
public DatabaseDTO create(Database resources) {
public DatabaseDto create(Database resources) {
resources.setId(IdUtil.simpleUUID());
return databaseMapper.toDto(databaseRepository.save(resources));
}

View File

@ -4,7 +4,7 @@ import cn.hutool.core.util.IdUtil;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.repository.DeployHistoryRepository;
import me.zhengjie.modules.mnt.service.DeployHistoryService;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDTO;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.DeployHistoryMapper;
import me.zhengjie.utils.PageUtil;
@ -45,7 +45,7 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
}
@Override
public DeployHistoryDTO findById(String id) {
public DeployHistoryDto findById(String id) {
DeployHistory deployhistory = deployhistoryRepository.findById(id).orElseGet(DeployHistory::new);
ValidationUtil.isNull(deployhistory.getId(),"DeployHistory","id",id);
return deployhistoryMapper.toDto(deployhistory);
@ -53,7 +53,7 @@ public class DeployHistoryServiceImpl implements DeployHistoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public DeployHistoryDTO create(DeployHistory resources) {
public DeployHistoryDto create(DeployHistory resources) {
resources.setId(IdUtil.simpleUUID());
return deployhistoryMapper.toDto(deployhistoryRepository.save(resources));
}

View File

@ -67,30 +67,30 @@ public class DeployServiceImpl implements DeployService {
}
@Override
public List<DeployDTO> queryAll(DeployQueryCriteria criteria) {
public List<DeployDto> queryAll(DeployQueryCriteria criteria) {
return deployMapper.toDto(deployRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
}
@Override
public DeployDTO findById(Long id) {
Deploy Deploy = deployRepository.findById(id).orElseGet(Deploy::new);
ValidationUtil.isNull(Deploy.getId(), "Deploy", "id", id);
return deployMapper.toDto(Deploy);
public DeployDto findById(Long id) {
Deploy deploy = deployRepository.findById(id).orElseGet(Deploy::new);
ValidationUtil.isNull(deploy.getId(), "Deploy", "id", id);
return deployMapper.toDto(deploy);
}
@Override
@Transactional(rollbackFor = Exception.class)
public DeployDTO create(Deploy resources) {
public DeployDto create(Deploy resources) {
return deployMapper.toDto(deployRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Deploy resources) {
Deploy Deploy = deployRepository.findById(resources.getId()).orElseGet(Deploy::new);
ValidationUtil.isNull(Deploy.getId(), "Deploy", "id", resources.getId());
Deploy.copy(resources);
deployRepository.save(Deploy);
Deploy deploy = deployRepository.findById(resources.getId()).orElseGet(Deploy::new);
ValidationUtil.isNull(deploy.getId(), "Deploy", "id", resources.getId());
deploy.copy(resources);
deployRepository.save(deploy);
}
@Override
@ -100,8 +100,8 @@ public class DeployServiceImpl implements DeployService {
}
@Override
public String deploy(String fileSavePath, Long id) {
return deployApp(fileSavePath, id);
public void deploy(String fileSavePath, Long id) {
deployApp(fileSavePath, id);
}
/**
@ -111,12 +111,12 @@ public class DeployServiceImpl implements DeployService {
*/
private String deployApp(String fileSavePath, Long id) {
DeployDTO deploy = findById(id);
DeployDto deploy = findById(id);
if (deploy == null) {
sendMsg("部署信息不存在", MsgType.ERROR);
throw new BadRequestException("部署信息不存在");
}
AppDTO app = deploy.getApp();
AppDto app = deploy.getApp();
if (app == null) {
sendMsg("包对应应用信息不存在", MsgType.ERROR);
throw new BadRequestException("包对应应用信息不存在");
@ -126,8 +126,8 @@ public class DeployServiceImpl implements DeployService {
String uploadPath = app.getUploadPath();
StringBuilder sb = new StringBuilder();
String msg;
Set<ServerDeployDTO> deploys = deploy.getDeploys();
for (ServerDeployDTO deployDTO : deploys) {
Set<ServerDeployDto> deploys = deploy.getDeploys();
for (ServerDeployDto deployDTO : deploys) {
String ip = deployDTO.getIp();
ExecuteShellUtil executeShellUtil = getExecuteShellUtil(ip);
//判断是否第一次部署
@ -252,7 +252,7 @@ public class DeployServiceImpl implements DeployService {
return "执行完毕";
}
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDTO appDTO) {
private boolean checkFile(ExecuteShellUtil executeShellUtil, AppDto appDTO) {
String sb = "find " +
appDTO.getDeployPath() +
" -name " +
@ -346,7 +346,8 @@ public class DeployServiceImpl implements DeployService {
//删除原来应用
sendMsg("删除应用", MsgType.INFO);
//考虑到系统安全性,必须限制下操作目录
if (!deployPath.startsWith("/opt")) {
String path = "/opt";
if (!deployPath.startsWith(path)) {
throw new BadRequestException("部署路径必须在opt目录下" + deployPath);
}
executeShellUtil.execute("rm -rf " + deployPath + FILE_SEPARATOR + resources.getAppName());
@ -366,7 +367,7 @@ public class DeployServiceImpl implements DeployService {
}
private ExecuteShellUtil getExecuteShellUtil(String ip) {
ServerDeployDTO serverDeployDTO = serverDeployService.findByIp(ip);
ServerDeployDto serverDeployDTO = serverDeployService.findByIp(ip);
if (serverDeployDTO == null) {
sendMsg("IP对应服务器信息不存在" + ip, MsgType.ERROR);
throw new BadRequestException("IP对应服务器信息不存在" + ip);
@ -375,7 +376,7 @@ public class DeployServiceImpl implements DeployService {
}
private ScpClientUtil getScpClientUtil(String ip) {
ServerDeployDTO serverDeployDTO = serverDeployService.findByIp(ip);
ServerDeployDto serverDeployDTO = serverDeployService.findByIp(ip);
if (serverDeployDTO == null) {
sendMsg("IP对应服务器信息不存在" + ip, MsgType.ERROR);
throw new BadRequestException("IP对应服务器信息不存在" + ip);

View File

@ -3,7 +3,7 @@ package me.zhengjie.modules.mnt.service.impl;
import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.repository.ServerDeployRepository;
import me.zhengjie.modules.mnt.service.ServerDeployService;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDTO;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria;
import me.zhengjie.modules.mnt.service.mapper.ServerDeployMapper;
import me.zhengjie.utils.PageUtil;
@ -44,21 +44,21 @@ public class ServerDeployServiceImpl implements ServerDeployService {
}
@Override
public ServerDeployDTO findById(Long id) {
public ServerDeployDto findById(Long id) {
ServerDeploy server = serverDeployRepository.findById(id).orElseGet(ServerDeploy::new);
ValidationUtil.isNull(server.getId(),"ServerDeploy","id",id);
return serverDeployMapper.toDto(server);
}
@Override
public ServerDeployDTO findByIp(String ip) {
public ServerDeployDto findByIp(String ip) {
ServerDeploy deploy = serverDeployRepository.findByIp(ip);
return serverDeployMapper.toDto(deploy);
}
@Override
@Transactional(rollbackFor = Exception.class)
public ServerDeployDTO create(ServerDeploy resources) {
public ServerDeployDto create(ServerDeploy resources) {
return serverDeployMapper.toDto(serverDeployRepository.save(resources));
}

View File

@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.App;
import me.zhengjie.modules.mnt.service.dto.AppDTO;
import me.zhengjie.modules.mnt.service.dto.AppDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AppMapper extends BaseMapper<AppDTO, App> {
public interface AppMapper extends BaseMapper<AppDto, App> {
}

View File

@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.Database;
import me.zhengjie.modules.mnt.service.dto.DatabaseDTO;
import me.zhengjie.modules.mnt.service.dto.DatabaseDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DatabaseMapper extends BaseMapper<DatabaseDTO, Database> {
public interface DatabaseMapper extends BaseMapper<DatabaseDto, Database> {
}

View File

@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.DeployHistory;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDTO;
import me.zhengjie.modules.mnt.service.dto.DeployHistoryDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DeployHistoryMapper extends BaseMapper<DeployHistoryDTO, DeployHistory> {
public interface DeployHistoryMapper extends BaseMapper<DeployHistoryDto, DeployHistory> {
}

View File

@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.Deploy;
import me.zhengjie.modules.mnt.service.dto.DeployDTO;
import me.zhengjie.modules.mnt.service.dto.DeployDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {AppMapper.class, ServerDeployMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface DeployMapper extends BaseMapper<DeployDTO, Deploy> {
public interface DeployMapper extends BaseMapper<DeployDto, Deploy> {
}

View File

@ -2,7 +2,7 @@ package me.zhengjie.modules.mnt.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.mnt.domain.ServerDeploy;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDTO;
import me.zhengjie.modules.mnt.service.dto.ServerDeployDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-08-24
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ServerDeployMapper extends BaseMapper<ServerDeployDTO, ServerDeploy> {
public interface ServerDeployMapper extends BaseMapper<ServerDeployDto, ServerDeploy> {
}

View File

@ -16,15 +16,15 @@ public class ScpClientUtil {
static private ScpClientUtil instance;
static synchronized public ScpClientUtil getInstance(String IP, int port, String username, String passward) {
static synchronized public ScpClientUtil getInstance(String ip, int port, String username, String passward) {
if (instance == null) {
instance = new ScpClientUtil(IP, port, username, passward);
instance = new ScpClientUtil(ip, port, username, passward);
}
return instance;
}
public ScpClientUtil(String IP, int port, String username, String passward) {
this.ip = IP;
public ScpClientUtil(String ip, int port, String username, String passward) {
this.ip = ip;
this.port = port;
this.username = username;
this.password = passward;

View File

@ -5,5 +5,12 @@ package me.zhengjie.modules.mnt.websocket;
* @date: 2019-08-10 9:56
*/
public enum MsgType {
CONNECT,CLOSE,INFO,ERROR
/** 连接 */
CONNECT,
/** 关闭 */
CLOSE,
/** 信息 */
INFO,
/** 错误 */
ERROR
}

View File

@ -8,6 +8,7 @@ import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* @author: ZhangHouYing
@ -58,7 +59,6 @@ public class WebSocketServer {
/**
*
*
* @param message */
@OnMessage
public void onMessage(String message, Session session) {
@ -73,11 +73,6 @@ public class WebSocketServer {
}
}
/**
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.error("发生错误");
@ -86,7 +81,7 @@ public class WebSocketServer {
/**
*
*/
public void sendMessage(String message) throws IOException {
private void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
@ -105,9 +100,25 @@ public class WebSocketServer {
}else if(item.sid.equals(sid)){
item.sendMessage(message);
}
} catch (IOException e) {
continue;
}
} catch (IOException ignored) { }
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
WebSocketServer that = (WebSocketServer) o;
return Objects.equals(session, that.session) &&
Objects.equals(sid, that.sid);
}
@Override
public int hashCode() {
return Objects.hash(session, sid);
}
}

View File

@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.atomic.AtomicInteger;
/**
*
* @author /
*
*/
@RestController

View File

@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
* @author Zhang houying
* @date 2019-11-03
*/
@Api(tags = "Server管理")
@Api(tags = "服务监控管理")
@RestController
@RequestMapping("/api/server")
public class ServerController {
@ -29,24 +29,24 @@ public class ServerController {
}
@GetMapping
@Log("查询Server")
@ApiOperation("查询Server")
@Log("查询服务监控")
@ApiOperation("查询服务监控")
@PreAuthorize("@el.check('server:list')")
public ResponseEntity getServers(ServerQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(serverService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增Server")
@ApiOperation("新增Server")
@Log("新增服务监控")
@ApiOperation("新增服务监控")
@PreAuthorize("@el.check('server:add')")
public ResponseEntity create(@Validated @RequestBody Server resources){
return new ResponseEntity<>(serverService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改Server")
@ApiOperation("修改Server")
@Log("修改服务监控")
@ApiOperation("修改服务监控")
@PreAuthorize("@el.check('server:edit')")
public ResponseEntity update(@Validated @RequestBody Server resources){
serverService.update(resources);
@ -54,8 +54,8 @@ public class ServerController {
}
@DeleteMapping(value = "/{id}")
@Log("删除Server")
@ApiOperation("删除Server")
@Log("删除服务监控")
@ApiOperation("删除服务监控")
@PreAuthorize("@el.check('server:del')")
public ResponseEntity delete(@PathVariable Integer id){
serverService.delete(id);

View File

@ -16,8 +16,9 @@ import java.util.List;
public interface RedisService {
/**
* findById
* KEY
* @param key
* @param pageable
* @return /
*/
Page findByKey(String key, Pageable pageable);
@ -55,9 +56,10 @@ public interface RedisService {
void deleteAll();
/**
*
*
* @param redisVos /
* @param response /
* @throws IOException /
*/
void download(List<RedisVo> redisVos, HttpServletResponse response) throws IOException;
}

View File

@ -36,10 +36,23 @@ public interface ServerService {
*/
ServerDTO findById(Integer id);
/**
*
* @param resources /
* @return /
*/
ServerDTO create(Server resources);
/**
*
* @param resources /
*/
void update(Server resources);
/**
*
* @param id /
*/
void delete(Integer id);
}

View File

@ -11,45 +11,39 @@ import java.io.Serializable;
@Data
public class ServerDTO implements Serializable {
// 编号
private Integer id;
// 名称
private String name;
// IP地址
private String address;
// 访问端口
private Integer port;
// 状态
private String state;
// CPU使用率
/** CPU使用率 */
private Float cpuRate;
// CPU内核数
/** CPU内核数 */
private Integer cpuCore;
// 内存总数
/** 内存总数 */
private Float memTotal;
// 内存使用量
/** 内存使用量 */
private Float memUsed;
// 磁盘总量
/** 磁盘总量 */
private Float diskTotal;
// 磁盘使用量
/** 磁盘使用量 */
private Float diskUsed;
// 交换区总量
/** 交换区总量 */
private Float swapTotal;
// 交换区使用量
/** 交换区使用量 */
private Float swapUsed;
// 排序
private Integer sort;
}

View File

@ -10,7 +10,6 @@ import me.zhengjie.annotation.Query;
@Data
public class ServerQueryCriteria{
// 模糊
@Query(blurry = "name,address")
private String blurry;
}

View File

@ -16,7 +16,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;

View File

@ -6,7 +6,6 @@ import me.zhengjie.modules.monitor.repository.VisitsRepository;
import me.zhengjie.modules.monitor.service.VisitsService;
import me.zhengjie.repository.LogRepository;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@ -61,7 +60,7 @@ public class VisitsServiceImpl implements VisitsService {
@Override
public Object get() {
Map<String,Object> map = new HashMap<>();
Map<String,Object> map = new HashMap<>(4);
LocalDate localDate = LocalDate.now();
Visits visits = visitsRepository.findByDate(localDate.toString());
List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString());
@ -80,7 +79,7 @@ public class VisitsServiceImpl implements VisitsService {
@Override
public Object getChartData() {
Map<String,Object> map = new HashMap<>();
Map<String,Object> map = new HashMap<>(3);
LocalDate localDate = LocalDate.now();
List<Visits> list = visitsRepository.findAllVisits(localDate.minusDays(6).toString(),localDate.plusDays(1).toString());
map.put("weekDays",list.stream().map(Visits::getWeekDay).collect(Collectors.toList()));

View File

@ -26,34 +26,34 @@ public class QuartzJob implements Serializable {
@NotNull(groups = {Update.class})
private Long id;
// 定时器名称
/** 定时器名称 */
@Column(name = "job_name")
private String jobName;
// Bean名称
/** Bean名称 */
@Column(name = "bean_name")
@NotBlank
private String beanName;
// 方法名称
/** 方法名称 */
@Column(name = "method_name")
@NotBlank
private String methodName;
// 参数
/** 参数 */
@Column(name = "params")
private String params;
// cron表达式
/** cron表达式 */
@Column(name = "cron_expression")
@NotBlank
private String cronExpression;
// 状态
/** 状态 */
@Column(name = "is_pause")
private Boolean isPause = false;
// 备注
/** 备注 */
@Column(name = "remark")
@NotBlank
private String remark;

View File

@ -20,38 +20,38 @@ public class QuartzLog implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// 任务名称
/** 任务名称 */
@Column(name = "job_name")
private String jobName;
// Bean名称
/** Bean名称 */
@Column(name = "baen_name")
private String beanName;
// 方法名称
/** 方法名称 */
@Column(name = "method_name")
private String methodName;
// 参数
/** 参数 */
@Column(name = "params")
private String params;
// cron表达式
/** cron表达式 */
@Column(name = "cron_expression")
private String cronExpression;
// 状态
/** 状态 */
@Column(name = "is_success")
private Boolean isSuccess;
// 异常详细
/** 异常详细 */
@Column(name = "exception_detail",columnDefinition = "text")
private String exceptionDetail;
// 耗时(毫秒)
/** 耗时(毫秒) */
private Long time;
// 创建日期
/** 创建日期 */
@CreationTimestamp
@Column(name = "create_time")
private Timestamp createTime;

View File

@ -15,20 +15,60 @@ import java.util.List;
*/
public interface QuartzJobService {
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(JobQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
List<QuartzJob> queryAll(JobQueryCriteria criteria);
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAllLog(JobQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return /
*/
List<QuartzLog> queryAllLog(JobQueryCriteria criteria);
/**
*
* @param resources /
* @return /
*/
QuartzJob create(QuartzJob resources);
/**
*
* @param resources /
*/
void update(QuartzJob resources);
/**
*
* @param quartzJob /
*/
void delete(QuartzJob quartzJob);
/**
* ID
* @param id ID
* @return /
*/
QuartzJob findById(Long id);
/**
@ -43,7 +83,19 @@ public interface QuartzJobService {
*/
void execution(QuartzJob quartzJob);
/**
*
* @param queryAll
* @param response /
* @throws IOException /
*/
void download(List<QuartzJob> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param queryAllLog
* @param response /
* @throws IOException /
*/
void downloadLog(List<QuartzLog> queryAllLog, HttpServletResponse response) throws IOException;
}

View File

@ -125,7 +125,7 @@ public class QuartzJobServiceImpl implements QuartzJobService {
if(quartzJob.getId().equals(1L)){
throw new BadRequestException("该任务不可操作");
}
quartzManage.runAJobNow(quartzJob);
quartzManage.runJobNow(quartzJob);
}
@Override

View File

@ -25,8 +25,8 @@ public class ExecutionJob extends QuartzJobBean {
private Logger logger = LoggerFactory.getLogger(this.getClass());
// 该处仅供参考
private final static ThreadPoolExecutor executor = ThreadPoolExecutorUtil.getPoll();
/** 该处仅供参考 */
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
@Override
@SuppressWarnings("unchecked")
@ -48,7 +48,7 @@ public class ExecutionJob extends QuartzJobBean {
logger.info("任务准备执行,任务名称:{}", quartzJob.getJobName());
QuartzRunnable task = new QuartzRunnable(quartzJob.getBeanName(), quartzJob.getMethodName(),
quartzJob.getParams());
Future<?> future = executor.submit(task);
Future<?> future = EXECUTOR.submit(task);
future.get();
long times = System.currentTimeMillis() - startTime;
log.setTime(times);

View File

@ -109,8 +109,9 @@ public class QuartzManage {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null)
if(trigger == null) {
addJob(quartzJob);
}
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
scheduler.resumeJob(jobKey);
} catch (Exception e){
@ -123,13 +124,14 @@ public class QuartzManage {
* job
* @param quartzJob /
*/
public void runAJobNow(QuartzJob quartzJob){
public void runJobNow(QuartzJob quartzJob){
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if(trigger == null)
if(trigger == null) {
addJob(quartzJob);
}
JobDataMap dataMap = new JobDataMap();
dataMap.put(QuartzJob.JOB_KEY, quartzJob);
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());

View File

@ -3,7 +3,7 @@ package me.zhengjie.modules.security.config;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.security.security.JwtAuthenticationEntryPoint;
import me.zhengjie.modules.security.security.JwtAuthorizationTokenFilter;
import me.zhengjie.modules.security.service.JwtUserDetailsService;
import me.zhengjie.modules.security.service.JwtUserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
@ -25,11 +25,13 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author Zheng Jie
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@ -37,17 +39,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final JwtAuthenticationEntryPoint unauthorizedHandler;
private final JwtUserDetailsService jwtUserDetailsService;
private final JwtUserDetailsServiceImpl jwtUserDetailsService;
private final ApplicationContext applicationContext;
// 自定义基于JWT的安全过滤器
/** 自定义基于JWT的安全过滤器 */
private final JwtAuthorizationTokenFilter authenticationTokenFilter;
@Value("${jwt.header}")
private String tokenHeader;
public SecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler, JwtUserDetailsService jwtUserDetailsService, JwtAuthorizationTokenFilter authenticationTokenFilter, ApplicationContext applicationContext) {
public SecurityConfig(JwtAuthenticationEntryPoint unauthorizedHandler, JwtUserDetailsServiceImpl jwtUserDetailsService, JwtAuthorizationTokenFilter authenticationTokenFilter, ApplicationContext applicationContext) {
this.unauthorizedHandler = unauthorizedHandler;
this.jwtUserDetailsService = jwtUserDetailsService;
this.authenticationTokenFilter = authenticationTokenFilter;

View File

@ -50,7 +50,7 @@ public class AuthenticationController {
private final OnlineUserService onlineUserService;
public AuthenticationController(JwtTokenUtil jwtTokenUtil, RedisService redisService, @Qualifier("jwtUserDetailsService") UserDetailsService userDetailsService, OnlineUserService onlineUserService) {
public AuthenticationController(JwtTokenUtil jwtTokenUtil, RedisService redisService, @Qualifier("jwtUserDetailsServiceImpl") UserDetailsService userDetailsService, OnlineUserService onlineUserService) {
this.jwtTokenUtil = jwtTokenUtil;
this.redisService = redisService;
this.userDetailsService = userDetailsService;

View File

@ -13,6 +13,9 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author Zheng Jie
*/
@RestController
@RequestMapping("/auth/online")
@Api(tags = "系统:在线用户管理")

View File

@ -9,6 +9,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
/**
* @author Zheng Jie
*/
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {

View File

@ -19,6 +19,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author Zheng Jie
*/
@Slf4j
@Component
public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
@ -31,7 +34,7 @@ public class JwtAuthorizationTokenFilter extends OncePerRequestFilter {
private final JwtTokenUtil jwtTokenUtil;
private final RedisTemplate redisTemplate;
public JwtAuthorizationTokenFilter(@Qualifier("jwtUserDetailsService") UserDetailsService userDetailsService, JwtTokenUtil jwtTokenUtil, RedisTemplate redisTemplate) {
public JwtAuthorizationTokenFilter(@Qualifier("jwtUserDetailsServiceImpl") UserDetailsService userDetailsService, JwtTokenUtil jwtTokenUtil, RedisTemplate redisTemplate) {
this.userDetailsService = userDetailsService;
this.jwtTokenUtil = jwtTokenUtil;
this.redisTemplate = redisTemplate;

View File

@ -3,7 +3,7 @@ package me.zhengjie.modules.security.service;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.utils.StringUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
@ -11,17 +11,19 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author Zheng Jie
*/
@Service
@CacheConfig(cacheNames = "role")
public class JwtPermissionService {
public class JwtPermissionServiceImpl {
private final RoleRepository roleRepository;
public JwtPermissionService(RoleRepository roleRepository) {
public JwtPermissionServiceImpl(RoleRepository roleRepository) {
this.roleRepository = roleRepository;
}
@ -31,7 +33,7 @@ public class JwtPermissionService {
* @return Collection
*/
@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDTO user) {
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDto user) {
System.out.println("--------------------loadPermissionByUser:" + user.getUsername() + "---------------------");

View File

@ -17,13 +17,13 @@ import java.util.Optional;
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class JwtUserDetailsService implements UserDetailsService {
public class JwtUserDetailsServiceImpl implements UserDetailsService {
private final UserService userService;
private final JwtPermissionService permissionService;
private final JwtPermissionServiceImpl permissionService;
public JwtUserDetailsService(UserService userService, JwtPermissionService permissionService) {
public JwtUserDetailsServiceImpl(UserService userService, JwtPermissionServiceImpl permissionService) {
this.userService = userService;
this.permissionService = permissionService;
}
@ -31,7 +31,7 @@ public class JwtUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username){
UserDTO user = userService.findByName(username);
UserDto user = userService.findByName(username);
if (user == null) {
throw new BadRequestException("账号不存在");
} else {
@ -39,7 +39,7 @@ public class JwtUserDetailsService implements UserDetailsService {
}
}
public UserDetails createJwtUser(UserDTO user) {
public UserDetails createJwtUser(UserDto user) {
return new JwtUser(
user.getId(),
user.getUsername(),
@ -47,8 +47,8 @@ public class JwtUserDetailsService implements UserDetailsService {
user.getAvatar(),
user.getEmail(),
user.getPhone(),
Optional.ofNullable(user.getDept()).map(DeptSmallDTO::getName).orElse(null),
Optional.ofNullable(user.getJob()).map(JobSmallDTO::getName).orElse(null),
Optional.ofNullable(user.getDept()).map(DeptSmallDto::getName).orElse(null),
Optional.ofNullable(user.getJob()).map(JobSmallDto::getName).orElse(null),
permissionService.mapToGrantedAuthorities(user),
user.getEnabled(),
user.getCreateTime(),

View File

@ -14,6 +14,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
/**
* @author /
*/
@Component
public class JwtTokenUtil implements Serializable {
@ -68,7 +71,7 @@ public class JwtTokenUtil implements Serializable {
}
public String generateToken(UserDetails userDetails) {
Map<String, Object> claims = new HashMap<>();
Map<String, Object> claims = new HashMap<>(16);
return doGenerateToken(claims, userDetails.getUsername());
}
@ -107,7 +110,8 @@ public class JwtTokenUtil implements Serializable {
public String getToken(HttpServletRequest request){
final String requestHeader = request.getHeader(tokenHeader);
if (requestHeader != null && requestHeader.startsWith("Bearer ")) {
String startsWith = "Bearer ";
if (requestHeader != null && requestHeader.startsWith(startsWith)) {
return requestHeader.substring(7);
}
return null;

View File

@ -9,6 +9,7 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;
/**
@ -47,4 +48,22 @@ public class Dept implements Serializable {
private Timestamp createTime;
public @interface Update {}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Dept dept = (Dept) o;
return Objects.equals(id, dept.id) &&
Objects.equals(name, dept.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}

View File

@ -24,19 +24,18 @@ public class DictDetail implements Serializable {
@NotNull(groups = Update.class)
private Long id;
// 字典标签
/** 字典标签 */
@Column(name = "label",nullable = false)
private String label;
// 字典值
/** 字典值 */
@Column(name = "value",nullable = false)
private String value;
// 排序
/** 排序 */
@Column(name = "sort")
private String sort = "999";
// 字典id
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "dict_id")
private Dict dict;

View File

@ -38,11 +38,11 @@ public class Menu implements Serializable {
private String component;
// 类型
/** 类型,目录、菜单、按钮 */
@Column(name = "type")
private Integer type;
// 权限
/** 权限 */
@Column(name = "permission")
private String permission;
@ -57,11 +57,11 @@ public class Menu implements Serializable {
@Column(columnDefinition = "bit(1) default 0")
private Boolean hidden;
// 上级菜单ID
/** 上级菜单ID */
@Column(name = "pid",nullable = false)
private Long pid;
// 是否为外链 true/false
/** 是否为外链 true/false */
@Column(name = "i_frame")
private Boolean iFrame;
@ -77,8 +77,12 @@ public class Menu implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Menu menu = (Menu) o;
return Objects.equals(id, menu.id);
}

View File

@ -32,18 +32,18 @@ public class Role implements Serializable {
@NotBlank
private String name;
// 数据权限类型 全部 、 本级 、 自定义
/** 数据权限类型 全部 、 本级 、 自定义 */
@Column(name = "data_scope")
private String dataScope = "本级";
// 数值越小,级别越大
/** 数值越小,级别越大 */
@Column(name = "level")
private Integer level = 3;
@Column
private String remark;
// 权限
/** 权限 */
@Column(name = "permission")
private String permission;
@ -67,8 +67,12 @@ public class Role implements Serializable {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Role role = (Role) o;
return Objects.equals(id, role.id);
}

View File

@ -10,6 +10,7 @@ import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;
import java.util.Set;
/**
@ -67,4 +68,22 @@ public class User implements Serializable {
private Dept dept;
public @interface Update {}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
return Objects.equals(id, user.id) &&
Objects.equals(username, user.username);
}
@Override
public int hashCode() {
return Objects.hash(id, username);
}
}

View File

@ -11,12 +11,28 @@ import java.util.Set;
* @author Zheng Jie
* @date 2019-03-25
*/
@SuppressWarnings("all")
public interface DeptRepository extends JpaRepository<Dept, Long>, JpaSpecificationExecutor<Dept> {
/**
* PID
* @param id pid
* @return
*/
List<Dept> findByPid(Long id);
/**
* ID
* @param id ID
* @return /
*/
@Query(value = "select name from dept where id = ?1",nativeQuery = true)
String findNameById(Long id);
/**
* ID
* @param id ID
* @return /
*/
Set<Dept> findByRoles_Id(Long id);
}

View File

@ -10,13 +10,35 @@ import java.util.List;
* @author Zheng Jie
* @date 2018-12-17
*/
@SuppressWarnings("all")
public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificationExecutor<Menu> {
/**
*
* @param name
* @return /
*/
Menu findByName(String name);
/**
*
* @param name
* @return /
*/
Menu findByComponentName(String name);
/**
* PID
* @param pid /
* @return /
*/
List<Menu> findByPid(long pid);
/**
* ID
* @param id roleID
* @param type
* @return /
*/
LinkedHashSet<Menu> findByRoles_IdAndTypeIsNotInOrderBySortAsc(Long id, Integer type);
}

View File

@ -11,12 +11,27 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-12-03
*/
@SuppressWarnings("all")
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {
/**
*
* @param name /
* @return /
*/
Role findByName(String name);
/**
* ID
* @param id ID
* @return
*/
Set<Role> findByUsers_Id(Long id);
/**
*
* @param id ID
*/
@Modifying
@Query(value = "delete from roles_menus where menu_id = ?1",nativeQuery = true)
void untiedMenu(Long id);

View File

@ -13,14 +13,35 @@ import java.util.Date;
*/
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
/**
*
* @param username
* @return /
*/
User findByUsername(String username);
/**
*
* @param email
* @return /
*/
User findByEmail(String email);
/**
*
* @param username
* @param pass
* @param lastPasswordResetTime /
*/
@Modifying
@Query(value = "update user set password = ?2 , last_password_reset_time = ?3 where username = ?1",nativeQuery = true)
void updatePass(String username, String pass, Date lastPasswordResetTime);
/**
*
* @param username
* @param email
*/
@Modifying
@Query(value = "update user set email = ?2 where username = ?1",nativeQuery = true)
void updateEmail(String username, String email);

View File

@ -7,7 +7,7 @@ import me.zhengjie.config.DataScope;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.DeptDto;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
import me.zhengjie.utils.ThrowableUtil;
import org.springframework.http.HttpStatus;
@ -55,8 +55,8 @@ public class DeptController {
public ResponseEntity getDepts(DeptQueryCriteria criteria){
// 数据权限
criteria.setIds(dataScope.getDeptIds());
List<DeptDTO> deptDTOS = deptService.queryAll(criteria);
return new ResponseEntity<>(deptService.buildTree(deptDTOS),HttpStatus.OK);
List<DeptDto> deptDtos = deptService.queryAll(criteria);
return new ResponseEntity<>(deptService.buildTree(deptDtos),HttpStatus.OK);
}
@Log("新增部门")

View File

@ -8,9 +8,9 @@ import me.zhengjie.exception.BadRequestException;
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.MenuDto;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -59,10 +59,10 @@ public class MenuController {
@ApiOperation("获取前端所需菜单")
@GetMapping(value = "/build")
public ResponseEntity buildMenus(){
UserDTO user = userService.findByName(SecurityUtils.getUsername());
List<MenuDTO> menuDTOList = menuService.findByRoles(roleService.findByUsers_Id(user.getId()));
List<MenuDTO> menuDTOS = (List<MenuDTO>) menuService.buildTree(menuDTOList).get("content");
return new ResponseEntity<>(menuService.buildMenus(menuDTOS),HttpStatus.OK);
UserDto user = userService.findByName(SecurityUtils.getUsername());
List<MenuDto> menuDtoList = menuService.findByRoles(roleService.findByUsersId(user.getId()));
List<MenuDto> menuDtos = (List<MenuDto>) menuService.buildTree(menuDtoList).get("content");
return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK);
}
@ApiOperation("返回全部的菜单")
@ -77,8 +77,8 @@ public class MenuController {
@GetMapping
@PreAuthorize("@el.check('menu:list')")
public ResponseEntity getMenus(MenuQueryCriteria criteria){
List<MenuDTO> menuDTOList = menuService.queryAll(criteria);
return new ResponseEntity<>(menuService.buildTree(menuDTOList),HttpStatus.OK);
List<MenuDto> menuDtoList = menuService.queryAll(criteria);
return new ResponseEntity<>(menuService.buildTree(menuDtoList),HttpStatus.OK);
}
@Log("新增菜单")

View File

@ -8,7 +8,7 @@ import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDto;
import me.zhengjie.utils.SecurityUtils;
import me.zhengjie.utils.ThrowableUtil;
import org.springframework.data.domain.Pageable;
@ -76,7 +76,7 @@ public class RoleController {
@ApiOperation("获取用户级别")
@GetMapping(value = "/level")
public ResponseEntity getLevel(){
List<Integer> levels = roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList());
List<Integer> levels = roleService.findByUsersId(SecurityUtils.getUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
return new ResponseEntity<>(Dict.create().set("level", Collections.min(levels)),HttpStatus.OK);
}

View File

@ -10,7 +10,7 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.vo.UserPassVo;
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.modules.system.service.dto.RoleSmallDto;
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
import me.zhengjie.service.VerificationCodeService;
import me.zhengjie.utils.*;
@ -87,7 +87,9 @@ public class UserController {
criteria.setDeptIds(result);
if(result.size() == 0){
return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK);
} else return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
} else {
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
}
// 否则取并集
} else {
result.addAll(deptSet);
@ -121,8 +123,8 @@ public class UserController {
@DeleteMapping(value = "/{id}")
@PreAuthorize("@el.check('user:del')")
public ResponseEntity delete(@PathVariable Long id){
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()));
Integer currentLevel = Collections.min(roleService.findByUsersId(SecurityUtils.getUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足");
@ -171,7 +173,7 @@ public class UserController {
* @param resources /
*/
private void checkLevel(User resources) {
Integer currentLevel = Collections.min(roleService.findByUsers_Id(SecurityUtils.getUserId()).stream().map(RoleSmallDTO::getLevel).collect(Collectors.toList()));
Integer currentLevel = Collections.min(roleService.findByUsersId(SecurityUtils.getUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
Integer optLevel = roleService.findByRoles(resources.getRoles());
if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足");

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.dto.DeptDto;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
import javax.servlet.http.HttpServletResponse;
@ -15,21 +15,65 @@ import java.util.Set;
*/
public interface DeptService {
List<DeptDTO> queryAll(DeptQueryCriteria criteria);
/**
*
* @param criteria
* @return /
*/
List<DeptDto> queryAll(DeptQueryCriteria criteria);
DeptDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
DeptDto findById(Long id);
DeptDTO create(Dept resources);
/**
*
* @param resources /
* @return /
*/
DeptDto create(Dept resources);
/**
*
* @param resources /
*/
void update(Dept resources);
/**
*
* @param id /
*/
void delete(Long id);
Object buildTree(List<DeptDTO> deptDTOS);
/**
*
* @param deptDtos
* @return /
*/
Object buildTree(List<DeptDto> deptDtos);
/**
* PID
* @param pid /
* @return /
*/
List<Dept> findByPid(long pid);
/**
* ID
* @param id /
* @return /
*/
Set<Dept> findByRoleIds(Long id);
void download(List<DeptDTO> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param queryAll
* @param response /
* @throws IOException /
*/
void download(List<DeptDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.DictDetail;
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
import me.zhengjie.modules.system.service.dto.DictDetailDto;
import me.zhengjie.modules.system.service.dto.DictDetailQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
@ -12,13 +12,37 @@ import java.util.Map;
*/
public interface DictDetailService {
DictDetailDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
DictDetailDto findById(Long id);
DictDetailDTO create(DictDetail resources);
/**
*
* @param resources /
* @return /
*/
DictDetailDto create(DictDetail resources);
/**
*
* @param resources /
*/
void update(DictDetail resources);
/**
*
* @param id /
*/
void delete(Long id);
Map queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @param pageable
* @return /
*/
Map<String,Object> queryAll(DictDetailQueryCriteria criteria, Pageable pageable);
}

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.dto.DictDTO;
import me.zhengjie.modules.system.service.dto.DictDto;
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
import org.springframework.data.domain.Pageable;
@ -16,17 +16,52 @@ import java.util.Map;
*/
public interface DictService {
Map<String,Object> queryAll(DictQueryCriteria dict, Pageable pageable);
/**
*
* @param criteria
* @param pageable
* @return /
*/
Map<String,Object> queryAll(DictQueryCriteria criteria, Pageable pageable);
List<DictDTO> queryAll(DictQueryCriteria dict);
/**
*
* @param dict /
* @return /
*/
List<DictDto> queryAll(DictQueryCriteria dict);
DictDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
DictDto findById(Long id);
DictDTO create(Dict resources);
/**
*
* @param resources /
* @return /
*/
DictDto create(Dict resources);
/**
*
* @param resources /
*/
void update(Dict resources);
/**
*
* @param id /
*/
void delete(Long id);
void download(List<DictDTO> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param queryAll
* @param response /
* @throws IOException /
*/
void download(List<DictDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -1,7 +1,7 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.service.dto.JobDTO;
import me.zhengjie.modules.system.service.dto.JobDto;
import me.zhengjie.modules.system.service.dto.JobQueryCriteria;
import org.springframework.data.domain.Pageable;
@ -16,17 +16,52 @@ import java.util.Map;
*/
public interface JobService {
JobDTO findById(Long id);
/**
* ID
* @param id /
* @return /
*/
JobDto findById(Long id);
JobDTO create(Job resources);
/**
*
* @param resources /
* @return /
*/
JobDto create(Job resources);
/**
*
* @param resources /
*/
void update(Job resources);
/**
*
* @param id /
*/
void delete(Long id);
/**
*
* @param criteria
* @param pageable
* @return /
*/
Map<String,Object> queryAll(JobQueryCriteria criteria, Pageable pageable);
List<JobDTO> queryAll(JobQueryCriteria criteria);
/**
*
* @param criteria /
* @return /
*/
List<JobDto> queryAll(JobQueryCriteria criteria);
void download(List<JobDTO> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param queryAll
* @param response /
* @throws IOException /
*/
void download(List<JobDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -1,9 +1,9 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.service.dto.MenuDTO;
import me.zhengjie.modules.system.service.dto.MenuDto;
import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDto;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@ -17,29 +17,94 @@ import java.util.Set;
*/
public interface MenuService {
List<MenuDTO> queryAll(MenuQueryCriteria criteria);
/**
*
* @param criteria
* @return /
*/
List<MenuDto> queryAll(MenuQueryCriteria criteria);
MenuDTO findById(long id);
/**
* ID
* @param id /
* @return /
*/
MenuDto findById(long id);
MenuDTO create(Menu resources);
/**
*
* @param resources /
* @return /
*/
MenuDto create(Menu resources);
/**
*
* @param resources /
*/
void update(Menu resources);
/**
*
* @param menuList /
* @param menuSet /
* @return /
*/
Set<Menu> getDeleteMenus(List<Menu> menuList, Set<Menu> menuSet);
/**
*
* @param menus /
* @return /
*/
Object getMenuTree(List<Menu> menus);
/**
* pid
* @param pid /
* @return /
*/
List<Menu> findByPid(long pid);
Map<String,Object> buildTree(List<MenuDTO> menuDTOS);
/**
*
* @param menuDtos
* @return /
*/
Map<String,Object> buildTree(List<MenuDto> menuDtos);
List<MenuDTO> findByRoles(List<RoleSmallDTO> roles);
/**
*
* @param roles /
* @return /
*/
List<MenuDto> findByRoles(List<RoleSmallDto> roles);
Object buildMenus(List<MenuDTO> byRoles);
/**
*
* @param menuDtos /
* @return /
*/
Object buildMenus(List<MenuDto> menuDtos);
/**
* ID
* @param id /
* @return /
*/
Menu findOne(Long id);
/**
*
* @param menuSet /
*/
void delete(Set<Menu> menuSet);
void download(List<MenuDTO> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param queryAll
* @param response /
* @throws IOException /
*/
void download(List<MenuDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -1,9 +1,9 @@
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.service.dto.RoleDTO;
import me.zhengjie.modules.system.service.dto.RoleDto;
import me.zhengjie.modules.system.service.dto.RoleQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.dto.RoleSmallDto;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
@ -17,27 +17,86 @@ import java.util.Set;
*/
public interface RoleService {
RoleDTO findById(long id);
/**
* ID
* @param id /
* @return /
*/
RoleDto findById(long id);
RoleDTO create(Role resources);
/**
*
* @param resources /
* @return /
*/
RoleDto create(Role resources);
/**
*
* @param resources /
*/
void update(Role resources);
/**
*
* @param id /
*/
void delete(Long id);
List<RoleSmallDTO> findByUsers_Id(Long id);
/**
* ID
* @param id ID
* @return /
*/
List<RoleSmallDto> findByUsersId(Long id);
/**
*
* @param roles /
* @return /
*/
Integer findByRoles(Set<Role> roles);
void updateMenu(Role resources, RoleDTO roleDTO);
/**
*
* @param resources /
* @param roleDTO /
*/
void updateMenu(Role resources, RoleDto roleDTO);
/**
*
* @param id /
*/
void untiedMenu(Long id);
/**
*
* @param pageable
* @return /
*/
Object queryAll(Pageable pageable);
/**
*
* @param criteria
* @param pageable
* @return /
*/
Object queryAll(RoleQueryCriteria criteria, Pageable pageable);
List<RoleDTO> queryAll(RoleQueryCriteria criteria);
/**
*
* @param criteria
* @return /
*/
List<RoleDto> queryAll(RoleQueryCriteria criteria);
void download(List<RoleDTO> queryAll, HttpServletResponse response) throws IOException;
/**
*
* @param queryAll
* @param response /
* @throws IOException /
*/
void download(List<RoleDto> queryAll, HttpServletResponse response) throws IOException;
}

Some files were not shown because too many files have changed in this diff Show More