| | |
| | | import com.example.erp.common.Result; |
| | | import com.example.erp.entity.sd.OrderDetail; |
| | | import com.example.erp.entity.sd.OrderFile; |
| | | import com.example.erp.mapper.sd.OrderDetailMapper; |
| | | import com.example.erp.mapper.sd.OrderFileMapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @RequiredArgsConstructor |
| | | public class OrderFileService { |
| | | private final OrderFileMapper orderFileMapper; |
| | | private final OrderDetailMapper orderDetailMapper; |
| | | public List<OrderFile> getOrderFilePicture(List<Map<String,Object>> orderDetails) throws NoSuchFieldException { |
| | | Set<String> seenKeys = new HashSet<>(); |
| | | List<Map<String,Object>> result = new ArrayList<>(); |
| | |
| | | result = orderDetails.stream() |
| | | .collect(Collectors.collectingAndThen( |
| | | Collectors.toMap( |
| | | map -> map.get("order_id"), |
| | | map -> { |
| | | Object v = map.get("order_id"); |
| | | if (v == null) { |
| | | v = map.get("orderId"); |
| | | } |
| | | return String.valueOf(v); |
| | | }, |
| | | map -> map, |
| | | (existing, replacement) -> existing // 保留第一个出现的 |
| | | (existing, replacement) -> existing // 保留第一个 |
| | | ), |
| | | map -> new ArrayList<>(map.values()) |
| | | m -> new ArrayList<>(m.values()) |
| | | )); |
| | | //循环获取图片 |
| | | List<OrderFile> orderFiles = new ArrayList<>(); |
| | | for (Map<String,Object> obj : result) { |
| | | List<OrderFile> orderFile = orderFileMapper.selectList(new QueryWrapper<OrderFile>() |
| | | .select("order_id, order_number, image_base64") |
| | | .eq("order_id", obj.get("order_id")) |
| | | for (Map<String, Object> obj : result) { |
| | | |
| | | Object orderId = obj.get("order_id"); |
| | | if (orderId == null) { |
| | | orderId = obj.get("orderId"); |
| | | } |
| | | |
| | | List<OrderFile> orderFile = orderFileMapper.selectList( |
| | | new QueryWrapper<OrderFile>() |
| | | .select("order_id, order_number, image_base64") |
| | | .eq("order_id", orderId) |
| | | ); |
| | | if (orderFile != null){ |
| | | |
| | | if (orderFile != null && !orderFile.isEmpty()) { |
| | | orderFiles.addAll(orderFile); |
| | | } |
| | | } |
| | | return orderFiles; |
| | | } |
| | | |
| | | public Object updateOrderFileByOrderNumber(MultipartFile file,String name,String orderId,String orderNumber) throws IOException { |
| | | public Object updateOrderFileByOrderNumber(MultipartFile file,String name,String orderId,String orderNumber,Float width,Float height) throws IOException { |
| | | //判断是否规定的格式后缀名 |
| | | if(!isAllowedFile(name)){ |
| | | return null; |
| | | } |
| | | |
| | | |
| | | try (InputStream is = License.class.getResourceAsStream("/lisence.xml")) { |
| | | String base64 = null; |
| | | if(name.toLowerCase().endsWith(".dwg")){ |
| | | |
| | | License license = new License(); |
| | | license.setLicense(is); |
| | | |
| | | |
| | | // 调用Image类的Load方法来加载输入的DWG文件。 |
| | | Image image = Image.load(file.getInputStream()); |
| | | // 创建CadRasterizationOptions实例以启用CAD栅格化选项。 |
| | | CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); |
| | | // 设置宽度 |
| | | rasterizationOptions.setPageWidth(1000); |
| | | rasterizationOptions.setPageWidth(width); |
| | | // 设置高度 |
| | | rasterizationOptions.setPageHeight(700); |
| | | rasterizationOptions.setPageHeight(height); |
| | | // 调用这个setEmbedBackground方法来设置背景色是否不等于输出格式的默认背景色 |
| | | //rasterizationOptions.setEmbedBackground(true); |
| | | // 为生成的图像创建一个PngOptions的实例,并将其分配给ImageOptionsBase类的实例。 |
| | |
| | | |
| | | OrderFile orderFile = new OrderFile(); |
| | | orderFile.setImageBase64(base64); |
| | | orderFile.setFileName(file.getName()); |
| | | orderFile.setFileName(name); |
| | | orderFile.setOrderId(orderId); |
| | | orderFile.setOrderNumber(orderNumber); |
| | | orderFile.setFileData(Arrays.toString(file.getBytes())); |
| | | orderFile.setWidth(width); |
| | | orderFile.setHeight(height); |
| | | |
| | | OrderFile orderFileExist = orderFileMapper |
| | | .selectOne(new LambdaQueryWrapper<OrderFile>() |
| | |
| | | .eq(OrderFile::getOrderNumber, orderNumber) |
| | | ); |
| | | } |
| | | |
| | | orderDetailMapper.update(null,new LambdaUpdateWrapper<OrderDetail>() |
| | | .setSql("file_name = '" + name + "'") |
| | | .eq(OrderDetail::getOrderId, orderId)); |
| | | |
| | | return orderFile; |
| | | } catch (Exception e) { |