diff --git a/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java b/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java index a2f4aac3..2016f205 100644 --- a/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java +++ b/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java @@ -114,7 +114,7 @@ public class RyTask { } /**每月1日执行1:10一次**/ public void dataBKTask(){ - logger.info("++数据库备份的数据+开始++dataClearTask+++++"); + logger.info("++数据库备份的数据+开始++dataBKTask+++++"); remoteMesService.dataBKTask(); } } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/controller/WCSInterfaceController.java b/op-modules/op-mes/src/main/java/com/op/mes/controller/WCSInterfaceController.java index 5c571759..c5432c13 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/controller/WCSInterfaceController.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/controller/WCSInterfaceController.java @@ -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 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()); diff --git a/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesMapper.java b/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesMapper.java index 4de2274e..e01e5f29 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesMapper.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesMapper.java @@ -40,4 +40,12 @@ public interface MesMapper { List 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); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/IWCSInterfaceService.java b/op-modules/op-mes/src/main/java/com/op/mes/service/IWCSInterfaceService.java index 33ad4c27..8b720e6f 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/IWCSInterfaceService.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/IWCSInterfaceService.java @@ -31,4 +31,6 @@ public interface IWCSInterfaceService { List getProShifts(BoardDTO boardDTO); R dataClearTask(List tables); + + R dataBKTask(List tables); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java index aff2697d..f424345e 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/IWCInterfaceServiceImpl.java @@ -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 tables) { + // 加载sf-cloud库的sys_datasource + SysUser sysUser = new SysUser(); + sysUser.setUserId(1L); + R>> dateSources0 = remoteUserService.getPoolNameList(sysUser); + List> dateSources = dateSources0.getData(); + ExecutorService executorService = new ThreadPoolExecutor( + dateSources.size(), + dateSources.size(), + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue()); + 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 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){ + //如果月份是 1,4,7,10则创建季度表 + 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 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()); } } diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml index fc72d0fa..5c279053 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/MesMapper.xml @@ -55,6 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ) + delete from ${table} where #{ymdhms} > CONVERT(varchar(30),create_time, 120) @@ -151,6 +152,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" equ.equipment_name, equ.equipment_type_code - + + + SELECT TOP 0 * INTO ${tableNew} FROM mes_material_transfer_result + + + + delete from mes_material_transfer_result + where create_time >= #{startDate} and #{endDate}>create_time + + + delete from ${table} + where create_time >= #{startDate} and #{endDate}>create_time + diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/ProRfidProcessDetailMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/ProRfidProcessDetailMapper.xml index 769e14e9..c71ed154 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/ProRfidProcessDetailMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/ProRfidProcessDetailMapper.xml @@ -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 diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/serviceImpl/QcProCheckServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/serviceImpl/QcProCheckServiceImpl.java index 58698799..ad1b37ec 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/service/serviceImpl/QcProCheckServiceImpl.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/service/serviceImpl/QcProCheckServiceImpl.java @@ -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())){ diff --git a/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java b/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java index 83074a24..3536f0fb 100644 --- a/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java +++ b/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java @@ -345,7 +345,6 @@ public class SysUserController extends BaseController { /** * 变更工厂数据源 */ - @RequiresPermissions("system:user:changePoolName") @PutMapping("/changePoolName") public AjaxResult changePoolName(@RequestBody SysUser user) { String username = SecurityUtils.getUsername();