Commit d5f54f243755de970308d94471d11a88e0582a75
1 parent
fe932d3a
fix: 订单导出图片支持
Showing
4 changed files
with
43 additions
and
14 deletions
pom.xml
@@ -30,6 +30,7 @@ | @@ -30,6 +30,7 @@ | ||
30 | <fastjson.version>1.2.83</fastjson.version> | 30 | <fastjson.version>1.2.83</fastjson.version> |
31 | <poi.version>3.17</poi.version> | 31 | <poi.version>3.17</poi.version> |
32 | <poi-ooxml.version>3.17</poi-ooxml.version> | 32 | <poi-ooxml.version>3.17</poi-ooxml.version> |
33 | + <poi-excel.version>poi-317.8</poi-excel.version> | ||
33 | <commons-csv.version>1.6</commons-csv.version> | 34 | <commons-csv.version>1.6</commons-csv.version> |
34 | <commons-lang3.version>3.8.1</commons-lang3.version> | 35 | <commons-lang3.version>3.8.1</commons-lang3.version> |
35 | <commons-pool2.version>2.11.1</commons-pool2.version> | 36 | <commons-pool2.version>2.11.1</commons-pool2.version> |
@@ -236,6 +237,13 @@ | @@ -236,6 +237,13 @@ | ||
236 | <version>${easy-captcha.version}</version> | 237 | <version>${easy-captcha.version}</version> |
237 | </dependency> | 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 | <dependency> | 248 | <dependency> |
241 | <groupId>com.aliyun</groupId> | 249 | <groupId>com.aliyun</groupId> |
src/main/java/com/order/erp/controller/OrderController.java
@@ -3,7 +3,10 @@ package com.order.erp.controller; | @@ -3,7 +3,10 @@ package com.order.erp.controller; | ||
3 | import com.order.erp.common.annotation.AnonymousAccess; | 3 | import com.order.erp.common.annotation.AnonymousAccess; |
4 | import com.order.erp.common.constant.ServerResult; | 4 | import com.order.erp.common.constant.ServerResult; |
5 | import com.order.erp.common.excel4j.exceptions.Excel4JException; | 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 | import com.order.erp.service.order.OrderBaseInfoService; | 10 | import com.order.erp.service.order.OrderBaseInfoService; |
8 | import io.swagger.annotations.Api; | 11 | import io.swagger.annotations.Api; |
9 | import io.swagger.annotations.ApiOperation; | 12 | import io.swagger.annotations.ApiOperation; |
@@ -52,11 +55,11 @@ public class OrderController { | @@ -52,11 +55,11 @@ public class OrderController { | ||
52 | * @param orderBaseInfoQueryVO 查询条件 | 55 | * @param orderBaseInfoQueryVO 查询条件 |
53 | * @return 查询结果 | 56 | * @return 查询结果 |
54 | */ | 57 | */ |
55 | - @PostMapping("/export") | 58 | + @PostMapping(value = "/export") |
56 | @ApiOperation("导出订单") | 59 | @ApiOperation("导出订单") |
57 | @AnonymousAccess | 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,8 +4,10 @@ import com.baomidou.mybatisplus.extension.service.IService; | ||
4 | import com.order.erp.common.constant.ServerResult; | 4 | import com.order.erp.common.constant.ServerResult; |
5 | import com.order.erp.common.excel4j.exceptions.Excel4JException; | 5 | import com.order.erp.common.excel4j.exceptions.Excel4JException; |
6 | import com.order.erp.domain.dto.order.OrderBaseInfoDO; | 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 | import javax.servlet.http.HttpServletResponse; | 12 | import javax.servlet.http.HttpServletResponse; |
11 | import java.io.IOException; | 13 | import java.io.IOException; |
@@ -38,22 +40,19 @@ public interface OrderBaseInfoService extends IService<OrderBaseInfoDO> { | @@ -38,22 +40,19 @@ public interface OrderBaseInfoService extends IService<OrderBaseInfoDO> { | ||
38 | 40 | ||
39 | 41 | ||
40 | /** | 42 | /** |
41 | - * | ||
42 | * @param orderBaseInfoQueryVO | 43 | * @param orderBaseInfoQueryVO |
43 | * @return | 44 | * @return |
44 | */ | 45 | */ |
45 | ServerResult listByPage(OrderBaseInfoQueryVO orderBaseInfoQueryVO); | 46 | ServerResult listByPage(OrderBaseInfoQueryVO orderBaseInfoQueryVO); |
46 | 47 | ||
47 | /** | 48 | /** |
48 | - * | ||
49 | * @param response | 49 | * @param response |
50 | * @param orderBaseInfoQueryVO | 50 | * @param orderBaseInfoQueryVO |
51 | * @return | 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 | * @param fieldVO | 56 | * @param fieldVO |
58 | * @return | 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,6 +11,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | ||
11 | import com.baomidou.mybatisplus.core.toolkit.StringUtils; | 11 | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
12 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 12 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
13 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 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 | import com.order.erp.common.constant.Constant; | 16 | import com.order.erp.common.constant.Constant; |
15 | import com.order.erp.common.constant.ServerResult; | 17 | import com.order.erp.common.constant.ServerResult; |
16 | import com.order.erp.common.constant.ServerResultCode; | 18 | import com.order.erp.common.constant.ServerResultCode; |
@@ -37,7 +39,9 @@ import org.springframework.transaction.annotation.Transactional; | @@ -37,7 +39,9 @@ import org.springframework.transaction.annotation.Transactional; | ||
37 | import javax.annotation.Resource; | 39 | import javax.annotation.Resource; |
38 | import javax.servlet.http.HttpServletResponse; | 40 | import javax.servlet.http.HttpServletResponse; |
39 | import java.io.IOException; | 41 | import java.io.IOException; |
42 | +import java.io.InputStream; | ||
40 | import java.math.BigDecimal; | 43 | import java.math.BigDecimal; |
44 | +import java.net.URL; | ||
41 | import java.util.*; | 45 | import java.util.*; |
42 | import java.util.function.Function; | 46 | import java.util.function.Function; |
43 | import java.util.stream.Collectors; | 47 | import java.util.stream.Collectors; |
@@ -168,7 +172,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | @@ -168,7 +172,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | ||
168 | } | 172 | } |
169 | 173 | ||
170 | @Override | 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 | OrderLockFieldVO lockFieldVO = queryVO.getFieldVO(); | 176 | OrderLockFieldVO lockFieldVO = queryVO.getFieldVO(); |
173 | if (Objects.isNull(lockFieldVO)) { | 177 | if (Objects.isNull(lockFieldVO)) { |
174 | throw new BusinessException("请选择要导出的列!"); | 178 | throw new BusinessException("请选择要导出的列!"); |
@@ -206,11 +210,17 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | @@ -206,11 +210,17 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | ||
206 | if (CollectionUtils.isNotEmpty(resultVOList)) { | 210 | if (CollectionUtils.isNotEmpty(resultVOList)) { |
207 | List<Map<String, Object>> list = buildExportMapVOS(resultVOList, lockFieldVO); | 211 | List<Map<String, Object>> list = buildExportMapVOS(resultVOList, lockFieldVO); |
208 | if (CollectionUtils.isNotEmpty(list)) { | 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,7 +228,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | ||
218 | * @param lockFieldVO | 228 | * @param lockFieldVO |
219 | * @return | 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 | List<Map<String, Object>> list = new ArrayList<>(); | 232 | List<Map<String, Object>> list = new ArrayList<>(); |
223 | for (OrderInfoResultVO orderInfoResultVO : resultVOList) { | 233 | for (OrderInfoResultVO orderInfoResultVO : resultVOList) { |
224 | Map<String, Object> map = new LinkedHashMap<>(); | 234 | Map<String, Object> map = new LinkedHashMap<>(); |
@@ -282,6 +292,15 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | @@ -282,6 +292,15 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | ||
282 | if (StringUtils.isNotBlank(baseFields.getPacketType())) { | 292 | if (StringUtils.isNotBlank(baseFields.getPacketType())) { |
283 | map.put("包装类型", orderInfoResultVO.getPacketType()); | 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 | OrderProfitAnalysisVO profitAnalysisVO = orderInfoResultVO.getProfitAnalysisInfo(); | 305 | OrderProfitAnalysisVO profitAnalysisVO = orderInfoResultVO.getProfitAnalysisInfo(); |
287 | if (Objects.nonNull(profitAnalysisFields) && Objects.nonNull(profitAnalysisVO)) { | 306 | if (Objects.nonNull(profitAnalysisFields) && Objects.nonNull(profitAnalysisVO)) { |