|
1
|
package com.lframework.xingyun.sc.procurement.controller.plan;
|
1
|
package com.lframework.xingyun.sc.procurement.controller.plan;
|
|
2
|
|
2
|
|
|
|
|
3
|
+import cn.hutool.core.io.resource.ClassPathResource;
|
|
3
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
4
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
5
|
+import com.lframework.starter.common.exceptions.impl.DefaultClientException;
|
|
4
|
import com.lframework.starter.common.utils.CollectionUtil;
|
6
|
import com.lframework.starter.common.utils.CollectionUtil;
|
|
5
|
import com.lframework.starter.web.core.annotations.security.HasPermission;
|
7
|
import com.lframework.starter.web.core.annotations.security.HasPermission;
|
|
6
|
import com.lframework.starter.web.core.controller.DefaultBaseController;
|
8
|
import com.lframework.starter.web.core.controller.DefaultBaseController;
|
|
@@ -8,7 +10,11 @@ import com.lframework.starter.web.core.components.resp.InvokeResult; |
|
@@ -8,7 +10,11 @@ import com.lframework.starter.web.core.components.resp.InvokeResult; |
|
8
|
import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
|
10
|
import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
|
|
9
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
11
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
10
|
import com.lframework.starter.web.core.utils.PageResultUtil;
|
12
|
import com.lframework.starter.web.core.utils.PageResultUtil;
|
|
|
|
13
|
+import com.lframework.starter.web.inner.entity.SysDataDicItem;
|
|
|
|
14
|
+import com.lframework.starter.web.inner.service.system.SysDataDicItemService;
|
|
|
|
15
|
+import com.lframework.xingyun.sc.bo.procurement.GetProcurementBuyoutApplyBo;
|
|
11
|
import com.lframework.xingyun.sc.bo.procurement.GetProcurementPlanBo;
|
16
|
import com.lframework.xingyun.sc.bo.procurement.GetProcurementPlanBo;
|
|
|
|
17
|
+import com.lframework.xingyun.sc.bo.procurement.ProcurementBuyoutApplyLineBo;
|
|
12
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApply;
|
18
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApply;
|
|
13
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
|
19
|
import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
|
|
14
|
import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService;
|
20
|
import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService;
|
|
@@ -16,16 +22,16 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService |
|
@@ -16,16 +22,16 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService |
|
16
|
import com.lframework.xingyun.sc.procurement.vo.plan.CreateProcurementPlanVo;
|
22
|
import com.lframework.xingyun.sc.procurement.vo.plan.CreateProcurementPlanVo;
|
|
17
|
import com.lframework.xingyun.sc.procurement.vo.plan.QueryProcurementPlanVo;
|
23
|
import com.lframework.xingyun.sc.procurement.vo.plan.QueryProcurementPlanVo;
|
|
18
|
import com.lframework.xingyun.sc.procurement.vo.plan.UpdateProcurementPlanVo;
|
24
|
import com.lframework.xingyun.sc.procurement.vo.plan.UpdateProcurementPlanVo;
|
|
|
|
25
|
+import com.lframework.xingyun.sc.utils.ExcelUtil;
|
|
19
|
import io.swagger.annotations.Api;
|
26
|
import io.swagger.annotations.Api;
|
|
20
|
import io.swagger.annotations.ApiImplicitParam;
|
27
|
import io.swagger.annotations.ApiImplicitParam;
|
|
21
|
import io.swagger.annotations.ApiOperation;
|
28
|
import io.swagger.annotations.ApiOperation;
|
|
22
|
-import java.util.HashMap;
|
|
|
|
23
|
-import java.util.List;
|
|
|
|
24
|
-import java.util.Map;
|
|
|
|
25
|
-import java.util.Set;
|
|
|
|
26
|
-import java.util.stream.Collectors;
|
|
|
|
27
|
-import javax.validation.Valid;
|
|
|
|
28
|
-import javax.validation.constraints.NotBlank;
|
29
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
30
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
31
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
32
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
33
|
+import org.apache.poi.util.IOUtils;
|
|
|
|
34
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
29
|
import org.springframework.beans.factory.annotation.Autowired;
|
35
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
30
|
import org.springframework.validation.annotation.Validated;
|
36
|
import org.springframework.validation.annotation.Validated;
|
|
31
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
37
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
@@ -35,8 +41,22 @@ import org.springframework.web.bind.annotation.PutMapping; |
|
@@ -35,8 +41,22 @@ import org.springframework.web.bind.annotation.PutMapping; |
|
35
|
import org.springframework.web.bind.annotation.RequestBody;
|
41
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
36
|
import org.springframework.web.bind.annotation.RequestMapping;
|
42
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
37
|
import org.springframework.web.bind.annotation.RestController;
|
43
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
44
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
45
|
+import javax.validation.Valid;
|
|
|
|
46
|
+import javax.validation.constraints.NotBlank;
|
|
|
|
47
|
+import java.io.FileNotFoundException;
|
|
|
|
48
|
+import java.io.IOException;
|
|
|
|
49
|
+import java.io.InputStream;
|
|
|
|
50
|
+import java.math.BigDecimal;
|
|
|
|
51
|
+import java.net.URLEncoder;
|
|
|
|
52
|
+import java.time.LocalDate;
|
|
|
|
53
|
+import java.time.LocalDateTime;
|
|
|
|
54
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
55
|
+import java.util.*;
|
|
|
|
56
|
+import java.util.stream.Collectors;
|
|
38
|
|
57
|
|
|
39
|
@Api(tags = "采购计划管理")
|
58
|
@Api(tags = "采购计划管理")
|
|
|
|
59
|
+@Slf4j
|
|
40
|
@Validated
|
60
|
@Validated
|
|
41
|
@RestController
|
61
|
@RestController
|
|
42
|
@RequestMapping("/procurement/plan")
|
62
|
@RequestMapping("/procurement/plan")
|
|
@@ -46,6 +66,9 @@ public class ProcurementPlanController extends DefaultBaseController { |
|
@@ -46,6 +66,9 @@ public class ProcurementPlanController extends DefaultBaseController { |
|
46
|
private ProcurementPlanService procurementPlanService;
|
66
|
private ProcurementPlanService procurementPlanService;
|
|
47
|
@Autowired
|
67
|
@Autowired
|
|
48
|
private ProcurementBuyoutApplyService procurementBuyoutApplyService;
|
68
|
private ProcurementBuyoutApplyService procurementBuyoutApplyService;
|
|
|
|
69
|
+ @Autowired
|
|
|
|
70
|
+ private SysDataDicItemService sysDataDicItemService;
|
|
|
|
71
|
+
|
|
49
|
|
72
|
|
|
50
|
/**
|
73
|
/**
|
|
51
|
* 查询列表
|
74
|
* 查询列表
|
|
@@ -240,4 +263,289 @@ public class ProcurementPlanController extends DefaultBaseController { |
|
@@ -240,4 +263,289 @@ public class ProcurementPlanController extends DefaultBaseController { |
|
240
|
bo.setShowAbolishBuyoutApply(buyoutFlag && count > 0L);
|
263
|
bo.setShowAbolishBuyoutApply(buyoutFlag && count > 0L);
|
|
241
|
}
|
264
|
}
|
|
242
|
}
|
265
|
}
|
|
|
|
266
|
+
|
|
|
|
267
|
+ /**
|
|
|
|
268
|
+ * 导出采购计划
|
|
|
|
269
|
+ */
|
|
|
|
270
|
+ @ApiOperation("导出采购计划")
|
|
|
|
271
|
+ @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
|
|
|
|
272
|
+ @HasPermission({"plan-manage:domestic-plan:print"})
|
|
|
|
273
|
+ @GetMapping("/export")
|
|
|
|
274
|
+ public void export(@NotBlank(message = "ID不能为空!") String id,
|
|
|
|
275
|
+ HttpServletResponse response) throws IOException {
|
|
|
|
276
|
+
|
|
|
|
277
|
+ GetProcurementPlanBo plan = procurementPlanService.getDetail(id);
|
|
|
|
278
|
+ if (plan == null) {
|
|
|
|
279
|
+ throw new DefaultClientException("采购计划不存在!");
|
|
|
|
280
|
+ }
|
|
|
|
281
|
+ setupResponse(response, (plan.getCode() == null ? "" : plan.getCode()) + "-采购计划.xlsx");
|
|
|
|
282
|
+
|
|
|
|
283
|
+ GetProcurementBuyoutApplyBo buyoutApply = procurementBuyoutApplyService.findByPlanId(id);
|
|
|
|
284
|
+ ClassPathResource templateResource = new ClassPathResource("templates/planTemplate.xlsx");
|
|
|
|
285
|
+ if (buyoutApply != null) {
|
|
|
|
286
|
+ templateResource = new ClassPathResource("templates/planAndBuyoutTemplate.xlsx");
|
|
|
|
287
|
+ }
|
|
|
|
288
|
+ try {
|
|
|
|
289
|
+ try (InputStream inputStream = templateResource.getStream();
|
|
|
|
290
|
+ Workbook workbook = new XSSFWorkbook(inputStream)) {
|
|
|
|
291
|
+ try {
|
|
|
|
292
|
+ DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
293
|
+
|
|
|
|
294
|
+ // === Sheet1:采购计划主表 + 子表 ===
|
|
|
|
295
|
+ Sheet sheet1 = workbook.getSheet("计划单");
|
|
|
|
296
|
+
|
|
|
|
297
|
+ List<GetProcurementPlanBo.ProcurementPlanLineBo> planLineList = plan.getProcurementPlanLineList();
|
|
|
|
298
|
+ int planStartRow = 4; // 采购计划子表开始行,可根据模板调整
|
|
|
|
299
|
+ if (CollectionUtils.isNotEmpty(planLineList)) {
|
|
|
|
300
|
+ for (int i = 0; i < planLineList.size(); i++) {
|
|
|
|
301
|
+ GetProcurementPlanBo.ProcurementPlanLineBo line = planLineList.get(i);
|
|
|
|
302
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 0, line.getProductName());
|
|
|
|
303
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 1, line.getMaterialType());
|
|
|
|
304
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 2, line.getQuantity());
|
|
|
|
305
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 3, line.getActualPurchasePrice());
|
|
|
|
306
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 4, line.getIncludingShippingPrice());
|
|
|
|
307
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 5, line.getPriceListPrices());
|
|
|
|
308
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 6, line.getCoordinationRange());
|
|
|
|
309
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 7, line.getEstimatedLoss());
|
|
|
|
310
|
+ ExcelUtil.setCellValue(sheet1, planStartRow, 8, line.getWorkshopName());
|
|
|
|
311
|
+ planStartRow++;
|
|
|
|
312
|
+ }
|
|
|
|
313
|
+ }
|
|
|
|
314
|
+
|
|
|
|
315
|
+ Map<String, Object> planDataMap = new HashMap<>();
|
|
|
|
316
|
+ planDataMap.put("code", nvl(plan.getCode()) + nvl(plan.getPlanType()));
|
|
|
|
317
|
+ planDataMap.put("companyShortName", nvl(plan.getCompanyShortName()));
|
|
|
|
318
|
+ planDataMap.put("workshopName", nvl(plan.getWorkshopName()));
|
|
|
|
319
|
+ planDataMap.put("purchaseDepartmentName", nvl(plan.getPurchaseDepartmentName()));
|
|
|
|
320
|
+ planDataMap.put("regionName", nvl(plan.getRegionName()));
|
|
|
|
321
|
+ planDataMap.put("date", plan.getDate() == null ? "" : plan.getDate().format(dateFormatter));
|
|
|
|
322
|
+ planDataMap.put("supplierName", nvl(plan.getSupplierName()));
|
|
|
|
323
|
+ planDataMap.put("commodityBuyout", plan.getCommodityBuyout() == null ? "□" : (plan.getCommodityBuyout() ? "■" : "□"));
|
|
|
|
324
|
+ planDataMap.put("qualityBuyout", plan.getQualityBuyout() == null ? "□" : (plan.getQualityBuyout() ? "■" : "□"));
|
|
|
|
325
|
+ planDataMap.put("quantityBuyout", plan.getQuantityBuyout() == null ? "□" : (plan.getQuantityBuyout() ? "■" : "□"));
|
|
|
|
326
|
+ planDataMap.put("doorDelivery", plan.getDoorDelivery() == null ? "□" : (plan.getDoorDelivery() ? "■" : "□"));
|
|
|
|
327
|
+ planDataMap.put("longTermOperation", plan.getLongTermOperation() == null ? "□" : (plan.getLongTermOperation() ? "■" : "□"));
|
|
|
|
328
|
+ planDataMap.put("terminalCustomer", plan.getTerminalCustomer() == null ? "□" : (plan.getTerminalCustomer() ? "■" : "□"));
|
|
|
|
329
|
+ planDataMap.put("shippingCostB", plan.getShippingCost() == null ? "□" : "■");
|
|
|
|
330
|
+ planDataMap.put("shippingCost", formatDecimal(plan.getShippingCost()));
|
|
|
|
331
|
+ planDataMap.put("loadingFeeB", plan.getLoadingFee() == null ? "□" : "■");
|
|
|
|
332
|
+ planDataMap.put("loadingFee", formatDecimal(plan.getLoadingFee()));
|
|
|
|
333
|
+ planDataMap.put("otherExpenseSettlement", plan.getOtherExpenseSettlement() == null ? "□" : (plan.getOtherExpenseSettlement() ? "■" : "□"));
|
|
|
|
334
|
+ planDataMap.put("remark", nvl(plan.getRemark()));
|
|
|
|
335
|
+ planDataMap.put("totalQuantity", formatDecimal(plan.getTotalQuantity()));
|
|
|
|
336
|
+ planDataMap.put("coordinationReason", nvl(plan.getCoordinationReason()));
|
|
|
|
337
|
+ planDataMap.put("invoiceTypeStatus", nvl(plan.getInvoiceTypeStatus()));
|
|
|
|
338
|
+ planDataMap.put("invoiceProductName", nvl(plan.getInvoiceProductName()));
|
|
|
|
339
|
+ //交货日期
|
|
|
|
340
|
+ if (plan.getDeliveryDate() != null) {
|
|
|
|
341
|
+ // M 表示不补零的月份,d 表示不补零的日期
|
|
|
|
342
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d'提'");
|
|
|
|
343
|
+ String formattedDate = plan.getDeliveryDate().format(formatter);
|
|
|
|
344
|
+ planDataMap.put("deliveryDate", formattedDate);
|
|
|
|
345
|
+ } else {
|
|
|
|
346
|
+ planDataMap.put("deliveryDate", ""); // 或者你需要的默认值
|
|
|
|
347
|
+ }
|
|
|
|
348
|
+ List<SysDataDicItem> deliveryModeList = sysDataDicItemService.findByDicCode("DELIVERY_METHOD");
|
|
|
|
349
|
+ Map<String, String> deliveryModeMap = deliveryModeList.stream()
|
|
|
|
350
|
+ .collect(Collectors.toMap(SysDataDicItem::getCode, SysDataDicItem::getName, (v1, v2) -> v1));
|
|
|
|
351
|
+ planDataMap.put("deliveryMode", deliveryModeMap.get(nvl(plan.getDeliveryMode())));
|
|
|
|
352
|
+ planDataMap.put("settlementRatio", formatDecimal(plan.getSettlementRatio()));
|
|
|
|
353
|
+ planDataMap.put("priceCode", nvl(plan.getPriceCode()));
|
|
|
|
354
|
+ //启用料质状况
|
|
|
|
355
|
+ if (Boolean.TRUE.equals(plan.getMaterialConditionEnabled())) {
|
|
|
|
356
|
+ planDataMap.put("copperRiceCondition",
|
|
|
|
357
|
+ buildMaterialConditionStr("COPPER_RICE", plan.getMaterialConditionCopperRice(), -1));
|
|
|
|
358
|
+ // 光亮铜:前4后换行(多股光亮丝/表面光亮的板材/表面光亮的棒材/内外表面光亮的管材;第2行光亮丝/光亮丝铜米)
|
|
|
|
359
|
+ planDataMap.put("brightCopperCondition",
|
|
|
|
360
|
+ buildMaterialConditionStr("BRIGHT_COPPER", plan.getMaterialConditionBrightCopper(), 4));
|
|
|
|
361
|
+ // 一特:前5后换行(火烧丝/火烧扁线/表面氧化的板材/表面氧化的棒材/表面氧化的管材;第2行镀白丝…)
|
|
|
|
362
|
+ planDataMap.put("firstClassCondition",
|
|
|
|
363
|
+ buildMaterialConditionStr("FIRST_CLASS", plan.getMaterialConditionFirstClass(), 5) + " 注:镀白板不扣杂");
|
|
|
|
364
|
+ planDataMap.put("secondClassCondition",
|
|
|
|
365
|
+ buildMaterialConditionStr("SECOND_CLASS", plan.getMaterialConditionSecondClass(), -1));
|
|
|
|
366
|
+ planDataMap.put("tinCoatedCondition",
|
|
|
|
367
|
+ buildMaterialConditionStr("TIN_COATED", plan.getMaterialConditionTinCoated(), -1));
|
|
|
|
368
|
+ // 角料:前7后换行(条形料/冲片料/字牌/天线管及管料/黄铜网/铜米/油铜米;第2行火烧拉链米/纽扣/锁球)
|
|
|
|
369
|
+ planDataMap.put("scrapCondition",
|
|
|
|
370
|
+ buildMaterialConditionStr("SCRAP", plan.getMaterialConditionScrap(), 7));
|
|
|
|
371
|
+ planDataMap.put("whiteYellowCondition",
|
|
|
|
372
|
+ buildMaterialConditionStr("WHITE_YELLOW", plan.getMaterialConditionWhiteYellow(), -1));
|
|
|
|
373
|
+ planDataMap.put("phosphorCopperCondition",
|
|
|
|
374
|
+ buildMaterialConditionStr("PHOSPHOR_COPPER", plan.getMaterialConditionPhosphorCopper(), -1));
|
|
|
|
375
|
+ } else {
|
|
|
|
376
|
+ planDataMap.put("copperRiceCondition", "□清一色通讯电话线加工的米粒状,表面光亮");
|
|
|
|
377
|
+ planDataMap.put("brightCopperCondition", "□多股光亮丝 □表面光亮的板材 □表面光亮的棒材 □内外表面光亮的管材\n" +
|
|
|
|
378
|
+ "□光亮丝 □光亮丝铜米");
|
|
|
|
379
|
+ planDataMap.put("firstClassCondition", "□火烧丝 □火烧扁线 □表面氧化的板材 □表面氧化的棒材 □表面氧化的管材\n" +
|
|
|
|
380
|
+ "□镀白丝、各种镀白型材、镀白冲料 注:镀白板不扣杂");
|
|
|
|
381
|
+ planDataMap.put("secondClassCondition", "□火烧丝 □火烧扁线 □镀白丝、各种镀白型材、镀白冲料");
|
|
|
|
382
|
+ planDataMap.put("tinCoatedCondition", "□镀锡丝 □镀锡针 □镀锡冲料 □镀锡条形料 □火烧镀锡针 □镀锡板 □镀锡棒");
|
|
|
|
383
|
+ planDataMap.put("scrapCondition", "□条形料 □冲片料 □字牌 □天线管及管料 □黄铜网 □铜米 □油铜米\n" +
|
|
|
|
384
|
+ "□火烧拉链米 □纽扣 □锁球");
|
|
|
|
385
|
+ planDataMap.put("whiteYellowCondition", "□条形料 □冲片料 □天线管及管料 □纽扣 □锁球");
|
|
|
|
386
|
+ planDataMap.put("phosphorCopperCondition", "□条形料 □冲片料 □磷铜型材 □磷铜网");
|
|
|
|
387
|
+ }
|
|
|
|
388
|
+ //制单人
|
|
|
|
389
|
+ planDataMap.put("createBy", nvl(plan.getCreateBy()));
|
|
|
|
390
|
+
|
|
|
|
391
|
+ processTemplateSheet(sheet1, planDataMap);
|
|
|
|
392
|
+
|
|
|
|
393
|
+ // === Sheet2:买断操作申请单(仅当存在时填充)===
|
|
|
|
394
|
+ if (buyoutApply != null && workbook.getNumberOfSheets() > 1) {
|
|
|
|
395
|
+ Sheet sheet2 = workbook.getSheet("买断申请单");
|
|
|
|
396
|
+
|
|
|
|
397
|
+ List<ProcurementBuyoutApplyLineBo> buyoutLineList = buyoutApply.getLineList();
|
|
|
|
398
|
+ int buyoutStartRow = 3; // 买断单子表开始行,可根据模板调整
|
|
|
|
399
|
+ if (CollectionUtils.isNotEmpty(buyoutLineList)) {
|
|
|
|
400
|
+ for (int i = 0; i < buyoutLineList.size(); i++) {
|
|
|
|
401
|
+ ProcurementBuyoutApplyLineBo line = buyoutLineList.get(i);
|
|
|
|
402
|
+ ExcelUtil.setCellValue(sheet2, buyoutStartRow, 2, line.getProductName());
|
|
|
|
403
|
+ ExcelUtil.setCellValue(sheet2, buyoutStartRow, 4, line.getQuantity());
|
|
|
|
404
|
+ ExcelUtil.setCellValue(sheet2, buyoutStartRow, 6, line.getBuyoutPrice());
|
|
|
|
405
|
+ buyoutStartRow++;
|
|
|
|
406
|
+ }
|
|
|
|
407
|
+ }
|
|
|
|
408
|
+
|
|
|
|
409
|
+ int buyoutStartRow1 = 15; // 买断单子表开始行,可根据模板调整
|
|
|
|
410
|
+ if (CollectionUtils.isNotEmpty(buyoutLineList)) {
|
|
|
|
411
|
+ for (int i = 0; i < buyoutLineList.size(); i++) {
|
|
|
|
412
|
+ ProcurementBuyoutApplyLineBo line = buyoutLineList.get(i);
|
|
|
|
413
|
+ ExcelUtil.setCellValue(sheet2, buyoutStartRow1, 2, line.getEstimatedLoss());
|
|
|
|
414
|
+ ExcelUtil.setCellValue(sheet2, buyoutStartRow1, 5, line.getPureCopperPrice());
|
|
|
|
415
|
+ buyoutStartRow1++;
|
|
|
|
416
|
+ }
|
|
|
|
417
|
+ }
|
|
|
|
418
|
+
|
|
|
|
419
|
+ Map<String, Object> buyoutDataMap = new HashMap<>();
|
|
|
|
420
|
+ buyoutDataMap.put("code", nvl(buyoutApply.getCode()));
|
|
|
|
421
|
+ buyoutDataMap.put("purchaseDepartmentName", nvl(buyoutApply.getPurchaseDepartmentName()));
|
|
|
|
422
|
+ buyoutDataMap.put("regionName", nvl(buyoutApply.getRegionName()));
|
|
|
|
423
|
+ buyoutDataMap.put("date", buyoutApply.getDate() == null ? "" : buyoutApply.getDate().format(dateFormatter));
|
|
|
|
424
|
+ buyoutDataMap.put("supplierName", nvl(buyoutApply.getSupplierName()));
|
|
|
|
425
|
+ buyoutDataMap.put("paintLoss", formatDecimal(buyoutApply.getPaintLoss()));
|
|
|
|
426
|
+ buyoutDataMap.put("createBy", nvl(buyoutApply.getCreateBy()));
|
|
|
|
427
|
+
|
|
|
|
428
|
+ processTemplateSheet(sheet2, buyoutDataMap);
|
|
|
|
429
|
+ }
|
|
|
|
430
|
+
|
|
|
|
431
|
+ workbook.write(response.getOutputStream());
|
|
|
|
432
|
+ response.getOutputStream().flush();
|
|
|
|
433
|
+ } finally {
|
|
|
|
434
|
+ IOUtils.closeQuietly(workbook);
|
|
|
|
435
|
+ }
|
|
|
|
436
|
+
|
|
|
|
437
|
+ } catch (FileNotFoundException e) {
|
|
|
|
438
|
+ throw new RuntimeException("模板文件不存在: templates/planAndBuyoutTemplate.xlsx", e);
|
|
|
|
439
|
+ } catch (IOException e) {
|
|
|
|
440
|
+ throw new RuntimeException("无法读取模板文件: templates/planAndBuyoutTemplate.xlsx", e);
|
|
|
|
441
|
+ }
|
|
|
|
442
|
+ } catch (Exception e) {
|
|
|
|
443
|
+ log.error("导出采购计划失败, id={}, {}", id, e.getMessage(), e);
|
|
|
|
444
|
+ throw e;
|
|
|
|
445
|
+ }
|
|
|
|
446
|
+ }
|
|
|
|
447
|
+
|
|
|
|
448
|
+ /**
|
|
|
|
449
|
+ * 设置HTTP响应头
|
|
|
|
450
|
+ */
|
|
|
|
451
|
+ private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
|
|
|
452
|
+ String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
|
453
|
+
|
|
|
|
454
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
|
455
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
|
456
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName);
|
|
|
|
457
|
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
458
|
+ }
|
|
|
|
459
|
+
|
|
|
|
460
|
+ /**
|
|
|
|
461
|
+ * 按单 Sheet 替换模板占位符(${...} / #{...})
|
|
|
|
462
|
+ */
|
|
|
|
463
|
+ private void processTemplateSheet(Sheet sheet, Map<String, Object> dataMap) {
|
|
|
|
464
|
+ for (Row row : sheet) {
|
|
|
|
465
|
+ for (Cell cell : row) {
|
|
|
|
466
|
+ if (cell.getCellTypeEnum() == CellType.STRING) {
|
|
|
|
467
|
+ String cellValue = cell.getStringCellValue();
|
|
|
|
468
|
+ String newValue = replacePlaceholders(cellValue, dataMap);
|
|
|
|
469
|
+ if (!cellValue.equals(newValue)) {
|
|
|
|
470
|
+ cell.setCellValue(newValue);
|
|
|
|
471
|
+ }
|
|
|
|
472
|
+ }
|
|
|
|
473
|
+ }
|
|
|
|
474
|
+ }
|
|
|
|
475
|
+ }
|
|
|
|
476
|
+
|
|
|
|
477
|
+ private String replacePlaceholders(String text, Map<String, Object> dataMap) {
|
|
|
|
478
|
+ if (text == null || text.isEmpty()) {
|
|
|
|
479
|
+ return text;
|
|
|
|
480
|
+ }
|
|
|
|
481
|
+
|
|
|
|
482
|
+ String result = text;
|
|
|
|
483
|
+ for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
|
|
|
484
|
+ String placeholder = "${" + entry.getKey() + "}";
|
|
|
|
485
|
+ String value = entry.getValue() != null ? entry.getValue().toString() : "";
|
|
|
|
486
|
+ value = value.replace("\\n", "\n");
|
|
|
|
487
|
+ result = result.replace(placeholder, value);
|
|
|
|
488
|
+ }
|
|
|
|
489
|
+
|
|
|
|
490
|
+ for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
|
|
|
491
|
+ String placeholder = "#{" + entry.getKey() + "}";
|
|
|
|
492
|
+ String value = entry.getValue() != null ? entry.getValue().toString() : "";
|
|
|
|
493
|
+ value = value.replace("\\n", "\n");
|
|
|
|
494
|
+ result = result.replace(placeholder, value);
|
|
|
|
495
|
+ }
|
|
|
|
496
|
+
|
|
|
|
497
|
+ return result;
|
|
|
|
498
|
+ }
|
|
|
|
499
|
+
|
|
|
|
500
|
+ private String nvl(Object o) {
|
|
|
|
501
|
+ return o == null ? "" : o.toString();
|
|
|
|
502
|
+ }
|
|
|
|
503
|
+
|
|
|
|
504
|
+ private String formatDecimal(BigDecimal bd) {
|
|
|
|
505
|
+ if (bd == null) {
|
|
|
|
506
|
+ return "";
|
|
|
|
507
|
+ }
|
|
|
|
508
|
+ return bd.stripTrailingZeros().toPlainString();
|
|
|
|
509
|
+ }
|
|
|
|
510
|
+
|
|
|
|
511
|
+ /**
|
|
|
|
512
|
+ * 料质状况复选框拼接
|
|
|
|
513
|
+ *
|
|
|
|
514
|
+ * @param dicCode 字典编码
|
|
|
|
515
|
+ * @param selectedCodeStr 已选中的字典项code,逗号分隔
|
|
|
|
516
|
+ * @param itemsPerLine 每行多少项后换行;<=0 表示不换行
|
|
|
|
517
|
+ * @return 形如 ☑选项1 □选项2\n☑选项3
|
|
|
|
518
|
+ */
|
|
|
|
519
|
+ private String buildMaterialConditionStr(String dicCode, String selectedCodeStr, int itemsPerLine) {
|
|
|
|
520
|
+ List<SysDataDicItem> dicItemList = sysDataDicItemService.findByDicCode(dicCode);
|
|
|
|
521
|
+ if (CollectionUtils.isEmpty(dicItemList)) {
|
|
|
|
522
|
+ return "";
|
|
|
|
523
|
+ }
|
|
|
|
524
|
+
|
|
|
|
525
|
+ Set<String> selectedCodes = new HashSet<>();
|
|
|
|
526
|
+ if (StringUtils.isNotBlank(selectedCodeStr)) {
|
|
|
|
527
|
+ selectedCodes = Arrays.stream(selectedCodeStr.split(","))
|
|
|
|
528
|
+ .map(String::trim)
|
|
|
|
529
|
+ .filter(StringUtils::isNotBlank)
|
|
|
|
530
|
+ .collect(Collectors.toSet());
|
|
|
|
531
|
+ }
|
|
|
|
532
|
+
|
|
|
|
533
|
+ Set<String> finalSelectedCodes = selectedCodes;
|
|
|
|
534
|
+ List<String> lines = new ArrayList<>();
|
|
|
|
535
|
+ List<String> currentLine = new ArrayList<>();
|
|
|
|
536
|
+ int idx = 0;
|
|
|
|
537
|
+ for (SysDataDicItem item : dicItemList) {
|
|
|
|
538
|
+ String prefix = finalSelectedCodes.contains(item.getCode()) ? "☑" : "□";
|
|
|
|
539
|
+ currentLine.add(prefix + item.getName());
|
|
|
|
540
|
+ idx++;
|
|
|
|
541
|
+ if (itemsPerLine > 0 && idx % itemsPerLine == 0) {
|
|
|
|
542
|
+ lines.add(String.join(" ", currentLine));
|
|
|
|
543
|
+ currentLine.clear();
|
|
|
|
544
|
+ }
|
|
|
|
545
|
+ }
|
|
|
|
546
|
+ if (!currentLine.isEmpty()) {
|
|
|
|
547
|
+ lines.add(String.join(" ", currentLine));
|
|
|
|
548
|
+ }
|
|
|
|
549
|
+ return String.join("\n", lines);
|
|
|
|
550
|
+ }
|
|
243
|
} |
551
|
} |