release: 新增访问埋点计数

release-2024-04-25
huangyw 3 weeks ago
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,45 @@
package com.luoo.comment.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Builder;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @program: luoo_parent
* @description: 访
* @author: yawei.huang
* @create: 2024-10-31 12:28
**/
@Builder
@Data
public class VisitCount implements Serializable {
private static final long serialVersionUID = 1161582568237312816L;
/**
* 访o2o, web
*/
private String type;
/**
* 访
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime visitTime;
/**
* ip
*/
private String ip;
/**
*
*/
private String location;
}

@ -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…
Cancel
Save