bug修复

This commit is contained in:
张锐 committed 2026-11-24 19:45:51 +08:00
1 parent ec4ca451bb
commit ab0245b9a3
24 files changed
+468 -3

No files matched your search

@@ -0,0 +1,10 @@
package com.shoplix.modules.analytics.dto;
import lombok.Data;
/** 访问设备分布数据。 */
@Data
public class FlowDeviceDto {
/** 设备类型。 */ private String device;
/** 页面浏览次数。 */ private Long pageViews;
}
@@ -0,0 +1,12 @@
package com.shoplix.modules.analytics.dto;
import lombok.Data;
/** 热门页面访问数据。 */
@Data
public class FlowPageDto {
/** 页面路径。 */ private String path;
/** 页面标题。 */ private String title;
/** 页面浏览次数。 */ private Long pageViews;
/** 独立访客数量。 */ private Long visitors;
}
@@ -0,0 +1,12 @@
package com.shoplix.modules.analytics.dto;
import lombok.Data;
/** 访问流量汇总数据。 */
@Data
public class FlowSummaryDto {
/** 页面浏览次数。 */ private Long pageViews;
/** 独立访客数量。 */ private Long visitors;
/** 独立会话数量。 */ private Long sessions;
/** 平均页面停留秒数。 */ private Long averageDuration;
}
@@ -0,0 +1,11 @@
package com.shoplix.modules.analytics.dto;
import lombok.Data;
/** 每日访问趋势数据。 */
@Data
public class FlowTrendDto {
/** 日期,格式yyyyMMdd。 */ private Integer date;
/** 页面浏览次数。 */ private Long pageViews;
/** 独立访客数量。 */ private Long visitors;
}
@@ -1,10 +1,56 @@
package com.shoplix.modules.analytics.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shoplix.modules.analytics.dto.FlowDeviceDto;
import com.shoplix.modules.analytics.dto.FlowPageDto;
import com.shoplix.modules.analytics.dto.FlowSummaryDto;
import com.shoplix.modules.analytics.dto.FlowTrendDto;
import com.shoplix.modules.analytics.repository.entity.FlowLogEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/** 前台访问打点Mapper。 */
@Mapper
public interface FlowLogMapper extends BaseMapper<FlowLogEntity> {
/** 汇总指定日期范围的访问数据。 */
@Select("""
SELECT COALESCE(SUM(event_name = 'page_view'), 0) AS pageViews,
COUNT(DISTINCT CASE WHEN event_name = 'page_view' THEN cuid END) AS visitors,
COUNT(DISTINCT CASE WHEN event_name = 'page_view' THEN session_code END) AS sessions,
COALESCE(ROUND(AVG(CASE WHEN event_name = 'page_leave' AND duration >= 0 THEN duration END)), 0) AS averageDuration
FROM flow_log WHERE site_code = #{siteCode} AND deleted = 0 AND dt >= #{startDate}
""")
FlowSummaryDto summary(@Param("siteCode") String siteCode, @Param("startDate") Integer startDate);
/** 查询指定日期范围的每日访问趋势。 */
@Select("""
SELECT dt AS date, COUNT(*) AS pageViews, COUNT(DISTINCT cuid) AS visitors
FROM flow_log WHERE site_code = #{siteCode} AND deleted = 0
AND event_name = 'page_view' AND dt >= #{startDate}
GROUP BY dt ORDER BY dt
""")
List<FlowTrendDto> trend(@Param("siteCode") String siteCode, @Param("startDate") Integer startDate);
/** 查询指定日期范围的热门页面。 */
@Select("""
SELECT COALESCE(NULLIF(url_body, ''), '/') AS path,
MAX(COALESCE(NULLIF(page_title, ''), NULLIF(page_name, ''), '未命名页面')) AS title,
COUNT(*) AS pageViews, COUNT(DISTINCT cuid) AS visitors
FROM flow_log WHERE site_code = #{siteCode} AND deleted = 0
AND event_name = 'page_view' AND dt >= #{startDate}
GROUP BY COALESCE(NULLIF(url_body, ''), '/') ORDER BY pageViews DESC LIMIT 8
""")
List<FlowPageDto> topPages(@Param("siteCode") String siteCode, @Param("startDate") Integer startDate);
/** 查询指定日期范围的设备分布。 */
@Select("""
SELECT COALESCE(NULLIF(device, ''), 'UNKNOWN') AS device, COUNT(*) AS pageViews
FROM flow_log WHERE site_code = #{siteCode} AND deleted = 0
AND event_name = 'page_view' AND dt >= #{startDate}
GROUP BY COALESCE(NULLIF(device, ''), 'UNKNOWN') ORDER BY pageViews DESC
""")
List<FlowDeviceDto> devices(@Param("siteCode") String siteCode, @Param("startDate") Integer startDate);
}
@@ -1,9 +1,15 @@
package com.shoplix.modules.analytics.repository.service;
import com.shoplix.modules.analytics.dto.FlowDeviceDto;
import com.shoplix.modules.analytics.dto.FlowPageDto;
import com.shoplix.modules.analytics.dto.FlowSummaryDto;
import com.shoplix.modules.analytics.dto.FlowTrendDto;
import com.shoplix.modules.analytics.repository.entity.FlowLogEntity;
import com.shoplix.modules.analytics.repository.mapper.FlowLogMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/** 前台访问打点单表数据源服务。 */
@Service
public class FlowLogRepositoryService {
@@ -19,4 +25,9 @@ public class FlowLogRepositoryService {
public int insert(FlowLogEntity entity) {
return mapper.insert(entity);
}
/** 汇总指定日期范围的访问数据。 */ public FlowSummaryDto summary(String siteCode, Integer startDate) { return mapper.summary(siteCode, startDate); }
/** 查询每日访问趋势。 */ public List<FlowTrendDto> trend(String siteCode, Integer startDate) { return mapper.trend(siteCode, startDate); }
/** 查询热门页面。 */ public List<FlowPageDto> topPages(String siteCode, Integer startDate) { return mapper.topPages(siteCode, startDate); }
/** 查询设备分布。 */ public List<FlowDeviceDto> devices(String siteCode, Integer startDate) { return mapper.devices(siteCode, startDate); }
}
@@ -32,6 +32,8 @@ public class ContentRepositoryService {
.eq(ContentEntity::getContentType, type).orderByDesc(ContentEntity::getPublishTime)
.orderByDesc(ContentEntity::getUpdateTime));
}
/** 统计站点指定类型的全部未删除内容。 */ public long count(String siteCode, String type) { return mapper.selectCount(Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode).eq(ContentEntity::getDeleted, 0).eq(ContentEntity::getContentType, type)); }
/** 统计站点指定类型及发布状态的内容。 */ public long countByStatus(String siteCode, String type, String status) { return mapper.selectCount(Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode).eq(ContentEntity::getDeleted, 0).eq(ContentEntity::getContentType, type).eq(ContentEntity::getStatus, status)); }
/** 查询站点指定类型的已发布内容列表。 */
public List<ContentEntity> listPublished(String siteCode, String type) {
return mapper.selectList(Wrappers.<ContentEntity>lambdaQuery().eq(ContentEntity::getSiteCode, siteCode)
@@ -5,6 +5,9 @@ public class InquiryRecordRepositoryService {
private final InquiryRecordMapper mapper; /** 注入Mapper。 */ public InquiryRecordRepositoryService(InquiryRecordMapper mapper){this.mapper=mapper;}
/** 新增询盘。 */ public int insert(InquiryRecordEntity e){return mapper.insert(e);}
/** 查询后台询盘列表。 */ public List<InquiryRecordEntity> list(String site,String status){var q=Wrappers.<InquiryRecordEntity>lambdaQuery().eq(InquiryRecordEntity::getSiteCode,site);if(status!=null&&!status.isBlank())q.eq(InquiryRecordEntity::getStatus,status);return mapper.selectList(q.orderByDesc(InquiryRecordEntity::getCreateTime).last("LIMIT 500"));}
/** 统计站点指定时间后的有效询盘。 */ public long countSince(String site,Long start){return mapper.selectCount(Wrappers.<InquiryRecordEntity>lambdaQuery().eq(InquiryRecordEntity::getSiteCode,site).eq(InquiryRecordEntity::getDeleted,0).ge(InquiryRecordEntity::getCreateTime,start).eq(InquiryRecordEntity::getSpamFlag,0));}
/** 统计站点未读且非垃圾询盘。 */ public long countUnread(String site){return mapper.selectCount(Wrappers.<InquiryRecordEntity>lambdaQuery().eq(InquiryRecordEntity::getSiteCode,site).eq(InquiryRecordEntity::getDeleted,0).eq(InquiryRecordEntity::getReadStatus,0).eq(InquiryRecordEntity::getSpamFlag,0));}
/** 查询站点最近的有效询盘。 */ public List<InquiryRecordEntity> recent(String site,int limit){return mapper.selectList(Wrappers.<InquiryRecordEntity>lambdaQuery().eq(InquiryRecordEntity::getSiteCode,site).eq(InquiryRecordEntity::getDeleted,0).eq(InquiryRecordEntity::getSpamFlag,0).orderByDesc(InquiryRecordEntity::getCreateTime).last("LIMIT "+limit));}
/** 按编号查询询盘。 */ public Optional<InquiryRecordEntity> find(String site,String code){return Optional.ofNullable(mapper.selectOne(Wrappers.<InquiryRecordEntity>lambdaQuery().eq(InquiryRecordEntity::getSiteCode,site).eq(InquiryRecordEntity::getInquiryCode,code)));}
/** 更新可变处理字段。 */ public int update(InquiryRecordEntity e){return mapper.update(e,Wrappers.<InquiryRecordEntity>lambdaUpdate().eq(InquiryRecordEntity::getSiteCode,e.getSiteCode()).eq(InquiryRecordEntity::getInquiryCode,e.getInquiryCode()));}
/** 统计IP时间窗口提交数。 */ public long countIp(String site,String hash,Long start){return mapper.selectCount(Wrappers.<InquiryRecordEntity>lambdaQuery().eq(InquiryRecordEntity::getSiteCode,site).eq(InquiryRecordEntity::getIpHash,hash).ge(InquiryRecordEntity::getCreateTime,start));}
@@ -31,6 +31,8 @@ public class ProductRepositoryService {
.eq(ProductEntity::getDeleted, 0)
.orderByAsc(ProductEntity::getSortNo).orderByDesc(ProductEntity::getUpdateTime));
}
/** 统计站点全部未删除产品。 */ public long count(String siteCode) { return mapper.selectCount(Wrappers.<ProductEntity>lambdaQuery().eq(ProductEntity::getSiteCode, siteCode).eq(ProductEntity::getDeleted, 0)); }
/** 统计站点指定发布状态的产品。 */ public long countByStatus(String siteCode, String status) { return mapper.selectCount(Wrappers.<ProductEntity>lambdaQuery().eq(ProductEntity::getSiteCode, siteCode).eq(ProductEntity::getDeleted, 0).eq(ProductEntity::getStatus, status)); }
/** 查询前台已发布产品列表。 */
public List<ProductEntity> listPublished(String siteCode, String categoryCode) {
var query = Wrappers.<ProductEntity>lambdaQuery().eq(ProductEntity::getSiteCode, siteCode)