Просмотр исходного кода

导出客服每月订单数据统计

zoujiajian 3 лет назад
Родитель
Сommit
6e19e4e78e

+ 15 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/OrderDon.java

@@ -1,5 +1,6 @@
 package com.cyksj.model.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import lombok.*;
 
@@ -111,6 +112,7 @@ public class OrderDon extends BaseEntity implements Serializable {
      * 订单标注来源
      * 用于客服标注订单来源
      */
+    @TableField(updateStrategy = FieldStrategy.IGNORED)
     private String labelSource;
 
     /**
@@ -249,4 +251,17 @@ public class OrderDon extends BaseEntity implements Serializable {
             this.desc = desc;
         }
     }
+
+    @Getter
+    public enum LabelSource {
+        red_book("小红书"),
+        guang_dian("广点通"),
+        tik_tok("抖音付费"),
+        ;
+        String desc;
+
+        LabelSource(String desc) {
+            this.desc = desc;
+        }
+    }
 }

+ 2 - 4
netflix-dao/src/main/java/com/cyksj/model/entity/RealGoodsOrderHandle.java

@@ -1,9 +1,6 @@
 package com.cyksj.model.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldFill;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.*;
 import com.ejlchina.searcher.bean.DbField;
 import com.ejlchina.searcher.bean.SearchBean;
 import lombok.Getter;
@@ -66,6 +63,7 @@ public class RealGoodsOrderHandle{
 	 * 用于客服标注订单来源
 	 */
 	@DbField("rh.label_source")
+	@TableField(updateStrategy = FieldStrategy.IGNORED)
 	private String labelSource;
 
 	/**

+ 93 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelServiceMonthStatisticsData.java

@@ -0,0 +1,93 @@
+package com.cyksj.model.excel;
+
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.cyksj.model.entity.OrderDon;
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/*
+ *项目名: netflix
+ *文件名: ExcelServiceMonthStatisticsData
+ *创建者: JavaZou
+ *创建时间:2023/7/11 10:37
+ */
+@Getter
+@Setter
+@SearchBean(tables = "real_goods_order_handle rh left join order_don od on od.id = rh.order_id" +
+		" left join goods_don_sku gdk on gdk.id = od.sku_id" +
+		" left join goods_don gd on gd.id = gdk.goods_id" +
+		" left join user u on u.id = od.user_id")
+public class ExcelServiceMonthStatisticsData {
+
+	@DbField("gd.title")
+	@ExcelProperty("商品名称")
+	private String goodsName;
+
+	@DbField("gdk.id")
+	@ExcelIgnore
+	private Long skuId;
+
+	@DbField("gdk.spec_val")
+	@ExcelProperty("规格")
+	private String specVal;
+
+	@DbField("cast(od.money/100 as decimal(10,2))")
+	@ExcelProperty("金额")
+	private BigDecimal money;
+
+	@DbField("u.nickname")
+	@ExcelProperty("用户名")
+	private String nickname;
+
+	@DbField("u.id")
+	@ExcelProperty("用户ID")
+	private Long userId;
+
+	@DbField("od.status")
+	@ExcelIgnore
+	private OrderDon.Status status;
+
+	/**
+	 * 订单标注来源
+	 * 用于客服标注订单来源
+	 */
+	@DbField("rh.label_source")
+	@ExcelIgnore
+	private String labelSource;
+
+	@DbIgnore
+	@ExcelProperty("订单来源")
+	private String labelSourceStr;
+
+	@DbField("od.created_time")
+	@ExcelProperty("日期")
+	private Date createdTime;
+
+	@DbField("rh.before_service_name")
+	@ExcelIgnore
+	private String beforeServiceName;
+
+	@DbField("rh.after_service_name")
+	@ExcelIgnore
+	private String afterServiceName;
+
+	@DbField("rh.created_time")
+	@ExcelIgnore
+	private Date recordCreatedTime;
+
+	public String getLabelSourceStr() {
+		if (StrUtil.isEmpty(labelSource)) {
+			return null;
+		}
+		OrderDon.LabelSource labelSource = OrderDon.LabelSource.valueOf(this.labelSource);
+		return labelSource.getDesc();
+	}
+}

+ 15 - 1
netflix-dao/src/main/java/com/cyksj/model/views/ServiceOrdersDetailView.java

@@ -1,11 +1,13 @@
 package com.cyksj.model.views;
 
+import com.alibaba.excel.annotation.ExcelIgnore;
 import com.cyksj.model.entity.OrderDon;
 import com.ejlchina.searcher.bean.DbField;
 import com.ejlchina.searcher.bean.SearchBean;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 /*
@@ -22,6 +24,7 @@ import java.util.Date;
 		" left join user u on u.id = od.user_id")
 public class ServiceOrdersDetailView {
 	@DbField("gd.id")
+	@ExcelIgnore
 	private Long goodsId;
 
 	@DbField("gd.title")
@@ -34,7 +37,7 @@ public class ServiceOrdersDetailView {
 	private String specVal;
 
 	@DbField("od.money")
-	private Long money;
+	private BigDecimal money;
 
 	@DbField("u.nickname")
 	private String nickname;
@@ -43,17 +46,28 @@ public class ServiceOrdersDetailView {
 	private Long userId;
 
 	@DbField("od.status")
+	@ExcelIgnore
 	private OrderDon.Status status;
 
+	/**
+	 * 订单标注来源
+	 * 用于客服标注订单来源
+	 */
+	@DbField("rh.label_source")
+	private String labelSource;
+
 	@DbField("od.created_time")
 	private Date createdTime;
 
 	@DbField("rh.before_service_name")
+	@ExcelIgnore
 	private String beforeServiceName;
 
 	@DbField("rh.after_service_name")
+	@ExcelIgnore
 	private String afterServiceName;
 
 	@DbField("rh.created_time")
+	@ExcelIgnore
 	private Date recordCreatedTime;
 }

+ 1 - 10
netflix-service/src/main/java/com/cyksj/task/OrderCustomerHandleScheduler.java

@@ -13,7 +13,6 @@ import com.cyksj.model.entity.StatisticsCustomerServiceEveryMonth;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapUtils;
-import com.google.common.util.concurrent.AtomicDouble;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -81,15 +80,7 @@ public class OrderCustomerHandleScheduler {
 			record.setType(type);
 			record.setCustomerServiceName(serviceName);
 			record.setStatisticsId(statisticsId);
-			AtomicDouble numOfOrder = new AtomicDouble(0);
-			handlers.forEach(handler -> {
-				if ("red_book".equals(handler.getLabelSource())) {
-					numOfOrder.addAndGet(1.5);
-					return;
-				}
-				numOfOrder.addAndGet(1);
-			});
-			record.setNumOfOrder(BigDecimal.valueOf(numOfOrder.doubleValue()));
+			record.setNumOfOrder(BigDecimal.valueOf(handlers.size()));
 			Optional<BigDecimal> money = handlers.stream().map(RealGoodsOrderHandle::getMoney).reduce(BigDecimal::add);
 			record.setMoney(money.isPresent() ? money.get() : BigDecimal.ZERO);
 			detailMapper.insert(record);

+ 0 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/CmsOrderController.java

@@ -457,7 +457,6 @@ public class CmsOrderController {
 	public Result<String> updateOrderSource(@RequestBody OrderDon orderDon) {
 		Long id = orderDon.getId();
 		String labelSource = orderDon.getLabelSource();
-		if (labelSource == null) labelSource = StrUtil.EMPTY;
 		cmsOrderDonService.update(null, Wrappers.lambdaUpdate(OrderDon.class)
 				.set(OrderDon::getLabelSource, labelSource)
 				.eq(OrderDon::getId, id));

+ 26 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/statistics/StatisticsDataController.java

@@ -26,6 +26,7 @@ import com.cyksj.mapper.manage.statistics.StatisticsUserDataMapper;
 import com.cyksj.mapper.stock.GoodsDonStockRecordMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.excel.ExcelAccountData;
+import com.cyksj.model.excel.ExcelServiceMonthStatisticsData;
 import com.cyksj.model.excel.ExcelSheetAndData;
 import com.cyksj.model.request.BatchServiceReq;
 import com.cyksj.model.request.RedBookReq;
@@ -295,6 +296,31 @@ public class StatisticsDataController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult(view);
 	}
 
+	/**
+	 * 导出客服每月订单数据统计
+	 */
+	@GetMapping("/export/service/orders")
+	public void exportServiceMonthStatisticsData(Integer type, String monthDate, String customerService, HttpServletRequest request, HttpServletResponse response) {
+		DateTime month = null;
+		if (StrUtil.isEmpty(monthDate)) {
+			month = DateTime.now();
+		} else {
+			month = DateUtil.parse(monthDate, "yyyy-MM-dd");
+		}
+		DateTime beginOfMonth = DateUtil.beginOfMonth(month);
+		DateTime endOfMonth = DateUtil.endOfMonth(month);
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap())
+				.field(ExcelServiceMonthStatisticsData::getRecordCreatedTime, beginOfMonth, endOfMonth).op(Operator.Between);
+		if (type == 1) {
+			builder.field(ExcelServiceMonthStatisticsData::getBeforeServiceName, customerService).op(Operator.Equal);
+		} else if (type == 2) {
+			builder.field(ExcelServiceMonthStatisticsData::getAfterServiceName, customerService).op(Operator.Equal);
+		}
+		builder.field(ExcelServiceMonthStatisticsData::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn);
+		List<ExcelServiceMonthStatisticsData> excelServiceMonthStatisticsData = beanSearcher.searchAll(ExcelServiceMonthStatisticsData.class, builder.build());
+		EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelServiceMonthStatisticsData.class, excelServiceMonthStatisticsData, "客服每月订单数据统计", "客服每月订单数据统计", ExcelTypeEnum.XLSX, null);
+	}
+
 	@GetMapping("/get/stock")
 	public Result<List<StatisticsStockView>> getStock(HttpServletRequest request, @RequestParam(defaultValue = "0") Long startTime,@RequestParam(defaultValue = "0") Long endTime){
 		List<GoodsDonStock> goodsDonStocks = beanSearcher.searchAll(GoodsDonStock.class, MapUtils.flatBuilder(request.getParameterMap()).build());