备份定时任务

highway
zhaoxiaolin 1 year ago
parent 05546bb4dd
commit 8e8ac0e125

@ -114,7 +114,7 @@ public class RyTask {
}
/**每月1日执行110一次**/
public void dataBKTask(){
logger.info("++数据库备份的数据+开始++dataClearTask+++++");
logger.info("++数据库备份的数据+开始++dataBKTask+++++");
remoteMesService.dataBKTask();
}
}

@ -113,6 +113,13 @@ public class WCSInterfaceController extends BaseController {
tables.add("mes_interface_log");
return success(wCInterfaceService.dataClearTask(tables));
}
//定期备份清理表
@PostMapping("/dataBKTask")
public AjaxResult dataBKTask() {
List<String> tables = new ArrayList<>();
tables.add("mes_material_transfer_result");
return success(wCInterfaceService.dataBKTask(tables));
}
public static void main(String args[]){
System.out.println(DateUtils.getDate());

@ -40,4 +40,12 @@ public interface MesMapper {
List<BoardDTO> getEveryNumL(BoardDTO boardDTO);
void deleteDateByTableName(@Param("table")String table,@Param("ymdhms")String ymdhms);
int createNewTable(@Param("tableNew")String tableNew);
void copyBkDateByTable(@Param("table")String addMonthTable,@Param("startDate") String startDate, @Param("endDate")String endDate);
void deleteBkDateByTable(@Param("startDate") String startDate, @Param("endDate")String endDate);
void deleteBkDate(@Param("table")String addMonthTable,@Param("startDate") String startDate, @Param("endDate")String endDate);
}

@ -31,4 +31,6 @@ public interface IWCSInterfaceService {
List<MesShift> getProShifts(BoardDTO boardDTO);
R dataClearTask(List<String> tables);
R dataBKTask(List<String> tables);
}

@ -210,8 +210,8 @@ public class IWCInterfaceServiceImpl implements IWCSInterfaceService {
executorService.execute(run);
});
} catch (Exception e) {
logger.error("service == deviceOfflineTimingTask == exception", e);
return R.fail("service == deviceOfflineTimingTask == exception");
logger.error("service == dataClearTask == exception", e);
return R.fail("service == dataClearTask == exception");
} finally {
executorService.shutdown();
}
@ -230,6 +230,84 @@ public class IWCInterfaceServiceImpl implements IWCSInterfaceService {
}
}
@Override
public R dataBKTask(List<String> tables) {
// 加载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 -> {
if("ds_1000".equals(dateSource.get("poolName"))){//只有999白坯工厂有这种情况
logger.info("++++++++++++" + dateSource.get("poolName") + "++++开始++++++++++");
Runnable run = () -> dateBKFunc(dateSource.get("poolName"),tables);
executorService.execute(run);
}
});
} catch (Exception e) {
logger.error("service == dataBKTask == exception", e);
return R.fail("service == dataBKTask == exception");
} finally {
executorService.shutdown();
}
return R.ok(true);
}
public void dateBKFunc(String poolName,List<String> tables){
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
DateTimeFormatter ymdhms = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate today = LocalDate.now();
LocalDate lastMonth3 = today.plus(-3, ChronoUnit.MONTHS);
String ymdhms3 = lastMonth3.format(ymdhms)+" 00:00:00";
LocalDate lastMonth2 = today.plus(-2, ChronoUnit.MONTHS);
String ymdhms2 = lastMonth2.format(ymdhms)+" 00:00:00";
for(String table:tables){
//如果月份是 14710则创建季度表
int monthFlag = lastMonth3.getMonthValue();
int yearFlag = lastMonth3.getYear();
String tablePre = table+"_" + yearFlag;
String newTable = "";
if(monthFlag == 1){
newTable = tablePre +"_01_02_03";
}else if(monthFlag == 4){
newTable = tablePre +"_04_05_06";
}else if(monthFlag == 7){
newTable = tablePre +"_07_08_09";
}else if(monthFlag == 10){
newTable = tablePre +"_10_11_12";
}
if(!"".equals(newTable)){
int m = mesMapper.createNewTable(newTable);
}
String addMonthTable = "";
if(monthFlag>=1 && monthFlag<4){
addMonthTable = tablePre + "_01_02_03";
}else if(monthFlag>=4 && monthFlag<7){
addMonthTable = tablePre + "_04_05_06";
}else if(monthFlag>=7 && monthFlag<10){
addMonthTable = tablePre + "_07_08_09";
}else if(monthFlag>=10 && monthFlag<=12){
addMonthTable = tablePre + "_10_11_12";
}
//先删除备份表数据该月数据
//mesMapper.deleteBkDate(addMonthTable,ymdhms3,ymdhms2);
//先备份1个月的数据
mesMapper.copyBkDateByTable(addMonthTable,ymdhms3,ymdhms2);
//删掉历史1个月的数据
mesMapper.deleteBkDateByTable(ymdhms3,ymdhms2);
}
}
@Override
public String saveLGusedLog(List<LGInfoDto> lgdtos) {
DynamicDataSourceContextHolder.push("ds_"+lgdtos.get(0).getFactoryCode());// 这是数据源的key
@ -247,9 +325,8 @@ public class IWCInterfaceServiceImpl implements IWCSInterfaceService {
public static void main(String args[]){
DateTimeFormatter ymdhms = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate today = LocalDate.now();
System.out.println("今天的日期为:"+today);
LocalDate nextWeek = today.plus(-3, ChronoUnit.DAYS);
String ymdhms7 = nextWeek.format(ymdhms);
System.out.println("7天之前的日期为:"+ymdhms7);
LocalDate lastMonth3 = today.plus(-3, ChronoUnit.MONTHS);
System.out.println("7天之前的日期为:"+lastMonth3.getYear());
}
}

@ -55,6 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</foreach>
</insert>
<delete id="deleteDateByTableName">
delete from ${table} where #{ymdhms} > CONVERT(varchar(30),create_time, 120)
</delete>
@ -151,6 +152,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
equ.equipment_name,
equ.equipment_type_code
</select>
<!--创建新表-->
<insert id="createNewTable">
SELECT TOP 0 * INTO ${tableNew} FROM mes_material_transfer_result
</insert>
<select id="copyBkDateByTable">
insert into ${table}
select * FROM mes_material_transfer_result
where create_time >= #{startDate} and #{endDate}>create_time
</select>
<delete id="deleteBkDateByTable">
delete from mes_material_transfer_result
where create_time >= #{startDate} and #{endDate}>create_time
</delete>
<delete id="deleteBkDate">
delete from ${table}
where create_time >= #{startDate} and #{endDate}>create_time
</delete>
</mapper>

@ -105,9 +105,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bp.product_model productModel,
w.prod_line_code prodLineCode
from pro_rfid_process_detail rfid
left join pro_process p on p.process_id = rfid.next_process_id
left join pro_order_workorder w on w.workorder_code = rfid.workorder_code
left join base_product bp on bp.product_code = w.product_code
left join pro_process p on p.process_id = rfid.next_process_id
left join pro_order_workorder w on w.workorder_code = rfid.workorder_code
left join base_product bp on bp.product_code = w.product_code
where rfid.bind_status = '1'
and rfid.rfid = #{rfidNo}
order by rfid.create_time desc

@ -84,6 +84,7 @@ public class QcProCheckServiceImpl implements QcProCheckService {
DynamicDataSourceContextHolder.push("ds_"+qcProCheck.getFactoryCode());
QcProCheck dto = qcProCheckMapper.getInfoByRfid(qcProCheck);
if(dto==null || StringUtils.isEmpty(dto.getProductCode())){
dto = new QcProCheck();
dto.setProductCode("EmptyPallet");
}else{
if(StringUtils.isNotEmpty(dto.getProductName())){

Loading…
Cancel
Save