Merge pull request #1371 from dataease/dev

Dev
This commit is contained in:
fit2cloudrd 2021-12-02 10:03:20 +08:00 committed by GitHub
commit cddd363852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
326 changed files with 7912 additions and 5473 deletions

View File

@ -2,6 +2,12 @@ FROM registry.cn-qingdao.aliyuncs.com/dataease/fabric8-java-alpine-openjdk8-jre
ARG IMAGE_TAG
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk add chromium=77.0.3865.120-r0 --no-cache
RUN apk add chromium-chromedriver=77.0.3865.120-r0 --no-cache
RUN mkdir -p /opt/apps
RUN mkdir -p /opt/dataease/data/feature/full

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>dataease-server</artifactId>
<groupId>io.dataease</groupId>
<version>1.4.0</version>
<version>1.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -21,6 +21,12 @@
</properties>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@ -201,7 +207,7 @@
<dependency>
<groupId>io.dataease</groupId>
<artifactId>dataease-plugin-interface</artifactId>
<version>1.4</version>
<version>1.5</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
@ -244,6 +250,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -8,6 +8,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableCaching
@SpringBootApplication(exclude = {
QuartzAutoConfiguration.class,

View File

@ -30,8 +30,7 @@ public interface AuthApi {
CurrentUserDto userInfo();
/*@GetMapping("/isLogin")
Boolean isLogin();*/
@ApiOperation("登出")

View File

@ -11,7 +11,6 @@ public class CurrentRoleDto implements Serializable {
@ApiModelProperty("ID")
private Long id;
// private String code;
@ApiModelProperty("名称")
private String name;
}

View File

@ -20,6 +20,8 @@ import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -44,9 +46,9 @@ public class F2CRealm extends AuthorizingRealm {
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Long userId = JWTUtils.tokenInfoByToken(principals.toString()).getUserId();
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
Set<String> role = authUserService.roles(userId).stream().collect(Collectors.toSet());
Set<String> role = new HashSet<>(authUserService.roles(userId));
simpleAuthorizationInfo.addRoles(role);
Set<String> permission = authUserService.permissions(userId).stream().collect(Collectors.toSet());
Set<String> permission = new HashSet<>(authUserService.permissions(userId));
simpleAuthorizationInfo.addStringPermissions(permission);
return simpleAuthorizationInfo;
}
@ -79,8 +81,8 @@ public class F2CRealm extends AuthorizingRealm {
throw new AuthenticationException("license error");
}
TokenInfo tokenInfo = null;
String token = null;
TokenInfo tokenInfo;
String token;
try {
token = (String) auth.getCredentials();
// 解密获得username用于和数据库进行对比
@ -94,14 +96,7 @@ public class F2CRealm extends AuthorizingRealm {
if (username == null) {
throw new AuthenticationException("token invalid");
}
// 使用缓存
/*SysUserEntity user = authUserService.getUserById(userId);
if (user == null) {
throw new AuthenticationException("User didn't existed!");
}
if (user.getEnabled()==0) {
throw new AuthenticationException("User is valid!");
}*/
SysUserEntity user = userWithId(userId);
String pass = null;
try {
@ -112,13 +107,7 @@ public class F2CRealm extends AuthorizingRealm {
if (! JWTUtils.verify(token, tokenInfo, pass)) {
throw new AuthenticationException("Username or password error");
}
/*// 使用缓存
List<CurrentRoleDto> currentRoleDtos = authUserService.roleInfos(user.getUserId());
// 使用缓存
List<String> permissions = authUserService.permissions(user.getUserId());
CurrentUserDto currentUserDto = BeanUtils.copyBean(new CurrentUserDto(), user);
currentUserDto.setRoles(currentRoleDtos);
currentUserDto.setPermissions(permissions);*/
CurrentUserDto currentUserDto = queryCacheUserDto(user);
return new SimpleAuthenticationInfo(currentUserDto, token, "f2cReam");
}

View File

@ -20,9 +20,6 @@ import org.springframework.context.annotation.DependsOn;
@Configuration
public class ShiroConfig {
@Bean("securityManager")
public DefaultWebSecurityManager getManager(F2CRealm f2cRealm) {
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();

View File

@ -3,6 +3,7 @@ package io.dataease.auth.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data

View File

@ -13,9 +13,7 @@ public class TokenInfo implements Serializable {
private Long userId;
/* private String idToken; */
public String format(){
return username + "," +userId;
public String format() {
return username + "," + userId;
}
}

View File

@ -4,32 +4,28 @@ import cn.hutool.core.util.ObjectUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import io.dataease.auth.config.RsaProperties;
import io.dataease.auth.util.JWTUtils;
import io.dataease.auth.util.LinkUtil;
import io.dataease.auth.util.RsaUtil;
import io.dataease.base.domain.PanelLink;
import io.dataease.commons.utils.LogUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.web.filter.authc.AnonymousFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class F2CLinkFilter extends AnonymousFilter {
private static final Logger logger = LoggerFactory.getLogger(F2CLogoutFilter.class);
private static final String LINK_TOKEN_KEY = "LINK-PWD-TOKEN";
@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) {
try{
try {
HttpServletRequest req = (HttpServletRequest) request;
String link_token = req.getHeader(LINK_TOKEN_KEY);
DecodedJWT jwt = JWT.decode(link_token);
String linkToken = req.getHeader(LINK_TOKEN_KEY);
DecodedJWT jwt = JWT.decode(linkToken);
Claim resourceId = jwt.getClaim("resourceId");
String id = resourceId.asString();
PanelLink panelLink = LinkUtil.queryLink(id);
@ -38,12 +34,11 @@ public class F2CLinkFilter extends AnonymousFilter {
if (!panelLink.getEnablePwd()) {
panelLink.setPwd("dataease");
pwd = panelLink.getPwd();
}else {
/* pwd = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, panelLink.getPwd()); */
} else {
pwd = panelLink.getPwd();
}
return JWTUtils.verifyLink(link_token, id, pwd);
}catch (Exception e) {
return JWTUtils.verifyLink(linkToken, id, pwd);
} catch (Exception e) {
LogUtil.error(e);
}
return false;
@ -51,6 +46,4 @@ public class F2CLinkFilter extends AnonymousFilter {
}
}

View File

@ -4,6 +4,7 @@ import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@ -18,7 +19,7 @@ public class F2CLogoutFilter extends LogoutFilter {
try {
subject.logout();
} catch (Exception ex) {
logger.error("退出登录错误",ex);
logger.error("退出登录错误", ex);
}
return true;
}

View File

@ -1,5 +1,6 @@
package io.dataease.auth.filter;
import com.auth0.jwt.algorithms.Algorithm;
import io.dataease.auth.entity.ASKToken;
import io.dataease.auth.entity.JWTToken;
import io.dataease.auth.entity.SysUserEntity;
@ -19,6 +20,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
@ -27,7 +29,6 @@ import javax.servlet.http.HttpServletResponse;
public class JWTFilter extends BasicHttpAuthenticationFilter {
private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
public final static String expireMessage = "Login token is expire.";
@ -53,11 +54,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
if (ApiKeyHandler.isApiKeyCall(httpServletRequest)) {
// Long userId = ApiKeyHandler.getUser(httpServletRequest);
ASKToken askToken = ApiKeyHandler.buildToken(httpServletRequest);
// UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userId.toString(), ApiKeyHandler.random);
getSubject(request, response).login(askToken);
return true;
}
@ -67,10 +66,10 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
return false;
}
// 当没有出现登录超时 且需要刷新token 则执行刷新token
if (JWTUtils.loginExpire(authorization)){
if (JWTUtils.loginExpire(authorization)) {
throw new AuthenticationException(expireMessage);
}
if (JWTUtils.needRefresh(authorization)){
if (JWTUtils.needRefresh(authorization)) {
authorization = refreshToken(request, response);
}
JWTToken token = new JWTToken(authorization);
@ -81,8 +80,8 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
}
/**
*
*/
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
@ -95,9 +94,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
return loginSuccess;
} catch (Exception e) {
LogUtil.error(e);
if (e instanceof AuthenticationException && StringUtils.equals(e.getMessage(), expireMessage)){
if (e instanceof AuthenticationException && StringUtils.equals(e.getMessage(), expireMessage)) {
responseExpire(request, response, e);
}else {
} else {
tokenError(request, response, e);
}
}
@ -106,22 +105,20 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
}
private String refreshToken(ServletRequest request, ServletResponse response) throws Exception{
private String refreshToken(ServletRequest request, ServletResponse response) throws Exception {
// 获取AccessToken(Shiro中getAuthzHeader方法已经实现)
String token = this.getAuthzHeader(request);
// 获取当前Token的帐号信息
TokenInfo tokenInfo = JWTUtils.tokenInfoByToken(token);
AuthUserService authUserService = CommonBeanFactory.getBean(AuthUserService.class);
SysUserEntity user = authUserService.getUserById(tokenInfo.getUserId());
if(user == null){
if (user == null) {
DataEaseException.throwException(Translator.get("i18n_not_find_user"));
}
String password = user.getPassword();
Algorithm algorithm = Algorithm.HMAC256(password);
JWTUtils.verifySign(algorithm, token);
String newToken = JWTUtils.sign(tokenInfo, password);
// 设置响应的Header头新Token
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.addHeader("Access-Control-Expose-Headers", "RefreshAuthorization");

View File

@ -16,7 +16,6 @@ public class ApiKeyHandler {
public static final String API_SIGNATURE = "signature";
public static String random = UUID.randomUUID().toString() + UUID.randomUUID().toString();
public static Long getUser(HttpServletRequest request) {

View File

@ -43,16 +43,12 @@ public class AuthServer implements AuthApi {
@Autowired
private AuthUserService authUserService;
@Autowired
private SysUserService sysUserService;
@Override
public Object login(@RequestBody LoginDto loginDto) throws Exception {
String username = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, loginDto.getUsername());;
String username = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, loginDto.getUsername());
String pwd = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, loginDto.getPassword());
// 增加ldap登录方式
@ -67,16 +63,19 @@ public class AuthServer implements AuthApi {
}
XpackLdapUserEntity ldapUserEntity = validateResult.getData();
SysUserEntity user = authUserService.getLdapUserByName(username);
if(ObjectUtils.isEmpty(user) || ObjectUtils.isEmpty(user.getUserId())) {
if (ObjectUtils.isEmpty(user) || ObjectUtils.isEmpty(user.getUserId())) {
LdapAddRequest ldapAddRequest = new LdapAddRequest();
ldapAddRequest.setUsers(new ArrayList<XpackLdapUserEntity>(){{add(ldapUserEntity);}});
ldapAddRequest.setUsers(new ArrayList<XpackLdapUserEntity>() {{
add(ldapUserEntity);
}});
ldapAddRequest.setEnabled(1L);
// ldapAddRequest.setDeptId(1L);
ldapAddRequest.setRoleIds(new ArrayList<Long>(){{add(2L);}});
ldapAddRequest.setRoleIds(new ArrayList<Long>() {{
add(2L);
}});
sysUserService.validateExistUser(ldapUserEntity.getUsername(), ldapUserEntity.getNickname(), ldapUserEntity.getEmail());
sysUserService.saveLdapUsers(ldapAddRequest);
}
username = validateResult.getData().getUsername();
}
// 增加ldap登录方式
@ -132,7 +131,7 @@ public class AuthServer implements AuthApi {
@Override
public String logout() {
String token = ServletUtils.getToken();
if (isOpenOidc()) {
HttpServletRequest request = ServletUtils.request();
String idToken = request.getHeader("IdToken");
@ -140,15 +139,15 @@ public class AuthServer implements AuthApi {
OidcXpackService oidcXpackService = SpringContextUtil.getBean(OidcXpackService.class);
oidcXpackService.logout(idToken);
}
}
if (StringUtils.isEmpty(token) || StringUtils.equals("null", token) || StringUtils.equals("undefined", token)) {
return "success";
}
try{
try {
Long userId = JWTUtils.tokenInfoByToken(token).getUserId();
authUserService.clearCache(userId);
}catch (Exception e) {
} catch (Exception e) {
LogUtil.error(e);
return "fail";
}
@ -161,29 +160,27 @@ public class AuthServer implements AuthApi {
String userName = nameDto.get("userName");
if (StringUtils.isEmpty(userName)) return false;
SysUserEntity userEntity = authUserService.getUserByName(userName);
if (ObjectUtils.isEmpty(userEntity)) return false;
return true;
return !ObjectUtils.isEmpty(userEntity);
}
@Override
public boolean isOpenLdap() {
Boolean licValid = PluginUtils.licValid();
if(!licValid) return false;
boolean open = authUserService.supportLdap();
return open;
if (!licValid) return false;
return authUserService.supportLdap();
}
@Override
public boolean isOpenOidc() {
Boolean licValid = PluginUtils.licValid();
if(!licValid) return false;
if (!licValid) return false;
return authUserService.supportOidc();
}
@Override
public boolean isPluginLoaded() {
Boolean licValid = PluginUtils.licValid();
if(!licValid) return false;
if (!licValid) return false;
return authUserService.pluginLoaded();
}
@ -192,12 +189,6 @@ public class AuthServer implements AuthApi {
public String getPublicKey() {
return RsaProperties.publicKey;
}
/*@Override
public Boolean isLogin() {
return null;
}*/
}

View File

@ -5,6 +5,7 @@ import io.dataease.auth.api.dto.DynamicMenuDto;
import io.dataease.auth.service.DynamicMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@ -14,7 +15,6 @@ public class DynamicMenuServer implements DynamicMenuApi {
@Override
public List<DynamicMenuDto> menus() {
//ServletUtils.getToken()
return dynamicMenuService.load(null);
}
}

View File

@ -8,7 +8,6 @@ import java.util.List;
public interface AuthUserService {
SysUserEntity getUserById(Long userId);
SysUserEntity getUserByName(String username);
@ -32,5 +31,4 @@ public interface AuthUserService {
Boolean pluginLoaded();
}

View File

@ -10,7 +10,7 @@ public interface ShiroService {
* 初始化权限 -> 拿全部权限
*
* @param :
* @return: java.util.Map<java.lang.String,java.lang.String>
* @return: java.util.Map<java.lang.String, java.lang.String>
*/
Map<String, String> loadFilterChainDefinitionMap();

View File

@ -19,6 +19,7 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@ -39,12 +40,17 @@ public class AuthUserServiceImpl implements AuthUserService {
/**
* 此处需被F2CRealm登录认证调用 也就是说每次请求都会被调用 所以最好加上缓存
*
* @param userId
* @return
*/
@Cacheable(value = AuthConstants.USER_CACHE_NAME, key = "'user' + #userId" )
@Cacheable(value = AuthConstants.USER_CACHE_NAME, key = "'user' + #userId")
@Override
public SysUserEntity getUserById(Long userId){
public SysUserEntity getUserById(Long userId) {
return authMapper.findUser(userId);
}
public SysUserEntity getUserByIdNoCache(Long userId) {
return authMapper.findUser(userId);
}
@ -65,30 +71,31 @@ public class AuthUserServiceImpl implements AuthUserService {
}
@Override
public List<String> roles(Long userId){
public List<String> roles(Long userId) {
return authMapper.roleCodes(userId);
}
/**
* 此处需被F2CRealm登录认证调用 也就是说每次请求都会被调用 所以最好加上缓存
*
* @param userId
* @return
*/
@Cacheable(value = AuthConstants.USER_PERMISSION_CACHE_NAME, key = "'user' + #userId" )
@Cacheable(value = AuthConstants.USER_PERMISSION_CACHE_NAME, key = "'user' + #userId")
@Override
public List<String> permissions(Long userId){
public List<String> permissions(Long userId) {
try {
// 用户登录获取菜单权限时同时更新插件菜单表
dynamicMenuService.syncPluginMenu();
}catch (Exception e){
} catch (Exception e) {
LogUtil.error(e);
//ignore
}
List<String> permissions;
SysUser sysUser = sysUserMapper.selectByPrimaryKey(userId);
if(sysUser.getIsAdmin()!=null&&sysUser.getIsAdmin()){
if (sysUser.getIsAdmin() != null && sysUser.getIsAdmin()) {
permissions = authMapper.permissionsAll();
}else{
} else {
permissions = authMapper.permissions(userId);
}
return Optional.ofNullable(permissions).orElse(new ArrayList<>()).stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList());
@ -96,10 +103,11 @@ public class AuthUserServiceImpl implements AuthUserService {
/**
* 此处需被F2CRealm登录认证调用 也就是说每次请求都会被调用 所以最好加上缓存
*
* @param userId
* @return
*/
@Cacheable(value = AuthConstants.USER_ROLE_CACHE_NAME, key = "'user' + #userId" )
@Cacheable(value = AuthConstants.USER_ROLE_CACHE_NAME, key = "'user' + #userId")
@Override
public List<CurrentRoleDto> roleInfos(Long userId) {
return authMapper.roles(userId);
@ -108,6 +116,7 @@ public class AuthUserServiceImpl implements AuthUserService {
/**
* 一波清除3个缓存
*
* @param userId
*/
@Caching(evict = {
@ -117,37 +126,35 @@ public class AuthUserServiceImpl implements AuthUserService {
})
@Override
public void clearCache(Long userId) {
LogUtil.info("正在清除用户缓存【{}】",userId);
LogUtil.info("正在清除用户缓存【{}】", userId);
}
@Override
public boolean supportLdap() {
Map<String, LdapXpackService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LdapXpackService.class));
if(beansOfType.keySet().size() == 0) return false;
if (beansOfType.keySet().size() == 0) return false;
LdapXpackService ldapXpackService = SpringContextUtil.getBean(LdapXpackService.class);
if(ObjectUtils.isEmpty(ldapXpackService)) return false;
if (ObjectUtils.isEmpty(ldapXpackService)) return false;
return ldapXpackService.isOpen();
}
@Override
public Boolean supportOidc() {
Map<String, OidcXpackService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((OidcXpackService.class));
if(beansOfType.keySet().size() == 0) return false;
if (beansOfType.keySet().size() == 0) return false;
OidcXpackService oidcXpackService = SpringContextUtil.getBean(OidcXpackService.class);
if(ObjectUtils.isEmpty(oidcXpackService)) return false;
if (ObjectUtils.isEmpty(oidcXpackService)) return false;
return oidcXpackService.isSuuportOIDC();
}
@Override
public Boolean pluginLoaded() {
Map<String, PluginCommonService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((PluginCommonService.class));
if(beansOfType.keySet().size() == 0) return false;
if (beansOfType.keySet().size() == 0) return false;
PluginCommonService pluginCommonService = SpringContextUtil.getBean(PluginCommonService.class);
if(ObjectUtils.isEmpty(pluginCommonService)) return false;
if (ObjectUtils.isEmpty(pluginCommonService)) return false;
return pluginCommonService.isPluginLoaded();
}
}

View File

@ -13,6 +13,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
@ -38,22 +39,21 @@ public class DynamicMenuServiceImpl implements DynamicMenuService {
List<DynamicMenuDto> dynamicMenuDtos = sysMenus.stream().map(this::convert).collect(Collectors.toList());
//增加插件中的菜单
List<PluginSysMenu> pluginSysMenus = PluginUtils.pluginMenus();
if (CollectionUtils.isNotEmpty(pluginSysMenus) ) {
if (CollectionUtils.isNotEmpty(pluginSysMenus)) {
pluginSysMenus = pluginSysMenus.stream().filter(menu -> menu.getType() <= 1).collect(Collectors.toList());
List<DynamicMenuDto> pluginDtos = pluginSysMenus.stream().map(this::convert).collect(Collectors.toList());
dynamicMenuDtos.addAll(pluginDtos);
}
dynamicMenuDtos = dynamicMenuDtos.stream().sorted((s1, s2) -> {
int sortIndex1 = null == s1.getMenuSort() ? 999: s1.getMenuSort();
int sortIndex2 = null == s2.getMenuSort() ? 999: s2.getMenuSort();
int sortIndex1 = null == s1.getMenuSort() ? 999 : s1.getMenuSort();
int sortIndex2 = null == s2.getMenuSort() ? 999 : s2.getMenuSort();
return sortIndex1 - sortIndex2;
}).collect(Collectors.toList());
dynamicMenuDtos.sort((s1, s2) -> s1.getHidden().compareTo(s2.getHidden()));
List<DynamicMenuDto> result = buildTree(dynamicMenuDtos);
return result;
return buildTree(dynamicMenuDtos);
}
private DynamicMenuDto convert(SysMenu sysMenu){
private DynamicMenuDto convert(SysMenu sysMenu) {
DynamicMenuDto dynamicMenuDto = new DynamicMenuDto();
dynamicMenuDto.setId(sysMenu.getMenuId());
dynamicMenuDto.setPid(sysMenu.getPid());
@ -72,7 +72,8 @@ public class DynamicMenuServiceImpl implements DynamicMenuService {
dynamicMenuDto.setIsPlugin(false);
return dynamicMenuDto;
}
private DynamicMenuDto convert(PluginSysMenu sysMenu){
private DynamicMenuDto convert(PluginSysMenu sysMenu) {
DynamicMenuDto dynamicMenuDto = new DynamicMenuDto();
dynamicMenuDto.setId(sysMenu.getMenuId());
dynamicMenuDto.setPid(sysMenu.getPid());
@ -93,17 +94,17 @@ public class DynamicMenuServiceImpl implements DynamicMenuService {
return dynamicMenuDto;
}
private List<DynamicMenuDto> buildTree(List<DynamicMenuDto> lists){
private List<DynamicMenuDto> buildTree(List<DynamicMenuDto> lists) {
List<DynamicMenuDto> rootNodes = new ArrayList<>();
lists.forEach(node -> {
if (isParent(node.getPid())) {
rootNodes.add(node);
}
lists.forEach(tNode -> {
if (tNode.getPid() == node.getId()) {
if (tNode.getPid().equals(node.getId())) {
if (node.getChildren() == null) {
node.setChildren(new ArrayList<DynamicMenuDto>());
node.setRedirect(node.getPath()+"/"+tNode.getPath());//第一个子节点的path
node.setRedirect(node.getPath() + "/" + tNode.getPath());//第一个子节点的path
}
node.getChildren().add(tNode);
}
@ -113,8 +114,8 @@ public class DynamicMenuServiceImpl implements DynamicMenuService {
}
private Boolean isParent(Long pid){
return null == pid || pid==0L;
private Boolean isParent(Long pid) {
return null == pid || pid == 0L;
}
@Transactional
@ -123,7 +124,7 @@ public class DynamicMenuServiceImpl implements DynamicMenuService {
List<PluginSysMenu> pluginSysMenuList = PluginUtils.pluginMenus();
Set<PluginSysMenu> pluginSysMenuSet = new HashSet<>(pluginSysMenuList);
pluginSysMenuList = new ArrayList<>(pluginSysMenuSet);
if(CollectionUtils.isNotEmpty(pluginSysMenuList)){
if (CollectionUtils.isNotEmpty(pluginSysMenuList)) {
extPluginSysMenuMapper.savePluginMenu(pluginSysMenuList);
}
}

View File

@ -2,7 +2,6 @@ package io.dataease.auth.service.impl;
import io.dataease.auth.service.ExtAuthService;
import io.dataease.base.domain.SysAuth;
import io.dataease.base.mapper.SysAuthMapper;
import io.dataease.base.mapper.ext.ExtAuthMapper;
import io.dataease.commons.model.AuthURD;
import org.springframework.stereotype.Service;
@ -21,9 +20,6 @@ public class ExtAuthServiceImpl implements ExtAuthService {
@Resource
private ExtAuthMapper extAuthMapper;
@Resource
private SysAuthMapper sysAuthMapper;
@Override
public Set<Long> userIdsByRD(AuthURD request) {
Set<Long> result = new HashSet<>();
@ -42,9 +38,7 @@ public class ExtAuthServiceImpl implements ExtAuthService {
@Override
public AuthURD resourceTarget(String resourceId) {
AuthURD authURD = new AuthURD();
/*SysAuthExample example = new SysAuthExample();
example.createCriteria().andAuthSourceEqualTo(resourceId);
List<SysAuth> sysAuths = sysAuthMapper.selectByExample(example);*/
List<SysAuth> sysAuths = extAuthMapper.queryByResource(resourceId);
Map<String, List<SysAuth>> authMap = sysAuths.stream().collect(Collectors.groupingBy(SysAuth::getAuthTargetType));

View File

@ -3,14 +3,14 @@ package io.dataease.auth.service.impl;
import io.dataease.auth.service.ShiroService;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
import java.util.Map;
@Service
public class ShiroServiceImpl implements ShiroService {
private final static String ANON = "anon";
private final static String ANON = "anon";
@Override
@ -20,15 +20,15 @@ public class ShiroServiceImpl implements ShiroService {
// 配置过滤:不会被拦截的链接 -> 放行 start ----------------------------------------------------------
// 放行Swagger2页面需要放行这些
filterChainDefinitionMap.put("/doc.html**","doc");
filterChainDefinitionMap.put("/deApi**",ANON);
filterChainDefinitionMap.put("/swagger-ui.html",ANON);
filterChainDefinitionMap.put("/swagger-ui/**",ANON);
filterChainDefinitionMap.put("/swagger/**",ANON);
filterChainDefinitionMap.put("/doc.html**", "doc");
filterChainDefinitionMap.put("/deApi**", ANON);
filterChainDefinitionMap.put("/swagger-ui.html", ANON);
filterChainDefinitionMap.put("/swagger-ui/**", ANON);
filterChainDefinitionMap.put("/swagger/**", ANON);
filterChainDefinitionMap.put("/webjars/**", ANON);
filterChainDefinitionMap.put("/swagger-resources/**",ANON);
filterChainDefinitionMap.put("/v2/**",ANON);
filterChainDefinitionMap.put("/v3/**",ANON);
filterChainDefinitionMap.put("/swagger-resources/**", ANON);
filterChainDefinitionMap.put("/v2/**", ANON);
filterChainDefinitionMap.put("/v3/**", ANON);
filterChainDefinitionMap.put("/static/**", ANON);
filterChainDefinitionMap.put("/css/**", ANON);
@ -41,7 +41,6 @@ public class ShiroServiceImpl implements ShiroService {
filterChainDefinitionMap.put("/link/**", ANON);
filterChainDefinitionMap.put("/index.html", ANON);
filterChainDefinitionMap.put("/link.html", ANON);
filterChainDefinitionMap.put("/xggznb/**", ANON);
//获取主题信息
@ -54,15 +53,11 @@ public class ShiroServiceImpl implements ShiroService {
filterChainDefinitionMap.put("/dataset/field/fieldValues/**", ANON);
filterChainDefinitionMap.put("/linkJump/queryPanelJumpInfo/**", ANON);
//未读消息数量
// filterChainDefinitionMap.put("/api/sys_msg/unReadCount/**", ANON);
filterChainDefinitionMap.put("/**/*.json", ANON);
filterChainDefinitionMap.put("/system/ui/**", ANON);
filterChainDefinitionMap.put("/**/*.js", ANON);
filterChainDefinitionMap.put("/**/*.css", ANON);
filterChainDefinitionMap.put("/**/*.map", ANON);
// filterChainDefinitionMap.put("/axios.map", ANON);
filterChainDefinitionMap.put("/api/auth/login", ANON);
filterChainDefinitionMap.put("/api/auth/isPluginLoaded", ANON);
@ -94,8 +89,7 @@ public class ShiroServiceImpl implements ShiroService {
return filterChainDefinitionMap;
}
@Override
public void updatePermission(ShiroFilterFactoryBean shiroFilterFactoryBean, Integer roleId, Boolean isRemoveSession) {

View File

@ -14,6 +14,7 @@ import io.dataease.exception.DataEaseException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.Environment;
import java.util.Date;
@ -21,70 +22,67 @@ public class JWTUtils {
// token过期时间1min (过期会自动刷新续命 目的是避免一直都是同一个token )
private static final long EXPIRE_TIME = 1*60*1000;
private static final long EXPIRE_TIME = 1 * 60 * 1000;
// 登录间隔时间10min 超过这个时间强制重新登录
private static long Login_Interval;
/**
* 校验token是否正确
* @param token 密钥
*
* @param token 密钥
* @param secret 用户的密码
* @return 是否正确
*/
public static boolean verify(String token, TokenInfo tokenInfo, String secret) {
Algorithm algorithm = Algorithm.HMAC256(secret);
Verification verification = JWT.require(algorithm)
.withClaim("username", tokenInfo.getUsername())
.withClaim("userId", tokenInfo.getUserId());
/* if (StringUtils.isNotBlank(tokenInfo.getIdToken())) {
verification.withClaim("idToken", tokenInfo.getIdToken());
} */
JWTVerifier verifier = verification.build();
JWTVerifier verifier = verification.build();
verifySign(algorithm, token);
verifier.verify(token);
return true;
}
public static void verifySign(Algorithm algorithm, String token) {
DecodedJWT decode = JWT.decode(token);
algorithm.verify(decode);
}
/**
* 获得token中的信息无需secret解密也能获得
*
* @return token中包含的用户名
*/
public static TokenInfo tokenInfoByToken(String token) {
DecodedJWT jwt = JWT.decode(token);
String username = jwt.getClaim("username").asString();
Long userId = jwt.getClaim("userId").asLong();
// String idToken = jwt.getClaim("idToken").asString();
if (StringUtils.isEmpty(username) || ObjectUtils.isEmpty(userId) ){
if (StringUtils.isEmpty(username) || ObjectUtils.isEmpty(userId)) {
DataEaseException.throwException("token格式错误");
}
TokenInfoBuilder tokenInfoBuilder = TokenInfo.builder().username(username).userId(userId);
/* if (StringUtils.isNotBlank(idToken)) {
tokenInfoBuilder.idToken(idToken);
} */
TokenInfo tokenInfo = tokenInfoBuilder.build();
return tokenInfo;
return tokenInfoBuilder.build();
}
public static boolean needRefresh(String token){
public static boolean needRefresh(String token) {
Date exp = JWTUtils.getExp(token);
return new Date().getTime() >= exp.getTime();
}
/**
* 当前token是否登录超时
*
* @param token
* @return
*/
public static boolean loginExpire(String token){
if (Login_Interval==0) {
public static boolean loginExpire(String token) {
if (Login_Interval == 0) {
// 默认超时时间是8h
int minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Integer.class, 8*60);
int minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Integer.class, 8 * 60);
// 分钟换算成毫秒
Login_Interval = minute * 1000 * 60;
}
@ -109,22 +107,20 @@ public class JWTUtils {
/**
* 生成签名,5min后过期
*
* @param tokenInfo 用户信息
* @param secret 用户的密码
* @param secret 用户的密码
* @return 加密的token
*/
public static String sign(TokenInfo tokenInfo, String secret) {
try {
Date date = new Date(System.currentTimeMillis()+EXPIRE_TIME);
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
Algorithm algorithm = Algorithm.HMAC256(secret);
Builder builder = JWT.create()
.withClaim("username", tokenInfo.getUsername())
.withClaim("userId", tokenInfo.getUserId());
/* if (StringUtils.isNotBlank(tokenInfo.getIdToken())) {
builder.withClaim("idToken", tokenInfo.getIdToken());
} */
return builder.withExpiresAt(date).sign(algorithm);
} catch (Exception e) {
return null;
}
@ -135,7 +131,7 @@ public class JWTUtils {
return JWT.create().withClaim("resourceId", resourceId).sign(algorithm);
}
public static boolean verifyLink(String token,String resourceId, String secret) {
public static boolean verifyLink(String token, String resourceId, String secret) {
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier verifier = JWT.require(algorithm)
.withClaim("resourceId", resourceId)
@ -143,17 +139,18 @@ public class JWTUtils {
try {
verifier.verify(token);
return true;
}catch (Exception e){
} catch (Exception e) {
return false;
}
}
/**
* 获取当前token上次操作时间
*
* @param token
* @return
*/
public static Long tokenLastOperateTime(String token){
public static Long tokenLastOperateTime(String token) {
DecodedJWT jwt = JWT.decode(token);
Date expiresAt = jwt.getExpiresAt();
return expiresAt.getTime();

View File

@ -16,7 +16,7 @@ public class RsaUtil {
* 私钥解密
*
* @param privateKeyText 私钥
* @param text 待解密的文本
* @param text 待解密的文本
* @return /
* @throws Exception /
*/
@ -26,12 +26,11 @@ public class RsaUtil {
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec5);
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
// byte[] result = cipher.doFinal(Base64.decodeBase64(text));
// 下面该用分段加密
byte[] result = null;
byte[] b = Base64.decodeBase64(text);
for (int i = 0; i < b.length; i += 64) {
byte[] doFinal = cipher.doFinal(ArrayUtils.subarray(b, i,i + 64));
byte[] doFinal = cipher.doFinal(ArrayUtils.subarray(b, i, i + 64));
result = ArrayUtils.addAll(result, doFinal);
}
return new String(result);
@ -41,7 +40,7 @@ public class RsaUtil {
* 公钥加密
*
* @param publicKeyText 公钥
* @param text 待加密的文本
* @param text 待加密的文本
* @return /
*/
public static String encryptByPublicKey(String publicKeyText, String text) throws Exception {
@ -50,12 +49,11 @@ public class RsaUtil {
PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec2);
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
/*byte[] result = cipher.doFinal(text.getBytes());*/
// 下面该用分段加密
byte[] result = null;
byte[] b = text.getBytes("utf-8");
for (int i = 0; i < b.length; i += 50) {
byte[] doFinal = cipher.doFinal(ArrayUtils.subarray(b, i,i + 50));
byte[] doFinal = cipher.doFinal(ArrayUtils.subarray(b, i, i + 50));
result = ArrayUtils.addAll(result, doFinal);
}
return Base64.encodeBase64String(result);

View File

@ -1,20 +1,15 @@
package io.dataease.base.domain;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("消息渠道")
public class SysMsgChannel implements Serializable {
@ApiModelProperty("消息渠道ID")
private Long msgChannelId;
@ApiModelProperty("消息渠道名称")
private String channelName;
private String serviceName;
private static final long serialVersionUID = 1L;
}

View File

@ -233,6 +233,76 @@ public class SysMsgChannelExample {
addCriterion("channel_name not between", value1, value2, "channelName");
return (Criteria) this;
}
public Criteria andServiceNameIsNull() {
addCriterion("service_name is null");
return (Criteria) this;
}
public Criteria andServiceNameIsNotNull() {
addCriterion("service_name is not null");
return (Criteria) this;
}
public Criteria andServiceNameEqualTo(String value) {
addCriterion("service_name =", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameNotEqualTo(String value) {
addCriterion("service_name <>", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameGreaterThan(String value) {
addCriterion("service_name >", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameGreaterThanOrEqualTo(String value) {
addCriterion("service_name >=", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameLessThan(String value) {
addCriterion("service_name <", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameLessThanOrEqualTo(String value) {
addCriterion("service_name <=", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameLike(String value) {
addCriterion("service_name like", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameNotLike(String value) {
addCriterion("service_name not like", value, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameIn(List<String> values) {
addCriterion("service_name in", values, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameNotIn(List<String> values) {
addCriterion("service_name not in", values, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameBetween(String value1, String value2) {
addCriterion("service_name between", value1, value2, "serviceName");
return (Criteria) this;
}
public Criteria andServiceNameNotBetween(String value1, String value2) {
addCriterion("service_name not between", value1, value2, "serviceName");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -19,5 +19,11 @@ public class VAuthModel implements Serializable {
private String createBy;
private Long level;
private Long mode;
private String dataSourceId;
private static final long serialVersionUID = 1L;
}

View File

@ -593,6 +593,196 @@ public class VAuthModelExample {
addCriterion("create_by not between", value1, value2, "createBy");
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(Long value) {
addCriterion("`level` =", value, "level");
return (Criteria) this;
}
public Criteria andLevelNotEqualTo(Long value) {
addCriterion("`level` <>", value, "level");
return (Criteria) this;
}
public Criteria andLevelGreaterThan(Long value) {
addCriterion("`level` >", value, "level");
return (Criteria) this;
}
public Criteria andLevelGreaterThanOrEqualTo(Long value) {
addCriterion("`level` >=", value, "level");
return (Criteria) this;
}
public Criteria andLevelLessThan(Long value) {
addCriterion("`level` <", value, "level");
return (Criteria) this;
}
public Criteria andLevelLessThanOrEqualTo(Long value) {
addCriterion("`level` <=", value, "level");
return (Criteria) this;
}
public Criteria andLevelIn(List<Long> values) {
addCriterion("`level` in", values, "level");
return (Criteria) this;
}
public Criteria andLevelNotIn(List<Long> values) {
addCriterion("`level` not in", values, "level");
return (Criteria) this;
}
public Criteria andLevelBetween(Long value1, Long value2) {
addCriterion("`level` between", value1, value2, "level");
return (Criteria) this;
}
public Criteria andLevelNotBetween(Long value1, Long value2) {
addCriterion("`level` not between", value1, value2, "level");
return (Criteria) this;
}
public Criteria andModeIsNull() {
addCriterion("`mode` is null");
return (Criteria) this;
}
public Criteria andModeIsNotNull() {
addCriterion("`mode` is not null");
return (Criteria) this;
}
public Criteria andModeEqualTo(Long value) {
addCriterion("`mode` =", value, "mode");
return (Criteria) this;
}
public Criteria andModeNotEqualTo(Long value) {
addCriterion("`mode` <>", value, "mode");
return (Criteria) this;
}
public Criteria andModeGreaterThan(Long value) {
addCriterion("`mode` >", value, "mode");
return (Criteria) this;
}
public Criteria andModeGreaterThanOrEqualTo(Long value) {
addCriterion("`mode` >=", value, "mode");
return (Criteria) this;
}
public Criteria andModeLessThan(Long value) {
addCriterion("`mode` <", value, "mode");
return (Criteria) this;
}
public Criteria andModeLessThanOrEqualTo(Long value) {
addCriterion("`mode` <=", value, "mode");
return (Criteria) this;
}
public Criteria andModeIn(List<Long> values) {
addCriterion("`mode` in", values, "mode");
return (Criteria) this;
}
public Criteria andModeNotIn(List<Long> values) {
addCriterion("`mode` not in", values, "mode");
return (Criteria) this;
}
public Criteria andModeBetween(Long value1, Long value2) {
addCriterion("`mode` between", value1, value2, "mode");
return (Criteria) this;
}
public Criteria andModeNotBetween(Long value1, Long value2) {
addCriterion("`mode` not between", value1, value2, "mode");
return (Criteria) this;
}
public Criteria andDataSourceIdIsNull() {
addCriterion("data_source_id is null");
return (Criteria) this;
}
public Criteria andDataSourceIdIsNotNull() {
addCriterion("data_source_id is not null");
return (Criteria) this;
}
public Criteria andDataSourceIdEqualTo(String value) {
addCriterion("data_source_id =", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdNotEqualTo(String value) {
addCriterion("data_source_id <>", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdGreaterThan(String value) {
addCriterion("data_source_id >", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdGreaterThanOrEqualTo(String value) {
addCriterion("data_source_id >=", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdLessThan(String value) {
addCriterion("data_source_id <", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdLessThanOrEqualTo(String value) {
addCriterion("data_source_id <=", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdLike(String value) {
addCriterion("data_source_id like", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdNotLike(String value) {
addCriterion("data_source_id not like", value, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdIn(List<String> values) {
addCriterion("data_source_id in", values, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdNotIn(List<String> values) {
addCriterion("data_source_id not in", values, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdBetween(String value1, String value2) {
addCriterion("data_source_id between", value1, value2, "dataSourceId");
return (Criteria) this;
}
public Criteria andDataSourceIdNotBetween(String value1, String value2) {
addCriterion("data_source_id not between", value1, value2, "dataSourceId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="io.dataease.base.domain.SysMsgChannel">
<id column="msg_channel_id" jdbcType="BIGINT" property="msgChannelId" />
<result column="channel_name" jdbcType="VARCHAR" property="channelName" />
<result column="service_name" jdbcType="VARCHAR" property="serviceName" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -64,7 +65,7 @@
</where>
</sql>
<sql id="Base_Column_List">
msg_channel_id, channel_name
msg_channel_id, channel_name, service_name
</sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.SysMsgChannelExample" resultMap="BaseResultMap">
select
@ -97,8 +98,10 @@
</if>
</delete>
<insert id="insert" parameterType="io.dataease.base.domain.SysMsgChannel">
insert into sys_msg_channel (msg_channel_id, channel_name)
values (#{msgChannelId,jdbcType=BIGINT}, #{channelName,jdbcType=VARCHAR})
insert into sys_msg_channel (msg_channel_id, channel_name, service_name
)
values (#{msgChannelId,jdbcType=BIGINT}, #{channelName,jdbcType=VARCHAR}, #{serviceName,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.SysMsgChannel">
insert into sys_msg_channel
@ -109,6 +112,9 @@
<if test="channelName != null">
channel_name,
</if>
<if test="serviceName != null">
service_name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="msgChannelId != null">
@ -117,6 +123,9 @@
<if test="channelName != null">
#{channelName,jdbcType=VARCHAR},
</if>
<if test="serviceName != null">
#{serviceName,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.dataease.base.domain.SysMsgChannelExample" resultType="java.lang.Long">
@ -134,6 +143,9 @@
<if test="record.channelName != null">
channel_name = #{record.channelName,jdbcType=VARCHAR},
</if>
<if test="record.serviceName != null">
service_name = #{record.serviceName,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -142,7 +154,8 @@
<update id="updateByExample" parameterType="map">
update sys_msg_channel
set msg_channel_id = #{record.msgChannelId,jdbcType=BIGINT},
channel_name = #{record.channelName,jdbcType=VARCHAR}
channel_name = #{record.channelName,jdbcType=VARCHAR},
service_name = #{record.serviceName,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -153,12 +166,16 @@
<if test="channelName != null">
channel_name = #{channelName,jdbcType=VARCHAR},
</if>
<if test="serviceName != null">
service_name = #{serviceName,jdbcType=VARCHAR},
</if>
</set>
where msg_channel_id = #{msgChannelId,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.SysMsgChannel">
update sys_msg_channel
set channel_name = #{channelName,jdbcType=VARCHAR}
set channel_name = #{channelName,jdbcType=VARCHAR},
service_name = #{serviceName,jdbcType=VARCHAR}
where msg_channel_id = #{msgChannelId,jdbcType=BIGINT}
</update>
</mapper>

View File

@ -9,6 +9,9 @@
<result column="model_inner_type" jdbcType="VARCHAR" property="modelInnerType" />
<result column="auth_type" jdbcType="VARCHAR" property="authType" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="level" jdbcType="BIGINT" property="level" />
<result column="mode" jdbcType="BIGINT" property="mode" />
<result column="data_source_id" jdbcType="VARCHAR" property="dataSourceId" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.dataease.base.domain.VAuthModelWithBLOBs">
<result column="name" jdbcType="LONGVARCHAR" property="name" />
@ -73,7 +76,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, pid, node_type, model_type, model_inner_type, auth_type, create_by
id, pid, node_type, model_type, model_inner_type, auth_type, create_by, `level`,
`mode`, data_source_id
</sql>
<sql id="Blob_Column_List">
`name`, `label`
@ -117,11 +121,13 @@
<insert id="insert" parameterType="io.dataease.base.domain.VAuthModelWithBLOBs">
insert into v_auth_model (id, pid, node_type,
model_type, model_inner_type, auth_type,
create_by, `name`, `label`
create_by, `level`, `mode`,
data_source_id, `name`, `label`
)
values (#{id,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR}, #{nodeType,jdbcType=VARCHAR},
#{modelType,jdbcType=VARCHAR}, #{modelInnerType,jdbcType=VARCHAR}, #{authType,jdbcType=VARCHAR},
#{createBy,jdbcType=VARCHAR}, #{name,jdbcType=LONGVARCHAR}, #{label,jdbcType=LONGVARCHAR}
#{createBy,jdbcType=VARCHAR}, #{level,jdbcType=BIGINT}, #{mode,jdbcType=BIGINT},
#{dataSourceId,jdbcType=VARCHAR}, #{name,jdbcType=LONGVARCHAR}, #{label,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.VAuthModelWithBLOBs">
@ -148,6 +154,15 @@
<if test="createBy != null">
create_by,
</if>
<if test="level != null">
`level`,
</if>
<if test="mode != null">
`mode`,
</if>
<if test="dataSourceId != null">
data_source_id,
</if>
<if test="name != null">
`name`,
</if>
@ -177,6 +192,15 @@
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="level != null">
#{level,jdbcType=BIGINT},
</if>
<if test="mode != null">
#{mode,jdbcType=BIGINT},
</if>
<if test="dataSourceId != null">
#{dataSourceId,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=LONGVARCHAR},
</if>
@ -215,6 +239,15 @@
<if test="record.createBy != null">
create_by = #{record.createBy,jdbcType=VARCHAR},
</if>
<if test="record.level != null">
`level` = #{record.level,jdbcType=BIGINT},
</if>
<if test="record.mode != null">
`mode` = #{record.mode,jdbcType=BIGINT},
</if>
<if test="record.dataSourceId != null">
data_source_id = #{record.dataSourceId,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=LONGVARCHAR},
</if>
@ -235,6 +268,9 @@
model_inner_type = #{record.modelInnerType,jdbcType=VARCHAR},
auth_type = #{record.authType,jdbcType=VARCHAR},
create_by = #{record.createBy,jdbcType=VARCHAR},
`level` = #{record.level,jdbcType=BIGINT},
`mode` = #{record.mode,jdbcType=BIGINT},
data_source_id = #{record.dataSourceId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=LONGVARCHAR},
`label` = #{record.label,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
@ -249,7 +285,10 @@
model_type = #{record.modelType,jdbcType=VARCHAR},
model_inner_type = #{record.modelInnerType,jdbcType=VARCHAR},
auth_type = #{record.authType,jdbcType=VARCHAR},
create_by = #{record.createBy,jdbcType=VARCHAR}
create_by = #{record.createBy,jdbcType=VARCHAR},
`level` = #{record.level,jdbcType=BIGINT},
`mode` = #{record.mode,jdbcType=BIGINT},
data_source_id = #{record.dataSourceId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>

View File

@ -14,5 +14,4 @@ public interface ExtAuthMapper {
List<Long> queryUserIdWithDeptIds(@Param("deptIds") List<Long> deptIds);
List<SysAuth> queryByResource(@Param("resourceId") String resourceId);
// Set<Long> queryUserIdWithRD(@Param("roleIds") List<Long> roleIds, @Param("deptIds") List<Long> deptIds);
}

View File

@ -75,10 +75,7 @@
</foreach>
</if>
</where>
<if test="sort != null">
order by ${sort}
</if>
ORDER BY CONVERT(`name` using gbk)
</select>
</mapper>

View File

@ -20,4 +20,8 @@ public interface ExtChartViewMapper {
List<String> allViewIds(@Param("tableId") String tableId);
String searchAdviceSceneId(@Param("userId") String userId,@Param("panelId") String panelId);
int checkSameDataSet(@Param("viewIdSource") String viewIdSource,@Param("viewIdTarget") String viewIdTarget);
ChartViewDTO searchOneWithPrivileges(@Param("userId") String userId,@Param("id") String id );
}

View File

@ -8,6 +8,13 @@
<result column="privileges" property="privileges"/>
</resultMap>
<select id="searchOneWithPrivileges" resultMap="BaseResultMapDTO">
select
chart_view.*,
get_auths(id,'chart',#{userId}) as `privileges`
from chart_view where id = #{id}
</select>
<select id="searchOne" resultMap="BaseResultMapDTO">
select
id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time,
@ -74,10 +81,7 @@
and name like CONCAT('%', #{name},'%')
</if>
</where>
<if test="sort != null">
order by ${sort}
</if>
ORDER BY CONVERT(`name` using gbk)
</select>
@ -150,4 +154,8 @@
chart_group.create_time DESC
LIMIT 1
</select>
<select id="checkSameDataSet" resultType="int">
select count(DISTINCT table_id) from chart_view where id = #{viewIdSource} or id = #{viewIdTarget}
</select>
</mapper>

View File

@ -75,9 +75,7 @@
</foreach>
</if>
</where>
<if test="sort != null">
order by ${sort}
</if>
ORDER BY CONVERT(`name` using gbk)
</select>
<select id="searchIds" resultType="java.util.Map">

View File

@ -11,9 +11,8 @@
select
id, `name`, scene_id, data_source_id, `type`, `mode`,`info`, create_by, create_time,
get_auths(id,'dataset',#{userId}) as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'dataset') cids) t,dataset_table
from dataset_table
<where>
FIND_IN_SET(dataset_table.id,cids)
<if test="id != null">
and id = #{id,jdbcType=VARCHAR}
</if>
@ -92,8 +91,6 @@
</foreach>
</if>
</where>
<if test="sort != null">
order by ${sort}
</if>
ORDER BY CONVERT(`name` using gbk)
</select>
</mapper>

View File

@ -12,14 +12,11 @@ public interface ExtPanelGroupMapper {
List<PanelGroupDTO> panelGroupListDefault(PanelGroupRequest request);
//会级联删除pid 下的所有数据
int deleteCircle(@Param("pid") String pid);
PanelGroupDTO panelGroup(String id);
void copyPanelView(@Param("pid") String panelId);

View File

@ -86,7 +86,7 @@
and panel_group.level = #{level}
</if>
</where>
order by panel_group.name asc,panel_group.create_time desc
ORDER BY CONVERT(panel_group.name using gbk)
</select>
<select id="panelGroupList" resultMap="BaseResultMapDTO">
@ -160,7 +160,7 @@
and panel_group.level = #{level}
</if>
</where>
order by panel_group.name asc,panel_group.create_time desc
ORDER BY panel_group.node_type desc, CONVERT(panel_group.name using gbk)
</select>
<delete id="deleteCircle">

View File

@ -0,0 +1,13 @@
package io.dataease.base.mapper.ext;
import io.dataease.controller.request.authModel.VAuthModelRequest;
import io.dataease.dto.authModel.VAuthModelDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtVAuthModelMapper {
List<VAuthModelDTO> queryAuthModel (@Param("record") VAuthModelRequest record);
}

View File

@ -0,0 +1,107 @@
<?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.ExtVAuthModelMapper">
<resultMap extends="io.dataease.base.mapper.VAuthModelMapper.ResultMapWithBLOBs" id="ExtResultMap"
type="io.dataease.dto.authModel.VAuthModelDTO">
<result column="privileges" jdbcType="VARCHAR" property="privileges"/>
</resultMap>
<select id="queryAuthModel" resultMap="ExtResultMap">
SELECT
v_auth_model.id,
v_auth_model.name,
v_auth_model.label,
v_auth_model.pid,
v_auth_model.node_type,
v_auth_model.model_type,
v_auth_model.model_inner_type,
v_auth_model.auth_type,
v_auth_model.create_by,
v_auth_model.level,
v_auth_model.mode,
v_auth_model.data_source_id,
authInfo.PRIVILEGES AS `privileges`
FROM
( SELECT GET_V_AUTH_MODEL_ID_P_USE ( #{record.userId}, #{record.modelType} ) cids ) t,
v_auth_model
LEFT JOIN (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) AS `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = #{record.modelType}
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{record.userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{record.userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{record.userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo ON v_auth_model.id = authInfo.auth_source
WHERE
FIND_IN_SET( v_auth_model.id, cids )
<if test="record.id != null">
and v_auth_model.id = #{record.id,jdbcType=VARCHAR}
</if>
<if test="record.pid != null">
and v_auth_model.pid = #{record.pid,jdbcType=VARCHAR}
</if>
<if test="record.nodeType != null">
and v_auth_model.node_type = #{record.nodeType,jdbcType=VARCHAR}
</if>
<if test="record.modelType != null">
and v_auth_model.model_type = #{record.modelType,jdbcType=VARCHAR}
</if>
<if test="record.modelInnerType != null">
and v_auth_model.model_inner_type = #{record.modelInnerType,jdbcType=VARCHAR}
</if>
<if test="record.authType != null">
and v_auth_model.auth_type = #{record.authType,jdbcType=VARCHAR}
</if>
<if test="record.createBy != null">
and v_auth_model.create_by = #{record.createBy,jdbcType=VARCHAR}
</if>
<if test="record.level != null">
and v_auth_model.`level` = #{record.level,jdbcType=BIGINT}
</if>
<if test="record.mode != null">
and v_auth_model.`mode` = #{record.mode,jdbcType=BIGINT}
</if>
<if test="record.dataSourceId != null">
and v_auth_model.data_source_id = #{record.dataSourceId,jdbcType=VARCHAR}
</if>
<if test="record.name != null">
and v_auth_model.`name` = #{record.name,jdbcType=LONGVARCHAR}
</if>
<if test="record.label != null">
and v_auth_model.`label` = #{record.label,jdbcType=LONGVARCHAR}
</if>
<if test="record.modelInnerTypeArray != null and record.modelInnerTypeArray.size() > 0">
and v_auth_model.model_inner_type in
<foreach collection="record.modelInnerTypeArray" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='record.modelType != null and record.modelType == "dataset"'>
or (v_auth_model.`model_inner_type` = 'group' and v_auth_model.model_type = 'dataset')
</if>
ORDER BY v_auth_model.node_type desc, CONVERT(v_auth_model.label using gbk) asc
</select>
</mapper>

View File

@ -9,20 +9,14 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class LicStatusCondition implements Condition {
@Override
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
// BeanDefinitionRegistry registry = conditionContext.getRegistry();
// DefaultLicenseService defaultLicenseService = conditionContext.getBeanFactory().getBean(DefaultLicenseService.class);
DefaultLicenseService defaultLicenseService = CommonBeanFactory.getBean(DefaultLicenseService.class);
/*if (null == defaultLicenseService) {
registry.registerBeanDefinition();
}*/
if (ObjectUtils.isNotEmpty(defaultLicenseService)) {
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.validateLicense();
return F2CLicenseResponse.Status.valid == f2CLicenseResponse.getStatus();

View File

@ -9,7 +9,7 @@ public class CommonConstants {
//操作类型
public static final class OPT_TYPE{
public static final class OPT_TYPE {
public static final String INSERT = "insert";
@ -22,19 +22,36 @@ public class CommonConstants {
}
//操作类型
public static final class CHECK_RESULT{
public static final class CHECK_RESULT {
// 不存在
public static final String NONE = "none";
// 全局存在
public static final String EXIST_ALL= "exist_all";
public static final String EXIST_ALL = "exist_all";
// 当前用户存在
public static final String EXIST_USER= "exist_user";
public static final String EXIST_USER = "exist_user";
// 其他用户存在
public static final String EXIST_OTHER= "exist_other";
public static final String EXIST_OTHER = "exist_other";
}
//视图数据查询来源
public static final class VIEW_QUERY_FROM {
// 仪表板
public static final String PANEL = "panel";
}
//视图数据查询模式
public static final class VIEW_RESULT_MODE {
// 所有
public static final String ALL = "all";
// 自定义
public static final String CUSTOM = "custom";
}
}

View File

@ -7,22 +7,21 @@ package io.dataease.commons.constants;
*/
public class SystemConstants {
public static final class WITH_EXTEND{
public static final class WITH_EXTEND {
public final static String NOW = "now";
public final static String PARENT = "parent";
public final static String CHILDREN = "children";
}
public static final class PRIVILEGE_VALUE{
public static final class PRIVILEGE_VALUE {
public final static Integer ON = 1;
public final static Integer OFF = 0;
}
public static final class AUTH_SOURCE{
public static final class AUTH_SOURCE {
public final static String MENU = "menu";
}
}

View File

@ -3,6 +3,7 @@ package io.dataease.commons.filter;
import io.dataease.commons.holder.ThreadLocalContextHolder;
import io.dataease.commons.wrapper.XssAndSqlHttpServletRequestWrapper;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -12,8 +13,6 @@ import java.io.*;
public class SqlFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
@ -31,7 +30,7 @@ public class SqlFilter implements Filter {
}
String method = "GET";
String param = "";
String param;
XssAndSqlHttpServletRequestWrapper xssRequest = null;
if (request instanceof HttpServletRequest) {
method = ((HttpServletRequest) request).getMethod();
@ -39,8 +38,8 @@ public class SqlFilter implements Filter {
}
if ("POST".equalsIgnoreCase(method)) {
param = this.getBodyString(xssRequest.getReader());
if(StringUtils.isNotBlank(param)){
if(xssRequest.checkXSSAndSql(param)){
if (StringUtils.isNotBlank(param)) {
if (xssRequest.checkXSSAndSql(param)) {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=UTF-8");
PrintWriter out = response.getWriter();

View File

@ -5,8 +5,8 @@ import io.dataease.base.domain.License;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.LogUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@ -17,50 +17,44 @@ import java.util.List;
public class DefaultLicenseService {
@Resource
private InnerLicenseService innerLicenseService;
@Value("${spring.application.name:null}")
private String moduleId;
private static final String LICENSE_ID = "fit2cloud_license";
private static final String validatorUtil = "/usr/bin/validator";
private static final String product = "DataEase";
/*private static final String[] NO_PLU_LIMIT_MODULES = new String[]{"dashboard", "gateway"};*/
public F2CLicenseResponse validateLicense(String product, String licenseKey){
public F2CLicenseResponse validateLicense(String product, String licenseKey) {
List<String> command = new ArrayList<String>();
StringBuilder result = new StringBuilder();
command.add(validatorUtil);
command.add(licenseKey);
try{
try {
execCommand(result, command);
LogUtil.info("read lic content is : " + result.toString());
F2CLicenseResponse f2CLicenseResponse = new Gson().fromJson(result.toString(), F2CLicenseResponse.class);
if(f2CLicenseResponse.getStatus() != F2CLicenseResponse.Status.valid){
if (f2CLicenseResponse.getStatus() != F2CLicenseResponse.Status.valid) {
return f2CLicenseResponse;
}
if(!StringUtils.equals(f2CLicenseResponse.getLicense().getProduct(), product)){
if (!StringUtils.equals(f2CLicenseResponse.getLicense().getProduct(), product)) {
f2CLicenseResponse.setStatus(F2CLicenseResponse.Status.invalid);
f2CLicenseResponse.setLicense(null);
f2CLicenseResponse.setMessage("The license is unavailable for this product.");
return f2CLicenseResponse;
}
return f2CLicenseResponse;
}catch (Exception e){
} catch (Exception e) {
LogUtil.error(e.getMessage());
// e.printStackTrace();
// return F2CLicenseResponse.invalid(e.getMessage());
return F2CLicenseResponse.noRecord();
}
}
private static int execCommand(StringBuilder result, List<String> command) throws Exception{
private static int execCommand(StringBuilder result, List<String> command) throws Exception {
ProcessBuilder builder = new ProcessBuilder();
builder.command(command);
Process process = builder.start();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line=bufferedReader.readLine()) != null){
while ((line = bufferedReader.readLine()) != null) {
result.append(line).append("\n");
}
int exitCode = process.waitFor();
@ -70,7 +64,7 @@ public class DefaultLicenseService {
public F2CLicenseResponse validateLicense() {
try {
License license = readLicense();
License license = readLicense();
return validateLicense(product, license.getLicense());
} catch (Exception e) {
return F2CLicenseResponse.noRecord();

View File

@ -30,11 +30,11 @@ public class F2CLicenseResponse {
this.message = message;
}
public static enum Status {
public enum Status {
no_record,
valid,
invalid,
expired;
expired
}
public static F2CLicenseResponse invalid(String a) {

View File

@ -22,7 +22,6 @@ class InnerLicenseService {
License getLicense(String key) {
License license = licenseMapper.selectByPrimaryKey(key);
if (license == null) return null;
return license;
}

View File

@ -20,8 +20,8 @@ public class AuthUtils {
AuthUtils.extAuthService = extAuthService;
}
public static CurrentUserDto getUser(){
CurrentUserDto userDto = (CurrentUserDto)SecurityUtils.getSubject().getPrincipal();
public static CurrentUserDto getUser() {
CurrentUserDto userDto = (CurrentUserDto) SecurityUtils.getSubject().getPrincipal();
return userDto;
}

View File

@ -153,16 +153,6 @@ public class CodingUtil {
}
}
/*public static String getSignature(String accessKey, String secretKey) throws Exception {
return aesEncrypt(accessKey + "|" + UUID.randomUUID().toString() + "|" + System.currentTimeMillis(), secretKey, accessKey);
}
public static void main(String[] args) throws Exception{
String accessKey = "gnPFmtAsdLhUEWPA";
String secretKey = "TfK5FGUle0KRfJJJ";
String signature = getSignature(accessKey, secretKey);
System.out.println(signature);
}*/
public static String secretKey() {
try {

View File

@ -95,23 +95,6 @@ public class DateUtils {
}
/* public static void main(String[] args) throws Exception {
// System.out.println("start:");
Date paramTime = getTime(getTimeString(new Long("1607672440731")));
Map<String, Date> weekDate = getWeedFirstTimeAndLastTime(paramTime);
for (Map.Entry<String, Date> entry :
weekDate.entrySet()) {
// System.out.println(entry.getKey() + ":" + getTimeString(entry.getValue())+":"+entry.getValue().getTime());
}
long countTimeLong = new Long("1607672440731");
// System.out.println(getTimeString(--countTimeLong));
} */
/**
* 获取当天的起始时间Date

View File

@ -46,14 +46,8 @@ public class DeFileUtils {
String path = filePath + fileName;
// getCanonicalFile 可解析正确各种路径
File dest = new File(path).getCanonicalFile();
// 检测是否存在目录
if (!dest.getParentFile().exists()) {
if (!dest.getParentFile().mkdirs()) {
// System.out.println("was not successful.");
}
}
// 文件写入
// file.transferTo(dest);
FileOutputStream fileOutputStream = new FileOutputStream(dest);
fileOutputStream.write(file.getBytes());
fileOutputStream.flush();

View File

@ -384,9 +384,14 @@ public class ExcelXlsxReader extends DefaultHandler {
String sstIndex = value.toString();
try {
int idx = Integer.parseInt(sstIndex);
XSSFRichTextString rtss = new XSSFRichTextString(sst.getEntryAt(idx));//根据idx索引值获取内容值
thisStr = rtss.toString();
rtss = null;
if(sst != null){
XSSFRichTextString rtss = new XSSFRichTextString(sst.getEntryAt(idx));//根据idx索引值获取内容值
thisStr = rtss.toString();
rtss = null;
}else {
thisStr = value.toString();
}
} catch (NumberFormatException ex) {
thisStr = value.toString();
}

View File

@ -8,8 +8,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
public class LogUtil {
//日志工具类
// public static final Log Logger = LogFactory.getLog(LogUtil.class);
private static final String DEBUG = "DEBUG";
private static final String INFO = "INFO";

View File

@ -1,40 +1,55 @@
package io.dataease.commons.utils;
import io.dataease.commons.constants.AuthConstants;
import io.dataease.plugins.config.SpringContextUtil;
import org.springframework.core.env.Environment;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class ServletUtils {
public static HttpServletRequest request(){
public static HttpServletRequest request() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();
return request;
}
public static HttpServletResponse response(){
public static HttpServletResponse response() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse();
return response;
}
public static void setToken(String token){
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(){
public static String getToken() {
HttpServletRequest request = request();
String token = request.getHeader(AuthConstants.TOKEN_KEY);
return token;
}
public static String domain() {
InetAddress ip;
String hostAddress = "";
try {
ip = InetAddress.getLocalHost();
hostAddress = ip.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
Environment environment = SpringContextUtil.getBean(Environment.class);
Integer port = environment.getProperty("server.port", Integer.class);
return "http://" + hostAddress + ":" + port;
}
}

View File

@ -124,12 +124,6 @@ public class XssAndSqlHttpServletRequestWrapper extends HttpServletRequestWrappe
case '<':
sb.append("");// 转义小于号
break;
// case '\'':
// sb.append("");// 转义单引号
// break;
// case '\"':
// sb.append("");// 转义双引号
// break;
case '&':
sb.append("");// 转义&
break;
@ -261,7 +255,6 @@ public class XssAndSqlHttpServletRequestWrapper extends HttpServletRequestWrappe
"<[\r\n| | ]*script[\r\n| | ]*>(.*?)</[\r\n| | ]*script[\r\n| | ]*>", Pattern.CASE_INSENSITIVE);
flag = scriptPattern.matcher(value).find();
if (flag) {
// threadLocal.set("包含XSS攻击脚本请检查参数");
return flag;
}
// Avoid anything in a

View File

@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration;
public class FilterConfig {
@Bean
public FilterRegistrationBean registration(){
public FilterRegistrationBean registration() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new SqlFilter());//实例化Filter类
filterRegistrationBean.addUrlPatterns("/*");//设置匹配模式,这里设置为所有可以按需求设置为"/hello"等等

View File

@ -62,13 +62,6 @@ public class Knife4jConfiguration implements BeanPostProcessor{
return defaultApi("系统管理", "io.dataease.controller.sys");
}
/*@Bean(value = "pluginsApi")
@Conditional(LicStatusCondition.class)
public Docket pluginsApi() {
return defaultApi("插件管理", "io.dataease.plugins.server");
}*/
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("DataEase")

View File

@ -32,15 +32,6 @@ public class IndexController {
return "index.html";
}
@GetMapping("/link")
public String link() {
return "link.html";
}
@GetMapping("/test")
public String test() {
return "test.html";
}
@GetMapping("/deApi")
public String deApi() {
@ -49,17 +40,16 @@ public class IndexController {
case valid:
return "doc.html";
default:
// DataEaseException.throwException("Invalid License.");
return "nolic.html";
}
}
@GetMapping("/xggznb/{index}")
public String xggznb(@PathVariable(value = "index", required = true) Long index) {
@GetMapping("/link/{index}")
public String link(@PathVariable(value = "index", required = true) Long index) {
String url = panelLinkService.getUrlByIndex(index);
HttpServletResponse response = ServletUtils.response();
String param = url.substring(url.indexOf("?") + 1);
Cookie cookie = new Cookie("link", param);
Cookie cookie = new Cookie("link", param.split("=")[1]);
response.addCookie(cookie);
return url;
}

View File

@ -1,10 +1,18 @@
package io.dataease.controller.authModel;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.controller.request.authModel.VAuthModelRequest;
import io.dataease.dto.authModel.VAuthModelDTO;
import io.dataease.service.authModel.VAuthModelService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* Author: wangjiahao
* Date: 2021/11/5
@ -16,4 +24,12 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("authModel")
public class VAuthModelController {
@Resource
private VAuthModelService vAuthModelService;
@PostMapping("/queryAuthModel")
public List<VAuthModelDTO> queryAuthModel(@RequestBody VAuthModelRequest request){
return vAuthModelService.queryAuthModel(request);
}
}

View File

@ -17,7 +17,6 @@ import java.util.List;
public class ChartController {
@ApiOperation("查询")
@PostMapping("list")
public List<JSON> list(@RequestBody DataSetTableRequest dataSetTableRequest) {

View File

@ -16,7 +16,6 @@ import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* @Author gin
@ -89,10 +88,6 @@ public class ChartViewController {
public ChartViewDTO getOneWithPermission(@PathVariable String id, @RequestBody ChartExtRequest requestList) throws Exception {
//如果能获取用户 则添加对应的权限
ChartViewDTO dto = chartViewService.getData(id, requestList);
if (dto != null && AuthUtils.getUser() != null) {
ChartViewDTO permissionDto = chartViewService.getOneWithPermission(dto.getId());
dto.setPrivileges(permissionDto.getPrivileges());
}
return dto;
}
@ -107,4 +102,10 @@ public class ChartViewController {
public ChartViewDTO calcData(@RequestBody ChartCalRequest request) throws Exception {
return chartViewService.calcData(request.getView(), request.getRequestList(), false);
}
@ApiOperation("验证视图是否使用相同数据集")
@GetMapping("/checkSameDataSet/{viewIdSource}/{viewIdTarget}")
public String checkSameDataSet(@PathVariable String viewIdSource, @PathVariable String viewIdTarget) throws Exception {
return chartViewService.checkSameDataSet(viewIdSource, viewIdTarget);
}
}

View File

@ -10,9 +10,7 @@ import io.dataease.dto.datasource.TableFiled;
import io.dataease.dto.dataset.DataSetTableDTO;
import io.dataease.dto.dataset.ExcelFileData;
import io.dataease.service.dataset.DataSetTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -132,8 +130,13 @@ public class DataSetTableController {
return dataSetTableService.getDatasetDetail(id);
}
// @ApiOperation("excel上传")
@ApiOperation("excel上传")
@PostMapping("excel/upload")
@ApiImplicitParams({
@ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "MultipartFile"),
@ApiImplicitParam(name = "tableId", value = "数据表ID", required = true, dataType = "String"),
@ApiImplicitParam(name = "editType", value = "编辑类型", required = true, dataType = "Integer")
})
public ExcelFileData excelUpload(@RequestParam("file") MultipartFile file, @RequestParam("tableId") String tableId, @RequestParam("editType") Integer editType) throws Exception {
return dataSetTableService.excelSaveAndParse(file, tableId, editType);
}

View File

@ -11,9 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author gin
@ -65,6 +63,7 @@ public class DataSetTableFieldController {
public DatasetTableField save(@RequestBody DatasetTableField datasetTableField) {
return dataSetTableFieldsService.save(datasetTableField);
}
@ApiOperation("删除")
@PostMapping("delete/{id}")
public void delete(@PathVariable String id) {

View File

@ -68,7 +68,6 @@ public class DatasourceController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<DatasourceDTO>> getDatasourceList(@RequestBody BaseGridRequest request, @PathVariable int goPage, @PathVariable int pageSize) throws Exception {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
// return PageUtils.setPageInfo(page, datasourceService.getDatasourceList(request));
return PageUtils.setPageInfo(page, datasourceService.gridQuery(request));
}

View File

@ -1,51 +0,0 @@
/*
package io.dataease.controller.handler;
import io.dataease.commons.exception.DEException;
import io.dataease.controller.ResultHolder;
import org.apache.shiro.ShiroException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
@RestControllerAdvice
public class RestControllerExceptionHandler {
*/
/*=========== Shiro 异常拦截==============*//*
@ExceptionHandler(ShiroException.class)
public ResultHolder exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
response.setStatus(HttpStatus.UNAUTHORIZED.value());
return ResultHolder.error(exception.getMessage());
}
*/
/*=========== Shiro 异常拦截==============*//*
@ExceptionHandler(UnauthorizedException.class)
public ResultHolder unauthorizedExceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
response.setStatus(HttpStatus.FORBIDDEN.value());
return ResultHolder.error(exception.getMessage());
}
@ExceptionHandler(SQLException.class)
public ResultHolder sqlExceptionHandler(HttpServletRequest request, HttpServletResponse response, DEException e) {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return ResultHolder.error("SQL error happened, please check logs.");
}
@ExceptionHandler(DEException.class)
public ResultHolder msExceptionHandler(HttpServletRequest request, HttpServletResponse response, DEException e) {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return ResultHolder.error(e.getMessage());
}
}
*/

View File

@ -55,7 +55,7 @@ public class ResultResponseBodyAdvice implements ResponseBodyAdvice<Object> {
// i18n
private Object translate(Object obj, String type) {
return Translator.translateObject(obj);
return Translator.translateObject(obj);
}

View File

@ -2,22 +2,16 @@ package io.dataease.controller.panel;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.base.domain.DatasetTableField;
import io.dataease.commons.model.BaseRspModel;
import io.dataease.controller.request.panel.PanelLinkageRequest;
import io.dataease.controller.request.panel.PanelSubjectRequest;
import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseRequest;
import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseResponse;
import io.dataease.dto.panel.linkJump.PanelLinkJumpDTO;
import io.dataease.dto.panel.linkJump.PanelLinkJumpInfoDTO;
import io.dataease.service.panel.PanelLinkJumpService;
import io.dataease.service.panel.PanelViewLinkageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* Author: wangjiahao
@ -35,32 +29,32 @@ public class PanelLinkJumpController {
@ApiOperation("根据视图ID获取对应表字段信息")
@GetMapping("/getTableFieldWithViewId/{viewId}")
public List<DatasetTableField> getTableFieldWithViewId(@PathVariable String viewId){
public List<DatasetTableField> getTableFieldWithViewId(@PathVariable String viewId) {
return panelLinkJumpService.getViewFields(viewId);
}
@ApiOperation("根据仪表板ID和视图ID获取跳转信息")
@GetMapping("/queryWithViewId/{panelId}/{viewId}")
public PanelLinkJumpDTO queryWithViewId(@PathVariable String panelId, @PathVariable String viewId){
return panelLinkJumpService.queryWithView(panelId,viewId);
public PanelLinkJumpDTO queryWithViewId(@PathVariable String panelId, @PathVariable String viewId) {
return panelLinkJumpService.queryWithView(panelId, viewId);
}
@ApiOperation("根据仪表板ID获取跳转信息")
@GetMapping("/queryPanelJumpInfo/{panelId}")
public PanelLinkJumpBaseResponse queryPanelJumpInfo(@PathVariable String panelId){
public PanelLinkJumpBaseResponse queryPanelJumpInfo(@PathVariable String panelId) {
return panelLinkJumpService.queryPanelJumpInfo(panelId);
}
@ApiOperation("更新跳转信息")
@PostMapping("/updateJumpSet")
public void updateJumpSet(@RequestBody PanelLinkJumpDTO jumpDTO){
public void updateJumpSet(@RequestBody PanelLinkJumpDTO jumpDTO) {
panelLinkJumpService.updateJumpSet(jumpDTO);
}
@ApiOperation("获取仪表板目标仪表板跳转联动信息")
@PostMapping("/queryTargetPanelJumpInfo")
public PanelLinkJumpBaseResponse queryTargetPanelJumpInfo(@RequestBody PanelLinkJumpBaseRequest request){
public PanelLinkJumpBaseResponse queryTargetPanelJumpInfo(@RequestBody PanelLinkJumpBaseRequest request) {
return panelLinkJumpService.queryTargetPanelJumpInfo(request);
}
}

View File

@ -27,7 +27,7 @@ public class PanelPdfTemplateController {
@GetMapping("queryAll")
@ApiOperation("查询所有仪表板模板")
public List<PanelPdfTemplate> queryAll(){
public List<PanelPdfTemplate> queryAll() {
return panelPdfTemplateService.queryAll();
}

View File

@ -29,22 +29,20 @@ public class PanelViewLinkageController {
@ApiOperation("获取仪表板所有视图联动信息")
@PostMapping("/getViewLinkageGather")
public Map getViewLinkageGather(@RequestBody PanelLinkageRequest request){
public Map getViewLinkageGather(@RequestBody PanelLinkageRequest request) {
return panelViewLinkageService.getViewLinkageGather(request);
}
@ApiOperation("保存仪表板视图联动信息")
@PostMapping("/saveLinkage")
public BaseRspModel saveLinkage(@RequestBody PanelLinkageRequest request){
public BaseRspModel saveLinkage(@RequestBody PanelLinkageRequest request) {
panelViewLinkageService.saveLinkage(request);
return new BaseRspModel();
}
@ApiOperation("获取当前仪表板所有联动信息")
@GetMapping("/getPanelAllLinkageInfo/{panelId}")
public Map<String, List<String>> getPanelAllLinkageInfo(@PathVariable String panelId){
public Map<String, List<String>> getPanelAllLinkageInfo(@PathVariable String panelId) {
return panelViewLinkageService.getPanelAllLinkageInfo(panelId);
}

View File

@ -4,7 +4,6 @@ import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.base.domain.PanelShare;
import io.dataease.controller.request.panel.PanelShareFineDto;
import io.dataease.controller.request.panel.PanelShareRemoveRequest;
import io.dataease.controller.request.panel.PanelShareRequest;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.dto.panel.PanelShareDto;
import io.dataease.dto.panel.PanelShareOutDTO;
@ -15,7 +14,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
@ -27,9 +25,7 @@ import java.util.List;
@RequestMapping("/api/share")
public interface ShareApi {
/*@ApiIgnore
@PostMapping("/")
void share(PanelShareRequest request);*/
@ApiOperation("查询分享给我")
@PostMapping("/treeList")

View File

@ -2,7 +2,6 @@ package io.dataease.controller.panel.server;
import io.dataease.base.domain.PanelLink;
import io.dataease.controller.ResultHolder;
import io.dataease.controller.panel.api.LinkApi;
import io.dataease.controller.request.chart.ChartExtRequest;
import io.dataease.controller.request.panel.link.*;
@ -17,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.net.URLDecoder;
import java.util.Map;
@ -24,7 +24,6 @@ import java.util.Map;
public class LinkServer implements LinkApi {
@Autowired
private PanelLinkService panelLinkService;
@ -42,12 +41,11 @@ public class LinkServer implements LinkApi {
panelLinkService.changeEnablePwd(request);
}
@Override
public void resetOverTime(@RequestBody OverTimeRequest request) {
panelLinkService.overTime(request);
}
@Override
@ -61,16 +59,16 @@ public class LinkServer implements LinkApi {
}
@Override
public ValidateDto validate(@RequestBody LinkValidateRequest request) throws Exception{
public ValidateDto validate(@RequestBody LinkValidateRequest request) throws Exception {
String link = request.getLink();
link = URLDecoder.decode(link, "UTF-8");
String json = panelLinkService.decryptParam(link);
ValidateDto dto = new ValidateDto();
String resourceId = json;
/* String resourceId = request.getResourceId(); */
PanelLink one = panelLinkService.findOne(resourceId);
dto.setResourceId(resourceId);
if (ObjectUtils.isEmpty(one)){
if (ObjectUtils.isEmpty(one)) {
dto.setValid(false);
return dto;
}
@ -92,18 +90,13 @@ public class LinkServer implements LinkApi {
}
@Override
public Object viewDetail(String viewId, ChartExtRequest requestList) throws Exception{
public Object viewDetail(String viewId, ChartExtRequest requestList) throws Exception {
return chartViewService.getData(viewId, requestList);
}
/*@Override
public ResultHolder shortUrl(Map<String,String> param) {
String url = param.get("url");
return panelLinkService.getShortUrl(url);
}*/
@Override
public String shortUrl(Map<String,String> param) {
public String shortUrl(Map<String, String> param) {
String resourceId = param.get("resourceId");
return panelLinkService.getShortUrl(resourceId);
}

View File

@ -22,10 +22,7 @@ public class ShareServer implements ShareApi {
@Resource
private ShareService shareService;
/*@Override
public void share(@RequestBody PanelShareRequest request) {
shareService.save(request);
}*/
@Override
public List<PanelShareDto> treeList(@RequestBody BaseGridRequest request) {

View File

@ -36,7 +36,6 @@ public class ViewServer implements ViewApi {
if(CollectionUtils.isNotEmpty(groups)&&CollectionUtils.isNotEmpty(views)){
groups.addAll(views);
}
// List<PanelViewDto> panelViewDtos = panelViewService.buildTree(groups, views);
return TreeUtils.mergeTree(groups);
}

View File

@ -0,0 +1,22 @@
package io.dataease.controller.request.authModel;
import io.dataease.dto.authModel.VAuthModelDTO;
import lombok.Data;
import java.util.List;
/**
* Author: wangjiahao
* Date: 2021/11/24
* Description:
*/
@Data
public class VAuthModelRequest extends VAuthModelDTO {
private String userId;
private String privileges;
private Integer datasetMode;
private boolean clearEmptyDir;
private List<String> modelInnerTypeArray;
}

View File

@ -1,6 +1,7 @@
package io.dataease.controller.request.chart;
import io.dataease.base.domain.ChartViewWithBLOBs;
import io.dataease.dto.chart.ChartViewDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -11,7 +12,7 @@ import lombok.Data;
@Data
public class ChartCalRequest {
@ApiModelProperty("视图")
private ChartViewWithBLOBs view;
private ChartViewDTO view;
@ApiModelProperty("额外请求参数")
private ChartExtRequest requestList;
}

View File

@ -22,4 +22,16 @@ public class ChartExtRequest {
@ApiModelProperty("下钻维度集合")
private List<ChartDrillRequest> drill;
@ApiModelProperty("数据查询来源")
private String queryFrom;
@ApiModelProperty("视图结果展示模式")
private String resultMode;
@ApiModelProperty("视图结果展示数量")
private Integer resultCount;
@ApiModelProperty("使用缓存:默认使用")
private boolean cache = true;
}

View File

@ -7,15 +7,15 @@ import java.util.List;
@Data
public class EsReponse {
private List<Column>columns = new ArrayList<>();
private List<String[]>rows = new ArrayList<>();
private List<Column> columns = new ArrayList<>();
private List<String[]> rows = new ArrayList<>();
private String cursor;
private Integer status;
private Error error;
private String version;
@Data
public class Error{
public class Error {
private String type;
private String reason;
}

View File

@ -62,7 +62,6 @@ public class MsgController {
if(null == AuthUtils.getUser() || (userId = AuthUtils.getUser().getUserId()) == null) {
throw new RuntimeException("缺少用户ID");
}
// Long userId = request.get("userId");
return sysMsgService.queryCount(userId);
}

View File

@ -4,14 +4,10 @@ import io.dataease.base.domain.SysDept;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.controller.ResultHolder;
import io.dataease.controller.sys.base.BaseGridRequest;
/*import io.dataease.controller.sys.request.DeptCreateRequest;
import io.dataease.controller.sys.request.DeptDeleteRequest;
import io.dataease.controller.sys.request.DeptStatusRequest;*/
import io.dataease.controller.sys.response.DeptNodeResponse;
import io.dataease.controller.sys.response.DeptTreeNode;
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.*;
@ -56,34 +52,7 @@ public class SysDeptController extends ResultHolder {
return nodeResponses;
}
/*@ApiOperation("查询部门")
@PostMapping("/root")
public ResultHolder rootData(){
List<SysDept> root = deptService.nodesByPid(null);
return success(root);
}*/
/*@ApiOperation("新增部门")
@PostMapping("/create")
public void create(@RequestBody DeptCreateRequest dept){
deptService.add(dept);
}
@ApiOperation("删除部门")
@PostMapping("/delete")
public void delete(@RequestBody List<DeptDeleteRequest> requests){
deptService.batchDelete(requests);
}
@ApiOperation("更新部门")
@PostMapping("/update")
public void update(@RequestBody DeptCreateRequest dept){
deptService.update(dept);
}
@ApiOperation("更新状态")
@PostMapping("/updateStatus")
public void updateStatus(@RequestBody DeptStatusRequest request){
deptService.updateStatus(request);
}*/
@PostMapping("/nodesByDeptId/{deptId}")
public List<DeptTreeNode> nodesByDeptId(@PathVariable("deptId") Long deptId){

View File

@ -1,78 +0,0 @@
package io.dataease.controller.sys;
/*import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.dataease.base.domain.SysRole;
import io.dataease.commons.utils.PageUtils;
import io.dataease.commons.utils.Pager;
import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.controller.sys.request.RoleMenusRequest;*/
import io.dataease.controller.sys.response.RoleUserItem;
import io.dataease.service.sys.SysRoleService;
import io.swagger.annotations.Api;
/*import io.swagger.annotations.ApiOperation;*/
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
/*@ApiIgnore
@RestController
@RequiredArgsConstructor
@Api(tags = "系统:角色管理")
@RequestMapping("/api/role")
public class SysRoleController {*/
/*
@Resource
private SysRoleService sysRoleService;
@ApiOperation("新增角色")
@PostMapping("/create")
public void create(@RequestBody SysRole role){
sysRoleService.add(role);
}
@ApiOperation("删除角色")
@PostMapping("/delete/{roleId}")
public void delete(@PathVariable("roleId") Long roleId){
sysRoleService.delete(roleId);
}
@ApiOperation("更新角色")
@PostMapping("/update")
public void update(@RequestBody SysRole role){
sysRoleService.update(role);
}
@ApiOperation("查询角色")
@PostMapping("/roleGrid/{goPage}/{pageSize}")
public Pager<List<SysRole>> roleGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody BaseGridRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
Pager<List<SysRole>> listPager = PageUtils.setPageInfo(page, sysRoleService.query(request));
return listPager;
}
@ApiOperation("查询角色对应的菜单ID")
@PostMapping("/menuIds/{roleId}")
public List<Long> menuIdsByRoleId(@PathVariable("roleId") Long roleId){
return sysRoleService.menuIds(roleId);
}
@PostMapping("/saveRolesMenus")
public void saveRolesMenus(@RequestBody RoleMenusRequest request){
sysRoleService.batchSaveRolesMenus(request);
}
@PostMapping("/all")
public List<RoleUserItem> all(){
return sysRoleService.allRoles();
}
*/
/*}*/

View File

@ -54,10 +54,7 @@ public class SysUserController {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, sysUserService.query(request));
}
/*public Pager<List<SysUserGridResponse>> userGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody UserGridRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, sysUserService.query(request));
}*/
@ApiOperation("创建用户")
@PostMapping("/create")
@ -146,11 +143,7 @@ public class SysUserController {
}
/* @ApiOperation("同步用户")
@PostMapping("/sync")
public void importLdap(@RequestBody LdapAddRequest request) {
sysUserService.saveLdapUsers(request);
} */
@ApiOperation("已同步用户")
@PostMapping("/existLdapUsers")

View File

@ -6,8 +6,8 @@ import io.dataease.controller.sys.response.BasicInfo;
import io.dataease.controller.sys.response.MailInfo;
import io.dataease.dto.SystemParameterDTO;
import io.dataease.service.FileService;
import io.dataease.service.system.EmailService;
import io.dataease.service.system.SystemParameterService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@ -16,12 +16,12 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ApiIgnore
@RestController
@RequestMapping(value = "/system")
@ -32,10 +32,13 @@ public class SystemParameterController {
@Resource
private FileService fileService;
@Resource
private EmailService emailService;
@GetMapping("/mail/info")
public MailInfo mailInfo() {
return systemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
return emailService.mailInfo();
}
@GetMapping("/basic/info")
@ -51,7 +54,7 @@ public class SystemParameterController {
@PostMapping("/edit/email")
public void editMail(@RequestBody List<SystemParameter> systemParameter) {
systemParameterService.editMail(systemParameter);
emailService.editMail(systemParameter);
}
@PostMapping("/edit/basic")
@ -61,7 +64,7 @@ public class SystemParameterController {
@PostMapping("/testConnection")
public void testConnection(@RequestBody HashMap<String, String> hashMap) {
systemParameterService.testConnection(hashMap);
emailService.testConnection(hashMap);
}
@GetMapping("/version")

View File

@ -15,34 +15,4 @@ import java.util.List;
public class SysAuthDTO extends SysAuth {
private List<SysAuthDetail> sysAuthDetails;
// private List<BaseAuthDetail> baseAuthDetails;
//
// private String authDetails;
//
// @Override
// public void setAuthDetails(String authDetails) {
// this.authDetails = authDetails;
// if(StringUtils.isNotEmpty(authDetails)){
// try{
// baseAuthDetails = JSON.parseArray(authDetails,BaseAuthDetail.class);
// }catch (Exception e){
// e.printStackTrace();
// //ignored
// }
// }
// }
//
// public List<BaseAuthDetail> getBaseAuthDetails() {
// return baseAuthDetails;
// }
//
// public void setBaseAuthDetails(List<BaseAuthDetail> baseAuthDetails) {
// this.baseAuthDetails = baseAuthDetails;
// }
//
// @Override
// public String getAuthDetails() {
// return authDetails;
// }
}

View File

@ -1,12 +1,21 @@
package io.dataease.dto.authModel;
import io.dataease.base.domain.VAuthModel;
import io.dataease.base.domain.VAuthModelWithBLOBs;
import io.dataease.commons.model.ITreeBase;
import lombok.Data;
import java.util.List;
/**
* Author: wangjiahao
* Date: 2021/11/5
* Description:
*/
public class VAuthModelDTO extends VAuthModel {
@Data
public class VAuthModelDTO extends VAuthModelWithBLOBs implements ITreeBase<VAuthModelDTO> {
private String privileges;
private List<VAuthModelDTO> children;
private long allLeafs = 0l;
}

View File

@ -75,9 +75,7 @@ public class ScheduleManager {
triggerBuilder.withIdentity(triggerKey);
Date nTimeByCron = getNTimeByCron(cron, startTime);
// if (startTime.before(new Date())) {
triggerBuilder.startAt(nTimeByCron);
// }
if (endTime != null) {
if (endTime.before(nTimeByCron)) {
@ -160,9 +158,7 @@ public class ScheduleManager {
triggerBuilder.withIdentity(triggerKey);// 触发器名,触发器组
Date nTimeByCron = getNTimeByCron(cron, startTime);
// if (startTime.before(new Date())) {
triggerBuilder.startAt(nTimeByCron);
// }
if (endTime != null) {
if (endTime.before(nTimeByCron)) {
@ -179,14 +175,6 @@ public class ScheduleManager {
trigger = (CronTrigger) triggerBuilder.build();// 创建Trigger对象
scheduler.rescheduleJob(triggerKey, trigger);// 修改一个任务的触发时间
/** 方式一 :调用 rescheduleJob 结束 */
/** 方式二先删除然后在创建一个新的Job */
// JobDetail jobDetail = sched.getJobDetail(JobKey.jobKey(jobName, jobGroupName));
// Class<? extends Job> jobClass = jobDetail.getJobClass();
// removeJob(jobName, jobGroupName, triggerName, triggerGroupName);
// addJob(jobName, jobGroupName, triggerName, triggerGroupName, jobClass, cron);
/** 方式二 先删除然后在创建一个新的Job */
} catch (Exception e) {
DataEaseException.throwException(e);
}
@ -227,15 +215,6 @@ public class ScheduleManager {
trigger = (SimpleTrigger) triggerBuilder.build();// 创建Trigger对象
scheduler.rescheduleJob(triggerKey, trigger);// 修改一个任务的触发时间
/** 方式一 :调用 rescheduleJob 结束 */
/** 方式二先删除然后在创建一个新的Job */
// JobDetail jobDetail = sched.getJobDetail(JobKey.jobKey(jobName, jobGroupName));
// Class<? extends Job> jobClass = jobDetail.getJobClass();
// removeJob(jobName, jobGroupName, triggerName, triggerGroupName);
// addJob(jobName, jobGroupName, triggerName, triggerGroupName, jobClass, cron);
/** 方式二 先删除然后在创建一个新的Job */
}
} catch (Exception e) {
@ -436,4 +415,8 @@ public class ScheduleManager {
scheduler.triggerJob(jobKey);
}
public void fireNow(JobKey jobKey) throws SchedulerException {
scheduler.triggerJob(jobKey);
}
}

View File

@ -0,0 +1,118 @@
package io.dataease.job.sechedule.strategy;
import io.dataease.job.sechedule.ScheduleManager;
import io.dataease.plugins.common.entity.GlobalTaskEntity;
import org.apache.commons.lang3.ObjectUtils;
import org.quartz.*;
import org.springframework.beans.factory.InitializingBean;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public abstract class TaskHandler implements InitializingBean {
private static final String[] week = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};
public void addTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) throws Exception {
// 1首先看看是否过期
Long endTime = taskEntity.getEndTime();
removeTask(scheduleManager, taskEntity);
if (taskExpire(endTime)) { // 过期了就删除任务
return;
}
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
TriggerKey triggerKey = new TriggerKey(taskEntity.getTaskId().toString());
Date start = new Date(taskEntity.getStartTime());
Date end = null;
if (ObjectUtils.isNotEmpty(taskEntity.getEndTime())) {
new Date(taskEntity.getEndTime());
}
Class executor = this.getClass();
String cron = cron(taskEntity);
scheduleManager.addOrUpdateCronJob(jobKey, triggerKey, executor, cron, start, end, jobDataMap(taskEntity));
}
protected abstract JobDataMap jobDataMap(GlobalTaskEntity taskEntity);
private String cron(GlobalTaskEntity taskEntity) {
if (taskEntity.getRateType() == -1) {
return taskEntity.getRateVal();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(taskEntity.getRateVal());
} catch (ParseException e) {
e.printStackTrace();
}
Calendar instance = Calendar.getInstance();
instance.setTime(date);
if (taskEntity.getRateType() == 0) {
return
instance.get(Calendar.SECOND) + " " +
instance.get(Calendar.MINUTE) + " " +
instance.get(Calendar.HOUR_OF_DAY) + " * * ?";
}
if (taskEntity.getRateType() == 1) {
return
instance.get(Calendar.SECOND) + " " +
instance.get(Calendar.MINUTE) + " " +
instance.get(Calendar.HOUR_OF_DAY) + " ? * " +
getDayOfWeek(instance);
}
if (taskEntity.getRateType() == 2) {
return
instance.get(Calendar.SECOND) + " " +
instance.get(Calendar.MINUTE) + " " +
instance.get(Calendar.HOUR_OF_DAY) + " " +
instance.get(Calendar.DATE) + " * ?";
}
return null;
}
private String getDayOfWeek(Calendar instance) {
int index = instance.get(Calendar.DAY_OF_WEEK) - 1;
return week[index];
}
public void removeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) {
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
TriggerKey triggerKey = new TriggerKey(taskEntity.getTaskId().toString());
scheduleManager.removeJob(jobKey, triggerKey);
}
public void executeTask(ScheduleManager scheduleManager, GlobalTaskEntity taskEntity) throws Exception {
JobKey jobKey = new JobKey(taskEntity.getTaskId().toString());
scheduleManager.fireNow(jobKey);
}
//判断任务是否过期
public Boolean taskExpire(Long endTime) {
if (ObjectUtils.isEmpty(endTime)) return false;
Long now = System.currentTimeMillis();
return now > endTime;
}
@Override
public void afterPropertiesSet() throws Exception {
String beanName = null;
String className = this.getClass().getName();
className = className.substring(className.lastIndexOf(".") + 1);
if (className.length() > 1) {
beanName = className.substring(0, 1).toLowerCase() + className.substring(1);
} else {
beanName = className.toLowerCase();
}
TaskStrategyFactory.register(beanName, this);
}
}

View File

@ -0,0 +1,23 @@
package io.dataease.job.sechedule.strategy;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TaskStrategyFactory {
private static Map<String, TaskHandler> strategyMap = new ConcurrentHashMap<>();
public static TaskHandler getInvokeStrategy(String name) {
return strategyMap.get(name);
}
public static void register(String name, TaskHandler handler) {
if (StringUtils.isEmpty(name) || null == handler) {
return;
}
strategyMap.put(name, handler);
}
}

View File

@ -0,0 +1,161 @@
package io.dataease.job.sechedule.strategy.impl;
import io.dataease.auth.entity.SysUserEntity;
import io.dataease.auth.entity.TokenInfo;
import io.dataease.auth.service.AuthUserService;
import io.dataease.auth.service.impl.AuthUserServiceImpl;
import io.dataease.auth.util.JWTUtils;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.LogUtil;
import io.dataease.commons.utils.ServletUtils;
import io.dataease.job.sechedule.ScheduleManager;
import io.dataease.job.sechedule.strategy.TaskHandler;
import io.dataease.plugins.common.entity.GlobalTaskEntity;
import io.dataease.plugins.common.entity.GlobalTaskInstance;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.email.dto.request.XpackPixelEntity;
import io.dataease.plugins.xpack.email.dto.response.XpackEmailTemplateDTO;
import io.dataease.plugins.xpack.email.service.EmailXpackService;
import io.dataease.service.system.EmailService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class EmailTaskHandler extends TaskHandler implements Job {
private static final Integer RUNING = 0;
private static final Integer SUCCESS = 1;
private static final Integer ERROR = -1;
@Resource
private AuthUserServiceImpl authUserServiceImpl;
@Override
protected JobDataMap jobDataMap(GlobalTaskEntity taskEntity) {
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("taskEntity", taskEntity);
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
XpackEmailTemplateDTO emailTemplateDTO = emailXpackService.emailTemplate(taskEntity.getTaskId());
jobDataMap.put("emailTemplate", emailTemplateDTO);
SysUserEntity creator = authUserServiceImpl.getUserByIdNoCache(taskEntity.getCreator());
jobDataMap.put("creator", creator);
return jobDataMap;
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// 插件没有加载 空转
if (!CommonBeanFactory.getBean(AuthUserService.class).pluginLoaded()) return;
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
GlobalTaskEntity taskEntity = (GlobalTaskEntity) jobDataMap.get("taskEntity");
if (taskExpire(taskEntity.getEndTime())) {
ScheduleManager scheduleManager = SpringContextUtil.getBean(ScheduleManager.class);
removeTask(scheduleManager, taskEntity);
return;
}
GlobalTaskInstance taskInstance = buildInstance(taskEntity);
Long instanceId = saveInstance(taskInstance);
taskInstance.setInstanceId(instanceId);
XpackEmailTemplateDTO emailTemplate = (XpackEmailTemplateDTO) jobDataMap.get("emailTemplate");
SysUserEntity creator = (SysUserEntity) jobDataMap.get("creator");
proxy().sendReport(taskInstance, emailTemplate, creator);
}
public EmailTaskHandler proxy() {
return CommonBeanFactory.getBean(EmailTaskHandler.class);
}
public Long saveInstance(GlobalTaskInstance taskInstance) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
return emailXpackService.saveInstance(taskInstance);
}
private GlobalTaskInstance buildInstance(GlobalTaskEntity taskEntity) {
GlobalTaskInstance taskInstance = new GlobalTaskInstance();
taskInstance.setTaskId(taskEntity.getTaskId());
taskInstance.setStatus(RUNING);
taskInstance.setExecuteTime(System.currentTimeMillis());
return taskInstance;
}
private void success(GlobalTaskInstance taskInstance) {
taskInstance.setStatus(SUCCESS);
taskInstance.setFinishTime(System.currentTimeMillis());
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
emailXpackService.saveInstance(taskInstance);
}
private void error(GlobalTaskInstance taskInstance, Throwable t) {
taskInstance.setStatus(ERROR);
taskInstance.setInfo(t.getMessage());
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
emailXpackService.saveInstance(taskInstance);
}
@Async
public void sendReport(GlobalTaskInstance taskInstance, XpackEmailTemplateDTO emailTemplateDTO, SysUserEntity user) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
try {
byte[] bytes = emailXpackService.printData(panelUrl(emailTemplateDTO.getPanelId()), tokenByUser(user), buildPixel(emailTemplateDTO));
// 下面继续执行发送邮件的
String recipients = emailTemplateDTO.getRecipients();
byte[] content = emailTemplateDTO.getContent();
EmailService emailService = SpringContextUtil.getBean(EmailService.class);
String contentStr = "";
if (ObjectUtils.isNotEmpty(content)) {
contentStr = new String(content, "UTF-8");
}
emailService.sendWithImage(recipients, emailTemplateDTO.getTitle(), contentStr, bytes);
success(taskInstance);
} catch (Exception e) {
error(taskInstance, e);
LogUtil.error(e.getMessage(), e);
}
}
private XpackPixelEntity buildPixel(XpackEmailTemplateDTO emailTemplateDTO) {
XpackPixelEntity pixelEntity = new XpackPixelEntity();
String pixelStr = emailTemplateDTO.getPixel();
if (StringUtils.isBlank(pixelStr)) return null;
String[] arr = pixelStr.split("\\*");
if (arr.length != 2) return null;
try {
int x = Integer.parseInt(arr[0]);
int y = Integer.parseInt(arr[1]);
pixelEntity.setX(String.valueOf(x));
pixelEntity.setY(String.valueOf(y));
return pixelEntity;
} catch (Exception e) {
return null;
}
}
private String tokenByUser(SysUserEntity user) {
TokenInfo tokenInfo = TokenInfo.builder().userId(user.getUserId()).username(user.getUsername()).build();
String token = JWTUtils.sign(tokenInfo, user.getPassword());
return token;
}
private String panelUrl(String panelId) {
String domain = ServletUtils.domain();
return domain + "/#/preview/" + panelId;
}
}

View File

@ -0,0 +1,42 @@
package io.dataease.listener;
import io.dataease.auth.service.AuthUserService;
import io.dataease.job.sechedule.ScheduleManager;
import io.dataease.job.sechedule.strategy.TaskHandler;
import io.dataease.job.sechedule.strategy.TaskStrategyFactory;
import io.dataease.plugins.common.entity.GlobalTaskEntity;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.email.service.EmailXpackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class GlobalTaskStartListener implements ApplicationListener<ApplicationReadyEvent> {
@Autowired
private AuthUserService authUserService;
@Autowired
private ScheduleManager scheduleManager;
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
if (authUserService.pluginLoaded()) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
List<GlobalTaskEntity> tasks = emailXpackService.allTask();
tasks.stream().forEach(task -> {
TaskHandler taskHandler = TaskStrategyFactory.getInvokeStrategy(task.getTaskType());
try {
taskHandler.addTask(scheduleManager, task);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}

View File

@ -21,20 +21,14 @@ public class LicCacheEventListener extends CacheEventListenerFactory implements
@Override
public void notifyElementRemoved(Ehcache ehcache, Element element) throws CacheException {
/*System.out.println("notifyElementRemoved");*/
}
@Override
public void notifyElementPut(Ehcache ehcache, Element element) throws CacheException {
/*long expirationTime = element.getExpirationTime();
System.out.println(expirationTime);
System.out.println("notifyElementPut");*/
}
@Override
public void notifyElementUpdated(Ehcache ehcache, Element element) throws CacheException {
/*System.out.println("notifyElementUpdated");*/
}
/**
@ -51,12 +45,10 @@ public class LicCacheEventListener extends CacheEventListenerFactory implements
@Override
public void notifyElementEvicted(Ehcache ehcache, Element element) {
/*System.out.println("notifyElementEvicted");*/
}
@Override
public void notifyRemoveAll(Ehcache ehcache) {
/*System.out.println("notifyRemoveAll");*/
}
@Override

View File

@ -28,7 +28,6 @@ public class MapServer implements MapApi {
@Override
public String asyncGeometry() {
try {
// List<AreaEntity> areaEntities = MapUtils.readAreaEntity();
List<AreaEntity> areaEntities = mapService.areaEntities();
MapUtils.recursionWriteFull(areaEntities);
}catch (Exception e) {

View File

@ -34,15 +34,10 @@ public class MapUtils {
public static String formatCode(String code) {
// return code.substring(3);
return code;
}
/*public static List<Map<String, Object>> readCodeList( ) {
ExcelReader reader = ExcelUtil.getReader(path);
List<Map<String, Object>> maps = reader.readAll();
return maps;
}*/
public static List<Map<String, Object>> readCodeList( ) {
AreaMappingExample example = new AreaMappingExample();
List<AreaMapping> areaMappings = areaMappingMapper.selectByExample(example);
@ -61,7 +56,6 @@ public class MapUtils {
public static List<AreaEntity> readAreaEntity() {
List<Map<String, Object>> maps = readCodeList();
// AreaEntity root = new AreaEntity;
Map<String, AreaEntity> provinceMap = new ConcurrentHashMap<>();
Map<String, AreaEntity> cityMap = new ConcurrentHashMap<>();
@ -70,7 +64,6 @@ public class MapUtils {
AreaEntity china = root();
maps.stream().forEach(map -> {
// maps.stream().forEach(map -> {
String province_code = map.get(Constants.PROVINCE_CODE).toString();
String city_code = map.get(Constants.CITY_CODE).toString();
String county_code = map.get(Constants.COUNTY_CODE).toString();
@ -114,7 +107,6 @@ public class MapUtils {
}
}
});
// List<AreaEntity> treeNodes = provinceMap.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList());
List<AreaEntity> result = new ArrayList<>();
result.add(china);
return result;
@ -131,10 +123,6 @@ public class MapUtils {
if (StrUtil.equals("1", mapResponse.getStatus()) && StrUtil.equalsAnyIgnoreCase("ok", mapResponse.getInfo()) && StrUtil.equalsAnyIgnoreCase("10000", mapResponse.getInfocode())) {
List<District> districts = mapResponse.getDistricts();
if (CollectionUtil.isNotEmpty(districts)) {
/*District district = districts.get(0);
MapResultDto mapResultDto = buildGeometry(district, areaEntity);
writeFeatureFile(mapResultDto, areaEntity.getCode());*/
List<Feature> kidFeatures = districts.stream().map(district -> buildFeature(district, areaEntity)).collect(Collectors.toList());
MapResultDto mapResultDto = buildGeometry(kidFeatures);
writeFeatureFile(mapResultDto, areaEntity.getCode());
@ -234,15 +222,7 @@ public class MapUtils {
/*public static MapResultDto buildGeometry(District district, AreaEntity areaEntity) {
Feature feature = buildFeature(district, areaEntity);
MapResultDto mapResultDto = new MapResultDto();
mapResultDto.setType("FeatureCollection");
List<Feature> features = new ArrayList<>();
features.add(feature);
mapResultDto.setFeatures(features);
return mapResultDto;
}*/
public static MapResultDto buildGeometry(List<Feature> features) {
MapResultDto mapResultDto = new MapResultDto();

View File

@ -47,7 +47,6 @@ public class PluginRunner implements ApplicationRunner {
}
} catch (Exception e) {
LogUtil.error(e);
//e.printStackTrace();
}
});

View File

@ -76,7 +76,6 @@ public class ControllerLoader {
try {
registerController(name);
} catch (Exception e) {
// e.printStackTrace();
LogUtil.error(e);
}
});

View File

@ -104,9 +104,6 @@ public class ModuleClassLoader extends URLClassLoader {
byte[] classBytes = baos.toByteArray();
classBytesMap.put(className,classBytes);
}
/*if (name.endsWith(".xml")) {
loadMapperXml(name);
}*/
}
} catch (IOException e) {
e.printStackTrace();

View File

@ -0,0 +1,150 @@
package io.dataease.plugins.server;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.dataease.commons.exception.DEException;
import io.dataease.commons.utils.*;
import io.dataease.plugins.common.entity.GlobalTaskEntity;
import io.dataease.plugins.common.entity.GlobalTaskInstance;
import io.dataease.plugins.common.entity.XpackGridRequest;
import io.dataease.plugins.config.SpringContextUtil;
import io.dataease.plugins.xpack.email.dto.request.XpackEmailCreate;
import io.dataease.plugins.xpack.email.dto.request.XpackEmailTaskRequest;
import io.dataease.plugins.xpack.email.dto.request.XpackEmailViewRequest;
import io.dataease.plugins.xpack.email.dto.request.XpackPixelEntity;
import io.dataease.plugins.xpack.email.dto.response.XpackTaskGridDTO;
import io.dataease.plugins.xpack.email.dto.response.XpackTaskInstanceDTO;
import io.dataease.plugins.xpack.email.service.EmailXpackService;
import io.dataease.service.ScheduleService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Api(tags = "xpack定时报告")
@RequestMapping("/plugin/task")
@RestController
public class XEmailTaskServer {
@Autowired
private ScheduleService scheduleService;
@PostMapping("/queryTasks/{goPage}/{pageSize}")
public Pager<List<XpackTaskGridDTO>> queryTask(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody XpackGridRequest request) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
List<XpackTaskGridDTO> tasks = emailXpackService.taskGrid(request);
Pager<List<XpackTaskGridDTO>> listPager = PageUtils.setPageInfo(page, tasks);
return listPager;
}
@PostMapping("/save")
public void save(@RequestBody XpackEmailCreate param) throws Exception {
XpackEmailTaskRequest request = param.fillContent();
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
request.setCreator(AuthUtils.getUser().getUserId());
emailXpackService.save(request);
GlobalTaskEntity globalTask = BeanUtils.copyBean(new GlobalTaskEntity(), request);
scheduleService.addSchedule(globalTask);
}
@PostMapping("/queryForm/{taskId}")
public XpackEmailCreate queryForm(@PathVariable Long taskId) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
XpackEmailTaskRequest taskForm = emailXpackService.taskForm(taskId);
XpackEmailCreate xpackEmailCreate = new XpackEmailCreate();
byte[] bytes = taskForm.getContent();
if (ObjectUtils.isNotEmpty(bytes)) {
String emailContent;
try {
emailContent = new String(bytes, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
taskForm.setContent(null);
xpackEmailCreate.setEmailContent(emailContent);
}
xpackEmailCreate.setRequest(taskForm);
return xpackEmailCreate;
}
@PostMapping("/preview")
public String preview(@RequestBody XpackEmailViewRequest request) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
String panelId = request.getPanelId();
String content = request.getContent();
String url = ServletUtils.domain() + "/#/preview/" + panelId;
String token = ServletUtils.getToken();
String fileId = null;
try {
fileId = emailXpackService.print(url, token, buildPixel(request.getPixel()));
} catch (Exception e) {
LogUtil.error(e);
DEException.throwException("预览失败,请联系管理员");
}
String imageUrl = "/system/ui/image/" + fileId;
String html = "<div>" +
"<h2>" + content + "</h2>" +
"<img style='width: 100%;' id='" + panelId + "' src='" + imageUrl + "' />" +
"</div>";
return html;
}
@PostMapping("/delete/{taskId}")
public void delete(@PathVariable Long taskId) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
try {
XpackEmailTaskRequest request = emailXpackService.taskForm(taskId);
GlobalTaskEntity globalTaskEntity = BeanUtils.copyBean(new GlobalTaskEntity(), request);
scheduleService.deleteSchedule(globalTaskEntity);
emailXpackService.delete(taskId);
} catch (Exception e) {
LogUtil.error(e);
DEException.throwException(e);
}
}
@PostMapping("/queryInstancies/{goPage}/{pageSize}")
public Pager<List<XpackTaskInstanceDTO>> instancesGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody XpackGridRequest request) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
List<XpackTaskInstanceDTO> instances = emailXpackService.taskInstanceGrid(request);
Pager<List<XpackTaskInstanceDTO>> listPager = PageUtils.setPageInfo(page, instances);
return listPager;
}
@PostMapping("/execInfo/{instanceId}")
public String execInfo(@PathVariable Long instanceId) {
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
GlobalTaskInstance instanceForm = emailXpackService.instanceForm(instanceId);
return instanceForm.getInfo();
}
private XpackPixelEntity buildPixel(String pixel) {
if (StringUtils.isBlank(pixel)) return null;
String[] arr = pixel.split("\\*");
if (arr.length != 2) return null;
try {
XpackPixelEntity result = new XpackPixelEntity();
int x = Integer.parseInt(arr[0]);
int y = Integer.parseInt(arr[1]);
result.setX(String.valueOf(x));
result.setY(String.valueOf(y));
return result;
} catch (Exception e) {
return null;
}
}
}

View File

@ -36,7 +36,6 @@ public class XOidcServer {
Map<String, String> authParam = new HashMap<>();
authParam.put("response_type", "code");
authParam.put("state", "state");
// authParam.put("redirect_uri", "http://localhost:9528");
oidcSettings.forEach(param -> {

View File

@ -24,7 +24,6 @@ public class XUserKeysServer {
@PostMapping("validate")
public String validate(ServletRequest request) {
// return ApiKeyHandler.getUser(WebUtils.toHttp(request));
return null;
}
@ -47,15 +46,5 @@ public class XUserKeysServer {
ukeyXpackService.switchStatus(id);
}
/*@GetMapping("active/{id}")
public void activeUserKey(@PathVariable Long id) {
UkeyXpackService ukeyXpackService = SpringContextUtil.getBean(UkeyXpackService.class);
ukeyXpackService.activeUserKey(id);
}
@GetMapping("disable/{id}")
public void disabledUserKey(@PathVariable Long id) {
UkeyXpackService ukeyXpackService = SpringContextUtil.getBean(UkeyXpackService.class);
ukeyXpackService.disableUserKey(id);
}*/
}

View File

@ -14,10 +14,6 @@ public abstract class DatasourceProvider {
abstract public List<String> getTables(DatasourceRequest datasourceRequest) throws Exception;
// public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
// return new ArrayList<>();
// };
public void checkStatus(DatasourceRequest datasourceRequest) throws Exception {
getData(datasourceRequest);
}
@ -31,4 +27,6 @@ public abstract class DatasourceProvider {
abstract public void handleDatasource(DatasourceRequest datasourceRequest, String type) throws Exception;
abstract public List<String> getSchema(DatasourceRequest datasourceRequest) throws Exception;
public abstract List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception;
}

View File

@ -12,6 +12,8 @@ import io.dataease.dto.datasource.EsConfiguration;
import io.dataease.dto.datasource.TableFiled;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import io.dataease.provider.ProviderFactory;
import io.dataease.provider.query.QueryProvider;
import io.dataease.provider.query.es.EsQueryProvider;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
@ -94,6 +96,13 @@ public class EsProvider extends DatasourceProvider {
return list;
}
@Override
public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
QueryProvider qp = ProviderFactory.getQueryProvider(datasourceRequest.getDatasource().getType());
datasourceRequest.setQuery(qp.convertTableToSql(datasourceRequest.getTable(), datasourceRequest.getDatasource()));
return fetchResultField(datasourceRequest);
}
private List<String[]> fetchResult(String response) throws Exception {
EsReponse esReponse = new Gson().fromJson(response, EsReponse.class);
return fetchResult(esReponse);
@ -209,17 +218,7 @@ public class EsProvider extends DatasourceProvider {
return new ArrayList<>();
}
// @Override
// public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
// List<TableFiled> tableFileds = new ArrayList<>();
// try {
// String response = exexQuery(datasourceRequest, "desc " + datasourceRequest.getTable(), "?format=json");
// tableFileds = fetchResultField(response);
// } catch (Exception e) {
// DataEaseException.throwException(e);
// }
// return tableFileds;
// }
@Override
public void checkStatus(DatasourceRequest datasourceRequest) throws Exception {

View File

@ -13,6 +13,7 @@ import io.dataease.provider.ProviderFactory;
import io.dataease.provider.query.QueryProvider;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.beans.PropertyVetoException;
import java.io.File;
@ -32,7 +33,7 @@ public class JdbcProvider extends DatasourceProvider {
public static final Pattern WITH_SQL_FRAGMENT = Pattern.compile(REG_WITH_SQL_FRAGMENT);
@PostConstruct
public void init() throws Exception{
public void init() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
extendedJdbcClassLoader = new ExtendedJdbcClassLoader(new URL[]{new File(FILE_PATH).toURI().toURL()}, classLoader);
File file = new File(FILE_PATH);
@ -59,21 +60,21 @@ public class JdbcProvider extends DatasourceProvider {
/**
* 这里使用声明式缓存不是很妥当
* 改为chartViewService中使用编程式缓存
@Cacheable(
value = JdbcConstants.JDBC_PROVIDER_KEY,
key = "'provider_sql_' + #dsr.datasource.id + '_' + #dsr.table + '_' + #dsr.query",
condition = "#dsr.pageSize == null || #dsr.pageSize == 0L"
)
*
* @Cacheable( value = JdbcConstants.JDBC_PROVIDER_KEY,
* key = "'provider_sql_' + #dsr.datasource.id + '_' + #dsr.table + '_' + #dsr.query",
* condition = "#dsr.pageSize == null || #dsr.pageSize == 0L"
* )
*/
@Override
public List<String[]> getData(DatasourceRequest dsr) throws Exception {
List<String[]> list = new LinkedList<>();
try (Connection connection = getConnectionFromPool(dsr); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(dsr.getQuery()) )){
try (Connection connection = getConnectionFromPool(dsr); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(dsr.getQuery()))) {
list = fetchResult(rs);
if(dsr.isPageable() && dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.sqlServer.name())){
Integer realSize = dsr.getPage() * dsr.getPageSize() < list.size() ? dsr.getPage() * dsr.getPageSize(): list.size();
if (dsr.isPageable() && dsr.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.sqlServer.name())) {
Integer realSize = dsr.getPage() * dsr.getPageSize() < list.size() ? dsr.getPage() * dsr.getPageSize() : list.size();
list = list.subList((dsr.getPage() - 1) * dsr.getPageSize(), realSize);
}
@ -86,7 +87,7 @@ public class JdbcProvider extends DatasourceProvider {
}
public void exec(DatasourceRequest datasourceRequest) throws Exception {
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement()){
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement()) {
Boolean result = stat.execute(datasourceRequest.getQuery());
} catch (SQLException e) {
DataEaseException.throwException(e);
@ -97,7 +98,7 @@ public class JdbcProvider extends DatasourceProvider {
@Override
public List<String[]> fetchResult(DatasourceRequest datasourceRequest) throws Exception {
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))){
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))) {
return fetchResult(rs);
} catch (SQLException e) {
DataEaseException.throwException(e);
@ -117,10 +118,13 @@ public class JdbcProvider extends DatasourceProvider {
int columType = metaData.getColumnType(j + 1);
switch (columType) {
case Types.DATE:
if(rs.getDate(j + 1) != null){
if (rs.getDate(j + 1) != null) {
row[j] = rs.getDate(j + 1).toString();
}
break;
case Types.BOOLEAN:
row[j] = rs.getBoolean(j + 1) ? "1" : "0";
break;
default:
row[j] = rs.getString(j + 1);
break;
@ -131,9 +135,101 @@ public class JdbcProvider extends DatasourceProvider {
return list;
}
@Override
public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
List<TableFiled> list = new LinkedList<>();
try (Connection connection = getConnectionFromPool(datasourceRequest)) {
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet resultSet = databaseMetaData.getColumns(null, "%", datasourceRequest.getTable(), "%");
while (resultSet.next()) {
String tableName = resultSet.getString("TABLE_NAME");
String database;
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name())) {
database = resultSet.getString("TABLE_SCHEM");
} else {
database = resultSet.getString("TABLE_CAT");
}
if (database != null) {
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) {
TableFiled tableFiled = getTableFiled(resultSet, datasourceRequest);
list.add(tableFiled);
}
} else {
if (tableName.equals(datasourceRequest.getTable())) {
TableFiled tableFiled = getTableFiled(resultSet, datasourceRequest);
list.add(tableFiled);
}
}
}
resultSet.close();
} catch (SQLException e) {
DataEaseException.throwException(e);
} catch (Exception e) {
DataEaseException.throwException(Translator.get("i18n_datasource_connect_error") + e.getMessage());
}
return list;
}
private TableFiled getTableFiled(ResultSet resultSet, DatasourceRequest datasourceRequest) throws SQLException {
TableFiled tableFiled = new TableFiled();
String colName = resultSet.getString("COLUMN_NAME");
tableFiled.setFieldName(colName);
String remarks = resultSet.getString("REMARKS");
if (remarks == null || remarks.equals("")) {
remarks = colName;
}
tableFiled.setRemarks(remarks);
String dbType = resultSet.getString("TYPE_NAME").toUpperCase();
tableFiled.setFieldType(dbType);
if (dbType.equalsIgnoreCase("LONG")) {
tableFiled.setFieldSize(65533);
}
if (StringUtils.isNotEmpty(dbType) && dbType.toLowerCase().contains("date") && tableFiled.getFieldSize() < 50) {
tableFiled.setFieldSize(50);
}
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name())) {
QueryProvider qp = ProviderFactory.getQueryProvider(datasourceRequest.getDatasource().getType());
tableFiled.setFieldSize(qp.transFieldSize(dbType));
} else {
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.hive.name()) && tableFiled.getFieldType().equalsIgnoreCase("BOOLEAN")) {
tableFiled.setFieldSize(1);
} else {
String size = resultSet.getString("COLUMN_SIZE");
if (size == null) {
tableFiled.setFieldSize(1);
} else {
tableFiled.setFieldSize(Integer.valueOf(size));
}
}
}
return tableFiled;
}
private String getDatabase(DatasourceRequest datasourceRequest) {
DatasourceTypes datasourceType = DatasourceTypes.valueOf(datasourceRequest.getDatasource().getType());
switch (datasourceType) {
case mysql:
case de_doris:
case ds_doris:
case mariadb:
MysqlConfiguration mysqlConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), MysqlConfiguration.class);
return mysqlConfiguration.getDataBase();
case sqlServer:
SqlServerConfiguration sqlServerConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfiguration.class);
return sqlServerConfiguration.getDataBase();
case pg:
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
return pgConfiguration.getDataBase();
default:
JdbcConfiguration jdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class);
return jdbcConfiguration.getDataBase();
}
}
@Override
public List<TableFiled> fetchResultField(DatasourceRequest datasourceRequest) throws Exception {
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))){
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))) {
return fetchResultField(rs, datasourceRequest);
} catch (SQLException e) {
DataEaseException.throwException(e);
@ -146,9 +242,9 @@ public class JdbcProvider extends DatasourceProvider {
@Override
public Map<String, List> fetchResultAndField(DatasourceRequest datasourceRequest) throws Exception {
Map<String, List> result = new HashMap<>();
List<String[]> dataList = new LinkedList<>();
List<TableFiled> fieldList = new ArrayList<>();
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))){
List<String[]> dataList;
List<TableFiled> fieldList;
try (Connection connection = getConnectionFromPool(datasourceRequest); Statement stat = connection.createStatement(); ResultSet rs = stat.executeQuery(rebuildSqlWithFragment(datasourceRequest.getQuery()))) {
dataList = fetchResult(rs);
fieldList = fetchResultField(rs, datasourceRequest);
result.put("dataList", dataList);
@ -170,7 +266,7 @@ public class JdbcProvider extends DatasourceProvider {
String f = metaData.getColumnName(j + 1);
String l = StringUtils.isNotEmpty(metaData.getColumnLabel(j + 1)) ? metaData.getColumnLabel(j + 1) : f;
String t = metaData.getColumnTypeName(j + 1);
if(datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.hive.name())){
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.hive.name())) {
l = l.split("\\.")[1];
}
TableFiled field = new TableFiled();
@ -178,14 +274,16 @@ public class JdbcProvider extends DatasourceProvider {
field.setRemarks(l);
field.setFieldType(t);
if(datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name())){
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name())) {
QueryProvider qp = ProviderFactory.getQueryProvider(datasourceRequest.getDatasource().getType());
field.setFieldSize(qp.transFieldSize(t));
}else {
} else {
field.setFieldSize(metaData.getColumnDisplaySize(j + 1));
}
if(t.equalsIgnoreCase("LONG")){field.setFieldSize(65533);} //oracle LONG
if(StringUtils.isNotEmpty(t) && t.toLowerCase().contains("date") && field.getFieldSize() < 50 ){
if (t.equalsIgnoreCase("LONG")) {
field.setFieldSize(65533);
} //oracle LONG
if (StringUtils.isNotEmpty(t) && t.toLowerCase().contains("date") && field.getFieldSize() < 50) {
field.setFieldSize(50);
}
fieldList.add(field);
@ -197,7 +295,7 @@ public class JdbcProvider extends DatasourceProvider {
public List<String> getTables(DatasourceRequest datasourceRequest) throws Exception {
List<String> tables = new ArrayList<>();
String queryStr = getTablesSql(datasourceRequest);
try (Connection con = getConnectionFromPool(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)){
try (Connection con = getConnectionFromPool(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)) {
while (resultSet.next()) {
tables.add(resultSet.getString(1));
}
@ -206,8 +304,8 @@ public class JdbcProvider extends DatasourceProvider {
}
String queryView = getViewSql(datasourceRequest);
if(queryView != null){
try (Connection con = getConnectionFromPool(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryView)){
if (queryView != null) {
try (Connection con = getConnectionFromPool(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryView)) {
while (resultSet.next()) {
tables.add(resultSet.getString(1));
}
@ -223,7 +321,7 @@ public class JdbcProvider extends DatasourceProvider {
public List<String> getSchema(DatasourceRequest datasourceRequest) throws Exception {
List<String> schemas = new ArrayList<>();
String queryStr = getSchemaSql(datasourceRequest);
try (Connection con = getConnection(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)){
try (Connection con = getConnection(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)) {
while (resultSet.next()) {
schemas.add(resultSet.getString(1));
}
@ -237,7 +335,7 @@ public class JdbcProvider extends DatasourceProvider {
@Override
public void checkStatus(DatasourceRequest datasourceRequest) throws Exception {
String queryStr = getTablesSql(datasourceRequest);
try (Connection con = getConnection(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)){
try (Connection con = getConnection(datasourceRequest); Statement statement = con.createStatement(); ResultSet resultSet = statement.executeQuery(queryStr)) {
} catch (Exception e) {
e.printStackTrace();
@ -248,7 +346,7 @@ public class JdbcProvider extends DatasourceProvider {
@Override
public void handleDatasource(DatasourceRequest datasourceRequest, String type) throws Exception {
DruidDataSource dataSource = null;
switch (type){
switch (type) {
case "add":
checkStatus(datasourceRequest);
dataSource = jdbcConnection.get(datasourceRequest.getDatasource().getId());
@ -316,7 +414,7 @@ public class JdbcProvider extends DatasourceProvider {
password = oracleConfiguration.getPassword();
driver = oracleConfiguration.getDriver();
jdbcurl = oracleConfiguration.getJdbc();
props.put( "oracle.net.CONNECT_TIMEOUT" , "5000") ;
props.put("oracle.net.CONNECT_TIMEOUT", "5000");
break;
case pg:
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
@ -376,7 +474,7 @@ public class JdbcProvider extends DatasourceProvider {
druidDataSource.setInitialSize(jdbcConfiguration.getInitialPoolSize());// 初始连接数
druidDataSource.setMinIdle(jdbcConfiguration.getMinPoolSize()); // 最小连接数
druidDataSource.setMaxActive(jdbcConfiguration.getMaxPoolSize()); // 最大连接数
if(datasourceRequest.getDatasource().getType().equals(DatasourceTypes.mongo.name()) || datasourceRequest.getDatasource().getType().equals(DatasourceTypes.hive.name())){
if (datasourceRequest.getDatasource().getType().equals(DatasourceTypes.mongo.name()) || datasourceRequest.getDatasource().getType().equals(DatasourceTypes.hive.name())) {
WallFilter wallFilter = new WallFilter();
wallFilter.setDbType(DatasourceTypes.mysql.name());
druidDataSource.setProxyFilters(Arrays.asList(new Filter[]{wallFilter}));
@ -467,7 +565,7 @@ public class JdbcProvider extends DatasourceProvider {
return "show tables";
case sqlServer:
SqlServerConfiguration sqlServerConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfiguration.class);
if(StringUtils.isEmpty(sqlServerConfiguration.getSchema())){
if (StringUtils.isEmpty(sqlServerConfiguration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'DS_SCHEMA' ;"
@ -475,13 +573,13 @@ public class JdbcProvider extends DatasourceProvider {
.replace("DS_SCHEMA", sqlServerConfiguration.getSchema());
case oracle:
OracleConfiguration oracleConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), OracleConfiguration.class);
if(StringUtils.isEmpty(oracleConfiguration.getSchema())){
if (StringUtils.isEmpty(oracleConfiguration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "select table_name, owner from all_tables where owner='" + oracleConfiguration.getSchema() + "'";
case pg:
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
if(StringUtils.isEmpty(pgConfiguration.getSchema())){
if (StringUtils.isEmpty(pgConfiguration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT tablename FROM pg_tables WHERE schemaname='SCHEMA' ;".replace("SCHEMA", pgConfiguration.getSchema());
@ -490,7 +588,7 @@ public class JdbcProvider extends DatasourceProvider {
return "SELECT name FROM system.tables where database='DATABASE';".replace("DATABASE", chConfiguration.getDataBase());
case redshift:
RedshiftConfigration redshiftConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), RedshiftConfigration.class);
if(StringUtils.isEmpty(redshiftConfigration.getSchema())){
if (StringUtils.isEmpty(redshiftConfigration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT tablename FROM pg_tables WHERE schemaname='SCHEMA' ;".replace("SCHEMA", redshiftConfigration.getSchema());
@ -510,7 +608,7 @@ public class JdbcProvider extends DatasourceProvider {
return null;
case sqlServer:
SqlServerConfiguration sqlServerConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfiguration.class);
if(StringUtils.isEmpty(sqlServerConfiguration.getSchema())){
if (StringUtils.isEmpty(sqlServerConfiguration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'DS_SCHEMA' ;"
@ -518,19 +616,19 @@ public class JdbcProvider extends DatasourceProvider {
.replace("DS_SCHEMA", sqlServerConfiguration.getSchema());
case oracle:
OracleConfiguration oracleConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), OracleConfiguration.class);
if(StringUtils.isEmpty(oracleConfiguration.getSchema())){
if (StringUtils.isEmpty(oracleConfiguration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "select VIEW_NAME from all_views where owner='" + oracleConfiguration.getSchema() + "'";
case pg:
PgConfiguration pgConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), PgConfiguration.class);
if(StringUtils.isEmpty(pgConfiguration.getSchema())){
if (StringUtils.isEmpty(pgConfiguration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT viewname FROM pg_views WHERE schemaname='SCHEMA' ;".replace("SCHEMA", pgConfiguration.getSchema());
case redshift:
RedshiftConfigration redshiftConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), RedshiftConfigration.class);
if(StringUtils.isEmpty(redshiftConfigration.getSchema())){
if (StringUtils.isEmpty(redshiftConfigration.getSchema())) {
throw new Exception(Translator.get("i18n_schema_is_empty"));
}
return "SELECT viewname FROM pg_views WHERE schemaname='SCHEMA' ;".replace("SCHEMA", redshiftConfigration.getSchema());

Some files were not shown because too many files have changed in this diff Show More