master
parent
138bfdbcf0
commit
82c0560bad
18
pom.xml
18
pom.xml
|
|
@ -99,10 +99,28 @@
|
|||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>2.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>3.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package com.boot.security.server.advice;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.UnsatisfiedServletRequestParameterException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
|
||||
import com.boot.security.server.dto.ResponseInfo;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* springmvc异常处理
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
*/
|
||||
@Slf4j(topic = "adminLogger")
|
||||
@RestControllerAdvice
|
||||
public class ExceptionHandlerAdvice {
|
||||
|
||||
@ExceptionHandler({ IllegalArgumentException.class })
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public ResponseInfo badRequestException(IllegalArgumentException exception) {
|
||||
return ResponseInfo.builder().code(HttpStatus.BAD_REQUEST.value() + "").message(exception.getMessage()).build();
|
||||
}
|
||||
|
||||
@ExceptionHandler({ UnknownAccountException.class, IncorrectCredentialsException.class })
|
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||
public ResponseInfo loginException(Exception exception) {
|
||||
return ResponseInfo.builder().code(HttpStatus.UNAUTHORIZED.value() + "").message(exception.getMessage())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ExceptionHandler({ UnauthorizedException.class })
|
||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||
public ResponseInfo forbidden(Exception exception) {
|
||||
return ResponseInfo.builder().code(HttpStatus.FORBIDDEN.value() + "").message(exception.getMessage()).build();
|
||||
}
|
||||
|
||||
@ExceptionHandler({ MissingServletRequestParameterException.class, HttpMessageNotReadableException.class,
|
||||
UnsatisfiedServletRequestParameterException.class, MethodArgumentTypeMismatchException.class })
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public ResponseInfo badRequestException(Exception exception) {
|
||||
return ResponseInfo.builder().code(HttpStatus.BAD_REQUEST.value() + "").message(exception.getMessage()).build();
|
||||
}
|
||||
|
||||
@ExceptionHandler(Throwable.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public ResponseInfo exception(Throwable throwable) {
|
||||
log.error("系统异常", throwable);
|
||||
return ResponseInfo.builder().code(HttpStatus.INTERNAL_SERVER_ERROR.value() + "")
|
||||
.message(throwable.getMessage()).build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.boot.security.server.advice;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.boot.security.server.annotation.LogAnnotation;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* 统一日志处理
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
* 2017年8月19日
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class LogAdvice {
|
||||
|
||||
@Autowired
|
||||
private SysLogService logService;
|
||||
|
||||
@Around(value = "@annotation(com.zw.admin.server.annotation.LogAnnotation)")
|
||||
public Object logSave(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
SysLogs sysLogs = new SysLogs();
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
|
||||
String module = null;
|
||||
LogAnnotation logAnnotation = methodSignature.getMethod().getDeclaredAnnotation(LogAnnotation.class);
|
||||
module = logAnnotation.module();
|
||||
if (StringUtils.isEmpty(module)) {
|
||||
ApiOperation apiOperation = methodSignature.getMethod().getDeclaredAnnotation(ApiOperation.class);
|
||||
if (apiOperation != null) {
|
||||
module = apiOperation.value();
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(module)) {
|
||||
throw new RuntimeException("没有指定日志module");
|
||||
}
|
||||
sysLogs.setModule(module);
|
||||
|
||||
try {
|
||||
Object object = joinPoint.proceed();
|
||||
|
||||
sysLogs.setFlag(true);
|
||||
logService.save(sysLogs);
|
||||
|
||||
return object;
|
||||
} catch (Exception e) {
|
||||
sysLogs.setFlag(false);
|
||||
sysLogs.setRemark(e.getMessage());
|
||||
logService.save(sysLogs);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.boot.security.server.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 日志注解
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
* 2017年8月19日
|
||||
*/
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface LogAnnotation {
|
||||
String module() default "";
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.boot.security.server.config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
|
||||
@Configuration
|
||||
public class JobConfig {
|
||||
|
||||
public static final String KEY = "applicationContextSchedulerContextKey";
|
||||
|
||||
@Bean("adminQuartzScheduler")
|
||||
public SchedulerFactoryBean quartzScheduler(DataSource dataSource) {
|
||||
SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
|
||||
|
||||
try {
|
||||
quartzScheduler.setQuartzProperties(
|
||||
PropertiesLoaderUtils.loadProperties(new ClassPathResource("quartz.properties")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
quartzScheduler.setDataSource(dataSource);
|
||||
quartzScheduler.setOverwriteExistingJobs(true);
|
||||
quartzScheduler.setApplicationContextSchedulerContextKey(KEY);
|
||||
quartzScheduler.setStartupDelay(10);
|
||||
|
||||
return quartzScheduler;
|
||||
}
|
||||
|
||||
// @Autowired
|
||||
// private JobService jobService;
|
||||
// @Autowired
|
||||
// private TaskExecutor taskExecutor;
|
||||
//
|
||||
// /**
|
||||
// * 初始化一个定时删除日志的任务
|
||||
// */
|
||||
// @PostConstruct
|
||||
// public void initDeleteLogsJob() {
|
||||
// taskExecutor.execute(() -> {
|
||||
// JobModel jobModel = new JobModel();
|
||||
// jobModel.setJobName("delete-logs-job");
|
||||
// jobModel.setCron("0 0 0 * * ?");
|
||||
// jobModel.setDescription("定时删除三个月前日志");
|
||||
// jobModel.setSpringBeanName("sysLogServiceImpl");
|
||||
// jobModel.setMethodName("deleteLogs");
|
||||
// jobModel.setIsSysJob(true);
|
||||
// jobModel.setStatus(1);
|
||||
//
|
||||
// jobService.saveJob(jobModel);
|
||||
// });
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.utils.ExcelUtil;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@Api(tags = "excel下载")
|
||||
@RestController
|
||||
@RequestMapping("/excels")
|
||||
public class ExcelController {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@ApiOperation("校验sql,并返回sql返回的数量")
|
||||
@PostMapping("/sql-count")
|
||||
public Integer checkSql(String sql) {
|
||||
sql = getAndCheckSql(sql);
|
||||
|
||||
Integer count = 0;
|
||||
try {
|
||||
count = jdbcTemplate.queryForObject("select count(1) from (" + sql + ") t", Integer.class);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(e.getMessage());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private String getAndCheckSql(String sql) {
|
||||
sql = sql.trim().toLowerCase();
|
||||
if (sql.endsWith(";") || sql.endsWith(";")) {
|
||||
sql = sql.substring(0, sql.length() - 1);
|
||||
}
|
||||
if (!sql.startsWith("select")) {
|
||||
throw new IllegalArgumentException("仅支持select语句");
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation("根据sql导出excel")
|
||||
@PostMapping
|
||||
@RequiresPermissions("excel:down")
|
||||
public void downloadExcel(String sql, String fileName, HttpServletResponse response) {
|
||||
sql = getAndCheckSql(sql);
|
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
Map<String, Object> map = list.get(0);
|
||||
|
||||
String[] headers = new String[map.size()];
|
||||
int i = 0;
|
||||
for (String key : map.keySet()) {
|
||||
headers[i++] = key;
|
||||
}
|
||||
|
||||
List<Object[]> datas = new ArrayList<>(list.size());
|
||||
for (Map<String, Object> m : list) {
|
||||
Object[] objects = new Object[headers.length];
|
||||
for (int j = 0; j < headers.length; j++) {
|
||||
objects[j] = m.get(headers[j]);
|
||||
}
|
||||
|
||||
datas.add(objects);
|
||||
}
|
||||
|
||||
ExcelUtil.excelExport(
|
||||
fileName == null || fileName.trim().length() <= 0 ? DigestUtils.md5Hex(sql) : fileName, headers,
|
||||
datas, response);
|
||||
}
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation("根据sql在页面显示结果")
|
||||
@PostMapping("/show-datas")
|
||||
@RequiresPermissions("excel:show:datas")
|
||||
public List<Object[]> showData(String sql) {
|
||||
sql = getAndCheckSql(sql);
|
||||
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
Map<String, Object> map = list.get(0);
|
||||
|
||||
String[] headers = new String[map.size()];
|
||||
int i = 0;
|
||||
for (String key : map.keySet()) {
|
||||
headers[i++] = key;
|
||||
}
|
||||
|
||||
List<Object[]> datas = new ArrayList<>(list.size());
|
||||
datas.add(headers);
|
||||
for (Map<String, Object> m : list) {
|
||||
Object[] objects = new Object[headers.length];
|
||||
for (int j = 0; j < headers.length; j++) {
|
||||
objects[j] = m.get(headers[j]);
|
||||
}
|
||||
|
||||
datas.add(objects);
|
||||
}
|
||||
|
||||
return datas;
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.FileInfoDao;
|
||||
import com.zw.admin.server.dto.LayuiFile;
|
||||
import com.zw.admin.server.dto.LayuiFile.LayuiFileData;
|
||||
import com.zw.admin.server.model.FileInfo;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.zw.admin.server.service.FileService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@Api(tags = "文件")
|
||||
@RestController
|
||||
@RequestMapping("/files")
|
||||
public class FileController {
|
||||
|
||||
@Autowired
|
||||
private FileService fileService;
|
||||
@Autowired
|
||||
private FileInfoDao fileInfoDao;
|
||||
|
||||
@LogAnnotation
|
||||
@PostMapping
|
||||
@ApiOperation(value = "文件上传")
|
||||
public FileInfo uploadFile(MultipartFile file) throws IOException {
|
||||
return fileService.save(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* layui富文本文件自定义上传
|
||||
*
|
||||
* @param file
|
||||
* @param domain
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@LogAnnotation
|
||||
@PostMapping("/layui")
|
||||
@ApiOperation(value = "layui富文本文件自定义上传")
|
||||
public LayuiFile uploadLayuiFile(MultipartFile file, String domain) throws IOException {
|
||||
FileInfo fileInfo = fileService.save(file);
|
||||
|
||||
LayuiFile layuiFile = new LayuiFile();
|
||||
layuiFile.setCode(0);
|
||||
LayuiFileData data = new LayuiFileData();
|
||||
layuiFile.setData(data);
|
||||
data.setSrc(domain + "/files" + fileInfo.getUrl());
|
||||
data.setTitle(file.getOriginalFilename());
|
||||
|
||||
return layuiFile;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "文件查询")
|
||||
@RequiresPermissions("sys:file:query")
|
||||
public PageTableResponse<FileInfo> listFiles(PageTableRequest request) {
|
||||
return PageTableHandler.<FileInfo> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return fileInfoDao.count(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<FileInfo>() {
|
||||
|
||||
@Override
|
||||
public List<FileInfo> list(PageTableRequest request) {
|
||||
List<FileInfo> list = fileInfoDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
return list;
|
||||
}
|
||||
}).build().handle(request);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@DeleteMapping("/{id}")
|
||||
@ApiOperation(value = "文件删除")
|
||||
@RequiresPermissions("sys:file:del")
|
||||
public void delete(@PathVariable String id) {
|
||||
fileService.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dto.BeanField;
|
||||
import com.zw.admin.server.dto.GenerateDetail;
|
||||
import com.zw.admin.server.dto.GenerateInput;
|
||||
import com.zw.admin.server.service.GenerateService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* 代码生成接口
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
*/
|
||||
@Api(tags = "代码生成")
|
||||
@RestController
|
||||
@RequestMapping("/generate")
|
||||
public class GenerateController {
|
||||
|
||||
@Autowired
|
||||
private GenerateService generateService;
|
||||
|
||||
@ApiOperation("根据表名显示表信息")
|
||||
@GetMapping(params = { "tableName" })
|
||||
@RequiresPermissions("generate:edit")
|
||||
public GenerateDetail generateByTableName(String tableName) {
|
||||
GenerateDetail detail = new GenerateDetail();
|
||||
detail.setBeanName(generateService.upperFirstChar(tableName));
|
||||
List<BeanField> fields = generateService.listBeanField(tableName);
|
||||
detail.setFields(fields);
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation("生成代码")
|
||||
@PostMapping
|
||||
@RequiresPermissions("generate:edit")
|
||||
public void save(@RequestBody GenerateInput input) {
|
||||
generateService.saveCode(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.quartz.CronExpression;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.JobDao;
|
||||
import com.zw.admin.server.model.JobModel;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.service.JobService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@Api(tags = "定时任务")
|
||||
@RestController
|
||||
@RequestMapping("/jobs")
|
||||
public class JobController {
|
||||
|
||||
@Autowired
|
||||
private JobService jobService;
|
||||
@Autowired
|
||||
private JobDao jobDao;
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation("添加定时任务")
|
||||
@PostMapping
|
||||
@RequiresPermissions("job:add")
|
||||
public void add(@RequestBody JobModel jobModel) {
|
||||
JobModel model = jobDao.getByName(jobModel.getJobName());
|
||||
if (model != null) {
|
||||
throw new IllegalArgumentException(jobModel.getJobName() + "已存在");
|
||||
}
|
||||
|
||||
jobModel.setIsSysJob(false);
|
||||
jobService.saveJob(jobModel);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation("修改定时任务")
|
||||
@PutMapping
|
||||
@RequiresPermissions("job:add")
|
||||
public void update(@RequestBody JobModel jobModel) {
|
||||
jobModel.setStatus(1);
|
||||
jobService.saveJob(jobModel);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation("删除定时任务")
|
||||
@DeleteMapping("/{id}")
|
||||
@RequiresPermissions("job:del")
|
||||
public void delete(@PathVariable Long id) throws SchedulerException {
|
||||
jobService.deleteJob(id);
|
||||
}
|
||||
|
||||
@ApiOperation("根据id获取定时任务")
|
||||
@GetMapping("/{id}")
|
||||
@RequiresPermissions("job:query")
|
||||
public JobModel getById(@PathVariable Long id) {
|
||||
return jobDao.getById(id);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "定时任务列表")
|
||||
@RequiresPermissions("job:query")
|
||||
public PageTableResponse<JobModel> list(PageTableRequest request) {
|
||||
return PageTableHandler.<JobModel> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return jobDao.count(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<JobModel>() {
|
||||
|
||||
@Override
|
||||
public List<JobModel> list(PageTableRequest request) {
|
||||
List<JobModel> list = jobDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
return list;
|
||||
}
|
||||
}).build().handle(request);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "校验cron表达式")
|
||||
@GetMapping(params = "cron")
|
||||
public boolean checkCron(String cron) {
|
||||
return CronExpression.isValidExpression(cron);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@ApiOperation(value = "springBean名字")
|
||||
@GetMapping("/beans")
|
||||
public List<String> listAllBeanName() {
|
||||
String[] strings = applicationContext.getBeanDefinitionNames();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String str : strings) {
|
||||
if (str.contains(".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<?> clazz = getClass(str);
|
||||
if (clazz.isAssignableFrom(Controller.class) || clazz.isAnnotationPresent(RestController.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list.add(str);
|
||||
}
|
||||
list.sort((l1, l2) -> l1.compareTo(l2));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "springBean的无参方法")
|
||||
@GetMapping("/beans/{name}")
|
||||
public Set<String> listMethodName(@PathVariable String name) {
|
||||
Class<?> clazz = getClass(name);
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
|
||||
Set<String> names = new HashSet<>();
|
||||
Arrays.asList(methods).parallelStream().forEach(m -> {
|
||||
int b = m.getModifiers();// public 1 static 8 final 16
|
||||
if (b == 1 || b == 9 || b == 17 || b == 25) {
|
||||
Class<?>[] classes = m.getParameterTypes();
|
||||
if (classes.length == 0) {
|
||||
names.add(m.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
private Class<?> getClass(String name) {
|
||||
Object object = applicationContext.getBean(name);
|
||||
Class<?> clazz = object.getClass();
|
||||
if (AopUtils.isAopProxy(object)) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
|
||||
return clazz;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dto.Token;
|
||||
import com.zw.admin.server.model.User;
|
||||
import com.zw.admin.server.service.TokenManager;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* 登陆相关接口
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
*/
|
||||
@Api(tags = "登陆")
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private TokenManager tokenManager;
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation(value = "web端登陆")
|
||||
@PostMapping("/sys/login")
|
||||
public void login(String username, String password) {
|
||||
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
|
||||
SecurityUtils.getSubject().login(usernamePasswordToken);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@ApiOperation(value = "Restful方式登陆,前后端分离时登录接口")
|
||||
@PostMapping("/sys/login/restful")
|
||||
public Token restfulLogin(String username, String password) {
|
||||
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
|
||||
SecurityUtils.getSubject().login(usernamePasswordToken);
|
||||
|
||||
return tokenManager.saveToken(usernamePasswordToken);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "当前登录用户")
|
||||
@GetMapping("/sys/login")
|
||||
public User getLoginInfo() {
|
||||
return UserUtil.getCurrentUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.MailDao;
|
||||
import com.zw.admin.server.model.Mail;
|
||||
import com.zw.admin.server.model.MailTo;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.zw.admin.server.service.MailService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@Api(tags = "邮件")
|
||||
@RestController
|
||||
@RequestMapping("/mails")
|
||||
public class MailController {
|
||||
|
||||
@Autowired
|
||||
private MailDao mailDao;
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
|
||||
@LogAnnotation
|
||||
@PostMapping
|
||||
@ApiOperation(value = "保存邮件")
|
||||
@RequiresPermissions("mail:send")
|
||||
public Mail save(@RequestBody Mail mail) {
|
||||
String toUsers = mail.getToUsers().trim();
|
||||
if (StringUtils.isBlank(toUsers)) {
|
||||
throw new IllegalArgumentException("收件人不能为空");
|
||||
}
|
||||
|
||||
toUsers = toUsers.replace(" ", "");
|
||||
toUsers = toUsers.replace(";", ";");
|
||||
String[] strings = toUsers.split(";");
|
||||
|
||||
List<String> toUser = Arrays.asList(strings);
|
||||
toUser = toUser.stream().filter(u -> !StringUtils.isBlank(u)).map(u -> u.trim()).collect(Collectors.toList());
|
||||
mailService.save(mail, toUser);
|
||||
|
||||
return mail;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据id获取邮件")
|
||||
@RequiresPermissions("mail:all:query")
|
||||
public Mail get(@PathVariable Long id) {
|
||||
return mailDao.getById(id);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/to")
|
||||
@ApiOperation(value = "根据id获取邮件发送详情")
|
||||
@RequiresPermissions("mail:all:query")
|
||||
public List<MailTo> getMailTo(@PathVariable Long id) {
|
||||
return mailDao.getToUsers(id);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "邮件列表")
|
||||
@RequiresPermissions("mail:all:query")
|
||||
public PageTableResponse<Mail> list(PageTableRequest request) {
|
||||
return PageTableHandler.<Mail> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return mailDao.count(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<Mail>() {
|
||||
|
||||
@Override
|
||||
public List<Mail> list(PageTableRequest request) {
|
||||
return mailDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
}
|
||||
}).build().handle(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.NoticeDao;
|
||||
import com.zw.admin.server.dto.NoticeReadVO;
|
||||
import com.zw.admin.server.dto.NoticeVO;
|
||||
import com.zw.admin.server.model.Notice;
|
||||
import com.zw.admin.server.model.Notice.Status;
|
||||
import com.zw.admin.server.model.User;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@Api(tags = "公告")
|
||||
@RestController
|
||||
@RequestMapping("/notices")
|
||||
public class NoticeController {
|
||||
|
||||
@Autowired
|
||||
private NoticeDao noticeDao;
|
||||
|
||||
@LogAnnotation
|
||||
@PostMapping
|
||||
@ApiOperation(value = "保存公告")
|
||||
@RequiresPermissions("notice:add")
|
||||
public Notice saveNotice(@RequestBody Notice notice) {
|
||||
noticeDao.save(notice);
|
||||
|
||||
return notice;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据id获取公告")
|
||||
@RequiresPermissions("notice:query")
|
||||
public Notice get(@PathVariable Long id) {
|
||||
return noticeDao.getById(id);
|
||||
}
|
||||
|
||||
@GetMapping(params = "id")
|
||||
public NoticeVO readNotice(Long id) {
|
||||
NoticeVO vo = new NoticeVO();
|
||||
|
||||
Notice notice = noticeDao.getById(id);
|
||||
if (notice == null || notice.getStatus() == Status.DRAFT) {
|
||||
return vo;
|
||||
}
|
||||
vo.setNotice(notice);
|
||||
|
||||
noticeDao.saveReadRecord(notice.getId(), UserUtil.getCurrentUser().getId());
|
||||
|
||||
List<User> users = noticeDao.listReadUsers(id);
|
||||
vo.setUsers(users);
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@PutMapping
|
||||
@ApiOperation(value = "修改公告")
|
||||
@RequiresPermissions("notice:add")
|
||||
public Notice updateNotice(@RequestBody Notice notice) {
|
||||
Notice no = noticeDao.getById(notice.getId());
|
||||
if (no.getStatus() == Status.PUBLISH) {
|
||||
throw new IllegalArgumentException("发布状态的不能修改");
|
||||
}
|
||||
noticeDao.update(notice);
|
||||
|
||||
return notice;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "公告管理列表")
|
||||
@RequiresPermissions("notice:query")
|
||||
public PageTableResponse<Notice> listNotice(PageTableRequest request) {
|
||||
return PageTableHandler.<Notice> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return noticeDao.count(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<Notice>() {
|
||||
|
||||
@Override
|
||||
public List<Notice> list(PageTableRequest request) {
|
||||
return noticeDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
}
|
||||
}).build().handle(request);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@DeleteMapping("/{id}")
|
||||
@ApiOperation(value = "删除公告")
|
||||
@RequiresPermissions(value = { "notice:del" })
|
||||
public void delete(@PathVariable Long id) {
|
||||
noticeDao.delete(id);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "未读公告数")
|
||||
@GetMapping("/count-unread")
|
||||
public Integer countUnread() {
|
||||
User user = UserUtil.getCurrentUser();
|
||||
return noticeDao.countUnread(user.getId());
|
||||
}
|
||||
|
||||
@GetMapping("/published")
|
||||
@ApiOperation(value = "公告列表")
|
||||
public PageTableResponse<NoticeReadVO> listNoticeReadVO(PageTableRequest request) {
|
||||
request.getParams().put("userId", UserUtil.getCurrentUser().getId());
|
||||
|
||||
return PageTableHandler.<NoticeReadVO> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return noticeDao.countNotice(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<NoticeReadVO>() {
|
||||
|
||||
@Override
|
||||
public List<NoticeReadVO> list(PageTableRequest request) {
|
||||
return noticeDao.listNotice(request.getParams(), request.getOffset(), request.getLimit());
|
||||
}
|
||||
}).build().handle(request);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -20,11 +21,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.boot.security.server.dao.PermissionDao;
|
||||
import com.boot.security.server.model.Permission;
|
||||
import com.boot.security.server.model.SysUser;
|
||||
import com.boot.security.server.service.PermissionService;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.PermissionDao;
|
||||
import com.zw.admin.server.model.Permission;
|
||||
import com.zw.admin.server.model.User;
|
||||
import com.zw.admin.server.service.PermissionService;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
@ -47,12 +50,12 @@ public class PermissionController {
|
|||
|
||||
@ApiOperation(value = "当前登录用户拥有的权限")
|
||||
@GetMapping("/current")
|
||||
public List<Permission> permissionsCurrent() {// TODO
|
||||
List<Permission> list = null;
|
||||
public List<Permission> permissionsCurrent() {
|
||||
List<Permission> list = UserUtil.getCurrentPermissions();
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
SysUser user = new SysUser();
|
||||
User user = UserUtil.getCurrentUser();
|
||||
list = permissionDao.listByUserId(user.getId());
|
||||
UserUtil.setPermissionSession(list);
|
||||
}
|
||||
final List<Permission> permissions = list.stream().filter(l -> l.getType().equals(1))
|
||||
.collect(Collectors.toList());
|
||||
|
|
@ -90,6 +93,7 @@ public class PermissionController {
|
|||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "菜单列表")
|
||||
@RequiresPermissions("sys:menu:query")
|
||||
public List<Permission> permissionsList() {
|
||||
List<Permission> permissionsAll = permissionDao.listAll();
|
||||
|
||||
|
|
@ -101,6 +105,7 @@ public class PermissionController {
|
|||
|
||||
@GetMapping("/all")
|
||||
@ApiOperation(value = "所有菜单")
|
||||
@RequiresPermissions("sys:menu:query")
|
||||
public JSONArray permissionsAll() {
|
||||
List<Permission> permissionsAll = permissionDao.listAll();
|
||||
JSONArray array = new JSONArray();
|
||||
|
|
@ -111,6 +116,7 @@ public class PermissionController {
|
|||
|
||||
@GetMapping("/parents")
|
||||
@ApiOperation(value = "一级菜单")
|
||||
@RequiresPermissions("sys:menu:query")
|
||||
public List<Permission> parentMenu() {
|
||||
List<Permission> parents = permissionDao.listParents();
|
||||
|
||||
|
|
@ -142,24 +148,30 @@ public class PermissionController {
|
|||
|
||||
@GetMapping(params = "roleId")
|
||||
@ApiOperation(value = "根据角色id删除权限")
|
||||
@RequiresPermissions(value = { "sys:menu:query", "sys:role:query" }, logical = Logical.OR)
|
||||
public List<Permission> listByRoleId(Long roleId) {
|
||||
return permissionDao.listByRoleId(roleId);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@PostMapping
|
||||
@ApiOperation(value = "保存菜单")
|
||||
@RequiresPermissions("sys:menu:add")
|
||||
public void save(@RequestBody Permission permission) {
|
||||
permissionDao.save(permission);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据菜单id获取菜单")
|
||||
@RequiresPermissions("sys:menu:query")
|
||||
public Permission get(@PathVariable Long id) {
|
||||
return permissionDao.getById(id);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@PutMapping
|
||||
@ApiOperation(value = "修改菜单")
|
||||
@RequiresPermissions("sys:menu:add")
|
||||
public void update(@RequestBody Permission permission) {
|
||||
permissionDao.update(permission);
|
||||
}
|
||||
|
|
@ -171,8 +183,8 @@ public class PermissionController {
|
|||
*/
|
||||
@GetMapping("/owns")
|
||||
@ApiOperation(value = "校验当前用户的权限")
|
||||
public Set<String> ownsPermission() {// TODO
|
||||
List<Permission> permissions = new ArrayList<>();
|
||||
public Set<String> ownsPermission() {
|
||||
List<Permission> permissions = UserUtil.getCurrentPermissions();
|
||||
if (CollectionUtils.isEmpty(permissions)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
|
@ -181,8 +193,10 @@ public class PermissionController {
|
|||
.map(Permission::getPermission).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@DeleteMapping("/{id}")
|
||||
@ApiOperation(value = "删除菜单")
|
||||
@RequiresPermissions(value = { "sys:menu:del" })
|
||||
public void delete(@PathVariable Long id) {
|
||||
permissionService.delete(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package com.boot.security.server.controller;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
|
@ -12,16 +13,17 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.boot.security.server.dao.RoleDao;
|
||||
import com.boot.security.server.dto.RoleDto;
|
||||
import com.boot.security.server.model.Role;
|
||||
import com.boot.security.server.page.table.PageTableHandler;
|
||||
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.boot.security.server.page.table.PageTableRequest;
|
||||
import com.boot.security.server.page.table.PageTableResponse;
|
||||
import com.boot.security.server.service.RoleService;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.RoleDao;
|
||||
import com.zw.admin.server.dto.RoleDto;
|
||||
import com.zw.admin.server.model.Role;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.zw.admin.server.service.RoleService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
@ -42,14 +44,17 @@ public class RoleController {
|
|||
@Autowired
|
||||
private RoleDao roleDao;
|
||||
|
||||
@LogAnnotation
|
||||
@PostMapping
|
||||
@ApiOperation(value = "保存角色")
|
||||
@RequiresPermissions("sys:role:add")
|
||||
public void saveRole(@RequestBody RoleDto roleDto) {
|
||||
roleService.saveRole(roleDto);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "角色列表")
|
||||
@RequiresPermissions("sys:role:query")
|
||||
public PageTableResponse<Role> listRoles(PageTableRequest request) {
|
||||
return PageTableHandler.<Role> builder().countHandler(new CountHandler() {
|
||||
|
||||
|
|
@ -67,28 +72,31 @@ public class RoleController {
|
|||
}).build().handle(request);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:role:query')")
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation(value = "根据id获取角色")
|
||||
@RequiresPermissions("sys:role:query")
|
||||
public Role get(@PathVariable Long id) {
|
||||
return roleDao.getById(id);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('sys:user:query','sys:role:query')")
|
||||
@GetMapping("/all")
|
||||
@ApiOperation(value = "所有角色")
|
||||
@RequiresPermissions(value = { "sys:user:query", "sys:role:query" }, logical = Logical.OR)
|
||||
public List<Role> roles() {
|
||||
return roleDao.list(Maps.newHashMap(), null, null);
|
||||
}
|
||||
|
||||
@GetMapping(params = "userId")
|
||||
@ApiOperation(value = "根据用户id获取拥有的角色")
|
||||
@RequiresPermissions(value = { "sys:user:query", "sys:role:query" }, logical = Logical.OR)
|
||||
public List<Role> roles(Long userId) {
|
||||
return roleDao.listByUserId(userId);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@DeleteMapping("/{id}")
|
||||
@ApiOperation(value = "删除角色")
|
||||
@RequiresPermissions(value = { "sys:role:del" })
|
||||
public void delete(@PathVariable Long id) {
|
||||
roleService.deleteRole(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package com.boot.security.server.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.zw.admin.server.dao.SysLogsDao;
|
||||
import com.zw.admin.server.model.SysLogs;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@Api(tags = "日志")
|
||||
@RestController
|
||||
@RequestMapping("/logs")
|
||||
public class SysLogsController {
|
||||
|
||||
@Autowired
|
||||
private SysLogsDao sysLogsDao;
|
||||
|
||||
@GetMapping
|
||||
@RequiresPermissions(value = "sys:log:query")
|
||||
@ApiOperation(value = "日志列表")
|
||||
public PageTableResponse<SysLogs> list(PageTableRequest request) {
|
||||
return PageTableHandler.<SysLogs> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return sysLogsDao.count(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<SysLogs>() {
|
||||
|
||||
@Override
|
||||
public List<SysLogs> list(PageTableRequest request) {
|
||||
return sysLogsDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
}
|
||||
}).build().handle(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@ package com.boot.security.server.controller;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
|
@ -13,15 +13,17 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.boot.security.server.dao.UserDao;
|
||||
import com.boot.security.server.dto.UserDto;
|
||||
import com.boot.security.server.model.SysUser;
|
||||
import com.boot.security.server.page.table.PageTableHandler;
|
||||
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.boot.security.server.page.table.PageTableRequest;
|
||||
import com.boot.security.server.page.table.PageTableResponse;
|
||||
import com.boot.security.server.service.UserService;
|
||||
import com.zw.admin.server.annotation.LogAnnotation;
|
||||
import com.zw.admin.server.dao.UserDao;
|
||||
import com.zw.admin.server.dto.UserDto;
|
||||
import com.zw.admin.server.model.User;
|
||||
import com.zw.admin.server.page.table.PageTableRequest;
|
||||
import com.zw.admin.server.page.table.PageTableHandler;
|
||||
import com.zw.admin.server.page.table.PageTableResponse;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.CountHandler;
|
||||
import com.zw.admin.server.page.table.PageTableHandler.ListHandler;
|
||||
import com.zw.admin.server.service.UserService;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
@ -44,10 +46,12 @@ public class UserController {
|
|||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@LogAnnotation
|
||||
@PostMapping
|
||||
@ApiOperation(value = "保存用户")
|
||||
public SysUser saveUser(@RequestBody UserDto userDto) {
|
||||
SysUser u = userService.getUser(userDto.getUsername());
|
||||
@RequiresPermissions("sys:user:add")
|
||||
public User saveUser(@RequestBody UserDto userDto) {
|
||||
User u = userService.getUser(userDto.getUsername());
|
||||
if (u != null) {
|
||||
throw new IllegalArgumentException(userDto.getUsername() + "已存在");
|
||||
}
|
||||
|
|
@ -55,17 +59,19 @@ public class UserController {
|
|||
return userService.saveUser(userDto);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@PutMapping
|
||||
@ApiOperation(value = "修改用户")
|
||||
public SysUser updateUser(@RequestBody UserDto userDto) {
|
||||
@RequiresPermissions("sys:user:add")
|
||||
public User updateUser(@RequestBody UserDto userDto) {
|
||||
return userService.updateUser(userDto);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@PutMapping(params = "headImgUrl")
|
||||
@ApiOperation(value = "修改头像")
|
||||
public void updateHeadImgUrl(String headImgUrl) {
|
||||
// SysUser user = UserUtil.getCurrentUser();
|
||||
SysUser user = new SysUser();// TODO
|
||||
User user = UserUtil.getCurrentUser();
|
||||
UserDto userDto = new UserDto();
|
||||
BeanUtils.copyProperties(user, userDto);
|
||||
userDto.setHeadImgUrl(headImgUrl);
|
||||
|
|
@ -74,26 +80,29 @@ public class UserController {
|
|||
log.debug("{}修改了头像", user.getUsername());
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@PutMapping("/{username}")
|
||||
@ApiOperation(value = "修改密码")
|
||||
@RequiresPermissions("sys:user:password")
|
||||
public void changePassword(@PathVariable String username, String oldPassword, String newPassword) {
|
||||
userService.changePassword(username, oldPassword, newPassword);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation(value = "用户列表")
|
||||
public PageTableResponse<SysUser> listUsers(PageTableRequest request) {
|
||||
return PageTableHandler.<SysUser> builder().countHandler(new CountHandler() {
|
||||
@RequiresPermissions("sys:user:query")
|
||||
public PageTableResponse<User> listUsers(PageTableRequest request) {
|
||||
return PageTableHandler.<User> builder().countHandler(new CountHandler() {
|
||||
|
||||
@Override
|
||||
public int count(PageTableRequest request) {
|
||||
return userDao.count(request.getParams());
|
||||
}
|
||||
}).listHandler(new ListHandler<SysUser>() {
|
||||
}).listHandler(new ListHandler<User>() {
|
||||
|
||||
@Override
|
||||
public List<SysUser> list(PageTableRequest request) {
|
||||
List<SysUser> list = userDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
public List<User> list(PageTableRequest request) {
|
||||
List<User> list = userDao.list(request.getParams(), request.getOffset(), request.getLimit());
|
||||
return list;
|
||||
}
|
||||
}).build().handle(request);
|
||||
|
|
@ -101,15 +110,14 @@ public class UserController {
|
|||
|
||||
@ApiOperation(value = "当前登录用户")
|
||||
@GetMapping("/current")
|
||||
public SysUser currentUser() {// TODO
|
||||
// User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
return new SysUser();
|
||||
public User currentUser() {
|
||||
return UserUtil.getCurrentUser();
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:user:query')")
|
||||
@ApiOperation(value = "根据用户id获取用户")
|
||||
@GetMapping("/{id}")
|
||||
public SysUser user(@PathVariable Long id) {
|
||||
@RequiresPermissions("sys:user:query")
|
||||
public User user(@PathVariable Long id) {
|
||||
return userDao.getById(id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.zw.admin.server.model.FileInfo;
|
||||
|
||||
@Mapper
|
||||
public interface FileInfoDao {
|
||||
|
||||
@Select("select * from file_info t where t.id = #{id}")
|
||||
FileInfo getById(String id);
|
||||
|
||||
@Insert("insert into file_info(id, contentType, size, path, url, type, createTime, updateTime) values(#{id}, #{contentType}, #{size}, #{path}, #{url}, #{type}, now(), now())")
|
||||
int save(FileInfo fileInfo);
|
||||
|
||||
@Update("update file_info t set t.updateTime = now() where t.id = #{id}")
|
||||
int update(FileInfo fileInfo);
|
||||
|
||||
@Delete("delete from file_info where id = #{id}")
|
||||
int delete(String id);
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<FileInfo> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.zw.admin.server.model.JobModel;
|
||||
|
||||
@Mapper
|
||||
public interface JobDao {
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into t_job(jobName, description, cron, springBeanName, methodName, isSysJob, status, createTime, updateTime) values(#{jobName}, #{description}, #{cron}, #{springBeanName}, #{methodName}, #{isSysJob}, 1, now(), now())")
|
||||
int save(JobModel jobModel);
|
||||
|
||||
@Select("select * from t_job t where t.id = #{id}")
|
||||
JobModel getById(Long id);
|
||||
|
||||
@Select("select * from t_job t where t.jobName = #{jobName}")
|
||||
JobModel getByName(String jobName);
|
||||
|
||||
int update(JobModel jobModel);
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<JobModel> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.zw.admin.server.model.Mail;
|
||||
import com.zw.admin.server.model.MailTo;
|
||||
|
||||
@Mapper
|
||||
public interface MailDao {
|
||||
|
||||
@Select("select * from t_mail t where t.id = #{id}")
|
||||
Mail getById(Long id);
|
||||
|
||||
// @Delete("delete from t_mail where id = #{id}")
|
||||
// int delete(Long id);
|
||||
|
||||
// @Update("update t_mail t set subject = #{subject}, content = #{content}, updateTime = now() where t.id = #{id}")
|
||||
// int update(Mail mail);
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into t_mail(userId, subject, content, createTime, updateTime) values(#{userId}, #{subject}, #{content}, now(), now())")
|
||||
int save(Mail mail);
|
||||
|
||||
@Insert("insert into t_mail_to(mailId, toUser, status) values(#{mailId}, #{toUser}, #{status})")
|
||||
int saveToUser(@Param("mailId") Long mailId, @Param("toUser") String toUser, @Param("status") int status);
|
||||
|
||||
@Select("select t.* from t_mail_to t where t.mailId = #{mailId}")
|
||||
List<MailTo> getToUsers(Long mailId);
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<Mail> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.zw.admin.server.dto.NoticeReadVO;
|
||||
import com.zw.admin.server.model.Notice;
|
||||
import com.zw.admin.server.model.User;
|
||||
|
||||
@Mapper
|
||||
public interface NoticeDao {
|
||||
|
||||
@Select("select * from t_notice t where t.id = #{id}")
|
||||
Notice getById(Long id);
|
||||
|
||||
@Delete("delete from t_notice where id = #{id}")
|
||||
int delete(Long id);
|
||||
|
||||
@Update("update t_notice t set title = #{title}, content = #{content}, status = #{status}, updateTime = #{updateTime} where t.id = #{id}")
|
||||
int update(Notice notice);
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into t_notice(title, content, status, createTime, updateTime) values(#{title}, #{content}, #{status}, #{createTime}, #{updateTime})")
|
||||
int save(Notice notice);
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<Notice> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
@Insert("insert ignore into t_notice_read(noticeId, userId, createTime) values(#{noticeId}, #{userId}, now())")
|
||||
int saveReadRecord(@Param("noticeId") Long noticeId, @Param("userId") Long userId);
|
||||
|
||||
List<User> listReadUsers(Long noticeId);
|
||||
|
||||
@Select("select count(1) from t_notice t left join t_notice_read r on r.noticeId = t.id and r.userId = #{userId} where t.status = 1 and r.userId is null")
|
||||
int countUnread(Long userId);
|
||||
|
||||
int countNotice(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<NoticeReadVO> listNotice(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.boot.security.server.model.Permission;
|
||||
import com.zw.admin.server.model.Permission;
|
||||
|
||||
@Mapper
|
||||
public interface PermissionDao {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Param;
|
|||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.boot.security.server.model.Role;
|
||||
import com.zw.admin.server.model.Role;
|
||||
|
||||
@Mapper
|
||||
public interface RoleDao {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.zw.admin.server.model.SysLogs;
|
||||
|
||||
@Mapper
|
||||
public interface SysLogsDao {
|
||||
|
||||
@Insert("insert into sys_logs(userId, module, flag, remark, createTime) values(#{user.id}, #{module}, #{flag}, #{remark}, now())")
|
||||
int save(SysLogs sysLogs);
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<SysLogs> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
@Delete("delete from sys_logs where createTime <= #{time}")
|
||||
int deleteLogs(String time);
|
||||
}
|
||||
|
|
@ -11,27 +11,27 @@ import org.apache.ibatis.annotations.Param;
|
|||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.boot.security.server.model.SysUser;
|
||||
import com.zw.admin.server.model.User;
|
||||
|
||||
@Mapper
|
||||
public interface UserDao {
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into sys_user(username, password, salt, nickname, headImgUrl, phone, telephone, email, birthday, sex, status, intro, createTime, updateTime) values(#{username}, #{password}, #{salt}, #{nickname}, #{headImgUrl}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, #{intro}, now(), now())")
|
||||
int save(SysUser user);
|
||||
@Insert("insert into sys_user(username, password, salt, nickname, headImgUrl, phone, telephone, email, birthday, sex, status, createTime, updateTime) values(#{username}, #{password}, #{salt}, #{nickname}, #{headImgUrl}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, now(), now())")
|
||||
int save(User user);
|
||||
|
||||
@Select("select * from sys_user t where t.id = #{id}")
|
||||
SysUser getById(Long id);
|
||||
User getById(Long id);
|
||||
|
||||
@Select("select * from sys_user t where t.username = #{username}")
|
||||
SysUser getUser(String username);
|
||||
User getUser(String username);
|
||||
|
||||
@Update("update sys_user t set t.password = #{password} where t.id = #{id}")
|
||||
int changePassword(@Param("id") Long id, @Param("password") String password);
|
||||
|
||||
Integer count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<SysUser> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
List<User> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
@Delete("delete from sys_role_user where userId = #{userId}")
|
||||
|
|
@ -39,5 +39,5 @@ public interface UserDao {
|
|||
|
||||
int saveUserRoles(@Param("userId") Long userId, @Param("roleIds") List<Long> roleIds);
|
||||
|
||||
int update(SysUser user);
|
||||
int update(User user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.boot.security.server.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BeanField implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4279960350136806659L;
|
||||
|
||||
private String columnName;
|
||||
|
||||
private String columnType;
|
||||
|
||||
private String columnComment;
|
||||
|
||||
private String columnDefault;
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.boot.security.server.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GenerateDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -164567294469931676L;
|
||||
|
||||
private String beanName;
|
||||
|
||||
private List<BeanField> fields;
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.boot.security.server.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GenerateInput implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2870071259702969061L;
|
||||
|
||||
/**
|
||||
* 保存路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* bean包名
|
||||
*/
|
||||
private String beanPackageName;
|
||||
|
||||
/**
|
||||
* java类名
|
||||
*/
|
||||
private String beanName;
|
||||
/**
|
||||
* dao包名
|
||||
*/
|
||||
private String daoPackageName;
|
||||
|
||||
/**
|
||||
* dao类名
|
||||
*/
|
||||
private String daoName;
|
||||
/**
|
||||
* controller包名
|
||||
*/
|
||||
private String controllerPkgName;
|
||||
/**
|
||||
* controller类名
|
||||
*/
|
||||
private String controllerName;
|
||||
/**
|
||||
* 字段名
|
||||
*/
|
||||
private List<String> columnNames;
|
||||
/**
|
||||
* 属性名
|
||||
*/
|
||||
private List<String> beanFieldName;
|
||||
/**
|
||||
* 成员变量类型
|
||||
*/
|
||||
private List<String> beanFieldType;
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
private List<String> beanFieldValue;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.boot.security.server.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class LayuiFile implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 35435494737590569L;
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private LayuiFileData data;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class LayuiFileData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7907356434695924597L;
|
||||
private String src;
|
||||
private String title;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.boot.security.server.dto;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.boot.security.server.model.Notice;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class NoticeReadVO extends Notice {
|
||||
|
||||
private static final long serialVersionUID = -3842182350180882396L;
|
||||
|
||||
private Long userId;
|
||||
private Date readTime;
|
||||
private Boolean isRead;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.boot.security.server.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.boot.security.server.model.Notice;
|
||||
import com.boot.security.server.model.SysUser;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class NoticeVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7363353918096951799L;
|
||||
|
||||
private Notice notice;
|
||||
|
||||
private List<SysUser> users;
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ public class TokenFilter extends OncePerRequestFilter {
|
|||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
System.out.println(request.getRequestURI());
|
||||
String token = getToken(request);
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(token);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.boot.security.server.job;
|
||||
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import com.boot.security.server.config.JobConfig;
|
||||
|
||||
public class SpringBeanJob extends QuartzJobBean {
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
try {
|
||||
ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext()
|
||||
.get(JobConfig.KEY);
|
||||
JobService jobService = applicationContext.getBean(JobService.class);
|
||||
jobService.doJob(context.getJobDetail().getJobDataMap());
|
||||
} catch (SchedulerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.boot.security.server.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class FileInfo extends BaseEntity<String> {
|
||||
|
||||
private static final long serialVersionUID = -5761547882766615438L;
|
||||
|
||||
private String contentType;
|
||||
private long size;
|
||||
private String path;
|
||||
private String url;
|
||||
private Integer type;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.boot.security.server.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class JobModel extends BaseEntity<Long> {
|
||||
|
||||
private static final long serialVersionUID = -2458935535811207209L;
|
||||
|
||||
private String jobName;
|
||||
|
||||
private String description;
|
||||
|
||||
private String cron;
|
||||
|
||||
private String springBeanName;
|
||||
|
||||
private String methodName;
|
||||
|
||||
private Boolean isSysJob;
|
||||
|
||||
private int status;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.boot.security.server.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Mail extends BaseEntity<Long> {
|
||||
|
||||
private static final long serialVersionUID = 5613231124043303948L;
|
||||
|
||||
private Long userId;
|
||||
private String toUsers;
|
||||
private String subject;
|
||||
private String content;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.boot.security.server.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class MailTo extends BaseEntity<Long> {
|
||||
|
||||
private static final long serialVersionUID = -8238779033956731073L;
|
||||
|
||||
private Long mailId;
|
||||
private String toUser;
|
||||
private Boolean status;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.boot.security.server.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Notice extends BaseEntity<Long> {
|
||||
|
||||
private static final long serialVersionUID = -4401913568806243090L;
|
||||
|
||||
private String title;
|
||||
private String content;
|
||||
private Integer status;
|
||||
|
||||
public interface Status {
|
||||
int DRAFT = 0;
|
||||
int PUBLISH = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.boot.security.server.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SysLogs extends BaseEntity<Long> {
|
||||
|
||||
private static final long serialVersionUID = -7809315432127036583L;
|
||||
private SysUser user;
|
||||
private String module;
|
||||
private Boolean flag;
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.boot.security.server.model.FileInfo;
|
||||
|
||||
public interface FileService {
|
||||
|
||||
FileInfo save(MultipartFile file) throws IOException;
|
||||
|
||||
void delete(String id);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.boot.security.server.dto.BeanField;
|
||||
import com.boot.security.server.dto.GenerateInput;
|
||||
|
||||
public interface GenerateService {
|
||||
|
||||
/**
|
||||
* 获取数据库表信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<BeanField> listBeanField(String tableName);
|
||||
|
||||
/**
|
||||
* 转成驼峰并大写第一个字母
|
||||
*
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
String upperFirstChar(String string);
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
void saveCode(GenerateInput input);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import com.boot.security.server.model.JobModel;
|
||||
|
||||
public interface JobService {
|
||||
|
||||
void saveJob(JobModel jobModel);
|
||||
|
||||
void doJob(JobDataMap jobDataMap);
|
||||
|
||||
void deleteJob(Long id) throws SchedulerException;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.boot.security.server.model.Mail;
|
||||
|
||||
public interface MailService {
|
||||
|
||||
void save(Mail mail, List<String> toUser);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
public interface SendMailSevice {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param toUser
|
||||
* @param subject
|
||||
* 标题
|
||||
* @param text
|
||||
* 内容(支持html格式)
|
||||
*/
|
||||
void sendMail(List<String> toUser, String subject, String text);
|
||||
|
||||
void sendMail(String toUser, String subject, String text) throws MessagingException;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import com.boot.security.server.model.SysLogs;
|
||||
|
||||
/**
|
||||
* 日志service
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
* 2017年8月19日
|
||||
*/
|
||||
public interface SysLogService {
|
||||
|
||||
void save(SysLogs sysLogs);
|
||||
|
||||
void save(Long userId, String module, Boolean flag, String remark);
|
||||
|
||||
void deleteLogs();
|
||||
}
|
||||
|
|
@ -1,15 +1,17 @@
|
|||
package com.boot.security.server.service;
|
||||
|
||||
import com.boot.security.server.dto.UserDto;
|
||||
import com.boot.security.server.model.SysUser;
|
||||
import com.zw.admin.server.dto.UserDto;
|
||||
import com.zw.admin.server.model.User;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
SysUser saveUser(UserDto userDto);
|
||||
User saveUser(UserDto userDto);
|
||||
|
||||
User updateUser(UserDto userDto);
|
||||
|
||||
SysUser updateUser(UserDto userDto);
|
||||
String passwordEncoder(String credentials, String salt);
|
||||
|
||||
SysUser getUser(String username);
|
||||
User getUser(String username);
|
||||
|
||||
void changePassword(String username, String oldPassword, String newPassword);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.zw.admin.server.dao.FileInfoDao;
|
||||
import com.zw.admin.server.model.FileInfo;
|
||||
import com.zw.admin.server.service.FileService;
|
||||
import com.zw.admin.server.utils.FileUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j(topic = "adminLogger")
|
||||
@Service
|
||||
public class FileServiceImpl implements FileService {
|
||||
|
||||
@Value("${files.path}")
|
||||
private String filesPath;
|
||||
@Autowired
|
||||
private FileInfoDao fileInfoDao;
|
||||
|
||||
@Override
|
||||
public FileInfo save(MultipartFile file) throws IOException {
|
||||
String fileOrigName = file.getOriginalFilename();
|
||||
if (!fileOrigName.contains(".")) {
|
||||
throw new IllegalArgumentException("缺少后缀名");
|
||||
}
|
||||
|
||||
String md5 = FileUtil.fileMd5(file.getInputStream());
|
||||
FileInfo fileInfo = fileInfoDao.getById(md5);
|
||||
if (fileInfo != null) {
|
||||
fileInfoDao.update(fileInfo);
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
fileOrigName = fileOrigName.substring(fileOrigName.lastIndexOf("."));
|
||||
String pathname = FileUtil.getPath() + md5 + fileOrigName;
|
||||
String fullPath = filesPath + pathname;
|
||||
FileUtil.saveFile(file, fullPath);
|
||||
|
||||
long size = file.getSize();
|
||||
String contentType = file.getContentType();
|
||||
|
||||
fileInfo = new FileInfo();
|
||||
fileInfo.setId(md5);
|
||||
fileInfo.setContentType(contentType);
|
||||
fileInfo.setSize(size);
|
||||
fileInfo.setPath(fullPath);
|
||||
fileInfo.setUrl(pathname);
|
||||
fileInfo.setType(contentType.startsWith("image/") ? 1 : 0);
|
||||
|
||||
fileInfoDao.save(fileInfo);
|
||||
|
||||
log.debug("上传文件{}", fullPath);
|
||||
|
||||
return fileInfo;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
FileInfo fileInfo = fileInfoDao.getById(id);
|
||||
if (fileInfo != null) {
|
||||
String fullPath = fileInfo.getPath();
|
||||
FileUtil.deleteFile(fullPath);
|
||||
|
||||
fileInfoDao.delete(id);
|
||||
log.debug("删除文件:{}", fileInfo.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.zw.admin.server.dto.BeanField;
|
||||
import com.zw.admin.server.dto.GenerateInput;
|
||||
import com.zw.admin.server.service.GenerateService;
|
||||
import com.zw.admin.server.utils.StrUtil;
|
||||
import com.zw.admin.server.utils.TemplateUtil;
|
||||
|
||||
@Service
|
||||
public class GenerateServiceImpl implements GenerateService {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private RowMapper<BeanField> beanFieldMapper = new RowMapper<BeanField>() {
|
||||
|
||||
@Override
|
||||
public BeanField mapRow(ResultSet rs, int paramInt) throws SQLException {
|
||||
BeanField beanField = new BeanField();
|
||||
beanField.setColumnName(rs.getString("column_name"));
|
||||
beanField.setColumnType(rs.getString("data_type"));
|
||||
beanField.setColumnComment(rs.getString("column_comment"));
|
||||
beanField.setColumnDefault(rs.getString("column_default"));
|
||||
|
||||
return beanField;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public List<BeanField> listBeanField(String tableName) {
|
||||
List<BeanField> beanFields = jdbcTemplate.query(
|
||||
"select column_name, data_type, column_comment, column_default FROM information_schema.columns WHERE table_name= ? and table_schema = (select database())",
|
||||
new String[] { tableName }, beanFieldMapper);
|
||||
if (CollectionUtils.isEmpty(beanFields)) {
|
||||
throw new IllegalArgumentException("表" + tableName + "不存在");
|
||||
}
|
||||
|
||||
beanFields.parallelStream().forEach(b -> {
|
||||
b.setName(StrUtil.str2hump(b.getColumnName()));
|
||||
String type = map.get(b.getColumnType());
|
||||
if (type == null) {
|
||||
type = String.class.getSimpleName();
|
||||
}
|
||||
b.setType(type);
|
||||
if ("id".equals(b.getName())) {
|
||||
b.setType(Long.class.getSimpleName());
|
||||
}
|
||||
|
||||
b.setColumnDefault(b.getColumnDefault() == null ? "" : b.getColumnDefault());
|
||||
});
|
||||
|
||||
return beanFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* mysql类型与java类型部分对应关系
|
||||
*/
|
||||
private static Map<String, String> map = Maps.newHashMap();
|
||||
static {
|
||||
map.put("int", Integer.class.getSimpleName());
|
||||
map.put("tinyint", Integer.class.getSimpleName());
|
||||
map.put("double", Double.class.getSimpleName());
|
||||
map.put("float", Float.class.getSimpleName());
|
||||
map.put("decimal", BigDecimal.class.getSimpleName());
|
||||
map.put("date", Date.class.getSimpleName());
|
||||
map.put("timestamp", Date.class.getSimpleName());
|
||||
map.put("datetime", Date.class.getSimpleName());
|
||||
map.put("varchar", String.class.getSimpleName());
|
||||
map.put("text", String.class.getSimpleName());
|
||||
map.put("longtext", String.class.getSimpleName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upperFirstChar(String string) {
|
||||
String name = StrUtil.str2hump(string);
|
||||
String firstChar = name.substring(0, 1);
|
||||
name = name.replaceFirst(firstChar, firstChar.toUpperCase());
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCode(GenerateInput input) {
|
||||
TemplateUtil.saveJava(input);
|
||||
TemplateUtil.saveJavaDao(input);
|
||||
TemplateUtil.saveController(input);
|
||||
TemplateUtil.saveHtmlList(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.quartz.CronScheduleBuilder;
|
||||
import org.quartz.CronTrigger;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobDetail;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.quartz.TriggerBuilder;
|
||||
import org.quartz.TriggerKey;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.zw.admin.server.dao.JobDao;
|
||||
import com.zw.admin.server.job.SpringBeanJob;
|
||||
import com.zw.admin.server.model.JobModel;
|
||||
import com.zw.admin.server.service.JobService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j(topic = "adminLogger")
|
||||
@Service
|
||||
public class JobServiceImpl implements JobService {
|
||||
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private static final String JOB_DATA_KEY = "JOB_DATA_KEY";
|
||||
@Autowired
|
||||
private JobDao jobDao;
|
||||
|
||||
@Override
|
||||
public void saveJob(JobModel jobModel) {
|
||||
checkJobModel(jobModel);
|
||||
String name = jobModel.getJobName();
|
||||
|
||||
JobKey jobKey = JobKey.jobKey(name);
|
||||
JobDetail jobDetail = JobBuilder.newJob(SpringBeanJob.class).storeDurably()
|
||||
.withDescription(jobModel.getDescription()).withIdentity(jobKey).build();
|
||||
|
||||
jobDetail.getJobDataMap().put(JOB_DATA_KEY, jobModel);
|
||||
|
||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(jobModel.getCron());
|
||||
CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(name).withSchedule(cronScheduleBuilder)
|
||||
.forJob(jobKey).build();
|
||||
|
||||
try {
|
||||
boolean exists = scheduler.checkExists(jobKey);
|
||||
if (exists) {
|
||||
scheduler.rescheduleJob(new TriggerKey(name), cronTrigger);
|
||||
scheduler.addJob(jobDetail, true);
|
||||
} else {
|
||||
scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||
}
|
||||
|
||||
JobModel model = jobDao.getByName(name);
|
||||
if (model == null) {
|
||||
jobDao.save(jobModel);
|
||||
} else {
|
||||
jobDao.update(jobModel);
|
||||
}
|
||||
} catch (SchedulerException e) {
|
||||
log.error("新增或修改job异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkJobModel(JobModel jobModel) {
|
||||
String springBeanName = jobModel.getSpringBeanName();
|
||||
boolean flag = applicationContext.containsBean(springBeanName);
|
||||
if (!flag) {
|
||||
throw new IllegalArgumentException("bean:" + springBeanName + "不存在,bean名如userServiceImpl,首字母小写");
|
||||
}
|
||||
|
||||
Object object = applicationContext.getBean(springBeanName);
|
||||
Class<?> clazz = object.getClass();
|
||||
if (AopUtils.isAopProxy(object)) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
|
||||
String methodName = jobModel.getMethodName();
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
|
||||
Set<String> names = new HashSet<>();
|
||||
Arrays.asList(methods).parallelStream().forEach(m -> {
|
||||
Class<?>[] classes = m.getParameterTypes();
|
||||
if (classes.length == 0) {
|
||||
names.add(m.getName());
|
||||
}
|
||||
});
|
||||
|
||||
if (names.size() == 0) {
|
||||
throw new IllegalArgumentException("该bean没有无参方法");
|
||||
}
|
||||
|
||||
if (!names.contains(methodName)) {
|
||||
throw new IllegalArgumentException("未找到无参方法" + methodName + ",该bean所有方法名为:" + names);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doJob(JobDataMap jobDataMap) {
|
||||
JobModel jobModel = (JobModel) jobDataMap.get(JOB_DATA_KEY);
|
||||
|
||||
String beanName = jobModel.getSpringBeanName();
|
||||
String methodName = jobModel.getMethodName();
|
||||
Object object = applicationContext.getBean(beanName);
|
||||
|
||||
try {
|
||||
log.info("job:bean:{},方法名:{}", beanName, methodName);
|
||||
Method method = object.getClass().getDeclaredMethod(methodName);
|
||||
method.invoke(object);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除job
|
||||
*
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
@Override
|
||||
public void deleteJob(Long id) throws SchedulerException {
|
||||
JobModel jobModel = jobDao.getById(id);
|
||||
|
||||
if (jobModel.getIsSysJob() != null && jobModel.getIsSysJob()) {
|
||||
throw new IllegalArgumentException("该job是系统任务,不能删除,因为此job是在代码里初始化的,删除该类job请先确保相关代码已经去除");
|
||||
}
|
||||
|
||||
String jobName = jobModel.getJobName();
|
||||
JobKey jobKey = JobKey.jobKey(jobName);
|
||||
|
||||
scheduler.pauseJob(jobKey);
|
||||
scheduler.unscheduleJob(new TriggerKey(jobName));
|
||||
scheduler.deleteJob(jobKey);
|
||||
|
||||
jobModel.setStatus(0);
|
||||
jobDao.update(jobModel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.zw.admin.server.dao.MailDao;
|
||||
import com.zw.admin.server.model.Mail;
|
||||
import com.zw.admin.server.service.MailService;
|
||||
import com.zw.admin.server.service.SendMailSevice;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j(topic = "adminLogger")
|
||||
@Service
|
||||
public class MailServiceImpl implements MailService {
|
||||
|
||||
@Autowired
|
||||
private SendMailSevice sendMailSevice;
|
||||
@Autowired
|
||||
private MailDao mailDao;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(Mail mail, List<String> toUser) {
|
||||
mail.setUserId(UserUtil.getCurrentUser().getId());
|
||||
mailDao.save(mail);
|
||||
|
||||
toUser.forEach(u -> {
|
||||
int status = 1;
|
||||
try {
|
||||
sendMailSevice.sendMail(u, mail.getSubject(), mail.getContent());
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件失败", e);
|
||||
status = 0;
|
||||
}
|
||||
|
||||
mailDao.saveToUser(mail.getId(), u, status);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.boot.security.server.dao.PermissionDao;
|
||||
import com.boot.security.server.model.Permission;
|
||||
import com.boot.security.server.service.PermissionService;
|
||||
import com.zw.admin.server.dao.PermissionDao;
|
||||
import com.zw.admin.server.model.Permission;
|
||||
import com.zw.admin.server.service.PermissionService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.boot.security.server.dao.RoleDao;
|
||||
import com.boot.security.server.dto.RoleDto;
|
||||
import com.boot.security.server.model.Role;
|
||||
import com.boot.security.server.service.RoleService;
|
||||
import com.zw.admin.server.dao.RoleDao;
|
||||
import com.zw.admin.server.dto.RoleDto;
|
||||
import com.zw.admin.server.model.Role;
|
||||
import com.zw.admin.server.service.RoleService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.zw.admin.server.service.SendMailSevice;
|
||||
|
||||
@Service
|
||||
public class SendMailSeviceImpl implements SendMailSevice {
|
||||
|
||||
@Autowired
|
||||
private JavaMailSender javaMailSender;
|
||||
|
||||
@Value("${spring.mail.username}")
|
||||
private String serverMail;
|
||||
|
||||
@Override
|
||||
public void sendMail(List<String> toUser, String subject, String text) {
|
||||
MimeMessage message = javaMailSender.createMimeMessage();
|
||||
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
helper.setFrom(serverMail);
|
||||
helper.setTo(toUser.toArray(new String[toUser.size()]));
|
||||
helper.setSubject(subject);
|
||||
helper.setText(text, true);
|
||||
|
||||
javaMailSender.send(message);
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMail(String toUser, String subject, String text) throws MessagingException {
|
||||
MimeMessage message = javaMailSender.createMimeMessage();
|
||||
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
helper.setFrom(serverMail);
|
||||
helper.setTo(toUser);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(text, true);
|
||||
|
||||
javaMailSender.send(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.zw.admin.server.dao.SysLogsDao;
|
||||
import com.zw.admin.server.model.SysLogs;
|
||||
import com.zw.admin.server.model.User;
|
||||
import com.zw.admin.server.service.SysLogService;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j(topic = "adminLogger")
|
||||
@Service
|
||||
public class SysLogServiceImpl implements SysLogService {
|
||||
|
||||
@Autowired
|
||||
private SysLogsDao sysLogsDao;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void save(SysLogs sysLogs) {
|
||||
User user = UserUtil.getCurrentUser();
|
||||
if (user == null || user.getId() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sysLogs.setUser(user);
|
||||
sysLogsDao.save(sysLogs);
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void save(Long userId, String module, Boolean flag, String remark) {
|
||||
SysLogs sysLogs = new SysLogs();
|
||||
sysLogs.setFlag(flag);
|
||||
sysLogs.setModule(module);
|
||||
sysLogs.setRemark(remark);
|
||||
|
||||
User user = new User();
|
||||
user.setId(userId);
|
||||
sysLogs.setUser(user);
|
||||
|
||||
sysLogsDao.save(sysLogs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteLogs() {
|
||||
Date date = DateUtils.addMonths(new Date(), -3);
|
||||
String time = DateFormatUtils.format(date, DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
|
||||
|
||||
int n = sysLogsDao.deleteLogs(time);
|
||||
log.info("删除{}之前日志{}条", time, n);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,22 @@
|
|||
package com.boot.security.server.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.shiro.crypto.hash.SimpleHash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.boot.security.server.dao.UserDao;
|
||||
import com.boot.security.server.dto.UserDto;
|
||||
import com.boot.security.server.model.SysUser;
|
||||
import com.boot.security.server.model.SysUser.Status;
|
||||
import com.boot.security.server.service.UserService;
|
||||
import com.zw.admin.server.constants.UserConstants;
|
||||
import com.zw.admin.server.dao.UserDao;
|
||||
import com.zw.admin.server.dto.UserDto;
|
||||
import com.zw.admin.server.model.User;
|
||||
import com.zw.admin.server.model.User.Status;
|
||||
import com.zw.admin.server.service.UserService;
|
||||
import com.zw.admin.server.utils.UserUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
|
@ -22,14 +26,14 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public SysUser saveUser(UserDto userDto) {
|
||||
SysUser user = userDto;
|
||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||
public User saveUser(UserDto userDto) {
|
||||
User user = userDto;
|
||||
user.setSalt(DigestUtils
|
||||
.md5Hex(UUID.randomUUID().toString() + System.currentTimeMillis() + UUID.randomUUID().toString()));
|
||||
user.setPassword(passwordEncoder(user.getPassword(), user.getSalt()));
|
||||
user.setStatus(Status.VALID);
|
||||
userDao.save(user);
|
||||
saveUserRoles(user.getId(), userDto.getRoleIds());
|
||||
|
|
@ -48,33 +52,47 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SysUser getUser(String username) {
|
||||
public String passwordEncoder(String credentials, String salt) {
|
||||
Object object = new SimpleHash("MD5", credentials, salt, UserConstants.HASH_ITERATIONS);
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(String username) {
|
||||
return userDao.getUser(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePassword(String username, String oldPassword, String newPassword) {
|
||||
SysUser u = userDao.getUser(username);
|
||||
User u = userDao.getUser(username);
|
||||
if (u == null) {
|
||||
throw new IllegalArgumentException("用户不存在");
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(newPassword, u.getPassword())) {
|
||||
if (!u.getPassword().equals(passwordEncoder(oldPassword, u.getSalt()))) {
|
||||
throw new IllegalArgumentException("密码错误");
|
||||
}
|
||||
|
||||
userDao.changePassword(u.getId(), passwordEncoder.encode(newPassword));
|
||||
userDao.changePassword(u.getId(), passwordEncoder(newPassword, u.getSalt()));
|
||||
|
||||
log.debug("修改{}的密码", username);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public SysUser updateUser(UserDto userDto) {
|
||||
public User updateUser(UserDto userDto) {
|
||||
userDao.update(userDto);
|
||||
saveUserRoles(userDto.getId(), userDto.getRoleIds());
|
||||
updateUserSession(userDto.getId());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
|
||||
private void updateUserSession(Long id) {
|
||||
User current = UserUtil.getCurrentUser();
|
||||
if (current.getId().equals(id)) {
|
||||
User user = userDao.getById(id);
|
||||
UserUtil.setUserSession(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,179 @@
|
|||
package com.boot.security.server.utils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* excel工具类
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
*/
|
||||
public class ExcelUtil {
|
||||
|
||||
public static void excelLocal(String path, String fileName, String[] headers, List<Object[]> datas) {
|
||||
Workbook workbook = getWorkbook(headers, datas);
|
||||
if (workbook != null) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = null;
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
workbook.write(byteArrayOutputStream);
|
||||
|
||||
String suffix = ".xls";
|
||||
File file = new File(path + File.separator + fileName + suffix);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
fileOutputStream = new FileOutputStream(file);
|
||||
fileOutputStream.write(byteArrayOutputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (fileOutputStream != null) {
|
||||
fileOutputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (byteArrayOutputStream != null) {
|
||||
byteArrayOutputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
workbook.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param fileName
|
||||
* @param headers
|
||||
* @param datas
|
||||
* @param response
|
||||
*/
|
||||
public static void excelExport(String fileName, String[] headers, List<Object[]> datas,
|
||||
HttpServletResponse response) {
|
||||
Workbook workbook = getWorkbook(headers, datas);
|
||||
if (workbook != null) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = null;
|
||||
try {
|
||||
byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
workbook.write(byteArrayOutputStream);
|
||||
|
||||
String suffix = ".xls";
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + new String((fileName + suffix).getBytes(), "iso-8859-1"));
|
||||
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
outputStream.write(byteArrayOutputStream.toByteArray());
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (byteArrayOutputStream != null) {
|
||||
byteArrayOutputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
workbook.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param headers
|
||||
* 列头
|
||||
* @param datas
|
||||
* 数据
|
||||
* @return
|
||||
*/
|
||||
public static Workbook getWorkbook(String[] headers, List<Object[]> datas) {
|
||||
Workbook workbook = new HSSFWorkbook();
|
||||
|
||||
Sheet sheet = workbook.createSheet();
|
||||
Row row = null;
|
||||
Cell cell = null;
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER_SELECTION);
|
||||
|
||||
Font font = workbook.createFont();
|
||||
|
||||
int line = 0, maxColumn = 0;
|
||||
if (headers != null && headers.length > 0) {// 设置列头
|
||||
row = sheet.createRow(line++);
|
||||
row.setHeightInPoints(23);
|
||||
font.setBold(true);
|
||||
font.setFontHeightInPoints((short) 13);
|
||||
style.setFont(font);
|
||||
|
||||
maxColumn = headers.length;
|
||||
for (int i = 0; i < maxColumn; i++) {
|
||||
cell = row.createCell(i);
|
||||
cell.setCellValue(headers[i]);
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
}
|
||||
|
||||
if (datas != null && datas.size() > 0) {// 渲染数据
|
||||
for (int index = 0, size = datas.size(); index < size; index++) {
|
||||
Object[] data = datas.get(index);
|
||||
if (data != null && data.length > 0) {
|
||||
row = sheet.createRow(line++);
|
||||
row.setHeightInPoints(20);
|
||||
|
||||
int length = data.length;
|
||||
if (length > maxColumn) {
|
||||
maxColumn = length;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
cell = row.createCell(i);
|
||||
cell.setCellValue(data[i] == null ? null : data[i].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxColumn; i++) {
|
||||
sheet.autoSizeColumn(i);
|
||||
}
|
||||
|
||||
return workbook;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
package com.boot.security.server.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 文件工具类
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
public static String saveFile(MultipartFile file, String pathname) {
|
||||
try {
|
||||
File targetFile = new File(pathname);
|
||||
if (targetFile.exists()) {
|
||||
return pathname;
|
||||
}
|
||||
|
||||
if (!targetFile.getParentFile().exists()) {
|
||||
targetFile.getParentFile().mkdirs();
|
||||
}
|
||||
file.transferTo(targetFile);
|
||||
|
||||
return pathname;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String pathname) {
|
||||
File file = new File(pathname);
|
||||
if (file.exists()) {
|
||||
boolean flag = file.delete();
|
||||
|
||||
if (flag) {
|
||||
File[] files = file.getParentFile().listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
file.getParentFile().delete();
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String fileMd5(InputStream inputStream) {
|
||||
try {
|
||||
return DigestUtils.md5Hex(inputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPath() {
|
||||
return "/" + LocalDate.now().toString().replace("-", "/") + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本写入文件
|
||||
*
|
||||
* @param value
|
||||
* @param path
|
||||
*/
|
||||
public static void saveTextFile(String value, String path) {
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
writer = new FileWriter(file);
|
||||
writer.write(value);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getText(String path) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return getText(new FileInputStream(file));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getText(InputStream inputStream) {
|
||||
InputStreamReader isr = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
isr = new InputStreamReader(inputStream, "utf-8");
|
||||
bufferedReader = new BufferedReader(isr);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String string;
|
||||
while ((string = bufferedReader.readLine()) != null) {
|
||||
string = string + "\n";
|
||||
builder.append(string);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bufferedReader != null) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (isr != null) {
|
||||
try {
|
||||
isr.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.boot.security.server.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* 字符串转化工具类
|
||||
*
|
||||
* @author 小威老师
|
||||
*
|
||||
*/
|
||||
public class StrUtil {
|
||||
|
||||
/**
|
||||
* 字符串转为驼峰
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String str2hump(String str) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (str != null && str.length() > 0) {
|
||||
if (str.contains("_")) {
|
||||
String[] chars = str.split("_");
|
||||
int size = chars.length;
|
||||
if (size > 0) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
for (String s : chars) {
|
||||
if (s != null && s.trim().length() > 0) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
size = list.size();
|
||||
if (size > 0) {
|
||||
buffer.append(list.get(0));
|
||||
for (int i = 1; i < size; i++) {
|
||||
String s = list.get(i);
|
||||
buffer.append(s.substring(0, 1).toUpperCase());
|
||||
if (s.length() > 1) {
|
||||
buffer.append(s.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buffer.append(str);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
package com.boot.security.server.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.boot.security.server.dto.GenerateInput;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j(topic = "adminLogger")
|
||||
public class TemplateUtil {
|
||||
|
||||
public static String getTemplete(String fileName) {
|
||||
return FileUtil.getText(TemplateUtil.class.getClassLoader().getResourceAsStream("generate/" + fileName));
|
||||
}
|
||||
|
||||
public static void saveJava(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String beanPackageName = input.getBeanPackageName();
|
||||
String beanName = input.getBeanName();
|
||||
List<String> beanFieldName = input.getBeanFieldName();
|
||||
List<String> beanFieldType = input.getBeanFieldType();
|
||||
List<String> beanFieldValue = input.getBeanFieldValue();
|
||||
|
||||
String text = getTemplete("java.txt");
|
||||
text = text.replace("{beanPackageName}", beanPackageName).replace("{beanName}", beanName);
|
||||
|
||||
String imports = "";
|
||||
if (beanFieldType.contains(BigDecimal.class.getSimpleName())) {
|
||||
imports += "import " + BigDecimal.class.getName() + ";\n";
|
||||
}
|
||||
if (beanFieldType.contains(Date.class.getSimpleName())) {
|
||||
imports += "import " + Date.class.getName() + ";";
|
||||
}
|
||||
|
||||
text = text.replace("{import}", imports);
|
||||
String filelds = getFields(beanFieldName, beanFieldType, beanFieldValue);
|
||||
text = text.replace("{filelds}", filelds);
|
||||
|
||||
FileUtil.saveTextFile(text, path + File.separator + getPackagePath(beanPackageName) + beanName + ".java");
|
||||
log.debug("生成java model:{}模板", beanName);
|
||||
}
|
||||
|
||||
private static String getFields(List<String> beanFieldName, List<String> beanFieldType,
|
||||
List<String> beanFieldValue) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = beanFieldName.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String name = beanFieldName.get(i);
|
||||
if ("id".equals(name) || "createTime".equals(name) || "updateTime".equals(name)) {
|
||||
continue;
|
||||
}
|
||||
String type = beanFieldType.get(i);
|
||||
buffer.append("\tprivate ").append(type).append(" ").append(name);
|
||||
// 默认值
|
||||
// String value = beanFieldValue.get(i);
|
||||
// if (!StringUtils.isEmpty(value)) {
|
||||
// buffer.append(" = ");
|
||||
// if (type.equals(String.class.getSimpleName())) {
|
||||
// value = "\"" + value + "\"";
|
||||
// } else if (type.equals(Double.class.getSimpleName())) {
|
||||
// value = value + "D";
|
||||
// } else if (type.equals(Float.class.getSimpleName())) {
|
||||
// value = value + "F";
|
||||
// } else if (type.equals(BigDecimal.class.getSimpleName())) {
|
||||
// value = "new BigDecimal(" + value + ")";
|
||||
// }
|
||||
//
|
||||
// buffer.append(value);
|
||||
// }
|
||||
buffer.append(";\n");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static void saveJavaDao(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String tableName = input.getTableName();
|
||||
String beanPackageName = input.getBeanPackageName();
|
||||
String beanName = input.getBeanName();
|
||||
String daoPackageName = input.getDaoPackageName();
|
||||
String daoName = input.getDaoName();
|
||||
|
||||
String text = getTemplete("dao.txt");
|
||||
text = text.replace("{daoPackageName}", daoPackageName);
|
||||
text = text.replace("{beanPackageName}", beanPackageName);
|
||||
text = text.replace("{daoName}", daoName);
|
||||
text = text.replace("{table_name}", tableName);
|
||||
text = text.replace("{beanName}", beanName);
|
||||
text = text.replace("{beanParamName}", lowerFirstChar(beanName));
|
||||
|
||||
String insertColumns = getInsertColumns(input.getColumnNames());
|
||||
text = text.replace("{insert_columns}", insertColumns);
|
||||
String insertValues = getInsertValues(input.getColumnNames(), input.getBeanFieldName());
|
||||
text = text.replace("{insert_values}", insertValues);
|
||||
FileUtil.saveTextFile(text, path + File.separator + getPackagePath(daoPackageName) + daoName + ".java");
|
||||
log.debug("生成java dao:{}模板", beanName);
|
||||
|
||||
text = getTemplete("mapper.xml");
|
||||
text = text.replace("{daoPackageName}", daoPackageName);
|
||||
text = text.replace("{daoName}", daoName);
|
||||
text = text.replace("{table_name}", tableName);
|
||||
text = text.replace("{beanName}", beanName);
|
||||
String sets = getUpdateSets(input.getColumnNames(), input.getBeanFieldName());
|
||||
text = text.replace("{update_sets}", sets);
|
||||
String where = getWhere(input.getColumnNames(), input.getBeanFieldName());
|
||||
text = text.replace("{where}", where);
|
||||
FileUtil.saveTextFile(text, path + File.separator + beanName + "Mapper.xml");
|
||||
}
|
||||
|
||||
private static String getInsertValues(List<String> columnNames, List<String> beanFieldName) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
if (!"id".equals(column)) {
|
||||
buffer.append("#{").append(beanFieldName.get(i)).append("}, ");
|
||||
}
|
||||
}
|
||||
|
||||
String sets = StringUtils.substringBeforeLast(buffer.toString(), ",");
|
||||
return sets;
|
||||
}
|
||||
|
||||
private static String getInsertColumns(List<String> columnNames) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
if (!"id".equals(column)) {
|
||||
buffer.append(column).append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
String insertColumns = StringUtils.substringBeforeLast(buffer.toString(), ",");
|
||||
return insertColumns;
|
||||
}
|
||||
|
||||
private static String getUpdateSets(List<String> columnNames, List<String> beanFieldName) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
if (!"id".equals(column)) {
|
||||
buffer.append("\t\t\t<if test=\"" + column + " != null\">\n");
|
||||
buffer.append("\t\t\t\t" + column).append(" = ").append("#{").append(beanFieldName.get(i))
|
||||
.append("}, \n");
|
||||
buffer.append("\t\t\t</if>\n");
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static String getWhere(List<String> columnNames, List<String> beanFieldName) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
String column = columnNames.get(i);
|
||||
buffer.append("\t\t\t<if test=\"params." + column + " != null and params." + column + " != ''\">\n");
|
||||
buffer.append("\t\t\t\tand " + column).append(" = ").append("#{params.").append(beanFieldName.get(i))
|
||||
.append("} \n");
|
||||
buffer.append("\t\t\t</if>\n");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 变量名
|
||||
*
|
||||
* @param beanName
|
||||
* @return
|
||||
*/
|
||||
public static String lowerFirstChar(String beanName) {
|
||||
String name = StrUtil.str2hump(beanName);
|
||||
String firstChar = name.substring(0, 1);
|
||||
name = name.replaceFirst(firstChar, firstChar.toLowerCase());
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String getPackagePath(String packageName) {
|
||||
String packagePath = packageName.replace(".", "/");
|
||||
if (!packagePath.endsWith("/")) {
|
||||
packagePath = packagePath + "/";
|
||||
}
|
||||
|
||||
return packagePath;
|
||||
}
|
||||
|
||||
public static void saveController(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String beanPackageName = input.getBeanPackageName();
|
||||
String beanName = input.getBeanName();
|
||||
String daoPackageName = input.getDaoPackageName();
|
||||
String daoName = input.getDaoName();
|
||||
|
||||
String text = getTemplete("controller.txt");
|
||||
text = text.replace("{daoPackageName}", daoPackageName);
|
||||
text = text.replace("{beanPackageName}", beanPackageName);
|
||||
text = text.replace("{daoName}", daoName);
|
||||
text = text.replace("{daoParamName}", lowerFirstChar(daoName));
|
||||
text = text.replace("{beanName}", beanName);
|
||||
text = text.replace("{beanParamName}", lowerFirstChar(beanName));
|
||||
text = text.replace("{controllerPkgName}", input.getControllerPkgName());
|
||||
text = text.replace("{controllerName}", input.getControllerName());
|
||||
|
||||
FileUtil.saveTextFile(text, path + File.separator + getPackagePath(input.getControllerPkgName())
|
||||
+ input.getControllerName() + ".java");
|
||||
log.debug("生成controller:{}模板", beanName);
|
||||
}
|
||||
|
||||
public static void saveHtmlList(GenerateInput input) {
|
||||
String path = input.getPath();
|
||||
String beanName = input.getBeanName();
|
||||
String beanParamName = lowerFirstChar(beanName);
|
||||
|
||||
String text = getTemplete("htmlList.txt");
|
||||
text = text.replace("{beanParamName}", beanParamName);
|
||||
text = text.replace("{beanName}", beanName);
|
||||
List<String> beanFieldNames = input.getBeanFieldName();
|
||||
text = text.replace("{columnsDatas}", getHtmlColumnsDatas(beanFieldNames));
|
||||
text = text.replace("{columnDefs}", getHtmlColumnDefs(beanFieldNames));
|
||||
text = text.replace("{ths}", getHtmlThs(beanFieldNames));
|
||||
text = text.replace("{lastIndex}", beanFieldNames.size() + "");
|
||||
|
||||
FileUtil.saveTextFile(text, path + File.separator + beanParamName + "List.html");
|
||||
log.debug("生成查询页面:{}模板", beanName);
|
||||
|
||||
text = getTemplete("htmlAdd.txt");
|
||||
text = text.replace("{beanParamName}", beanParamName);
|
||||
text = text.replace("{addDivs}", getAddDivs(beanFieldNames));
|
||||
FileUtil.saveTextFile(text, path + File.separator + "add" + beanName + ".html");
|
||||
log.debug("生成添加页面:{}模板", beanName);
|
||||
|
||||
text = getTemplete("htmlUpdate.txt");
|
||||
text = text.replace("{beanParamName}", beanParamName);
|
||||
text = text.replace("{addDivs}", getAddDivs(beanFieldNames));
|
||||
text = text.replace("{initData}", getInitData(beanFieldNames));
|
||||
FileUtil.saveTextFile(text, path + File.separator + "update" + beanName + ".html");
|
||||
log.debug("生成修改页面:{}模板", beanName);
|
||||
}
|
||||
|
||||
private static CharSequence getInitData(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
builder.append("\t\t\t\t\t\t$('#" + b + "').val(data." + b + ");\n");
|
||||
});
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getAddDivs(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
if (!"id".equals(b)) {
|
||||
builder.append("\t\t\t<div class='form-group'>\n");
|
||||
builder.append("\t\t\t\t<label class='col-md-2 control-label'>" + b + "</label>\n");
|
||||
builder.append("\t\t\t\t<div class='col-md-10'>\n");
|
||||
builder.append("\t\t\t\t\t<input class='form-control' placeholder='" + b + "' type='text' name='" + b
|
||||
+ "' id='" + b + "' data-bv-notempty='true' data-bv-notempty-message='" + b + " 不能为空'>\n");
|
||||
builder.append("\t\t\t\t</div>\n");
|
||||
builder.append("\t\t\t</div>\n");
|
||||
}
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getHtmlThs(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
builder.append("\t\t\t\t\t\t\t\t\t<th>{beanFieldName}</th>\n".replace("{beanFieldName}", b));
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getHtmlColumnsDatas(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
beanFieldNames.forEach(b -> {
|
||||
builder.append("\t\t\t\t{\"data\" : \"{beanFieldName}\", \"defaultContent\" : \"\"},\n"
|
||||
.replace("{beanFieldName}", b));
|
||||
});
|
||||
|
||||
builder.append("");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getHtmlColumnDefs(List<String> beanFieldNames) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < beanFieldNames.size(); i++) {
|
||||
builder.append("\t\t\t\t{\"name\" : \"" + beanFieldNames.get(i) + "\", \"targets\" : \"" + i + "\"},\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.boot.security.server.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import com.boot.security.server.dto.LoginUser;
|
||||
import com.boot.security.server.model.SysUser;
|
||||
import com.zw.admin.server.constants.UserConstants;
|
||||
import com.zw.admin.server.model.Permission;
|
||||
import com.zw.admin.server.model.User;
|
||||
|
||||
public class UserUtil {
|
||||
|
||||
public static SysUser getCurrentUser() {
|
||||
LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
public static void setUserSession(User user) {
|
||||
getSession().setAttribute(UserConstants.LOGIN_USER, user);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Permission> getCurrentPermissions() {
|
||||
List<Permission> list = (List<Permission>) getSession().getAttribute(UserConstants.USER_PERMISSIONS);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void setPermissionSession(List<Permission> list) {
|
||||
getSession().setAttribute(UserConstants.USER_PERMISSIONS, list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<configuration>
|
||||
<springProperty name="logFile" source="log.file" />
|
||||
<springProperty name="rootlevel" source="log.level.root" />
|
||||
<springProperty name="mylevel" source="log.level.my" />
|
||||
<springProperty name="maxFileSize" source="log.maxsize" />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d [%thread] %-5level %logger{50} -[%file:%line]- %msg%n
|
||||
</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="adminLog"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${logFile}</file>
|
||||
<encoder>
|
||||
<pattern>%d [%thread] %-5level -[%file:%line]- %msg%n
|
||||
</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${logFile}.%d{yyyy-MM-dd}.%i</fileNamePattern>
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<appender name="errorLog"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${logFile}.error</file>
|
||||
<encoder>
|
||||
<pattern>%d [%thread] %-5level %logger{36} -[%file:%line]- %msg%n
|
||||
</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${logFile}.error.%d{yyyy-MM-dd}.%i</fileNamePattern>
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>error</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="sqlLog"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${logFile}.sql</file>
|
||||
<encoder>
|
||||
<pattern>%d [%thread] %msg%n
|
||||
</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${logFile}.sql.%d{yyyy-MM-dd}.%i</fileNamePattern>
|
||||
<maxFileSize>${maxFileSize}</maxFileSize>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<logger name="adminLogger" level="${mylevel}" additivity="true">
|
||||
<appender-ref ref="adminLog" />
|
||||
</logger>
|
||||
|
||||
<logger name="com.zw.admin.server.dao" level="DEBUG" additivity="true">
|
||||
<appender-ref ref="sqlLog" />
|
||||
</logger>
|
||||
|
||||
<root level="${rootlevel}">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="errorLog" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
|
||||
org.quartz.scheduler.instanceId = AUTO
|
||||
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
|
||||
org.quartz.threadPool.threadCount = 10
|
||||
org.quartz.threadPool.threadPriority = 5
|
||||
|
||||
org.quartz.jobStore.misfireThreshold = 60000
|
||||
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
|
||||
org.quartz.jobStore.tablePrefix = QRTZ_
|
||||
|
||||
org.quartz.jobStore.isClustered = true
|
||||
org.quartz.jobStore.clusterCheckinInterval = 15000
|
||||
Loading…
Reference in New Issue