Przeglądaj źródła

修改主页统计

silent 4 lat temu
rodzic
commit
ec36d62f4a

+ 46 - 0
src/main/java/org/springblade/gateway/common_gateway/controller/IndexCensusController.java

@@ -0,0 +1,46 @@
+package org.springblade.gateway.common_gateway.controller;
+
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springblade.core.tool.api.R;
+import org.springblade.gateway.common_gateway.dto.IndexCensusDto;
+import org.springblade.gateway.common_gateway.service.IndexCensusService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author: Silent
+ * @Description
+ * @Date: Created in 16:20 2021/11/19
+ * @Modified By:
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("app/index/census")
+@Api(value = "首页统计", tags = "首页统计接口")
+public class IndexCensusController {
+	private final IndexCensusService indexCensusService;
+
+	/**
+	 * 统计所有数量
+	 */
+	@GetMapping("/censusAllTotal")
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "统计所有数量")
+	public R<IndexCensusDto> censusAllTotal(){
+		return R.data(indexCensusService.censusTotalCount(false));
+	}
+
+	/**
+	 * 统计今天数量
+	 */
+	@GetMapping("/censusTodayTotal")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "统计今日数量")
+	public R<IndexCensusDto> censusTodayTotal(){
+		return R.data(indexCensusService.censusTotalCount(true));
+	}
+}

+ 26 - 0
src/main/java/org/springblade/gateway/common_gateway/dto/IndexCensusDto.java

@@ -0,0 +1,26 @@
+package org.springblade.gateway.common_gateway.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Builder;
+import lombok.Data;
+
+/**
+ * @Author: Silent
+ * @Description
+ * @Date: Created in 16:32 2021/11/19
+ * @Modified By:
+ */
+@Data
+@Builder
+@ApiModel("首页数据统计")
+public class IndexCensusDto {
+	@ApiModelProperty("用户总数")
+	private Integer userCount;
+
+	@ApiModelProperty("活动总数")
+	private Integer activeCount;
+
+	@ApiModelProperty("作品总数")
+	private Integer activeProductCount;
+}

+ 13 - 0
src/main/java/org/springblade/gateway/common_gateway/service/IndexCensusService.java

@@ -0,0 +1,13 @@
+package org.springblade.gateway.common_gateway.service;
+
+import org.springblade.gateway.common_gateway.dto.IndexCensusDto;
+
+/**
+ * @Author: Silent
+ * @Description
+ * @Date: Created in 16:21 2021/11/19
+ * @Modified By:
+ */
+public interface IndexCensusService {
+	IndexCensusDto censusTotalCount(boolean today);
+}

+ 60 - 0
src/main/java/org/springblade/gateway/common_gateway/service/impl/IndexCensusServiceImpl.java

@@ -0,0 +1,60 @@
+package org.springblade.gateway.common_gateway.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.springblade.common.utils.BeanPropertyUtil;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.gateway.common_gateway.dto.IndexCensusDto;
+import org.springblade.gateway.common_gateway.service.IndexCensusService;
+import org.springblade.sing.active.entity.ActiveProductRecord;
+import org.springblade.sing.active.entity.ActiveRecord;
+import org.springblade.sing.active.service.IActiveProductRecordService;
+import org.springblade.sing.active.service.IActiveRecordService;
+import org.springblade.sing.point.entity.PointRecord;
+import org.springblade.sing.user.entity.LoginUser;
+import org.springblade.sing.user.service.ILoginUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author: Silent
+ * @Description
+ * @Date: Created in 16:21 2021/11/19
+ * @Modified By:
+ */
+@Service
+public class IndexCensusServiceImpl implements IndexCensusService {
+	@Autowired
+	private IActiveRecordService activeRecordService;
+
+	@Autowired
+	private IActiveProductRecordService activeProductRecordService;
+
+	@Autowired
+	private ILoginUserService loginUserService;
+
+	/**
+	 * 统计平台各项数据总次数
+	 * @return
+	 */
+	@Override
+	public IndexCensusDto censusTotalCount(boolean today) {
+		//判断今日SQL语句
+		if(today){
+			String lastSQL = new StringBuilder("and date_format(")
+				.append(BeanPropertyUtil.getFieldNameToUnder(PointRecord::getCreateTime))
+				.append(",\"%Y-%m-%d\")=\"")
+				.append(DateUtil.format(DateUtil.now(), "yyyy-MM-dd").trim()).append("\"").toString();
+			return IndexCensusDto.builder()
+				.userCount(loginUserService.count(Wrappers.<LoginUser>lambdaQuery().last(lastSQL)))
+				.activeCount(activeRecordService.count(Wrappers.<ActiveRecord>lambdaQuery().last(lastSQL)))
+				.activeProductCount(activeProductRecordService.count(Wrappers.<ActiveProductRecord>lambdaQuery().last(lastSQL)))
+				.build();
+		}else{
+			return IndexCensusDto.builder()
+				.userCount(loginUserService.count())
+				.activeCount(activeRecordService.count())
+				.activeProductCount(activeProductRecordService.count())
+				.build();
+		}
+	}
+}