瀏覽代碼

新增订单excel导出

赵冬冬 4 年之前
父節點
當前提交
86d92b1167

+ 20 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/controller/OmsOrderController.java

@@ -1,5 +1,7 @@
 package com.hwrj.cloud.admin.controller;
 
+import com.alibaba.excel.EasyExcel;
+import com.hwrj.cloud.admin.dao.excel.model.OmsOrderExcel;
 import com.hwrj.cloud.common.api.CommonPage;
 import com.hwrj.cloud.common.api.CommonResult;
 import com.hwrj.cloud.admin.dto.*;
@@ -11,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
+import java.net.URLEncoder;
 import java.util.List;
 
 /**
@@ -34,6 +38,22 @@ public class OmsOrderController {
         return CommonResult.success(CommonPage.restPage(orderList));
     }
 
+    @ApiOperation("查询订单")
+    @RequestMapping(value = "/list/excel", method = RequestMethod.GET)
+    public void listExcel(HttpServletResponse response,OmsOrderQueryParam queryParam) throws Exception{
+        List<OmsOrderExcel> orderList = orderService.listExcel(queryParam);
+
+        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
+        String fileName = URLEncoder.encode("测试", "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+        EasyExcel.write(response.getOutputStream(), OmsOrderExcel.class).sheet("模板").doWrite(orderList);
+    }
+
+
+
     @ApiOperation("批量发货")
     @RequestMapping(value = "/update/delivery", method = RequestMethod.POST)
     @ResponseBody

+ 52 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/excel/enumbo/ConfirmStatus.java

@@ -0,0 +1,52 @@
+package com.hwrj.cloud.admin.dao.excel.enumbo;
+
+public enum ConfirmStatus {
+    NOT_CONFIRMED(0, "未确认"),
+    CONFIRMED(1, "已确认"),
+    DEFAULT(99, "未知");
+
+    private Integer key;
+
+    private String name;
+
+    /**
+     * @param key
+     * @param name
+     */
+    ConfirmStatus(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    /**
+     * @return Returns the key.
+     */
+    public Integer getKey() {
+        return key;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * 根据Key得到枚举的Value
+     * 普通for循环遍历,比较判断
+     *
+     * @param key
+     * @return
+     */
+    public static ConfirmStatus getEnumType(Integer key) {
+        ConfirmStatus[] alarmGrades = ConfirmStatus.values();
+        for (int i = 0; i < alarmGrades.length; i++) {
+            if (alarmGrades[i].getKey().equals(key)) {
+                return alarmGrades[i];
+            }
+        }
+        return ConfirmStatus.DEFAULT;
+    }
+}

+ 53 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/excel/enumbo/OrderType.java

@@ -0,0 +1,53 @@
+package com.hwrj.cloud.admin.dao.excel.enumbo;
+
+public enum OrderType {
+
+    NORMAL_ORDER(0, "正常订单"),
+    SECKILL_ORDER(1, "秒杀订单"),
+    DEFAULT(99, "未知");
+
+    private Integer key;
+
+    private String name;
+
+    /**
+     * @param key
+     * @param name
+     */
+    OrderType(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    /**
+     * @return Returns the key.
+     */
+    public Integer getKey() {
+        return key;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * 根据Key得到枚举的Value
+     * 普通for循环遍历,比较判断
+     *
+     * @param key
+     * @return
+     */
+    public static OrderType getEnumType(Integer key) {
+        OrderType[] alarmGrades = OrderType.values();
+        for (int i = 0; i < alarmGrades.length; i++) {
+            if (alarmGrades[i].getKey().equals(key)) {
+                return alarmGrades[i];
+            }
+        }
+        return OrderType.DEFAULT;
+    }
+}

+ 55 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/excel/enumbo/PayType.java

@@ -0,0 +1,55 @@
+package com.hwrj.cloud.admin.dao.excel.enumbo;
+
+public enum PayType {
+
+
+    UNPAID(0, "未支付"),
+    ALIPAY(1, "支付宝"),
+    WECHAT(2, "微信"),
+    DEFAULT(99, "未知");
+
+    private Integer key;
+
+    private String name;
+
+    /**
+     * @param key
+     * @param name
+     */
+    PayType(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    /**
+     * @return Returns the key.
+     */
+    public Integer getKey() {
+        return key;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * 根据Key得到枚举的Value
+     * 普通for循环遍历,比较判断
+     *
+     * @param key
+     * @return
+     */
+    public static PayType getEnumType(Integer key) {
+        PayType[] alarmGrades = PayType.values();
+        for (int i = 0; i < alarmGrades.length; i++) {
+            if (alarmGrades[i].getKey().equals(key)) {
+                return alarmGrades[i];
+            }
+        }
+        return PayType.DEFAULT;
+    }
+}

+ 52 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/excel/enumbo/SourceType.java

@@ -0,0 +1,52 @@
+package com.hwrj.cloud.admin.dao.excel.enumbo;
+
+public enum SourceType {
+
+    APP(1, "app订单"),
+    PC(0, "PC订单");
+
+    private Integer key;
+
+    private String name;
+
+    /**
+     * @param key
+     * @param name
+     */
+    SourceType(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    /**
+     * @return Returns the key.
+     */
+    public Integer getKey() {
+        return key;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * 根据Key得到枚举的Value
+     * 普通for循环遍历,比较判断
+     *
+     * @param key
+     * @return
+     */
+    public static SourceType getEnumType(Integer key) {
+        SourceType[] alarmGrades = SourceType.values();
+        for (int i = 0; i < alarmGrades.length; i++) {
+            if (alarmGrades[i].getKey().equals(key)) {
+                return alarmGrades[i];
+            }
+        }
+        return SourceType.PC;
+    }
+}

+ 57 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/excel/enumbo/Status.java

@@ -0,0 +1,57 @@
+package com.hwrj.cloud.admin.dao.excel.enumbo;
+
+public enum Status {
+
+    TO_BE_PAID(0, "待付款"),
+    TO_BE_DELIVERED(1, "待发货"),
+    DELIVERED(2, "已发货"),
+    COMPLETED(3, "已完成"),
+    CLOSED(4, "已关闭"),
+    INVALID_ORDER(5, "无效订单"),
+    DEFAULT(99, "未知");
+
+    private Integer key;
+
+    private String name;
+
+    /**
+     * @param key
+     * @param name
+     */
+    Status(Integer key, String name) {
+        this.key = key;
+        this.name = name;
+    }
+
+    /**
+     * @return Returns the key.
+     */
+    public Integer getKey() {
+        return key;
+    }
+
+    /**
+     * @return Returns the name.
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * 根据Key得到枚举的Value
+     * 普通for循环遍历,比较判断
+     *
+     * @param key
+     * @return
+     */
+    public static Status getEnumType(Integer key) {
+        Status[] alarmGrades = Status.values();
+        for (int i = 0; i < alarmGrades.length; i++) {
+            if (alarmGrades[i].getKey().equals(key)) {
+                return alarmGrades[i];
+            }
+        }
+        return Status.DEFAULT;
+    }
+}

+ 178 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/dao/excel/model/OmsOrderExcel.java

@@ -0,0 +1,178 @@
+package com.hwrj.cloud.admin.dao.excel.model;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@ApiModel("订单excel导出实体")
+public class OmsOrderExcel {
+
+    @ApiModelProperty(value = "订单编号")
+    @ExcelProperty(value = {"订单编号"})
+    private String orderSn;
+
+    @ApiModelProperty(value = "提交时间")
+    @ExcelProperty(value = {"提交时间"})
+    private Date createTime;
+
+    @ApiModelProperty(value = "用户帐号")
+    @ExcelProperty(value = {"用户帐号"})
+    private String memberUsername;
+
+    @ApiModelProperty(value = "订单总金额")
+    @ExcelProperty(value = {"订单总金额"})
+    private BigDecimal totalAmount;
+
+    @ApiModelProperty(value = "应付金额(实际支付金额)")
+    @ExcelProperty(value = {"应付金额(实际支付金额)"})
+    private BigDecimal payAmount;
+
+//    @ApiModelProperty(value = "运费金额")
+//    @ExcelProperty(value = {"运费金额"})
+//    private BigDecimal freightAmount;
+//
+//    @ApiModelProperty(value = "促销优化金额(促销价、满减、阶梯价)")
+//    @ExcelProperty(value = {"促销优化金额(促销价、满减、阶梯价)"})
+//    private BigDecimal promotionAmount;
+//
+//    @ApiModelProperty(value = "积分抵扣金额")
+//    @ExcelProperty(value = {"积分抵扣金额"})
+//    private BigDecimal integrationAmount;
+//
+//    @ApiModelProperty(value = "优惠券抵扣金额")
+//    @ExcelProperty(value = {"优惠券抵扣金额"})
+//    private BigDecimal couponAmount;
+//
+//    @ApiModelProperty(value = "管理员后台调整订单使用的折扣金额")
+//    @ExcelProperty(value = {"管理员后台调整订单使用的折扣金额"})
+//    private BigDecimal discountAmount;
+
+    @ApiModelProperty(value = "支付方式:0->未支付;1->支付宝;2->微信")
+    @ExcelProperty(value = {"支付方式"})
+    private String payType;
+
+    @ApiModelProperty(value = "订单来源:0->PC订单;1->app订单")
+    @ExcelProperty(value = {"订单来源"})
+    private String sourceType;
+
+    @ApiModelProperty(value = "订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单")
+    @ExcelProperty(value = {"订单状态"})
+    private String status;
+
+    @ApiModelProperty(value = "订单类型:0->正常订单;1->秒杀订单")
+    @ExcelProperty(value = {"订单类型"})
+    private String orderType;
+
+    @ApiModelProperty(value = "物流公司(配送方式)")
+    @ExcelProperty(value = {"物流公司(配送方式)"})
+    private String deliveryCompany;
+
+    @ApiModelProperty(value = "物流单号")
+    @ExcelProperty(value = {"物流单号"})
+    private String deliverySn;
+
+//    @ApiModelProperty(value = "自动确认时间(天)")
+//    @ExcelProperty(value = {"自动确认时间(天)"})
+//    private Integer autoConfirmDay;
+//
+//    @ApiModelProperty(value = "可以获得的积分")
+//    @ExcelProperty(value = {"可以获得的积分"})
+//    private Integer integration;
+//
+//    @ApiModelProperty(value = "可以活动的成长值")
+//    @ExcelProperty(value = {"可以活动的成长值"})
+//    private Integer growth;
+//
+//    @ApiModelProperty(value = "活动信息")
+//    @ExcelProperty(value = {"活动信息"})
+//    private String promotionInfo;
+
+//    @ApiModelProperty(value = "发票类型:0->不开发票;1->电子发票;2->纸质发票")
+//    @ExcelProperty(value = {"发票类型:0->不开发票;1->电子发票;2->纸质发票"})
+//    private Integer billType;
+
+//    @ApiModelProperty(value = "发票抬头")
+//    @ExcelProperty(value = {"发票抬头"})
+//    private String billHeader;
+//
+//    @ApiModelProperty(value = "发票内容")
+//    @ExcelProperty(value = {"发票内容"})
+//    private String billContent;
+
+//    @ApiModelProperty(value = "收票人电话")
+//    @ExcelProperty(value = {"收票人电话"})
+//    private String billReceiverPhone;
+//
+//    @ApiModelProperty(value = "收票人邮箱")
+//    @ExcelProperty(value = {"收票人邮箱"})
+//    private String billReceiverEmail;
+
+    @ApiModelProperty(value = "收货人姓名")
+    @ExcelProperty(value = {"收货人姓名"})
+    private String receiverName;
+
+    @ApiModelProperty(value = "收货人电话")
+    @ExcelProperty(value = {"收货人电话"})
+    private String receiverPhone;
+
+    @ApiModelProperty(value = "收货人邮编")
+    @ExcelProperty(value = {"收货人邮编"})
+    private String receiverPostCode;
+
+    @ApiModelProperty(value = "省份/直辖市")
+    @ExcelProperty(value = {"省份/直辖市"})
+    private String receiverProvince;
+
+    @ApiModelProperty(value = "城市")
+    @ExcelProperty(value = {"城市"})
+    private String receiverCity;
+
+    @ApiModelProperty(value = "区")
+    @ExcelProperty(value = {"区"})
+    private String receiverRegion;
+
+    @ApiModelProperty(value = "详细地址")
+    @ExcelProperty(value = {"详细地址"})
+    private String receiverDetailAddress;
+
+    @ApiModelProperty(value = "订单备注")
+    @ExcelProperty(value = {"订单备注"})
+    private String note;
+
+    @ApiModelProperty(value = "确认收货状态:0->未确认;1->已确认")
+    @ExcelProperty(value = {"确认收货状态"})
+    private Integer confirmStatus;
+
+//    @ApiModelProperty(value = "删除状态:0->未删除;1->已删除")
+//    @ExcelProperty(value = {"删除状态:0->未删除;1->已删除"})
+//    private Integer deleteStatus;
+
+//    @ApiModelProperty(value = "下单时使用的积分")
+//    @ExcelProperty(value = {"下单时使用的积分"})
+//    private Integer useIntegration;
+
+    @ApiModelProperty(value = "支付时间")
+    @ExcelProperty(value = {"支付时间"})
+    private Date paymentTime;
+
+    @ApiModelProperty(value = "发货时间")
+    @ExcelProperty(value = {"发货时间"})
+    private Date deliveryTime;
+
+    @ApiModelProperty(value = "确认收货时间")
+    @ExcelProperty(value = {"确认收货时间"})
+    private Date receiveTime;
+
+//    @ApiModelProperty(value = "评价时间")
+//    @ExcelProperty(value = {"评价时间"})
+//    private Date commentTime;
+//
+//    @ApiModelProperty(value = "修改时间")
+//    @ExcelProperty(value = {"修改时间"})
+//    private Date modifyTime;
+}

+ 3 - 0
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/service/OmsOrderService.java

@@ -1,5 +1,6 @@
 package com.hwrj.cloud.admin.service;
 
+import com.hwrj.cloud.admin.dao.excel.model.OmsOrderExcel;
 import com.hwrj.cloud.admin.dto.*;
 import com.hwrj.cloud.admin.model.OmsOrder;
 import org.springframework.transaction.annotation.Transactional;
@@ -55,4 +56,6 @@ public interface OmsOrderService {
      */
     @Transactional
     int updateNote(Long id, String note, Integer status);
+
+    List<OmsOrderExcel> listExcel(OmsOrderQueryParam queryParam);
 }

+ 38 - 2
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/service/impl/OmsOrderServiceImpl.java

@@ -3,6 +3,8 @@ package com.hwrj.cloud.admin.service.impl;
 import com.github.pagehelper.PageHelper;
 import com.hwrj.cloud.admin.dao.OmsOrderDao;
 import com.hwrj.cloud.admin.dao.OmsOrderOperateHistoryDao;
+import com.hwrj.cloud.admin.dao.excel.enumbo.*;
+import com.hwrj.cloud.admin.dao.excel.model.OmsOrderExcel;
 import com.hwrj.cloud.admin.dto.*;
 import com.hwrj.cloud.admin.mapper.OmsOrderMapper;
 import com.hwrj.cloud.admin.mapper.OmsOrderOperateHistoryMapper;
@@ -10,6 +12,7 @@ import com.hwrj.cloud.admin.model.OmsOrder;
 import com.hwrj.cloud.admin.model.OmsOrderExample;
 import com.hwrj.cloud.admin.model.OmsOrderOperateHistory;
 import com.hwrj.cloud.admin.service.OmsOrderService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -70,7 +73,7 @@ public class OmsOrderServiceImpl implements OmsOrderService {
             history.setCreateTime(new Date());
             history.setOperateMan("后台管理员");
             history.setOrderStatus(4);
-            history.setNote("订单关闭:"+note);
+            history.setNote("订单关闭:" + note);
             return history;
         }).collect(Collectors.toList());
         orderOperateHistoryDao.insertList(historyList);
@@ -146,8 +149,41 @@ public class OmsOrderServiceImpl implements OmsOrderService {
         history.setCreateTime(new Date());
         history.setOperateMan("后台管理员");
         history.setOrderStatus(status);
-        history.setNote("修改备注信息:"+note);
+        history.setNote("修改备注信息:" + note);
         orderOperateHistoryMapper.insert(history);
         return count;
     }
+
+    @Override
+    public List<OmsOrderExcel> listExcel(OmsOrderQueryParam queryParam) {
+        List<OmsOrder> list = orderDao.getList(queryParam);
+        List<OmsOrderExcel> collect = list.stream().map(x -> {
+            OmsOrderExcel omsOrderExcel = new OmsOrderExcel();
+            BeanUtils.copyProperties(x, omsOrderExcel);
+            //支付方式
+            Integer payType = x.getPayType();
+            String payTypeName = PayType.getEnumType(payType).getName();
+            omsOrderExcel.setPayType(payTypeName);
+            //订单来源
+            Integer sourceType = x.getSourceType();
+            String sourceeName = SourceType.getEnumType(sourceType).getName();
+            omsOrderExcel.setSourceType(sourceeName);
+
+            //设置订单状态
+            Integer status = x.getStatus();
+            String statusName = Status.getEnumType(status).getName();
+            omsOrderExcel.setStatus(statusName);
+
+            //订单类型
+            Integer orderType = x.getOrderType();
+            String orderTypeName = OrderType.getEnumType(orderType).getName();
+            omsOrderExcel.setOrderType(orderTypeName);
+            //确认收货状态
+            Integer confirmStatus = x.getConfirmStatus();
+            String confirmStatusName = ConfirmStatus.getEnumType(confirmStatus).getName();
+            omsOrderExcel.setConfirmStatus(confirmStatus);
+            return omsOrderExcel;
+        }).collect(Collectors.toList());
+        return collect;
+    }
 }