Răsfoiți Sursa

fix 订单导出

zoujiajian 1 an în urmă
părinte
comite
b8dd6aad70

+ 32 - 25
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelOrderDonData.java

@@ -20,12 +20,9 @@ import java.util.Date;
  */
 @Getter
 @Setter
-@SearchBean(tables = "order_don o left join goods_don_sku sku on o.sku_id = sku.id " +
-		"left join goods_don g on g.id = sku.goods_id " +
-		"left join user u on o.user_id = u.id " +
-		"left join groups_relation gr on gr.id = o.relation_id " +
-		"left join channel_popularize cp on o.popularize_id = cp.id " +
-		"left join channel c on c.id = cp.channel_id "
+@SearchBean(tables = "order_don o left join goods_don g on g.id = o.goods_id" +
+		" left join goods_don_sku sku on sku.id = o.sku_id",
+		where = ":condition:"
 )
 public class ExcelOrderDonData {
 
@@ -33,10 +30,6 @@ public class ExcelOrderDonData {
 	@ExcelIgnore
 	private Long id;
 
-	@DbField("c.id")
-	@ExcelIgnore
-	private Long channelId;
-
 	@DbField("o.relation_id")
 	@ExcelIgnore
 	private Long relationId;
@@ -53,7 +46,15 @@ public class ExcelOrderDonData {
 	@ExcelProperty("订单号")
 	private String orderNo;
 
-	@DbField("c.name")
+	@DbField("o.goods_id")
+	@ExcelIgnore
+	private Long goodsId;
+
+	@DbField("o.sku_id")
+	@ExcelIgnore
+	private Long skuId;
+
+	@DbIgnore
 	@ExcelProperty("渠道")
 	private String channel;
 
@@ -77,23 +78,23 @@ public class ExcelOrderDonData {
 	@ExcelProperty("金额")
 	private BigDecimal money;
 
-	@DbField("u.id")
+	@DbField("o.user_id")
 	@ExcelProperty("用户ID")
 	private Long userId;
 
-	@DbField("u.nickname")
+	@DbIgnore
 	@ExcelProperty("用户名")
 	private String nickname;
 
-	@DbField("case when u.login_phone != '' then 'phone' when u.email != '' then 'email' when u.open_id != '' then 'wechat' else 'wechat' end")
+	@DbIgnore
 	@ExcelIgnore
 	private String register;
 
-	@DbField("case when u.login_phone != '' then concat('手机号',login_phone) when u.email != '' then concat('邮箱',email) when u.open_id != '' then '微信授权' else '微信授权' end")
+	@DbIgnore
 	@ExcelProperty("注册方式")
 	private String registerStr;
 
-	@DbField("gr.account")
+	@DbField("select gr.account from groups_relation gr where gr.id = o.relation_id and gr.user_id = o.user_id limit 1")
 	@ExcelProperty("账号")
 	private String account;
 
@@ -120,10 +121,6 @@ public class ExcelOrderDonData {
 	@ExcelIgnore
 	private OrderDon.Type type;
 
-	@DbField("o.source")
-	@ExcelIgnore
-	private OrderDon.Source source;
-
 	@ExcelProperty("支付方式")
 	private String typeStr;
 
@@ -151,15 +148,25 @@ public class ExcelOrderDonData {
 	@ExcelIgnore
 	private Integer orderType;
 
-	@DbField("o.num")
-	@ExcelIgnore
-	private Integer num;
-
 	@DbField("o.coupon_user_id")
 	@ExcelIgnore
 	private Long couponUserId;
 
-	@DbField("cp.id")
+	@DbField("o.coupon_id")
+	@ExcelIgnore
+	private Long couponId;
+
+	@DbField("o.popularize_id")
 	@ExcelIgnore
 	private Long popularizeId;
+
+	public String getRegisterStr() {
+		if ("phone".equals(register)) {
+			return "手机号";
+		}
+		if ("email".equals(register)) {
+			return "邮箱";
+		}
+		return "微信授权";
+	}
 }

+ 113 - 27
netflix-web/src/main/java/com/cyksj/web/controller/manage/CmsOrderController.java

@@ -14,6 +14,7 @@ import com.cyksj.common.annotation.Log;
 import com.cyksj.common.annotation.NoSubmit;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.IoKit;
 import com.cyksj.common.util.Xmls;
 import com.cyksj.dto.Result;
@@ -48,6 +49,7 @@ import com.ejlchina.searcher.SearchResult;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
+import com.google.common.collect.Lists;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -61,6 +63,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -120,6 +124,7 @@ public class CmsOrderController {
 
 	private final ChatgptUserMapper chatgptUserMapper;
 
+	private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@GetMapping("/get")
 	@SaCheckPermission("order:view")
@@ -299,37 +304,72 @@ public class CmsOrderController {
 	@GetMapping("/export")
 	@SaCheckPermission("order:export")
 	@Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
-	public void exportOrders(HttpServletResponse response) {
-		List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, MapUtils.flatBuilder(request.getParameterMap()).build());
-		list.forEach(data -> {
-			data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
-			OrderDon.Type type = data.getType();
-			data.setTypeStr(type != null ? type.getDesc() : "");
-			OrderDon.Status status = data.getStatus();
-			data.setStatusStr(status != null ? status.getDesc() : "");
-			if (data.getChannelId() == null) {
-				data.setChannel("自然流量渠道");
+	public void exportOrders(HttpServletResponse response, Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle, Boolean isSubsidy, Boolean isRenewPackage) throws InterruptedException {
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
+		if (channelId != null) {
+			List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
+			builder.field(ExcelOrderDonData::getPopularizeId, popularizeIds).op(Operator.InList);
+		}
+		if (StrUtil.isNotBlank(account)) {
+			GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
+					.eq(GroupsRelation::getAccount, account).last("limit 1"));
+			if (relation != null) {
+				builder.field(ExcelOrderDonData::getRelationId, relation.getId());
+			} else {
+				builder.field(ExcelOrderDonData::getRelationId).op(Operator.IsNull);
 			}
-			if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
-				OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
-				if (transportView != null) {
-					data.setTransportStr(String.format("%s%s%s%s", transportView.getProvince(), transportView.getCity(), transportView.getDistrict(), transportView.getAddress()));
-					data.setPhone(transportView.getPhone());
-					data.setReceiver(transportView.getReceiver());
-					data.setCodeCn(transportView.getCodeCn());
-					data.setTrackingNumber(transportView.getTrackingNumber());
-				}
-				RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
-				if (realGoodsOrderHandle != null) {
-					data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
-					data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
+		}
+		if (StrUtil.isNotBlank(showId)) {
+			builder.field(ExcelOrderDonData::getUserId, userService.getUserIdByShowId(showId));
+		}
+		String conditionSql = StrUtil.EMPTY;
+		if (acId != null) {
+			conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
+		}
+		if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
+			if (StrUtil.isNotEmpty(conditionSql)) {
+				conditionSql += " and ";
+			}
+			conditionSql += " exists (select u.id from user u where u.id = o.user_id";
+			if (StrUtil.isNotEmpty(nickname)) {
+				conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
+			}
+			if (StrUtil.isNotEmpty(register)) {
+				if ("phone".equals(register)) {
+					conditionSql += " and u.login_phone != ''";
+				} else if ("email".equals(register)) {
+					conditionSql += " and u.email != ''";
+				} else if ("wechat".equals(register)) {
+					conditionSql += " and u.unionid != ''";
 				}
 			}
-			if (data.getCouponUserId() != 0) {
-				data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
-				data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney().divide(BigDecimal.valueOf(100)));
+			if (isGoogle != null && isGoogle) {
+				conditionSql += String.format(" and u.is_google is %s", isGoogle);
 			}
-		});
+			conditionSql += " limit 1)";
+		}
+		if (isSubsidy != null) {
+			if (StrUtil.isNotEmpty(conditionSql)) {
+				conditionSql += " and ";
+			}
+			conditionSql += " exists (select 1 from order_don_subsidy_relate ocr where ocr.order_id = o.id limit 1)";
+		}
+		if (isRenewPackage != null) {
+			if (StrUtil.isNotEmpty(conditionSql)) {
+				conditionSql += " and ";
+			}
+			conditionSql += " exists (select 1 from order_don_renew_record odrr1 where odrr1.order_id = o.id limit 1)";
+		}
+		if (StrUtil.isNotBlank(conditionSql)) {
+			builder.put("condition", conditionSql);
+		}
+		List<ExcelOrderDonData> list = beanSearcher.searchAll(ExcelOrderDonData.class, builder.build());
+		List<List<ExcelOrderDonData>> partition = Lists.partition(list, 500);
+		CountDownLatch countDownLatch = new CountDownLatch(partition.size());
+		for (List<ExcelOrderDonData> excelOrderDonData : partition) {
+			TASK_EXECUTOR.execute(() -> setExportOrderInfo(excelOrderDonData, countDownLatch));
+		}
+		countDownLatch.await(15, TimeUnit.MINUTES);
 		EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
 	}
 
@@ -1108,4 +1148,50 @@ public class CmsOrderController {
 		}
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
+
+	public void setExportOrderInfo(List<ExcelOrderDonData> datas, CountDownLatch countDownLatch) {
+		datas.forEach(data -> {
+			data.setMoney(data.getMoney().divide(BigDecimal.valueOf(100)));
+			OrderDon.Type type = data.getType();
+			data.setTypeStr(type != null ? type.getDesc() : "");
+			OrderDon.Status status = data.getStatus();
+			data.setStatusStr(status != null ? status.getDesc() : "");
+			data.setChannel("自然流量渠道");
+			if (data.getPopularizeId() != null) {
+				Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
+						.ifPresent(channelName -> data.setChannel(channelName));
+			}
+			User user = userMapper.selectById(data.getUserId());
+			if (user != null) {
+				data.setNickname(user.getNickname());
+				data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
+
+			}
+			if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
+				OrderDonTransportView transportView = beanSearcher.searchFirst(OrderDonTransportView.class, MapUtils.builder().field(OrderDonTransportView::getOrderId, data.getId()).build());
+				if (transportView != null) {
+					data.setTransportStr(String.format("%s%s%s%s", transportView.getProvince(), transportView.getCity(), transportView.getDistrict(), transportView.getAddress()));
+					data.setPhone(transportView.getPhone());
+					data.setReceiver(transportView.getReceiver());
+					data.setCodeCn(transportView.getCodeCn());
+					data.setTrackingNumber(transportView.getTrackingNumber());
+				}
+				RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
+				if (realGoodsOrderHandle != null) {
+					data.setBeforeServiceName(realGoodsOrderHandle.getBeforeServiceName());
+					data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
+				}
+			}
+			//使用优惠码
+			if (data.getCouponId() != null) {
+				Optional.ofNullable(couponMapper.selectById(data.getCouponId())).ifPresent(coupon -> data.setCouponName(coupon.getName()));
+				data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
+			}
+			if (data.getCouponUserId() != 0) {
+				data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
+				data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
+			}
+		});
+		countDownLatch.countDown();
+	}
 }