| | |
| | | |
| | | import com.aspose.cad.Image; |
| | | import com.aspose.cad.ImageOptionsBase; |
| | | import com.aspose.cad.License; |
| | | import com.aspose.cad.imageoptions.CadRasterizationOptions; |
| | | import com.aspose.cad.imageoptions.PngOptions; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | public Object updateOrderFileByOrderNumber(MultipartFile file,String orderId,String orderNumber) throws IOException { |
| | | |
| | | // 调用Image类的Load方法来加载输入的DWG文件。 |
| | | Image image = Image.load(file.getInputStream()); |
| | | // 创建CadRasterizationOptions实例以启用CAD栅格化选项。 |
| | | CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); |
| | | // 设置宽度 |
| | | rasterizationOptions.setPageWidth(1000); |
| | | // 设置高度 |
| | | rasterizationOptions.setPageHeight(1000); |
| | | // 调用这个setEmbedBackground方法来设置背景色是否不等于输出格式的默认背景色 |
| | | rasterizationOptions.setEmbedBackground(true); |
| | | // 为生成的图像创建一个PngOptions的实例,并将其分配给ImageOptionsBase类的实例。 |
| | | ImageOptionsBase options = new PngOptions(); |
| | | // 调用 setVectorRasterizationOptions 方法来定义光栅化选项 |
| | | options.setVectorRasterizationOptions(rasterizationOptions); |
| | | try (InputStream is = License.class.getResourceAsStream("/lisence.xml")) { |
| | | License license = new License(); |
| | | license.setLicense(is); |
| | | |
| | | // 保存到字节流 |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | image.save(outputStream, options); |
| | | byte[] imageBytes = outputStream.toByteArray(); |
| | | String base64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes); |
| | | OrderFile orderFile = new OrderFile(); |
| | | orderFile.setImageBase64(base64); |
| | | orderFile.setFileName(file.getName()); |
| | | orderFile.setOrderId(orderId); |
| | | orderFile.setOrderNumber(orderNumber); |
| | | orderFile.setFileData(Arrays.toString(file.getBytes())); |
| | | |
| | | OrderFile orderFileExist = orderFileMapper |
| | | .selectOne(new LambdaQueryWrapper<OrderFile>() |
| | | // 调用Image类的Load方法来加载输入的DWG文件。 |
| | | Image image = Image.load(file.getInputStream()); |
| | | // 创建CadRasterizationOptions实例以启用CAD栅格化选项。 |
| | | CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); |
| | | // 设置宽度 |
| | | rasterizationOptions.setPageWidth(1000); |
| | | // 设置高度 |
| | | rasterizationOptions.setPageHeight(1000); |
| | | // 调用这个setEmbedBackground方法来设置背景色是否不等于输出格式的默认背景色 |
| | | //rasterizationOptions.setEmbedBackground(true); |
| | | // 为生成的图像创建一个PngOptions的实例,并将其分配给ImageOptionsBase类的实例。 |
| | | ImageOptionsBase options = new PngOptions(); |
| | | // 调用 setVectorRasterizationOptions 方法来定义光栅化选项 |
| | | options.setVectorRasterizationOptions(rasterizationOptions); |
| | | |
| | | // 保存到字节流 |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | image.save(outputStream, options); |
| | | byte[] imageBytes = outputStream.toByteArray(); |
| | | String base64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes); |
| | | OrderFile orderFile = new OrderFile(); |
| | | orderFile.setImageBase64(base64); |
| | | orderFile.setFileName(file.getName()); |
| | | orderFile.setOrderId(orderId); |
| | | orderFile.setOrderNumber(orderNumber); |
| | | orderFile.setFileData(Arrays.toString(file.getBytes())); |
| | | |
| | | OrderFile orderFileExist = orderFileMapper |
| | | .selectOne(new LambdaQueryWrapper<OrderFile>() |
| | | .eq(OrderFile::getOrderId, orderId) |
| | | .eq(OrderFile::getOrderNumber, orderNumber) |
| | | ); |
| | | if (orderFileExist == null) { |
| | | orderFileMapper.insert(orderFile); |
| | | }else { |
| | | orderFileMapper.update(orderFile,new LambdaUpdateWrapper<OrderFile>() |
| | | .eq(OrderFile::getOrderId, orderId) |
| | | .eq(OrderFile::getOrderNumber, orderNumber) |
| | | ); |
| | | if (orderFileExist == null) { |
| | | orderFileMapper.insert(orderFile); |
| | | }else { |
| | | orderFileMapper.update(orderFile,new LambdaUpdateWrapper<OrderFile>() |
| | | .eq(OrderFile::getOrderId, orderId) |
| | | .eq(OrderFile::getOrderNumber, orderNumber) |
| | | ); |
| | | } |
| | | |
| | | |
| | | return base64; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | return base64; |
| | | } |
| | | } |