|
@@ -14,6 +14,7 @@ import com.cyksj.common.annotation.Log;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
|
|
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
import com.cyksj.common.util.IoKit;
|
|
import com.cyksj.common.util.IoKit;
|
|
|
import com.cyksj.common.util.Xmls;
|
|
import com.cyksj.common.util.Xmls;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
@@ -48,6 +49,7 @@ import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -61,6 +63,8 @@ import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -120,6 +124,7 @@ public class CmsOrderController {
|
|
|
|
|
|
|
|
private final ChatgptUserMapper chatgptUserMapper;
|
|
private final ChatgptUserMapper chatgptUserMapper;
|
|
|
|
|
|
|
|
|
|
+ private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
|
|
@GetMapping("/get")
|
|
@GetMapping("/get")
|
|
|
@SaCheckPermission("order:view")
|
|
@SaCheckPermission("order:view")
|
|
@@ -299,37 +304,72 @@ public class CmsOrderController {
|
|
|
@GetMapping("/export")
|
|
@GetMapping("/export")
|
|
|
@SaCheckPermission("order:export")
|
|
@SaCheckPermission("order:export")
|
|
|
@Log(module = "订单管理/导出订单", businessType = BusinessType.EXPORT, isSaveRequestData = true)
|
|
@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);
|
|
EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, ExcelOrderDonData.class, list, "订单列表", "订单列表", ExcelTypeEnum.XLSX, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1108,4 +1148,50 @@ public class CmsOrderController {
|
|
|
}
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
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();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|