1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.ruoyi.sales.vo;
 
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import lombok.Data;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 销售台账导出对象(主从表格)。
 * <p>
 * 台账字段做纵向合并居中,右侧同行展开该台账下的产品明细,避免出现大片空白单元格。
 * products 必须是最后一个字段:无产品的台账不会输出产品列,若其后面还有字段会导致列错位。
 */
@Data
public class SalesLedgerExportVo {
 
    @Excel(name = "销售合同号", needMerge = true)
    private String salesContractNo;
 
    @Excel(name = "项目名称", needMerge = true)
    private String projectName;
 
    @Excel(name = "录入日期", width = 30, dateFormat = "yyyy-MM-dd", needMerge = true)
    private Date entryDate;
 
    @Excel(name = "业务员", needMerge = true)
    private String salesman;
 
    @Excel(name = "客户名称", needMerge = true)
    private String customerName;
 
    @Excel(name = "录入人", needMerge = true)
    private String entryPersonName;
 
    @Excel(name = "合同金额", scale = 2, needMerge = true)
    private BigDecimal contractAmount;
 
    @Excel(name = "备注", needMerge = true)
    private String remarks;
 
    @Excel(name = "产品明细")
    private List<Item> products = new ArrayList<>();
 
    @Data
    public static class Item {
 
        @Excel(name = "产品大类")
        private String productCategory;
 
        @Excel(name = "规格型号")
        private String specificationModel;
 
        @Excel(name = "单位")
        private String unit;
 
        @Excel(name = "数量", cellType = Excel.ColumnType.NUMERIC)
        private BigDecimal quantity;
 
        @Excel(name = "待发货数量", cellType = Excel.ColumnType.NUMERIC)
        private BigDecimal noQuantity;
 
        @Excel(name = "发货状态")
        private String shippingStatus;
 
        @Excel(name = "税率(%)", cellType = Excel.ColumnType.NUMERIC)
        private BigDecimal taxRate;
 
        @Excel(name = "含税单价(元)", scale = 2)
        private BigDecimal taxInclusiveUnitPrice;
 
        @Excel(name = "含税总价(元)", scale = 2)
        private BigDecimal taxInclusiveTotalPrice;
 
        @Excel(name = "不含税总价(元)", scale = 2)
        private BigDecimal taxExclusiveTotalPrice;
 
        public static Item fromProduct(SalesLedgerProduct product) {
            Item item = new Item();
            item.setProductCategory(product.getProductCategory());
            item.setSpecificationModel(product.getSpecificationModel());
            item.setUnit(product.getUnit());
            item.setQuantity(product.getQuantity());
            item.setNoQuantity(product.getNoQuantity());
            item.setShippingStatus(product.getShippingStatus());
            item.setTaxRate(product.getTaxRate());
            item.setTaxInclusiveUnitPrice(product.getTaxInclusiveUnitPrice());
            item.setTaxInclusiveTotalPrice(product.getTaxInclusiveTotalPrice());
            item.setTaxExclusiveTotalPrice(product.getTaxExclusiveTotalPrice());
            return item;
        }
    }
 
    public static SalesLedgerExportVo fromLedger(SalesLedger ledger) {
        SalesLedgerExportVo vo = new SalesLedgerExportVo();
        vo.setSalesContractNo(ledger.getSalesContractNo());
        vo.setProjectName(ledger.getProjectName());
        vo.setEntryDate(ledger.getEntryDate());
        vo.setSalesman(ledger.getSalesman());
        vo.setCustomerName(ledger.getCustomerName());
        vo.setEntryPersonName(ledger.getEntryPersonName());
        vo.setContractAmount(ledger.getContractAmount());
        vo.setRemarks(ledger.getRemarks());
        return vo;
    }
 
    public void addProduct(SalesLedgerProduct product) {
        this.products.add(Item.fromProduct(product));
    }
}