wangyunpeng před 4 týdny
rodič
revize
8681d1e1be

+ 5 - 3
core/src/main/java/com/tzld/supply/job/SpiderContentFeishuJob.java

@@ -25,6 +25,7 @@ import org.springframework.web.client.RestTemplate;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Component
@@ -70,6 +71,7 @@ public class SpiderContentFeishuJob {
         if (CollectionUtil.isEmpty(exportList)) {
             return;
         }
+        List<String> dateStrList = exportList.stream().map(SpiderContentEntity::getDate).distinct().collect(Collectors.toList());
         int rowNum = exportList.size();
         List<List<Object>> rows = new ArrayList<>();
         Field[] fields = SpiderContentEntity.class.getDeclaredFields();
@@ -89,11 +91,11 @@ public class SpiderContentFeishuJob {
             }
         }
 
-        doSendFeishuSheet("RKgdwQsUbix4lfkOtwKcJ8DonDh", "a337ce", rowNum, rows,
+        doSendFeishuSheet(dateStrList, "RKgdwQsUbix4lfkOtwKcJ8DonDh", "a337ce", rowNum, rows,
                 2, null, null);
     }
 
-    public void doSendFeishuSheet(String sheetToken, String sheetId,
+    public void doSendFeishuSheet(List<String> dateStrList, String sheetToken, String sheetId,
                                   int rowNum, List<List<Object>> rows, Integer startRowIndex,
                                   List<Pair<String, String>> styles,
                                   List<Pair<String, List<Pair<String, String>>>> thanks) {
@@ -103,7 +105,7 @@ public class SpiderContentFeishuJob {
         httpHeaders.add("Authorization", "Bearer " + token.getFirst());
 
         // 先删除掉已存在的dateStr数据
-        // FeishuExcelUtil.feishuSheetDelete(sheetToken, sheetId, rowNum, startRowIndex, httpHeaders, restTemplate);
+         FeishuExcelUtil.feishuSheetDelete(sheetToken, sheetId, rowNum, startRowIndex, httpHeaders, restTemplate, dateStrList);
         List<List<List<Object>>> partitions = Lists.partition(rows, 100);
         FeishuExcelUtil.feishuSheetInsert(sheetToken, sheetId, startRowIndex, httpHeaders, restTemplate, partitions);
         // 此处先简单处理,调整单元格为”百分比小数点“

+ 8 - 8
core/src/main/java/com/tzld/supply/util/DateUtils.java

@@ -185,10 +185,10 @@ public final class DateUtils {
             calendar.set(Calendar.SECOND, 0);
             calendar.set(Calendar.MILLISECOND, 0);
 
-            return calendar.getTimeInMillis() / 1000;
+            return calendar.getTimeInMillis();
         } catch (Exception e) {
             Date date = new Date();
-            return date.getTime() / 1000;
+            return date.getTime();
         }
     }
 
@@ -198,7 +198,7 @@ public final class DateUtils {
             // 设置时区为UTC(你可以根据需要更改时区)
             calendar.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
             // 将时间戳转换为毫秒并设置时间
-            calendar.setTimeInMillis(timestamp * 1000L);
+            calendar.setTimeInMillis(timestamp);
             calendar.set(Calendar.HOUR_OF_DAY, 0);
             calendar.set(Calendar.MINUTE, 0);
             calendar.set(Calendar.SECOND, 0);
@@ -224,10 +224,10 @@ public final class DateUtils {
             calendar.set(Calendar.SECOND, 59);
             calendar.set(Calendar.MILLISECOND, 999);
 
-            return calendar.getTimeInMillis() / 1000;
+            return calendar.getTimeInMillis();
         } catch (Exception e) {
             Date date = new Date();
-            return date.getTime() / 1000;
+            return date.getTime();
         }
     }
 
@@ -236,7 +236,7 @@ public final class DateUtils {
         // 设置时区为UTC(你可以根据需要更改时区)
         calendar.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
         // 将时间戳转换为毫秒并设置时间
-        calendar.setTimeInMillis(timestamp * 1000L);
+        calendar.setTimeInMillis(timestamp);
         // 获取小时
         return calendar.get(Calendar.HOUR_OF_DAY);
     }
@@ -246,7 +246,7 @@ public final class DateUtils {
         // 设置时区为UTC(你可以根据需要更改时区)
         calendar.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
         // 将时间戳转换为毫秒并设置时间
-        calendar.setTimeInMillis(timestamp * 1000L);
+        calendar.setTimeInMillis(timestamp);
         // 获取小时
         return calendar.get(Calendar.MINUTE);
     }
@@ -279,7 +279,7 @@ public final class DateUtils {
         calendar.set(Calendar.SECOND, 0);
         calendar.set(Calendar.MILLISECOND, 0);
         calendar.add(Calendar.DAY_OF_MONTH, -days);
-        return calendar.getTime().getTime() / 1000;
+        return calendar.getTime().getTime();
     }
 
     public static String getBeforeDayStr(String dateStr, String format, int days) {

+ 20 - 2
core/src/main/java/com/tzld/supply/util/feishu/FeishuExcelUtil.java

@@ -1,5 +1,6 @@
 package com.tzld.supply.util.feishu;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.tzld.supply.util.MapBuilder;
@@ -24,12 +25,12 @@ public class FeishuExcelUtil {
                                    RestTemplate restTemplate,
                                    List<String> dateStrList) {
         HttpEntity<Object> queryEntity = new HttpEntity<>(httpHeaders);
-        int deleteRowNum = rowNum < 20 ? startRowIndex + rowNum : startRowIndex + (rowNum * 2);
+        int deleteRowNum = rowNum < 20 ? startRowIndex + dateStrList.size() * rowNum : startRowIndex + (rowNum * 2);
         ResponseEntity<String> queryResponseEntity = restTemplate.exchange(
                 String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values/%s!A"
                         + startRowIndex + ":A" + deleteRowNum, sheetToken, sheetId),
                 HttpMethod.GET, queryEntity, String.class);
-        JSONArray values = JSONObject.parseObject(queryResponseEntity.getBody())
+        JSONArray values = JSON.parseObject(queryResponseEntity.getBody())
                 .getJSONObject("data")
                 .getJSONObject("valueRange")
                 .getJSONArray("values");
@@ -94,6 +95,23 @@ public class FeishuExcelUtil {
             if (0 != responseJSON.getInteger("code")) {
                 log.error("doSendFeishuSheet write error :{}", responseJSON.getString("msg"));
             }
+            // 设置行高
+            httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<Object> putEntity = new HttpEntity<>(
+                    String.format("{\n" +
+                            "    \"dimension\": {\n" +
+                            "        \"sheetId\": \"%s\",\n" +
+                            "        \"majorDimension\": \"ROWS\",\n" +
+                            "        \"startIndex\": %s,\n" +
+                            "        \"endIndex\": %s\n" +
+                            "    },\n" +
+                            "    \"dimensionProperties\":{\n" +
+                            "        \"fixedSize\":27\n" +
+                            "    }\n" +
+                            "}", sheetId, startRow, Math.min(startRow + 4000, startRow + partition.size()) - 1),
+                    httpHeaders);
+            restTemplate.exchange(String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/dimension_range", sheetToken),
+                    HttpMethod.PUT, putEntity, String.class);
             startRow += partition.size();
         }
     }