Kaynağa Gözat

根据传入时间自动计算当月需要添加的分区数量

sbj 1 yıl önce
ebeveyn
işleme
469dbf180b

+ 5 - 0
pom.xml

@@ -45,6 +45,11 @@
       <systemPath>${project.basedir}/libs/Infrastructure-1.1-SNAPSHOT.jar</systemPath>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-freemarker</artifactId>

+ 10 - 1
src/main/java/com/example/sqlrun/service/impl/SpaceAndPartitionServiceImpl.java

@@ -9,10 +9,12 @@ import com.shanghaigeography.Util.DateUtils;
 import java.sql.SQLException;
 import java.text.ParseException;
 import java.time.YearMonth;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import java.sql.Statement;
 
@@ -111,7 +113,14 @@ public class SpaceAndPartitionServiceImpl implements SpaceAndPartitionService {
       String partitionNamePrefix = param.get("partitionNamePrefix");
       String tableSpaceName = param.get("tableSpaceName");
       Date startDate = DateUtils.stringToDate(param.get("startDate"), "yyyy-MM-dd");
-      Integer wantedDay = Integer.valueOf(param.get("wantedDay"));
+      Integer wantedDay = null;
+      if (StringUtils.isBlank(param.get("wantedDay"))){
+        Calendar instance = Calendar.getInstance();
+        instance.setTime(startDate);
+        wantedDay = instance.getActualMaximum(Calendar.DAY_OF_MONTH) - instance.get(Calendar.DAY_OF_MONTH) + 1;
+      }else {
+        wantedDay = Integer.valueOf(param.get("wantedDay"));
+      }
       List<String> partitionSql = MakePartitionSql
           .makePartitionSql(tableName, partitionNamePrefix, tableSpaceName, startDate, wantedDay);
       for (String s : partitionSql) {

+ 7 - 6
src/main/java/com/example/sqlrun/test.java

@@ -2,17 +2,16 @@ package com.example.sqlrun;
 
 import com.example.sqlrun.fixSql.MakePartitionSql;
 import com.example.sqlrun.fixSql.MakeTableSpace;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.text.ParseException;
-import java.time.YearMonth;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-import org.springframework.stereotype.Component;
-
 import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
-import java.sql.SQLException;
-import java.sql.Statement;
+import org.springframework.stereotype.Component;
 
 @Component
 public class test {
@@ -34,13 +33,15 @@ public class test {
             "GHJG_DYANMIC.GPSINFO_HISTORY", "GPSINFO_HISTORY", null, 10, 50, 100, "202312", 10);
     for (Map map : gpsinfo_history) {
       Date date = (Date) map.get("date");
+      Calendar instance = Calendar.getInstance();
+      instance.setTime(date);
       List<String> strings =
           MakePartitionSql.makePartitionSql(
               "GHJG_DYANMIC.GPSINFO_HISTORY",
               "GPSINFO_HISTORY",
               map.get("tableSpaceName").toString(),
               date,
-              YearMonth.of(date.getYear() + 1900,date.getMonth() + 1).lengthOfMonth()
+              instance.getActualMaximum(Calendar.DAY_OF_MONTH) - instance.get(Calendar.DAY_OF_MONTH) + 1
               );
       System.out.println(map.get("tableSpaceSql"));
       for (String string : strings) {