czt
2026-01-06 9072fdbdd4fdafcf529829df93327b1e1256f794
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package com.fzzy.igds.export;
 
 
import com.fzzy.igds.*;
import com.fzzy.igds.data.*;
import com.fzzy.igds.domain.Company;
import com.fzzy.igds.domain.Depot;
import com.fzzy.igds.domain.Dept;
import com.fzzy.igds.domain.InoutRecord;
import com.fzzy.igds.service.*;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
 
 
/**
 * 数据导出EXCEL入口
 *
 * @author sgj
 * @date 2025/12/24
 */
@Controller
@RequestMapping("export")
public class ReportController {
 
 
    @Resource
    private InoutRecordService inoutReportService;
    @Resource
    private SysDeptService sysDeptService;
    @Resource
    private CoreDeptService coreDeptService;
    @Resource
    private DepotService depotService;
    @Resource
    private CoreCompanyService coreCompanyService;
    @Autowired
    private ReportInDetailPR reportInDetailPR;
    @Autowired
    private ReportOutDetailPR reportOutDetailPR;
    @Autowired
    private SuperInventoryReportPR superInventoryReportPR;
 
    @Autowired
    private CompanyPR companyPR;
 
    @Autowired
    private DeptPR deptPR;
 
    @Autowired
    private DepotPR depotPR;
 
    @Autowired
    private DicPR dicPR;
 
 
    /**
     * 出入库报表导出
     *
     * @return
     */
    @RequestMapping("/inOutReport-excel")
    @ResponseBody
    public AjaxResult inOutReport(InoutParam param) {
        //设置标题
        String sheetName = "报表数据";
        //查询数据
        List<InoutRecord> list = new ArrayList<>();
        //获取分库编码对应的分库名称
        String deptName = "";
        SysDept subDept = sysDeptService.getCacheDept(null, ContextUtil.subDeptId(null));
        if (null != subDept) {
            deptName = subDept.getDeptName();
        }
        //创建收储公司ID到名称的映射
        Map<String, String> companyMap = Optional.ofNullable(companyPR.getData())
                .orElse(new ArrayList<>())
                .stream()
                .collect(Collectors.toMap(Company::getId, Company::getDwmc, (key1, key2) -> key2));
        //创建所在库区ID到名称的映射
        Map<String, String> deptMap = Optional.ofNullable(deptPR.getAllData())
                .orElse(new ArrayList<>())
                .stream()
                .collect(Collectors.toMap(Dept::getId, Dept::getKqmc, (key1, key2) -> key2));
        // 创建仓库ID到名称的映射
        Map<String, String> depotMap = Optional.ofNullable(depotPR.getData(null))
                .orElse(new ArrayList<>())
                .stream()
                .collect(Collectors.toMap(Depot::getId, Depot::getName, (key1, key2) -> key2));
        //创建粮食品种ID到名称的映射
        Map<String, String> foodVarietyMap = Optional.ofNullable(dicPR.sysDictData("FOOD_VARIETY_"))
                .orElse(new ArrayList<>())
                .stream()
                .collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel, (key1, key2) -> key2));
 
        //组装实际导出数据
        if (StringUtils.isNotEmpty(param.getType()) && "IN".equals(param.getType())) {
            sheetName = "入库报表数据";
            list = reportInDetailPR.listRecord(param);
            List<InoutRecordInExport> exportList = new ArrayList<>();
            for (InoutRecord record : list) {
                InoutRecordInExport export = new InoutRecordInExport();
                export.setId(record.getId());
                export.setPlateNum(record.getPlateNum());
                // 将仓库ID映射为仓库名称
                String depotNameValue = depotMap.get(record.getDepotId());
                export.setDepotId(depotNameValue != null ? depotNameValue : "");
                //粮食品种映射
                String foodVarietyNameValue = foodVarietyMap.get(record.getFoodVariety());
                export.setFoodVariety(foodVarietyNameValue != null ? foodVarietyNameValue : "");
                export.setFullWeight(record.getFullWeight());
                export.setEmptyWeight(record.getEmptyWeight());
                export.setNetWeight(record.getNetWeight());
                export.setSettleWeight(record.getSettleWeight());
                export.setRecordWeight(record.getRecordWeight());
                export.setCompleteTime(record.getCompleteTime());
                export.setDeOther(record.getDeOther());
                exportList.add(export);
            }
            ExcelUtil<InoutRecordInExport> util = new ExcelUtil<InoutRecordInExport>(InoutRecordInExport.class);
            return util.exportExcel(exportList, sheetName, deptName);
        }
 
        if (StringUtils.isNotEmpty(param.getType()) && "OUT".equals(param.getType())) {
            sheetName = "出库报表数据";
            list = reportOutDetailPR.listRecord(param);
            List<InoutRecordOutExport> exportList = new ArrayList<>();
            for (InoutRecord record : list) {
                InoutRecordOutExport export = new InoutRecordOutExport();
                export.setId(record.getId());
                export.setPlateNum(record.getPlateNum());
                // 将仓库ID映射为仓库名称
                String depotNameValue = depotMap.get(record.getDepotId());
                export.setDepotId(depotNameValue != null ? depotNameValue : "");
                //粮食品种映射
                String foodVarietyNameValue = foodVarietyMap.get(record.getFoodVariety());
                export.setFoodVariety(foodVarietyNameValue != null ? foodVarietyNameValue : "");
                export.setFullWeight(record.getFullWeight());
                export.setEmptyWeight(record.getEmptyWeight());
                export.setNetWeight(record.getNetWeight());
                export.setSettleWeight(record.getSettleWeight());
                export.setRecordWeight(record.getRecordWeight());
                export.setCompleteTime(record.getCompleteTime());
                export.setDeOther(record.getDeOther());
                exportList.add(export);
            }
            ExcelUtil<InoutRecordOutExport> util = new ExcelUtil<InoutRecordOutExport>(InoutRecordOutExport.class);
            return util.exportExcel(exportList, sheetName, deptName);
        }
 
        if (StringUtils.isNotEmpty(param.getType()) && "IN_DETAIL".equals(param.getType())) {
            sheetName = "入库明细报表数据";
            list = reportInDetailPR.listRecord(param);
            List<InoutRecordDetailInExport> exportList = new ArrayList<>();
            for (InoutRecord record : list) {
                InoutRecordDetailInExport export = new InoutRecordDetailInExport();
                //收储公司映射
                String companyNameValue = companyMap.get(record.getCompanyId());
                export.setCompanyId(companyNameValue != null ? companyNameValue : "");
                //库区映射
                String deptNameValue = deptMap.get(record.getDeptId());
                export.setDeptId(deptNameValue != null ? deptNameValue : "");
                export.setId(record.getId());
                export.setPlateNum(record.getPlateNum());
                // 将仓库ID映射为仓库名称
                String depotNameValue = depotMap.get(record.getDepotId());
                export.setDepotId(depotNameValue != null ? depotNameValue : "");
                //粮食品种映射
                String foodVarietyNameValue = foodVarietyMap.get(record.getFoodVariety());
                export.setFoodVariety(foodVarietyNameValue != null ? foodVarietyNameValue : "");
                export.setSettleWeight(record.getSettleWeight());
                export.setRecordWeight(record.getRecordWeight());
                export.setCompleteTime(record.getCompleteTime());
                exportList.add(export);
            }
            ExcelUtil<InoutRecordDetailInExport> util = new ExcelUtil<InoutRecordDetailInExport>(InoutRecordDetailInExport.class);
            return util.exportExcel(exportList, sheetName, deptName);
        }
 
        if (StringUtils.isNotEmpty(param.getType()) && "OUT_DETAIL".equals(param.getType())) {
            sheetName = "出库明细报表数据";
            list = reportOutDetailPR.listRecord(param);
            List<InoutRecordDetailOutExport> exportList = new ArrayList<>();
            for (InoutRecord record : list) {
                InoutRecordDetailOutExport export = new InoutRecordDetailOutExport();
                //收储公司映射
                String companyNameValue = companyMap.get(record.getCompanyId());
                export.setCompanyId(companyNameValue != null ? companyNameValue : "");
                //库区映射
                String deptNameValue = deptMap.get(record.getDeptId());
                export.setDeptId(deptNameValue != null ? deptNameValue : "");
                export.setId(record.getId());
                export.setPlateNum(record.getPlateNum());
                // 将仓库ID映射为仓库名称
                String depotNameValue = depotMap.get(record.getDepotId());
                export.setDepotId(depotNameValue != null ? depotNameValue : "");
                //粮食品种映射
                String foodVarietyNameValue = foodVarietyMap.get(record.getFoodVariety());
                export.setFoodVariety(foodVarietyNameValue != null ? foodVarietyNameValue : "");
                export.setSettleWeight(record.getSettleWeight());
                export.setRecordWeight(record.getRecordWeight());
                export.setCompleteTime(record.getCompleteTime());
                exportList.add(export);
            }
            ExcelUtil<InoutRecordDetailOutExport> util = new ExcelUtil<InoutRecordDetailOutExport>(InoutRecordDetailOutExport.class);
            return util.exportExcel(exportList, sheetName, deptName);
        }
        return AjaxResult.error("参数错误");
    }
 
 
    /**
     * 库存报表导出
     *
     * @return
     */
    @RequestMapping("/superInventoryReport-excel")
    @ResponseBody
    public AjaxResult superInventoryReport(SuperInventoryReportParam param) {
        //设置标题
        String sheetName = "库存报表数据";
        //查询数据
        List<SuperInventoryReportData> list = superInventoryReportPR.getReportData(param);
        //获取分库编码对应的分库名称
        String deptName = "";
        SysDept subDept = sysDeptService.getCacheDept(null, ContextUtil.subDeptId(null));
        if (null != subDept) {
            deptName = subDept.getDeptName();
        }
 
        //导出
        ExcelUtil<SuperInventoryReportData> util = new ExcelUtil<SuperInventoryReportData>(SuperInventoryReportData.class);
        return util.exportExcel(list, sheetName, deptName);
    }
 
}