mirror of
https://github.com/dataease/dataease.git
synced 2026-06-17 13:01:44 +08:00
Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
@@ -8,6 +8,8 @@ import io.dataease.auth.entity.TokenInfo;
|
||||
import io.dataease.auth.service.AuthUserService;
|
||||
import io.dataease.auth.util.JWTUtils;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
@@ -54,6 +56,11 @@ public class F2CRealm extends AuthorizingRealm {
|
||||
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
|
||||
try {
|
||||
CacheUtils.get("lic_info", "lic");
|
||||
}catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
String token = (String) auth.getCredentials();
|
||||
// 解密获得username,用于和数据库进行对比
|
||||
TokenInfo tokenInfo = JWTUtils.tokenInfoByToken(token);
|
||||
|
||||
@@ -6,12 +6,9 @@ import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.JWTDecodeException;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import io.dataease.auth.entity.TokenInfo;
|
||||
import io.dataease.auth.filter.JWTFilter;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
<if test="mode != null">
|
||||
and mode = #{mode,jdbcType=INTEGER}
|
||||
</if>
|
||||
<if test="typeFilter != null">
|
||||
and type in
|
||||
<foreach collection="typeFilter" item="item" open="(" separator="," close=")">
|
||||
#{item,jdbcType=INTEGER}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
<if test="sort != null">
|
||||
order by ${sort}
|
||||
|
||||
@@ -25,12 +25,12 @@ public class DataSetTableController {
|
||||
private DataSetTableService dataSetTableService;
|
||||
|
||||
@PostMapping("batchAdd")
|
||||
public void batchAdd(@RequestBody List<DatasetTable> datasetTable) throws Exception {
|
||||
public void batchAdd(@RequestBody List<DataSetTableRequest> datasetTable) throws Exception {
|
||||
dataSetTableService.batchInsert(datasetTable);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
public DatasetTable save(@RequestBody DatasetTable datasetTable) throws Exception {
|
||||
public DatasetTable save(@RequestBody DataSetTableRequest datasetTable) throws Exception {
|
||||
return dataSetTableService.save(datasetTable);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ public class DataSetTableRequest extends DatasetTable {
|
||||
private String sort;
|
||||
private List<String> tableNames;
|
||||
private String row = "1000";
|
||||
|
||||
private String userId;
|
||||
private Integer editType;
|
||||
private Boolean isRename;
|
||||
private List<String> typeFilter;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR:" + e.getMessage(), e);
|
||||
} finally {
|
||||
connection.close();
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -52,7 +54,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR:" + e.getMessage(), e);
|
||||
} finally {
|
||||
connection.close();
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +74,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR:" + e.getMessage(), e);
|
||||
} finally {
|
||||
connection.close();
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +116,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR:" + e.getMessage(), e);
|
||||
} finally {
|
||||
connection.close();
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +143,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR:" + e.getMessage(), e);
|
||||
} finally {
|
||||
connection.close();
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +185,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR: " + e.getMessage(), e);
|
||||
} finally {
|
||||
con.close();
|
||||
if(con != null){
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +226,9 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
} catch (Exception e) {
|
||||
throw new Exception("ERROR:" + e.getMessage(), e);
|
||||
} finally {
|
||||
connection.close();
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ScheduleManager {
|
||||
|
||||
triggerBuilder.withIdentity(triggerKey);
|
||||
|
||||
Date nTimeByCron = getNTimeByCron(cron);
|
||||
Date nTimeByCron = getNTimeByCron(cron, startTime);
|
||||
if (startTime.before(new Date())) {
|
||||
triggerBuilder.startAt(nTimeByCron);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class ScheduleManager {
|
||||
|
||||
triggerBuilder.withIdentity(triggerKey);// 触发器名,触发器组
|
||||
|
||||
Date nTimeByCron = getNTimeByCron(cron);
|
||||
Date nTimeByCron = getNTimeByCron(cron, startTime);
|
||||
if (startTime.before(new Date())) {
|
||||
triggerBuilder.startAt(nTimeByCron);
|
||||
}
|
||||
@@ -410,22 +410,38 @@ public class ScheduleManager {
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public static Date getNTimeByCron(String cron) {
|
||||
try {
|
||||
CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
|
||||
cronTriggerImpl.setCronExpression(cron);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date now = calendar.getTime();
|
||||
// calendar.add(java.util.Calendar.YEAR, 1);
|
||||
calendar.add(Calendar.MONTH, 2);
|
||||
// public static Date getNTimeByCron(String cron) {
|
||||
// try {
|
||||
// CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
|
||||
// cronTriggerImpl.setCronExpression(cron);
|
||||
// Calendar calendar = Calendar.getInstance();
|
||||
// Date now = calendar.getTime();
|
||||
//// calendar.add(java.util.Calendar.YEAR, 1);
|
||||
// calendar.add(Calendar.MONTH, 2);
|
||||
//
|
||||
// List<Date> dates = TriggerUtils.computeFireTimesBetween(cronTriggerImpl, null, now, calendar.getTime());
|
||||
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// String nextTime = dateFormat.format(dates.get(0));
|
||||
// Date date = dateFormat.parse(nextTime);
|
||||
// return date;
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
List<Date> dates = TriggerUtils.computeFireTimesBetween(cronTriggerImpl, null, now, calendar.getTime());
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String nextTime = dateFormat.format(dates.get(0));
|
||||
Date date = dateFormat.parse(nextTime);
|
||||
return date;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
public static CronTrigger getCronTrigger(String cron) {
|
||||
if (!CronExpression.isValidExpression(cron)) {
|
||||
throw new RuntimeException("cron :" + cron + " error");
|
||||
}
|
||||
return TriggerBuilder.newTrigger().withIdentity("Calculate Date").withSchedule(CronScheduleBuilder.cronSchedule(cron)).build();
|
||||
|
||||
}
|
||||
|
||||
public static Date getNTimeByCron(String cron, Date start) {
|
||||
CronTrigger trigger = getCronTrigger(cron);
|
||||
if (start == null) {
|
||||
start = trigger.getStartTime();
|
||||
}
|
||||
return trigger.getFireTimeAfter(start);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.dataease.listener;
|
||||
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
import net.sf.ehcache.CacheException;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.Element;
|
||||
import net.sf.ehcache.event.CacheEventListener;
|
||||
import net.sf.ehcache.event.CacheEventListenerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class LicCacheEventListener extends CacheEventListenerFactory implements CacheEventListener {
|
||||
|
||||
private static CacheEventListener cacheEventListener;
|
||||
|
||||
public LicCacheEventListener() {
|
||||
cacheEventListener = cacheEventListener == null ? this : cacheEventListener;
|
||||
}
|
||||
|
||||
@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");*/
|
||||
}
|
||||
|
||||
/**
|
||||
* lic过期触发: 清除用户、角色、权限缓存
|
||||
* @param ehcache
|
||||
* @param element
|
||||
*/
|
||||
@Override
|
||||
public void notifyElementExpired(Ehcache ehcache, Element element) {
|
||||
// System.out.println("notifyElementExpired");
|
||||
/*String token = ServletUtils.getToken();
|
||||
Long userId = JWTUtils.tokenInfoByToken(token).getUserId();
|
||||
authUserService.clearCache(userId);*/
|
||||
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyElementEvicted(Ehcache ehcache, Element element) {
|
||||
/*System.out.println("notifyElementEvicted");*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyRemoveAll(Ehcache ehcache) {
|
||||
/*System.out.println("notifyRemoveAll");*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheEventListener createCacheEventListener(Properties properties) {
|
||||
return cacheEventListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package io.dataease.listener.util;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.Element;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import java.util.Date;
|
||||
|
||||
@Configuration
|
||||
public class CacheUtils {
|
||||
|
||||
private static CacheManager manager;
|
||||
|
||||
@Autowired
|
||||
public void setManager(CacheManager manager) {
|
||||
CacheUtils.manager = manager;
|
||||
}
|
||||
|
||||
public static Object get(String cacheName, Object key) {
|
||||
Element element = cache(cacheName).get(key);
|
||||
if (null == element) return null;
|
||||
return element.getObjectValue();
|
||||
}
|
||||
|
||||
private static void put(String cacheName, Object key, Object value, Integer ttl, Integer tti) {
|
||||
Element e = new Element(key, value);
|
||||
//不设置则使用xml配置
|
||||
if (ttl != null)
|
||||
e.setEternal(false);
|
||||
e.setTimeToLive(ttl);
|
||||
if (tti != null)
|
||||
e.setTimeToIdle(tti);
|
||||
cache(cacheName).put(e);
|
||||
}
|
||||
|
||||
private static boolean remove(String cacheName, Object key) {
|
||||
return cache(cacheName).remove(key);
|
||||
}
|
||||
|
||||
public static void removeAll(String cacheName) {
|
||||
cache(cacheName).removeAll();
|
||||
}
|
||||
|
||||
private static Cache cache(String cacheName) {
|
||||
net.sf.ehcache.CacheManager cacheManager = ((EhCacheCacheManager) manager).getCacheManager();
|
||||
if (!cacheManager.cacheExists(cacheName))
|
||||
cacheManager.addCache(cacheName);
|
||||
Cache cacheManagerCache = cacheManager.getCache(cacheName);
|
||||
return cacheManagerCache;
|
||||
}
|
||||
|
||||
public static void updateLicCache(Date expDate){
|
||||
long time = expDate.getTime();
|
||||
long exp = (time - System.currentTimeMillis()) / 1000;
|
||||
int intExp = (int)exp;
|
||||
removeAll("lic_info");
|
||||
put("lic_info", "lic", "lic", intExp, intExp);
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,22 @@ package io.dataease.plugins.server;
|
||||
|
||||
|
||||
import io.dataease.auth.api.dto.CurrentUserDto;
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.controller.handler.annotation.I18n;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
import io.dataease.plugins.config.SpringContextUtil;
|
||||
import io.dataease.plugins.xpack.auth.dto.request.XpackBaseTreeRequest;
|
||||
import io.dataease.plugins.xpack.auth.dto.request.XpackSysAuthRequest;
|
||||
import io.dataease.plugins.xpack.auth.dto.response.XpackSysAuthDetail;
|
||||
import io.dataease.plugins.xpack.auth.dto.response.XpackSysAuthDetailDTO;
|
||||
import io.dataease.plugins.xpack.auth.dto.response.XpackVAuthModelDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.dataease.plugins.xpack.auth.service.AuthXpackService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequestMapping("/plugin/auth")
|
||||
@RestController
|
||||
@@ -45,5 +49,13 @@ public class XAuthServer {
|
||||
AuthXpackService sysAuthService = SpringContextUtil.getBean(AuthXpackService.class);
|
||||
CurrentUserDto user = AuthUtils.getUser();
|
||||
sysAuthService.authChange(request, user.getUserId(), user.getUsername(), user.getIsAdmin());
|
||||
// 当权限发生变化 前端实时刷新对应菜单
|
||||
Optional.ofNullable(request.getAuthSourceType()).ifPresent(type -> {
|
||||
if (StringUtils.equals("menu", type)) {
|
||||
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +295,8 @@ public class DorisQueryProvider extends QueryProvider {
|
||||
filter.append(" ")
|
||||
.append(transMysqlFilterTerm(request.getTerm()))
|
||||
.append(" ");
|
||||
if (StringUtils.containsIgnoreCase(request.getTerm(), "in")) {
|
||||
if (StringUtils.containsIgnoreCase(request.getTerm(), "null")) {
|
||||
} else if (StringUtils.containsIgnoreCase(request.getTerm(), "in")) {
|
||||
filter.append("('").append(StringUtils.join(value, "','")).append("')");
|
||||
} else if (StringUtils.containsIgnoreCase(request.getTerm(), "like")) {
|
||||
filter.append("'%").append(value).append("%'");
|
||||
|
||||
@@ -302,7 +302,8 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
filter.append(" ")
|
||||
.append(transMysqlFilterTerm(request.getTerm()))
|
||||
.append(" ");
|
||||
if (StringUtils.containsIgnoreCase(request.getTerm(), "in")) {
|
||||
if (StringUtils.containsIgnoreCase(request.getTerm(), "null")) {
|
||||
} else if (StringUtils.containsIgnoreCase(request.getTerm(), "in")) {
|
||||
filter.append("('").append(StringUtils.join(value, "','")).append("')");
|
||||
} else if (StringUtils.containsIgnoreCase(request.getTerm(), "like")) {
|
||||
filter.append("'%").append(value).append("%'");
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package io.dataease.service;
|
||||
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.commons.license.DefaultLicenseService;
|
||||
import io.dataease.commons.license.F2CLicenseResponse;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@@ -23,6 +25,15 @@ public class AboutService {
|
||||
|
||||
public F2CLicenseResponse updateLicense(String licenseKey) {
|
||||
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.updateLicense(product, licenseKey);
|
||||
Optional.ofNullable(f2CLicenseResponse).ifPresent(resp -> {
|
||||
if (resp.getStatus() == F2CLicenseResponse.Status.valid){
|
||||
CacheUtils.updateLicCache(new Date(f2CLicenseResponse.getLicense().getExpired()));
|
||||
|
||||
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
||||
}
|
||||
});
|
||||
return f2CLicenseResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,13 +84,13 @@ public class DataSetTableService {
|
||||
@Value("${upload.file.path}")
|
||||
private String path;
|
||||
|
||||
public void batchInsert(List<DatasetTable> datasetTable) throws Exception {
|
||||
for (DatasetTable table : datasetTable) {
|
||||
public void batchInsert(List<DataSetTableRequest> datasetTable) throws Exception {
|
||||
for (DataSetTableRequest table : datasetTable) {
|
||||
save(table);
|
||||
}
|
||||
}
|
||||
|
||||
public DatasetTable save(DatasetTable datasetTable) throws Exception {
|
||||
public DatasetTable save(DataSetTableRequest datasetTable) throws Exception {
|
||||
checkName(datasetTable);
|
||||
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql")) {
|
||||
DataSetTableRequest dataSetTableRequest = new DataSetTableRequest();
|
||||
@@ -114,12 +114,25 @@ public class DataSetTableService {
|
||||
}
|
||||
} else {
|
||||
int update = datasetTableMapper.updateByPrimaryKeySelective(datasetTable);
|
||||
// sql 更新
|
||||
if (update == 1) {
|
||||
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql") || StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
||||
// 删除所有字段,重新抽象
|
||||
dataSetTableFieldsService.deleteByTableId(datasetTable.getId());
|
||||
saveTableField(datasetTable);
|
||||
if (datasetTable.getIsRename() == null || !datasetTable.getIsRename()) {
|
||||
// 更新数据和字段
|
||||
if (update == 1) {
|
||||
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql") || StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
||||
// 删除所有字段,重新抽象
|
||||
dataSetTableFieldsService.deleteByTableId(datasetTable.getId());
|
||||
saveTableField(datasetTable);
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "excel")) {
|
||||
if (datasetTable.getEditType() == 0) {
|
||||
commonThreadPool.addTask(() -> {
|
||||
extractDataService.extractData(datasetTable.getId(), null, "all_scope", null);
|
||||
});
|
||||
} else if (datasetTable.getEditType() == 1) {
|
||||
commonThreadPool.addTask(() -> {
|
||||
extractDataService.extractData(datasetTable.getId(), null, "add_scope", null);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,9 +148,12 @@ public class DataSetTableService {
|
||||
// 删除关联关系
|
||||
dataSetTableUnionService.deleteUnionByTableId(id);
|
||||
try {
|
||||
deleteDorisTable(id, table);
|
||||
// 抽取的数据集删除doris
|
||||
if (table.getMode() == 1) {
|
||||
deleteDorisTable(id, table);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +179,7 @@ public class DataSetTableService {
|
||||
|
||||
public List<DataSetTableDTO> list(DataSetTableRequest dataSetTableRequest) {
|
||||
dataSetTableRequest.setUserId(String.valueOf(AuthUtils.getUser().getUserId()));
|
||||
dataSetTableRequest.setTypeFilter(dataSetTableRequest.getTypeFilter());
|
||||
return extDataSetTableMapper.search(dataSetTableRequest);
|
||||
}
|
||||
|
||||
@@ -706,10 +723,17 @@ public class DataSetTableService {
|
||||
} else {
|
||||
rows = sheet0.getPhysicalNumberOfRows();
|
||||
}
|
||||
int columnNum = 0;
|
||||
for (int i = 0; i < rows; i++) {
|
||||
HSSFRow row = sheet0.getRow(i);
|
||||
String[] r = new String[row.getPhysicalNumberOfCells()];
|
||||
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
|
||||
if (i == 0) {
|
||||
if (row == null) {
|
||||
throw new RuntimeException(Translator.get("i18n_excel_header_empty"));
|
||||
}
|
||||
columnNum = row.getPhysicalNumberOfCells();
|
||||
}
|
||||
String[] r = new String[columnNum];
|
||||
for (int j = 0; j < columnNum; j++) {
|
||||
if (i == 0) {
|
||||
TableFiled tableFiled = new TableFiled();
|
||||
tableFiled.setFieldType("TEXT");
|
||||
@@ -722,8 +746,14 @@ public class DataSetTableService {
|
||||
tableFiled.setRemarks(columnName);
|
||||
fields.add(tableFiled);
|
||||
} else if (i == 1) {
|
||||
if (row == null) {
|
||||
break;
|
||||
}
|
||||
r[j] = readCell(row.getCell(j), true, fields.get(j));
|
||||
} else {
|
||||
if (row == null) {
|
||||
break;
|
||||
}
|
||||
r[j] = readCell(row.getCell(j), false, null);
|
||||
}
|
||||
}
|
||||
@@ -746,10 +776,17 @@ public class DataSetTableService {
|
||||
} else {
|
||||
rows = sheet0.getPhysicalNumberOfRows();
|
||||
}
|
||||
int columnNum = 0;
|
||||
for (int i = 0; i < rows; i++) {
|
||||
XSSFRow row = sheet0.getRow(i);
|
||||
String[] r = new String[row.getPhysicalNumberOfCells()];
|
||||
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
|
||||
if (i == 0) {
|
||||
if (row == null) {
|
||||
throw new RuntimeException(Translator.get("i18n_excel_header_empty"));
|
||||
}
|
||||
columnNum = row.getPhysicalNumberOfCells();
|
||||
}
|
||||
String[] r = new String[columnNum];
|
||||
for (int j = 0; j < columnNum; j++) {
|
||||
if (i == 0) {
|
||||
TableFiled tableFiled = new TableFiled();
|
||||
tableFiled.setFieldType("TEXT");
|
||||
@@ -762,8 +799,14 @@ public class DataSetTableService {
|
||||
tableFiled.setRemarks(columnName);
|
||||
fields.add(tableFiled);
|
||||
} else if (i == 1) {
|
||||
if (row == null) {
|
||||
break;
|
||||
}
|
||||
r[j] = readCell(row.getCell(j), true, fields.get(j));
|
||||
} else {
|
||||
if (row == null) {
|
||||
break;
|
||||
}
|
||||
r[j] = readCell(row.getCell(j), false, null);
|
||||
}
|
||||
}
|
||||
@@ -815,6 +858,9 @@ public class DataSetTableService {
|
||||
}
|
||||
|
||||
private String readCell(Cell cell, boolean cellType, TableFiled tableFiled) {
|
||||
if (cell == null) {
|
||||
return "";
|
||||
}
|
||||
CellType cellTypeEnum = cell.getCellTypeEnum();
|
||||
if (cellTypeEnum.equals(CellType.STRING)) {
|
||||
if (cellType) {
|
||||
@@ -915,7 +961,7 @@ public class DataSetTableService {
|
||||
}
|
||||
|
||||
DatasetTable record = new DatasetTable();
|
||||
record.setSyncStatus(JobStatus.Completed.name());
|
||||
record.setSyncStatus(JobStatus.Error.name());
|
||||
example.clear();
|
||||
example.createCriteria().andSyncStatusEqualTo(JobStatus.Underway.name()).andIdIn(jobStoppeddDatasetTables.stream().map(DatasetTable::getId).collect(Collectors.toList()));
|
||||
datasetTableMapper.updateByExampleSelective(record, example);
|
||||
|
||||
@@ -69,6 +69,7 @@ public class DataSetTableTaskLogService {
|
||||
if(StringUtils.isNotEmpty(datasetTableTaskLog.getTaskId())){
|
||||
criteria.andTaskIdEqualTo(datasetTableTaskLog.getTaskId());
|
||||
}
|
||||
example.setOrderByClause("create_time desc");
|
||||
return datasetTableTaskLogMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.dataease.commons.constants.ScheduleType;
|
||||
import io.dataease.controller.request.dataset.DataSetTaskRequest;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.ScheduleService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.quartz.CronExpression;
|
||||
@@ -61,7 +62,16 @@ public class DataSetTableTaskService {
|
||||
datasetTableTask.setCreateTime(System.currentTimeMillis());
|
||||
// SIMPLE 类型,提前占位
|
||||
if (datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
if (extractDataService.updateSyncStatus(dataSetTableService.get(datasetTableTask.getTableId()))) {
|
||||
if(datasetTableTask.getType().equalsIgnoreCase("add_scope")){
|
||||
DatasetTableTaskLog request = new DatasetTableTaskLog();
|
||||
request.setTableId(datasetTableTask.getTableId());
|
||||
request.setStatus(JobStatus.Completed.name());
|
||||
List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.select(request);
|
||||
if (CollectionUtils.isEmpty(datasetTableTaskLogs)) {
|
||||
throw new Exception(Translator.get("i18n_not_exec_add_sync"));
|
||||
}
|
||||
}
|
||||
if (extractDataService.updateSyncStatusIsNone(dataSetTableService.get(datasetTableTask.getTableId()))) {
|
||||
throw new Exception(Translator.get("i18n_sync_job_exists"));
|
||||
}else {
|
||||
//write log
|
||||
|
||||
@@ -27,6 +27,9 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
@@ -34,6 +37,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.pentaho.di.cluster.SlaveServer;
|
||||
import org.pentaho.di.core.database.DatabaseMeta;
|
||||
import org.pentaho.di.core.row.ValueMetaInterface;
|
||||
import org.pentaho.di.core.util.HttpClientManager;
|
||||
import org.pentaho.di.job.Job;
|
||||
import org.pentaho.di.job.JobExecutionConfiguration;
|
||||
import org.pentaho.di.job.JobHopMeta;
|
||||
@@ -66,6 +70,7 @@ import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -124,6 +129,181 @@ public class ExtractDataService {
|
||||
" exit 1\n" +
|
||||
"fi\n" +
|
||||
"rm -rf %s\n";
|
||||
|
||||
public synchronized boolean updateSyncStatusIsNone(DatasetTable datasetTable ){
|
||||
datasetTable.setSyncStatus(JobStatus.Underway.name());
|
||||
DatasetTableExample example = new DatasetTableExample();
|
||||
example.createCriteria().andIdEqualTo(datasetTable.getId());
|
||||
datasetTableMapper.selectByExample(example);
|
||||
example.clear();
|
||||
example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusNotEqualTo(JobStatus.Underway.name());
|
||||
example.or(example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusIsNull());
|
||||
return datasetTableMapper.updateByExampleSelective(datasetTable, example) == 0;
|
||||
}
|
||||
|
||||
public void extractData(String datasetTableId, String taskId, String type, JobExecutionContext context) {
|
||||
DatasetTable datasetTable = getDatasetTable(datasetTableId);
|
||||
if(datasetTable == null){
|
||||
LogUtil.error("Can not find DatasetTable: " + datasetTableId);
|
||||
}
|
||||
DatasetTableTask datasetTableTask = datasetTableTaskMapper.selectByPrimaryKey(taskId);
|
||||
boolean isCronJob = (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.CRON.toString()));
|
||||
if(updateSyncStatusIsNone(datasetTable) && isCronJob){
|
||||
LogUtil.info("Skip synchronization task for table : " + datasetTableId);
|
||||
return;
|
||||
}
|
||||
DatasetTableTaskLog datasetTableTaskLog = new DatasetTableTaskLog();
|
||||
UpdateType updateType = UpdateType.valueOf(type);
|
||||
Datasource datasource = new Datasource();
|
||||
if(context != null){
|
||||
datasetTable.setQrtzInstance(context.getFireInstanceId());
|
||||
datasetTableMapper.updateByPrimaryKeySelective(datasetTable);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(datasetTable.getDataSourceId())) {
|
||||
datasource = datasourceMapper.selectByPrimaryKey(datasetTable.getDataSourceId());
|
||||
} else {
|
||||
datasource.setType(datasetTable.getType());
|
||||
}
|
||||
|
||||
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.list(DatasetTableField.builder().tableId(datasetTable.getId()).build());
|
||||
datasetTableFields.sort((o1, o2) -> {
|
||||
if (o1.getColumnIndex() == null) {
|
||||
return -1;
|
||||
}
|
||||
if (o2.getColumnIndex() == null) {
|
||||
return 1;
|
||||
}
|
||||
return o1.getColumnIndex().compareTo(o2.getColumnIndex());
|
||||
});
|
||||
String dorisTablColumnSql = createDorisTablColumnSql(datasetTableFields);
|
||||
|
||||
switch (updateType) {
|
||||
case all_scope: // 全量更新
|
||||
try{
|
||||
if(datasource.getType().equalsIgnoreCase("excel")){
|
||||
datasetTableTaskLog = writeDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, null);
|
||||
}
|
||||
if(datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.CRON.toString())) {
|
||||
datasetTableTaskLog = writeDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, taskId);
|
||||
}
|
||||
if(datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
datasetTableTaskLog = getDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, taskId);
|
||||
}
|
||||
createDorisTable(DorisTableUtils.dorisName(datasetTableId), dorisTablColumnSql);
|
||||
createDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId)), dorisTablColumnSql);
|
||||
generateTransFile("all_scope", datasetTable, datasource, datasetTableFields, null);
|
||||
generateJobFile("all_scope", datasetTable, String.join(",", datasetTableFields.stream().map(DatasetTableField::getDataeaseName).collect(Collectors.toList())));
|
||||
extractData(datasetTable, "all_scope");
|
||||
replaceTable(DorisTableUtils.dorisName(datasetTableId));
|
||||
saveSucessLog(datasetTableTaskLog);
|
||||
updateTableStatus(datasetTableId, datasetTable, JobStatus.Completed);
|
||||
}catch (Exception e){
|
||||
saveErrorLog(datasetTableId, taskId, e);
|
||||
updateTableStatus(datasetTableId, datasetTable, JobStatus.Error);
|
||||
dropDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId)));
|
||||
}finally {
|
||||
if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString());
|
||||
dataSetTableTaskService.update(datasetTableTask);
|
||||
}
|
||||
deleteFile("all_scope", datasetTableId);
|
||||
}
|
||||
break;
|
||||
|
||||
case add_scope: // 增量更新
|
||||
try {
|
||||
if(datasource.getType().equalsIgnoreCase("excel")){
|
||||
datasetTableTaskLog = writeDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, null);
|
||||
generateTransFile("incremental_add", datasetTable, datasource, datasetTableFields, null);
|
||||
generateJobFile("incremental_add", datasetTable, String.join(",", datasetTableFields.stream().map(DatasetTableField::getDataeaseName).collect(Collectors.toList())));
|
||||
extractData(datasetTable, "incremental_add");
|
||||
saveSucessLog(datasetTableTaskLog);
|
||||
updateTableStatus(datasetTableId, datasetTable, JobStatus.Completed);
|
||||
}else {
|
||||
DatasetTableIncrementalConfig datasetTableIncrementalConfig = dataSetTableService.incrementalConfig(datasetTableId);
|
||||
if (datasetTableIncrementalConfig == null || StringUtils.isEmpty(datasetTableIncrementalConfig.getTableId())) {
|
||||
return;
|
||||
}
|
||||
DatasetTableTaskLog request = new DatasetTableTaskLog();
|
||||
request.setTableId(datasetTableId);
|
||||
request.setStatus(JobStatus.Completed.name());
|
||||
List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.select(request);
|
||||
if (CollectionUtils.isEmpty(datasetTableTaskLogs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.CRON.toString())) {
|
||||
datasetTableTaskLog = writeDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, taskId);
|
||||
}
|
||||
if(datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
datasetTableTaskLog = getDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, taskId);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalAdd().replace(" ", ""))) {// 增量添加
|
||||
String sql = datasetTableIncrementalConfig.getIncrementalAdd().replace(lastUpdateTime, datasetTableTaskLogs.get(0).getStartTime().toString())
|
||||
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
|
||||
generateTransFile("incremental_add", datasetTable, datasource, datasetTableFields, sql);
|
||||
generateJobFile("incremental_add", datasetTable, fetchSqlField(sql, datasource));
|
||||
extractData(datasetTable, "incremental_add");
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalDelete().replace(" ", ""))) {// 增量删除
|
||||
String sql = datasetTableIncrementalConfig.getIncrementalDelete().replace(lastUpdateTime, datasetTableTaskLogs.get(0).getStartTime().toString())
|
||||
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
|
||||
generateTransFile("incremental_delete", datasetTable, datasource, datasetTableFields, sql);
|
||||
generateJobFile("incremental_delete", datasetTable, fetchSqlField(sql, datasource));
|
||||
extractData(datasetTable, "incremental_delete");
|
||||
}
|
||||
saveSucessLog(datasetTableTaskLog);
|
||||
updateTableStatus(datasetTableId, datasetTable, JobStatus.Completed);
|
||||
}
|
||||
}catch (Exception e){
|
||||
saveErrorLog(datasetTableId, taskId, e);
|
||||
updateTableStatus(datasetTableId, datasetTable, JobStatus.Error);
|
||||
}finally {
|
||||
if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString());
|
||||
dataSetTableTaskService.update(datasetTableTask);
|
||||
}
|
||||
deleteFile("incremental_add", datasetTableId);
|
||||
deleteFile("incremental_delete", datasetTableId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTableStatus(String datasetTableId, DatasetTable datasetTable, JobStatus completed) {
|
||||
datasetTable.setSyncStatus(completed.name());
|
||||
DatasetTableExample example = new DatasetTableExample();
|
||||
example.createCriteria().andIdEqualTo(datasetTableId);
|
||||
datasetTableMapper.updateByExampleSelective(datasetTable, example);
|
||||
}
|
||||
|
||||
private void saveSucessLog(DatasetTableTaskLog datasetTableTaskLog) {
|
||||
datasetTableTaskLog.setStatus(JobStatus.Completed.name());
|
||||
datasetTableTaskLog.setEndTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
}
|
||||
|
||||
private void saveErrorLog(String datasetTableId, String taskId, Exception e){
|
||||
LogUtil.error("Extract data error: " + datasetTableId, e);
|
||||
DatasetTableTaskLog datasetTableTaskLog = new DatasetTableTaskLog();
|
||||
datasetTableTaskLog.setTableId(datasetTableId);
|
||||
datasetTableTaskLog.setStatus(JobStatus.Underway.name());
|
||||
if(StringUtils.isNotEmpty(taskId)){
|
||||
datasetTableTaskLog.setTaskId(taskId);
|
||||
}
|
||||
List<DatasetTableTaskLog> datasetTableTaskLogs = dataSetTableTaskLogService.select(datasetTableTaskLog);
|
||||
if(CollectionUtils.isNotEmpty(datasetTableTaskLogs)){
|
||||
datasetTableTaskLog = datasetTableTaskLogs.get(0);
|
||||
datasetTableTaskLog.setStatus(JobStatus.Error.name());
|
||||
datasetTableTaskLog.setInfo(ExceptionUtils.getStackTrace(e));
|
||||
datasetTableTaskLog.setEndTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String createDorisTablColumnSql(List<DatasetTableField> datasetTableFields) {
|
||||
String Column_Fields = "dataease_uuid varchar(50), `";
|
||||
for (DatasetTableField datasetTableField : datasetTableFields) {
|
||||
@@ -189,133 +369,6 @@ public class ExtractDataService {
|
||||
jdbcProvider.exec(datasourceRequest);
|
||||
}
|
||||
|
||||
public synchronized boolean updateSyncStatus(DatasetTable datasetTable ){
|
||||
datasetTable.setSyncStatus(JobStatus.Underway.name());
|
||||
DatasetTableExample example = new DatasetTableExample();
|
||||
example.createCriteria().andIdEqualTo(datasetTable.getId());
|
||||
datasetTableMapper.selectByExample(example);
|
||||
example.clear();
|
||||
example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusNotEqualTo(JobStatus.Underway.name());
|
||||
example.or(example.createCriteria().andIdEqualTo(datasetTable.getId()).andSyncStatusIsNull());
|
||||
return datasetTableMapper.updateByExampleSelective(datasetTable, example) == 0;
|
||||
}
|
||||
|
||||
public void extractData(String datasetTableId, String taskId, String type, JobExecutionContext context) {
|
||||
DatasetTable datasetTable = getDatasetTable(datasetTableId);
|
||||
if(datasetTable == null){
|
||||
LogUtil.error("Can not find DatasetTable: " + datasetTableId);
|
||||
}
|
||||
DatasetTableTask datasetTableTask = datasetTableTaskMapper.selectByPrimaryKey(taskId);
|
||||
boolean isCronJob = (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.CRON.toString()));
|
||||
if(updateSyncStatus(datasetTable) && isCronJob){
|
||||
LogUtil.info("Skip synchronization task for table : " + datasetTableId);
|
||||
return;
|
||||
}
|
||||
DatasetTableTaskLog datasetTableTaskLog = new DatasetTableTaskLog();
|
||||
UpdateType updateType = UpdateType.valueOf(type);
|
||||
Datasource datasource = new Datasource();
|
||||
try {
|
||||
if(context != null){
|
||||
datasetTable.setQrtzInstance(context.getFireInstanceId());
|
||||
datasetTableMapper.updateByPrimaryKeySelective(datasetTable);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(datasetTable.getDataSourceId())) {
|
||||
datasource = datasourceMapper.selectByPrimaryKey(datasetTable.getDataSourceId());
|
||||
} else {
|
||||
datasource.setType(datasetTable.getType());
|
||||
}
|
||||
|
||||
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.list(DatasetTableField.builder().tableId(datasetTable.getId()).build());
|
||||
datasetTableFields.sort((o1, o2) -> {
|
||||
if (o1.getColumnIndex() == null) {
|
||||
return -1;
|
||||
}
|
||||
if (o2.getColumnIndex() == null) {
|
||||
return 1;
|
||||
}
|
||||
return o1.getColumnIndex().compareTo(o2.getColumnIndex());
|
||||
});
|
||||
String dorisTablColumnSql = createDorisTablColumnSql(datasetTableFields);
|
||||
switch (updateType) {
|
||||
// 全量更新
|
||||
case all_scope:
|
||||
datasetTableTaskLog = getDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, taskId);
|
||||
createDorisTable(DorisTableUtils.dorisName(datasetTableId), dorisTablColumnSql);
|
||||
createDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId)), dorisTablColumnSql);
|
||||
generateTransFile("all_scope", datasetTable, datasource, datasetTableFields, null);
|
||||
generateJobFile("all_scope", datasetTable, String.join(",", datasetTableFields.stream().map(DatasetTableField::getDataeaseName).collect(Collectors.toList())));
|
||||
extractData(datasetTable, "all_scope");
|
||||
replaceTable(DorisTableUtils.dorisName(datasetTableId));
|
||||
datasetTableTaskLog.setStatus(JobStatus.Completed.name());
|
||||
datasetTableTaskLog.setEndTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
break;
|
||||
|
||||
// 增量更新
|
||||
case add_scope:
|
||||
DatasetTableIncrementalConfig datasetTableIncrementalConfig = dataSetTableService.incrementalConfig(datasetTableId);
|
||||
if (datasetTableIncrementalConfig == null || StringUtils.isEmpty(datasetTableIncrementalConfig.getTableId())) {
|
||||
return;
|
||||
}
|
||||
DatasetTableTaskLog request = new DatasetTableTaskLog();
|
||||
request.setTableId(datasetTableId);
|
||||
request.setStatus(JobStatus.Completed.name());
|
||||
List<DataSetTaskLogDTO> dataSetTaskLogDTOS = dataSetTableTaskLogService.list(request);
|
||||
if (CollectionUtils.isEmpty(dataSetTaskLogDTOS)) {
|
||||
return;
|
||||
}
|
||||
datasetTableTaskLog = writeDatasetTableTaskLog(datasetTableTaskLog, datasetTableId, taskId);
|
||||
|
||||
// 增量添加
|
||||
if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalAdd().replace(" ", ""))) {
|
||||
String sql = datasetTableIncrementalConfig.getIncrementalAdd().replace(lastUpdateTime, dataSetTaskLogDTOS.get(0).getStartTime().toString()
|
||||
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()));
|
||||
generateTransFile("incremental_add", datasetTable, datasource, datasetTableFields, sql);
|
||||
generateJobFile("incremental_add", datasetTable, fetchSqlField(sql, datasource));
|
||||
extractData(datasetTable, "incremental_add");
|
||||
}
|
||||
|
||||
// 增量删除
|
||||
if (StringUtils.isNotEmpty(datasetTableIncrementalConfig.getIncrementalDelete())) {
|
||||
String sql = datasetTableIncrementalConfig.getIncrementalDelete().replace(lastUpdateTime, dataSetTaskLogDTOS.get(0).getStartTime().toString()
|
||||
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString()));
|
||||
generateTransFile("incremental_delete", datasetTable, datasource, datasetTableFields, sql);
|
||||
generateJobFile("incremental_delete", datasetTable, fetchSqlField(sql, datasource));
|
||||
extractData(datasetTable, "incremental_delete");
|
||||
}
|
||||
datasetTableTaskLog.setStatus(JobStatus.Completed.name());
|
||||
datasetTableTaskLog.setEndTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
break;
|
||||
}
|
||||
datasetTable.setSyncStatus(JobStatus.Completed.name());
|
||||
DatasetTableExample example = new DatasetTableExample();
|
||||
example.createCriteria().andIdEqualTo(datasetTableId);
|
||||
datasetTableMapper.updateByExampleSelective(datasetTable, example);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.error("Extract data error: " + datasetTableId, e);
|
||||
datasetTableTaskLog.setStatus(JobStatus.Error.name());
|
||||
datasetTableTaskLog.setInfo(ExceptionUtils.getStackTrace(e));
|
||||
datasetTableTaskLog.setEndTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
|
||||
datasetTable.setSyncStatus(JobStatus.Error.name());
|
||||
DatasetTableExample example = new DatasetTableExample();
|
||||
example.createCriteria().andIdEqualTo(datasetTableId);
|
||||
datasetTableMapper.updateByExampleSelective(datasetTable, example);
|
||||
|
||||
if(updateType.name().equalsIgnoreCase("all_scope")){
|
||||
dropDorisTable(DorisTableUtils.dorisTmpName(DorisTableUtils.dorisName(datasetTableId)));
|
||||
}
|
||||
} finally {
|
||||
if (datasetTableTask != null && datasetTableTask.getRate().equalsIgnoreCase(ScheduleType.SIMPLE.toString())) {
|
||||
datasetTableTask.setRate(ScheduleType.SIMPLE_COMPLETE.toString());
|
||||
dataSetTableTaskService.update(datasetTableTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DatasetTable getDatasetTable(String datasetTableId){
|
||||
for (int i=0;i<5;i++){
|
||||
DatasetTable datasetTable = dataSetTableService.get(datasetTableId);
|
||||
@@ -353,6 +406,9 @@ public class ExtractDataService {
|
||||
if(CollectionUtils.isNotEmpty(datasetTableTaskLogs)){
|
||||
return datasetTableTaskLogs.get(0);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}catch (Exception ignore){}
|
||||
}
|
||||
datasetTableTaskLog.setStartTime(System.currentTimeMillis());
|
||||
dataSetTableTaskLogService.save(datasetTableTaskLog);
|
||||
@@ -360,8 +416,6 @@ public class ExtractDataService {
|
||||
}
|
||||
|
||||
private void extractData(DatasetTable datasetTable, String extractType) throws Exception {
|
||||
|
||||
|
||||
KettleFileRepository repository = CommonBeanFactory.getBean(KettleFileRepository.class);
|
||||
RepositoryDirectoryInterface repositoryDirectoryInterface = repository.loadRepositoryDirectoryTree();
|
||||
JobMeta jobMeta = null;
|
||||
@@ -643,7 +697,7 @@ public class ExtractDataService {
|
||||
ExcelInputField field = new ExcelInputField();
|
||||
field.setName(datasetTableFields.get(i).getOriginName());
|
||||
if(datasetTableFields.get(i).getDeExtractType() == 1){
|
||||
field.setType("Date");
|
||||
field.setType("String");
|
||||
field.setFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}else {
|
||||
field.setType("String");
|
||||
@@ -692,6 +746,7 @@ public class ExtractDataService {
|
||||
tmp_code = tmp_code.replace("handleExcelWraps", handleExcelWraps);
|
||||
}else {
|
||||
tmp_code = tmp_code.replace("handleExcelIntColumn", "");
|
||||
tmp_code = tmp_code.replace("handleExcelWraps", "");
|
||||
}
|
||||
UserDefinedJavaClassDef userDefinedJavaClassDef = new UserDefinedJavaClassDef(UserDefinedJavaClassDef.ClassType.TRANSFORM_CLASS, "Processor", tmp_code);
|
||||
|
||||
@@ -705,28 +760,57 @@ public class ExtractDataService {
|
||||
return userDefinedJavaClassStep;
|
||||
}
|
||||
|
||||
private void deleteFile(String type, String dataSetTableId){
|
||||
String transName = null;
|
||||
String jobName = null;
|
||||
|
||||
switch (type) {
|
||||
case "all_scope":
|
||||
transName = "trans_" + dataSetTableId;
|
||||
jobName = "job_" + dataSetTableId;
|
||||
break;
|
||||
case "incremental_add":
|
||||
transName = "trans_add_" + dataSetTableId;
|
||||
jobName = "job_add_" + dataSetTableId;
|
||||
break;
|
||||
case "incremental_delete":
|
||||
transName = "trans_delete_" + dataSetTableId;
|
||||
jobName = "job_delete_" + dataSetTableId;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
try{
|
||||
File file = new File(root_path + jobName + ".kjb");
|
||||
FileUtils.forceDelete(file);
|
||||
}catch (Exception e){}
|
||||
try{
|
||||
File file = new File(root_path + transName + ".ktr");
|
||||
FileUtils.forceDelete(file);
|
||||
}catch (Exception e){}
|
||||
}
|
||||
|
||||
public boolean isKettleRunning() {
|
||||
return true;
|
||||
// try {
|
||||
// if (!InetAddress.getByName(carte).isReachable(1000)) {
|
||||
// return false;
|
||||
// }
|
||||
// HttpClient httpClient;
|
||||
// HttpGet getMethod = new HttpGet("http://" + carte + ":" + port);
|
||||
// HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder();
|
||||
// clientBuilder.setConnectionTimeout(1);
|
||||
// clientBuilder.setCredentials(user, passwd);
|
||||
// httpClient = clientBuilder.build();
|
||||
// HttpResponse httpResponse = httpClient.execute(getMethod);
|
||||
// int statusCode = httpResponse.getStatusLine().getStatusCode();
|
||||
// if (statusCode != -1 && statusCode < 400) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// return false;
|
||||
// }
|
||||
try {
|
||||
if (!InetAddress.getByName(carte).isReachable(1000)) {
|
||||
return false;
|
||||
}
|
||||
HttpClient httpClient;
|
||||
HttpGet getMethod = new HttpGet("http://" + carte + ":" + port);
|
||||
HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder();
|
||||
clientBuilder.setConnectionTimeout(1);
|
||||
clientBuilder.setCredentials(user, passwd);
|
||||
httpClient = clientBuilder.build();
|
||||
HttpResponse httpResponse = httpClient.execute(getMethod);
|
||||
int statusCode = httpResponse.getStatusLine().getStatusCode();
|
||||
if (statusCode != -1 && statusCode < 400) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String alterColumnTypeCode = " if(\"FILED\".equalsIgnoreCase(filed)){\n" +
|
||||
|
||||
@@ -5,9 +5,11 @@ import io.dataease.base.domain.MyPlugin;
|
||||
import io.dataease.base.mapper.MyPluginMapper;
|
||||
import io.dataease.base.mapper.ext.ExtSysPluginMapper;
|
||||
import io.dataease.base.mapper.ext.query.GridExample;
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.commons.utils.DeFileUtils;
|
||||
import io.dataease.commons.utils.ZipUtils;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
import io.dataease.plugins.config.LoadjarUtil;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -89,6 +91,10 @@ public class PluginService {
|
||||
jarPath = DeFileUtils.copy(jarFile, targetDir);
|
||||
loadJar(jarPath, myPlugin);
|
||||
myPluginMapper.insert(myPlugin);
|
||||
|
||||
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
||||
} catch (Exception e) {
|
||||
if (StringUtils.isNotEmpty(targetDir)) {
|
||||
DeFileUtils.deleteFile(targetDir);
|
||||
@@ -137,6 +143,9 @@ public class PluginService {
|
||||
* @return
|
||||
*/
|
||||
public Boolean uninstall(Long pluginId) {
|
||||
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
||||
myPluginMapper.deleteByPrimaryKey(pluginId);
|
||||
return true;
|
||||
}
|
||||
@@ -148,6 +157,9 @@ public class PluginService {
|
||||
* @return
|
||||
*/
|
||||
public Boolean changeStatus(Long pluginId, Boolean status) {
|
||||
CacheUtils.removeAll(AuthConstants.USER_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_ROLE_CACHE_NAME);
|
||||
CacheUtils.removeAll(AuthConstants.USER_PERMISSION_CACHE_NAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user