Browse Source

fuwuhao content link

丁云鹏 10 months ago
parent
commit
2132537273

+ 12 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/JobService.java

@@ -11,6 +11,9 @@ import org.apache.commons.lang.math.NumberUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -32,8 +35,15 @@ public class JobService {
     public void syncViewCount() {
         ArticleContentLinkExample example = new ArticleContentLinkExample();
 
-        long now = System.currentTimeMillis();
-        long time = now - (now % seconds1d) - seconds7d;
+
+        LocalDate today = LocalDate.now();
+        // 计算7天前的日期
+        LocalDate dateSevenDaysAgo = today.minusDays(7);
+        // 将日期转换为当天开始的时间(00:00:00)并指定时区
+        ZonedDateTime zonedDateTime = dateSevenDaysAgo.atStartOfDay(ZoneId.systemDefault());
+        // 将ZonedDateTime转换为时间戳(毫秒)
+        long time = zonedDateTime.toInstant().toEpochMilli();
+
 
         example.createCriteria().andCreateTimeGreaterThanOrEqualTo(time);
         List<ArticleContentLink> links = articleContentLinkMapper.selectByExample(example);

+ 2 - 1
long-article-recommend-service/src/main/resources/mapper/crawler/ArticleContentLinkMapper.xml

@@ -260,7 +260,8 @@
     INSERT INTO article_content_link (gzh_id, idx, content_link, create_time, title, view_count, update_time)
     VALUES
     <foreach collection="list" item="item" separator=",">
-      (#{item.gzhId}, #{item.idx}, #{item.contentLink}, #{item.createTime}, #{item.title}, #{item.viewCount}, #{item.updateTime}
+      (#{item.gzhId}, #{item.idx}, #{item.contentLink}, #{item.createTime}, #{item.title}, #{item.viewCount},
+      #{item.updateTime})
     </foreach>
   </insert>
 </mapper>