Merge remote-tracking branch 'origin/master'

This commit is contained in:
zhouhao
2018-05-08 18:15:32 +08:00
26 changed files with 588 additions and 35 deletions

View File

@@ -59,7 +59,7 @@ public abstract class GenericEntityService<E extends GenericEntity<PK>, PK>
@Override
public int deleteByPk(PK pk) {
Assert.notNull(pk, "parameter can not be null");
return getDao().deleteByPk(pk);
return getDao().deleteByPk(pk);
// return createDelete()
// .where(GenericEntity.id, pk)
// .exec();

View File

@@ -9,7 +9,11 @@ import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.logging.AccessLoggerInfo;
import org.hswebframework.web.logging.AccessLoggerListener;
import org.hswebframework.web.logging.LoggerDefine;
import org.hswebframework.web.logging.events.AccessLoggerAfterEvent;
import org.hswebframework.web.logging.events.AccessLoggerBeforeEvent;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Controller;
@@ -35,7 +39,11 @@ public class AopAccessLoggerSupport extends StaticMethodMatcherPointcutAdvisor {
private final List<AccessLoggerListener> listeners = new ArrayList<>();
private final List<AccessLoggerParser> loggerParsers=new ArrayList<>();
private final List<AccessLoggerParser> loggerParsers = new ArrayList<>();
@Autowired
private ApplicationEventPublisher eventPublisher;
public AopAccessLoggerSupport addListener(AccessLoggerListener loggerListener) {
listeners.add(loggerListener);
@@ -53,6 +61,7 @@ public class AopAccessLoggerSupport extends StaticMethodMatcherPointcutAdvisor {
AccessLoggerInfo info = createLogger(methodInterceptorHolder);
Object response;
try {
eventPublisher.publishEvent(new AccessLoggerBeforeEvent(info));
listeners.forEach(listener -> listener.onLogBefore(info));
response = methodInvocation.proceed();
info.setResponse(response);
@@ -62,6 +71,7 @@ public class AopAccessLoggerSupport extends StaticMethodMatcherPointcutAdvisor {
throw e;
} finally {
//触发监听
eventPublisher.publishEvent(new AccessLoggerAfterEvent(info));
listeners.forEach(listener -> listener.onLogger(info));
}
return response;
@@ -73,15 +83,13 @@ public class AopAccessLoggerSupport extends StaticMethodMatcherPointcutAdvisor {
info.setId(IDGenerator.MD5.generate());
info.setRequestTime(System.currentTimeMillis());
LoggerDefine define=loggerParsers.stream()
.filter(parser->parser.support(ClassUtils.getUserClass(holder.getTarget()),holder.getMethod()))
LoggerDefine define = loggerParsers.stream()
.filter(parser -> parser.support(ClassUtils.getUserClass(holder.getTarget()), holder.getMethod()))
.findAny()
.map(parser->parser.parse(holder))
.map(parser -> parser.parse(holder))
.orElse(null);
if(define!=null) {
if (define != null) {
info.setAction(define.getAction());
info.setDescribe(define.getDescribe());
}
@@ -108,11 +116,11 @@ public class AopAccessLoggerSupport extends StaticMethodMatcherPointcutAdvisor {
@Override
public boolean matches(Method method, Class<?> aClass) {
AccessLogger ann = AopUtils.findAnnotation(aClass, method, AccessLogger.class);
if(ann!=null&&ann.ignore()){
if (ann != null && ann.ignore()) {
return false;
}
RequestMapping mapping= AopUtils.findAnnotation(aClass,method, RequestMapping.class);
return mapping!=null;
RequestMapping mapping = AopUtils.findAnnotation(aClass, method, RequestMapping.class);
return mapping != null;
// //注解了并且未取消
// return null != ann && !ann.ignore();

View File

@@ -35,6 +35,7 @@ public class AopAccessLoggerSupportAutoConfiguration {
public SwaggerAccessLoggerParser swaggerAccessLoggerParser(){
return new SwaggerAccessLoggerParser();
}
@Bean
public ListenerProcessor listenerProcessor() {
return new ListenerProcessor();

View File

@@ -0,0 +1,12 @@
package org.hswebframework.web.logging.events;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.hswebframework.web.logging.AccessLoggerInfo;
@AllArgsConstructor
@Getter
public class AccessLoggerAfterEvent {
private AccessLoggerInfo logger;
}

View File

@@ -0,0 +1,12 @@
package org.hswebframework.web.logging.events;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.hswebframework.web.logging.AccessLoggerInfo;
@AllArgsConstructor
@Getter
public class AccessLoggerBeforeEvent {
private AccessLoggerInfo logger;
}

View File

@@ -19,14 +19,11 @@ package org.hswebframework.web.controller.authorization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.AopUtils;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.AuthenticationManager;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.exception.UnAuthorizedException;
import org.hswebframework.web.authorization.token.TokenState;
import org.hswebframework.web.authorization.token.UserToken;
import org.hswebframework.web.authorization.token.UserTokenManager;
import org.hswebframework.web.commons.entity.PagerResult;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.CreateController;
@@ -34,14 +31,10 @@ import org.hswebframework.web.controller.QueryController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.entity.authorization.UserEntity;
import org.hswebframework.web.entity.authorization.bind.BindRoleUserEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.authorization.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static org.hswebframework.web.controller.message.ResponseMessage.ok;
/**
@@ -52,24 +45,23 @@ import static org.hswebframework.web.controller.message.ResponseMessage.ok;
@RestController
@RequestMapping("${hsweb.web.mappings.user:user}")
@Authorize(permission = "user", description = "用户管理")
@Api(value = "用户管理",tags = "权限-用户管理")
@Api(value = "用户管理", tags = "权限-用户管理")
public class UserController implements
QueryController<UserEntity, String, QueryParamEntity>,
CreateController<BindRoleUserEntity, String, BindRoleUserEntity> {
@Autowired
private UserService userService;
@Autowired
private AuthenticationManager authenticationManager;
@Override
@SuppressWarnings("unchecked")
public UserService getService() {
return userService;
}
@Autowired
public void setUserService(UserService userService) {
this.userService = userService;
}
@Override
@SuppressWarnings("all")
public ResponseMessage<PagerResult<UserEntity>> list(QueryParamEntity param) {
@@ -78,11 +70,6 @@ public class UserController implements
.exclude(UserEntity.class, "password", "salt");
}
public static void main(String[] args) throws NoSuchMethodException {
System.out.println(AopUtils
.findMethodAnnotation(UserController.class,UserController.class.getMethod("list",QueryParamEntity.class),Authorize.class));
}
@Override
@SuppressWarnings("all")
public ResponseMessage<UserEntity> getByPrimaryKey(@PathVariable String id) {
@@ -99,6 +86,13 @@ public class UserController implements
return ok();
}
@Authorize(action = Permission.ACTION_GET)
@GetMapping(path = "/{id:.+}/authentication")
@ApiOperation("获取用户的权限信息")
public ResponseMessage<Authentication> getUserAuthentication(@PathVariable String id) {
return ok(authenticationManager.getByUserId(id));
}
@Authorize(merge = false)
@PutMapping(path = "/password")
@ApiOperation("修改当前登录用户的密码")

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-dashboard</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-dashboard-api</artifactId>
<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-service-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-authorization-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,36 @@
package org.hswebframework.web.dashboard;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.NotBlank;
import org.hswebframework.web.commons.entity.DataStatusEnum;
import org.hswebframework.web.commons.entity.RecordCreationEntity;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
import org.hswebframework.web.validator.group.CreateGroup;
@EqualsAndHashCode(callSuper = true)
@Data
public class DashBoardConfigEntity extends SimpleGenericEntity<String> implements RecordCreationEntity {
private static final long serialVersionUID = 3911748291957287662L;
@NotBlank(groups = CreateGroup.class)
private String name;
private String type;
private String template;
private String script;
private String scriptLanguage;
private DataStatusEnum status;
@NotBlank(groups = CreateGroup.class)
private String creatorId;
@NotBlank(groups = CreateGroup.class)
private Long createTime;
}

View File

@@ -0,0 +1,6 @@
package org.hswebframework.web.dashboard;
import org.hswebframework.web.service.CrudService;
public interface DashBoardService extends CrudService<DashBoardConfigEntity,String> {
}

View File

@@ -0,0 +1,8 @@
package org.hswebframework.web.dashboard.executor;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
public interface DashBoardExecutor {
Object execute(DashBoardConfigEntity entity, Authentication authentication);
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-dashboard</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-dashboard-local</artifactId>
<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dashboard-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-service-simple</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,11 @@
package org.hswebframework.web.dashboard.local;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
public interface DashBoardExecutorStrategy {
boolean support(DashBoardConfigEntity entity);
Object execute(DashBoardConfigEntity entity, Authentication authentication);
}

View File

@@ -0,0 +1,29 @@
package org.hswebframework.web.dashboard.local;
import org.hswebframework.web.dao.CrudDao;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
import org.hswebframework.web.dashboard.DashBoardService;
import org.hswebframework.web.dashboard.local.dao.DashBoardConfigDao;
import org.hswebframework.web.id.IDGenerator;
import org.hswebframework.web.service.EnableCacheGenericEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
@Service
@CacheConfig(cacheNames = "hsweb:dashboard-conf")
public class DefaultDashBoardService extends EnableCacheGenericEntityService<DashBoardConfigEntity, String> implements DashBoardService {
@Autowired
private DashBoardConfigDao dashBoardConfigDao;
@Override
protected IDGenerator<String> getIDGenerator() {
return IDGenerator.MD5;
}
@Override
public CrudDao<DashBoardConfigEntity, String> getDao() {
return dashBoardConfigDao;
}
}

View File

@@ -0,0 +1,29 @@
package org.hswebframework.web.dashboard.local;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
import org.hswebframework.web.dashboard.executor.DashBoardExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.util.List;
@Component
public class DefaultDashBordExecutor implements DashBoardExecutor {
@Autowired
private List<DashBoardExecutorStrategy> strategies;
@Override
public Object execute(DashBoardConfigEntity entity, Authentication authentication) {
Assert.notNull(entity, "配置不能为空");
return strategies.stream()
.filter(strategy -> strategy.support(entity))
.findFirst()
.map(strategy -> strategy.execute(entity, authentication))
.orElse(null);
}
}

View File

@@ -0,0 +1,7 @@
package org.hswebframework.web.dashboard.local.dao;
import org.hswebframework.web.dao.CrudDao;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
public interface DashBoardConfigDao extends CrudDao<DashBoardConfigEntity,String> {
}

View File

@@ -0,0 +1,52 @@
package org.hswebframework.web.dashboard.local.strategy;
import lombok.SneakyThrows;
import org.hswebframework.expands.script.engine.DynamicScriptEngine;
import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
import org.hswebframework.ezorm.rdb.executor.SqlExecutor;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
import org.hswebframework.web.dashboard.local.DashBoardExecutorStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import java.util.HashMap;
import java.util.Map;
@Component
public class ScriptExecutorStrategy implements DashBoardExecutorStrategy {
@Autowired
private SqlExecutor sqlExecutor;
@Override
public boolean support(DashBoardConfigEntity entity) {
return "script".equals(entity.getType());
}
@Override
@SneakyThrows
public Object execute(DashBoardConfigEntity entity, Authentication authentication) {
Map<String, Object> scriptContext = new HashMap<>();
scriptContext.put("autz", authentication);
if ("sql".equals(entity.getScriptLanguage())) {
return sqlExecutor.list(entity.getScript(), scriptContext);
}
DynamicScriptEngine engine = DynamicScriptEngineFactory.getEngine(entity.getScriptLanguage());
if (engine != null) {
String id = DigestUtils.md5DigestAsHex(entity.getScript().getBytes());
if (!engine.compiled(id)) {
engine.compile(id, entity.getScript());
}
return engine.execute(id, scriptContext).getIfSuccess();
}
return null;
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hswebframework.web.dashboard.local.dao.DashBoardConfigDao">
<resultMap id="DashBoardConfigEntityResultMap" type="org.hswebframework.web.dashboard.DashBoardConfigEntity">
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
<result property="type" column="type" javaType="String" jdbcType="VARCHAR"/>
<result property="template" column="template" javaType="String" jdbcType="CLOB"/>
<result property="script" column="script" javaType="String" jdbcType="CLOB"/>
<result property="scriptLanguage" column="script_lang" javaType="String" jdbcType="VARCHAR"/>
<result property="creatorId" column="creator_id" javaType="String" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" javaType="Date" jdbcType="TIMESTAMP"/>
<result property="status" column="status" javaType="org.hswebframework.web.commons.entity.DataStatusEnum" jdbcType="INTEGER"/>
</resultMap>
<!--用于动态生成sql所需的配置-->
<sql id="config">
<bind name="resultMapId" value="'TemplateResultMap'"/>
<bind name="tableName" value="'s_dashboard_conf'"/>
</sql>
<insert id="insert" parameterType="org.hswebframework.web.dashboard.DashBoardConfigEntity">
<include refid="config"/>
<include refid="BasicMapper.buildInsertSql"/>
</insert>
<delete id="deleteByPk" parameterType="String">
delete from s_dashboard_conf where u_id =#{id}
</delete>
<delete id="delete" parameterType="org.hswebframework.web.commons.entity.Entity">
<include refid="config"/>
<include refid="BasicMapper.buildDeleteSql"/>
</delete>
<update id="update" parameterType="org.hswebframework.web.commons.entity.Entity">
<include refid="config"/>
<include refid="BasicMapper.buildUpdateSql"/>
</update>
<select id="query" parameterType="org.hswebframework.web.commons.entity.Entity" resultMap="DashBoardConfigEntityResultMap">
<include refid="config"/>
<include refid="BasicMapper.buildSelectSql"/>
</select>
<select id="count" parameterType="org.hswebframework.web.commons.entity.Entity" resultType="int">
<include refid="config"/>
<include refid="BasicMapper.buildTotalSql"/>
</select>
</mapper>

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-dashboard</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-dashboard-starter</artifactId>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dashboard-local</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dashboard-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.26</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-spring-boot-starter</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-tests</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,16 @@
package org.hswebframework.web.dashboard.starter;
import org.hswebframework.web.dao.Dao;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @author zhouhao
*/
@Configuration
@ComponentScan({"org.hswebframework.web.dashboard.local"
, "org.hswebframework.web.controller.dashboard"})
@MapperScan(value = "org.hswebframework.web.dashboard.local.dao", markerInterface = Dao.class)
public class DashboardAutoConfiguration {
}

View File

@@ -0,0 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.hswebframework.web.dashboard.starter.DashboadAutoConfiguration

View File

@@ -0,0 +1,48 @@
//组件信息
var info = {
groupId: "${project.groupId}",
artifactId: "${project.artifactId}",
version: "${project.version}",
website: "https://github.com/hs-web/hsweb-framework",
author: "admin@hsweb.me",
comment: "仪表盘配置"
};
//版本更新信息
var versions = [
// {
// version: "3.0.2",
// upgrade: function (context) {
// java.lang.System.out.println("更新到3.0.2了");
// }
// }
];
var JDBCType = java.sql.JDBCType;
function install(context) {
var database = context.database;
database.createOrAlter("s_dashboard_conf")
.addColumn().name("u_id").alias("id").comment("ID").jdbcType(java.sql.JDBCType.VARCHAR).length(32).primaryKey().commit()
.addColumn().name("name").alias("name").comment("配置名称").jdbcType(java.sql.JDBCType.VARCHAR).length(32).commit()
.addColumn().name("type").alias("type").comment("配置类型").jdbcType(java.sql.JDBCType.VARCHAR).length(32).commit()
.addColumn().name("template").alias("template").comment("模板").jdbcType(java.sql.JDBCType.CLOB).commit()
.addColumn().name("script").alias("script").comment("脚本").jdbcType(java.sql.JDBCType.CLOB).commit()
.addColumn().name("script_lang").alias("scriptLanguage").comment("脚本语言").jdbcType(java.sql.JDBCType.CLOB).commit()
.addColumn().name("creator_id").alias("creatorId").comment("创建人").varchar(32).commit()
.addColumn().name("create_time").alias("createTime").comment("创建时间").datetime().commit()
.addColumn().name("status").alias("status").comment("状态").number(4).commit()
.comment("模板").commit();
}
//设置依赖
dependency.setup(info)
.onInstall(install)
.onUpgrade(function (context) { //更新时执行
var upgrader = context.upgrader;
upgrader.filter(versions)
.upgrade(function (newVer) {
newVer.upgrade(context);
});
})
.onUninstall(function (context) { //卸载时执行
});

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-dashboard</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-dashboard-web</artifactId>
<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dashboard-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-controller</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,44 @@
package org.hswebframework.web.controller.dashboard;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.controller.message.ResponseMessage;
import org.hswebframework.web.dashboard.DashBoardConfigEntity;
import org.hswebframework.web.dashboard.DashBoardService;
import org.hswebframework.web.dashboard.executor.DashBoardExecutor;
import org.hswebframework.web.service.CrudService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/dashboard")
@Api(tags = "仪表盘-配置", value = "仪表盘配置")
@Authorize(permission = "dashboard", description = "仪表盘配置")
public class DashBoardConfigController implements SimpleGenericEntityController<DashBoardConfigEntity, String, QueryParamEntity> {
@Autowired
DashBoardService dashBoardService;
@Autowired
DashBoardExecutor dashBoardExecutor;
@Override
public CrudService<DashBoardConfigEntity, String> getService() {
return dashBoardService;
}
@GetMapping("{id}/execute")
@Authorize
@ApiOperation("执行仪表盘配置")
public ResponseMessage<Object> execute(@PathVariable String id) {
return ResponseMessage.ok(dashBoardExecutor.execute(dashBoardService.selectByPk(id), Authentication.current().orElse(null)));
}
}

View File

@@ -10,6 +10,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>hsweb-system-dashboard</artifactId>
<packaging>pom</packaging>
<modules>
<module>hsweb-system-dashboard-api</module>
<module>hsweb-system-dashboard-local</module>
<module>hsweb-system-dashboard-web</module>
<module>hsweb-system-dashboard-starter</module>
</modules>
</project>

View File

@@ -1,5 +1,7 @@
package org.hswebframework.web.dev.tools.reader;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.File;
@@ -9,22 +11,35 @@ import java.io.File;
* @since 3.0
*/
@Data
@ApiModel("文件信息")
public class FileInfo {
@ApiModelProperty("文件名")
private String name;
@ApiModelProperty("文件长度")
private Long length;
@ApiModelProperty("父目录")
private String parent;
@ApiModelProperty("文件长度")
private String absolutePath;
@ApiModelProperty("是否为文件")
private boolean file;
public static FileInfo from(File file){
FileInfo info=new FileInfo();
@ApiModelProperty("是否为目录")
private boolean dir;
public static FileInfo from(File file) {
FileInfo info = new FileInfo();
info.setName(file.getName());
info.setLength(file.length());
info.setParent(file.getParent());
info.setAbsolutePath(file.getAbsolutePath());
return info;
info.setFile(file.isFile());
info.setDir(file.isDirectory());
return info;
}
}

View File

@@ -48,7 +48,7 @@ public class FileManagerDevToolsController {
public ResponseMessage<List<FileInfo>> write(@RequestParam String path) {
File file = new File(path);
if (!file.exists()) {
return null;
return ResponseMessage.error(404,"文件不存在");
}
List<FileInfo> list;
if (file.isDirectory()) {
@@ -73,7 +73,7 @@ public class FileManagerDevToolsController {
public ResponseMessage<String> read(@RequestParam String file) {
File fileInfo = new File(file);
if (!fileInfo.exists()) {
return null;
return ResponseMessage.error(404,"文件不存在");
}
if (fileInfo.length() > 2 * 1024 * 1024 * 1024L) {
return ResponseMessage.error(500, "文件过大,无法读取");