Commit d5f54f243755de970308d94471d11a88e0582a75
1 parent
fe932d3a
fix: 订单导出图片支持
Showing
4 changed files
with
43 additions
and
14 deletions
pom.xml
... | ... | @@ -30,6 +30,7 @@ |
30 | 30 | <fastjson.version>1.2.83</fastjson.version> |
31 | 31 | <poi.version>3.17</poi.version> |
32 | 32 | <poi-ooxml.version>3.17</poi-ooxml.version> |
33 | + <poi-excel.version>poi-317.8</poi-excel.version> | |
33 | 34 | <commons-csv.version>1.6</commons-csv.version> |
34 | 35 | <commons-lang3.version>3.8.1</commons-lang3.version> |
35 | 36 | <commons-pool2.version>2.11.1</commons-pool2.version> |
... | ... | @@ -236,6 +237,13 @@ |
236 | 237 | <version>${easy-captcha.version}</version> |
237 | 238 | </dependency> |
238 | 239 | |
240 | + <!-- excel导入导出 POI版本为3.17 --> | |
241 | + <dependency> | |
242 | + <groupId>com.github.stupdit1t</groupId> | |
243 | + <artifactId>poi-excel</artifactId> | |
244 | + <version>${poi-excel.version}</version> | |
245 | + </dependency> | |
246 | + | |
239 | 247 | <!--短信服务--> |
240 | 248 | <dependency> |
241 | 249 | <groupId>com.aliyun</groupId> | ... | ... |
src/main/java/com/order/erp/controller/OrderController.java
... | ... | @@ -3,7 +3,10 @@ package com.order.erp.controller; |
3 | 3 | import com.order.erp.common.annotation.AnonymousAccess; |
4 | 4 | import com.order.erp.common.constant.ServerResult; |
5 | 5 | import com.order.erp.common.excel4j.exceptions.Excel4JException; |
6 | -import com.order.erp.domain.vo.order.*; | |
6 | +import com.order.erp.domain.vo.order.OrderAddVO; | |
7 | +import com.order.erp.domain.vo.order.OrderBaseInfoQueryVO; | |
8 | +import com.order.erp.domain.vo.order.OrderUnlockFieldApplyVO; | |
9 | +import com.order.erp.domain.vo.order.OrderUpdateVO; | |
7 | 10 | import com.order.erp.service.order.OrderBaseInfoService; |
8 | 11 | import io.swagger.annotations.Api; |
9 | 12 | import io.swagger.annotations.ApiOperation; |
... | ... | @@ -52,11 +55,11 @@ public class OrderController { |
52 | 55 | * @param orderBaseInfoQueryVO 查询条件 |
53 | 56 | * @return 查询结果 |
54 | 57 | */ |
55 | - @PostMapping("/export") | |
58 | + @PostMapping(value = "/export") | |
56 | 59 | @ApiOperation("导出订单") |
57 | 60 | @AnonymousAccess |
58 | - public ServerResult export(HttpServletResponse response, @RequestBody @Validated OrderBaseInfoQueryVO orderBaseInfoQueryVO) throws IOException, Excel4JException { | |
59 | - return orderBaseInfoService.export(response, orderBaseInfoQueryVO); | |
61 | + public void export(HttpServletResponse response, @RequestBody @Validated OrderBaseInfoQueryVO orderBaseInfoQueryVO) throws IOException, Excel4JException { | |
62 | + orderBaseInfoService.export(response, orderBaseInfoQueryVO); | |
60 | 63 | } |
61 | 64 | |
62 | 65 | /** | ... | ... |
src/main/java/com/order/erp/service/order/OrderBaseInfoService.java
... | ... | @@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.extension.service.IService; |
4 | 4 | import com.order.erp.common.constant.ServerResult; |
5 | 5 | import com.order.erp.common.excel4j.exceptions.Excel4JException; |
6 | 6 | import com.order.erp.domain.dto.order.OrderBaseInfoDO; |
7 | -import com.order.erp.domain.vo.IndexDataVO; | |
8 | -import com.order.erp.domain.vo.order.*; | |
7 | +import com.order.erp.domain.vo.order.OrderAddVO; | |
8 | +import com.order.erp.domain.vo.order.OrderBaseInfoQueryVO; | |
9 | +import com.order.erp.domain.vo.order.OrderUnlockFieldApplyVO; | |
10 | +import com.order.erp.domain.vo.order.OrderUpdateVO; | |
9 | 11 | |
10 | 12 | import javax.servlet.http.HttpServletResponse; |
11 | 13 | import java.io.IOException; |
... | ... | @@ -38,22 +40,19 @@ public interface OrderBaseInfoService extends IService<OrderBaseInfoDO> { |
38 | 40 | |
39 | 41 | |
40 | 42 | /** |
41 | - * | |
42 | 43 | * @param orderBaseInfoQueryVO |
43 | 44 | * @return |
44 | 45 | */ |
45 | 46 | ServerResult listByPage(OrderBaseInfoQueryVO orderBaseInfoQueryVO); |
46 | 47 | |
47 | 48 | /** |
48 | - * | |
49 | 49 | * @param response |
50 | 50 | * @param orderBaseInfoQueryVO |
51 | 51 | * @return |
52 | 52 | */ |
53 | - ServerResult export(HttpServletResponse response, OrderBaseInfoQueryVO orderBaseInfoQueryVO) throws IOException, Excel4JException; | |
53 | + void export(HttpServletResponse response, OrderBaseInfoQueryVO orderBaseInfoQueryVO) throws IOException, Excel4JException; | |
54 | 54 | |
55 | 55 | /** |
56 | - * | |
57 | 56 | * @param fieldVO |
58 | 57 | * @return |
59 | 58 | */ | ... | ... |
src/main/java/com/order/erp/service/order/impl/OrderBaseInfoServiceImpl.java
... | ... | @@ -11,6 +11,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
11 | 11 | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
12 | 12 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
13 | 13 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
14 | +import com.github.stupdit1t.excel.common.PoiWorkbookType; | |
15 | +import com.github.stupdit1t.excel.core.ExcelHelper; | |
14 | 16 | import com.order.erp.common.constant.Constant; |
15 | 17 | import com.order.erp.common.constant.ServerResult; |
16 | 18 | import com.order.erp.common.constant.ServerResultCode; |
... | ... | @@ -37,7 +39,9 @@ import org.springframework.transaction.annotation.Transactional; |
37 | 39 | import javax.annotation.Resource; |
38 | 40 | import javax.servlet.http.HttpServletResponse; |
39 | 41 | import java.io.IOException; |
42 | +import java.io.InputStream; | |
40 | 43 | import java.math.BigDecimal; |
44 | +import java.net.URL; | |
41 | 45 | import java.util.*; |
42 | 46 | import java.util.function.Function; |
43 | 47 | import java.util.stream.Collectors; |
... | ... | @@ -168,7 +172,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O |
168 | 172 | } |
169 | 173 | |
170 | 174 | @Override |
171 | - public ServerResult export(HttpServletResponse response, OrderBaseInfoQueryVO queryVO) throws IOException, Excel4JException { | |
175 | + public void export(HttpServletResponse response, OrderBaseInfoQueryVO queryVO) throws IOException, Excel4JException { | |
172 | 176 | OrderLockFieldVO lockFieldVO = queryVO.getFieldVO(); |
173 | 177 | if (Objects.isNull(lockFieldVO)) { |
174 | 178 | throw new BusinessException("请选择要导出的列!"); |
... | ... | @@ -206,11 +210,17 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O |
206 | 210 | if (CollectionUtils.isNotEmpty(resultVOList)) { |
207 | 211 | List<Map<String, Object>> list = buildExportMapVOS(resultVOList, lockFieldVO); |
208 | 212 | if (CollectionUtils.isNotEmpty(list)) { |
209 | - FileUtil.downloadExcel(list, response); | |
213 | + List<String> keys = new ArrayList<>(list.get(Constant.ZERO).keySet()); | |
214 | + | |
215 | + ExcelHelper.opsExport(PoiWorkbookType.XLSX) | |
216 | + .opsSheet(list) | |
217 | + .opsHeader().simple().texts(keys).done() | |
218 | + .opsColumn().fields(keys).done() | |
219 | + .done() | |
220 | + .export(response.getOutputStream()); | |
210 | 221 | } |
211 | 222 | } |
212 | 223 | } |
213 | - return ServerResult.success(); | |
214 | 224 | } |
215 | 225 | |
216 | 226 | /** |
... | ... | @@ -218,7 +228,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O |
218 | 228 | * @param lockFieldVO |
219 | 229 | * @return |
220 | 230 | */ |
221 | - private List<Map<String, Object>> buildExportMapVOS(List<OrderInfoResultVO> resultVOList, OrderLockFieldVO lockFieldVO) { | |
231 | + private List<Map<String, Object>> buildExportMapVOS(List<OrderInfoResultVO> resultVOList, OrderLockFieldVO lockFieldVO) throws IOException { | |
222 | 232 | List<Map<String, Object>> list = new ArrayList<>(); |
223 | 233 | for (OrderInfoResultVO orderInfoResultVO : resultVOList) { |
224 | 234 | Map<String, Object> map = new LinkedHashMap<>(); |
... | ... | @@ -282,6 +292,15 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O |
282 | 292 | if (StringUtils.isNotBlank(baseFields.getPacketType())) { |
283 | 293 | map.put("包装类型", orderInfoResultVO.getPacketType()); |
284 | 294 | } |
295 | + if (StringUtils.isNotBlank(baseFields.getPicUrl())) { | |
296 | + if (StringUtils.isNotBlank(orderInfoResultVO.getSmallPicUrl())) { | |
297 | + URL url = new URL(orderInfoResultVO.getSmallPicUrl()); | |
298 | + InputStream inputStream = url.openStream(); | |
299 | + map.put("订单图片", FileUtil.imageParseBytes(inputStream)); | |
300 | + } else { | |
301 | + map.put("订单图片", ""); | |
302 | + } | |
303 | + } | |
285 | 304 | } |
286 | 305 | OrderProfitAnalysisVO profitAnalysisVO = orderInfoResultVO.getProfitAnalysisInfo(); |
287 | 306 | if (Objects.nonNull(profitAnalysisFields) && Objects.nonNull(profitAnalysisVO)) { | ... | ... |