forked from github/dataease
feat: shiro从session模式改为token模式 增加jwt
This commit is contained in:
parent
b2b8814ee5
commit
281caea95f
@ -16,6 +16,7 @@
|
||||
<shiro.version>1.7.1</shiro.version>
|
||||
<java.version>1.8</java.version>
|
||||
<graalvm.version>20.1.0</graalvm.version>
|
||||
<jwt.version>3.12.1</jwt.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -104,12 +105,22 @@
|
||||
<version>5.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring-boot-starter</artifactId>
|
||||
<version>${shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
@ -135,6 +146,12 @@
|
||||
<version>1.2.72</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- openapi -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
@ -345,27 +362,27 @@
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>-->
|
||||
<!-- <artifactId>maven-clean-plugin</artifactId>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <filesets>-->
|
||||
<!-- <fileset>-->
|
||||
<!-- <directory>src/main/resources/static</directory>-->
|
||||
<!-- <includes>-->
|
||||
<!-- <include>**</include>-->
|
||||
<!-- </includes>-->
|
||||
<!-- <followSymlinks>false</followSymlinks>-->
|
||||
<!-- </fileset>-->
|
||||
<!-- <fileset>-->
|
||||
<!-- <directory>src/main/resources/templates</directory>-->
|
||||
<!-- <includes>-->
|
||||
<!-- <include>**</include>-->
|
||||
<!-- </includes>-->
|
||||
<!-- <followSymlinks>false</followSymlinks>-->
|
||||
<!-- </fileset>-->
|
||||
<!-- </filesets>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>src/main/resources/static</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
<fileset>
|
||||
<directory>src/main/resources/templates</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<followSymlinks>false</followSymlinks>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
@ -0,0 +1,15 @@
|
||||
package io.dataease.auth.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CurrentRoleDto implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package io.dataease.auth.api.dto;
|
||||
|
||||
import io.dataease.auth.entity.SysUserEntity;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class CurrentUserDto extends SysUserEntity implements Serializable {
|
||||
|
||||
private List<CurrentRoleDto> roles;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package io.dataease.auth.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
//1,允许任何来源
|
||||
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
|
||||
//2,允许任何请求头
|
||||
corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
|
||||
//3,允许任何方法
|
||||
corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
|
||||
//4,允许凭证
|
||||
corsConfiguration.setAllowCredentials(true);
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", corsConfiguration);
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package io.dataease.base.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChartGroup implements Serializable {
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String pid;
|
||||
|
||||
private Integer level;
|
||||
|
||||
private String type;
|
||||
|
||||
private String createBy;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -1,670 +0,0 @@
|
||||
package io.dataease.base.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChartGroupExample {
|
||||
protected String orderByClause;
|
||||
|
||||
protected boolean distinct;
|
||||
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
public ChartGroupExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andIdIsNull() {
|
||||
addCriterion("id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIsNotNull() {
|
||||
addCriterion("id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdEqualTo(String value) {
|
||||
addCriterion("id =", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotEqualTo(String value) {
|
||||
addCriterion("id <>", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThan(String value) {
|
||||
addCriterion("id >", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("id >=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThan(String value) {
|
||||
addCriterion("id <", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThanOrEqualTo(String value) {
|
||||
addCriterion("id <=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLike(String value) {
|
||||
addCriterion("id like", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotLike(String value) {
|
||||
addCriterion("id not like", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIn(List<String> values) {
|
||||
addCriterion("id in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotIn(List<String> values) {
|
||||
addCriterion("id not in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdBetween(String value1, String value2) {
|
||||
addCriterion("id between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotBetween(String value1, String value2) {
|
||||
addCriterion("id not between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameIsNull() {
|
||||
addCriterion("`name` is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameIsNotNull() {
|
||||
addCriterion("`name` is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameEqualTo(String value) {
|
||||
addCriterion("`name` =", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotEqualTo(String value) {
|
||||
addCriterion("`name` <>", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameGreaterThan(String value) {
|
||||
addCriterion("`name` >", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("`name` >=", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameLessThan(String value) {
|
||||
addCriterion("`name` <", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameLessThanOrEqualTo(String value) {
|
||||
addCriterion("`name` <=", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameLike(String value) {
|
||||
addCriterion("`name` like", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotLike(String value) {
|
||||
addCriterion("`name` not like", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameIn(List<String> values) {
|
||||
addCriterion("`name` in", values, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotIn(List<String> values) {
|
||||
addCriterion("`name` not in", values, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameBetween(String value1, String value2) {
|
||||
addCriterion("`name` between", value1, value2, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotBetween(String value1, String value2) {
|
||||
addCriterion("`name` not between", value1, value2, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidIsNull() {
|
||||
addCriterion("pid is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidIsNotNull() {
|
||||
addCriterion("pid is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidEqualTo(String value) {
|
||||
addCriterion("pid =", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidNotEqualTo(String value) {
|
||||
addCriterion("pid <>", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidGreaterThan(String value) {
|
||||
addCriterion("pid >", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("pid >=", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidLessThan(String value) {
|
||||
addCriterion("pid <", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidLessThanOrEqualTo(String value) {
|
||||
addCriterion("pid <=", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidLike(String value) {
|
||||
addCriterion("pid like", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidNotLike(String value) {
|
||||
addCriterion("pid not like", value, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidIn(List<String> values) {
|
||||
addCriterion("pid in", values, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidNotIn(List<String> values) {
|
||||
addCriterion("pid not in", values, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidBetween(String value1, String value2) {
|
||||
addCriterion("pid between", value1, value2, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPidNotBetween(String value1, String value2) {
|
||||
addCriterion("pid not between", value1, value2, "pid");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelIsNull() {
|
||||
addCriterion("`level` is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelIsNotNull() {
|
||||
addCriterion("`level` is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelEqualTo(Integer value) {
|
||||
addCriterion("`level` =", value, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelNotEqualTo(Integer value) {
|
||||
addCriterion("`level` <>", value, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelGreaterThan(Integer value) {
|
||||
addCriterion("`level` >", value, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelGreaterThanOrEqualTo(Integer value) {
|
||||
addCriterion("`level` >=", value, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelLessThan(Integer value) {
|
||||
addCriterion("`level` <", value, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelLessThanOrEqualTo(Integer value) {
|
||||
addCriterion("`level` <=", value, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelIn(List<Integer> values) {
|
||||
addCriterion("`level` in", values, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelNotIn(List<Integer> values) {
|
||||
addCriterion("`level` not in", values, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelBetween(Integer value1, Integer value2) {
|
||||
addCriterion("`level` between", value1, value2, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andLevelNotBetween(Integer value1, Integer value2) {
|
||||
addCriterion("`level` not between", value1, value2, "level");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeIsNull() {
|
||||
addCriterion("`type` is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeIsNotNull() {
|
||||
addCriterion("`type` is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeEqualTo(String value) {
|
||||
addCriterion("`type` =", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotEqualTo(String value) {
|
||||
addCriterion("`type` <>", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeGreaterThan(String value) {
|
||||
addCriterion("`type` >", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("`type` >=", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeLessThan(String value) {
|
||||
addCriterion("`type` <", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeLessThanOrEqualTo(String value) {
|
||||
addCriterion("`type` <=", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeLike(String value) {
|
||||
addCriterion("`type` like", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotLike(String value) {
|
||||
addCriterion("`type` not like", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeIn(List<String> values) {
|
||||
addCriterion("`type` in", values, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotIn(List<String> values) {
|
||||
addCriterion("`type` not in", values, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeBetween(String value1, String value2) {
|
||||
addCriterion("`type` between", value1, value2, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotBetween(String value1, String value2) {
|
||||
addCriterion("`type` not between", value1, value2, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByIsNull() {
|
||||
addCriterion("create_by is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByIsNotNull() {
|
||||
addCriterion("create_by is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByEqualTo(String value) {
|
||||
addCriterion("create_by =", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByNotEqualTo(String value) {
|
||||
addCriterion("create_by <>", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByGreaterThan(String value) {
|
||||
addCriterion("create_by >", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("create_by >=", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByLessThan(String value) {
|
||||
addCriterion("create_by <", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByLessThanOrEqualTo(String value) {
|
||||
addCriterion("create_by <=", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByLike(String value) {
|
||||
addCriterion("create_by like", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByNotLike(String value) {
|
||||
addCriterion("create_by not like", value, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByIn(List<String> values) {
|
||||
addCriterion("create_by in", values, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByNotIn(List<String> values) {
|
||||
addCriterion("create_by not in", values, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByBetween(String value1, String value2) {
|
||||
addCriterion("create_by between", value1, value2, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateByNotBetween(String value1, String value2) {
|
||||
addCriterion("create_by not between", value1, value2, "createBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIsNull() {
|
||||
addCriterion("create_time is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIsNotNull() {
|
||||
addCriterion("create_time is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeEqualTo(Long value) {
|
||||
addCriterion("create_time =", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeNotEqualTo(Long value) {
|
||||
addCriterion("create_time <>", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeGreaterThan(Long value) {
|
||||
addCriterion("create_time >", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("create_time >=", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeLessThan(Long value) {
|
||||
addCriterion("create_time <", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
|
||||
addCriterion("create_time <=", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIn(List<Long> values) {
|
||||
addCriterion("create_time in", values, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeNotIn(List<Long> values) {
|
||||
addCriterion("create_time not in", values, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeBetween(Long value1, Long value2) {
|
||||
addCriterion("create_time between", value1, value2, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
|
||||
addCriterion("create_time not between", value1, value2, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package io.dataease.base.mapper;
|
||||
|
||||
import io.dataease.base.domain.ChartGroup;
|
||||
import io.dataease.base.domain.ChartGroupExample;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface ChartGroupMapper {
|
||||
long countByExample(ChartGroupExample example);
|
||||
|
||||
int deleteByExample(ChartGroupExample example);
|
||||
|
||||
int deleteByPrimaryKey(String id);
|
||||
|
||||
int insert(ChartGroup record);
|
||||
|
||||
int insertSelective(ChartGroup record);
|
||||
|
||||
List<ChartGroup> selectByExample(ChartGroupExample example);
|
||||
|
||||
ChartGroup selectByPrimaryKey(String id);
|
||||
|
||||
int updateByExampleSelective(@Param("record") ChartGroup record, @Param("example") ChartGroupExample example);
|
||||
|
||||
int updateByExample(@Param("record") ChartGroup record, @Param("example") ChartGroupExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(ChartGroup record);
|
||||
|
||||
int updateByPrimaryKey(ChartGroup record);
|
||||
}
|
@ -1,243 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.dataease.base.mapper.ChartGroupMapper">
|
||||
<resultMap id="BaseResultMap" type="io.dataease.base.domain.ChartGroup">
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="pid" jdbcType="VARCHAR" property="pid" />
|
||||
<result column="level" jdbcType="INTEGER" property="level" />
|
||||
<result column="type" jdbcType="VARCHAR" property="type" />
|
||||
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
|
||||
<result column="create_time" jdbcType="BIGINT" property="createTime" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
<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>
|
||||
<sql id="Update_By_Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="example.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>
|
||||
<sql id="Base_Column_List">
|
||||
id, `name`, pid, `level`, `type`, create_by, create_time
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.dataease.base.domain.ChartGroupExample" resultMap="BaseResultMap">
|
||||
select
|
||||
<if test="distinct">
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
from chart_group
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from chart_group
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from chart_group
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<delete id="deleteByExample" parameterType="io.dataease.base.domain.ChartGroupExample">
|
||||
delete from chart_group
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="io.dataease.base.domain.ChartGroup">
|
||||
insert into chart_group (id, `name`, pid,
|
||||
`level`, `type`, create_by,
|
||||
create_time)
|
||||
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR},
|
||||
#{level,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=BIGINT})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.dataease.base.domain.ChartGroup">
|
||||
insert into chart_group
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
id,
|
||||
</if>
|
||||
<if test="name != null">
|
||||
`name`,
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
pid,
|
||||
</if>
|
||||
<if test="level != null">
|
||||
`level`,
|
||||
</if>
|
||||
<if test="type != null">
|
||||
`type`,
|
||||
</if>
|
||||
<if test="createBy != null">
|
||||
create_by,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
#{id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
#{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
#{pid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="level != null">
|
||||
#{level,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="type != null">
|
||||
#{type,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createBy != null">
|
||||
#{createBy,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.dataease.base.domain.ChartGroupExample" resultType="java.lang.Long">
|
||||
select count(*) from chart_group
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</select>
|
||||
<update id="updateByExampleSelective" parameterType="map">
|
||||
update chart_group
|
||||
<set>
|
||||
<if test="record.id != null">
|
||||
id = #{record.id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.name != null">
|
||||
`name` = #{record.name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.pid != null">
|
||||
pid = #{record.pid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.level != null">
|
||||
`level` = #{record.level,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.type != null">
|
||||
`type` = #{record.type,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.createBy != null">
|
||||
create_by = #{record.createBy,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExample" parameterType="map">
|
||||
update chart_group
|
||||
set id = #{record.id,jdbcType=VARCHAR},
|
||||
`name` = #{record.name,jdbcType=VARCHAR},
|
||||
pid = #{record.pid,jdbcType=VARCHAR},
|
||||
`level` = #{record.level,jdbcType=INTEGER},
|
||||
`type` = #{record.type,jdbcType=VARCHAR},
|
||||
create_by = #{record.createBy,jdbcType=VARCHAR},
|
||||
create_time = #{record.createTime,jdbcType=BIGINT}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="io.dataease.base.domain.ChartGroup">
|
||||
update chart_group
|
||||
<set>
|
||||
<if test="name != null">
|
||||
`name` = #{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
pid = #{pid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="level != null">
|
||||
`level` = #{level,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="type != null">
|
||||
`type` = #{type,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createBy != null">
|
||||
create_by = #{createBy,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.ChartGroup">
|
||||
update chart_group
|
||||
set `name` = #{name,jdbcType=VARCHAR},
|
||||
pid = #{pid,jdbcType=VARCHAR},
|
||||
`level` = #{level,jdbcType=INTEGER},
|
||||
`type` = #{type,jdbcType=VARCHAR},
|
||||
create_by = #{createBy,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=BIGINT}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
@ -0,0 +1,26 @@
|
||||
package io.dataease.base.mapper.ext;
|
||||
|
||||
|
||||
|
||||
import io.dataease.auth.api.dto.CurrentRoleDto;
|
||||
import io.dataease.auth.entity.SysUserEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface AuthMapper {
|
||||
|
||||
|
||||
|
||||
List<String> roleCodes(@Param("userId") Long userId);
|
||||
|
||||
|
||||
|
||||
List<String> permissions(@Param("userId") Long userId);
|
||||
|
||||
|
||||
SysUserEntity findUser(@Param("username") String username);
|
||||
|
||||
|
||||
List<CurrentRoleDto> roles(@Param("userId") Long userId);
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="io.dataease.base.mapper.ext.AuthMapper">
|
||||
|
||||
<resultMap id="baseMap" type="io.dataease.auth.entity.SysUserEntity">
|
||||
<id column="user_id" property="userId"/>
|
||||
<result column="username" jdbcType="VARCHAR" property="username" />
|
||||
<result column="nick_name" jdbcType="VARCHAR" property="nickName" />
|
||||
<result column="dept_id" property="deptId" />
|
||||
<result column="password" jdbcType="VARCHAR" property="password" />
|
||||
<result column="email" jdbcType="VARCHAR" property="email" />
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone" />
|
||||
<result column="enabled" property="enabled" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="roleMap" type="io.dataease.auth.api.dto.CurrentRoleDto" >
|
||||
<id column="role_id" property="id"/>
|
||||
<result column="code" jdbcType="VARCHAR" property="code"/>
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="findUser" resultMap="baseMap">
|
||||
select user_id, username, password, enabled from sys_user where username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="roleCodes" >
|
||||
select r.code from sys_role r
|
||||
left join sys_users_roles sur on sur.role_id = r.role_id
|
||||
where sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="permissions" >
|
||||
select sm.permission
|
||||
from sys_menu sm
|
||||
left join sys_roles_menus srm on srm.menu_id = sm.menu_id
|
||||
left join sys_users_roles sur on sur.role_id = srm.role_id
|
||||
where sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="roles" resultMap="roleMap">
|
||||
select r.role_id, r.code, r.name
|
||||
from sys_role r
|
||||
left join sys_users_roles sur on sur.role_id = r.role_id
|
||||
where sur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
@ -2,7 +2,6 @@ package io.dataease.base.mapper.ext;
|
||||
|
||||
import io.dataease.base.domain.User;
|
||||
import io.dataease.controller.request.UserRequest;
|
||||
import io.dataease.notice.domain.UserDetail;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@ -19,8 +18,6 @@ public interface ExtUserMapper {
|
||||
|
||||
List<User> searchUser(String condition);
|
||||
|
||||
List<UserDetail> queryTypeByIds(List<String> userIds);
|
||||
|
||||
@MapKey("id")
|
||||
Map<String, User> queryNameByIds(List<String> userIds);
|
||||
}
|
||||
|
@ -16,18 +16,6 @@
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="queryTypeByIds" parameterType="java.lang.String" resultType="io.dataease.notice.domain.UserDetail">
|
||||
SELECT
|
||||
email,phone
|
||||
from user
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" index="index"
|
||||
open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getUserList" resultMap="BaseResultMap">
|
||||
select u.id, u.name, u.email, u.phone, u.language, u.status, u.source,
|
||||
u.last_organization_id, u.last_workspace_id, u.language, u.create_time, u.update_time
|
||||
|
@ -0,0 +1,6 @@
|
||||
package io.dataease.commons.constants;
|
||||
|
||||
public class AuthConstants {
|
||||
|
||||
public final static String TOKEN_KEY = "Authorization";
|
||||
}
|
@ -31,7 +31,6 @@ public interface ParamConstants {
|
||||
MAIL("smtp"),
|
||||
BASE("base"),
|
||||
LDAP("ldap"),
|
||||
UI("ui"),
|
||||
REGISTRY("registry");
|
||||
|
||||
private String value;
|
||||
|
@ -2,7 +2,7 @@ package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ServletUtils {
|
||||
|
||||
public static HttpServletRequest request(){
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
return request;
|
||||
}
|
||||
|
||||
public static HttpServletResponse response(){
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletResponse response = servletRequestAttributes.getResponse();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public static void setToken(String token){
|
||||
HttpServletResponse httpServletResponse = response();
|
||||
httpServletResponse.addHeader("Access-Control-Expose-Headers", "Authorization");
|
||||
httpServletResponse.setHeader(AuthConstants.TOKEN_KEY, token);
|
||||
}
|
||||
|
||||
public static String getToken(){
|
||||
HttpServletRequest request = request();
|
||||
String token = request.getHeader(AuthConstants.TOKEN_KEY);
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.session.mgt.DefaultSessionManager;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.subject.support.DefaultSubjectContext;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static io.dataease.commons.constants.SessionConstants.ATTR_USER;
|
||||
|
||||
public class SessionUtils {
|
||||
|
||||
public static String getUserId() {
|
||||
return Objects.requireNonNull(getUser()).getId();
|
||||
}
|
||||
|
||||
public static SessionUser getUser() {
|
||||
try {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
Session session = subject.getSession();
|
||||
SessionUser user = (SessionUser) session.getAttribute(ATTR_USER);
|
||||
assert user != null;
|
||||
return user;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Session getSessionByUsername(String username) {
|
||||
DefaultSessionManager sessionManager = CommonBeanFactory.getBean(DefaultSessionManager.class);
|
||||
Collection<Session> sessions = sessionManager.getSessionDAO().getActiveSessions();
|
||||
for (Session session : sessions) {
|
||||
if (null != session && StringUtils.equals(String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)), username)) {
|
||||
return session;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 踢除用户
|
||||
*
|
||||
* @param username
|
||||
*/
|
||||
public static void kickOutUser(String username) {
|
||||
Session session = getSessionByUsername(username);
|
||||
if (session != null) {
|
||||
DefaultSessionManager sessionManager = CommonBeanFactory.getBean(DefaultSessionManager.class);
|
||||
sessionManager.getSessionDAO().delete(session);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public static void putUser(SessionUser sessionUser) {
|
||||
SecurityUtils.getSubject().getSession().setAttribute(ATTR_USER, sessionUser);
|
||||
}
|
||||
|
||||
public static String getCurrentWorkspaceId() {
|
||||
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastWorkspaceId();
|
||||
}
|
||||
|
||||
public static String getCurrentOrganizationId() {
|
||||
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastOrganizationId();
|
||||
}
|
||||
|
||||
public static String getCurrentProjectId() {
|
||||
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastProjectId();
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import org.apache.shiro.cache.CacheManager;
|
||||
import org.apache.shiro.session.mgt.SessionManager;
|
||||
import org.apache.shiro.web.servlet.Cookie;
|
||||
import org.apache.shiro.web.servlet.SimpleCookie;
|
||||
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ShiroUtils {
|
||||
|
||||
public static void loadBaseFilterChain(Map<String, String> filterChainDefinitionMap){
|
||||
|
||||
filterChainDefinitionMap.put("/resource/**", "anon");
|
||||
filterChainDefinitionMap.put("/signin", "anon");
|
||||
filterChainDefinitionMap.put("/ldap/signin", "anon");
|
||||
filterChainDefinitionMap.put("/ldap/open", "anon");
|
||||
filterChainDefinitionMap.put("/isLogin", "anon");
|
||||
filterChainDefinitionMap.put("/css/**", "anon");
|
||||
filterChainDefinitionMap.put("/js/**", "anon");
|
||||
filterChainDefinitionMap.put("/img/**", "anon");
|
||||
filterChainDefinitionMap.put("/fonts/**", "anon");
|
||||
filterChainDefinitionMap.put("/display/info", "anon");
|
||||
filterChainDefinitionMap.put("/favicon.ico", "anon");
|
||||
filterChainDefinitionMap.put("/display/file/**", "anon");
|
||||
filterChainDefinitionMap.put("/jmeter/download/**", "anon");
|
||||
filterChainDefinitionMap.put("/authsource/list/allenable", "anon");
|
||||
filterChainDefinitionMap.put("/sso/signin", "anon");
|
||||
filterChainDefinitionMap.put("/sso/callback", "anon");
|
||||
filterChainDefinitionMap.put("/license/valid", "anon");
|
||||
|
||||
// for swagger
|
||||
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
|
||||
filterChainDefinitionMap.put("/swagger-ui/**", "anon");
|
||||
filterChainDefinitionMap.put("/v3/api-docs/**", "anon");
|
||||
|
||||
filterChainDefinitionMap.put("/403", "anon");
|
||||
filterChainDefinitionMap.put("/anonymous/**", "anon");
|
||||
}
|
||||
|
||||
public static Cookie getSessionIdCookie(){
|
||||
SimpleCookie sessionIdCookie = new SimpleCookie();
|
||||
sessionIdCookie.setPath("/");
|
||||
sessionIdCookie.setName("MS_SESSION_ID");
|
||||
return sessionIdCookie;
|
||||
}
|
||||
|
||||
public static SessionManager getSessionManager(Long sessionTimeout, CacheManager cacheManager){
|
||||
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
|
||||
sessionManager.setSessionIdUrlRewritingEnabled(false);
|
||||
sessionManager.setDeleteInvalidSessions(true);
|
||||
sessionManager.setSessionValidationSchedulerEnabled(true);
|
||||
sessionManager.setSessionIdCookie(ShiroUtils.getSessionIdCookie());
|
||||
sessionManager.setGlobalSessionTimeout(sessionTimeout * 1000);// 超时时间ms
|
||||
sessionManager.setCacheManager(cacheManager);
|
||||
|
||||
//sessionManager.setSessionIdCookieEnabled(true);
|
||||
return sessionManager;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class XMLUtils {
|
||||
|
||||
private static void jsonToXmlStr(JSONObject jObj, StringBuffer buffer) {
|
||||
Set<Map.Entry<String, Object>> se = jObj.entrySet();
|
||||
for (Map.Entry<String, Object> en : se) {
|
||||
if ("com.alibaba.fastjson.JSONObject".equals(en.getValue().getClass().getName())) {
|
||||
buffer.append("<").append(en.getKey()).append(">");
|
||||
JSONObject jo = jObj.getJSONObject(en.getKey());
|
||||
jsonToXmlStr(jo, buffer);
|
||||
buffer.append("</").append(en.getKey()).append(">");
|
||||
} else if ("com.alibaba.fastjson.JSONArray".equals(en.getValue().getClass().getName())) {
|
||||
JSONArray jarray = jObj.getJSONArray(en.getKey());
|
||||
for (int i = 0; i < jarray.size(); i++) {
|
||||
buffer.append("<").append(en.getKey()).append(">");
|
||||
if (StringUtils.isNotBlank(jarray.getString(i))) {
|
||||
JSONObject jsonobject = jarray.getJSONObject(i);
|
||||
jsonToXmlStr(jsonobject, buffer);
|
||||
buffer.append("</").append(en.getKey()).append(">");
|
||||
}
|
||||
}
|
||||
} else if ("java.lang.String".equals(en.getValue().getClass().getName())) {
|
||||
buffer.append("<").append(en.getKey()).append(">").append(en.getValue());
|
||||
buffer.append("</").append(en.getKey()).append(">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String jsonToXmlStr(JSONObject jObj) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
try {
|
||||
jsonToXmlStr(jObj, buffer);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
package io.dataease.config;
|
||||
|
||||
import io.dataease.commons.utils.ShiroUtils;
|
||||
import io.dataease.security.ApiKeyFilter;
|
||||
import io.dataease.security.UserModularRealmAuthenticator;
|
||||
import io.dataease.security.realm.LdapRealm;
|
||||
import io.dataease.security.realm.ShiroDBRealm;
|
||||
import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
|
||||
import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
|
||||
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
|
||||
import org.apache.shiro.realm.Realm;
|
||||
import org.apache.shiro.session.mgt.SessionManager;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import java.util.*;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "sso", name = "mode", havingValue = "local", matchIfMissing = true)
|
||||
public class ShiroConfig implements EnvironmentAware {
|
||||
private Environment env;
|
||||
|
||||
@Bean
|
||||
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager sessionManager) {
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||
shiroFilterFactoryBean.setLoginUrl("/login");
|
||||
shiroFilterFactoryBean.setSecurityManager(sessionManager);
|
||||
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
|
||||
shiroFilterFactoryBean.setSuccessUrl("/");
|
||||
|
||||
shiroFilterFactoryBean.getFilters().put("apikey", new ApiKeyFilter());
|
||||
Map<String, String> filterChainDefinitionMap = shiroFilterFactoryBean.getFilterChainDefinitionMap();
|
||||
ShiroUtils.loadBaseFilterChain(filterChainDefinitionMap);
|
||||
|
||||
filterChainDefinitionMap.put("/**", "apikey, authc");
|
||||
return shiroFilterFactoryBean;
|
||||
}
|
||||
|
||||
@Bean(name = "shiroFilter")
|
||||
public FilterRegistrationBean<Filter> shiroFilter(ShiroFilterFactoryBean shiroFilterFactoryBean) throws Exception {
|
||||
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter((Filter) Objects.requireNonNull(shiroFilterFactoryBean.getObject()));
|
||||
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MemoryConstrainedCacheManager memoryConstrainedCacheManager() {
|
||||
return new MemoryConstrainedCacheManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* securityManager 不用直接注入shiroDBRealm,可能会导致事务失效
|
||||
* 解决方法见 handleContextRefresh
|
||||
* http://www.debugrun.com/a/NKS9EJQ.html
|
||||
*/
|
||||
@Bean(name = "securityManager")
|
||||
public DefaultWebSecurityManager securityManager(SessionManager sessionManager, MemoryConstrainedCacheManager memoryConstrainedCacheManager) {
|
||||
DefaultWebSecurityManager dwsm = new DefaultWebSecurityManager();
|
||||
dwsm.setSessionManager(sessionManager);
|
||||
dwsm.setCacheManager(memoryConstrainedCacheManager);
|
||||
dwsm.setAuthenticator(modularRealmAuthenticator());
|
||||
return dwsm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("lifecycleBeanPostProcessor")
|
||||
public ShiroDBRealm shiroDBRealm() {
|
||||
return new ShiroDBRealm();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("lifecycleBeanPostProcessor")
|
||||
public LdapRealm ldapRealm() {
|
||||
return new LdapRealm();
|
||||
}
|
||||
|
||||
@Bean(name = "lifecycleBeanPostProcessor")
|
||||
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
|
||||
DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
|
||||
daap.setProxyTargetClass(true);
|
||||
return daap;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ModularRealmAuthenticator modularRealmAuthenticator() {
|
||||
//自己重写的ModularRealmAuthenticator
|
||||
UserModularRealmAuthenticator modularRealmAuthenticator = new UserModularRealmAuthenticator();
|
||||
modularRealmAuthenticator.setAuthenticationStrategy(new FirstSuccessfulStrategy());
|
||||
return modularRealmAuthenticator;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor(DefaultWebSecurityManager sessionManager) {
|
||||
AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor();
|
||||
aasa.setSecurityManager(sessionManager);
|
||||
return new AuthorizationAttributeSourceAdvisor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SessionManager sessionManager(MemoryConstrainedCacheManager memoryConstrainedCacheManager) {
|
||||
Long sessionTimeout = env.getProperty("session.timeout", Long.class, 43200L); // 默认43200s, 12个小时
|
||||
return ShiroUtils.getSessionManager(sessionTimeout, memoryConstrainedCacheManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等到ApplicationContext 加载完成之后 装配shiroRealm
|
||||
*/
|
||||
@EventListener
|
||||
public void handleContextRefresh(ContextRefreshedEvent event) {
|
||||
ApplicationContext context = event.getApplicationContext();
|
||||
List<Realm> realmList = new ArrayList<>();
|
||||
ShiroDBRealm shiroDBRealm = context.getBean(ShiroDBRealm.class);
|
||||
LdapRealm ldapRealm = context.getBean(LdapRealm.class);
|
||||
// 基本realm
|
||||
realmList.add(shiroDBRealm);
|
||||
realmList.add(ldapRealm);
|
||||
context.getBean(DefaultWebSecurityManager.class).setRealms(realmList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.env = environment;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package io.dataease.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplateWithTimeOut() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||
httpRequestFactory.setConnectionRequestTimeout(4000);
|
||||
httpRequestFactory.setConnectTimeout(4000);
|
||||
httpRequestFactory.setReadTimeout(10 * 1000);
|
||||
restTemplate.setRequestFactory(httpRequestFactory);
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.i18n.Lang;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -28,8 +27,8 @@ public class I18nController {
|
||||
@Value("${run.mode:release}")
|
||||
private String runMode;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
// @Resource
|
||||
// private UserService userService;
|
||||
|
||||
@GetMapping("lang/change/{lang}")
|
||||
public void changeLang(@PathVariable String lang, HttpServletRequest request, HttpServletResponse response) {
|
||||
@ -39,7 +38,7 @@ public class I18nController {
|
||||
LogUtil.error("Invalid parameter: " + lang);
|
||||
DEException.throwException(Translator.get("error_lang_invalid"));
|
||||
}
|
||||
userService.setLanguage(targetLang.getDesc());
|
||||
// userService.setLanguage(targetLang.getDesc());
|
||||
Cookie cookie = new Cookie(I18nConstants.LANG_COOKIE_NAME, targetLang.getDesc());
|
||||
cookie.setPath("/");
|
||||
cookie.setMaxAge(FOR_EVER);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -16,7 +15,8 @@ public class IndexController {
|
||||
|
||||
@GetMapping(value = "/login")
|
||||
public String login() {
|
||||
if (SessionUtils.getUser() == null) {
|
||||
// if (SessionUtils.getUser() == null) {
|
||||
if (null == null) {
|
||||
return "login.html";
|
||||
} else {
|
||||
return "redirect:/";
|
||||
|
@ -1,75 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.commons.constants.SsoMode;
|
||||
import io.dataease.commons.constants.UserSource;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.request.LoginRequest;
|
||||
import io.dataease.service.BaseDisplayService;
|
||||
import io.dataease.service.UserService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class LoginController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private Environment env;
|
||||
@Resource
|
||||
private BaseDisplayService baseDisplayService;
|
||||
|
||||
@GetMapping(value = "/isLogin")
|
||||
public ResultHolder isLogin() {
|
||||
if (SecurityUtils.getSubject().isAuthenticated()) {
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
if (StringUtils.isBlank(user.getLanguage())) {
|
||||
user.setLanguage(LocaleContextHolder.getLocale().toString());
|
||||
}
|
||||
return ResultHolder.success(user);
|
||||
}
|
||||
String ssoMode = env.getProperty("sso.mode");
|
||||
if (ssoMode != null && StringUtils.equalsIgnoreCase(SsoMode.CAS.name(), ssoMode)) {
|
||||
return ResultHolder.error("sso");
|
||||
}
|
||||
return ResultHolder.error("");
|
||||
}
|
||||
|
||||
@PostMapping(value = "/signin")
|
||||
public ResultHolder login(@RequestBody LoginRequest request) {
|
||||
SecurityUtils.getSubject().getSession().setAttribute("authenticate", UserSource.LOCAL.name());
|
||||
return userService.login(request);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/currentUser")
|
||||
public ResultHolder currentUser() {
|
||||
return ResultHolder.success(SecurityUtils.getSubject().getSession().getAttribute("user"));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/signout")
|
||||
public ResultHolder logout() throws Exception {
|
||||
userService.logout();
|
||||
SecurityUtils.getSubject().logout();
|
||||
return ResultHolder.success("");
|
||||
}
|
||||
|
||||
/*Get default language*/
|
||||
@GetMapping(value = "/language")
|
||||
public String getDefaultLanguage() {
|
||||
return userService.getDefaultLanguage();
|
||||
}
|
||||
|
||||
@GetMapping("display/file/{imageName}")
|
||||
public ResponseEntity<byte[]> image(@PathVariable("imageName") String imageName) throws IOException {
|
||||
return baseDisplayService.getImage(imageName);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.dataease.base.domain.Organization;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.controller.request.OrganizationRequest;
|
||||
import io.dataease.dto.OrganizationMemberDTO;
|
||||
import io.dataease.service.OrganizationService;
|
||||
import io.dataease.service.UserService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("organization")
|
||||
@RestController
|
||||
public class OrganizationController {
|
||||
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public Organization addOrganization(@RequestBody Organization organization) {
|
||||
return organizationService.addOrganization(organization);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public List<Organization> getOrganizationList() {
|
||||
return organizationService.getOrganizationList(new OrganizationRequest());
|
||||
}
|
||||
|
||||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public Pager<List<Organization>> getOrganizationList(@RequestBody OrganizationRequest request, @PathVariable int goPage, @PathVariable int pageSize) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, organizationService.getOrganizationList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{organizationId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void deleteOrganization(@PathVariable(value = "organizationId") String organizationId) {
|
||||
userService.refreshSessionUser("organization", organizationId);
|
||||
organizationService.deleteOrganization(organizationId);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public void updateOrganization(@RequestBody Organization organization) {
|
||||
organizationService.updateOrganization(organization);
|
||||
}
|
||||
|
||||
@GetMapping("/list/userorg/{userId}")
|
||||
public List<Organization> getOrganizationListByUserId(@PathVariable String userId) {
|
||||
return organizationService.getOrganizationListByUserId(userId);
|
||||
}
|
||||
|
||||
@PostMapping("/member/update")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public void updateOrgMember(@RequestBody OrganizationMemberDTO memberDTO) {
|
||||
organizationService.updateOrgMember(memberDTO);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.base.domain.Role;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.service.RoleService;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
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;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("role")
|
||||
@RestController
|
||||
public class RoleController {
|
||||
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@GetMapping("/list/{sign}")
|
||||
public List<Role> getRoleList(@PathVariable String sign) {
|
||||
return roleService.getRoleList(sign);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public List<Role> getAllRole() {
|
||||
return roleService.getAllRole();
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.base.domain.ServiceIntegration;
|
||||
import io.dataease.controller.request.IntegrationRequest;
|
||||
import io.dataease.service.IntegrationService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("service/integration")
|
||||
@RestController
|
||||
public class ServiceIntegrationController {
|
||||
|
||||
@Resource
|
||||
private IntegrationService integrationService;
|
||||
|
||||
@PostMapping("/save")
|
||||
public ServiceIntegration save(@RequestBody ServiceIntegration service) {
|
||||
return integrationService.save(service);
|
||||
}
|
||||
|
||||
@PostMapping("/type")
|
||||
public ServiceIntegration getByPlatform(@RequestBody IntegrationRequest request) {
|
||||
return integrationService.get(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public void delete(@RequestBody IntegrationRequest request) {
|
||||
integrationService.delete(request);
|
||||
}
|
||||
|
||||
@GetMapping("/all/{orgId}")
|
||||
public List<ServiceIntegration> getAll(@PathVariable String orgId) {
|
||||
return integrationService.getAll(orgId);
|
||||
}
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.base.domain.SystemParameter;
|
||||
import io.dataease.commons.constants.ParamConstants;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.dto.BaseSystemConfigDTO;
|
||||
import io.dataease.dto.SystemParameterDTO;
|
||||
import io.dataease.notice.domain.MailInfo;
|
||||
import io.dataease.service.system.SystemParameterService;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/system")
|
||||
public class SystemParameterController {
|
||||
@Resource
|
||||
private SystemParameterService systemParameterService;
|
||||
|
||||
@PostMapping("/edit/email")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN})
|
||||
public void editMail(@RequestBody List<SystemParameter> systemParameter) {
|
||||
systemParameterService.editMail(systemParameter);
|
||||
}
|
||||
|
||||
@PostMapping("/testConnection")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN})
|
||||
public void testConnection(@RequestBody HashMap<String, String> hashMap) {
|
||||
systemParameterService.testConnection(hashMap);
|
||||
}
|
||||
|
||||
@GetMapping("/version")
|
||||
public String getVersion() {
|
||||
return systemParameterService.getVersion();
|
||||
}
|
||||
|
||||
@GetMapping("/mail/info")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN})
|
||||
public MailInfo mailInfo() {
|
||||
return systemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/base/info")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN})
|
||||
public List<SystemParameterDTO> getBaseInfo () {
|
||||
return systemParameterService.getSystemParameterInfo(ParamConstants.Classify.BASE.getValue());
|
||||
}
|
||||
|
||||
@GetMapping("/ui/info")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN})
|
||||
public List<SystemParameterDTO> getDisplayInfo () {
|
||||
return systemParameterService.getSystemParameterInfo(ParamConstants.Classify.UI.getValue());
|
||||
}
|
||||
|
||||
@PostMapping(value="/save/ui", consumes = {"multipart/form-data"})
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN})
|
||||
public void saveUIInfo (@RequestPart("request") Map<String,List<SystemParameterDTO>> systemParameterMap,@RequestPart(value = "files") List<MultipartFile> bodyFiles) throws IOException {
|
||||
systemParameterService.saveUIInfo(systemParameterMap,bodyFiles);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.dataease.base.domain.User;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.handler.annotation.NoResultHolder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/test")
|
||||
public class TestController {
|
||||
|
||||
|
||||
@PostMapping(value = "/upload", consumes = {"multipart/form-data"})
|
||||
public Object testUpload(@RequestPart(value = "id") String id, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles
|
||||
, @RequestPart(value = "user") User user, @RequestParam(value = "name") String name) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", id);
|
||||
jsonObject.put("file", file.getOriginalFilename());
|
||||
jsonObject.put("files", bodyFiles.stream().map(MultipartFile::getOriginalFilename).collect(Collectors.toList()));
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/multipart", consumes = {"multipart/form-data"})
|
||||
public Object testMultipart(@RequestPart(value = "id") String id, @RequestPart(value = "user") User user, @RequestParam(value = "name") String name) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", id);
|
||||
jsonObject.put("user", user.getName());
|
||||
jsonObject.put("name", name);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/wwwform", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public Object testWwwForm(String id, User user, String name) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("id", id);
|
||||
jsonObject.put("user", user.getName());
|
||||
jsonObject.put("name", name);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@NoResultHolder
|
||||
@GetMapping(value = "/xml")
|
||||
public String getXmlString() {
|
||||
return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
|
||||
"\n" +
|
||||
"<bookstore>\n" +
|
||||
"\n" +
|
||||
"<book>\n" +
|
||||
" <title lang=\"eng\">Harry Potter</title>\n" +
|
||||
" <price>29.99</price>\n" +
|
||||
"</book>\n" +
|
||||
"\n" +
|
||||
"<book>\n" +
|
||||
" <title lang=\"eng\">Learning XML</title>\n" +
|
||||
" <price>39.95</price>\n" +
|
||||
"</book>\n" +
|
||||
"\n" +
|
||||
"</bookstore>";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{str}")
|
||||
public Object getString(@PathVariable String str) throws InterruptedException {
|
||||
if (StringUtils.equals("error", str)) {
|
||||
throw new RuntimeException("test error");
|
||||
}
|
||||
if (StringUtils.equals("warning", str)) {
|
||||
return ResultHolder.error("test warning");
|
||||
}
|
||||
if (StringUtils.equals("user", str)) {
|
||||
return ResultHolder.success(SessionUtils.getUser());
|
||||
}
|
||||
if (StringUtils.equals("sleep", str)) {
|
||||
Thread.sleep(2000L);
|
||||
return ResultHolder.success(str);
|
||||
}
|
||||
return ResultHolder.success(str);
|
||||
}
|
||||
|
||||
}
|
@ -1,301 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.dataease.base.domain.User;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.request.member.AddMemberRequest;
|
||||
import io.dataease.controller.request.member.EditPassWordRequest;
|
||||
import io.dataease.controller.request.member.QueryMemberRequest;
|
||||
import io.dataease.controller.request.member.UserRequest;
|
||||
import io.dataease.controller.request.organization.AddOrgMemberRequest;
|
||||
import io.dataease.controller.request.organization.QueryOrgMemberRequest;
|
||||
import io.dataease.dto.UserDTO;
|
||||
import io.dataease.dto.UserRoleDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.OrganizationService;
|
||||
import io.dataease.service.UserService;
|
||||
import io.dataease.service.WorkspaceService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("user")
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
|
||||
@PostMapping("/special/add")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public UserDTO insertUser(@RequestBody UserRequest user) {
|
||||
return userService.insert(user);
|
||||
}
|
||||
|
||||
@PostMapping("/special/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public Pager<List<User>> getUserList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody io.dataease.controller.request.UserRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getUserListWithRequest(request));
|
||||
}
|
||||
|
||||
@GetMapping("/special/user/role/{userId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public UserRoleDTO getUserRole(@PathVariable("userId") String userId) {
|
||||
return userService.getUserRole(userId);
|
||||
}
|
||||
|
||||
@GetMapping("/special/delete/{userId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void deleteUser(@PathVariable(value = "userId") String userId) {
|
||||
userService.deleteUser(userId);
|
||||
// 踢掉在线用户
|
||||
SessionUtils.kickOutUser(userId);
|
||||
}
|
||||
|
||||
@PostMapping("/special/update")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void updateUser(@RequestBody UserRequest user) {
|
||||
userService.updateUserRole(user);
|
||||
}
|
||||
|
||||
@PostMapping("/special/update_status")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void updateStatus(@RequestBody User user) {
|
||||
userService.updateUser(user);
|
||||
}
|
||||
|
||||
@PostMapping("/special/ws/member/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public Pager<List<User>> getMemberListByAdmin(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getMemberList(request));
|
||||
}
|
||||
|
||||
@PostMapping("/special/ws/member/list/all")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public List<User> getMemberListByAdmin(@RequestBody QueryMemberRequest request) {
|
||||
return userService.getMemberList(request);
|
||||
}
|
||||
|
||||
@PostMapping("/special/ws/member/add")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void addMemberByAdmin(@RequestBody AddMemberRequest request) {
|
||||
userService.addMember(request);
|
||||
}
|
||||
|
||||
@GetMapping("/special/ws/member/delete/{workspaceId}/{userId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void deleteMemberByAdmin(@PathVariable String workspaceId, @PathVariable String userId) {
|
||||
userService.deleteMember(workspaceId, userId);
|
||||
}
|
||||
|
||||
@PostMapping("/special/org/member/add")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void addOrganizationMemberByAdmin(@RequestBody AddOrgMemberRequest request) {
|
||||
userService.addOrganizationMember(request);
|
||||
}
|
||||
|
||||
@GetMapping("/special/org/member/delete/{organizationId}/{userId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void delOrganizationMemberByAdmin(@PathVariable String organizationId, @PathVariable String userId) {
|
||||
userService.delOrganizationMember(organizationId, userId);
|
||||
}
|
||||
|
||||
@PostMapping("/special/org/member/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public Pager<List<User>> getOrgMemberListByAdmin(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getOrgMemberList(request));
|
||||
}
|
||||
|
||||
@PostMapping("/special/org/member/list/all")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public List<User> getOrgMemberListByAdmin(@RequestBody QueryOrgMemberRequest request) {
|
||||
return userService.getOrgMemberList(request);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public List<User> getUserList() {
|
||||
return userService.getUserList();
|
||||
}
|
||||
|
||||
@PostMapping("/update/current")
|
||||
public UserDTO updateCurrentUser(@RequestBody User user) {
|
||||
String currentUserId = SessionUtils.getUserId();
|
||||
if (!StringUtils.equals(currentUserId, user.getId())) {
|
||||
DEException.throwException(Translator.get("not_authorized"));
|
||||
}
|
||||
userService.updateUser(user);
|
||||
UserDTO userDTO = userService.getUserDTO(user.getId());
|
||||
SessionUtils.putUser(SessionUser.fromUser(userDTO));
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@PostMapping("/switch/source/org/{sourceId}")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER, RoleConstants.TEST_VIEWER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
|
||||
userService.switchUserRole("organization", sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@PostMapping("/switch/source/ws/{sourceId}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_VIEWER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
|
||||
userService.switchUserRole("workspace", sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@PostMapping("/refresh/{sign}/{sourceId}")
|
||||
public UserDTO refreshSessionUser(@PathVariable String sign, @PathVariable String sourceId) {
|
||||
userService.refreshSessionUser(sign, sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@GetMapping("/info/{userId}")
|
||||
public UserDTO getUserInfo(@PathVariable(value = "userId") String userId) {
|
||||
if (!StringUtils.equals(userId, SessionUtils.getUserId())) {
|
||||
DEException.throwException(Translator.get("not_authorized"));
|
||||
}
|
||||
return userService.getUserInfo(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工作空间成员用户
|
||||
*/
|
||||
@PostMapping("/ws/member/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getMemberList(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工作空间成员用户 不分页
|
||||
*/
|
||||
@PostMapping("/ws/member/list/all")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public List<User> getMemberList(@RequestBody QueryMemberRequest request) {
|
||||
return userService.getMemberList(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加工作空间成员
|
||||
*/
|
||||
@PostMapping("/ws/member/add")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public void addMember(@RequestBody AddMemberRequest request) {
|
||||
String wsId = request.getWorkspaceId();
|
||||
workspaceService.checkWorkspaceOwner(wsId);
|
||||
userService.addMember(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除工作空间成员
|
||||
*/
|
||||
@GetMapping("/ws/member/delete/{workspaceId}/{userId}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
|
||||
workspaceService.checkWorkspaceOwner(workspaceId);
|
||||
String currentUserId = SessionUtils.getUser().getId();
|
||||
if (StringUtils.equals(userId, currentUserId)) {
|
||||
DEException.throwException(Translator.get("cannot_remove_current"));
|
||||
}
|
||||
userService.deleteMember(workspaceId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加组织成员
|
||||
*/
|
||||
@PostMapping("/org/member/add")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public void addOrganizationMember(@RequestBody AddOrgMemberRequest request) {
|
||||
organizationService.checkOrgOwner(request.getOrganizationId());
|
||||
userService.addOrganizationMember(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除组织成员
|
||||
*/
|
||||
@GetMapping("/org/member/delete/{organizationId}/{userId}")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public void delOrganizationMember(@PathVariable String organizationId, @PathVariable String userId) {
|
||||
organizationService.checkOrgOwner(organizationId);
|
||||
String currentUserId = SessionUtils.getUser().getId();
|
||||
if (StringUtils.equals(userId, currentUserId)) {
|
||||
DEException.throwException(Translator.get("cannot_remove_current"));
|
||||
}
|
||||
userService.delOrganizationMember(organizationId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询组织成员列表
|
||||
*/
|
||||
@PostMapping("/org/member/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public Pager<List<User>> getOrgMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getOrgMemberList(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 组织成员列表不分页
|
||||
*/
|
||||
@PostMapping("/org/member/list/all")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public List<User> getOrgMemberList(@RequestBody QueryOrgMemberRequest request) {
|
||||
return userService.getOrgMemberList(request);
|
||||
}
|
||||
|
||||
@GetMapping("/besideorg/list/{orgId}")
|
||||
public List<User> getBesideOrgMemberList(@PathVariable String orgId) {
|
||||
return userService.getBesideOrgMemberList(orgId);
|
||||
}
|
||||
|
||||
/*
|
||||
* 修改当前用户密码
|
||||
* */
|
||||
@PostMapping("/update/password")
|
||||
public int updateCurrentUserPassword(@RequestBody EditPassWordRequest request) {
|
||||
return userService.updateCurrentUserPassword(request);
|
||||
}
|
||||
|
||||
/*管理员修改用户密码*/
|
||||
@PostMapping("/special/password")
|
||||
public int updateUserPassword(@RequestBody EditPassWordRequest request) {
|
||||
return userService.updateUserPassword(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取工作空间成员用户 不分页
|
||||
*/
|
||||
@PostMapping("/ws/member/tester/list")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public List<User> getTestManagerAndTestUserList(@RequestBody QueryMemberRequest request) {
|
||||
return userService.getTestManagerAndTestUserList(request);
|
||||
}
|
||||
|
||||
@GetMapping("/search/{condition}")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public List<User> searchUser(@PathVariable String condition) {
|
||||
return userService.searchUser(condition);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.base.domain.UserKey;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.security.ApiKeyHandler;
|
||||
import io.dataease.service.UserKeyService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.apache.shiro.web.util.WebUtils;
|
||||
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;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user/key")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public class UserKeysController {
|
||||
|
||||
@Resource
|
||||
private UserKeyService userKeyService;
|
||||
|
||||
@GetMapping("info")
|
||||
public List<UserKey> getUserKeysInfo() {
|
||||
String userId = SessionUtils.getUser().getId();
|
||||
return userKeyService.getUserKeysInfo(userId);
|
||||
}
|
||||
|
||||
@GetMapping("validate")
|
||||
public String validate(ServletRequest request) {
|
||||
return ApiKeyHandler.getUser(WebUtils.toHttp(request));
|
||||
}
|
||||
|
||||
@GetMapping("generate")
|
||||
public void generateUserKey() {
|
||||
String userId = SessionUtils.getUser().getId();
|
||||
userKeyService.generateUserKey(userId);
|
||||
}
|
||||
|
||||
@GetMapping("delete/{id}")
|
||||
public void deleteUserKey(@PathVariable String id) {
|
||||
userKeyService.deleteUserKey(id);
|
||||
}
|
||||
|
||||
@GetMapping("active/{id}")
|
||||
public void activeUserKey(@PathVariable String id) {
|
||||
userKeyService.activeUserKey(id);
|
||||
}
|
||||
|
||||
@GetMapping("disable/{id}")
|
||||
public void disabledUserKey(@PathVariable String id) {
|
||||
userKeyService.disableUserKey(id);
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import io.dataease.base.domain.Role;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.service.UserRoleService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
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;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequestMapping("userrole")
|
||||
@RestController
|
||||
public class UserRoleController {
|
||||
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@GetMapping("/list/org/{orgId}/{userId}")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public List<Role> getOrganizationMemberRoles(@PathVariable String orgId, @PathVariable String userId) {
|
||||
return userRoleService.getOrganizationMemberRoles(orgId, userId);
|
||||
}
|
||||
|
||||
@GetMapping("/list/ws/{workspaceId}/{userId}")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public List<Role> getWorkspaceMemberRoles(@PathVariable String workspaceId, @PathVariable String userId) {
|
||||
return userRoleService.getWorkspaceMemberRoles(workspaceId, userId);
|
||||
}
|
||||
|
||||
@GetMapping("/all/{userId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public List<Map<String, Object>> getUserRole(@PathVariable("userId") String userId) {
|
||||
return userRoleService.getUserRole(userId);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package io.dataease.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.dataease.base.domain.Workspace;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.request.WorkspaceRequest;
|
||||
import io.dataease.dto.WorkspaceDTO;
|
||||
import io.dataease.dto.WorkspaceMemberDTO;
|
||||
import io.dataease.service.OrganizationService;
|
||||
import io.dataease.service.UserService;
|
||||
import io.dataease.service.WorkspaceService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("workspace")
|
||||
@RestController
|
||||
public class WorkspaceController {
|
||||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("add")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public Workspace addWorkspace(@RequestBody Workspace workspace) {
|
||||
String currentOrganizationId = SessionUtils.getCurrentOrganizationId();
|
||||
organizationService.checkOrgOwner(currentOrganizationId);
|
||||
return workspaceService.saveWorkspace(workspace);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public List<Workspace> getWorkspaceList() {
|
||||
return workspaceService.getWorkspaceList(new WorkspaceRequest());
|
||||
}
|
||||
|
||||
@PostMapping("special/add")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public Workspace addWorkspaceByAdmin(@RequestBody Workspace workspace) {
|
||||
return workspaceService.addWorkspaceByAdmin(workspace);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public Workspace updateWorkspace(@RequestBody Workspace workspace) {
|
||||
workspaceService.checkWorkspaceOwnerByOrgAdmin(workspace.getId());
|
||||
return workspaceService.saveWorkspace(workspace);
|
||||
}
|
||||
|
||||
@PostMapping("special/update")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void updateWorkspaceByAdmin(@RequestBody Workspace workspace) {
|
||||
workspaceService.updateWorkspaceByAdmin(workspace);
|
||||
}
|
||||
|
||||
@GetMapping("special/delete/{workspaceId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void deleteWorkspaceByAdmin(@PathVariable String workspaceId) {
|
||||
userService.refreshSessionUser("workspace", workspaceId);
|
||||
workspaceService.deleteWorkspace(workspaceId);
|
||||
}
|
||||
|
||||
@GetMapping("delete/{workspaceId}")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public void deleteWorkspace(@PathVariable String workspaceId) {
|
||||
workspaceService.checkWorkspaceOwnerByOrgAdmin(workspaceId);
|
||||
userService.refreshSessionUser("workspace", workspaceId);
|
||||
workspaceService.deleteWorkspace(workspaceId);
|
||||
}
|
||||
|
||||
@PostMapping("list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public Pager<List<Workspace>> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) {
|
||||
request.setOrganizationId(SessionUtils.getCurrentOrganizationId());
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList(request));
|
||||
}
|
||||
|
||||
@PostMapping("list/all/{goPage}/{pageSize}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public Pager<List<WorkspaceDTO>> getAllWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, workspaceService.getAllWorkspaceList(request));
|
||||
}
|
||||
|
||||
@GetMapping("/list/userworkspace/{userId}")
|
||||
public List<Workspace> getWorkspaceListByUserId(@PathVariable String userId) {
|
||||
return workspaceService.getWorkspaceListByUserId(userId);
|
||||
}
|
||||
|
||||
@GetMapping("/list/orgworkspace/")
|
||||
public List<Workspace> getWorkspaceListByOrgIdAndUserId() {
|
||||
String currentOrganizationId = SessionUtils.getCurrentOrganizationId();
|
||||
return workspaceService.getWorkspaceListByOrgIdAndUserId(currentOrganizationId);
|
||||
}
|
||||
|
||||
@PostMapping("/member/update")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public void updateOrgMember(@RequestBody WorkspaceMemberDTO memberDTO) {
|
||||
workspaceService.updateWorkspaceMember(memberDTO);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package io.dataease.controller.chart;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.dataease.base.domain.DatasetTable;
|
||||
import io.dataease.controller.request.dataset.DataSetTableRequest;
|
||||
import io.dataease.datasource.dto.TableFiled;
|
||||
import io.dataease.service.dataset.DataSetTableService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("chart/table")
|
||||
public class ChartController {
|
||||
|
||||
|
||||
|
||||
@PostMapping("list")
|
||||
public List<JSON> list(@RequestBody DataSetTableRequest dataSetTableRequest) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package io.dataease.controller.chart;
|
||||
|
||||
import io.dataease.base.domain.ChartGroup;
|
||||
import io.dataease.controller.request.chart.ChartGroupRequest;
|
||||
import io.dataease.dto.chart.ChartGroupDTO;
|
||||
import io.dataease.service.chart.ChartGroupService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("chart/group")
|
||||
public class ChartGroupController {
|
||||
@Resource
|
||||
private ChartGroupService chartGroupService;
|
||||
|
||||
@PostMapping("/save")
|
||||
public ChartGroupDTO save(@RequestBody ChartGroup ChartGroup) {
|
||||
return chartGroupService.save(ChartGroup);
|
||||
}
|
||||
|
||||
@PostMapping("/tree")
|
||||
public List<ChartGroupDTO> tree(@RequestBody ChartGroupRequest ChartGroup) {
|
||||
return chartGroupService.tree(ChartGroup);
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public void tree(@PathVariable String id) {
|
||||
chartGroupService.delete(id);
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
/*
|
||||
package io.dataease.controller.handler;
|
||||
|
||||
|
||||
@ -16,14 +17,18 @@ import java.sql.SQLException;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class RestControllerExceptionHandler {
|
||||
/*=========== Shiro 异常拦截==============*/
|
||||
*/
|
||||
/*=========== Shiro 异常拦截==============*//*
|
||||
|
||||
@ExceptionHandler(ShiroException.class)
|
||||
public ResultHolder exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||
return ResultHolder.error(exception.getMessage());
|
||||
}
|
||||
|
||||
/*=========== Shiro 异常拦截==============*/
|
||||
*/
|
||||
/*=========== Shiro 异常拦截==============*//*
|
||||
|
||||
@ExceptionHandler(UnauthorizedException.class)
|
||||
public ResultHolder unauthorizedExceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
@ -43,3 +48,4 @@ public class RestControllerExceptionHandler {
|
||||
return ResultHolder.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -1,11 +0,0 @@
|
||||
package io.dataease.controller.request.chart;
|
||||
|
||||
import io.dataease.base.domain.ChartGroup;
|
||||
import io.dataease.base.domain.DatasetGroup;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class ChartGroupRequest extends ChartGroup {
|
||||
private String sort;
|
||||
}
|
@ -11,6 +11,7 @@ import io.dataease.service.sys.DeptService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@ -23,7 +24,7 @@ import java.util.stream.Collectors;
|
||||
public class SysDeptController extends ResultHolder {
|
||||
|
||||
|
||||
@Resource
|
||||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
@PostMapping("/childNodes/{pid}")
|
||||
|
@ -1,28 +0,0 @@
|
||||
package io.dataease.dto;
|
||||
|
||||
import io.dataease.base.domain.SystemParameter;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public class SystemParameterDTO extends SystemParameter {
|
||||
@ApiModelProperty("文件")
|
||||
private MultipartFile file;
|
||||
@ApiModelProperty("文件名称")
|
||||
private String fileName;
|
||||
|
||||
public MultipartFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(MultipartFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package io.dataease.dto.chart;
|
||||
|
||||
import io.dataease.base.domain.DatasetGroup;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class ChartGroupDTO extends DatasetGroup {
|
||||
private String label;
|
||||
private List<ChartGroupDTO> children;
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package io.dataease.excel.domain;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Data
|
||||
@ColumnWidth(15)
|
||||
public class TestCaseExcelDataCn extends TestCaseExcelData {
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@Length(max = 255)
|
||||
@ExcelProperty("用例名称")
|
||||
private String name;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@Length(max = 1000)
|
||||
@ExcelProperty("所属模块")
|
||||
@ColumnWidth(30)
|
||||
@Pattern(regexp = "^(?!.*//).*$", message = "{incorrect_format}")
|
||||
private String nodePath;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("用例类型")
|
||||
@Pattern(regexp = "(^functional$)|(^performance$)|(^api$)", message = "{test_case_type_validate}")
|
||||
private String type;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("维护人")
|
||||
private String maintainer;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("用例等级")
|
||||
@Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
|
||||
private String priority;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("测试方式")
|
||||
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}")
|
||||
private String method;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("前置条件")
|
||||
@Length(min = 0, max = 1000)
|
||||
private String prerequisite;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("备注")
|
||||
@Length(max = 1000)
|
||||
private String remark;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("步骤描述")
|
||||
@Length(max = 1000)
|
||||
private String stepDesc;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("预期结果")
|
||||
@Length(max = 1000)
|
||||
private String stepResult;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package io.dataease.excel.domain;
|
||||
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class TestCaseExcelDataFactory implements ExcelDataFactory {
|
||||
@Override
|
||||
public Class getExcelDataByLocal() {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if (Locale.US.toString().equalsIgnoreCase(locale.toString())) {
|
||||
return TestCaseExcelDataUs.class;
|
||||
} else if (Locale.TRADITIONAL_CHINESE.toString().equalsIgnoreCase(locale.toString())) {
|
||||
return TestCaseExcelDataTw.class;
|
||||
}
|
||||
return TestCaseExcelDataCn.class;
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package io.dataease.excel.domain;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@Data
|
||||
@ColumnWidth(15)
|
||||
public class TestCaseExcelDataTw extends TestCaseExcelData {
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@Length(max = 255)
|
||||
@ExcelProperty("用例名稱")
|
||||
private String name;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@Length(max = 1000)
|
||||
@ExcelProperty("所屬模塊")
|
||||
@ColumnWidth(30)
|
||||
@Pattern(regexp = "^(?!.*//).*$", message = "{incorrect_format}")
|
||||
private String nodePath;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("用例類型")
|
||||
@Pattern(regexp = "(^functional$)|(^performance$)|(^api$)", message = "{test_case_type_validate}")
|
||||
private String type;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("維護人")
|
||||
private String maintainer;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("用例等級")
|
||||
@Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
|
||||
private String priority;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("測試方式")
|
||||
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}")
|
||||
private String method;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("前置條件")
|
||||
@Length(min = 0, max = 1000)
|
||||
private String prerequisite;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("備註")
|
||||
@Length(max = 1000)
|
||||
private String remark;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("步驟描述")
|
||||
@Length(max = 1000)
|
||||
private String stepDesc;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("預期結果")
|
||||
@Length(max = 1000)
|
||||
private String stepResult;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package io.dataease.excel.domain;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
|
||||
@Data
|
||||
@ColumnWidth(15)
|
||||
public class TestCaseExcelDataUs extends TestCaseExcelData {
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@Length(max = 255)
|
||||
@ExcelProperty("Name")
|
||||
private String name;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@Length(max = 1000)
|
||||
@ExcelProperty("Module")
|
||||
@ColumnWidth(30)
|
||||
@Pattern(regexp = "^(?!.*//).*$", message = "{incorrect_format}")
|
||||
private String nodePath;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("Type")
|
||||
@Pattern(regexp = "(^functional$)|(^performance$)|(^api$)", message = "{test_case_type_validate}")
|
||||
private String type;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("Maintainer")
|
||||
private String maintainer;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("Priority")
|
||||
@Pattern(regexp = "(^P0$)|(^P1$)|(^P2$)|(^P3$)", message = "{test_case_priority_validate}")
|
||||
private String priority;
|
||||
|
||||
@NotBlank(message = "{cannot_be_null}")
|
||||
@ExcelProperty("Method")
|
||||
@Pattern(regexp = "(^manual$)|(^auto$)", message = "{test_case_method_validate}")
|
||||
private String method;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("Prerequisite")
|
||||
@Length(min = 0, max = 1000)
|
||||
private String prerequisite;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("Remark")
|
||||
@Length(max = 1000)
|
||||
private String remark;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("Step description")
|
||||
@Length(max = 1000)
|
||||
private String stepDesc;
|
||||
|
||||
@ColumnWidth(50)
|
||||
@ExcelProperty("Step result")
|
||||
@Length(max = 1000)
|
||||
private String stepResult;
|
||||
}
|
@ -2,7 +2,7 @@ package io.dataease.interceptor;
|
||||
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.MybatisInterceptorConfig;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.cache.CacheKey;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
|
@ -1,36 +0,0 @@
|
||||
package io.dataease.notice.controller;
|
||||
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import io.dataease.notice.service.NoticeService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("notice")
|
||||
public class NoticeController {
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
@PostMapping("save/message/task")
|
||||
public void saveMessage(@RequestBody MessageDetail messageDetail) {
|
||||
noticeService.saveMessageTask(messageDetail);
|
||||
}
|
||||
|
||||
@GetMapping("/search/message/type/{type}")
|
||||
public List<MessageDetail> searchMessage(@PathVariable String type) {
|
||||
return noticeService.searchMessageByType(type);
|
||||
}
|
||||
|
||||
@GetMapping("/search/message/{testId}")
|
||||
public List<MessageDetail> searchMessageSchedule(@PathVariable String testId) {
|
||||
return noticeService.searchMessageByTestId(testId);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/message/{identification}")
|
||||
public int deleteMessage(@PathVariable String identification) {
|
||||
return noticeService.delMessage(identification);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package io.dataease.notice.controller.request;
|
||||
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MessageRequest {
|
||||
private List<MessageDetail> messageDetail;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package io.dataease.notice.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Mail {
|
||||
// 发送给谁
|
||||
private String to;
|
||||
|
||||
// 发送主题
|
||||
private String subject;
|
||||
|
||||
// 发送内容
|
||||
private String content;
|
||||
|
||||
// 附件地址
|
||||
private String filePath;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package io.dataease.notice.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MailInfo {
|
||||
private String host;
|
||||
private String port;
|
||||
private String account;
|
||||
private String password;
|
||||
private String ssl;
|
||||
private String tls;
|
||||
private String recipient;
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package io.dataease.notice.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MessageDetail {
|
||||
private List<String> userIds = new ArrayList<>();
|
||||
private String event;
|
||||
private String taskType;
|
||||
private String webhook;
|
||||
private String type;
|
||||
private String identification;
|
||||
private String organizationId;
|
||||
private Boolean isSet;
|
||||
private String testId;
|
||||
private Long createTime;
|
||||
private String template;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package io.dataease.notice.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MessageSettingDetail {
|
||||
private List<MessageDetail> jenkinsTask;
|
||||
private List<MessageDetail> testCasePlanTask;
|
||||
private List<MessageDetail> reviewTask;
|
||||
private List<MessageDetail> defectTask;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package io.dataease.notice.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserDetail {
|
||||
private String email;
|
||||
private String phone;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package io.dataease.notice.message;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class LinkMessage implements Message {
|
||||
|
||||
private String title;
|
||||
private String text;
|
||||
private String picUrl;
|
||||
private String messageUrl;
|
||||
|
||||
public String toJsonString() {
|
||||
Map<String, Object> items = new HashMap<String, Object>();
|
||||
items.put("msgtype", "link");
|
||||
|
||||
Map<String, String> linkContent = new HashMap<String, String>();
|
||||
if (StringUtils.isBlank(title)) {
|
||||
throw new IllegalArgumentException("title should not be blank");
|
||||
}
|
||||
linkContent.put("title", title);
|
||||
|
||||
if (StringUtils.isBlank(messageUrl)) {
|
||||
throw new IllegalArgumentException("messageUrl should not be blank");
|
||||
}
|
||||
linkContent.put("messageUrl", messageUrl);
|
||||
|
||||
if (StringUtils.isBlank(text)) {
|
||||
throw new IllegalArgumentException("text should not be blank");
|
||||
}
|
||||
linkContent.put("text", text);
|
||||
|
||||
if (StringUtils.isNotBlank(picUrl)) {
|
||||
linkContent.put("picUrl", picUrl);
|
||||
}
|
||||
|
||||
items.put("link", linkContent);
|
||||
|
||||
return JSON.toJSONString(items);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package io.dataease.notice.message;
|
||||
|
||||
public interface Message {
|
||||
String toJsonString();
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package io.dataease.notice.message;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class TextMessage implements Message {
|
||||
private String text;
|
||||
private List<String> mentionedMobileList;
|
||||
private boolean isAtAll;
|
||||
|
||||
public TextMessage(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public boolean isAtAll() {
|
||||
return isAtAll;
|
||||
}
|
||||
|
||||
public void setIsAtAll(boolean isAtAll) {
|
||||
this.isAtAll = isAtAll;
|
||||
}
|
||||
|
||||
public List<String> getMentionedMobileList() {
|
||||
return mentionedMobileList;
|
||||
}
|
||||
|
||||
public void setMentionedMobileList(List<String> mentionedMobileList) {
|
||||
this.mentionedMobileList = mentionedMobileList;
|
||||
}
|
||||
|
||||
public String toJsonString() {
|
||||
Map<String, Object> items = new HashMap<String, Object>();
|
||||
items.put("msgtype", "text");
|
||||
|
||||
Map<String, Object> textContent = new HashMap<String, Object>();
|
||||
if (StringUtils.isBlank(text)) {
|
||||
throw new IllegalArgumentException("text should not be blank");
|
||||
}
|
||||
textContent.put("content", text);
|
||||
if (isAtAll) {
|
||||
if (mentionedMobileList == null) mentionedMobileList = new ArrayList<String>();
|
||||
mentionedMobileList.add("@all");
|
||||
}
|
||||
if (mentionedMobileList != null && !mentionedMobileList.isEmpty()) {
|
||||
textContent.put("mentioned_mobile_list", mentionedMobileList);
|
||||
}
|
||||
items.put("text", textContent);
|
||||
return JSON.toJSONString(items);
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
package io.dataease.notice.sender;
|
||||
|
||||
import io.dataease.commons.constants.NoticeConstants;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import io.dataease.notice.domain.UserDetail;
|
||||
import io.dataease.service.UserService;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.RegExUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractNoticeSender implements NoticeSender {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
protected String getContext(MessageDetail messageDetail, NoticeModel noticeModel) {
|
||||
// 如果配置了模版就直接使用模版
|
||||
if (StringUtils.isNotBlank(messageDetail.getTemplate())) {
|
||||
return getContent(messageDetail.getTemplate(), noticeModel.getParamMap());
|
||||
}
|
||||
// 处理 userIds 中包含的特殊值
|
||||
List<String> realUserIds = getRealUserIds(messageDetail.getUserIds(), noticeModel.getRelatedUsers(), messageDetail.getEvent());
|
||||
messageDetail.setUserIds(realUserIds);
|
||||
|
||||
// 处理 WeCom Ding context
|
||||
String context = "";
|
||||
switch (messageDetail.getEvent()) {
|
||||
case NoticeConstants.Event.CREATE:
|
||||
case NoticeConstants.Event.UPDATE:
|
||||
case NoticeConstants.Event.DELETE:
|
||||
case NoticeConstants.Event.COMMENT:
|
||||
context = noticeModel.getContext();
|
||||
break;
|
||||
case NoticeConstants.Event.EXECUTE_FAILED:
|
||||
context = noticeModel.getFailedContext();
|
||||
break;
|
||||
case NoticeConstants.Event.EXECUTE_SUCCESSFUL:
|
||||
context = noticeModel.getSuccessContext();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
protected String getHtmlContext(MessageDetail messageDetail, NoticeModel noticeModel) {
|
||||
// 如果配置了模版就直接使用模版
|
||||
if (StringUtils.isNotBlank(messageDetail.getTemplate())) {
|
||||
return getContent(messageDetail.getTemplate(), noticeModel.getParamMap());
|
||||
}
|
||||
// 处理 userIds 中包含的特殊值
|
||||
List<String> realUserIds = getRealUserIds(messageDetail.getUserIds(), noticeModel.getRelatedUsers(), messageDetail.getEvent());
|
||||
messageDetail.setUserIds(realUserIds);
|
||||
|
||||
// 处理 mail context
|
||||
String context = "";
|
||||
try {
|
||||
switch (messageDetail.getEvent()) {
|
||||
case NoticeConstants.Event.CREATE:
|
||||
case NoticeConstants.Event.UPDATE:
|
||||
case NoticeConstants.Event.DELETE:
|
||||
case NoticeConstants.Event.COMMENT:
|
||||
URL resource = this.getClass().getResource("/mail/" + noticeModel.getMailTemplate() + ".html");
|
||||
context = IOUtils.toString(resource, StandardCharsets.UTF_8);
|
||||
break;
|
||||
case NoticeConstants.Event.EXECUTE_FAILED:
|
||||
URL resource1 = this.getClass().getResource("/mail/" + noticeModel.getFailedMailTemplate() + ".html");
|
||||
context = IOUtils.toString(resource1, StandardCharsets.UTF_8);
|
||||
break;
|
||||
case NoticeConstants.Event.EXECUTE_SUCCESSFUL:
|
||||
URL resource2 = this.getClass().getResource("/mail/" + noticeModel.getSuccessMailTemplate() + ".html");
|
||||
context = IOUtils.toString(resource2, StandardCharsets.UTF_8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return getContent(context, noticeModel.getParamMap());
|
||||
}
|
||||
|
||||
protected String getContent(String template, Map<String, Object> context) {
|
||||
if (MapUtils.isNotEmpty(context)) {
|
||||
for (String k : context.keySet()) {
|
||||
if (context.get(k) != null) {
|
||||
template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k).toString());
|
||||
} else {
|
||||
template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", "未设置");
|
||||
}
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
protected List<String> getUserPhones(List<String> userIds) {
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
List<String> phoneList = new ArrayList<>();
|
||||
list.forEach(u -> phoneList.add(u.getPhone()));
|
||||
LogUtil.info("收件人地址: " + phoneList);
|
||||
return phoneList.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected List<String> getUserEmails(List<String> userIds) {
|
||||
List<UserDetail> list = userService.queryTypeByIds(userIds);
|
||||
List<String> phoneList = new ArrayList<>();
|
||||
list.forEach(u -> phoneList.add(u.getEmail()));
|
||||
LogUtil.info("收件人地址: " + phoneList);
|
||||
return phoneList.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<String> getRealUserIds(List<String> userIds, List<String> relatedUsers, String event) {
|
||||
List<String> toUserIds = new ArrayList<>();
|
||||
for (String userId : userIds) {
|
||||
switch (userId) {
|
||||
case NoticeConstants.RelatedUser.EXECUTOR:
|
||||
if (StringUtils.equals(NoticeConstants.Event.CREATE, event)) {
|
||||
toUserIds.addAll(relatedUsers);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.RelatedUser.FOUNDER:
|
||||
if (StringUtils.equals(NoticeConstants.Event.UPDATE, event)
|
||||
|| StringUtils.equals(NoticeConstants.Event.DELETE, event)) {
|
||||
toUserIds.addAll(relatedUsers);
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.RelatedUser.MAINTAINER:
|
||||
if (StringUtils.equals(NoticeConstants.Event.COMMENT, event)) {
|
||||
toUserIds.addAll(relatedUsers);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
toUserIds.add(userId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return toUserIds;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package io.dataease.notice.sender;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class NoticeModel {
|
||||
/**
|
||||
* 保存 测试id
|
||||
*/
|
||||
private String testId;
|
||||
/**
|
||||
* 保存状态
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* Event
|
||||
*/
|
||||
private String event;
|
||||
/**
|
||||
* 消息主题
|
||||
*/
|
||||
private String subject;
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String context;
|
||||
private String successContext;
|
||||
private String failedContext;
|
||||
|
||||
/**
|
||||
* html 消息模版
|
||||
*/
|
||||
private String mailTemplate;
|
||||
private String failedMailTemplate;
|
||||
private String successMailTemplate;
|
||||
|
||||
/**
|
||||
* 保存特殊的用户
|
||||
*/
|
||||
private List<String> relatedUsers;
|
||||
|
||||
/**
|
||||
* 模版里的参数信息
|
||||
*/
|
||||
private Map<String, Object> paramMap;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package io.dataease.notice.sender;
|
||||
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
public interface NoticeSender {
|
||||
@Async
|
||||
void send(MessageDetail messageDetail, NoticeModel noticeModel);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package io.dataease.notice.sender.impl;
|
||||
|
||||
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import io.dataease.notice.sender.AbstractNoticeSender;
|
||||
import io.dataease.notice.sender.NoticeModel;
|
||||
import io.dataease.notice.service.MailService;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MailNoticeSender extends AbstractNoticeSender {
|
||||
@Resource
|
||||
private MailService mailService;
|
||||
|
||||
private void sendMail(MessageDetail messageDetail, String context, NoticeModel noticeModel) throws MessagingException {
|
||||
LogUtil.info("发送邮件开始 ");
|
||||
JavaMailSenderImpl javaMailSender = mailService.getMailSender();
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
LogUtil.info("发件人地址"+javaMailSender.getUsername());
|
||||
LogUtil.info("helper"+helper);
|
||||
helper.setSubject("MeterSphere " + noticeModel.getSubject());
|
||||
List<String> emails = super.getUserEmails(messageDetail.getUserIds());
|
||||
String[] users = emails.toArray(new String[0]);
|
||||
LogUtil.info("收件人地址: " + emails);
|
||||
helper.setText(context, true);
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MessageDetail messageDetail, NoticeModel noticeModel) {
|
||||
String context = super.getHtmlContext(messageDetail, noticeModel);
|
||||
try {
|
||||
sendMail(messageDetail, context, noticeModel);
|
||||
LogUtil.info("发送邮件结束");
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package io.dataease.notice.sender.impl;
|
||||
|
||||
import io.dataease.notice.sender.AbstractNoticeSender;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import io.dataease.notice.message.TextMessage;
|
||||
import io.dataease.notice.sender.NoticeModel;
|
||||
import io.dataease.notice.util.WxChatbotClient;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class WeComNoticeSender extends AbstractNoticeSender {
|
||||
|
||||
|
||||
public void sendWechatRobot(MessageDetail messageDetail, String context) {
|
||||
List<String> userIds = messageDetail.getUserIds();
|
||||
if (CollectionUtils.isEmpty(userIds)) {
|
||||
return;
|
||||
}
|
||||
TextMessage message = new TextMessage(context);
|
||||
List<String> phoneLists = super.getUserPhones(userIds);
|
||||
message.setMentionedMobileList(phoneLists);
|
||||
try {
|
||||
WxChatbotClient.send(messageDetail.getWebhook(), message);
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MessageDetail messageDetail, NoticeModel noticeModel) {
|
||||
String context = super.getContext(messageDetail, noticeModel);
|
||||
sendWechatRobot(messageDetail, context);
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package io.dataease.notice.service;
|
||||
|
||||
import io.dataease.base.domain.SystemParameter;
|
||||
import io.dataease.commons.constants.ParamConstants;
|
||||
import io.dataease.commons.utils.EncryptUtils;
|
||||
import io.dataease.service.system.SystemParameterService;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public class MailService {
|
||||
@Resource
|
||||
private SystemParameterService systemParameterService;
|
||||
|
||||
public JavaMailSenderImpl getMailSender() {
|
||||
Properties props = new Properties();
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
List<SystemParameter> paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setProtocol("smtp");
|
||||
props.put("mail.smtp.auth", "true");
|
||||
|
||||
for (SystemParameter p : paramList) {
|
||||
switch (p.getParamKey()) {
|
||||
case "smtp.host":
|
||||
javaMailSender.setHost(p.getParamValue());
|
||||
break;
|
||||
case "smtp.port":
|
||||
javaMailSender.setPort(Integer.parseInt(p.getParamValue()));
|
||||
break;
|
||||
case "smtp.account":
|
||||
javaMailSender.setUsername(p.getParamValue());
|
||||
break;
|
||||
case "smtp.password":
|
||||
javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString());
|
||||
break;
|
||||
case "smtp.ssl":
|
||||
if (BooleanUtils.toBoolean(p.getParamValue())) {
|
||||
javaMailSender.setProtocol("smtps");
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
}
|
||||
break;
|
||||
case "smtp.tls":
|
||||
String result = BooleanUtils.toString(BooleanUtils.toBoolean(p.getParamValue()), "true", "false");
|
||||
props.put("mail.smtp.starttls.enable", result);
|
||||
props.put("mail.smtp.starttls.required", result);
|
||||
break;
|
||||
/* case "smtp.anon":
|
||||
boolean isAnon = BooleanUtils.toBoolean(p.getParamValue());
|
||||
if (isAnon) {
|
||||
props.put("mail.smtp.auth", "false");
|
||||
javaMailSender.setUsername(null);
|
||||
javaMailSender.setPassword(null);
|
||||
}
|
||||
break;*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
props.put("mail.smtp.timeout", "30000");
|
||||
props.put("mail.smtp.connectiontimeout", "5000");
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
return javaMailSender;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
package io.dataease.notice.service;
|
||||
|
||||
import io.dataease.commons.constants.NoticeConstants;
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import io.dataease.notice.sender.NoticeModel;
|
||||
import io.dataease.notice.sender.NoticeSender;
|
||||
import io.dataease.notice.sender.impl.MailNoticeSender;
|
||||
import io.dataease.notice.sender.impl.WeComNoticeSender;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class NoticeSendService {
|
||||
@Resource
|
||||
private MailNoticeSender mailNoticeSender;
|
||||
@Resource
|
||||
private WeComNoticeSender weComNoticeSender;
|
||||
|
||||
@Resource
|
||||
private NoticeService noticeService;
|
||||
|
||||
private NoticeSender getNoticeSender(MessageDetail messageDetail) {
|
||||
NoticeSender noticeSender = null;
|
||||
switch (messageDetail.getType()) {
|
||||
case NoticeConstants.Type.EMAIL:
|
||||
noticeSender = mailNoticeSender;
|
||||
break;
|
||||
case NoticeConstants.Type.WECHAT_ROBOT:
|
||||
noticeSender = weComNoticeSender;
|
||||
break;
|
||||
// case NoticeConstants.Type.NAIL_ROBOT:
|
||||
// noticeSender = dingNoticeSender;
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return noticeSender;
|
||||
}
|
||||
|
||||
public void send(String taskType, NoticeModel noticeModel) {
|
||||
List<MessageDetail> messageDetails;
|
||||
switch (taskType) {
|
||||
case NoticeConstants.Mode.API:
|
||||
messageDetails = noticeService.searchMessageByType(NoticeConstants.TaskType.JENKINS_TASK);
|
||||
break;
|
||||
case NoticeConstants.Mode.SCHEDULE:
|
||||
messageDetails = noticeService.searchMessageByTestId(noticeModel.getTestId());
|
||||
break;
|
||||
default:
|
||||
messageDetails = noticeService.searchMessageByType(taskType);
|
||||
break;
|
||||
}
|
||||
messageDetails.forEach(messageDetail -> {
|
||||
if (StringUtils.equals(messageDetail.getEvent(), noticeModel.getEvent())) {
|
||||
this.getNoticeSender(messageDetail).send(messageDetail, noticeModel);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
package io.dataease.notice.service;
|
||||
|
||||
import io.dataease.base.domain.MessageTask;
|
||||
import io.dataease.base.domain.MessageTaskExample;
|
||||
import io.dataease.base.mapper.MessageTaskMapper;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.notice.domain.MessageDetail;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class NoticeService {
|
||||
@Resource
|
||||
private MessageTaskMapper messageTaskMapper;
|
||||
|
||||
public void saveMessageTask(MessageDetail messageDetail) {
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
example.createCriteria().andIdentificationEqualTo(messageDetail.getIdentification());
|
||||
List<MessageTask> messageTaskLists = messageTaskMapper.selectByExample(example);
|
||||
if (messageTaskLists.size() > 0) {
|
||||
delMessage(messageDetail.getIdentification());
|
||||
}
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
String orgId = user.getLastOrganizationId();
|
||||
long time = System.currentTimeMillis();
|
||||
String identification = messageDetail.getIdentification();
|
||||
if (StringUtils.isBlank(identification)) {
|
||||
identification = UUID.randomUUID().toString();
|
||||
}
|
||||
for (String userId : messageDetail.getUserIds()) {
|
||||
checkUserIdExist(userId, messageDetail, orgId);
|
||||
MessageTask messageTask = new MessageTask();
|
||||
messageTask.setId(UUID.randomUUID().toString());
|
||||
messageTask.setEvent(messageDetail.getEvent());
|
||||
messageTask.setTaskType(messageDetail.getTaskType());
|
||||
messageTask.setUserId(userId);
|
||||
messageTask.setType(messageDetail.getType());
|
||||
messageTask.setWebhook(messageDetail.getWebhook());
|
||||
messageTask.setIdentification(identification);
|
||||
messageTask.setIsSet(false);
|
||||
messageTask.setOrganizationId(orgId);
|
||||
messageTask.setTestId(messageDetail.getTestId());
|
||||
messageTask.setCreateTime(time);
|
||||
setTemplate(messageDetail, messageTask);
|
||||
messageTaskMapper.insert(messageTask);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTemplate(MessageDetail messageDetail, MessageTask messageTask) {
|
||||
if (StringUtils.isNotBlank(messageDetail.getTemplate())) {
|
||||
messageTask.setTemplate(messageDetail.getTemplate());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUserIdExist(String userId, MessageDetail list, String orgId) {
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
if (StringUtils.isBlank(list.getTestId())) {
|
||||
example.createCriteria()
|
||||
.andUserIdEqualTo(userId)
|
||||
.andEventEqualTo(list.getEvent())
|
||||
.andTypeEqualTo(list.getType())
|
||||
.andTaskTypeEqualTo(list.getTaskType())
|
||||
.andWebhookEqualTo(list.getWebhook())
|
||||
.andOrganizationIdEqualTo(orgId);
|
||||
} else {
|
||||
example.createCriteria()
|
||||
.andUserIdEqualTo(userId)
|
||||
.andEventEqualTo(list.getEvent())
|
||||
.andTypeEqualTo(list.getType())
|
||||
.andTaskTypeEqualTo(list.getTaskType())
|
||||
.andWebhookEqualTo(list.getWebhook())
|
||||
.andTestIdEqualTo(list.getTestId())
|
||||
.andOrganizationIdEqualTo(orgId);
|
||||
}
|
||||
if (messageTaskMapper.countByExample(example) > 0) {
|
||||
DEException.throwException(Translator.get("message_task_already_exists"));
|
||||
}
|
||||
}
|
||||
|
||||
public List<MessageDetail> searchMessageByTestId(String testId) {
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
example.createCriteria().andTestIdEqualTo(testId);
|
||||
List<MessageTask> messageTaskLists = messageTaskMapper.selectByExampleWithBLOBs(example);
|
||||
List<MessageDetail> scheduleMessageTask = new ArrayList<>();
|
||||
Map<String, List<MessageTask>> MessageTaskMap = messageTaskLists.stream().collect(Collectors.groupingBy(MessageTask::getIdentification));
|
||||
MessageTaskMap.forEach((k, v) -> {
|
||||
MessageDetail messageDetail = getMessageDetail(v);
|
||||
scheduleMessageTask.add(messageDetail);
|
||||
});
|
||||
scheduleMessageTask.sort(Comparator.comparing(MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed());
|
||||
return scheduleMessageTask;
|
||||
}
|
||||
|
||||
public List<MessageDetail> searchMessageByType(String type) {
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
String orgId = user.getLastOrganizationId();
|
||||
List<MessageDetail> messageDetails = new ArrayList<>();
|
||||
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
example.createCriteria()
|
||||
.andTaskTypeEqualTo(type)
|
||||
.andOrganizationIdEqualTo(orgId);
|
||||
List<MessageTask> messageTaskLists = messageTaskMapper.selectByExampleWithBLOBs(example);
|
||||
|
||||
Map<String, List<MessageTask>> messageTaskMap = messageTaskLists.stream()
|
||||
.collect(Collectors.groupingBy(NoticeService::fetchGroupKey));
|
||||
messageTaskMap.forEach((k, v) -> {
|
||||
MessageDetail messageDetail = getMessageDetail(v);
|
||||
messageDetails.add(messageDetail);
|
||||
});
|
||||
|
||||
return messageDetails.stream()
|
||||
.sorted(Comparator.comparing(MessageDetail::getCreateTime, Comparator.nullsLast(Long::compareTo)).reversed())
|
||||
.collect(Collectors.toList())
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private MessageDetail getMessageDetail(List<MessageTask> messageTasks) {
|
||||
Set<String> userIds = new HashSet<>();
|
||||
|
||||
MessageDetail messageDetail = new MessageDetail();
|
||||
for (MessageTask m : messageTasks) {
|
||||
userIds.add(m.getUserId());
|
||||
messageDetail.setEvent(m.getEvent());
|
||||
messageDetail.setTaskType(m.getTaskType());
|
||||
messageDetail.setWebhook(m.getWebhook());
|
||||
messageDetail.setIdentification(m.getIdentification());
|
||||
messageDetail.setType(m.getType());
|
||||
messageDetail.setIsSet(m.getIsSet());
|
||||
messageDetail.setCreateTime(m.getCreateTime());
|
||||
messageDetail.setTemplate(m.getTemplate());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
messageDetail.setUserIds(new ArrayList<>(userIds));
|
||||
}
|
||||
return messageDetail;
|
||||
}
|
||||
|
||||
private static String fetchGroupKey(MessageTask messageTask) {
|
||||
return messageTask.getTaskType() + "#" + messageTask.getIdentification();
|
||||
}
|
||||
|
||||
public int delMessage(String identification) {
|
||||
MessageTaskExample example = new MessageTaskExample();
|
||||
example.createCriteria().andIdentificationEqualTo(identification);
|
||||
return messageTaskMapper.deleteByExample(example);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package io.dataease.notice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SendResult {
|
||||
private boolean isSuccess;
|
||||
private Integer errorCode;
|
||||
private String errorMsg;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
public void setIsSuccess(boolean isSuccess) {
|
||||
this.isSuccess = isSuccess;
|
||||
}
|
||||
|
||||
public Integer getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(Integer errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Map<String, Object> items = new HashMap<String, Object>();
|
||||
items.put("errorCode", errorCode);
|
||||
items.put("errorMsg", errorMsg);
|
||||
items.put("isSuccess", isSuccess);
|
||||
return JSON.toJSONString(items);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package io.dataease.notice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.dataease.notice.message.Message;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class WxChatbotClient {
|
||||
|
||||
static HttpClient httpclient = HttpClients.createDefault();
|
||||
|
||||
public static SendResult send(String webhook, Message message) throws IOException {
|
||||
|
||||
if (StringUtils.isBlank(webhook)) {
|
||||
return new SendResult();
|
||||
}
|
||||
HttpPost httppost = new HttpPost(webhook);
|
||||
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
|
||||
StringEntity se = new StringEntity(message.toJsonString(), "utf-8");
|
||||
httppost.setEntity(se);
|
||||
|
||||
SendResult sendResult = new SendResult();
|
||||
HttpResponse response = httpclient.execute(httppost);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
String result = EntityUtils.toString(response.getEntity());
|
||||
JSONObject obj = JSONObject.parseObject(result);
|
||||
|
||||
Integer errcode = obj.getInteger("errcode");
|
||||
sendResult.setErrorCode(errcode);
|
||||
sendResult.setErrorMsg(obj.getString("errmsg"));
|
||||
sendResult.setIsSuccess(errcode.equals(0));
|
||||
}
|
||||
|
||||
return sendResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
package io.dataease.security;
|
||||
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.web.filter.authc.AnonymousFilter;
|
||||
import org.apache.shiro.web.util.WebUtils;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ApiKeyFilter extends AnonymousFilter {
|
||||
|
||||
@Override
|
||||
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) {
|
||||
try {
|
||||
if (!SecurityUtils.getSubject().isAuthenticated()) {
|
||||
String userId = ApiKeyHandler.getUser(WebUtils.toHttp(request));
|
||||
if (StringUtils.isNotBlank(userId)) {
|
||||
if (LogUtil.getLogger().isDebugEnabled()) {
|
||||
LogUtil.getLogger().debug("user auth: " + userId);
|
||||
}
|
||||
SecurityUtils.getSubject().login(new MsUserToken(userId, ApiKeySessionHandler.random, "LOCAL"));
|
||||
}
|
||||
} else {
|
||||
if (ApiKeyHandler.isApiKeyCall(WebUtils.toHttp(request))) {
|
||||
String userId = ApiKeyHandler.getUser(WebUtils.toHttp(request));
|
||||
SecurityUtils.getSubject().login(new MsUserToken(userId, ApiKeySessionHandler.random, "LOCAL"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!SecurityUtils.getSubject().isAuthenticated()) {
|
||||
((HttpServletResponse) response).setHeader("Authentication-Status", "invalid");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (ApiKeyHandler.isApiKeyCall(WebUtils.toHttp(request))) {
|
||||
throw e;
|
||||
}
|
||||
LogUtil.getLogger().error("failed to handle single sign on..", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package io.dataease.security;
|
||||
|
||||
import io.dataease.base.domain.UserKey;
|
||||
import io.dataease.commons.utils.CodingUtil;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.service.UserKeyService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class ApiKeyHandler {
|
||||
|
||||
public static final String API_ACCESS_KEY = "accessKey";
|
||||
|
||||
public static final String API_SIGNATURE = "signature";
|
||||
|
||||
public static String getUser(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
return getUser(request.getHeader(API_ACCESS_KEY), request.getHeader(API_SIGNATURE));
|
||||
}
|
||||
|
||||
public static Boolean isApiKeyCall(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return false;
|
||||
}
|
||||
return !StringUtils.isBlank(request.getHeader(API_ACCESS_KEY)) && !StringUtils.isBlank(request.getHeader(API_SIGNATURE));
|
||||
}
|
||||
|
||||
public static String getUser(String accessKey, String signature) {
|
||||
if (StringUtils.isBlank(accessKey) || StringUtils.isBlank(signature)) {
|
||||
return null;
|
||||
}
|
||||
UserKey userKey = CommonBeanFactory.getBean(UserKeyService.class).getUserKey(accessKey);
|
||||
if (userKey == null) {
|
||||
throw new RuntimeException("invalid accessKey");
|
||||
}
|
||||
String signatureDecrypt;
|
||||
try {
|
||||
signatureDecrypt = CodingUtil.aesDecrypt(signature, userKey.getSecretKey(), accessKey);
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException("invalid signature");
|
||||
}
|
||||
String[] signatureArray = StringUtils.split(StringUtils.trimToNull(signatureDecrypt), "|");
|
||||
if (signatureArray.length < 2) {
|
||||
throw new RuntimeException("invalid signature");
|
||||
}
|
||||
if (!StringUtils.equals(accessKey, signatureArray[0])) {
|
||||
throw new RuntimeException("invalid signature");
|
||||
}
|
||||
long signatureTime;
|
||||
try {
|
||||
signatureTime = Long.parseLong(signatureArray[signatureArray.length - 1]);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (Math.abs(System.currentTimeMillis() - signatureTime) > 1800000) {
|
||||
//签名30分钟超时
|
||||
throw new RuntimeException("expired signature");
|
||||
}
|
||||
return userKey.getUserId();
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package io.dataease.security;
|
||||
|
||||
import io.dataease.commons.utils.EncryptUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class ApiKeySessionHandler {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ApiKeySessionHandler.class);
|
||||
|
||||
|
||||
public static String random = UUID.randomUUID().toString() + UUID.randomUUID().toString();
|
||||
|
||||
public static String generateId(String authInfo) {
|
||||
return SessionGenerator.generateId(authInfo);
|
||||
}
|
||||
|
||||
public static String validate(HttpServletRequest request) {
|
||||
try {
|
||||
String v = request.getHeader(ApiKeyHandler.API_SIGNATURE);
|
||||
if (StringUtils.isNotBlank(v)) {
|
||||
return SessionGenerator.fromId(v);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("failed to validate", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static class SessionGenerator {
|
||||
public SessionGenerator() {
|
||||
}
|
||||
|
||||
public static String generateId(String authInfo) {
|
||||
return EncryptUtils.aesEncrypt(parse2Str(authInfo)).toString();
|
||||
}
|
||||
|
||||
public static String fromId(String sessionId) {
|
||||
String authInfoString = EncryptUtils.aesDecrypt(sessionId).toString();
|
||||
return fromStr(authInfoString);
|
||||
}
|
||||
|
||||
private static String parse2Str(String authInfo) {
|
||||
return UUID.randomUUID().toString() + "|" + authInfo + "|" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private static String fromStr(String authInfoString) {
|
||||
String[] sp = authInfoString.split("\\|");
|
||||
return sp[1];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package io.dataease.security;
|
||||
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
|
||||
public class MsUserToken extends UsernamePasswordToken {
|
||||
private String loginType;
|
||||
|
||||
public MsUserToken() {
|
||||
}
|
||||
|
||||
public MsUserToken(final String username, final String password, final String loginType) {
|
||||
super(username, password);
|
||||
this.loginType = loginType;
|
||||
}
|
||||
|
||||
public String getLoginType() {
|
||||
return loginType;
|
||||
}
|
||||
|
||||
public void setLoginType(String loginType) {
|
||||
this.loginType = loginType;
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package io.dataease.security;
|
||||
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
|
||||
import org.apache.shiro.realm.Realm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class UserModularRealmAuthenticator extends ModularRealmAuthenticator {
|
||||
|
||||
@Override
|
||||
protected AuthenticationInfo doAuthenticate(AuthenticationToken authenticationToken)
|
||||
throws AuthenticationException {
|
||||
// 判断getRealms()是否返回为空
|
||||
assertRealmsConfigured();
|
||||
// 强制转换回自定义的CustomizedToken
|
||||
MsUserToken userToken = (MsUserToken) authenticationToken;
|
||||
// 登录类型
|
||||
String loginType = userToken.getLoginType();
|
||||
// 所有Realm
|
||||
Collection<Realm> realms = getRealms();
|
||||
// 登录类型对应的所有Realm
|
||||
List<Realm> typeRealms = new ArrayList<>();
|
||||
|
||||
// 默认使用本地验证
|
||||
for (Realm realm : realms) {
|
||||
if (realm.getName().contains(loginType)) {
|
||||
typeRealms.add(realm);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeRealms.size() == 0) {
|
||||
DEException.throwException("No realm");
|
||||
}
|
||||
// 判断是单Realm还是多Realm
|
||||
if (typeRealms.size() == 1) {
|
||||
return doSingleRealmAuthentication(typeRealms.get(0), userToken);
|
||||
} else {
|
||||
return doMultiRealmAuthentication(typeRealms, userToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package io.dataease.security.realm;
|
||||
|
||||
|
||||
import io.dataease.base.domain.Role;
|
||||
import io.dataease.commons.constants.UserSource;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.dto.UserDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.UserService;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义Realm 注入service 可能会导致在 service的aop 失效,例如@Transactional,
|
||||
* 解决方法:
|
||||
* <p>
|
||||
* 1. 这里改成注入mapper,这样mapper 中的事务失效<br/>
|
||||
* 2. 这里仍然注入service,在配置ShiroConfig 的时候不去set realm, 等到spring 初始化完成之后
|
||||
* set realm
|
||||
* </p>
|
||||
*/
|
||||
public class LdapRealm extends AuthorizingRealm {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(LdapRealm.class);
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LDAP";
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限认证
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
String userId = (String) principals.getPrimaryPrincipal();
|
||||
return getAuthorizationInfo(userId, userService);
|
||||
}
|
||||
|
||||
public static AuthorizationInfo getAuthorizationInfo(String userId, UserService userService) {
|
||||
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
|
||||
// roles 内容填充
|
||||
UserDTO userDTO = userService.getUserDTO(userId);
|
||||
Set<String> roles = userDTO.getRoles().stream().map(Role::getId).collect(Collectors.toSet());
|
||||
authorizationInfo.setRoles(roles);
|
||||
return authorizationInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录认证
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
|
||||
|
||||
String userId = token.getUsername();
|
||||
String password = String.valueOf(token.getPassword());
|
||||
|
||||
return loginLdapMode(userId, password);
|
||||
}
|
||||
|
||||
private AuthenticationInfo loginLdapMode(String userId, String password) {
|
||||
// userId 或 email 有一个相同就返回User
|
||||
String email = (String) SecurityUtils.getSubject().getSession().getAttribute("email");
|
||||
UserDTO user = userService.getLoginUser(userId, Arrays.asList(UserSource.LDAP.name(), UserSource.LOCAL.name()));
|
||||
String msg;
|
||||
if (user == null) {
|
||||
user = userService.getUserDTOByEmail(email, UserSource.LDAP.name(), UserSource.LOCAL.name());
|
||||
if (user == null) {
|
||||
msg = "The user does not exist: " + userId;
|
||||
logger.warn(msg);
|
||||
throw new UnknownAccountException(Translator.get("user_not_exist") + userId);
|
||||
}
|
||||
userId = user.getId();
|
||||
}
|
||||
|
||||
SessionUser sessionUser = SessionUser.fromUser(user);
|
||||
SessionUtils.putUser(sessionUser);
|
||||
return new SimpleAuthenticationInfo(userId, password, getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermitted(PrincipalCollection principals, String permission) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
package io.dataease.security.realm;
|
||||
|
||||
|
||||
import io.dataease.base.domain.Role;
|
||||
import io.dataease.commons.constants.UserSource;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.dto.UserDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.UserService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义Realm 注入service 可能会导致在 service的aop 失效,例如@Transactional,
|
||||
* 解决方法:
|
||||
* <p>
|
||||
* 1. 这里改成注入mapper,这样mapper 中的事务失效<br/>
|
||||
* 2. 这里仍然注入service,在配置ShiroConfig 的时候不去set realm, 等到spring 初始化完成之后
|
||||
* set realm
|
||||
* </p>
|
||||
*/
|
||||
public class ShiroDBRealm extends AuthorizingRealm {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ShiroDBRealm.class);
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Value("${run.mode:release}")
|
||||
private String runMode;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LOCAL";
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限认证
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
String userId = (String) principals.getPrimaryPrincipal();
|
||||
return getAuthorizationInfo(userId, userService);
|
||||
}
|
||||
|
||||
public static AuthorizationInfo getAuthorizationInfo(String userId, UserService userService) {
|
||||
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
|
||||
// roles 内容填充
|
||||
UserDTO userDTO = userService.getUserDTO(userId);
|
||||
Set<String> roles = userDTO.getRoles().stream().map(Role::getId).collect(Collectors.toSet());
|
||||
authorizationInfo.setRoles(roles);
|
||||
return authorizationInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录认证
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
|
||||
String login = (String) SecurityUtils.getSubject().getSession().getAttribute("authenticate");
|
||||
|
||||
String userId = token.getUsername();
|
||||
String password = String.valueOf(token.getPassword());
|
||||
|
||||
if (StringUtils.equals("local", runMode)) {
|
||||
UserDTO user = getUserWithOutAuthenticate(userId);
|
||||
userId = user.getId();
|
||||
SessionUser sessionUser = SessionUser.fromUser(user);
|
||||
SessionUtils.putUser(sessionUser);
|
||||
return new SimpleAuthenticationInfo(userId, password, getName());
|
||||
}
|
||||
|
||||
if (StringUtils.equals(login, UserSource.LOCAL.name())) {
|
||||
return loginLocalMode(userId, password);
|
||||
}
|
||||
|
||||
UserDTO user = getUserWithOutAuthenticate(userId);
|
||||
userId = user.getId();
|
||||
SessionUser sessionUser = SessionUser.fromUser(user);
|
||||
SessionUtils.putUser(sessionUser);
|
||||
return new SimpleAuthenticationInfo(userId, password, getName());
|
||||
|
||||
}
|
||||
|
||||
private UserDTO getUserWithOutAuthenticate(String userId) {
|
||||
UserDTO user = userService.getUserDTO(userId);
|
||||
String msg;
|
||||
if (user == null) {
|
||||
user = userService.getUserDTOByEmail(userId);
|
||||
if (user == null) {
|
||||
msg = "The user does not exist: " + userId;
|
||||
logger.warn(msg);
|
||||
throw new UnknownAccountException(Translator.get("password_is_incorrect"));
|
||||
}
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private AuthenticationInfo loginLocalMode(String userId, String password) {
|
||||
UserDTO user = userService.getLoginUser(userId, Collections.singletonList(UserSource.LOCAL.name()));
|
||||
String msg;
|
||||
if (user == null) {
|
||||
user = userService.getUserDTOByEmail(userId, UserSource.LOCAL.name());
|
||||
if (user == null) {
|
||||
msg = "The user does not exist: " + userId;
|
||||
logger.warn(msg);
|
||||
throw new UnknownAccountException(Translator.get("password_is_incorrect"));
|
||||
}
|
||||
userId = user.getId();
|
||||
}
|
||||
// 密码验证
|
||||
if (!userService.checkUserPassword(userId, password)) {
|
||||
throw new IncorrectCredentialsException(Translator.get("password_is_incorrect"));
|
||||
}
|
||||
SessionUser sessionUser = SessionUser.fromUser(user);
|
||||
SessionUtils.putUser(sessionUser);
|
||||
return new SimpleAuthenticationInfo(userId, password, getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermitted(PrincipalCollection principals, String permission) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package io.dataease.service;
|
||||
import io.dataease.base.domain.SystemParameter;
|
||||
import io.dataease.base.domain.SystemParameterExample;
|
||||
import io.dataease.base.mapper.SystemParameterMapper;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
@ -48,19 +48,15 @@ public class BaseDisplayService {
|
||||
if (bytes == null) {
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
|
||||
switch (imageName) {
|
||||
case "favicon":
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/favicon.ico")[0].getInputStream());
|
||||
contentType = MediaType.valueOf("image/vnd.microsoft.icon");
|
||||
break;
|
||||
case "logo":
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/logo-light-MeterSphere*.svg")[0].getInputStream());
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/logo-light-MeterSphere.*.svg")[0].getInputStream());
|
||||
contentType = MediaType.valueOf("image/svg+xml");
|
||||
break;
|
||||
case "loginImage":
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/info*.png")[0].getInputStream());
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/info.*.png")[0].getInputStream());
|
||||
break;
|
||||
case "loginLogo":
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/logo-dark-MeterSphere*.svg")[0].getInputStream());
|
||||
bytes = IOUtils.toByteArray(resolver.getResources("/static/img/logo-dark-MeterSphere.*.svg")[0].getInputStream());
|
||||
contentType = MediaType.valueOf("image/svg+xml");
|
||||
break;
|
||||
default:
|
||||
|
@ -85,13 +85,9 @@ public class FileService {
|
||||
}
|
||||
|
||||
public FileMetadata saveFile(MultipartFile file) {
|
||||
return saveFile(file,file.getOriginalFilename());
|
||||
}
|
||||
|
||||
public FileMetadata saveFile(MultipartFile file,String originalFilename) {
|
||||
final FileMetadata fileMetadata = new FileMetadata();
|
||||
fileMetadata.setId(UUID.randomUUID().toString());
|
||||
fileMetadata.setName(originalFilename);
|
||||
fileMetadata.setName(file.getOriginalFilename());
|
||||
fileMetadata.setSize(file.getSize());
|
||||
fileMetadata.setCreateTime(System.currentTimeMillis());
|
||||
fileMetadata.setUpdateTime(System.currentTimeMillis());
|
||||
|
@ -1,79 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.ServiceIntegration;
|
||||
import io.dataease.base.domain.ServiceIntegrationExample;
|
||||
import io.dataease.base.mapper.ServiceIntegrationMapper;
|
||||
import io.dataease.base.mapper.ext.ExtProjectMapper;
|
||||
import io.dataease.controller.request.IntegrationRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class IntegrationService {
|
||||
|
||||
@Resource
|
||||
private ServiceIntegrationMapper serviceIntegrationMapper;
|
||||
@Resource
|
||||
private ExtProjectMapper extProjectMapper;
|
||||
|
||||
public ServiceIntegration save(ServiceIntegration service) {
|
||||
ServiceIntegrationExample example = new ServiceIntegrationExample();
|
||||
example.createCriteria()
|
||||
.andOrganizationIdEqualTo(service.getOrganizationId())
|
||||
.andPlatformEqualTo(service.getPlatform());
|
||||
List<ServiceIntegration> list = serviceIntegrationMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
serviceIntegrationMapper.updateByExampleSelective(service, example);
|
||||
return list.get(0);
|
||||
} else {
|
||||
service.setId(UUID.randomUUID().toString());
|
||||
serviceIntegrationMapper.insertSelective(service);
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceIntegration get(IntegrationRequest request) {
|
||||
String platform = request.getPlatform();
|
||||
String orgId = request.getOrgId();
|
||||
ServiceIntegrationExample example = new ServiceIntegrationExample();
|
||||
ServiceIntegrationExample.Criteria criteria = example.createCriteria();
|
||||
|
||||
if (StringUtils.isNotBlank(platform)) {
|
||||
criteria.andPlatformEqualTo(platform);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(orgId)) {
|
||||
criteria.andOrganizationIdEqualTo(orgId);
|
||||
}
|
||||
|
||||
List<ServiceIntegration> list = serviceIntegrationMapper.selectByExampleWithBLOBs(example);
|
||||
return CollectionUtils.isEmpty(list) ? new ServiceIntegration() : list.get(0);
|
||||
}
|
||||
|
||||
public void delete(IntegrationRequest request) {
|
||||
String platform = request.getPlatform();
|
||||
String orgId = request.getOrgId();
|
||||
ServiceIntegrationExample example = new ServiceIntegrationExample();
|
||||
example.createCriteria()
|
||||
.andOrganizationIdEqualTo(orgId)
|
||||
.andPlatformEqualTo(platform);
|
||||
serviceIntegrationMapper.deleteByExample(example);
|
||||
// 删除项目关联的id/key
|
||||
extProjectMapper.removeIssuePlatform(platform, orgId);
|
||||
}
|
||||
|
||||
public List<ServiceIntegration> getAll(String orgId) {
|
||||
ServiceIntegrationExample example = new ServiceIntegrationExample();
|
||||
example.createCriteria().andOrganizationIdEqualTo(orgId);
|
||||
List<ServiceIntegration> list = serviceIntegrationMapper.selectByExample(example);
|
||||
return CollectionUtils.isEmpty(list) ? new ArrayList<>() : list;
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.dataease.base.domain.TestResource;
|
||||
import io.dataease.base.domain.TestResourceExample;
|
||||
import io.dataease.base.mapper.TestResourceMapper;
|
||||
import io.dataease.commons.constants.ResourceStatusEnum;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.dto.NodeDTO;
|
||||
import io.dataease.dto.TestResourcePoolDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.commons.constants.ResourceStatusEnum.VALID;
|
||||
|
||||
@Service
|
||||
public class NodeResourcePoolService {
|
||||
private final static String nodeControllerUrl = "http://%s:%s/status";
|
||||
|
||||
@Resource(name = "restTemplateWithTimeOut")
|
||||
private RestTemplate restTemplateWithTimeOut;
|
||||
@Resource
|
||||
private TestResourceMapper testResourceMapper;
|
||||
|
||||
public boolean validate(TestResourcePoolDTO testResourcePool) {
|
||||
if (CollectionUtils.isEmpty(testResourcePool.getResources())) {
|
||||
DEException.throwException(Translator.get("no_nodes_message"));
|
||||
}
|
||||
|
||||
deleteTestResource(testResourcePool.getId());
|
||||
List<ImmutablePair> Ip_Port = testResourcePool.getResources().stream()
|
||||
.map(resource -> {
|
||||
NodeDTO nodeDTO = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
|
||||
return new ImmutablePair(nodeDTO.getIp(), nodeDTO.getPort());
|
||||
})
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (Ip_Port.size() < testResourcePool.getResources().size()) {
|
||||
DEException.throwException(Translator.get("duplicate_node_ip_port"));
|
||||
}
|
||||
testResourcePool.setStatus(VALID.name());
|
||||
boolean isValid = true;
|
||||
for (TestResource resource : testResourcePool.getResources()) {
|
||||
NodeDTO nodeDTO = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
|
||||
boolean isValidate = validateNode(nodeDTO);
|
||||
if (!isValidate) {
|
||||
testResourcePool.setStatus(ResourceStatusEnum.INVALID.name());
|
||||
resource.setStatus(ResourceStatusEnum.INVALID.name());
|
||||
isValid = false;
|
||||
} else {
|
||||
resource.setStatus(VALID.name());
|
||||
}
|
||||
resource.setTestResourcePoolId(testResourcePool.getId());
|
||||
updateTestResource(resource);
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
||||
private boolean validateNode(NodeDTO node) {
|
||||
try {
|
||||
ResponseEntity<String> entity = restTemplateWithTimeOut.getForEntity(String.format(nodeControllerUrl, node.getIp(), node.getPort()), String.class);
|
||||
return HttpStatus.OK.equals(entity.getStatusCode());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTestResource(TestResource testResource) {
|
||||
testResource.setUpdateTime(System.currentTimeMillis());
|
||||
testResource.setCreateTime(System.currentTimeMillis());
|
||||
if (StringUtils.isBlank(testResource.getId())) {
|
||||
testResource.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
// 如果是更新操作,插入与原来的ID相同的数据
|
||||
testResourceMapper.insertSelective(testResource);
|
||||
}
|
||||
|
||||
private void deleteTestResource(String testResourcePoolId) {
|
||||
TestResourceExample testResourceExample = new TestResourceExample();
|
||||
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId);
|
||||
testResourceMapper.deleteByExample(testResourceExample);
|
||||
}
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.OrganizationMapper;
|
||||
import io.dataease.base.mapper.UserMapper;
|
||||
import io.dataease.base.mapper.UserRoleMapper;
|
||||
import io.dataease.base.mapper.WorkspaceMapper;
|
||||
import io.dataease.base.mapper.ext.ExtOrganizationMapper;
|
||||
import io.dataease.base.mapper.ext.ExtUserRoleMapper;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.request.OrganizationRequest;
|
||||
import io.dataease.dto.OrganizationMemberDTO;
|
||||
import io.dataease.dto.UserDTO;
|
||||
import io.dataease.dto.UserRoleHelpDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class OrganizationService {
|
||||
|
||||
@Resource
|
||||
private OrganizationMapper organizationMapper;
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
@Resource
|
||||
private ExtUserRoleMapper extUserRoleMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ExtOrganizationMapper extOrganizationMapper;
|
||||
@Resource
|
||||
private WorkspaceMapper workspaceMapper;
|
||||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
public Organization addOrganization(Organization organization) {
|
||||
checkOrganization(organization);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
organization.setId(UUID.randomUUID().toString());
|
||||
organization.setCreateTime(currentTimeMillis);
|
||||
organization.setUpdateTime(currentTimeMillis);
|
||||
organizationMapper.insertSelective(organization);
|
||||
return organization;
|
||||
}
|
||||
|
||||
public List<Organization> getOrganizationList(OrganizationRequest request) {
|
||||
OrganizationExample example = new OrganizationExample();
|
||||
OrganizationExample.Criteria criteria = example.createCriteria();
|
||||
if (StringUtils.isNotBlank(request.getName())) {
|
||||
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
|
||||
}
|
||||
example.setOrderByClause("update_time desc");
|
||||
return organizationMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
private void checkOrganization(Organization organization) {
|
||||
if (StringUtils.isBlank(organization.getName())) {
|
||||
DEException.throwException(Translator.get("organization_name_is_null"));
|
||||
}
|
||||
|
||||
OrganizationExample example = new OrganizationExample();
|
||||
OrganizationExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(organization.getName());
|
||||
if (StringUtils.isNotBlank(organization.getId())) {
|
||||
criteria.andIdNotEqualTo(organization.getId());
|
||||
}
|
||||
|
||||
if (organizationMapper.countByExample(example) > 0) {
|
||||
DEException.throwException(Translator.get("organization_name_already_exists"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteOrganization(String organizationId) {
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
WorkspaceExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andOrganizationIdEqualTo(organizationId);
|
||||
|
||||
// delete workspace
|
||||
List<Workspace> workspaces = workspaceMapper.selectByExample(example);
|
||||
List<String> workspaceIdList = workspaces.stream().map(Workspace::getId).collect(Collectors.toList());
|
||||
for (String workspaceId : workspaceIdList) {
|
||||
workspaceService.deleteWorkspace(workspaceId);
|
||||
}
|
||||
|
||||
// delete organization member
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andSourceIdEqualTo(organizationId);
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
|
||||
// delete org
|
||||
organizationMapper.deleteByPrimaryKey(organizationId);
|
||||
}
|
||||
|
||||
public void updateOrganization(Organization organization) {
|
||||
checkOrganization(organization);
|
||||
organization.setCreateTime(null);
|
||||
organization.setUpdateTime(System.currentTimeMillis());
|
||||
organizationMapper.updateByPrimaryKeySelective(organization);
|
||||
}
|
||||
|
||||
public List<Organization> getOrganizationListByUserId(String userId) {
|
||||
List<UserRoleHelpDTO> userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId);
|
||||
List<String> list = new ArrayList<>();
|
||||
userRoleHelpList.forEach(r -> {
|
||||
if (StringUtils.isEmpty(r.getParentId())) {
|
||||
list.add(r.getSourceId());
|
||||
} else {
|
||||
list.add(r.getParentId());
|
||||
}
|
||||
});
|
||||
|
||||
// ignore list size is 0
|
||||
list.add("no_such_id");
|
||||
|
||||
OrganizationExample organizationExample = new OrganizationExample();
|
||||
organizationExample.createCriteria().andIdIn(list);
|
||||
return organizationMapper.selectByExample(organizationExample);
|
||||
}
|
||||
|
||||
public void updateOrgMember(OrganizationMemberDTO memberDTO) {
|
||||
String orgId = memberDTO.getOrganizationId();
|
||||
String userId = memberDTO.getId();
|
||||
// 已有角色
|
||||
List<Role> memberRoles = extUserRoleMapper.getOrganizationMemberRoles(orgId, userId);
|
||||
// 修改后的角色
|
||||
List<String> roles = memberDTO.getRoleIds();
|
||||
List<String> allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList());
|
||||
// 更新用户时添加了角色
|
||||
for (int i = 0; i < roles.size(); i++) {
|
||||
if (checkSourceRole(orgId, userId, roles.get(i)) == 0) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(roles.get(i));
|
||||
userRole.setSourceId(orgId);
|
||||
userRole.setCreateTime(System.currentTimeMillis());
|
||||
userRole.setUpdateTime(System.currentTimeMillis());
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
}
|
||||
}
|
||||
allRoleIds.removeAll(roles);
|
||||
if (allRoleIds.size() > 0) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId)
|
||||
.andSourceIdEqualTo(orgId)
|
||||
.andRoleIdIn(allRoleIds);
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer checkSourceRole(String orgId, String userId, String roleId) {
|
||||
return extOrganizationMapper.checkSourceRole(orgId, userId, roleId);
|
||||
}
|
||||
|
||||
public void checkOrgOwner(String organizationId) {
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
UserDTO user = userService.getUserDTO(sessionUser.getId());
|
||||
List<String> collect = user.getUserRoles().stream()
|
||||
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()) || RoleConstants.ORG_MEMBER.equals(ur.getRoleId()))
|
||||
.map(UserRole::getSourceId)
|
||||
.collect(Collectors.toList());
|
||||
if (!collect.contains(organizationId)) {
|
||||
DEException.throwException(Translator.get("organization_does_not_belong_to_user"));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.Role;
|
||||
import io.dataease.base.mapper.RoleMapper;
|
||||
import io.dataease.base.mapper.ext.ExtRoleMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class RoleService {
|
||||
|
||||
@Resource
|
||||
private ExtRoleMapper extRoleMapper;
|
||||
@Resource
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
public List<Role> getRoleList(String sign) {
|
||||
return extRoleMapper.getRoleList(sign);
|
||||
}
|
||||
|
||||
public List<Role> getAllRole() {
|
||||
return roleMapper.selectByExample(null);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
public interface SSOService {
|
||||
void logout() throws Exception;
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.TestResource;
|
||||
import io.dataease.base.domain.TestResourceExample;
|
||||
import io.dataease.base.mapper.TestResourceMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestResourceService {
|
||||
|
||||
@Resource
|
||||
private TestResourceMapper testResourceMapper;
|
||||
|
||||
public TestResource addTestResource(TestResource testResource) {
|
||||
testResource.setId(UUID.randomUUID().toString());
|
||||
testResource.setStatus("1");
|
||||
testResource.setCreateTime(System.currentTimeMillis());
|
||||
testResource.setUpdateTime(System.currentTimeMillis());
|
||||
testResourceMapper.insertSelective(testResource);
|
||||
return testResource;
|
||||
}
|
||||
|
||||
public List<TestResource> getTestResourceList(String testResourcePoolId) {
|
||||
TestResourceExample testResourceExample = new TestResourceExample();
|
||||
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId);
|
||||
List<TestResource> testResources = testResourceMapper.selectByExampleWithBLOBs(testResourceExample);
|
||||
return testResources;
|
||||
}
|
||||
|
||||
public void deleteTestResource(String testResourceId) {
|
||||
testResourceMapper.deleteByPrimaryKey(testResourceId);
|
||||
}
|
||||
|
||||
public void updateTestResource(TestResource testResource) {
|
||||
testResource.setUpdateTime(System.currentTimeMillis());
|
||||
testResourceMapper.updateByPrimaryKeySelective(testResource);
|
||||
}
|
||||
|
||||
public List<TestResource> getResourcesByPoolId(String resourcePoolId) {
|
||||
TestResourceExample example = new TestResourceExample();
|
||||
example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
|
||||
return testResourceMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
|
||||
public TestResource getTestResource(String resourceId) {
|
||||
return testResourceMapper.selectByPrimaryKey(resourceId);
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.UserKey;
|
||||
import io.dataease.base.domain.UserKeyExample;
|
||||
import io.dataease.base.mapper.UserKeyMapper;
|
||||
import io.dataease.commons.constants.ApiKeyConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class UserKeyService {
|
||||
|
||||
@Resource
|
||||
private UserKeyMapper userKeyMapper;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
public List<UserKey> getUserKeysInfo(String userId) {
|
||||
UserKeyExample userKeysExample = new UserKeyExample();
|
||||
userKeysExample.createCriteria().andUserIdEqualTo(userId);
|
||||
userKeysExample.setOrderByClause("create_time");
|
||||
return userKeyMapper.selectByExample(userKeysExample);
|
||||
}
|
||||
|
||||
public UserKey generateUserKey(String userId) {
|
||||
if (userService.getUserDTO(userId) == null) {
|
||||
DEException.throwException(Translator.get("user_not_exist") + userId);
|
||||
}
|
||||
UserKeyExample userKeysExample = new UserKeyExample();
|
||||
userKeysExample.createCriteria().andUserIdEqualTo(userId);
|
||||
List<UserKey> userKeysList = userKeyMapper.selectByExample(userKeysExample);
|
||||
|
||||
if (!CollectionUtils.isEmpty(userKeysList) && userKeysList.size() >= 5) {
|
||||
DEException.throwException(Translator.get("user_apikey_limit"));
|
||||
}
|
||||
|
||||
UserKey userKeys = new UserKey();
|
||||
userKeys.setId(UUID.randomUUID().toString());
|
||||
userKeys.setUserId(userId);
|
||||
userKeys.setStatus(ApiKeyConstants.ACTIVE.name());
|
||||
userKeys.setAccessKey(RandomStringUtils.randomAlphanumeric(16));
|
||||
userKeys.setSecretKey(RandomStringUtils.randomAlphanumeric(16));
|
||||
userKeys.setCreateTime(System.currentTimeMillis());
|
||||
userKeyMapper.insert(userKeys);
|
||||
return userKeyMapper.selectByPrimaryKey(userKeys.getId());
|
||||
}
|
||||
|
||||
public void deleteUserKey(String id) {
|
||||
userKeyMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void activeUserKey(String id) {
|
||||
UserKey userKeys = new UserKey();
|
||||
userKeys.setId(id);
|
||||
userKeys.setStatus(ApiKeyConstants.ACTIVE.name());
|
||||
userKeyMapper.updateByPrimaryKeySelective(userKeys);
|
||||
}
|
||||
|
||||
public void disableUserKey(String id) {
|
||||
UserKey userKeys = new UserKey();
|
||||
userKeys.setId(id);
|
||||
userKeys.setStatus(ApiKeyConstants.DISABLED.name());
|
||||
userKeyMapper.updateByPrimaryKeySelective(userKeys);
|
||||
}
|
||||
|
||||
public UserKey getUserKey(String accessKey) {
|
||||
UserKeyExample userKeyExample = new UserKeyExample();
|
||||
userKeyExample.createCriteria().andAccessKeyEqualTo(accessKey).andStatusEqualTo(ApiKeyConstants.ACTIVE.name());
|
||||
List<UserKey> userKeysList = userKeyMapper.selectByExample(userKeyExample);
|
||||
if (!CollectionUtils.isEmpty(userKeysList)) {
|
||||
return userKeysList.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.Role;
|
||||
import io.dataease.base.domain.UserRole;
|
||||
import io.dataease.base.domain.UserRoleExample;
|
||||
import io.dataease.base.mapper.UserRoleMapper;
|
||||
import io.dataease.base.mapper.ext.ExtUserRoleMapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class UserRoleService {
|
||||
|
||||
@Resource
|
||||
private ExtUserRoleMapper extUserRoleMapper;
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
public List<Role> getOrganizationMemberRoles(String orgId, String userId) {
|
||||
return extUserRoleMapper.getOrganizationMemberRoles(orgId, userId);
|
||||
}
|
||||
|
||||
public List<Role> getWorkspaceMemberRoles(String workspaceId, String userId) {
|
||||
return extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getUserRole(String userId) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId);
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
List<String> collect = userRoles.stream()
|
||||
.map(userRole -> userRole.getRoleId())
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
for (int i = 0; i < collect.size(); i++) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("id", collect.get(i));
|
||||
map.put("ids", new ArrayList<>());
|
||||
for (int j = 0; j < userRoles.size(); j++) {
|
||||
String role = userRoles.get(j).getRoleId();
|
||||
if (StringUtils.equals(role, collect.get(i))) {
|
||||
List ids = (List) map.get("ids");
|
||||
ids.add(userRoles.get(j).getSourceId());
|
||||
}
|
||||
}
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -1,616 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.*;
|
||||
import io.dataease.base.mapper.ext.ExtUserMapper;
|
||||
import io.dataease.base.mapper.ext.ExtUserRoleMapper;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.constants.UserSource;
|
||||
import io.dataease.commons.constants.UserStatus;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.CodingUtil;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.ResultHolder;
|
||||
import io.dataease.controller.request.LoginRequest;
|
||||
import io.dataease.controller.request.member.AddMemberRequest;
|
||||
import io.dataease.controller.request.member.EditPassWordRequest;
|
||||
import io.dataease.controller.request.member.QueryMemberRequest;
|
||||
import io.dataease.controller.request.member.UserRequest;
|
||||
import io.dataease.controller.request.organization.AddOrgMemberRequest;
|
||||
import io.dataease.controller.request.organization.QueryOrgMemberRequest;
|
||||
import io.dataease.dto.UserDTO;
|
||||
import io.dataease.dto.UserRoleDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.notice.domain.UserDetail;
|
||||
import io.dataease.security.MsUserToken;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.commons.constants.SessionConstants.ATTR_USER;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class UserService {
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private RoleMapper roleMapper;
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
@Resource
|
||||
private ExtUserRoleMapper extUserRoleMapper;
|
||||
@Resource
|
||||
private OrganizationMapper organizationMapper;
|
||||
@Resource
|
||||
private WorkspaceMapper workspaceMapper;
|
||||
@Resource
|
||||
private ExtUserMapper extUserMapper;
|
||||
@Lazy
|
||||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
|
||||
public List<UserDetail> queryTypeByIds(List<String> userIds) {
|
||||
return extUserMapper.queryTypeByIds(userIds);
|
||||
}
|
||||
|
||||
public Map<String, User> queryNameByIds(List<String> userIds) {
|
||||
return extUserMapper.queryNameByIds(userIds);
|
||||
}
|
||||
|
||||
|
||||
public UserDTO insert(UserRequest user) {
|
||||
checkUserParam(user);
|
||||
//
|
||||
String id = user.getId();
|
||||
User user1 = userMapper.selectByPrimaryKey(id);
|
||||
if (user1 != null) {
|
||||
DEException.throwException(Translator.get("user_id_already_exists"));
|
||||
} else {
|
||||
createUser(user);
|
||||
}
|
||||
List<Map<String, Object>> roles = user.getRoles();
|
||||
if (!roles.isEmpty()) {
|
||||
insertUserRole(roles, user.getId());
|
||||
}
|
||||
return getUserDTO(user.getId());
|
||||
}
|
||||
|
||||
public User selectUser(String userId, String email) {
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
if (user == null) {
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andEmailEqualTo(email);
|
||||
List<User> users = userMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(users)) {
|
||||
return users.get(0);
|
||||
}
|
||||
}
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
private void insertUserRole(List<Map<String, Object>> roles, String userId) {
|
||||
for (int i = 0; i < roles.size(); i++) {
|
||||
Map<String, Object> map = roles.get(i);
|
||||
String role = (String) map.get("id");
|
||||
if (StringUtils.equals(role, RoleConstants.ADMIN)) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setUpdateTime(System.currentTimeMillis());
|
||||
userRole.setCreateTime(System.currentTimeMillis());
|
||||
userRole.setRoleId(role);
|
||||
// TODO 修改
|
||||
userRole.setSourceId("adminSourceId");
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
} else {
|
||||
// if (!map.keySet().contains("ids")) {
|
||||
// MSException.throwException(role + " no source id");
|
||||
// }
|
||||
List<String> list = (List<String>) map.get("ids");
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
UserRole userRole1 = new UserRole();
|
||||
userRole1.setId(UUID.randomUUID().toString());
|
||||
userRole1.setUserId(userId);
|
||||
userRole1.setRoleId(role);
|
||||
userRole1.setUpdateTime(System.currentTimeMillis());
|
||||
userRole1.setCreateTime(System.currentTimeMillis());
|
||||
userRole1.setSourceId(list.get(j));
|
||||
userRoleMapper.insertSelective(userRole1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUserParam(User user) {
|
||||
|
||||
if (StringUtils.isBlank(user.getId())) {
|
||||
DEException.throwException(Translator.get("user_id_is_null"));
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(user.getName())) {
|
||||
DEException.throwException(Translator.get("user_name_is_null"));
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(user.getEmail())) {
|
||||
DEException.throwException(Translator.get("user_email_is_null"));
|
||||
}
|
||||
// password
|
||||
}
|
||||
|
||||
public void createUser(User userRequest) {
|
||||
User user = new User();
|
||||
BeanUtils.copyProperties(userRequest, user);
|
||||
user.setCreateTime(System.currentTimeMillis());
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
// 默认1:启用状态
|
||||
user.setStatus(UserStatus.NORMAL);
|
||||
user.setSource(UserSource.LOCAL.name());
|
||||
// 密码使用 MD5
|
||||
user.setPassword(CodingUtil.md5(user.getPassword()));
|
||||
checkEmailIsExist(user.getEmail());
|
||||
userMapper.insertSelective(user);
|
||||
}
|
||||
|
||||
public void addLdapUser(User user) {
|
||||
user.setCreateTime(System.currentTimeMillis());
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
user.setStatus(UserStatus.NORMAL);
|
||||
checkEmailIsExist(user.getEmail());
|
||||
userMapper.insertSelective(user);
|
||||
}
|
||||
|
||||
public void createOssUser(User user) {
|
||||
user.setCreateTime(System.currentTimeMillis());
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
user.setStatus(UserStatus.NORMAL);
|
||||
if (StringUtils.isBlank(user.getEmail())) {
|
||||
user.setEmail(user.getId() + "@metershpere.io");
|
||||
}
|
||||
userMapper.insertSelective(user);
|
||||
}
|
||||
|
||||
|
||||
private void checkEmailIsExist(String email) {
|
||||
UserExample userExample = new UserExample();
|
||||
UserExample.Criteria criteria = userExample.createCriteria();
|
||||
criteria.andEmailEqualTo(email);
|
||||
List<User> userList = userMapper.selectByExample(userExample);
|
||||
if (!CollectionUtils.isEmpty(userList)) {
|
||||
DEException.throwException(Translator.get("user_email_already_exists"));
|
||||
}
|
||||
}
|
||||
|
||||
public UserDTO getUserDTO(String userId) {
|
||||
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
if (StringUtils.equals(user.getStatus(), UserStatus.DISABLED)) {
|
||||
throw new DisabledAccountException();
|
||||
}
|
||||
UserDTO userDTO = new UserDTO();
|
||||
BeanUtils.copyProperties(user, userDTO);
|
||||
UserRoleDTO userRole = getUserRole(userId);
|
||||
userDTO.setUserRoles(Optional.ofNullable(userRole.getUserRoles()).orElse(new ArrayList<>()));
|
||||
userDTO.setRoles(Optional.ofNullable(userRole.getRoles()).orElse(new ArrayList<>()));
|
||||
return userDTO;
|
||||
}
|
||||
|
||||
public UserDTO getLoginUser(String userId, List<String> list) {
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andIdEqualTo(userId).andSourceIn(list);
|
||||
if (userMapper.countByExample(example) == 0) {
|
||||
return null;
|
||||
}
|
||||
return getUserDTO(userId);
|
||||
}
|
||||
|
||||
public UserDTO getUserDTOByEmail(String email, String... source) {
|
||||
UserExample example = new UserExample();
|
||||
UserExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andEmailEqualTo(email);
|
||||
|
||||
if (!CollectionUtils.isEmpty(Arrays.asList(source))) {
|
||||
criteria.andSourceIn(Arrays.asList(source));
|
||||
}
|
||||
|
||||
List<User> users = userMapper.selectByExample(example);
|
||||
|
||||
if (users == null || users.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getUserDTO(users.get(0).getId());
|
||||
}
|
||||
|
||||
public UserRoleDTO getUserRole(String userId) {
|
||||
UserRoleDTO userRoleDTO = new UserRoleDTO();
|
||||
//
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId);
|
||||
List<UserRole> userRoleList = userRoleMapper.selectByExample(userRoleExample);
|
||||
|
||||
if (CollectionUtils.isEmpty(userRoleList)) {
|
||||
return userRoleDTO;
|
||||
}
|
||||
// 设置 user_role
|
||||
userRoleDTO.setUserRoles(userRoleList);
|
||||
|
||||
List<String> roleIds = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList());
|
||||
|
||||
RoleExample roleExample = new RoleExample();
|
||||
roleExample.createCriteria().andIdIn(roleIds);
|
||||
|
||||
List<Role> roleList = roleMapper.selectByExample(roleExample);
|
||||
userRoleDTO.setRoles(roleList);
|
||||
|
||||
return userRoleDTO;
|
||||
}
|
||||
|
||||
public List<User> getUserList() {
|
||||
UserExample example = new UserExample();
|
||||
example.setOrderByClause("update_time desc");
|
||||
return userMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<User> getUserListWithRequest(io.dataease.controller.request.UserRequest request) {
|
||||
return extUserMapper.getUserList(request);
|
||||
}
|
||||
|
||||
public void deleteUser(String userId) {
|
||||
SessionUser user = SessionUtils.getUser();
|
||||
if (StringUtils.equals(user.getId(), userId)) {
|
||||
DEException.throwException(Translator.get("cannot_delete_current_user"));
|
||||
}
|
||||
|
||||
UserRoleExample example = new UserRoleExample();
|
||||
example.createCriteria().andUserIdEqualTo(userId);
|
||||
userRoleMapper.deleteByExample(example);
|
||||
|
||||
userMapper.deleteByPrimaryKey(userId);
|
||||
}
|
||||
|
||||
public void updateUserRole(UserRequest user) {
|
||||
String userId = user.getId();
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId);
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
List<String> list = userRoles.stream().map(UserRole::getSourceId).collect(Collectors.toList());
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
if (list.contains(user.getLastWorkspaceId()) || list.contains(user.getLastOrganizationId())) {
|
||||
user.setLastOrganizationId("");
|
||||
user.setLastWorkspaceId("");
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
}
|
||||
}
|
||||
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
List<Map<String, Object>> roles = user.getRoles();
|
||||
if (!roles.isEmpty()) {
|
||||
insertUserRole(roles, user.getId());
|
||||
}
|
||||
|
||||
UserExample example = new UserExample();
|
||||
UserExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andEmailEqualTo(user.getEmail());
|
||||
criteria.andIdNotEqualTo(user.getId());
|
||||
if (userMapper.countByExample(example) > 0) {
|
||||
DEException.throwException(Translator.get("user_email_already_exists"));
|
||||
}
|
||||
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
}
|
||||
|
||||
public void updateUser(User user) {
|
||||
// todo 提取重复代码
|
||||
if (StringUtils.isNotBlank(user.getEmail())) {
|
||||
UserExample example = new UserExample();
|
||||
UserExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andEmailEqualTo(user.getEmail());
|
||||
criteria.andIdNotEqualTo(user.getId());
|
||||
if (userMapper.countByExample(example) > 0) {
|
||||
DEException.throwException(Translator.get("user_email_already_exists"));
|
||||
}
|
||||
}
|
||||
user.setPassword(null);
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
// 禁用用户之后,剔除在线用户
|
||||
if (StringUtils.equals(user.getStatus(), UserStatus.DISABLED)) {
|
||||
SessionUtils.kickOutUser(user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void switchUserRole(String sign, String sourceId) {
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
// 获取最新UserDTO
|
||||
UserDTO user = getUserDTO(sessionUser.getId());
|
||||
User newUser = new User();
|
||||
|
||||
if (StringUtils.equals("organization", sign)) {
|
||||
user.setLastOrganizationId(sourceId);
|
||||
List<Workspace> workspaces = workspaceService.getWorkspaceListByOrgIdAndUserId(sourceId);
|
||||
if (workspaces.size() > 0) {
|
||||
user.setLastWorkspaceId(workspaces.get(0).getId());
|
||||
} else {
|
||||
user.setLastWorkspaceId("");
|
||||
}
|
||||
}
|
||||
if (StringUtils.equals("workspace", sign)) {
|
||||
Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId);
|
||||
user.setLastOrganizationId(workspace.getOrganizationId());
|
||||
user.setLastWorkspaceId(sourceId);
|
||||
}
|
||||
BeanUtils.copyProperties(user, newUser);
|
||||
// 切换工作空间或组织之后更新 session 里的 user
|
||||
SessionUtils.putUser(SessionUser.fromUser(user));
|
||||
userMapper.updateByPrimaryKeySelective(newUser);
|
||||
}
|
||||
|
||||
public UserDTO getUserInfo(String userId) {
|
||||
return getUserDTO(userId);
|
||||
}
|
||||
|
||||
public List<User> getMemberList(QueryMemberRequest request) {
|
||||
return extUserRoleMapper.getMemberList(request);
|
||||
}
|
||||
|
||||
public void addMember(AddMemberRequest request) {
|
||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
for (String userId : request.getUserIds()) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getWorkspaceId());
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
if (userRoles.size() > 0) {
|
||||
DEException.throwException(Translator.get("user_already_exists"));
|
||||
} else {
|
||||
for (String roleId : request.getRoleIds()) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.setSourceId(request.getWorkspaceId());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUpdateTime(System.currentTimeMillis());
|
||||
userRole.setCreateTime(System.currentTimeMillis());
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteMember(String workspaceId, String userId) {
|
||||
UserRoleExample example = new UserRoleExample();
|
||||
example.createCriteria().andRoleIdLike("%test%")
|
||||
.andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId);
|
||||
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
if (StringUtils.equals(workspaceId, user.getLastWorkspaceId())) {
|
||||
user.setLastWorkspaceId("");
|
||||
user.setLastOrganizationId("");
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
}
|
||||
|
||||
userRoleMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void addOrganizationMember(AddOrgMemberRequest request) {
|
||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||
for (String userId : request.getUserIds()) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getOrganizationId());
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
if (userRoles.size() > 0) {
|
||||
DEException.throwException(Translator.get("user_already_exists") + ": " + userId);
|
||||
} else {
|
||||
for (String roleId : request.getRoleIds()) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setRoleId(roleId);
|
||||
userRole.setSourceId(request.getOrganizationId());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setUpdateTime(System.currentTimeMillis());
|
||||
userRole.setCreateTime(System.currentTimeMillis());
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delOrganizationMember(String organizationId, String userId) {
|
||||
|
||||
List<String> resourceIds = workspaceService.getWorkspaceIdsOrgId(organizationId);
|
||||
resourceIds.add(organizationId);
|
||||
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId).andSourceIdIn(resourceIds);
|
||||
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
if (StringUtils.equals(organizationId, user.getLastOrganizationId())) {
|
||||
user.setLastWorkspaceId("");
|
||||
user.setLastOrganizationId("");
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
}
|
||||
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
}
|
||||
|
||||
public List<User> getOrgMemberList(QueryOrgMemberRequest request) {
|
||||
return extUserRoleMapper.getOrgMemberList(request);
|
||||
}
|
||||
|
||||
public boolean checkUserPassword(String userId, String password) {
|
||||
if (StringUtils.isBlank(userId)) {
|
||||
DEException.throwException(Translator.get("user_name_is_null"));
|
||||
}
|
||||
if (StringUtils.isBlank(password)) {
|
||||
DEException.throwException(Translator.get("password_is_null"));
|
||||
}
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andIdEqualTo(userId).andPasswordEqualTo(CodingUtil.md5(password));
|
||||
return userMapper.countByExample(example) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询该组织外的其他用户列表
|
||||
*/
|
||||
public List<User> getBesideOrgMemberList(String orgId) {
|
||||
return extUserRoleMapper.getBesideOrgMemberList(orgId);
|
||||
}
|
||||
|
||||
public void setLanguage(String lang) {
|
||||
if (SessionUtils.getUser() != null) {
|
||||
User user = new User();
|
||||
user.setId(SessionUtils.getUser().getId());
|
||||
user.setLanguage(lang);
|
||||
updateUser(user);
|
||||
SessionUtils.getUser().setLanguage(lang);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshSessionUser(String sign, String sourceId) {
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
// 获取最新UserDTO
|
||||
UserDTO user = getUserDTO(sessionUser.getId());
|
||||
User newUser = new User();
|
||||
if (StringUtils.equals("organization", sign) && StringUtils.equals(sourceId, user.getLastOrganizationId())) {
|
||||
user.setLastOrganizationId("");
|
||||
user.setLastWorkspaceId("");
|
||||
}
|
||||
if (StringUtils.equals("workspace", sign) && StringUtils.equals(sourceId, user.getLastWorkspaceId())) {
|
||||
user.setLastWorkspaceId("");
|
||||
}
|
||||
|
||||
BeanUtils.copyProperties(user, newUser);
|
||||
|
||||
SessionUtils.putUser(SessionUser.fromUser(user));
|
||||
userMapper.updateByPrimaryKeySelective(newUser);
|
||||
}
|
||||
|
||||
|
||||
/*修改当前用户用户密码*/
|
||||
private User updateCurrentUserPwd(EditPassWordRequest request) {
|
||||
String oldPassword = CodingUtil.md5(request.getPassword(), "utf-8");
|
||||
String newPassword = request.getNewpassword();
|
||||
UserExample userExample = new UserExample();
|
||||
userExample.createCriteria().andIdEqualTo(SessionUtils.getUser().getId()).andPasswordEqualTo(oldPassword);
|
||||
List<User> users = userMapper.selectByExample(userExample);
|
||||
if (!CollectionUtils.isEmpty(users)) {
|
||||
User user = users.get(0);
|
||||
user.setPassword(CodingUtil.md5(newPassword));
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
return user;
|
||||
}
|
||||
DEException.throwException(Translator.get("password_modification_failed"));
|
||||
return null;
|
||||
}
|
||||
|
||||
public int updateCurrentUserPassword(EditPassWordRequest request) {
|
||||
User user = updateCurrentUserPwd(request);
|
||||
return extUserMapper.updatePassword(user);
|
||||
}
|
||||
|
||||
/*管理员修改用户密码*/
|
||||
private User updateUserPwd(EditPassWordRequest request) {
|
||||
User user = userMapper.selectByPrimaryKey(request.getId());
|
||||
String newPassword = request.getNewpassword();
|
||||
user.setPassword(CodingUtil.md5(newPassword));
|
||||
user.setUpdateTime(System.currentTimeMillis());
|
||||
return user;
|
||||
}
|
||||
|
||||
public int updateUserPassword(EditPassWordRequest request) {
|
||||
User user = updateUserPwd(request);
|
||||
return extUserMapper.updatePassword(user);
|
||||
}
|
||||
|
||||
public String getDefaultLanguage() {
|
||||
final String key = "default.language";
|
||||
return extUserMapper.getDefaultLanguage(key);
|
||||
}
|
||||
|
||||
public List<User> getTestManagerAndTestUserList(QueryMemberRequest request) {
|
||||
return extUserRoleMapper.getTestManagerAndTestUserList(request);
|
||||
}
|
||||
|
||||
public ResultHolder login(LoginRequest request) {
|
||||
String login = (String) SecurityUtils.getSubject().getSession().getAttribute("authenticate");
|
||||
String username = StringUtils.trim(request.getUsername());
|
||||
String password = "";
|
||||
if (!StringUtils.equals(login, UserSource.LDAP.name())) {
|
||||
password = StringUtils.trim(request.getPassword());
|
||||
if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
|
||||
return ResultHolder.error("user or password can't be null");
|
||||
}
|
||||
}
|
||||
|
||||
MsUserToken token = new MsUserToken(username, password, login);
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
try {
|
||||
subject.login(token);
|
||||
if (subject.isAuthenticated()) {
|
||||
UserDTO user = (UserDTO) subject.getSession().getAttribute(ATTR_USER);
|
||||
// 自动选中组织,工作空间
|
||||
if (StringUtils.isEmpty(user.getLastOrganizationId())) {
|
||||
List<UserRole> userRoles = user.getUserRoles();
|
||||
List<UserRole> test = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("test")).collect(Collectors.toList());
|
||||
List<UserRole> org = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("org")).collect(Collectors.toList());
|
||||
if (test.size() > 0) {
|
||||
String wsId = test.get(0).getSourceId();
|
||||
switchUserRole("workspace", wsId);
|
||||
} else if (org.size() > 0) {
|
||||
String orgId = org.get(0).getSourceId();
|
||||
switchUserRole("organization", orgId);
|
||||
}
|
||||
}
|
||||
// 返回 userDTO
|
||||
return ResultHolder.success(subject.getSession().getAttribute("user"));
|
||||
} else {
|
||||
return ResultHolder.error(Translator.get("login_fail"));
|
||||
}
|
||||
} catch (ExcessiveAttemptsException e) {
|
||||
throw new ExcessiveAttemptsException(Translator.get("excessive_attempts"));
|
||||
} catch (LockedAccountException e) {
|
||||
throw new LockedAccountException(Translator.get("user_locked"));
|
||||
} catch (DisabledAccountException e) {
|
||||
throw new DisabledAccountException(Translator.get("user_has_been_disabled"));
|
||||
} catch (ExpiredCredentialsException e) {
|
||||
throw new ExpiredCredentialsException(Translator.get("user_expires"));
|
||||
} catch (AuthenticationException e) {
|
||||
throw new AuthenticationException(e.getMessage());
|
||||
} catch (UnauthorizedException e) {
|
||||
throw new UnauthorizedException(Translator.get("not_authorized") + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public List<User> searchUser(String condition) {
|
||||
return extUserMapper.searchUser(condition);
|
||||
}
|
||||
|
||||
public void logout() throws Exception {
|
||||
SSOService ssoService = CommonBeanFactory.getBean(SSOService.class);
|
||||
if (ssoService != null) {
|
||||
ssoService.logout();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,285 +0,0 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.ProjectMapper;
|
||||
import io.dataease.base.mapper.UserMapper;
|
||||
import io.dataease.base.mapper.UserRoleMapper;
|
||||
import io.dataease.base.mapper.WorkspaceMapper;
|
||||
import io.dataease.base.mapper.ext.ExtOrganizationMapper;
|
||||
import io.dataease.base.mapper.ext.ExtUserRoleMapper;
|
||||
import io.dataease.base.mapper.ext.ExtWorkspaceMapper;
|
||||
import io.dataease.commons.constants.RoleConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.user.SessionUser;
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
import io.dataease.controller.request.WorkspaceRequest;
|
||||
import io.dataease.dto.UserDTO;
|
||||
import io.dataease.dto.UserRoleHelpDTO;
|
||||
import io.dataease.dto.WorkspaceDTO;
|
||||
import io.dataease.dto.WorkspaceMemberDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class WorkspaceService {
|
||||
@Resource
|
||||
private WorkspaceMapper workspaceMapper;
|
||||
@Resource
|
||||
private ExtWorkspaceMapper extWorkspaceMapper;
|
||||
@Resource
|
||||
private ExtUserRoleMapper extUserRoleMapper;
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ExtOrganizationMapper extOrganizationMapper;
|
||||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
public Workspace saveWorkspace(Workspace workspace) {
|
||||
if (StringUtils.isBlank(workspace.getName())) {
|
||||
DEException.throwException(Translator.get("workspace_name_is_null"));
|
||||
}
|
||||
// set organization id
|
||||
String currentOrgId = SessionUtils.getCurrentOrganizationId();
|
||||
workspace.setOrganizationId(currentOrgId);
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
checkWorkspace(workspace);
|
||||
|
||||
if (StringUtils.isBlank(workspace.getId())) {
|
||||
workspace.setId(UUID.randomUUID().toString());
|
||||
workspace.setCreateTime(currentTime);
|
||||
workspace.setUpdateTime(currentTime);
|
||||
workspaceMapper.insertSelective(workspace);
|
||||
} else {
|
||||
workspace.setUpdateTime(currentTime);
|
||||
workspaceMapper.updateByPrimaryKeySelective(workspace);
|
||||
}
|
||||
return workspace;
|
||||
}
|
||||
|
||||
public List<Workspace> getWorkspaceList(WorkspaceRequest request) {
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
WorkspaceExample.Criteria criteria = example.createCriteria();
|
||||
if (StringUtils.isNotBlank(request.getOrganizationId())) {
|
||||
criteria.andOrganizationIdEqualTo(request.getOrganizationId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getName())) {
|
||||
criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%"));
|
||||
}
|
||||
example.setOrderByClause("update_time desc");
|
||||
return workspaceMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<WorkspaceDTO> getAllWorkspaceList(WorkspaceRequest request) {
|
||||
if (StringUtils.isNotBlank(request.getName())) {
|
||||
request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));
|
||||
}
|
||||
return extWorkspaceMapper.getWorkspaceWithOrg(request);
|
||||
}
|
||||
|
||||
public void deleteWorkspace(String workspaceId) {
|
||||
// delete project
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
|
||||
List<Project> projectList = projectMapper.selectByExample(projectExample);
|
||||
List<String> projectIdList = projectList.stream().map(Project::getId).collect(Collectors.toList());
|
||||
projectIdList.forEach(projectId -> {
|
||||
// projectService.deleteProject(projectId);
|
||||
});
|
||||
|
||||
// delete workspace member
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andSourceIdEqualTo(workspaceId);
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
|
||||
// delete workspace
|
||||
workspaceMapper.deleteByPrimaryKey(workspaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* ORG_ADMIN需要检查是否有操作此工作空间的权限
|
||||
*/
|
||||
public void checkWorkspaceOwnerByOrgAdmin(String workspaceId) {
|
||||
checkWorkspaceIsExist(workspaceId);
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
UserDTO user = userService.getUserDTO(sessionUser.getId());
|
||||
List<String> orgIds = user.getUserRoles().stream()
|
||||
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
||||
.map(UserRole::getSourceId)
|
||||
.collect(Collectors.toList());
|
||||
example.createCriteria()
|
||||
.andOrganizationIdIn(orgIds)
|
||||
.andIdEqualTo(workspaceId);
|
||||
if (workspaceMapper.countByExample(example) == 0) {
|
||||
DEException.throwException(Translator.get("workspace_does_not_belong_to_user"));
|
||||
}
|
||||
}
|
||||
|
||||
public void checkWorkspaceOwner(String workspaceId) {
|
||||
checkWorkspaceIsExist(workspaceId);
|
||||
int size = 0;
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
UserDTO user = userService.getUserDTO(sessionUser.getId());
|
||||
List<String> orgIds = user.getUserRoles().stream()
|
||||
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
||||
.map(UserRole::getSourceId)
|
||||
.collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(orgIds)) {
|
||||
example.createCriteria()
|
||||
.andOrganizationIdIn(orgIds)
|
||||
.andIdEqualTo(workspaceId);
|
||||
size = (int) workspaceMapper.countByExample(example);
|
||||
}
|
||||
List<String> wsIds = user.getUserRoles().stream()
|
||||
.filter(ur -> RoleConstants.TEST_MANAGER.equals(ur.getRoleId()))
|
||||
.map(UserRole::getSourceId)
|
||||
.collect(Collectors.toList());
|
||||
boolean contains = wsIds.contains(workspaceId);
|
||||
if (size == 0 && !contains) {
|
||||
DEException.throwException(Translator.get("workspace_does_not_belong_to_user"));
|
||||
}
|
||||
}
|
||||
|
||||
public void checkWorkspaceIsExist(String workspaceId) {
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
example.createCriteria().andIdEqualTo(workspaceId);
|
||||
if (workspaceMapper.countByExample(example) == 0) {
|
||||
DEException.throwException(Translator.get("workspace_not_exists"));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Workspace> getWorkspaceListByUserId(String userId) {
|
||||
List<UserRoleHelpDTO> userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId);
|
||||
List<String> workspaceIds = new ArrayList<>();
|
||||
userRoleHelpList.forEach(r -> {
|
||||
if (!StringUtils.isEmpty(r.getParentId())) {
|
||||
workspaceIds.add(r.getSourceId());
|
||||
}
|
||||
});
|
||||
WorkspaceExample workspaceExample = new WorkspaceExample();
|
||||
workspaceExample.createCriteria().andIdIn(workspaceIds);
|
||||
return workspaceMapper.selectByExample(workspaceExample);
|
||||
}
|
||||
|
||||
public List<Workspace> getWorkspaceListByOrgIdAndUserId(String orgId) {
|
||||
String useId = SessionUtils.getUser().getId();
|
||||
WorkspaceExample workspaceExample = new WorkspaceExample();
|
||||
workspaceExample.createCriteria().andOrganizationIdEqualTo(orgId);
|
||||
List<Workspace> workspaces = workspaceMapper.selectByExample(workspaceExample);
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(useId);
|
||||
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
|
||||
List<Workspace> resultWorkspaceList = new ArrayList<>();
|
||||
userRoles.forEach(userRole -> {
|
||||
workspaces.forEach(workspace -> {
|
||||
if (StringUtils.equals(userRole.getSourceId(), workspace.getId())) {
|
||||
if (!resultWorkspaceList.contains(workspace)) {
|
||||
resultWorkspaceList.add(workspace);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return resultWorkspaceList;
|
||||
}
|
||||
|
||||
public List<String> getWorkspaceIdsOrgId(String orgId) {
|
||||
return extWorkspaceMapper.getWorkspaceIdsByOrgId(orgId);
|
||||
}
|
||||
|
||||
public void updateWorkspaceMember(WorkspaceMemberDTO memberDTO) {
|
||||
String workspaceId = memberDTO.getWorkspaceId();
|
||||
String userId = memberDTO.getId();
|
||||
// 已有角色
|
||||
List<Role> memberRoles = extUserRoleMapper.getWorkspaceMemberRoles(workspaceId, userId);
|
||||
// 修改后的角色
|
||||
List<String> roles = memberDTO.getRoleIds();
|
||||
List<String> allRoleIds = memberRoles.stream().map(Role::getId).collect(Collectors.toList());
|
||||
// 更新用户时添加了角色
|
||||
for (int i = 0; i < roles.size(); i++) {
|
||||
if (checkSourceRole(workspaceId, userId, roles.get(i)) == 0) {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setId(UUID.randomUUID().toString());
|
||||
userRole.setUserId(userId);
|
||||
userRole.setRoleId(roles.get(i));
|
||||
userRole.setSourceId(workspaceId);
|
||||
userRole.setCreateTime(System.currentTimeMillis());
|
||||
userRole.setUpdateTime(System.currentTimeMillis());
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
}
|
||||
}
|
||||
allRoleIds.removeAll(roles);
|
||||
if (allRoleIds.size() > 0) {
|
||||
UserRoleExample userRoleExample = new UserRoleExample();
|
||||
userRoleExample.createCriteria().andUserIdEqualTo(userId)
|
||||
.andSourceIdEqualTo(workspaceId)
|
||||
.andRoleIdIn(allRoleIds);
|
||||
userRoleMapper.deleteByExample(userRoleExample);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer checkSourceRole(String workspaceId, String userId, String roleId) {
|
||||
return extOrganizationMapper.checkSourceRole(workspaceId, userId, roleId);
|
||||
}
|
||||
|
||||
public void updateWorkspaceByAdmin(Workspace workspace) {
|
||||
checkWorkspace(workspace);
|
||||
workspace.setCreateTime(null);
|
||||
workspace.setUpdateTime(System.currentTimeMillis());
|
||||
workspaceMapper.updateByPrimaryKeySelective(workspace);
|
||||
}
|
||||
|
||||
public Workspace addWorkspaceByAdmin(Workspace workspace) {
|
||||
checkWorkspace(workspace);
|
||||
workspace.setId(UUID.randomUUID().toString());
|
||||
workspace.setCreateTime(System.currentTimeMillis());
|
||||
workspace.setUpdateTime(System.currentTimeMillis());
|
||||
workspaceMapper.insertSelective(workspace);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
private void checkWorkspace(Workspace workspace) {
|
||||
if (StringUtils.isBlank(workspace.getName())) {
|
||||
DEException.throwException(Translator.get("workspace_name_is_null"));
|
||||
}
|
||||
if (StringUtils.isBlank(workspace.getOrganizationId())) {
|
||||
DEException.throwException(Translator.get("organization_id_is_null"));
|
||||
}
|
||||
|
||||
WorkspaceExample example = new WorkspaceExample();
|
||||
WorkspaceExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(workspace.getName())
|
||||
.andOrganizationIdEqualTo(workspace.getOrganizationId());
|
||||
if (StringUtils.isNotBlank(workspace.getId())) {
|
||||
criteria.andIdNotEqualTo(workspace.getId());
|
||||
}
|
||||
|
||||
if (workspaceMapper.countByExample(example) > 0) {
|
||||
DEException.throwException(Translator.get("workspace_name_already_exists"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Project> getProjects(String workspaceId) {
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
|
||||
return projectMapper.selectByExample(projectExample);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package io.dataease.service.chart;
|
||||
|
||||
import io.dataease.base.domain.ChartGroup;
|
||||
import io.dataease.base.domain.ChartGroupExample;
|
||||
import io.dataease.base.mapper.ChartGroupMapper;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.request.chart.ChartGroupRequest;
|
||||
import io.dataease.dto.chart.ChartGroupDTO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
public class ChartGroupService {
|
||||
@Resource
|
||||
private ChartGroupMapper chartGroupMapper;
|
||||
|
||||
public ChartGroupDTO save(ChartGroup chartGroup) {
|
||||
if (StringUtils.isEmpty(chartGroup.getId())) {
|
||||
chartGroup.setId(UUID.randomUUID().toString());
|
||||
chartGroup.setCreateTime(System.currentTimeMillis());
|
||||
chartGroupMapper.insert(chartGroup);
|
||||
} else {
|
||||
chartGroupMapper.updateByPrimaryKey(chartGroup);
|
||||
}
|
||||
ChartGroupDTO ChartGroupDTO = new ChartGroupDTO();
|
||||
BeanUtils.copyBean(ChartGroupDTO, chartGroup);
|
||||
ChartGroupDTO.setLabel(ChartGroupDTO.getName());
|
||||
return ChartGroupDTO;
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
ChartGroupRequest ChartGroup = new ChartGroupRequest();
|
||||
ChartGroup.setId(id);
|
||||
List<ChartGroupDTO> tree = tree(ChartGroup);
|
||||
List<String> ids = new ArrayList<>();
|
||||
getAllId(tree, ids);
|
||||
ChartGroupExample ChartGroupExample = new ChartGroupExample();
|
||||
ChartGroupExample.createCriteria().andIdIn(ids);
|
||||
chartGroupMapper.deleteByExample(ChartGroupExample);
|
||||
}
|
||||
|
||||
public List<ChartGroupDTO> tree(ChartGroupRequest ChartGroup) {
|
||||
ChartGroupExample ChartGroupExample = new ChartGroupExample();
|
||||
ChartGroupExample.Criteria criteria = ChartGroupExample.createCriteria();
|
||||
if (StringUtils.isNotEmpty(ChartGroup.getName())) {
|
||||
criteria.andNameLike("%" + ChartGroup.getName() + "%");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(ChartGroup.getType())) {
|
||||
criteria.andTypeEqualTo(ChartGroup.getType());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(ChartGroup.getId())) {
|
||||
criteria.andIdEqualTo(ChartGroup.getId());
|
||||
} else {
|
||||
criteria.andLevelEqualTo(0);
|
||||
}
|
||||
ChartGroupExample.setOrderByClause(ChartGroup.getSort());
|
||||
List<ChartGroup> ChartGroups = chartGroupMapper.selectByExample(ChartGroupExample);
|
||||
List<ChartGroupDTO> DTOs = ChartGroups.stream().map(ele -> {
|
||||
ChartGroupDTO dto = new ChartGroupDTO();
|
||||
BeanUtils.copyBean(dto, ele);
|
||||
dto.setLabel(ele.getName());
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
getAll(DTOs, ChartGroup);
|
||||
return DTOs;
|
||||
}
|
||||
|
||||
public void getAll(List<ChartGroupDTO> list, ChartGroupRequest ChartGroup) {
|
||||
for (ChartGroupDTO obj : list) {
|
||||
ChartGroupExample ChartGroupExample = new ChartGroupExample();
|
||||
ChartGroupExample.Criteria criteria = ChartGroupExample.createCriteria();
|
||||
if (StringUtils.isNotEmpty(ChartGroup.getName())) {
|
||||
criteria.andNameLike("%" + ChartGroup.getName() + "%");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(ChartGroup.getType())) {
|
||||
criteria.andTypeEqualTo(ChartGroup.getType());
|
||||
}
|
||||
criteria.andPidEqualTo(obj.getId());
|
||||
ChartGroupExample.setOrderByClause(ChartGroup.getSort());
|
||||
List<ChartGroup> ChartGroups = chartGroupMapper.selectByExample(ChartGroupExample);
|
||||
List<ChartGroupDTO> DTOs = ChartGroups.stream().map(ele -> {
|
||||
ChartGroupDTO dto = new ChartGroupDTO();
|
||||
BeanUtils.copyBean(dto, ele);
|
||||
dto.setLabel(ele.getName());
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
obj.setChildren(DTOs);
|
||||
if (CollectionUtils.isNotEmpty(DTOs)) {
|
||||
getAll(DTOs, ChartGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getAllId(List<ChartGroupDTO> list, List<String> ids) {
|
||||
for (ChartGroupDTO dto : list) {
|
||||
ids.add(dto.getId());
|
||||
if (CollectionUtils.isNotEmpty(dto.getChildren())) {
|
||||
getAllId(dto.getChildren(), ids);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
}
|
@ -8,7 +8,8 @@ import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.sys.request.MenuCreateRequest;
|
||||
import io.dataease.controller.sys.request.MenuDeleteRequest;
|
||||
import io.dataease.controller.sys.response.MenuNodeResponse;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -13,16 +13,14 @@ import io.dataease.controller.sys.request.SysUserCreateRequest;
|
||||
import io.dataease.controller.sys.request.UserGridRequest;
|
||||
import io.dataease.controller.sys.response.SysUserGridResponse;
|
||||
import io.dataease.controller.sys.response.SysUserRole;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
public class SysUserService {
|
||||
|
@ -1,269 +0,0 @@
|
||||
package io.dataease.service.system;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.dataease.base.domain.FileMetadata;
|
||||
import io.dataease.base.domain.SystemParameter;
|
||||
import io.dataease.base.domain.SystemParameterExample;
|
||||
import io.dataease.base.mapper.FileContentMapper;
|
||||
import io.dataease.base.mapper.FileMetadataMapper;
|
||||
import io.dataease.base.mapper.SystemParameterMapper;
|
||||
import io.dataease.base.mapper.ext.ExtSystemParameterMapper;
|
||||
import io.dataease.commons.constants.ParamConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.EncryptUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.dto.BaseSystemConfigDTO;
|
||||
import io.dataease.dto.SystemParameterDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.notice.domain.MailInfo;
|
||||
import io.dataease.service.FileService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.FileStore;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class SystemParameterService {
|
||||
|
||||
@Resource
|
||||
private SystemParameterMapper systemParameterMapper;
|
||||
@Resource
|
||||
private ExtSystemParameterMapper extSystemParameterMapper;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
|
||||
public String searchEmail() {
|
||||
return extSystemParameterMapper.email();
|
||||
}
|
||||
|
||||
public String getSystemLanguage() {
|
||||
String result = StringUtils.EMPTY;
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
example.createCriteria().andParamKeyEqualTo(ParamConstants.I18n.LANGUAGE.getValue());
|
||||
List<SystemParameter> list = systemParameterMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
String value = list.get(0).getParamValue();
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void editMail(List<SystemParameter> parameters) {
|
||||
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
boolean empty = paramList.size() <= 0;
|
||||
|
||||
parameters.forEach(parameter -> {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
if (parameter.getParamKey().equals(ParamConstants.MAIL.PASSWORD.getValue())) {
|
||||
if (!StringUtils.isBlank(parameter.getParamValue())) {
|
||||
String string = EncryptUtils.aesEncrypt(parameter.getParamValue()).toString();
|
||||
parameter.setParamValue(string);
|
||||
}
|
||||
}
|
||||
example.createCriteria().andParamKeyEqualTo(parameter.getParamKey());
|
||||
if (systemParameterMapper.countByExample(example) > 0) {
|
||||
systemParameterMapper.updateByPrimaryKey(parameter);
|
||||
} else {
|
||||
systemParameterMapper.insert(parameter);
|
||||
}
|
||||
example.clear();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public List<SystemParameter> getParamList(String type) {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
example.createCriteria().andParamKeyLike(type + "%");
|
||||
return systemParameterMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public void testConnection(HashMap<String, String> hashMap) {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.SERVER.getValue()));
|
||||
javaMailSender.setPort(Integer.valueOf(hashMap.get(ParamConstants.MAIL.PORT.getValue())));
|
||||
javaMailSender.setUsername(hashMap.get(ParamConstants.MAIL.ACCOUNT.getValue()));
|
||||
javaMailSender.setPassword(hashMap.get(ParamConstants.MAIL.PASSWORD.getValue()));
|
||||
Properties props = new Properties();
|
||||
String recipients = hashMap.get(ParamConstants.MAIL.RECIPIENTS.getValue());
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.SSL.getValue()))) {
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
}
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.TLS.getValue()))) {
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
}
|
||||
props.put("mail.smtp.timeout", "30000");
|
||||
props.put("mail.smtp.connectiontimeout", "5000");
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
try {
|
||||
javaMailSender.testConnection();
|
||||
} catch (MessagingException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
if(!StringUtils.isBlank(recipients)){
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = null;
|
||||
try {
|
||||
helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("MeterSphere测试邮件 " );
|
||||
helper.setText("这是一封测试邮件,邮件发送成功", true);
|
||||
helper.setTo(recipients);
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MessagingException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return System.getenv("MS_VERSION");
|
||||
}
|
||||
|
||||
public MailInfo mailInfo(String type) {
|
||||
List<SystemParameter> paramList = this.getParamList(type);
|
||||
MailInfo mailInfo=new MailInfo ();
|
||||
if (!CollectionUtils.isEmpty(paramList)) {
|
||||
for (SystemParameter param : paramList) {
|
||||
if (StringUtils.equals(param.getParamKey(),ParamConstants.MAIL.SERVER.getValue() )) {
|
||||
mailInfo.setHost(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.PORT.getValue())) {
|
||||
mailInfo.setPort(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.ACCOUNT.getValue())) {
|
||||
mailInfo.setAccount(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.PASSWORD.getValue())) {
|
||||
String password = EncryptUtils.aesDecrypt(param.getParamValue()).toString();
|
||||
mailInfo.setPassword(password);
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.SSL.getValue())) {
|
||||
mailInfo.setSsl(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.TLS.getValue())) {
|
||||
mailInfo.setTls(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.RECIPIENTS.getValue())) {
|
||||
mailInfo.setRecipient(param.getParamValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return mailInfo;
|
||||
}
|
||||
|
||||
public void saveLdap(List<SystemParameter> parameters) {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
parameters.forEach(param -> {
|
||||
if (param.getParamKey().equals(ParamConstants.LDAP.PASSWORD.getValue())) {
|
||||
String string = EncryptUtils.aesEncrypt(param.getParamValue()).toString();
|
||||
param.setParamValue(string);
|
||||
}
|
||||
example.createCriteria().andParamKeyEqualTo(param.getParamKey());
|
||||
if (systemParameterMapper.countByExample(example) > 0) {
|
||||
systemParameterMapper.updateByPrimaryKey(param);
|
||||
} else {
|
||||
systemParameterMapper.insert(param);
|
||||
}
|
||||
example.clear();
|
||||
});
|
||||
}
|
||||
|
||||
public String getValue(String key) {
|
||||
SystemParameter param = systemParameterMapper.selectByPrimaryKey(key);
|
||||
if (param == null) {
|
||||
return null;
|
||||
}
|
||||
return param.getParamValue();
|
||||
}
|
||||
|
||||
|
||||
public List<SystemParameterDTO> getSystemParameterInfo(String paramConstantsType) {
|
||||
List<SystemParameter> paramList = this.getParamList(paramConstantsType);
|
||||
List<SystemParameterDTO> dtoList = new ArrayList<>();
|
||||
for (SystemParameter systemParameter : paramList) {
|
||||
SystemParameterDTO systemParameterDTO = new SystemParameterDTO();
|
||||
BeanUtils.copyBean(systemParameterDTO, systemParameter);
|
||||
if (systemParameter.getType().equalsIgnoreCase("file")) {
|
||||
FileMetadata fileMetadata = fileService.getFileMetadataById(systemParameter.getParamValue());
|
||||
if (fileMetadata != null) {
|
||||
systemParameterDTO.setFileName(fileMetadata.getName());
|
||||
}
|
||||
}
|
||||
dtoList.add(systemParameterDTO);
|
||||
}
|
||||
dtoList.sort(Comparator.comparingInt(SystemParameter::getSort));
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void saveUIInfo(Map<String,List<SystemParameterDTO>> request, List<MultipartFile> bodyFiles) throws IOException {
|
||||
List<SystemParameterDTO> parameters = request.get("systemParams");
|
||||
for (MultipartFile multipartFile : bodyFiles) {
|
||||
if (!multipartFile.isEmpty()) {
|
||||
//防止添加非图片文件
|
||||
try (InputStream input = multipartFile.getInputStream()) {
|
||||
try {
|
||||
// It's an image (only BMP, GIF, JPG and PNG are recognized).
|
||||
ImageIO.read(input).toString();
|
||||
} catch (Exception e) {
|
||||
DEException.throwException("Uploaded images do not meet the image format requirements");
|
||||
return;
|
||||
}
|
||||
}
|
||||
String multipartFileName = multipartFile.getOriginalFilename();
|
||||
String[] split = Objects.requireNonNull(multipartFileName).split(",");
|
||||
parameters.stream().filter(systemParameterDTO -> systemParameterDTO.getParamKey().equalsIgnoreCase(split[1])).forEach(systemParameterDTO -> {
|
||||
systemParameterDTO.setFileName(split[0]);
|
||||
systemParameterDTO.setFile(multipartFile);
|
||||
});
|
||||
}
|
||||
}
|
||||
for (SystemParameterDTO systemParameter : parameters) {
|
||||
MultipartFile file = systemParameter.getFile();
|
||||
if (systemParameter.getType().equalsIgnoreCase("file")) {
|
||||
if (StringUtils.isBlank(systemParameter.getFileName())) {
|
||||
fileService.deleteFileById(systemParameter.getParamValue());
|
||||
}
|
||||
if (file != null) {
|
||||
fileService.deleteFileById(systemParameter.getParamValue());
|
||||
FileMetadata fileMetadata = fileService.saveFile(systemParameter.getFile(),systemParameter.getFileName());
|
||||
systemParameter.setParamValue(fileMetadata.getId());
|
||||
}
|
||||
if (file == null && systemParameter.getFileName() == null) {
|
||||
systemParameter.setParamValue(null);
|
||||
}
|
||||
}
|
||||
systemParameterMapper.deleteByPrimaryKey(systemParameter.getParamKey());
|
||||
systemParameterMapper.insert(systemParameter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String info="[{\"paramKey\":\"base.url\",\"paramValue\":null,\"type\":\"text\",\"sort\":1,\"file\":null,\"fileName\":null},{\"paramKey\":\"base.title\",\"paramValue\":\"DataEase Title\",\"type\":\"text\",\"sort\":3,\"file\":null,\"fileName\":null},{\"paramKey\":\"base.logo\",\"paramValue\":\"DataEase\",\"type\":\"text\",\"sort\":4,\"file\":null,\"fileName\":\"favicon.icon.png\"}]";
|
||||
List<SystemParameterDTO> temp = JSON.parseArray(info,SystemParameterDTO.class);
|
||||
System.out.println("===>");
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package io.dataease.websocket;
|
||||
|
||||
import io.dataease.commons.utils.SessionUtils;
|
||||
|
||||
import javax.websocket.HandshakeResponse;
|
||||
import javax.websocket.server.HandshakeRequest;
|
||||
@ -10,8 +9,8 @@ public class ServerEndpointConfigurator extends ServerEndpointConfig.Configurato
|
||||
@Override
|
||||
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
|
||||
// 将用户信息存储到socket的配置里
|
||||
System.out.println(SessionUtils.getUser());
|
||||
sec.getUserProperties().put("user", SessionUtils.getUser());
|
||||
// System.out.println(SessionUtils.getUser());
|
||||
// sec.getUserProperties().put("user", SessionUtils.getUser());
|
||||
super.modifyHandshake(sec, request, response);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
-- chart start
|
||||
CREATE TABLE IF NOT EXISTS `chart_group` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'ID',
|
||||
`name` varchar(64) NOT NULL COMMENT '名称',
|
||||
`pid` varchar(50) COMMENT '父级ID',
|
||||
`level` int(10) COMMENT '当前分组处于第几级',
|
||||
`type` varchar(50) COMMENT 'group or scene',
|
||||
`create_by` varchar(50) COMMENT '创建人ID',
|
||||
`create_time` bigint(13) COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
-- chart end
|
@ -44,6 +44,7 @@ CREATE TABLE IF NOT EXISTS `sys_menu` (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sys_role` (
|
||||
`role_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`code` varchar(100) NOT NULL COMMENT '代码',
|
||||
`name` varchar(255) NOT NULL COMMENT '名称',
|
||||
`description` varchar(255) DEFAULT NULL COMMENT '描述',
|
||||
`create_by` varchar(255) DEFAULT NULL COMMENT '创建者',
|
||||
|
@ -64,7 +64,7 @@
|
||||
|
||||
<!--要生成的数据库表 -->
|
||||
|
||||
<table tableName="chart_group"/>
|
||||
<table tableName="datasource"/>
|
||||
|
||||
|
||||
</context>
|
||||
|
@ -52,7 +52,8 @@
|
||||
"sass": "^1.26.10",
|
||||
"sass-loader": "^7.1.0",
|
||||
"svgo": "1.2.0",
|
||||
"svg-sprite-loader": "4.1.3"
|
||||
"svg-sprite-loader": "4.1.3",
|
||||
"js-cookie": "2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^4.1.0",
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 107 KiB |
@ -30,7 +30,7 @@ import MsUser from "./components/common/head/HeaderUser";
|
||||
// import MsHeaderOrgWs from "./components/common/head/HeaderOrgWs";
|
||||
import MsLanguageSwitch from "./components/common/head/LanguageSwitch";
|
||||
import {saveLocalStorage} from "@/common/js/utils";
|
||||
|
||||
import {getToken} from '@/utils/auth'
|
||||
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
|
||||
const header = requireComponent.keys().length > 0 ? requireComponent("./license/LicenseMessage.vue") : {};
|
||||
const display = requireComponent.keys().length > 0 ? requireComponent("./display/Display.vue") : {};
|
||||
@ -41,7 +41,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
licenseHeader: null,
|
||||
auth: false,
|
||||
auth: true,
|
||||
header: {},
|
||||
logoId: '_blank',
|
||||
}
|
||||
@ -50,30 +50,29 @@ export default {
|
||||
if (localStorage.getItem("store")) {
|
||||
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem("store"))))
|
||||
}
|
||||
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem("store"))))
|
||||
window.addEventListener("beforeunload", () => {
|
||||
localStorage.setItem("store", JSON.stringify(this.$store.state))
|
||||
})
|
||||
},
|
||||
beforeCreate() {
|
||||
this.$get("/isLogin").then(response => {
|
||||
if (response.data.success) {
|
||||
this.$setLang(response.data.data.language);
|
||||
saveLocalStorage(response.data);
|
||||
if(getToken()){
|
||||
this.$setLang('zh_CN');
|
||||
//saveLocalStorage(response.data);
|
||||
this.auth = true;
|
||||
// 是否显示校验信息
|
||||
if (header.default !== undefined) {
|
||||
this.licenseHeader = "LicenseMessage";
|
||||
}
|
||||
|
||||
this.licenseHeader = "LicenseMessage";
|
||||
if (display.default !== undefined) {
|
||||
display.default.showHome(this);
|
||||
}
|
||||
} else {
|
||||
window.location.href = "/login"
|
||||
}
|
||||
}).catch(() => {
|
||||
//display.default.showHome(this);
|
||||
}else{
|
||||
window.location.href = "/login"
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
components: {
|
||||
MsLanguageSwitch,
|
||||
|
@ -1,45 +0,0 @@
|
||||
<template>
|
||||
<ms-container>
|
||||
|
||||
<ms-aside-container>
|
||||
<group/>
|
||||
</ms-aside-container>
|
||||
|
||||
<ms-main-container>
|
||||
<keep-alive>
|
||||
<router-view/>
|
||||
</keep-alive>
|
||||
</ms-main-container>
|
||||
</ms-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MsMainContainer from "../common/components/MsMainContainer";
|
||||
import MsContainer from "../common/components/MsContainer";
|
||||
import MsAsideContainer from "../common/components/MsAsideContainer";
|
||||
import MsSettingMenu from "../settings/SettingMenu";
|
||||
import MsCurrentUser from "../settings/CurrentUser";
|
||||
import Group from "./group/Group";
|
||||
|
||||
export default {
|
||||
name: "Chart",
|
||||
components: {MsMainContainer, MsContainer, MsAsideContainer, MsSettingMenu, MsCurrentUser, Group},
|
||||
data() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ms-aside-container {
|
||||
height: calc(100vh - 40px);
|
||||
padding: 15px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.ms-main-container {
|
||||
height: calc(100vh - 40px);
|
||||
}
|
||||
|
||||
</style>
|
@ -1,148 +0,0 @@
|
||||
<template>
|
||||
<el-col>
|
||||
<el-row>
|
||||
<el-row style="height: 26px;">
|
||||
<span style="line-height: 26px;">
|
||||
{{$t('dataset.add_db_table')}}
|
||||
</span>
|
||||
<el-row style="float: right">
|
||||
<el-button size="mini" @click="cancel">
|
||||
{{$t('dataset.cancel')}}
|
||||
</el-button>
|
||||
<el-button size="mini" type="primary" @click="save" :disabled="checkTableList.length < 1">
|
||||
{{$t('dataset.confirm')}}
|
||||
</el-button>
|
||||
</el-row>
|
||||
</el-row>
|
||||
<el-divider/>
|
||||
<el-row>
|
||||
<el-form :inline="true">
|
||||
<el-form-item class="form-item">
|
||||
<el-select v-model="dataSource" filterable :placeholder="$t('dataset.pls_slc_data_source')" size="mini">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item class="form-item" style="float: right;">
|
||||
<el-input
|
||||
size="mini"
|
||||
:placeholder="$t('dataset.search')"
|
||||
prefix-icon="el-icon-search"
|
||||
v-model="searchTable"
|
||||
clearable>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-row>
|
||||
<el-row style="overflow: auto;height: 600px;">
|
||||
<el-checkbox-group v-model="checkTableList" size="small">
|
||||
<el-checkbox
|
||||
border
|
||||
v-for="t in tables"
|
||||
:label="t"
|
||||
:key="t">
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-row>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "AddDB",
|
||||
data() {
|
||||
return {
|
||||
searchTable: '',
|
||||
options: [],
|
||||
dataSource: '',
|
||||
tables: [],
|
||||
checkTableList: [],
|
||||
scene: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initDataSource();
|
||||
this.scene = this.$route.params.scene;
|
||||
},
|
||||
activated() {
|
||||
this.initDataSource();
|
||||
this.scene = this.$route.params.scene;
|
||||
},
|
||||
methods: {
|
||||
initDataSource() {
|
||||
this.$get("/datasource/list", response => {
|
||||
this.options = response.data;
|
||||
})
|
||||
},
|
||||
|
||||
save() {
|
||||
// console.log(this.checkTableList);
|
||||
// console.log(this.scene);
|
||||
let sceneId = this.scene.id;
|
||||
let dataSourceId = this.dataSource;
|
||||
let tables = [];
|
||||
this.checkTableList.forEach(function (name) {
|
||||
tables.push({
|
||||
name: name,
|
||||
sceneId: sceneId,
|
||||
dataSourceId: dataSourceId,
|
||||
type: 'db'
|
||||
})
|
||||
});
|
||||
this.$post('/dataset/table/batchAdd', tables, response => {
|
||||
this.$store.commit('setSceneData', new Date().getTime());
|
||||
this.cancel();
|
||||
});
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.dataReset();
|
||||
this.$router.push("/dataset/home");
|
||||
},
|
||||
|
||||
dataReset() {
|
||||
this.searchTable = '';
|
||||
this.options = [];
|
||||
this.dataSource = '';
|
||||
this.tables = [];
|
||||
this.checkTableList = [];
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
dataSource(val) {
|
||||
if (val) {
|
||||
this.$post("/datasource/getTables", {id: val}, response => {
|
||||
this.tables = response.data;
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-divider--horizontal {
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.el-checkbox {
|
||||
margin-bottom: 14px;
|
||||
margin-left: 0;
|
||||
margin-right: 14px;
|
||||
}
|
||||
|
||||
.el-checkbox.is-bordered + .el-checkbox.is-bordered {
|
||||
margin-left: 0;
|
||||
}
|
||||
</style>
|
@ -1,25 +0,0 @@
|
||||
<template>
|
||||
<el-col style="height: 100%;">
|
||||
<el-row style="height: 100%;" class="custom-position">
|
||||
{{$t('chart.pls_slc_tbl_left')}}
|
||||
</el-row>
|
||||
</el-col>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "ChartHome"
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.custom-position {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 14px;
|
||||
flex-flow: row nowrap;
|
||||
color: #9ea6b2;
|
||||
}
|
||||
</style>
|
@ -1,62 +0,0 @@
|
||||
<template>
|
||||
<el-col>
|
||||
<el-table
|
||||
size="mini"
|
||||
:data="data"
|
||||
border
|
||||
style="width: 100%;">
|
||||
<el-table-column
|
||||
width="180px"
|
||||
v-for="field in fields"
|
||||
:key="field.fieldName"
|
||||
:prop="field.fieldName"
|
||||
:label="field.fieldName">
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-col>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
table: Object,
|
||||
fields: Array,
|
||||
data: Array
|
||||
},
|
||||
name: "TabDataPreview",
|
||||
data() {
|
||||
return {
|
||||
tableData: [{
|
||||
date: '2016-05-02',
|
||||
name: '王小虎',
|
||||
address: '上海市普陀区金沙江路 1518 弄'
|
||||
}, {
|
||||
date: '2016-05-04',
|
||||
name: '王小虎',
|
||||
address: '上海市普陀区金沙江路 1517 弄'
|
||||
}, {
|
||||
date: '2016-05-01',
|
||||
name: '王小虎',
|
||||
address: '上海市普陀区金沙江路 1519 弄'
|
||||
}, {
|
||||
date: '2016-05-03',
|
||||
name: '王小虎',
|
||||
address: '上海市普陀区金沙江路 1516 弄'
|
||||
}]
|
||||
}
|
||||
},
|
||||
computed: {},
|
||||
created() {
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
activated() {
|
||||
},
|
||||
methods: {},
|
||||
watch: {}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@ -1,122 +0,0 @@
|
||||
<template>
|
||||
<el-col>
|
||||
<el-row>
|
||||
<el-row style="height: 26px;">
|
||||
<span v-show="false">{{tableId}}</span>
|
||||
<span style="line-height: 26px;">
|
||||
{{table.name}}
|
||||
</span>
|
||||
<el-row style="float: right">
|
||||
<el-button size="mini">
|
||||
{{$t('dataset.edit')}}
|
||||
</el-button>
|
||||
<el-button size="mini">
|
||||
{{$t('dataset.create_view')}}
|
||||
</el-button>
|
||||
</el-row>
|
||||
</el-row>
|
||||
<el-divider/>
|
||||
|
||||
<el-tabs v-model="tabActive">
|
||||
<el-tab-pane :label="$t('dataset.data_preview')" name="dataPreview">
|
||||
<tab-data-preview :table="table" :fields="fields" :data="data"/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="tab2" name="tab2">
|
||||
tab2
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="tab3" name="tab3">
|
||||
tab3
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="tab4" name="tab4">
|
||||
tab4
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import TabDataPreview from "./TabDataPreview";
|
||||
|
||||
export default {
|
||||
name: "ViewTable",
|
||||
components: {TabDataPreview},
|
||||
data() {
|
||||
return {
|
||||
table: {
|
||||
name: ''
|
||||
},
|
||||
fields: [],
|
||||
data: [],
|
||||
tabActive: 'dataPreview',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
tableId() {
|
||||
console.log(this.$store.state.dataset.table);
|
||||
this.initTable(this.$store.state.dataset.table);
|
||||
return this.$store.state.dataset.table;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.resetTable();
|
||||
},
|
||||
mounted() {
|
||||
this.resetTable();
|
||||
},
|
||||
activated() {
|
||||
this.resetTable();
|
||||
},
|
||||
methods: {
|
||||
initTable(id) {
|
||||
if (id !== null) {
|
||||
this.fields = [];
|
||||
this.data = [];
|
||||
this.$post('/dataset/table/get/' + id, null, response => {
|
||||
this.table = response.data;
|
||||
this.initPreviewData();
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
initPreviewData() {
|
||||
if (this.table.id) {
|
||||
this.$post('/dataset/table/getPreviewData', this.table, response => {
|
||||
this.fields = response.data.fields;
|
||||
this.data = response.data.data;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
initTableFields() {
|
||||
if (this.table.id) {
|
||||
this.$post('/dataset/table/getFields', this.table, response => {
|
||||
});
|
||||
}
|
||||
},
|
||||
initTableData() {
|
||||
if (this.table.id) {
|
||||
this.$post('/dataset/table/getData', this.table, response => {
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
resetTable() {
|
||||
this.table = {
|
||||
name: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-divider--horizontal {
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
</style>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user