forked from github/dataease
feat: 优化查询任务日志
This commit is contained in:
parent
e59864c5ee
commit
084aab5e92
@ -15,7 +15,11 @@ import java.util.List;
|
||||
public interface ExtDataSetTaskMapper {
|
||||
List<DataSetTaskLogDTO> listTaskLog(GridExample example);
|
||||
|
||||
List<DataSetTaskLogDTO> listUserTaskLog(GridExample example);
|
||||
|
||||
List<DataSetTaskDTO> taskList(GridExample example);
|
||||
|
||||
List<DataSetTaskDTO> userTaskList(GridExample example);
|
||||
|
||||
List<DataSetTaskDTO> taskWithTriggers(GridExample example);
|
||||
}
|
||||
|
@ -30,6 +30,22 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="listUserTaskLog" resultMap="BaseResult" parameterType="io.dataease.base.domain.DatasetTableTaskLog">
|
||||
SELECT dataset_table_task_log.*, dataset_table_task.name, dataset_table.name as dataset_name
|
||||
FROM dataset_table_task_log
|
||||
LEFT JOIN dataset_table_task ON dataset_table_task_log.task_id = dataset_table_task.id
|
||||
LEFT JOIN dataset_table ON dataset_table_task_log.table_id = dataset_table.id
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.taskListGridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
ORDER BY dataset_table_task_log.create_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="taskList" resultMap="TaskResult" parameterType="io.dataease.base.mapper.ext.query.GridExample">
|
||||
SELECT dataset_table.name as table_name, get_auths(dataset_table_task.table_id,'dataset', #{extendCondition}) as `privileges`,dataset_table_task.* , qrtz_triggers.NEXT_FIRE_TIME
|
||||
FROM dataset_table_task
|
||||
@ -46,6 +62,22 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="userTaskList" resultMap="TaskResult" parameterType="io.dataease.base.mapper.ext.query.GridExample">
|
||||
SELECT dataset_table.name as table_name, get_auths(dataset_table_task.table_id,'dataset', #{extendCondition}) as `privileges`,dataset_table_task.* , qrtz_triggers.NEXT_FIRE_TIME
|
||||
FROM dataset_table_task
|
||||
left join dataset_table on dataset_table.id=dataset_table_task.table_id
|
||||
left join qrtz_triggers on dataset_table_task.id=qrtz_triggers.TRIGGER_NAME
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.base.mapper.ext.query.GridSql.taskListGridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
order by dataset_table_task.create_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="taskWithTriggers" resultMap="TaskResult" parameterType="io.dataease.base.mapper.ext.query.GridExample">
|
||||
SELECT dataset_table.name as table_name, get_auths(dataset_table_task.table_id,'dataset', #{extendCondition}) as `privileges`,dataset_table_task.* , qrtz_triggers.NEXT_FIRE_TIME
|
||||
FROM dataset_table_task
|
||||
|
@ -114,6 +114,15 @@ public class GridExample {
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addSqlCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
Criterion criterion = new Criterion(condition, value);
|
||||
criterion.sqlValue = true;
|
||||
criteria.add(criterion);
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
@ -209,6 +218,16 @@ public class GridExample {
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
public boolean isSqlValue() {
|
||||
return sqlValue;
|
||||
}
|
||||
|
||||
public void setSqlValue(boolean sqlValue) {
|
||||
this.sqlValue = sqlValue;
|
||||
}
|
||||
|
||||
private boolean sqlValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
|
@ -32,4 +32,36 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
|
||||
<sql id="taskListGridCondition">
|
||||
<where>
|
||||
dataset_table.id in (SELECT `sys_auth`.`auth_source` FROM `sys_auth` LEFT JOIN `sys_auth_detail` ON `sys_auth`.`id` = `sys_auth_detail`.`auth_id` LEFT JOIN `dataset_table` ON `dataset_table`.`id` = `sys_auth`.`auth_source` WHERE `sys_auth_detail`.`privilege_type` = '1' and `sys_auth_detail`.`privilege_value` = '1'and `sys_auth`.`auth_source_type` = 'dataset' AND ((`sys_auth`.`auth_target_type` = 'dept' AND `sys_auth`.`auth_target` in ( SELECT dept_id FROM `sys_user` WHERE `sys_user`.`user_id` = #{extendCondition} )) OR (sys_auth.auth_target_type = 'user'AND sys_auth.auth_target = #{extendCondition} ) OR (sys_auth.auth_target_type = 'role' AND `sys_auth`.`auth_target` in ( SELECT role_id FROM `sys_users_roles` WHERE `sys_users_roles`.`user_id` = #{extendCondition} )) OR (1 = ( SELECT is_admin FROM `sys_user` WHERE `sys_user`.`user_id` = #{extendCondition} )))) and
|
||||
<foreach collection="oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
|
@ -36,7 +36,7 @@ public class DataSetTableTaskLogController {
|
||||
@PostMapping("list/{type}/{goPage}/{pageSize}")
|
||||
public Pager<List<DataSetTaskLogDTO>> list(@RequestBody BaseGridRequest request, @PathVariable String type, @PathVariable int goPage, @PathVariable int pageSize) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, dataSetTableTaskLogService.list(request, type));
|
||||
return PageUtils.setPageInfo(page, dataSetTableTaskLogService.listTaskLog(request, type));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,41 +45,48 @@ public class DataSetTableTaskLogService {
|
||||
datasetTableTaskLogMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public List<DataSetTaskLogDTO> list(BaseGridRequest request, String type) {
|
||||
public List<DataSetTaskLogDTO> listTaskLog(BaseGridRequest request, String type) {
|
||||
List<ConditionEntity> conditionEntities = request.getConditions();
|
||||
if(!type.equalsIgnoreCase("excel")){
|
||||
ConditionEntity entity = new ConditionEntity();
|
||||
entity.setField("task_id");
|
||||
entity.setOperator("not in");
|
||||
List<String>status = new ArrayList<>();status.add("初始导入");status.add("替换");status.add("追加");
|
||||
entity.setValue(status);
|
||||
List<ConditionEntity> conditionEntities = request.getConditions();
|
||||
if(CollectionUtils.isEmpty(conditionEntities)){
|
||||
conditionEntities = new ArrayList<>();
|
||||
}
|
||||
conditionEntities.add(entity);
|
||||
|
||||
ConditionEntity entity2 = new ConditionEntity();
|
||||
entity2.setField("dataset_table.id");
|
||||
entity2.setOperator("sql in");
|
||||
entity2.setValue(" SELECT\tsys_auth.auth_source FROM sys_auth\n" +
|
||||
"LEFT JOIN sys_auth_detail ON sys_auth.id = sys_auth_detail.auth_id\n" +
|
||||
"LEFT JOIN dataset_table ON dataset_table.id = sys_auth.auth_source\n" +
|
||||
"WHERE\tsys_auth_detail.privilege_type = '1'and sys_auth.auth_source_type = 'dataset'\n" +
|
||||
"AND ((sys_auth.auth_target_type = 'dept'AND sys_auth.auth_target in ( SELECT dept_id FROM sys_user WHERE user_id = userId ))\n" +
|
||||
"\tOR (sys_auth.auth_target_type = 'user'AND sys_auth.auth_target = '1')OR (sys_auth.auth_target_type = 'role'AND sys_auth.auth_target in ( SELECT role_id FROM sys_users_roles WHERE user_id = userId ))\n" +
|
||||
"\tOR (1 = ( SELECT is_admin FROM sys_user WHERE user_id = userId ))\n" +
|
||||
"\t) ".replace("userId", AuthUtils.getUser().getUserId().toString()));
|
||||
conditionEntities.add(entity2);
|
||||
request.setConditions(conditionEntities);
|
||||
}
|
||||
|
||||
ConditionEntity entity2 = new ConditionEntity();
|
||||
entity2.setField("1");
|
||||
entity2.setOperator("eq");
|
||||
entity2.setValue("1");
|
||||
conditionEntities.add(entity2);
|
||||
request.setConditions(conditionEntities);
|
||||
|
||||
GridExample gridExample = request.convertExample();
|
||||
List<DataSetTaskLogDTO> dataSetTaskLogDTOS = extDataSetTaskMapper.listTaskLog(gridExample);
|
||||
dataSetTaskLogDTOS.forEach(dataSetTaskLogDTO -> {
|
||||
if(StringUtils.isEmpty(dataSetTaskLogDTO.getName())){
|
||||
dataSetTaskLogDTO.setName(dataSetTaskLogDTO.getTaskId());
|
||||
}
|
||||
});
|
||||
return dataSetTaskLogDTOS;
|
||||
gridExample.setExtendCondition(AuthUtils.getUser().getUserId().toString());
|
||||
|
||||
if(AuthUtils.getUser().getIsAdmin()){
|
||||
List<DataSetTaskLogDTO> dataSetTaskLogDTOS = extDataSetTaskMapper.listTaskLog(gridExample);
|
||||
dataSetTaskLogDTOS.forEach(dataSetTaskLogDTO -> {
|
||||
if(StringUtils.isEmpty(dataSetTaskLogDTO.getName())){
|
||||
dataSetTaskLogDTO.setName(dataSetTaskLogDTO.getTaskId());
|
||||
}
|
||||
});
|
||||
return dataSetTaskLogDTOS;
|
||||
}else {
|
||||
List<DataSetTaskLogDTO> dataSetTaskLogDTOS = extDataSetTaskMapper.listUserTaskLog(gridExample);
|
||||
dataSetTaskLogDTOS.forEach(dataSetTaskLogDTO -> {
|
||||
if(StringUtils.isEmpty(dataSetTaskLogDTO.getName())){
|
||||
dataSetTaskLogDTO.setName(dataSetTaskLogDTO.getTaskId());
|
||||
}
|
||||
});
|
||||
return dataSetTaskLogDTOS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteByTaskId(String taskId){
|
||||
|
@ -237,22 +237,20 @@ public class DataSetTableTaskService {
|
||||
public List<DataSetTaskDTO> taskList4User(BaseGridRequest request) {
|
||||
List<ConditionEntity> conditionEntities = request.getConditions() == null ? new ArrayList<>() : new ArrayList(request.getConditions());;
|
||||
ConditionEntity entity = new ConditionEntity();
|
||||
entity.setField("dataset_table.id");
|
||||
entity.setOperator("sql in");
|
||||
entity.setValue(" SELECT\tsys_auth.auth_source FROM sys_auth\n" +
|
||||
"LEFT JOIN sys_auth_detail ON sys_auth.id = sys_auth_detail.auth_id\n" +
|
||||
"LEFT JOIN dataset_table ON dataset_table.id = sys_auth.auth_source\n" +
|
||||
"WHERE\tsys_auth_detail.privilege_type = '1'and sys_auth.auth_source_type = 'dataset'\n" +
|
||||
"AND ((sys_auth.auth_target_type = 'dept'AND sys_auth.auth_target in ( SELECT dept_id FROM sys_user WHERE user_id = userId ))\n" +
|
||||
"\tOR (sys_auth.auth_target_type = 'user'AND sys_auth.auth_target = '1')OR (sys_auth.auth_target_type = 'role'AND sys_auth.auth_target in ( SELECT role_id FROM sys_users_roles WHERE user_id = userId ))\n" +
|
||||
"\tOR (1 = ( SELECT is_admin FROM sys_user WHERE user_id = userId ))\n" +
|
||||
"\t) ".replace("userId", AuthUtils.getUser().getUserId().toString()));
|
||||
entity.setField("1");
|
||||
entity.setOperator("eq");
|
||||
entity.setValue("1");
|
||||
conditionEntities.add(entity);
|
||||
request.setConditions(conditionEntities);
|
||||
GridExample gridExample = request.convertExample();
|
||||
gridExample.setExtendCondition(AuthUtils.getUser().getUserId().toString());
|
||||
List<DataSetTaskDTO> dataSetTaskDTOS = extDataSetTaskMapper.taskList(gridExample);
|
||||
return dataSetTaskDTOS;
|
||||
if(AuthUtils.getUser().getIsAdmin()){
|
||||
List<DataSetTaskDTO> dataSetTaskDTOS = extDataSetTaskMapper.taskList(gridExample);
|
||||
return dataSetTaskDTOS;
|
||||
}else {
|
||||
List<DataSetTaskDTO> dataSetTaskDTOS = extDataSetTaskMapper.userTaskList(gridExample);
|
||||
return dataSetTaskDTOS;
|
||||
}
|
||||
}
|
||||
|
||||
public List<DataSetTaskDTO> taskWithTriggers(BaseGridRequest request) {
|
||||
|
Loading…
Reference in New Issue
Block a user