Kaynağa Gözat

add 商务当月渠道以及历史渠道当月数据

zoujiajian 2 yıl önce
ebeveyn
işleme
db87015825

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/BusinessDistributesDataView.java

@@ -53,4 +53,10 @@ public class BusinessDistributesDataView {
 	 */
 	@DbField("count(distinct us.id)")
 	private Integer numOfNewUser;
+
+	/**
+	 * 1本月,2历史
+	 */
+	@DbField(":type:")
+	private Integer type;
 }

+ 74 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/distribute/DistributeController.java

@@ -3,6 +3,7 @@ package com.cyksj.web.controller.manage.distribute;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
@@ -46,6 +47,7 @@ import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
 
 /*
  *项目名: netflix
@@ -707,4 +709,76 @@ public class DistributeController {
 		UserDistributeViews userDistributeViews = userDistributeMapper.getApplyDetailByUserId(userId);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(userDistributeViews);
 	}
+
+	/**
+	 * 商务分销当月渠道商以及历史渠道商在当月的数据
+	 */
+	@GetMapping("/get/business/distribute/monthlyData")
+	public Result<List<BusinessDistributesDataView>> getBusinessMonthlyData(String firstMonthDate, String secondMonthDate) {
+		long adminId = StpUtil.getLoginIdAsLong();
+		if (StrUtil.isEmpty(firstMonthDate)) {
+			firstMonthDate = DateUtil.beginOfMonth(DateTime.now()).toDateStr();
+		}
+		if (StrUtil.isEmpty(secondMonthDate)) {
+			secondMonthDate = DateUtil.offsetMonth(DateUtil.beginOfMonth(DateTime.now()), 1).toDateStr();
+		}
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
+		//是否是商务人员
+		Boolean isBusiness = userBusinessRateService.isBusiness(adminId);
+		if (isBusiness) {
+			builder.field(BusinessDistributesDataView::getBusinessId, adminId);
+		}
+		//当月渠道本月数据
+		String time1Sql = StrUtil.EMPTY;
+		String time2Sql = StrUtil.EMPTY;
+		String time3Sql = StrUtil.EMPTY;
+		if (StrUtil.isNotBlank(firstMonthDate)) {
+			time1Sql += String.format(" and ud.business_bind_time >= '%s'", firstMonthDate);
+			time2Sql += String.format(" and us.created_time >= '%s'", firstMonthDate);
+			time3Sql += String.format(" and od.created_time >= '%s'", firstMonthDate);
+		}
+		if (StrUtil.isNotBlank(secondMonthDate)) {
+			time1Sql += String.format(" and ud.business_bind_time < '%s'", secondMonthDate);
+			time2Sql += String.format(" and us.created_time < '%s'", secondMonthDate);
+			time3Sql += String.format(" and od.created_time < '%s'", secondMonthDate);
+		}
+		if (StrUtil.isNotBlank(time1Sql)) {
+			builder.put("time1", time1Sql);
+		}
+		if (StrUtil.isNotBlank(time2Sql)) {
+			builder.put("time2", time2Sql);
+		}
+		if (StrUtil.isNotBlank(time3Sql)) {
+			builder.put("time3", time3Sql);
+		}
+		builder.put("type", 1);
+		List<BusinessDistributesDataView> search = beanSearcher.searchAll(BusinessDistributesDataView.class, builder.build());
+		//历史渠道 当月数据
+		time1Sql = StrUtil.EMPTY;
+		time2Sql = StrUtil.EMPTY;
+		time3Sql = StrUtil.EMPTY;
+		if (StrUtil.isNotBlank(firstMonthDate)) {
+			time1Sql += String.format(" and ud.business_bind_time < '%s'", firstMonthDate);
+			time2Sql += String.format(" and us.created_time >= '%s'", firstMonthDate);
+			time3Sql += String.format(" and od.created_time >= '%s'", firstMonthDate);
+		}
+		if (StrUtil.isNotBlank(secondMonthDate)) {
+			time2Sql += String.format(" and us.created_time < '%s'", secondMonthDate);
+			time3Sql += String.format(" and od.created_time < '%s'", secondMonthDate);
+		}
+		if (StrUtil.isNotBlank(time1Sql)) {
+			builder.put("time1", time1Sql);
+		}
+		if (StrUtil.isNotBlank(time2Sql)) {
+			builder.put("time2", time2Sql);
+		}
+		if (StrUtil.isNotBlank(time3Sql)) {
+			builder.put("time3", time3Sql);
+		}
+		builder.put("type", 2);
+		List<BusinessDistributesDataView> search2 = beanSearcher.searchAll(BusinessDistributesDataView.class, builder.build());
+		Collection<BusinessDistributesDataView> businessDistributesDataViews = CollUtil.addAll(search, search2);
+		List<BusinessDistributesDataView> collect = businessDistributesDataViews.stream().sorted(Comparator.comparing(BusinessDistributesDataView::getBusinessId).thenComparing(BusinessDistributesDataView::getType)).collect(Collectors.toList());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(collect);
+	}
 }