若依Excel导出

 

@RestController
@RequestMapping("/web/order/export")
public class OrderExportController extends BaseController
{
@GetMapping("/test")
public AjaxResult listExportTest()
{
List<OrderExport> list = buildList();
ExcelUtil<OrderExport> util = new ExcelUtil<>(OrderExport.class);
return util.exportExcel(list, "售后列表测试");
}


private List<OrderExport> buildList() {
List<OrderExport> list = new ArrayList<>();

for (int i = 1; i < 3; i++) {
OrderExport export1 = new OrderExport();
export1.setId(String.valueOf(i));
export1.setOrderType(String.valueOf(i));
export1.setOrderStatus(String.valueOf(i));
export1.setSex(String.valueOf(i));

SaleExport saleExport = new SaleExport();
saleExport.setSaleName("售后"+i);
saleExport.setSaleStatus(String.valueOf(i));

LogisticsExport logisticsExport = new LogisticsExport();
logisticsExport.setLogisticsName("物流"+i);
saleExport.setSec(logisticsExport);

export1.setSaleExport(saleExport);

list.add(export1);
}
return list;
}


}

 

package com.chdz.goods.domain.dto;

import com.chdz.common.annotation.Excel;
import com.chdz.common.annotation.Excels;
import com.chdz.common.utils.DictUtils;

/**
 * @Author: zcjie
 * @create: 2024-09-06 10:07
 * @Description:
 * @Version: 1.0
 */
public class OrderExport {

    @Excel(name = "订单id")
    private String id;
    @Excel(name = "订单状态", dictType = "order_status")
    private String orderStatus;
    @Excel(name = "下单类型", readConverterExp = "1=微信,2=支付宝")
    private String orderType;
    @Excel(name = "性别", readConverterExp = "1=男,2=女", combo = {"男", "女"})
    private String sex;
    @Excels(value = {
            @Excel(name = "售后名称1", targetAttr = "saleName"),
            @Excel(name = "售后状态1", targetAttr = "saleStatus", dictType = "order_after_sale_status"),
            @Excel(name = "物流名称", targetAttr = "sec.logisticsName")
    })
    private SaleExport saleExport;

    @Excel(name = "提示", prompt = "不能为空哟", type = Excel.Type.IMPORT)
    private String prompt;

    @Excel(name = "订单状态描述")
    private String orderStatusDesc;

    public String getOrderStatusDesc() {
        return DictUtils.getDictDesc("order_status", orderStatus);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public SaleExport getSaleExport() {
        return saleExport;
    }

    public void setSaleExport(SaleExport saleExport) {
        this.saleExport = saleExport;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getPrompt() {
        return prompt;
    }

    public void setPrompt(String prompt) {
        this.prompt = prompt;
    }
}

 

public class SaleExport {
    
    private String saleName;

    private String saleStatus;

    private LogisticsExport sec;
    
    public String getSaleName() {
        return saleName;
    }

    public void setSaleName(String saleName) {
        this.saleName = saleName;
    }

    public String getSaleStatus() {
        return saleStatus;
    }

    public void setSaleStatus(String saleStatus) {
        this.saleStatus = saleStatus;
    }

    public LogisticsExport getSec() {
        return sec;
    }

    public void setSec(LogisticsExport sec) {
        this.sec = sec;
    }
}

 

public class LogisticsExport {
    
    private String logisticsName;

    public String getLogisticsName() {
        return logisticsName;
    }

    public void setLogisticsName(String logisticsName) {
        this.logisticsName = logisticsName;
    }
}

 

posted @ 2024-09-06 17:54  真某人  阅读(31)  评论(0编辑  收藏  举报