qin il y a 1 an
Parent
commit
0af943293a

+ 30 - 1
src/main/java/com/poteviohealth/cgp/statistics/controller/OrderController.java

@@ -10,14 +10,15 @@ import com.poteviohealth.cgp.common.facade.lock.DistributedLock;
 import com.poteviohealth.cgp.common.facade.time.MethodTime;
 import com.poteviohealth.cgp.common.filter.TokenContext;
 import com.poteviohealth.cgp.common.filter.repeatSubmit.RepeatSubmit;
-import com.poteviohealth.cgp.statistics.utils.ExcelUtils2;
 import com.poteviohealth.cgp.statistics.model.indto.DishesOrderWebInDTO;
 import com.poteviohealth.cgp.statistics.model.indto.OrderCostWebInDTO;
 import com.poteviohealth.cgp.statistics.model.indto.OrderServiceWebInDTO;
+import com.poteviohealth.cgp.statistics.model.indto.OrderWebInDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
 import com.poteviohealth.cgp.statistics.service.IOrderService;
+import com.poteviohealth.cgp.statistics.utils.ExcelUtils2;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
@@ -142,6 +143,34 @@ public class OrderController extends BaseWebController {
         }
     }
 
+
+    @PostMapping(value = "/orderExport")
+    @ApiOperation(httpMethod = "POST", value = "订单Excel导出")
+    public void orderExport(HttpServletResponse resp,@RequestBody OrderWebInDTO orderWebInDTO){
+        String key ="orderExport";
+        String error =  this.checkExcelExport(key);
+        try{
+            if ("".equals(error)) {
+        String templateLocation = "classpath:excel/order.xlsx";
+        String filename = "";
+        Map<String, Object> data = Maps.newHashMap();
+        List<OrderExcelDTO> list = orderService.excelList(orderWebInDTO);
+        ExcelUtils2.easyDownload(templateLocation,data , list, filename, resp);
+            }else{
+                throw new BusinessException(error);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new BusinessException(e.getMessage());
+        }finally {
+            if(cacheService.exists(key)){
+                if(cacheService.get(key).equals(TokenContext.cureWebUser().getUserId().toString())){
+                    cacheService.del(key);
+                }
+            }
+        }
+    }
+
     @DistributedLock(fairLock =true)
     private String checkExcelExport(String key){
         String returnVal = "";

+ 74 - 0
src/main/java/com/poteviohealth/cgp/statistics/model/indto/OrderWebInDTO.java

@@ -0,0 +1,74 @@
+package com.poteviohealth.cgp.statistics.model.indto;
+
+import com.poteviohealth.cgp.common.model.PageQuery;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 订单列表查询入参
+ * @Author Qin
+ * @Date 2019/7/26 18:46
+ **/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="订单列表查询入参")
+public class OrderWebInDTO extends PageQuery {
+
+    @ApiModelProperty(value="搜索团长或驿站名称",example = "10")
+    private String stationOrGroup;
+
+    @ApiModelProperty(value="搜索订单code/商品名称",example = "10")
+    private String searchValueOrderCode;
+
+    @ApiModelProperty(value="用户名",example = "张三")
+    private String searchValueCustomerName;
+
+    @ApiModelProperty(value="收货人",example = "张三")
+    private String searchValueName;
+
+    @ApiModelProperty(value="联系电话",example = "18888888883")
+    private String searchValuePhone;
+
+    @ApiModelProperty(value="收货地址",example = "北京市..")
+    private String searchValueAddress;
+
+    @ApiModelProperty(value="配送地址",example = "1")
+    private String addressType;
+
+    @ApiModelProperty(value="订单类型",example = "订单类型:1.零售;2.团购")
+    private String orderStyle;
+
+    @ApiModelProperty(value="订单状态",example = "订单状态:1.待付款;2.待发货;3.待收货;4.待取货;5.已完成;6.已取消;7.拒收中")
+    private String orderStatus;
+
+    @ApiModelProperty(value="支付状态",example = "支付状态:1.待支付;2.支付中,3.已支付,4:支付失败,5:退款中,6:退款成功,7:退款失败")
+    private String payStatus;
+
+    @ApiModelProperty(value="支付方式",example = "支付类型:1.补贴支付;2.自费支付;3.混合支付")
+    private Integer payWay;
+
+    @ApiModelProperty(value="支付账户",example = "支付账户:1.微信;2.农商行;3.pos机;4.积分;5.账户;6.失能补贴支付金额;7.养老券支付金额;8.凤凰豆/积分支付金额;9.微孝付积分支付金额")
+    private List<String> payAccount;
+
+    @ApiModelProperty(value = "起始时间")
+    private Date startDate;
+
+    @ApiModelProperty(value = "结束时间")
+    private Date endDate;
+
+    @ApiModelProperty(value = "站点id")
+    private Integer stationId;
+
+    @ApiModelProperty(value = "运营商id")
+    private Integer supplierId;
+
+}

+ 8 - 0
src/main/java/com/poteviohealth/cgp/statistics/service/IOrderService.java

@@ -5,6 +5,7 @@ import com.poteviohealth.cgp.statistics.model.Order;
 import com.poteviohealth.cgp.statistics.model.indto.DishesOrderWebInDTO;
 import com.poteviohealth.cgp.statistics.model.indto.OrderCostWebInDTO;
 import com.poteviohealth.cgp.statistics.model.indto.OrderServiceWebInDTO;
+import com.poteviohealth.cgp.statistics.model.indto.OrderWebInDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.DishesOrderWebOutDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.OrderCostWebOutDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.OrderExcelDTO;
@@ -38,4 +39,11 @@ public interface IOrderService extends IBaseService<Order> {
 
     List<OrderCostWebOutDTO> OrderCostList(OrderCostWebInDTO orderCostWebInDTO);
 
+    /**
+     * excel导出
+     * @param orderWebInDTO
+     * @return
+     */
+    List<OrderExcelDTO> excelList(OrderWebInDTO orderWebInDTO);
+
 }

+ 121 - 0
src/main/java/com/poteviohealth/cgp/statistics/service/impl/OrderServiceImpl.java

@@ -28,6 +28,7 @@ import com.poteviohealth.cgp.statistics.model.Order;
 import com.poteviohealth.cgp.statistics.model.indto.DishesOrderWebInDTO;
 import com.poteviohealth.cgp.statistics.model.indto.OrderCostWebInDTO;
 import com.poteviohealth.cgp.statistics.model.indto.OrderServiceWebInDTO;
+import com.poteviohealth.cgp.statistics.model.indto.OrderWebInDTO;
 import com.poteviohealth.cgp.statistics.model.outdto.*;
 import com.poteviohealth.cgp.statistics.service.IOrderService;
 import lombok.extern.log4j.Log4j2;
@@ -246,6 +247,76 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
     }
 
 
+    @Override
+    public List<OrderExcelDTO> excelList(OrderWebInDTO dto) {
+        try {
+            Integer operatorId = TokenContext.cureOperatorId();
+            QueryWrapper<Order> queryWrapper = webOrderQuery(dto, "o.");
+            //int count;
+           /* if (null != dto.getProductIds()) {
+                queryWrapper.eq("od.product_id", dto.getProductIds());
+                count = baseMapper.orderPageListAllSize(queryWrapper,dbName,operatorId);
+            }else{*/
+            int  count = baseMapper.orderPageListSize(queryWrapper,dbName,operatorId);
+          //  }
+            //每页10000条,计算总页数
+            int maxPage = (int) Math.ceil(count/10000.0);
+            int start = 0;
+            LinkedList<OrderExcelDTO> list = Lists.newLinkedList();
+            for (int i = 0; i < maxPage; i++) {
+                LinkedList<OrderExcelDTO> findList = baseMapper.orderExcel(queryWrapper,dbName,operatorId,start);
+                start = findList.getLast().getId();
+                list.addAll(findList);
+            }
+
+            for (OrderExcelDTO orderExcelDTO : list) {
+                for (OrderConstantEnum.OrderStatus status : EnumUtils.getEnumList(OrderConstantEnum.OrderStatus.class)) {
+                    if (status.getCode().toString().equals(orderExcelDTO.getOrderStatus())) {
+                        orderExcelDTO.setOrderStatus(status.getDisplay());
+                        break;
+                    }
+                }
+
+                for (OrderConstantEnum.PayStyle status : EnumUtils.getEnumList(OrderConstantEnum.PayStyle.class)) {
+                    if (status.getCode().toString().equals(orderExcelDTO.getPayStyle())) {
+                        orderExcelDTO.setPayStyle(status.getDisplay());
+                        break;
+                    }
+                }
+
+                for (OrderConstantEnum.PayStatus status : EnumUtils.getEnumList(OrderConstantEnum.PayStatus.class)) {
+                    if (status.getCode().toString().equals(orderExcelDTO.getPayStatus())) {
+                        orderExcelDTO.setPayStatus(status.getDisplay());
+                        break;
+                    }
+                }
+
+                for (OrderConstantEnum.OrderStyle status : EnumUtils.getEnumList(OrderConstantEnum.OrderStyle.class)) {
+                    if (status.getCode().toString().equals(orderExcelDTO.getOrderStyle())) {
+                        orderExcelDTO.setOrderStyle(status.getDisplay());
+                        break;
+                    }
+                }
+                orderExcelDTO.setPayAccount(getPayAccountString(orderExcelDTO.getPayAccount()));
+                orderExcelDTO.setStationOrGroupName(StringUtils.isNotBlank(orderExcelDTO.getGroupLeaderName())?orderExcelDTO.getGroupLeaderName():orderExcelDTO.getServiceStationName());
+            }
+            //ForkJoinPool pool = new ForkJoinPool();
+
+           /* OrderExcelTask task = new OrderExcelTask(1,maxPage,queryWrapper, operatorId, dbName,baseMapper);
+            Future<List<OrderExcelDTO>> future = pool.submit(task);
+                do {
+                   pool.awaitTermination(1, TimeUnit.SECONDS);
+                } while (!future.isDone());
+                pool.shutdown();
+                list = future.get();*/
+            return list;
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new BuilderException("工单导出失败,请重新操作");
+        }
+    }
+
+
     private String getPayAccountString(String payAccount){
         StringBuilder sb = new StringBuilder();
         for (String s : payAccount.split(",")) {
@@ -388,6 +459,56 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
         return orderQueryWrapper;
     }
 
+    private QueryWrapper<Order> webOrderQuery(OrderWebInDTO orderWebInDTO, String prefix) {
+        QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
+        if (StringUtils.isNotBlank(orderWebInDTO.getSearchValuePhone())) {
+            orderQueryWrapper.eq(prefix + "phone", orderWebInDTO.getSearchValuePhone());
+        }
+        if (StringUtils.isNotBlank(orderWebInDTO.getSearchValueName())) {
+            orderQueryWrapper.like(prefix + "name", orderWebInDTO.getSearchValueName());
+        }
+        if (StringUtils.isNotBlank(orderWebInDTO.getSearchValueOrderCode())) {
+            orderQueryWrapper.eq(prefix + "sn", orderWebInDTO.getSearchValueOrderCode());
+        }
+        if (StringUtils.isNotBlank(orderWebInDTO.getOrderStatus())) {
+            orderQueryWrapper.eq(prefix + "order_status", orderWebInDTO.getOrderStatus());
+        }
+        if (StringUtils.isNotBlank(orderWebInDTO.getPayStatus())) {
+            orderQueryWrapper.eq(prefix + "pay_status", orderWebInDTO.getPayStatus());
+        }
+        if (orderWebInDTO.getPayWay() != null) {
+            orderQueryWrapper.eq(prefix + "pay_way", orderWebInDTO.getPayWay());
+        }
+        if (StringUtils.isNotBlank(orderWebInDTO.getOrderStyle())) {
+            orderQueryWrapper.eq(prefix + "order_style", orderWebInDTO.getOrderStyle());
+        }
+        if (orderWebInDTO.getStartDate() != null) {
+            orderQueryWrapper.ge(prefix + "order_time", orderWebInDTO.getStartDate());
+        }
+        if (orderWebInDTO.getEndDate() != null) {
+            orderQueryWrapper.le(prefix + "order_time", orderWebInDTO.getEndDate());
+        }
+
+        Integer stationId = TokenContext.curStationId();
+        Integer belong = TokenContext.wbBelong();
+        Integer supplierId = TokenContext.curSupplierId();
+        if(belong.equals(1)){
+            orderQueryWrapper.eq(prefix + "supplier_one_id", supplierId);
+        }else if(belong.equals(2)){
+            orderQueryWrapper.eq(stationId != null,prefix+"service_station_id",stationId);
+        }else{
+            orderQueryWrapper.eq(stationId != null,prefix+"station_id",stationId);
+            if (supplierId != null && !supplierId.equals(-1)) {
+                orderWebInDTO.setSupplierId(supplierId);
+            }else if(orderWebInDTO.getSupplierId() == null){
+                orderQueryWrapper.in(!TokenContext.supplierList().isEmpty(),prefix + "supplier_id",TokenContext.supplierList());
+            }
+            orderQueryWrapper.eq(orderWebInDTO.getSupplierId() != null,prefix + "supplier_id", orderWebInDTO.getSupplierId());
+        }
+        orderQueryWrapper.eq(prefix + "order_type", OrderConstantEnum.OrderType.PRODUCT.getCode());
+        return orderQueryWrapper;
+    }
+
 
     private QueryWrapper webQuery(DishesOrderWebInDTO orderWebInDTO) {
         QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();

+ 0 - 1
src/main/resources/mapper/statistics/OrderMapper.xml

@@ -220,7 +220,6 @@
             o.service_sku_name as serviceSkuName,
             o.service_num as serviceNum,
             TRUNCATE(IFNULL(o.sum_order_price,0)/100.0,2) as sumOrderPrice,
-            TRUNCATE(IFNULL(o.sum_coupon_price,0)/100.0,2) as sumCouponPrice,
             TRUNCATE(IFNULL(o.sum_price,0)/100.0,2) as sumPrice,
             o.pay_style as payStyle,
             o.reservation_time as reservationTime,