Browse Source

feature 增加自动创建分区的代码

xiahan 3 months ago
parent
commit
b679ecf0e9

+ 3 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/dao/CommonBusinessDao.java

@@ -26,4 +26,7 @@ public interface CommonBusinessDao {
     List<SysUserDo>getHandlerInfoByVolumeNo(@Param("roleCode") String roleCode,@Param("userNum") String userNum);
 
     List<SysUserVo> getUserByRoleCode(@Param("roleCodes") List<String> roleCodes);
+
+
+    void  mysqlPartitionCreate(String partitionName,int year);
 }

+ 2 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/ScheduledTaskService.java

@@ -10,4 +10,6 @@ import com.rongwei.rwcommon.base.R;
  */
 public interface ScheduledTaskService {
     R generateRoutineInspectionTask();
+
+    R mysqlPartitionCreate();
 }

+ 13 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/ScheduledTaskServiceImpl.java

@@ -82,6 +82,19 @@ public class ScheduledTaskServiceImpl implements ScheduledTaskService {
         return R.ok();
     }
 
+    /**
+     * 定时任务新增分区
+     * @return
+     */
+    @Override
+    public R mysqlPartitionCreate() {
+        LocalDate now = LocalDate.now();
+        int currentYear = now.getYear();
+
+
+        return null;
+    }
+
     public List<SwInspectionRouteDo> getRouteList(String weekValue, String monthValue, int dayOfMonth, int currentMontLastDay) {
         List<SwInspectionRouteDo> list = swInspectionRouteService.list(new LambdaQueryWrapper<SwInspectionRouteDo>()
                 .eq(BaseDo::getDeleted, NO_REMOVE_FLAG)

+ 12 - 0
zhsw-common/src/main/resources/mybatis/zhsw/CommonBusinessDao.xml

@@ -76,4 +76,16 @@
             </foreach>
         </where>
     </select>
+    <select id="mysqlPartitionCreate">
+        ALTER TABLE sw_water_usage_entry
+            REORGANIZE PARTITION p_future INTO (
+                PARTITION ${partitionName} VALUES LESS THAN (#{year,javaType=Integer.class}),
+                PARTITION p_future VALUES LESS THAN MAXVALUE
+                );
+        ALTER TABLE sw_bill_management_paid
+            REORGANIZE PARTITION p_future INTO (
+                PARTITION ${partitionName} VALUES LESS THAN (#{year,javaType=Integer.class}),
+                PARTITION p_future VALUES LESS THAN MAXVALUE
+                );
+    </select>
 </mapper>

+ 9 - 0
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/ScheduledTaskController.java

@@ -28,10 +28,19 @@ public class ScheduledTaskController {
 
     @Autowired
     private ScheduledTaskServiceImpl scheduledTaskService;
+
     @Scheduled(cron = "0 0 1 * * ?")
     @PostMapping("/routine/inspection")
     private R generateRoutineInspectionTask(){
         log.info("开始手动生成任务");
         return scheduledTaskService.generateRoutineInspectionTask();
     }
+
+    @Scheduled(cron = "0 0 1 1 12 ?")
+    @PostMapping("/partition")
+    private R mysqlPartitionCreate(){
+        log.info("开始手动生成任务");
+        return scheduledTaskService.mysqlPartitionCreate();
+    }
+
 }