Commit 82b7b5ac91b8a89e079294687ac38c8b446af00c

Authored by 谢茂盛
1 parent c94daedf

fix: 审批管理/待审批/已审批列表查询接口

src/main/java/com/order/erp/common/excel4j/handler/SheetTemplateHandler.java
1 package com.order.erp.common.excel4j.handler; 1 package com.order.erp.common.excel4j.handler;
2 2
3 import com.order.erp.common.excel4j.exceptions.Excel4JException; 3 import com.order.erp.common.excel4j.exceptions.Excel4JException;
  4 +import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
  5 +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
4 import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 6 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
5 import org.apache.poi.ss.usermodel.*; 7 import org.apache.poi.ss.usermodel.*;
  8 +import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  9 +import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
  10 +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
6 11
7 import java.io.File; 12 import java.io.File;
8 import java.io.FileInputStream; 13 import java.io.FileInputStream;
@@ -257,12 +262,57 @@ public class SheetTemplateHandler { @@ -257,12 +262,57 @@ public class SheetTemplateHandler {
257 template.currentColumnIndex++; 262 template.currentColumnIndex++;
258 return; 263 return;
259 } 264 }
  265 +
  266 + if (value instanceof byte[]) {
  267 + byte[] data = (byte[]) value;
  268 + // 5.1anchor主要用于设置图片的属性
  269 + short x = (short) cell.getColumnIndex();
  270 + int y = cell.getRowIndex();
  271 + // 5.2插入图片
  272 + addImage(cell.getSheet(), new Integer[]{y, y, (int) x, (int) x}, data);
  273 + cell.setCellValue("");
  274 + template.currentColumnIndex++;
  275 + return;
  276 + }
  277 +
260 // default value#toString 278 // default value#toString
261 cell.setCellValue(value.toString()); 279 cell.setCellValue(value.toString());
262 template.currentColumnIndex++; 280 template.currentColumnIndex++;
263 } 281 }
264 282
265 /** 283 /**
  284 + * 指定单元格,添加图片
  285 + *
  286 + * @param position 下标位置, row start, row end, col start, col end
  287 + * @param images 图片数据
  288 + */
  289 + public static void addImage(Sheet sheet, Integer[] position, byte[] images) {
  290 + Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
  291 + Workbook workbook = sheet.getWorkbook();
  292 + // 5.2插入图片
  293 + ClientAnchor anchor;
  294 + int add1;
  295 + Integer startRow = position[0];
  296 + Integer endRow = position[1] + 1;
  297 + Integer startCol = position[2];
  298 + Integer endCol = position[3] + 1;
  299 + if (workbook instanceof XSSFWorkbook) {
  300 + anchor = new XSSFClientAnchor(0, 0, 0, 0, startCol, startRow, endCol, endRow);
  301 + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
  302 + add1 = workbook.addPicture(images, XSSFWorkbook.PICTURE_TYPE_PNG);
  303 + } else if (workbook instanceof HSSFWorkbook) {
  304 + anchor = new HSSFClientAnchor(0, 0, 0, 0, startCol.shortValue(), startRow, endCol.shortValue(), endRow);
  305 + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
  306 + add1 = workbook.addPicture(images, SXSSFWorkbook.PICTURE_TYPE_PNG);
  307 + } else {
  308 + anchor = new XSSFClientAnchor(0, 0, 0, 0, startCol, startRow, endCol, endRow);
  309 + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
  310 + add1 = workbook.addPicture(images, XSSFWorkbook.PICTURE_TYPE_PNG);
  311 + }
  312 + drawingPatriarch.createPicture(anchor, add1);
  313 + }
  314 +
  315 + /**
266 * 设置某个元素的样式 316 * 设置某个元素的样式
267 * 317 *
268 * @param cell cell元素 318 * @param cell cell元素
src/main/java/com/order/erp/common/utils/FileUtil.java
@@ -114,7 +114,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { @@ -114,7 +114,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
114 /** 114 /**
115 * inputStream 转 File 115 * inputStream 转 File
116 */ 116 */
117 - static File inputStreamToFile(InputStream ins, String name) throws Exception { 117 + public static File inputStreamToFile(InputStream ins, String name) throws Exception {
118 File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name); 118 File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
119 if (file.exists()) { 119 if (file.exists()) {
120 return file; 120 return file;
@@ -132,6 +132,52 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { @@ -132,6 +132,52 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
132 } 132 }
133 133
134 /** 134 /**
  135 + * 将文件转换为byte数组,作为图片数据导入
  136 + *
  137 + * @param file
  138 + * @return byte[]
  139 + */
  140 + public static byte[] imageParseBytes(File file) {
  141 + FileInputStream fileInputStream = null;
  142 + try {
  143 + fileInputStream = new FileInputStream(file);
  144 + } catch (FileNotFoundException e) {
  145 + e.printStackTrace();
  146 + }
  147 + return imageParseBytes(fileInputStream);
  148 + }
  149 +
  150 + /**
  151 + * 将流转换为byte数组,作为图片数据导入
  152 + *
  153 + * @param fis
  154 + * @return byte[]
  155 + */
  156 + public static byte[] imageParseBytes(InputStream fis) {
  157 + byte[] buffer = null;
  158 + ByteArrayOutputStream bos = null;
  159 + try {
  160 + bos = new ByteArrayOutputStream(1024);
  161 + byte[] b = new byte[1024];
  162 + int n;
  163 + while ((n = fis.read(b)) != -1) {
  164 + bos.write(b, 0, n);
  165 + }
  166 + buffer = bos.toByteArray();
  167 + } catch (Exception e) {
  168 + e.printStackTrace();
  169 + } finally {
  170 + try {
  171 + fis.close();
  172 + bos.close();
  173 + } catch (IOException e) {
  174 + e.printStackTrace();
  175 + }
  176 + }
  177 + return buffer;
  178 + }
  179 +
  180 + /**
135 * 将文件名解析成文件的上传路径 181 * 将文件名解析成文件的上传路径
136 */ 182 */
137 public static File upload(MultipartFile file, String filePath) { 183 public static File upload(MultipartFile file, String filePath) {
src/main/java/com/order/erp/domain/dto/order/OrderFieldLockApplyDO.java
@@ -40,7 +40,7 @@ public class OrderFieldLockApplyDO extends BaseDO implements Serializable { @@ -40,7 +40,7 @@ public class OrderFieldLockApplyDO extends BaseDO implements Serializable {
40 */ 40 */
41 private String fields; 41 private String fields;
42 /** 42 /**
43 - * 状态:0 待审批,1 通过,2 拒绝 43 + * 状态:0 待审批,10 通过,20 拒绝
44 */ 44 */
45 private Integer status; 45 private Integer status;
46 46
src/main/java/com/order/erp/domain/excel/OrderExcelVO.java
@@ -68,9 +68,14 @@ public class OrderExcelVO implements Serializable { @@ -68,9 +68,14 @@ public class OrderExcelVO implements Serializable {
68 /** 68 /**
69 * pic图片地址 69 * pic图片地址
70 */ 70 */
71 - @ExcelField(title = "pic图片地址", order = 11) 71 +// @ExcelField(title = "pic图片地址", order = 11)
72 private String picUrl; 72 private String picUrl;
73 /** 73 /**
  74 + * pic图片
  75 + */
  76 + @ExcelField(title = "pic图片", order = 11)
  77 + private byte[] picDate;
  78 + /**
74 * 生产要求 79 * 生产要求
75 */ 80 */
76 @ExcelField(title = "生产要求", order = 12) 81 @ExcelField(title = "生产要求", order = 12)
src/main/java/com/order/erp/domain/vo/order/OrderApplyResultVO.java
@@ -44,7 +44,7 @@ public class OrderApplyResultVO implements Serializable { @@ -44,7 +44,7 @@ public class OrderApplyResultVO implements Serializable {
44 */ 44 */
45 private OrderLockFieldVO fieldInfos; 45 private OrderLockFieldVO fieldInfos;
46 /** 46 /**
47 - * 状态:0 待审批,1 通过,2 拒绝 47 + * 状态:0 待审批,10 通过,20 拒绝
48 */ 48 */
49 private Integer status; 49 private Integer status;
50 50
src/main/java/com/order/erp/service/order/impl/OrderBaseInfoServiceImpl.java
@@ -16,6 +16,7 @@ import com.order.erp.common.constant.ServerResultCode; @@ -16,6 +16,7 @@ import com.order.erp.common.constant.ServerResultCode;
16 import com.order.erp.common.excel4j.ExcelUtils; 16 import com.order.erp.common.excel4j.ExcelUtils;
17 import com.order.erp.common.excel4j.exceptions.Excel4JException; 17 import com.order.erp.common.excel4j.exceptions.Excel4JException;
18 import com.order.erp.common.exception.BusinessException; 18 import com.order.erp.common.exception.BusinessException;
  19 +import com.order.erp.common.utils.FileUtil;
19 import com.order.erp.common.utils.OrderFieldUtils; 20 import com.order.erp.common.utils.OrderFieldUtils;
20 import com.order.erp.common.utils.ProfitUtils; 21 import com.order.erp.common.utils.ProfitUtils;
21 import com.order.erp.config.DataScope; 22 import com.order.erp.config.DataScope;
@@ -33,11 +34,13 @@ import com.order.erp.mapper.order.OrderBaseInfoMapper; @@ -33,11 +34,13 @@ import com.order.erp.mapper.order.OrderBaseInfoMapper;
33 import com.order.erp.service.order.*; 34 import com.order.erp.service.order.*;
34 import lombok.extern.slf4j.Slf4j; 35 import lombok.extern.slf4j.Slf4j;
35 import org.springframework.beans.BeanUtils; 36 import org.springframework.beans.BeanUtils;
  37 +import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.stereotype.Service; 38 import org.springframework.stereotype.Service;
37 import org.springframework.transaction.annotation.Transactional; 39 import org.springframework.transaction.annotation.Transactional;
38 40
39 import javax.annotation.Resource; 41 import javax.annotation.Resource;
40 import javax.servlet.http.HttpServletResponse; 42 import javax.servlet.http.HttpServletResponse;
  43 +import java.io.File;
41 import java.io.IOException; 44 import java.io.IOException;
42 import java.util.*; 45 import java.util.*;
43 import java.util.function.Function; 46 import java.util.function.Function;
@@ -53,6 +56,11 @@ import java.util.stream.Collectors; @@ -53,6 +56,11 @@ import java.util.stream.Collectors;
53 @Service 56 @Service
54 public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, OrderBaseInfoDO> implements OrderBaseInfoService { 57 public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, OrderBaseInfoDO> implements OrderBaseInfoService {
55 58
  59 + @Value("${file.path}")
  60 + private String path;
  61 +
  62 + @Value("${file.host}")
  63 + private String host;
56 64
57 @Resource 65 @Resource
58 private OrderProfitAnalysisService profitAnalysisService; 66 private OrderProfitAnalysisService profitAnalysisService;
@@ -184,6 +192,15 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl&lt;OrderBaseInfoMapper, O @@ -184,6 +192,15 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl&lt;OrderBaseInfoMapper, O
184 List<OrderExcelVO> excelVOS = resultVOList.stream().map(x -> { 192 List<OrderExcelVO> excelVOS = resultVOList.stream().map(x -> {
185 OrderExcelVO excelVO = new OrderExcelVO(); 193 OrderExcelVO excelVO = new OrderExcelVO();
186 BeanUtils.copyProperties(x, excelVO); 194 BeanUtils.copyProperties(x, excelVO);
  195 + if (StringUtils.isNotBlank(x.getPicUrl())) {
  196 + String filename = x.getPicUrl().replaceAll(host + "/images/", "");
  197 + try {
  198 + excelVO.setPicDate(FileUtil.imageParseBytes(new File(path + File.separator + filename)));
  199 + } catch (Exception e) {
  200 + log.error("图片转换异常,订单:{},e:{}", x.getId(), e.getMessage());
  201 + }
  202 +
  203 + }
187 return excelVO; 204 return excelVO;
188 }).collect(Collectors.toList()); 205 }).collect(Collectors.toList());
189 //response为HttpServletResponse对象 206 //response为HttpServletResponse对象