parent
1c81b6bf5a
commit
ffb80dd5c6
@ -0,0 +1,35 @@
|
||||
package com.luoo.comment.controller;
|
||||
|
||||
import api.Result;
|
||||
import com.luoo.comment.service.VisitCountService;
|
||||
import controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @program: luoo_parent
|
||||
* @description:
|
||||
* @author: yawei.huang
|
||||
* @create: 2024-10-31 12:37
|
||||
**/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/visit")
|
||||
@Api(tags = "埋点")
|
||||
public class VisitCountController extends BaseController {
|
||||
@Autowired
|
||||
private VisitCountService visitCountService;
|
||||
|
||||
@GetMapping("/count/o2o")
|
||||
public Result<Void> addNewVisit(HttpServletRequest req){
|
||||
String ipAddr = getIpAddr(req);
|
||||
visitCountService.addNewVisit(ipAddr);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.luoo.comment.dao;
|
||||
|
||||
import com.luoo.comment.pojo.VisitCount;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
public interface VisitCountDao extends MongoRepository<VisitCount,String> {
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.luoo.comment.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum VisitTypeEnums {
|
||||
O2O("o2o","o2o"),
|
||||
WEB("web","web");
|
||||
|
||||
private String type;
|
||||
private String desc;
|
||||
|
||||
VisitTypeEnums(String type, String desc) {
|
||||
this.type = type;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.luoo.comment.service;
|
||||
|
||||
import com.luoo.comment.dao.VisitCountDao;
|
||||
import com.luoo.comment.enums.VisitTypeEnums;
|
||||
import com.luoo.comment.pojo.VisitCount;
|
||||
import com.luoo.comment.util.IpUtil;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @program: luoo_parent
|
||||
* @description: 访问页面service层
|
||||
* @author: yawei.huang
|
||||
* @create: 2024-10-31 12:30
|
||||
**/
|
||||
@Service
|
||||
public class VisitCountService {
|
||||
|
||||
private final VisitCountDao visitCountDao;
|
||||
|
||||
public VisitCountService(VisitCountDao visitCountDao) {
|
||||
this.visitCountDao = visitCountDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增一次访问
|
||||
*/
|
||||
public void addNewVisit(String ipAddr) {
|
||||
String ipLocation = IpUtil.getIpLocation(ipAddr);
|
||||
VisitCount visitCount = VisitCount.builder()
|
||||
.ip(ipAddr)
|
||||
.type(VisitTypeEnums.O2O.getType())
|
||||
.visitTime(LocalDateTime.now())
|
||||
.location(ipLocation)
|
||||
.build();
|
||||
visitCountDao.save(visitCount);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue