|
|
@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -210,6 +211,39 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
return success();
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设备运行记录数据库备份(每年)
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public AjaxResult equipmentBKTask() {
|
|
|
|
|
|
|
|
// 加载sf-cloud库的sys_datasource
|
|
|
|
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
|
|
|
|
|
sysUser.setUserId(1L);
|
|
|
|
|
|
|
|
R<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
|
|
|
|
|
|
|
|
List<Map<String, String>> dateSources = dateSources0.getData();
|
|
|
|
|
|
|
|
ExecutorService executorService = new ThreadPoolExecutor(
|
|
|
|
|
|
|
|
dateSources.size(),
|
|
|
|
|
|
|
|
dateSources.size(),
|
|
|
|
|
|
|
|
0L, TimeUnit.MILLISECONDS,
|
|
|
|
|
|
|
|
new LinkedBlockingQueue<Runnable>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
dateSources.forEach(dateSource -> {
|
|
|
|
|
|
|
|
logger.info("++++++++++++" + dateSource.get("poolName") + "++++设备运行记录数据库备份开始++++++++++");
|
|
|
|
|
|
|
|
Runnable run = () -> backupEquipmentOperation(dateSource.get("poolName"));
|
|
|
|
|
|
|
|
executorService.execute(run);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
logger.error("service == dataClearTask == exception", e);
|
|
|
|
|
|
|
|
return error("service == dataClearTask == exception");
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
executorService.shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createSpotCheckPlanFunc(String poolName){
|
|
|
|
public void createSpotCheckPlanFunc(String poolName){
|
|
|
|
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
|
|
|
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
|
|
|
/**equ_plan equ_plan_equ**/
|
|
|
|
/**equ_plan equ_plan_equ**/
|
|
|
@ -431,7 +465,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
operation.setCreateTime(DateUtils.getNowDate());
|
|
|
|
operation.setCreateTime(DateUtils.getNowDate());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int batchSize = 200;// 批次数量
|
|
|
|
int batchSize = 100;// 批次数量
|
|
|
|
|
|
|
|
|
|
|
|
// 分批次处理
|
|
|
|
// 分批次处理
|
|
|
|
int batchCount = (operationList.size() + batchSize - 1)/batchSize;// 计算批次数量
|
|
|
|
int batchCount = (operationList.size() + batchSize - 1)/batchSize;// 计算批次数量
|
|
|
@ -450,6 +484,40 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void backupEquipmentOperation(String poolName) {
|
|
|
|
|
|
|
|
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
|
|
|
|
|
|
|
// 校验当前YEAR-2是否备份过数据
|
|
|
|
|
|
|
|
EquOperation check = equOperationMapper.checkBackupOperation();
|
|
|
|
|
|
|
|
if (check == null) {
|
|
|
|
|
|
|
|
// 获取插入数量
|
|
|
|
|
|
|
|
int insertNum = equOperationMapper.getBackupOperationNum();
|
|
|
|
|
|
|
|
int insertSize = 100;// 新增批次数量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 分批次备份
|
|
|
|
|
|
|
|
int batchCount = (insertNum + insertSize - 1)/insertSize;// 计算批次数量
|
|
|
|
|
|
|
|
for (int i = 0;i < batchCount; i++) {
|
|
|
|
|
|
|
|
int startIndex = i * insertSize;// 索引开始值
|
|
|
|
|
|
|
|
int endIndex = Math.min((i + 1)*insertSize,insertNum);// 索引结束值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 备份至数据库
|
|
|
|
|
|
|
|
int num = equOperationMapper.backupOperation(startIndex,insertSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("数据源:"+poolName+"--->"+"第"+(i+1)+"轮备份"+"开始索引:"+startIndex+"________结束索引:"+endIndex+"________成功插入数量:"+num);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除源数据库数据
|
|
|
|
|
|
|
|
int delSize = 100;// 删除批次数量
|
|
|
|
|
|
|
|
for (int i = 0; i < insertNum/delSize+1; i++) {
|
|
|
|
|
|
|
|
// 在源数据库中删除
|
|
|
|
|
|
|
|
int num = equOperationMapper.deleteOperation(delSize);
|
|
|
|
|
|
|
|
System.out.println("数据源:"+poolName+"--->"+"第"+(i+1)+"轮删除"+"------>成功删除数量:"+num);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
System.out.println("数据源:"+poolName+"---->"+"年份:"+( LocalDate.now().getYear()-2) +"--->已备份");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
|
|
int batchSize = 200;// 批次数量
|
|
|
|
int batchSize = 200;// 批次数量
|
|
|
|