Browse Source

开发打卡浏览数统计功能

lutong 2 months ago
parent
commit
4da05fe25f

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/StoreClockIn.java

@@ -59,6 +59,10 @@ public class StoreClockIn extends Model<StoreClockIn> {
     @TableField("like_count")
     @TableField("like_count")
     private Integer likeCount;
     private Integer likeCount;
 
 
+    @ApiModelProperty(value = "浏览数量")
+    @TableField("view_count")
+    private Integer viewCount;
+
     @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
     @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
     @TableField("delete_flag")
     @TableField("delete_flag")
     @TableLogic
     @TableLogic

+ 10 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreClockInController.java

@@ -97,4 +97,14 @@ public class StoreClockInController {
         return R.data(storeClockInService.getStoreClockInById(id, userId));
         return R.data(storeClockInService.getStoreClockInById(id, userId));
     }
     }
 
 
+    @ApiOperation("增加浏览数")
+    @ApiOperationSupport(order = 7)
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query")})
+    @GetMapping("/increaseViewCount")
+    public R<String> increaseViewCount(Integer id) {
+        log.info("StoreClockInController.increaseViewCount?id={}", id);
+        int result = storeClockInService.increaseViewCount(id);
+        return 1 == result ? R.success("浏览数增加成功") : R.fail("浏览数增加失败");
+    }
+
 }
 }

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/StoreClockInService.java

@@ -44,4 +44,12 @@ public interface StoreClockInService extends IService<StoreClockIn> {
      * @return 打卡记录
      * @return 打卡记录
      */
      */
     StoreClockInVo getStoreClockInById(Integer id, Integer userId);
     StoreClockInVo getStoreClockInById(Integer id, Integer userId);
+
+    /**
+     * 增加浏览数
+     *
+     * @param id 打卡记录id
+     * @return 更新结果
+     */
+    int increaseViewCount(Integer id);
 }
 }

+ 12 - 2
alien-store/src/main/java/shop/alien/store/service/impl/StoreClockInServiceImpl.java

@@ -21,7 +21,6 @@ import shop.alien.store.config.WebSocketProcess;
 import shop.alien.store.service.StoreClockInService;
 import shop.alien.store.service.StoreClockInService;
 import shop.alien.store.service.StoreCommentService;
 import shop.alien.store.service.StoreCommentService;
 import shop.alien.store.util.ai.AiContentModerationUtil;
 import shop.alien.store.util.ai.AiContentModerationUtil;
-import shop.alien.store.util.ai.AiVideoModerationUtil;
 
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.annotation.PreDestroy;
@@ -431,11 +430,14 @@ public class StoreClockInServiceImpl extends ServiceImpl<StoreClockInMapper, Sto
     @Override
     @Override
     public StoreClockInVo getStoreClockInById(Integer id, Integer userId) {
     public StoreClockInVo getStoreClockInById(Integer id, Integer userId) {
         StoreClockIn storeClockIn = storeClockInMapper.selectById(id);
         StoreClockIn storeClockIn = storeClockInMapper.selectById(id);
-        StoreClockInVo storeClockInVo = BeanUtil.copyProperties(storeClockIn, StoreClockInVo.class);
         if (null == storeClockIn) {
         if (null == storeClockIn) {
             return null;
             return null;
         }
         }
 
 
+        // 查看详情时自动增加浏览数
+        increaseViewCount(id);
+
+        StoreClockInVo storeClockInVo = BeanUtil.copyProperties(storeClockIn, StoreClockInVo.class);
         StoreInfo storeInfo = storeInfoMapper.selectById(storeClockIn.getStoreId());
         StoreInfo storeInfo = storeInfoMapper.selectById(storeClockIn.getStoreId());
         // 店铺名称
         // 店铺名称
         storeClockInVo.setStoreName(storeInfo.getStoreName());
         storeClockInVo.setStoreName(storeInfo.getStoreName());
@@ -471,4 +473,12 @@ public class StoreClockInServiceImpl extends ServiceImpl<StoreClockInMapper, Sto
         }
         }
         return storeClockInVo;
         return storeClockInVo;
     }
     }
+
+    @Override
+    public int increaseViewCount(Integer id) {
+        LambdaUpdateWrapper<StoreClockIn> wrapper = new LambdaUpdateWrapper<>();
+        wrapper.eq(StoreClockIn::getId, id);
+        wrapper.setSql("view_count = IFNULL(view_count, 0) + 1");
+        return storeClockInMapper.update(null, wrapper);
+    }
 }
 }