1.修改quartz问题。2完善数据范围添加策略支持。3修改swaggerbug。4取消验证码

This commit is contained in:
yandanyang 2020-11-28 23:02:08 +08:00
parent 70173ebd22
commit 01fe8a7c16
17 changed files with 263 additions and 115 deletions

View File

@ -2,6 +2,7 @@ package net.lab1024.smartadmin.common.anno;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeTypeEnum; import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeWhereInTypeEnum; import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeWhereInTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.strategy.DataScopePowerStrategy;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -27,11 +28,22 @@ public @interface DataScope {
DataScopeWhereInTypeEnum whereInType() default DataScopeWhereInTypeEnum.EMPLOYEE; DataScopeWhereInTypeEnum whereInType() default DataScopeWhereInTypeEnum.EMPLOYEE;
/** /**
* DataScopeWhereInTypeEnum.CUSTOM_STRATEGY类型 才可使用joinSqlImplClazz属性
* @return
*/
Class<? extends DataScopePowerStrategy> joinSqlImplClazz() default DataScopePowerStrategy.class;
/**
*
* 第几个where 条件 从0开始 * 第几个where 条件 从0开始
* @return * @return
*/ */
int whereIndex() default 0; int whereIndex() default 0;
/**
* DataScopeWhereInTypeEnum为CUSTOM_STRATEGY类型时此属性无效
* @return
*/
String joinSql() default ""; String joinSql() default "";
} }

View File

@ -19,6 +19,7 @@ import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.RequestHandler; import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
@ -194,7 +195,11 @@ public class SmartSwaggerDynamicGroupConfig implements EnvironmentAware, BeanDef
return false; return false;
}; };
groupIndex++; groupIndex++;
return Predicates.and(RequestHandlerSelectors.withClassAnnotation(RestController.class), methodPredicate); return Predicates.or(
Predicates.and(RequestHandlerSelectors.withClassAnnotation(RestController.class),methodPredicate),
Predicates.and(
RequestHandlerSelectors.withMethodAnnotation(ResponseBody.class),methodPredicate)
);
} }
private ApiInfo serviceApiInfo() { private ApiInfo serviceApiInfo() {

View File

@ -1,14 +1,14 @@
package net.lab1024.smartadmin.module.support.quartz.service; package net.lab1024.smartadmin.module.support.quartz.service;
import lombok.extern.slf4j.Slf4j;
import net.lab1024.smartadmin.common.domain.ITask;
import net.lab1024.smartadmin.module.support.quartz.constant.QuartzConst; import net.lab1024.smartadmin.module.support.quartz.constant.QuartzConst;
import net.lab1024.smartadmin.module.support.quartz.constant.TaskResultEnum; import net.lab1024.smartadmin.module.support.quartz.constant.TaskResultEnum;
import net.lab1024.smartadmin.module.support.quartz.domain.entity.QuartzTaskEntity; import net.lab1024.smartadmin.module.support.quartz.domain.entity.QuartzTaskEntity;
import net.lab1024.smartadmin.module.support.quartz.domain.entity.QuartzTaskLogEntity; import net.lab1024.smartadmin.module.support.quartz.domain.entity.QuartzTaskLogEntity;
import net.lab1024.smartadmin.common.domain.ITask;
import net.lab1024.smartadmin.third.SmartApplicationContext; import net.lab1024.smartadmin.third.SmartApplicationContext;
import net.lab1024.smartadmin.util.SmartIPUtil; import net.lab1024.smartadmin.util.SmartIPUtil;
import net.lab1024.smartadmin.util.SmartQuartzUtil; import net.lab1024.smartadmin.util.SmartQuartzUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDetail; import org.quartz.JobDetail;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
@ -17,7 +17,6 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
/** /**

View File

@ -130,7 +130,12 @@ public class QuartzTaskService {
taskEntity.setTaskStatus(updateEntity.getTaskStatus()); taskEntity.setTaskStatus(updateEntity.getTaskStatus());
taskEntity.setUpdateTime(new Date()); taskEntity.setUpdateTime(new Date());
quartzTaskDao.updateById(taskEntity); quartzTaskDao.updateById(taskEntity);
this.updateQuartzTask(scheduler, taskEntity); if(this.checkExist(taskEntity.getId())){
this.updateQuartzTask(scheduler, taskEntity);
}else{
this.createQuartzTask(scheduler,taskEntity);
}
return ResponseDTO.succ(); return ResponseDTO.succ();
} }
@ -165,7 +170,7 @@ public class QuartzTaskService {
} }
quartzTaskEntity.setTaskStatus(TaskStatusEnum.PAUSE.getStatus()); quartzTaskEntity.setTaskStatus(TaskStatusEnum.PAUSE.getStatus());
quartzTaskDao.updateById(quartzTaskEntity); quartzTaskDao.updateById(quartzTaskEntity);
this.pauseQuartzTask(scheduler, taskId); this.pauseQuartzTask(scheduler, quartzTaskEntity);
return ResponseDTO.succ(); return ResponseDTO.succ();
} }
@ -184,7 +189,7 @@ public class QuartzTaskService {
} }
quartzTaskEntity.setTaskStatus(TaskStatusEnum.NORMAL.getStatus()); quartzTaskEntity.setTaskStatus(TaskStatusEnum.NORMAL.getStatus());
quartzTaskDao.updateById(quartzTaskEntity); quartzTaskDao.updateById(quartzTaskEntity);
this.resumeQuartzTask(scheduler, taskId); this.resumeQuartzTask(scheduler, quartzTaskEntity);
return ResponseDTO.succ(); return ResponseDTO.succ();
} }
@ -233,6 +238,10 @@ public class QuartzTaskService {
jobDetail.getJobDataMap().put(QuartzConst.QUARTZ_PARAMS_KEY, taskEntity.getTaskParams()); jobDetail.getJobDataMap().put(QuartzConst.QUARTZ_PARAMS_KEY, taskEntity.getTaskParams());
scheduler.scheduleJob(jobDetail, trigger); scheduler.scheduleJob(jobDetail, trigger);
//如果任务是暂停状态则暂停任务
if (TaskStatusEnum.PAUSE.getStatus().equals(taskEntity.getTaskStatus())) {
this.pauseQuartzTask(scheduler, taskEntity);
}
} }
/** /**
@ -256,7 +265,7 @@ public class QuartzTaskService {
scheduler.rescheduleJob(triggerKey, trigger); scheduler.rescheduleJob(triggerKey, trigger);
//如果更新之前任务是暂停状态此时再次暂停任务 //如果更新之前任务是暂停状态此时再次暂停任务
if (TaskStatusEnum.PAUSE.getStatus().equals(taskEntity.getTaskStatus())) { if (TaskStatusEnum.PAUSE.getStatus().equals(taskEntity.getTaskStatus())) {
this.pauseQuartzTask(scheduler, Long.valueOf(taskEntity.getId())); this.pauseQuartzTask(scheduler, taskEntity);
} }
} }
@ -276,6 +285,11 @@ public class QuartzTaskService {
JobDataMap dataMap = new JobDataMap(); JobDataMap dataMap = new JobDataMap();
dataMap.put(QuartzConst.QUARTZ_PARAMS_KEY, taskEntity.getTaskParams()); dataMap.put(QuartzConst.QUARTZ_PARAMS_KEY, taskEntity.getTaskParams());
JobKey jobKey = SmartQuartzUtil.getJobKey(taskEntity.getId()); JobKey jobKey = SmartQuartzUtil.getJobKey(taskEntity.getId());
if(!scheduler.checkExists(jobKey)){
this.createQuartzTask(scheduler,taskEntity);
scheduler.triggerJob(jobKey, dataMap);
return;
}
scheduler.triggerJob(jobKey, dataMap); scheduler.triggerJob(jobKey, dataMap);
} }
@ -283,11 +297,16 @@ public class QuartzTaskService {
* 暂停任务 * 暂停任务
* *
* @param scheduler * @param scheduler
* @param taskId * @param quartzTaskEntity
* @throws Exception * @throws Exception
*/ */
private void pauseQuartzTask(Scheduler scheduler, Long taskId) throws Exception { private void pauseQuartzTask(Scheduler scheduler, QuartzTaskEntity quartzTaskEntity) throws Exception {
JobKey jobKey = SmartQuartzUtil.getJobKey(taskId); JobKey jobKey = SmartQuartzUtil.getJobKey(quartzTaskEntity.getId());
if(!scheduler.checkExists(jobKey)){
this.createQuartzTask(scheduler,quartzTaskEntity);
scheduler.pauseJob(jobKey);
return;
}
scheduler.pauseJob(jobKey); scheduler.pauseJob(jobKey);
} }
@ -295,11 +314,15 @@ public class QuartzTaskService {
* 恢复任务 * 恢复任务
* *
* @param scheduler * @param scheduler
* @param taskId * @param quartzTaskEntity
* @throws Exception * @throws Exception
*/ */
private void resumeQuartzTask(Scheduler scheduler, Long taskId) throws Exception { private void resumeQuartzTask(Scheduler scheduler, QuartzTaskEntity quartzTaskEntity) throws Exception {
JobKey jobKey = SmartQuartzUtil.getJobKey(taskId); JobKey jobKey = SmartQuartzUtil.getJobKey(quartzTaskEntity.getId());
if(!scheduler.checkExists(jobKey)){
this.createQuartzTask(scheduler,quartzTaskEntity);
return;
}
scheduler.resumeJob(jobKey); scheduler.resumeJob(jobKey);
} }
@ -312,6 +335,15 @@ public class QuartzTaskService {
*/ */
private void deleteQuartzTask(Scheduler scheduler, Long taskId) throws Exception { private void deleteQuartzTask(Scheduler scheduler, Long taskId) throws Exception {
JobKey jobKey = SmartQuartzUtil.getJobKey(taskId); JobKey jobKey = SmartQuartzUtil.getJobKey(taskId);
if(!scheduler.checkExists(jobKey)){
return;
}
scheduler.deleteJob(jobKey); scheduler.deleteJob(jobKey);
} }
private Boolean checkExist(Long taskId) throws Exception{
JobKey jobKey = SmartQuartzUtil.getJobKey(taskId);
return scheduler.checkExists(jobKey);
}
} }

View File

@ -1,5 +1,6 @@
package net.lab1024.smartadmin.module.support.quartz.task.test; package net.lab1024.smartadmin.module.support.quartz.task.test;
import lombok.extern.slf4j.Slf4j;
import net.lab1024.smartadmin.common.domain.ITask; import net.lab1024.smartadmin.common.domain.ITask;
import net.lab1024.smartadmin.util.SmartDateUtil; import net.lab1024.smartadmin.util.SmartDateUtil;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -16,11 +17,12 @@ import java.util.Date;
* @date 2019/4/13 0013 下午 14:26 * @date 2019/4/13 0013 下午 14:26
* @since JDK1.8 * @since JDK1.8
*/ */
@Slf4j
@Component("exampleTask") @Component("exampleTask")
public class Example implements ITask { public class Example implements ITask {
@Override @Override
public void execute(String paramJson) throws Exception { public void execute(String paramJson) throws Exception {
System.out.println(SmartDateUtil.formatYMDHMS(new Date()) + ",今天搬了" + System.currentTimeMillis() + "块砖,paramJson:" + paramJson); log.warn("{}-今天搬了{}块砖,paramJson:{}",SmartDateUtil.formatYMDHMS(new Date()),System.currentTimeMillis(),paramJson );
} }
} }

View File

@ -1,6 +1,8 @@
package net.lab1024.smartadmin.module.system.datascope.constant; package net.lab1024.smartadmin.module.system.datascope.constant;
import net.lab1024.smartadmin.common.domain.BaseEnum;
/** /**
* [ ] * [ ]
* *
@ -11,30 +13,32 @@ package net.lab1024.smartadmin.module.system.datascope.constant;
* @date 2019/4/28 0028 下午 15:37 * @date 2019/4/28 0028 下午 15:37
* @since JDK1.8 * @since JDK1.8
*/ */
public enum DataScopeTypeEnum { public enum DataScopeTypeEnum implements BaseEnum {
DEFAULT(0,0,"默认类型","数据范围样例"); DEFAULT(0,0,"默认类型","数据范围样例");
private Integer type; private Integer value;
private Integer sort; private Integer sort;
private String name; private String name;
private String desc; private String desc;
DataScopeTypeEnum(Integer type,Integer sort,String name,String desc) { DataScopeTypeEnum(Integer value,Integer sort,String name,String desc) {
this.type = type; this.value = value;
this.sort = sort; this.sort = sort;
this.name = name; this.name = name;
this.desc = desc; this.desc = desc;
} }
public Integer getType() { @Override
return type; public Integer getValue() {
return value;
} }
public Integer getSort() { public Integer getSort() {
return sort; return sort;
} }
@Override
public String getDesc() { public String getDesc() {
return desc; return desc;
} }

View File

@ -1,6 +1,8 @@
package net.lab1024.smartadmin.module.system.datascope.constant; package net.lab1024.smartadmin.module.system.datascope.constant;
import net.lab1024.smartadmin.common.domain.BaseEnum;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
@ -14,7 +16,7 @@ import java.util.Optional;
* @date 2019/4/28 0028 下午 15:37 * @date 2019/4/28 0028 下午 15:37
* @since JDK1.8 * @since JDK1.8
*/ */
public enum DataScopeViewTypeEnum { public enum DataScopeViewTypeEnum implements BaseEnum {
ME(0,0,"本人"), ME(0,0,"本人"),
@ -24,32 +26,29 @@ public enum DataScopeViewTypeEnum {
ALL(3,15,"全部"); ALL(3,15,"全部");
private Integer type; private Integer value;
private Integer level; private Integer level;
private String name; private String desc;
DataScopeViewTypeEnum(Integer type,Integer level, String name) { DataScopeViewTypeEnum(Integer value,Integer level, String desc) {
this.type = type; this.value = value;
this.level = level; this.level = level;
this.name = name; this.desc = desc;
} }
public Integer getType() { @Override
return type; public Integer getValue() {
return value;
} }
public Integer getLevel() { public Integer getLevel() {
return level; return level;
} }
public String getName() { @Override
return name; public String getDesc() {
return desc;
} }
public static DataScopeViewTypeEnum valueOf(Integer type) {
DataScopeViewTypeEnum[] values = DataScopeViewTypeEnum.values();
Optional<DataScopeViewTypeEnum> first = Arrays.stream(values).filter(e -> e.getType().equals(type)).findFirst();
return !first.isPresent() ? null : first.get();
}
} }

View File

@ -1,5 +1,7 @@
package net.lab1024.smartadmin.module.system.datascope.constant; package net.lab1024.smartadmin.module.system.datascope.constant;
import net.lab1024.smartadmin.common.domain.BaseEnum;
/** /**
* [ ] * [ ]
* *
@ -10,25 +12,28 @@ package net.lab1024.smartadmin.module.system.datascope.constant;
* @date 2019/5/8 0008 下午 16:00 * @date 2019/5/8 0008 下午 16:00
* @since JDK1.8 * @since JDK1.8
*/ */
public enum DataScopeWhereInTypeEnum { public enum DataScopeWhereInTypeEnum implements BaseEnum {
EMPLOYEE(0,"以员工IN"), EMPLOYEE(0,"以员工IN"),
DEPARTMENT(1,"以部门IN"); DEPARTMENT(1,"以部门IN"),
private Integer type; CUSTOM_STRATEGY(2,"自定义策略");
private Integer value;
private String desc; private String desc;
DataScopeWhereInTypeEnum(Integer type, String desc) { DataScopeWhereInTypeEnum(Integer value, String desc) {
this.type = type; this.value = value;
this.desc = desc; this.desc = desc;
} }
public Integer getType() { @Override
return type; public Integer getValue() {
return value;
} }
@Override
public String getDesc() { public String getDesc() {
return desc; return desc;
} }

View File

@ -1,6 +1,8 @@
package net.lab1024.smartadmin.module.system.datascope.domain.dto; package net.lab1024.smartadmin.module.system.datascope.domain.dto;
import lombok.Data; import lombok.Data;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeWhereInTypeEnum;
/** /**
* [ ] * [ ]
@ -15,11 +17,24 @@ import lombok.Data;
@Data @Data
public class DataScopeSqlConfigDTO { public class DataScopeSqlConfigDTO {
private Integer dataScopeType; /**
* 数据范围类型
* {@link DataScopeTypeEnum}
*/
private DataScopeTypeEnum dataScopeType;
/**
* join sql 具体实现类
*/
private Class joinSqlImplClazz;
private String joinSql; private String joinSql;
private Integer whereIndex; private Integer whereIndex;
private Integer dataScopeWhereInType; /**
* whereIn类型
* {@link DataScopeWhereInTypeEnum}
*/
private DataScopeWhereInTypeEnum dataScopeWhereInType;
} }

View File

@ -58,7 +58,7 @@ public class DataScopeService {
DataScopeViewTypeEnum[] enums = DataScopeViewTypeEnum.class.getEnumConstants(); DataScopeViewTypeEnum[] enums = DataScopeViewTypeEnum.class.getEnumConstants();
DataScopeViewTypeVO dataScopeViewTypeDTO; DataScopeViewTypeVO dataScopeViewTypeDTO;
for (DataScopeViewTypeEnum viewTypeEnum : enums) { for (DataScopeViewTypeEnum viewTypeEnum : enums) {
dataScopeViewTypeDTO = DataScopeViewTypeVO.builder().viewType(viewTypeEnum.getType()).viewTypeLevel(viewTypeEnum.getLevel()).viewTypeName(viewTypeEnum.getName()).build(); dataScopeViewTypeDTO = DataScopeViewTypeVO.builder().viewType(viewTypeEnum.getValue()).viewTypeLevel(viewTypeEnum.getLevel()).viewTypeName(viewTypeEnum.getDesc()).build();
viewTypeList.add(dataScopeViewTypeDTO); viewTypeList.add(dataScopeViewTypeDTO);
} }
Comparator<DataScopeViewTypeVO> comparator = (h1, h2) -> h1.getViewTypeLevel().compareTo(h2.getViewTypeLevel()); Comparator<DataScopeViewTypeVO> comparator = (h1, h2) -> h1.getViewTypeLevel().compareTo(h2.getViewTypeLevel());
@ -72,7 +72,7 @@ public class DataScopeService {
DataScopeDTO dataScopeDTO; DataScopeDTO dataScopeDTO;
for (DataScopeTypeEnum typeEnum : enums) { for (DataScopeTypeEnum typeEnum : enums) {
dataScopeDTO = dataScopeDTO =
DataScopeDTO.builder().dataScopeType(typeEnum.getType()).dataScopeTypeDesc(typeEnum.getDesc()).dataScopeTypeName(typeEnum.getName()).dataScopeTypeSort(typeEnum.getSort()).build(); DataScopeDTO.builder().dataScopeType(typeEnum.getValue()).dataScopeTypeDesc(typeEnum.getDesc()).dataScopeTypeName(typeEnum.getName()).dataScopeTypeSort(typeEnum.getSort()).build();
dataScopeTypeList.add(dataScopeDTO); dataScopeTypeList.add(dataScopeDTO);
} }
Comparator<DataScopeDTO> comparator = (h1, h2) -> h1.getDataScopeTypeSort().compareTo(h2.getDataScopeTypeSort()); Comparator<DataScopeDTO> comparator = (h1, h2) -> h1.getDataScopeTypeSort().compareTo(h2.getDataScopeTypeSort());

View File

@ -1,9 +1,14 @@
package net.lab1024.smartadmin.module.system.datascope.service; package net.lab1024.smartadmin.module.system.datascope.service;
import lombok.extern.slf4j.Slf4j;
import net.lab1024.smartadmin.common.anno.DataScope; import net.lab1024.smartadmin.common.anno.DataScope;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeViewTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeWhereInTypeEnum; import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeWhereInTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.domain.dto.DataScopeSqlConfigDTO; import net.lab1024.smartadmin.module.system.datascope.domain.dto.DataScopeSqlConfigDTO;
import net.lab1024.smartadmin.module.system.datascope.strategy.DataScopePowerStrategy;
import net.lab1024.smartadmin.module.system.login.domain.RequestTokenBO; import net.lab1024.smartadmin.module.system.login.domain.RequestTokenBO;
import net.lab1024.smartadmin.third.SmartApplicationContext;
import net.lab1024.smartadmin.util.SmartRequestTokenUtil; import net.lab1024.smartadmin.util.SmartRequestTokenUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -32,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @date 2019/4/29 0029 上午 10:12 * @date 2019/4/29 0029 上午 10:12
* @since JDK1.8 * @since JDK1.8
*/ */
@Slf4j
@Service @Service
public class DataScopeSqlConfigService { public class DataScopeSqlConfigService {
@ -67,10 +73,10 @@ public class DataScopeSqlConfigService {
DataScope dataScopeAnnotation = method.getAnnotation(DataScope.class); DataScope dataScopeAnnotation = method.getAnnotation(DataScope.class);
if (dataScopeAnnotation != null) { if (dataScopeAnnotation != null) {
DataScopeSqlConfigDTO configDTO = new DataScopeSqlConfigDTO(); DataScopeSqlConfigDTO configDTO = new DataScopeSqlConfigDTO();
configDTO.setDataScopeType(dataScopeAnnotation.dataScopeType().getType()); configDTO.setDataScopeType(dataScopeAnnotation.dataScopeType());
configDTO.setJoinSql(dataScopeAnnotation.joinSql()); configDTO.setJoinSql(dataScopeAnnotation.joinSql());
configDTO.setWhereIndex(dataScopeAnnotation.whereIndex()); configDTO.setWhereIndex(dataScopeAnnotation.whereIndex());
configDTO.setDataScopeWhereInType(dataScopeAnnotation.whereInType().getType()); configDTO.setDataScopeWhereInType(dataScopeAnnotation.whereInType());
dataScopeMethodMap.put(method.getDeclaringClass().getSimpleName() + "." + method.getName(), configDTO); dataScopeMethodMap.put(method.getDeclaringClass().getSimpleName() + "." + method.getName(), configDTO);
} }
} }
@ -95,12 +101,26 @@ public class DataScopeSqlConfigService {
* @return * @return
*/ */
public String getJoinSql(DataScopeSqlConfigDTO sqlConfigDTO) { public String getJoinSql(DataScopeSqlConfigDTO sqlConfigDTO) {
Integer dataScopeType = sqlConfigDTO.getDataScopeType(); DataScopeTypeEnum dataScopeTypeEnum = sqlConfigDTO.getDataScopeType();
String joinSql = sqlConfigDTO.getJoinSql(); String joinSql = sqlConfigDTO.getJoinSql();
RequestTokenBO requestToken = SmartRequestTokenUtil.getThreadLocalUser(); RequestTokenBO requestToken = SmartRequestTokenUtil.getThreadLocalUser();
Long employeeId = requestToken.getRequestUserId(); Long employeeId = requestToken.getRequestUserId();
if (DataScopeWhereInTypeEnum.EMPLOYEE.getType().equals(sqlConfigDTO.getDataScopeWhereInType())) { if (DataScopeWhereInTypeEnum.CUSTOM_STRATEGY == sqlConfigDTO.getDataScopeWhereInType()) {
List<Long> canViewEmployeeIds = dataScopeViewService.getCanViewEmployeeId(dataScopeType, employeeId); Class strategyClass = sqlConfigDTO.getJoinSqlImplClazz();
if(strategyClass == null){
log.warn("data scope custom strategy class is null");
return "";
}
DataScopePowerStrategy powerStrategy = (DataScopePowerStrategy)SmartApplicationContext.getBean(sqlConfigDTO.getJoinSqlImplClazz());
if (powerStrategy == null) {
log.warn("data scope custom strategy class{} ,bean is null",sqlConfigDTO.getJoinSqlImplClazz());
return "";
}
DataScopeViewTypeEnum viewTypeEnum = dataScopeViewService.getEmployeeDataScopeViewType(dataScopeTypeEnum, employeeId);
return powerStrategy.getCondition(viewTypeEnum,sqlConfigDTO);
}
if (DataScopeWhereInTypeEnum.EMPLOYEE == sqlConfigDTO.getDataScopeWhereInType()) {
List<Long> canViewEmployeeIds = dataScopeViewService.getCanViewEmployeeId(dataScopeTypeEnum, employeeId);
if (CollectionUtils.isEmpty(canViewEmployeeIds)) { if (CollectionUtils.isEmpty(canViewEmployeeIds)) {
return ""; return "";
} }
@ -108,8 +128,8 @@ public class DataScopeSqlConfigService {
String sql = joinSql.replaceAll(EMPLOYEE_PARAM, employeeIds); String sql = joinSql.replaceAll(EMPLOYEE_PARAM, employeeIds);
return sql; return sql;
} }
if (DataScopeWhereInTypeEnum.DEPARTMENT.getType().equals(sqlConfigDTO.getDataScopeWhereInType())) { if (DataScopeWhereInTypeEnum.DEPARTMENT == sqlConfigDTO.getDataScopeWhereInType()) {
List<Long> canViewDepartmentIds = dataScopeViewService.getCanViewDepartmentId(dataScopeType, employeeId); List<Long> canViewDepartmentIds = dataScopeViewService.getCanViewDepartmentId(dataScopeTypeEnum, employeeId);
if (CollectionUtils.isEmpty(canViewDepartmentIds)) { if (CollectionUtils.isEmpty(canViewDepartmentIds)) {
return ""; return "";
} }

View File

@ -1,6 +1,8 @@
package net.lab1024.smartadmin.module.system.datascope.service; package net.lab1024.smartadmin.module.system.datascope.service;
import com.google.common.collect.Lists;
import net.lab1024.smartadmin.module.system.datascope.DataScopeRoleDao; import net.lab1024.smartadmin.module.system.datascope.DataScopeRoleDao;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeViewTypeEnum; import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeViewTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.domain.entity.DataScopeRoleEntity; import net.lab1024.smartadmin.module.system.datascope.domain.entity.DataScopeRoleEntity;
import net.lab1024.smartadmin.module.system.department.DepartmentTreeService; import net.lab1024.smartadmin.module.system.department.DepartmentTreeService;
@ -10,7 +12,7 @@ import net.lab1024.smartadmin.module.system.employee.domain.entity.EmployeeEntit
import net.lab1024.smartadmin.module.system.employee.domain.vo.EmployeeVO; import net.lab1024.smartadmin.module.system.employee.domain.vo.EmployeeVO;
import net.lab1024.smartadmin.module.system.privilege.service.PrivilegeEmployeeService; import net.lab1024.smartadmin.module.system.privilege.service.PrivilegeEmployeeService;
import net.lab1024.smartadmin.module.system.role.roleemployee.RoleEmployeeDao; import net.lab1024.smartadmin.module.system.role.roleemployee.RoleEmployeeDao;
import com.google.common.collect.Lists; import net.lab1024.smartadmin.util.SmartBaseEnumUtil;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -51,33 +53,40 @@ public class DataScopeViewService {
/** /**
* 获取某人可以查看的所有人员信息 * 获取某人可以查看的所有人员信息
* *
* @param dataScopeType * @param dataScopeTypeEnum
* @param employeeId * @param employeeId
* @return * @return
*/ */
public List<Long> getCanViewEmployeeId(Integer dataScopeType, Long employeeId) { public List<Long> getCanViewEmployeeId(DataScopeTypeEnum dataScopeTypeEnum, Long employeeId) {
Integer viewType = this.getEmployeeDataScopeViewType(dataScopeType, employeeId); DataScopeViewTypeEnum viewType = this.getEmployeeDataScopeViewType(dataScopeTypeEnum, employeeId);
if (DataScopeViewTypeEnum.ME.getType().equals(viewType)) { if (DataScopeViewTypeEnum.ME == viewType) {
return this.getMeEmployeeIdList(employeeId); return this.getMeEmployeeIdList(employeeId);
} }
if (DataScopeViewTypeEnum.DEPARTMENT.getType().equals(viewType)) { if (DataScopeViewTypeEnum.DEPARTMENT == viewType) {
return this.getDepartmentEmployeeIdList(employeeId); return this.getDepartmentEmployeeIdList(employeeId);
} }
if (DataScopeViewTypeEnum.DEPARTMENT_AND_SUB.getType().equals(viewType)) { if (DataScopeViewTypeEnum.DEPARTMENT_AND_SUB == viewType) {
return this.getDepartmentAndSubEmployeeIdList(employeeId); return this.getDepartmentAndSubEmployeeIdList(employeeId);
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
public List<Long> getCanViewDepartmentId(Integer dataScopeType, Long employeeId) { /**
Integer viewType = this.getEmployeeDataScopeViewType(dataScopeType, employeeId); * 获取某人可以查看的所有部门信息
if (DataScopeViewTypeEnum.ME.getType().equals(viewType)) { *
* @param dataScopeTypeEnum
* @param employeeId
* @return
*/
public List<Long> getCanViewDepartmentId(DataScopeTypeEnum dataScopeTypeEnum, Long employeeId) {
DataScopeViewTypeEnum viewType = this.getEmployeeDataScopeViewType(dataScopeTypeEnum, employeeId);
if (DataScopeViewTypeEnum.ME == viewType) {
return this.getMeDepartmentIdList(employeeId); return this.getMeDepartmentIdList(employeeId);
} }
if (DataScopeViewTypeEnum.DEPARTMENT.getType().equals(viewType)) { if (DataScopeViewTypeEnum.DEPARTMENT == viewType) {
return this.getMeDepartmentIdList(employeeId); return this.getMeDepartmentIdList(employeeId);
} }
if (DataScopeViewTypeEnum.DEPARTMENT_AND_SUB.getType().equals(viewType)) { if (DataScopeViewTypeEnum.DEPARTMENT_AND_SUB == viewType) {
return this.getDepartmentAndSubIdList(employeeId); return this.getDepartmentAndSubIdList(employeeId);
} }
return Lists.newArrayList(); return Lists.newArrayList();
@ -101,28 +110,28 @@ public class DataScopeViewService {
* @param employeeId * @param employeeId
* @return * @return
*/ */
private Integer getEmployeeDataScopeViewType(Integer dataScopeType, Long employeeId) { public DataScopeViewTypeEnum getEmployeeDataScopeViewType(DataScopeTypeEnum dataScopeTypeEnum, Long employeeId) {
if (employeeId == null) { if (employeeId == null) {
return DataScopeViewTypeEnum.ME.getType(); return DataScopeViewTypeEnum.ME;
} }
if (privilegeEmployeeService.isSuperman(employeeId)) { if (privilegeEmployeeService.isSuperman(employeeId)) {
return DataScopeViewTypeEnum.ALL.getType(); return DataScopeViewTypeEnum.ALL;
} }
List<Long> roleIdList = roleEmployeeDao.selectRoleIdByEmployeeId(employeeId); List<Long> roleIdList = roleEmployeeDao.selectRoleIdByEmployeeId(employeeId);
//未设置角色 默认本人 //未设置角色 默认本人
if (CollectionUtils.isEmpty(roleIdList)) { if (CollectionUtils.isEmpty(roleIdList)) {
return DataScopeViewTypeEnum.ME.getType(); return DataScopeViewTypeEnum.ME;
} }
//未设置角色数据范围 默认本人 //未设置角色数据范围 默认本人
List<DataScopeRoleEntity> dataScopeRoleList = dataScopeRoleDao.listByRoleIdList(roleIdList); List<DataScopeRoleEntity> dataScopeRoleList = dataScopeRoleDao.listByRoleIdList(roleIdList);
if (CollectionUtils.isEmpty(dataScopeRoleList)) { if (CollectionUtils.isEmpty(dataScopeRoleList)) {
return DataScopeViewTypeEnum.ME.getType(); return DataScopeViewTypeEnum.ME;
} }
Map<Integer, List<DataScopeRoleEntity>> listMap = dataScopeRoleList.stream().collect(Collectors.groupingBy(DataScopeRoleEntity :: getDataScopeType)); Map<Integer, List<DataScopeRoleEntity>> listMap = dataScopeRoleList.stream().collect(Collectors.groupingBy(DataScopeRoleEntity::getDataScopeType));
List<DataScopeRoleEntity> viewLevelList = listMap.get(dataScopeType); List<DataScopeRoleEntity> viewLevelList = listMap.get(dataScopeTypeEnum.getValue());
DataScopeRoleEntity maxLevel = viewLevelList.stream().max(Comparator.comparing(e -> DataScopeViewTypeEnum.valueOf(e.getViewType()).getLevel())).get(); DataScopeRoleEntity maxLevel = viewLevelList.stream().max(Comparator.comparing(e -> SmartBaseEnumUtil.getEnumByValue(e.getViewType(), DataScopeViewTypeEnum.class).getLevel())).get();
return maxLevel.getViewType(); return SmartBaseEnumUtil.getEnumByValue(maxLevel.getViewType(), DataScopeViewTypeEnum.class);
} }
/** /**
@ -134,6 +143,7 @@ public class DataScopeViewService {
private List<Long> getMeEmployeeIdList(Long employeeId) { private List<Long> getMeEmployeeIdList(Long employeeId) {
return Lists.newArrayList(employeeId); return Lists.newArrayList(employeeId);
} }
/** /**
* 获取本部门相关 可查看员工id * 获取本部门相关 可查看员工id
* *

View File

@ -0,0 +1,24 @@
package net.lab1024.smartadmin.module.system.datascope.strategy;
import net.lab1024.smartadmin.module.system.datascope.constant.DataScopeViewTypeEnum;
import net.lab1024.smartadmin.module.system.datascope.domain.dto.DataScopeSqlConfigDTO;
/**
* [ 数据范围策略 ,使用DataScopeWhereInTypeEnum.CUSTOM_STRATEGY类型DataScope注解的joinSql属性无用]
*
* @author yandanyang
* @version 1.0
* @company 1024lab.net
* @copyright (c) 2018 1024lab.netInc. All rights reserved.
* @date 2020/11/28 0008 下午 16:00
* @since JDK1.8
*/
public abstract class DataScopePowerStrategy {
/**
* 获取joinsql 字符串
* @param viewTypeEnum 查看的类型
* @param sqlConfigDTO
* @return
*/
public abstract String getCondition(DataScopeViewTypeEnum viewTypeEnum, DataScopeSqlConfigDTO sqlConfigDTO);
}

View File

@ -22,11 +22,9 @@ public class EmployeeLoginFormDTO {
@ApiModelProperty(example = "123456") @ApiModelProperty(example = "123456")
private String loginPwd; private String loginPwd;
@NotNull(message = "验证码id不能为空")
@ApiModelProperty(value = "验证码uuid") @ApiModelProperty(value = "验证码uuid")
private String codeUuid; private String codeUuid;
@NotNull(message = "验证码不能为空")
@ApiModelProperty(value = "验证码") @ApiModelProperty(value = "验证码")
private String code; private String code;

View File

@ -83,15 +83,15 @@ public class LoginService {
* @return 登录用户基本信息 * @return 登录用户基本信息
*/ */
public ResponseDTO<LoginDetailVO> login(@Valid EmployeeLoginFormDTO loginForm, HttpServletRequest request) { public ResponseDTO<LoginDetailVO> login(@Valid EmployeeLoginFormDTO loginForm, HttpServletRequest request) {
String redisVerificationCode = redisValueOperations.get(loginForm.getCodeUuid()); // String redisVerificationCode = redisValueOperations.get(loginForm.getCodeUuid());
//增加删除已使用的验证码方式 频繁登录 // //增加删除已使用的验证码方式 频繁登录
redisValueOperations.getOperations().delete(loginForm.getCodeUuid()); // redisValueOperations.getOperations().delete(loginForm.getCodeUuid());
if (StringUtils.isEmpty(redisVerificationCode)) { // if (StringUtils.isEmpty(redisVerificationCode)) {
return ResponseDTO.wrap(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID); // return ResponseDTO.wrap(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID);
} // }
if (!redisVerificationCode.equalsIgnoreCase(loginForm.getCode())) { // if (!redisVerificationCode.equalsIgnoreCase(loginForm.getCode())) {
return ResponseDTO.wrap(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID); // return ResponseDTO.wrap(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID);
} // }
String loginPwd = SmartDigestUtil.encryptPassword(CommonConst.Password.SALT_FORMAT, loginForm.getLoginPwd()); String loginPwd = SmartDigestUtil.encryptPassword(CommonConst.Password.SALT_FORMAT, loginForm.getLoginPwd());
EmployeeDTO employeeDTO = employeeDao.login(loginForm.getLoginName(), loginPwd); EmployeeDTO employeeDTO = employeeDao.login(loginForm.getLoginName(), loginPwd);
if (null == employeeDTO) { if (null == employeeDTO) {

View File

@ -7,10 +7,10 @@
<FormItem prop="loginPwd"> <FormItem prop="loginPwd">
<Input placeholder="请输入密码" type="password" v-model="formData.loginPwd"></Input> <Input placeholder="请输入密码" type="password" v-model="formData.loginPwd"></Input>
</FormItem> </FormItem>
<FormItem prop="code"> <!-- <FormItem prop="code">
<Input class="code-input" placeholder="请输入验证码" v-model="formData.code"></Input> <Input class="code-input" placeholder="请输入验证码" v-model="formData.code"></Input>
<img :src="codeUrl" @click="verificationCode" class="codeUrl" v-if="codeUrl" /> <img :src="codeUrl" @click="verificationCode" class="codeUrl" v-if="codeUrl" />
</FormItem> </FormItem> -->
<FormItem class="remember"> <FormItem class="remember">
<Checkbox>记住密码</Checkbox> <Checkbox>记住密码</Checkbox>
</FormItem> </FormItem>
@ -47,14 +47,15 @@ export default {
default: () => { default: () => {
return [{ required: true, message: '密码不能为空', trigger: 'blur' }]; return [{ required: true, message: '密码不能为空', trigger: 'blur' }];
} }
},
//
codedRules: {
type: Array,
default: () => {
return [{ required: true, message: '验证码不能为空', trigger: 'blur' }];
}
} }
// ,
// //
// codedRules: {
// type: Array,
// default: () => {
// return [{ required: true, message: '', trigger: 'blur' }];
// }
// }
}, },
data() { data() {
return { return {
@ -79,7 +80,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.verificationCode(); // this.verificationCode();
}, },
methods: { methods: {
// //
@ -125,7 +126,7 @@ export default {
//TODO zhuoda sentry //TODO zhuoda sentry
console.error(e); console.error(e);
this.btnLoading = false; this.btnLoading = false;
this.verificationCode(); //this.verificationCode();
} }
} }
} }

View File

@ -365,6 +365,7 @@ export default {
} catch (e) { } catch (e) {
//TODO zhuoda sentry //TODO zhuoda sentry
console.error(e); console.error(e);
} finally {
this.loading = false; this.loading = false;
} }
}, },
@ -400,33 +401,52 @@ export default {
}, },
// //
async deleteTask(id) { async deleteTask(id) {
let result = await taskApi.deleteTask(id); this.$Spin.show();
this.$Message.success('删除任务成功!'); try{
this.getTaskList(); let result = await taskApi.deleteTask(id);
this.$Message.success('删除任务成功!');
this.getTaskList();
} catch (error) {
console.error(e);
} finally {
this.$Spin.hide();
}
}, },
// //
async controlTask(type, id) { async controlTask(type, id) {
this.$Spin.show(); this.$Spin.show();
switch (type) { try{
case 'RUN': switch (type) {
await taskApi.updateTaskRun(id); case 'RUN':
break; await taskApi.updateTaskRun(id);
case 'PAUSE': break;
await taskApi.updateTaskPause(id); case 'PAUSE':
break; await taskApi.updateTaskPause(id);
case 'RESUME': break;
await taskApi.updateTaskResume(id); case 'RESUME':
break; await taskApi.updateTaskResume(id);
break;
}
this.$Message.success('操作成功');
this.getTaskList();
} catch (error) {
console.error(e);
} finally {
this.$Spin.hide();
} }
this.$Spin.hide();
this.$Message.success('操作成功');
this.getTaskList();
}, },
// //
handleUpdate() { handleUpdate() {
this.$refs['updateRef'].validate(valid => { this.$refs['updateRef'].validate(valid => {
if (valid) { if (valid) {
this.updateTask(); this.$Spin.show();
try{
this.updateTask();
} catch (error) {
console.error(e);
} finally {
this.$Spin.hide();
}
} else { } else {
this.$Message.success('验证信息不通过'); this.$Message.success('验证信息不通过');
} }
@ -444,6 +464,7 @@ export default {
} catch (e) { } catch (e) {
//TODO zhuoda sentry //TODO zhuoda sentry
console.error(e); console.error(e);
} finally {
this.updateLoading = false; this.updateLoading = false;
} }
}, },
@ -464,6 +485,7 @@ export default {
} catch (e) { } catch (e) {
//TODO zhuoda sentry //TODO zhuoda sentry
console.error(e); console.error(e);
} finally {
this.saveLoading = false; this.saveLoading = false;
} }
}, },