【新增】APP访问统计接口

This commit is contained in:
MichaelWin
2026-01-30 14:32:54 +08:00
parent ed3209d69d
commit e85b25754d
7 changed files with 136 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ public class SaTokenConfig implements WebMvcConfigurer {
// 排除获取最新app接口
.excludePathPatterns("/api/app", "/api/app/getAppVersion")
.excludePathPatterns("/api/website/**")
.excludePathPatterns("/api/app/access_statistics/**")
// 排除模型接口
.excludePathPatterns("/model/page", "/model/list", "/model/detail/**", "/model/category/**")
// 排除咨询接口

View File

@@ -0,0 +1,17 @@
package com.corewing.app.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("APP统计请求模型")
@Data
public class AccessStatisticsRequest {
@ApiModelProperty("访问页面")
private String visitPage;
@ApiModelProperty("访问类型")
private String accessType;
}

View File

@@ -0,0 +1,40 @@
package com.corewing.app.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.corewing.app.common.base.CommonEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ApiModel("APP访问统计")
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("app_access_statistics")
public class AppAccessStatistics extends CommonEntity {
@ApiModelProperty("id")
@TableId
private String id;
@ApiModelProperty("用户id")
private Long userId;
@ApiModelProperty("访问页面")
private String visitPage;
@ApiModelProperty("访问类型")
private String accessType;
@ApiModelProperty("访问IP")
private String accessIp;
@ApiModelProperty("备注")
private String remark;
@ApiModelProperty("扩展参数")
private String extJson;
}

View File

@@ -0,0 +1,9 @@
package com.corewing.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.corewing.app.entity.AppAccessStatistics;
import org.mapstruct.Mapper;
@Mapper
public interface AppAccessStatisticsMapper extends BaseMapper<AppAccessStatistics> {
}

View File

@@ -0,0 +1,28 @@
package com.corewing.app.modules.app;
import com.corewing.app.common.Result;
import com.corewing.app.dto.AccessStatisticsRequest;
import com.corewing.app.service.AppAccessStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Api(tags = "APP访问统计")
@RestController
@RequestMapping("/api/app/access_statistics")
public class AppAccessStatisticsController {
@Resource
private AppAccessStatisticsService appAccessStatisticsService;
@ApiOperation("访问统计接口")
@GetMapping("/accumulate")
private Result<String> accumulate(AccessStatisticsRequest accessStatisticsRequest) {
return Result.isBool(appAccessStatisticsService.accumulate(accessStatisticsRequest));
}
}

View File

@@ -0,0 +1,11 @@
package com.corewing.app.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.corewing.app.dto.AccessStatisticsRequest;
import com.corewing.app.entity.AppAccessStatistics;
public interface AppAccessStatisticsService extends IService<AppAccessStatistics> {
boolean accumulate(AccessStatisticsRequest accessStatisticsRequest);
}

View File

@@ -0,0 +1,30 @@
package com.corewing.app.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.corewing.app.dto.AccessStatisticsRequest;
import com.corewing.app.entity.AppAccessStatistics;
import com.corewing.app.mapper.AppAccessStatisticsMapper;
import com.corewing.app.service.AppAccessStatisticsService;
import org.springframework.stereotype.Service;
@Service
public class AppAccessStatisticsServiceImpl extends ServiceImpl<AppAccessStatisticsMapper, AppAccessStatistics> implements AppAccessStatisticsService {
@Override
public boolean accumulate(AccessStatisticsRequest accessStatisticsRequest) {
Object loginId = StpUtil.getLoginId();
AppAccessStatistics appAccessStatistics = new AppAccessStatistics();
if(loginId != null) {
appAccessStatistics.setUserId(Long.parseLong(loginId.toString()));
}
if(StrUtil.isNotBlank(accessStatisticsRequest.getVisitPage())) {
appAccessStatistics.setVisitPage(accessStatisticsRequest.getVisitPage());
}
if(StrUtil.isNotBlank(accessStatisticsRequest.getAccessType())) {
appAccessStatistics.setAccessType(accessStatisticsRequest.getAccessType());
}
return save(appAccessStatistics);
}
}