瀏覽代碼

浏览记录

openHj 11 月之前
父節點
當前提交
804019136c

+ 11 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/entity/browsing/dto/AddBrowsingDto.java

@@ -0,0 +1,11 @@
+package com.fjhx.xmhjc.entity.browsing.dto;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class AddBrowsingDto {
+    private Date createTime;
+    private String name;
+}

+ 5 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/entity/browsing/po/BrowsingHistory.java

@@ -37,6 +37,11 @@ public class BrowsingHistory extends BaseIdPo {
     private Integer day;
 
     /**
+     * 时
+     */
+    private Integer hour;
+
+    /**
      * 周
      */
     private Integer week;

+ 2 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/browsing/BrowsingHistoryService.java

@@ -1,5 +1,6 @@
 package com.fjhx.xmhjc.service.browsing;
 
+import com.fjhx.xmhjc.entity.browsing.dto.AddBrowsingDto;
 import com.fjhx.xmhjc.entity.browsing.po.BrowsingHistory;
 import com.ruoyi.common.core.service.BaseService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -49,4 +50,5 @@ public interface BrowsingHistoryService extends BaseService<BrowsingHistory> {
      */
     void delete(Long id);
 
+    void addBrowsingHistory(AddBrowsingDto addBrowsingDto);
 }

+ 21 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/browsing/impl/BrowsingHistoryServiceImpl.java

@@ -1,9 +1,14 @@
 package com.fjhx.xmhjc.service.browsing.impl;
 
+import cn.hutool.core.date.DateUtil;
+import com.fjhx.xmhjc.entity.browsing.dto.AddBrowsingDto;
 import com.fjhx.xmhjc.entity.browsing.po.BrowsingHistory;
 import com.fjhx.xmhjc.mapper.browsing.BrowsingHistoryMapper;
 import com.fjhx.xmhjc.service.browsing.BrowsingHistoryService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.xmhjc.utils.NetUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.ServletUtils;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.xmhjc.entity.browsing.vo.BrowsingHistoryVo;
@@ -12,6 +17,8 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.fjhx.xmhjc.entity.browsing.dto.BrowsingHistoryDto;
 import cn.hutool.core.bean.BeanUtil;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -63,4 +70,18 @@ public class BrowsingHistoryServiceImpl extends ServiceImpl<BrowsingHistoryMappe
         this.removeById(id);
     }
 
+    @Override
+    public void addBrowsingHistory(AddBrowsingDto addBrowsingDto) {
+        HttpServletRequest request = ServletUtils.getRequest();
+        String ip = NetUtils.getIpAddress(request);
+        BrowsingHistoryDto browsingHistoryDto = new BrowsingHistoryDto();
+        BeanUtil.copyProperties(addBrowsingDto, browsingHistoryDto);
+        browsingHistoryDto.setIp(ip);
+        Date createTime = addBrowsingDto.getCreateTime();
+        browsingHistoryDto.setYear(DateUtil.year(createTime));
+        browsingHistoryDto.setMonth(DateUtil.month(createTime) + 1);
+        browsingHistoryDto.setDay(DateUtil.dayOfMonth(createTime));
+        browsingHistoryDto.setHour(DateUtil.hour(createTime, true));
+        browsingHistoryDto.setWeek(DateUtil.weekOfYear(createTime));
+    }
 }