Showing
3 changed files
with
72 additions
and
10 deletions
xingyun-sc/src/main/java/com/lframework/xingyun/sc/controller/order/PurchaseOrderInfoController.java
| @@ -18,6 +18,7 @@ import com.lframework.xingyun.sc.entity.PurchaseOrderInfo; | @@ -18,6 +18,7 @@ import com.lframework.xingyun.sc.entity.PurchaseOrderInfo; | ||
| 18 | import com.lframework.xingyun.sc.entity.PurchaseOrderLine; | 18 | import com.lframework.xingyun.sc.entity.PurchaseOrderLine; |
| 19 | import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService; | 19 | import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService; |
| 20 | import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService; | 20 | import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService; |
| 21 | +import com.lframework.xingyun.sc.utils.LatexFormulaExcelExporterUtil; | ||
| 21 | import com.lframework.xingyun.sc.vo.order.CreatePurchaseOrderInfoVo; | 22 | import com.lframework.xingyun.sc.vo.order.CreatePurchaseOrderInfoVo; |
| 22 | import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderInfoVo; | 23 | import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderInfoVo; |
| 23 | import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderLineVo; | 24 | import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderLineVo; |
| @@ -27,6 +28,7 @@ import io.swagger.annotations.ApiImplicitParam; | @@ -27,6 +28,7 @@ import io.swagger.annotations.ApiImplicitParam; | ||
| 27 | import io.swagger.annotations.ApiOperation; | 28 | import io.swagger.annotations.ApiOperation; |
| 28 | import lombok.extern.slf4j.Slf4j; | 29 | import lombok.extern.slf4j.Slf4j; |
| 29 | import org.apache.commons.collections4.CollectionUtils; | 30 | import org.apache.commons.collections4.CollectionUtils; |
| 31 | +import org.apache.commons.lang3.StringUtils; | ||
| 30 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | 32 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| 31 | import org.apache.poi.ss.usermodel.*; | 33 | import org.apache.poi.ss.usermodel.*; |
| 32 | import org.apache.poi.ss.util.CellRangeAddress; | 34 | import org.apache.poi.ss.util.CellRangeAddress; |
| @@ -213,7 +215,36 @@ public class PurchaseOrderInfoController extends DefaultBaseController { | @@ -213,7 +215,36 @@ public class PurchaseOrderInfoController extends DefaultBaseController { | ||
| 213 | setCellValue(sheet, startRow, 2, currentOrderLine.getQuality()); | 215 | setCellValue(sheet, startRow, 2, currentOrderLine.getQuality()); |
| 214 | setCellValue(sheet, startRow, 3, currentOrderLine.getBrand()); | 216 | setCellValue(sheet, startRow, 3, currentOrderLine.getBrand()); |
| 215 | 217 | ||
| 216 | - //todo 规格 | 218 | + List<LatexFormulaExcelExporterUtil.FormulaComponent> formulaComponentList = new ArrayList<>(3); |
| 219 | + if (currentOrderLine.getThickness() != null) { | ||
| 220 | + LatexFormulaExcelExporterUtil.FormulaComponent formulaComponent = new LatexFormulaExcelExporterUtil.FormulaComponent(); | ||
| 221 | + formulaComponent.setBase(currentOrderLine.getThickness()); | ||
| 222 | + formulaComponent.setSup(currentOrderLine.getThicknessTolPos()); | ||
| 223 | + formulaComponent.setSub(currentOrderLine.getThicknessTolNeg()); | ||
| 224 | + formulaComponentList.add(formulaComponent); | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + if (currentOrderLine.getWidth() != null) { | ||
| 228 | + LatexFormulaExcelExporterUtil.FormulaComponent formulaComponent = new LatexFormulaExcelExporterUtil.FormulaComponent(); | ||
| 229 | + formulaComponent.setBase(currentOrderLine.getWidth()); | ||
| 230 | + formulaComponent.setSup(currentOrderLine.getWidthTolPos()); | ||
| 231 | + formulaComponent.setSub(currentOrderLine.getWidthTolNeg()); | ||
| 232 | + formulaComponentList.add(formulaComponent); | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + if (currentOrderLine.getLength() != null) { | ||
| 236 | + LatexFormulaExcelExporterUtil.FormulaComponent formulaComponent = new LatexFormulaExcelExporterUtil.FormulaComponent(); | ||
| 237 | + formulaComponent.setBase(currentOrderLine.getLength()); | ||
| 238 | + formulaComponent.setSup(currentOrderLine.getLengthTolPos()); | ||
| 239 | + formulaComponent.setSub(currentOrderLine.getLengthTolNeg()); | ||
| 240 | + formulaComponentList.add(formulaComponent); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + String latex = LatexFormulaExcelExporterUtil.convertToLatex(formulaComponentList); | ||
| 244 | + if (StringUtils.isNotBlank(latex)) { | ||
| 245 | + LatexFormulaExcelExporterUtil.insertLatexImageToCell(workbook, sheet, latex, startRow, 4, 1, 7); | ||
| 246 | + } | ||
| 247 | + | ||
| 217 | setCellValue(sheet, startRow, 11, currentOrderLine.getStatus()); | 248 | setCellValue(sheet, startRow, 11, currentOrderLine.getStatus()); |
| 218 | setCellValue(sheet, startRow, 13, currentOrderLine.getQuantity()); | 249 | setCellValue(sheet, startRow, 13, currentOrderLine.getQuantity()); |
| 219 | setCellValue(sheet, startRow, 14, currentOrderLine.getSalesPrice()); | 250 | setCellValue(sheet, startRow, 14, currentOrderLine.getSalesPrice()); |
| @@ -242,6 +273,7 @@ public class PurchaseOrderInfoController extends DefaultBaseController { | @@ -242,6 +273,7 @@ public class PurchaseOrderInfoController extends DefaultBaseController { | ||
| 242 | dataMap.put("shippingCost", data.getShippingCost()); | 273 | dataMap.put("shippingCost", data.getShippingCost()); |
| 243 | dataMap.put("remarks", data.getRemarks()); | 274 | dataMap.put("remarks", data.getRemarks()); |
| 244 | dataMap.put("createUser", data.getCreateBy()); | 275 | dataMap.put("createUser", data.getCreateBy()); |
| 276 | + dataMap.put("element", data.getElement()); | ||
| 245 | 277 | ||
| 246 | 278 | ||
| 247 | 279 | ||
| @@ -382,21 +414,17 @@ public class PurchaseOrderInfoController extends DefaultBaseController { | @@ -382,21 +414,17 @@ public class PurchaseOrderInfoController extends DefaultBaseController { | ||
| 382 | newCell.setCellStyle(oldCell.getCellStyle()); | 414 | newCell.setCellStyle(oldCell.getCellStyle()); |
| 383 | } | 415 | } |
| 384 | 416 | ||
| 385 | - switch (oldCell.getCellType()) { | ||
| 386 | - case 1: | ||
| 387 | - //STRING | 417 | + switch (oldCell.getCellTypeEnum()) { |
| 418 | + case STRING: | ||
| 388 | newCell.setCellValue(oldCell.getStringCellValue()); | 419 | newCell.setCellValue(oldCell.getStringCellValue()); |
| 389 | break; | 420 | break; |
| 390 | - case 0: | ||
| 391 | - //NUMERIC | 421 | + case NUMERIC: |
| 392 | newCell.setCellValue(oldCell.getNumericCellValue()); | 422 | newCell.setCellValue(oldCell.getNumericCellValue()); |
| 393 | break; | 423 | break; |
| 394 | - case 4: | ||
| 395 | - //BOOLEAN | 424 | + case BOOLEAN: |
| 396 | newCell.setCellValue(oldCell.getBooleanCellValue()); | 425 | newCell.setCellValue(oldCell.getBooleanCellValue()); |
| 397 | break; | 426 | break; |
| 398 | - case 2: | ||
| 399 | - //FORMULA | 427 | + case FORMULA: |
| 400 | newCell.setCellFormula(oldCell.getCellFormula()); | 428 | newCell.setCellFormula(oldCell.getCellFormula()); |
| 401 | break; | 429 | break; |
| 402 | default: | 430 | default: |
| @@ -168,6 +168,40 @@ public class LatexFormulaExcelExporterUtil { | @@ -168,6 +168,40 @@ public class LatexFormulaExcelExporterUtil { | ||
| 168 | // pict.resize(0.95); // 缩小到90%,自然产生边距 | 168 | // pict.resize(0.95); // 缩小到90%,自然产生边距 |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | + /** | ||
| 172 | + * 将LaTeX公式作为图片插入到指定单元格 | ||
| 173 | + */ | ||
| 174 | + public static void insertLatexImageToCell(Workbook workbook, Sheet sheet, String latex, int rowIndex, int colIndex, int rowRange, int colRange) throws IOException { | ||
| 175 | + // 1. 将LaTeX渲染为图片字节 | ||
| 176 | + byte[] imageBytes = latexToImageBytes(latex, 36); | ||
| 177 | + | ||
| 178 | + // 2. 将图片添加到工作簿 | ||
| 179 | + int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG); | ||
| 180 | + | ||
| 181 | + // 3. 创建绘图对象 | ||
| 182 | + Drawing<?> drawing = sheet.createDrawingPatriarch(); | ||
| 183 | + | ||
| 184 | + // 4. 创建锚点,确定图片位置 | ||
| 185 | + ClientAnchor anchor = workbook.getCreationHelper().createClientAnchor(); | ||
| 186 | + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE); | ||
| 187 | + anchor.setCol1(colIndex); // C列 (从0开始计数) | ||
| 188 | + anchor.setRow1(rowIndex); // 当前数据行 (表头在第0行) | ||
| 189 | + anchor.setCol2(colIndex + colRange); // 结束于D列 | ||
| 190 | + anchor.setRow2(rowIndex + rowRange); // 结束于下一行 | ||
| 191 | + | ||
| 192 | + // 设置较小的起始偏移 | ||
| 193 | + anchor.setDx1(50); // 水平偏移(建议值:10-100) | ||
| 194 | + anchor.setDy1(25); // 垂直偏移(建议值:10-50) | ||
| 195 | + | ||
| 196 | + | ||
| 197 | + // 5. 创建图片并插入 | ||
| 198 | + Picture pict = drawing.createPicture(anchor, pictureIdx); | ||
| 199 | + | ||
| 200 | + // 6. 自动调整图片大小以适应单元格 (可选) | ||
| 201 | + // 取消注释此行使图片自动适应锚点区域 | ||
| 202 | +// pict.resize(0.95); // 缩小到90%,自然产生边距 | ||
| 203 | + } | ||
| 204 | + | ||
| 171 | @Data | 205 | @Data |
| 172 | public static class FormulaComponent { | 206 | public static class FormulaComponent { |
| 173 | BigDecimal base; | 207 | BigDecimal base; |
No preview for this file type