Commit 3a11c06382cffb12e253152a0592179762e9a68f

Authored by yeqianyong
1 parent 58ce32a4

楚江ERP-发货单批量打印接口开发

@@ -167,7 +167,7 @@ public class OrderChangeRecordController extends DefaultBaseController { @@ -167,7 +167,7 @@ public class OrderChangeRecordController extends DefaultBaseController {
167 try (InputStream inputStream = templateResource.getStream(); 167 try (InputStream inputStream = templateResource.getStream();
168 Workbook workbook = new XSSFWorkbook(inputStream)) { 168 Workbook workbook = new XSSFWorkbook(inputStream)) {
169 // 设置响应头 169 // 设置响应头
170 - ResponseUtil.setResponseHead(response, data.getOrderNo() + "-订货单变更记录.xlsx"); 170 + ResponseUtil.setExcelResponseHead(response, data.getOrderNo() + "-订货单变更记录.xlsx");
171 171
172 Sheet sheet = workbook.getSheetAt(0); 172 Sheet sheet = workbook.getSheetAt(0);
173 // 规格变更开始行 173 // 规格变更开始行
1 package com.lframework.xingyun.sc.controller.shipments; 1 package com.lframework.xingyun.sc.controller.shipments;
2 2
  3 +import cn.hutool.core.io.resource.ClassPathResource;
  4 +import com.lframework.starter.web.core.utils.JsonUtil;
  5 +import com.lframework.starter.web.inner.entity.SysUser;
  6 +import com.lframework.starter.web.inner.service.system.SysUserService;
3 import com.lframework.xingyun.sc.bo.shipments.order.GetShipmentsOrderInfoBo; 7 import com.lframework.xingyun.sc.bo.shipments.order.GetShipmentsOrderInfoBo;
4 import com.lframework.xingyun.sc.bo.shipments.order.QueryShipmentsOrderInfoBo; 8 import com.lframework.xingyun.sc.bo.shipments.order.QueryShipmentsOrderInfoBo;
5 import com.lframework.xingyun.sc.bo.shipments.plan.ShipmentsPlanDetailBo; 9 import com.lframework.xingyun.sc.bo.shipments.plan.ShipmentsPlanDetailBo;
6 import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail; 10 import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
7 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService; 11 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
  12 +import com.lframework.xingyun.sc.utils.ExcelUtil;
  13 +import com.lframework.xingyun.sc.utils.LatexFormulaExcelExporterUtil;
  14 +import com.lframework.xingyun.sc.utils.ResponseUtil;
8 import com.lframework.xingyun.sc.vo.shipments.order.*; 15 import com.lframework.xingyun.sc.vo.shipments.order.*;
9 import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService; 16 import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
10 import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo; 17 import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
@@ -13,6 +20,7 @@ import com.lframework.starter.web.core.components.resp.PageResult; @@ -13,6 +20,7 @@ import com.lframework.starter.web.core.components.resp.PageResult;
13 import com.lframework.starter.web.core.components.resp.InvokeResult; 20 import com.lframework.starter.web.core.components.resp.InvokeResult;
14 21
15 import javax.annotation.Resource; 22 import javax.annotation.Resource;
  23 +import javax.servlet.http.HttpServletResponse;
16 import javax.validation.constraints.NotBlank; 24 import javax.validation.constraints.NotBlank;
17 import io.swagger.annotations.ApiImplicitParam; 25 import io.swagger.annotations.ApiImplicitParam;
18 import com.lframework.starter.web.core.components.resp.InvokeResultBuilder; 26 import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
@@ -20,6 +28,12 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException; @@ -20,6 +28,12 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException;
20 import io.swagger.annotations.ApiOperation; 28 import io.swagger.annotations.ApiOperation;
21 import com.lframework.starter.common.utils.CollectionUtil; 29 import com.lframework.starter.common.utils.CollectionUtil;
22 import io.swagger.annotations.Api; 30 import io.swagger.annotations.Api;
  31 +import lombok.extern.slf4j.Slf4j;
  32 +import org.apache.commons.collections4.CollectionUtils;
  33 +import org.apache.commons.lang3.StringUtils;
  34 +import org.apache.poi.ss.usermodel.Sheet;
  35 +import org.apache.poi.ss.usermodel.Workbook;
  36 +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
23 import org.springframework.web.bind.annotation.DeleteMapping; 37 import org.springframework.web.bind.annotation.DeleteMapping;
24 import com.lframework.starter.web.core.controller.DefaultBaseController; 38 import com.lframework.starter.web.core.controller.DefaultBaseController;
25 import com.lframework.starter.web.core.annotations.security.HasPermission; 39 import com.lframework.starter.web.core.annotations.security.HasPermission;
@@ -27,8 +41,19 @@ import org.springframework.validation.annotation.Validated; @@ -27,8 +41,19 @@ import org.springframework.validation.annotation.Validated;
27 import org.springframework.web.bind.annotation.*; 41 import org.springframework.web.bind.annotation.*;
28 42
29 import javax.validation.Valid; 43 import javax.validation.Valid;
  44 +import java.io.*;
  45 +import java.math.BigDecimal;
  46 +import java.math.RoundingMode;
  47 +import java.nio.file.Files;
  48 +import java.nio.file.Path;
  49 +import java.time.format.DateTimeFormatter;
  50 +import java.util.ArrayList;
  51 +import java.util.Comparator;
30 import java.util.List; 52 import java.util.List;
  53 +import java.util.Map;
31 import java.util.stream.Collectors; 54 import java.util.stream.Collectors;
  55 +import java.util.zip.ZipEntry;
  56 +import java.util.zip.ZipOutputStream;
32 57
33 /** 58 /**
34 * 发货单 Controller 59 * 发货单 Controller
@@ -36,6 +61,7 @@ import java.util.stream.Collectors; @@ -36,6 +61,7 @@ import java.util.stream.Collectors;
36 */ 61 */
37 @Api(tags = "发货单") 62 @Api(tags = "发货单")
38 @Validated 63 @Validated
  64 +@Slf4j
39 @RestController 65 @RestController
40 @RequestMapping("/shipments/order") 66 @RequestMapping("/shipments/order")
41 public class ShipmentsOrderInfoController extends DefaultBaseController { 67 public class ShipmentsOrderInfoController extends DefaultBaseController {
@@ -45,6 +71,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { @@ -45,6 +71,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
45 private ShipmentsOrderInfoService shipmentsOrderInfoService; 71 private ShipmentsOrderInfoService shipmentsOrderInfoService;
46 @Resource 72 @Resource
47 private ShipmentsPlanDetailService shipmentsPlanDetailService; 73 private ShipmentsPlanDetailService shipmentsPlanDetailService;
  74 + @Resource
  75 + private SysUserService sysUserService;
48 76
49 77
50 /** 78 /**
@@ -164,4 +192,252 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { @@ -164,4 +192,252 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
164 shipmentsOrderInfoService.saveSignInTicket(vo); 192 shipmentsOrderInfoService.saveSignInTicket(vo);
165 return InvokeResultBuilder.success(); 193 return InvokeResultBuilder.success();
166 } 194 }
  195 +
  196 +
  197 + /**
  198 + * 发货单批量打印
  199 + * @param vo 打印参数
  200 + * @param response 响应体
  201 + */
  202 + @ApiOperation("发货单批量打印")
  203 + @GetMapping("/batchPrintShipmentsOrder")
  204 + public void batchPrintShipmentsOrder(@Valid ExportShipmentsOrderVo vo, HttpServletResponse response) {
  205 + List<ShipmentsOrderInfo> orderInfoList = shipmentsOrderInfoService.listByIds(vo.getIds());
  206 + if (CollectionUtils.isEmpty(orderInfoList)) {
  207 + throw new DefaultClientException("发货单不存在!");
  208 + }
  209 + // 加载模板文件
  210 + String templatePath = "templates/shipmentsOrderTemplate_02.xlsx";
  211 + if ("TYPE_1".equals(vo.getType())) {
  212 + templatePath = "templates/shipmentsOrderTemplate_01.xlsx";
  213 + }
  214 + // 创建临时目录
  215 + Path tempDir = null;
  216 + File zipFile = null;
  217 + try {
  218 + // 设置响应头
  219 + ResponseUtil.setZipResponseHead(response, "发货单.zip");
  220 + // 创建临时目录存放Excel文件
  221 + tempDir = Files.createTempDirectory("/tmp/shipments_order_export");
  222 +
  223 + List<String> shipmentsOrderIds = new ArrayList<>();
  224 + for (ShipmentsOrderInfo orderInfo : orderInfoList) {
  225 + String id = orderInfo.getId();
  226 + shipmentsOrderIds.add(id);
  227 + }
  228 + List<ShipmentsPlanDetail> detailList = shipmentsPlanDetailService.listByShipmentOrderId(shipmentsOrderIds);
  229 + if (CollectionUtils.isEmpty(detailList)) {
  230 + throw new DefaultClientException("发货单明细不存在!");
  231 + }
  232 + // 按发货单ID分组明细数据
  233 + Map<String, List<ShipmentsPlanDetail>> shipmentsOrderDetailMap = detailList.stream()
  234 + .collect(Collectors.groupingBy(ShipmentsPlanDetail::getShipmentOrderId));
  235 + // 为每个发货单生成Excel文件
  236 + List<File> excelFiles = new ArrayList<>();
  237 + for (ShipmentsOrderInfo orderInfo : orderInfoList) {
  238 + String id = orderInfo.getId();
  239 + List<ShipmentsPlanDetail> details = shipmentsOrderDetailMap.get(id);
  240 + if (CollectionUtils.isEmpty(details)) {
  241 + throw new DefaultClientException("发货单明细不存在!");
  242 + }
  243 + // 生成单个Excel文件(使用模板引擎)
  244 + File excelFile = generateExcelWithTemplate(orderInfo, details, templatePath, tempDir, vo.getType());
  245 + if (excelFile != null) {
  246 + excelFiles.add(excelFile);
  247 + }
  248 + }
  249 + // 创建ZIP压缩包
  250 + createZipFile(excelFiles, "发货单批量导出_" + System.currentTimeMillis() + ".zip");
  251 + } catch (FileNotFoundException e) {
  252 + log.error("发货单批量打印失败: ", e);
  253 + throw new DefaultClientException("模板文件不存在: " + templatePath);
  254 + } catch (IOException e) {
  255 + log.error("发货单批量打印失败: ", e);
  256 + throw new DefaultClientException("无法读取模板文件: " + templatePath);
  257 + } catch (Exception e) {
  258 + log.error("发货单批量打印失败: ", e);
  259 + throw new DefaultClientException(e.getMessage());
  260 + } finally {
  261 + // 清理临时文件
  262 + cleanupTempFiles(tempDir, zipFile);
  263 + }
  264 + }
  265 +
  266 +
  267 + /**
  268 + * 生成excel文件
  269 + *
  270 + * @param orderInfo 发货单
  271 + * @param detailList 发货单明细
  272 + * @param templatePath 模板文件路径
  273 + * @param tempDir 临时目录
  274 + * @return File
  275 + * @throws IOException 抛出异常
  276 + */
  277 + private File generateExcelWithTemplate(ShipmentsOrderInfo orderInfo, List<ShipmentsPlanDetail> detailList, String templatePath, Path tempDir
  278 + , String type) throws IOException {
  279 + ClassPathResource templateResource = new ClassPathResource(templatePath);
  280 + try (InputStream inputStream = templateResource.getStream();
  281 + Workbook workbook = new XSSFWorkbook(inputStream)) {
  282 + Sheet sheet = workbook.getSheetAt(0);
  283 + // 发货单明细开始行
  284 + int startRow = 4;
  285 + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  286 + for (int i = startRow + 1; i < startRow + detailList.size(); i++) {
  287 + ExcelUtil.copyRow(workbook, sheet, startRow, i);
  288 + }
  289 + BigDecimal totalQuantity = BigDecimal.ZERO;
  290 + BigDecimal totalActualQuantity = BigDecimal.ZERO;
  291 + BigDecimal totalNum = BigDecimal.ZERO;
  292 + BigDecimal totalPrice = BigDecimal.ZERO;
  293 + for (ShipmentsPlanDetail detail : detailList) {
  294 + BigDecimal quantity = detail.getQuantity() == null ? BigDecimal.ZERO : detail.getQuantity();
  295 + BigDecimal actualQuantity = detail.getActualShipmentQuantity() == null ? BigDecimal.ZERO : new BigDecimal(detail.getActualShipmentQuantity());
  296 + BigDecimal num = detail.getNum() == null ? BigDecimal.ZERO : new BigDecimal(detail.getNum());
  297 +
  298 + totalQuantity = totalQuantity.add(quantity);
  299 + totalActualQuantity = totalActualQuantity.add(actualQuantity);
  300 + totalNum = totalNum.add(num);
  301 + // 计算总金额
  302 + if (detail.getSalesPrice() != null) {
  303 + BigDecimal result = actualQuantity.multiply(detail.getSalesPrice());
  304 + totalPrice = totalPrice.add(result);
  305 + }
  306 + }
  307 + for (ShipmentsPlanDetail detail : detailList) {
  308 + ExcelUtil.setCellValue(sheet, startRow, 0, detail.getOrderNo());
  309 + ExcelUtil.setCellValue(sheet, startRow, 1, detail.getBrand());
  310 + // 处理规格数据
  311 + List<LatexFormulaExcelExporterUtil.FormulaComponent> formulaComponentList = new ArrayList<>(3);
  312 + if (detail.getThickness() != null) {
  313 + LatexFormulaExcelExporterUtil.FormulaComponent formulaComponent = new LatexFormulaExcelExporterUtil.FormulaComponent();
  314 + formulaComponent.setBase(detail.getThickness());
  315 + formulaComponent.setSup(detail.getThicknessTolPos());
  316 + formulaComponent.setSub(detail.getThicknessTolNeg());
  317 + formulaComponentList.add(formulaComponent);
  318 + }
  319 + if (detail.getWidth() != null) {
  320 + LatexFormulaExcelExporterUtil.FormulaComponent formulaComponent = new LatexFormulaExcelExporterUtil.FormulaComponent();
  321 + formulaComponent.setBase(detail.getWidth());
  322 + formulaComponent.setSup(detail.getWidthTolPos());
  323 + formulaComponent.setSub(detail.getWidthTolNeg());
  324 + formulaComponentList.add(formulaComponent);
  325 + }
  326 + if (detail.getLength() != null) {
  327 + LatexFormulaExcelExporterUtil.FormulaComponent formulaComponent = new LatexFormulaExcelExporterUtil.FormulaComponent();
  328 + formulaComponent.setBase(detail.getLength());
  329 + formulaComponent.setSup(detail.getLengthTolPos());
  330 + formulaComponent.setSub(detail.getLengthTolNeg());
  331 + formulaComponentList.add(formulaComponent);
  332 + }
  333 + String latex = LatexFormulaExcelExporterUtil.convertToLatex(formulaComponentList);
  334 + if (StringUtils.isNotBlank(latex)) {
  335 + LatexFormulaExcelExporterUtil.insertLatexImageToCell(workbook, sheet, latex, startRow, 4, 1, 7);
  336 + }
  337 + // 处理订单类型
  338 + String orderType = handleContractType(detail.getContractType());
  339 +
  340 + ExcelUtil.setCellValue(sheet, startRow, 9, detail.getQuantity());
  341 + if ("TYPE_2".equals(type)) {
  342 + ExcelUtil.setCellValue(sheet, startRow, 10, detail.getActualShipmentQuantity());
  343 + ExcelUtil.setCellValue(sheet, startRow, 11, detail.getNum());
  344 + ExcelUtil.setCellValue(sheet, startRow, 12, detail.getSalesPrice());
  345 + ExcelUtil.setCellValue(sheet, startRow, 13, orderType);
  346 + ExcelUtil.setCellValue(sheet, startRow, 14, detail.getYieldBatchNo());
  347 + } else {
  348 + ExcelUtil.setCellValue(sheet, startRow, 13, detail.getPackagingFee());
  349 + ExcelUtil.setCellValue(sheet, startRow, 15, orderType);
  350 + }
  351 + startRow++;
  352 + }
  353 + // 准备模板数据
  354 + Map<String, Object> dataMap = JsonUtil.parseMap(JsonUtil.toJsonString(orderInfo), String.class, Object.class);
  355 + dataMap.put("createDate", dateFormatter.format(orderInfo.getCreateTime()));
  356 + SysUser user = sysUserService.findById(orderInfo.getCreateById());
  357 + dataMap.put("createBy", user.getName());
  358 + dataMap.put("totalQuantity", totalQuantity.setScale(2, RoundingMode.HALF_UP));
  359 + dataMap.put("totalActualQuantity", totalActualQuantity.setScale(2, RoundingMode.HALF_UP));
  360 + dataMap.put("totalNum", totalNum.setScale(2, RoundingMode.HALF_UP));
  361 + dataMap.put("totalPrice", totalPrice.setScale(2, RoundingMode.HALF_UP));
  362 + // 流水号
  363 + String serialNumber = "";
  364 + // 处理模板中的占位符
  365 + ExcelUtil.processTemplate(workbook, dataMap);
  366 + // 生成文件名
  367 + String fileName = String.format("发货单_%s.xlsx", serialNumber);
  368 + File excelFile = new File(tempDir.toFile(), fileName);
  369 + // 保存Excel文件
  370 + try (FileOutputStream fos = new FileOutputStream(excelFile)) {
  371 + workbook.write(fos);
  372 + }
  373 + return excelFile;
  374 + } catch (IOException e) {
  375 + log.error("生成发货单Excel失败, 发货单ID: {}", orderInfo.getId(), e);
  376 + return null;
  377 + }
  378 + }
  379 +
  380 + /**
  381 + * 处理订单类型
  382 + *
  383 + * @param contractType 合同类型
  384 + * @return String
  385 + */
  386 + private String handleContractType(String contractType) {
  387 + String result = "";
  388 + if ("DISTRIB_STD".equals(contractType) || "DIST_STOCK_CONTRACT".equals(contractType)
  389 + || "DRAFT_DIST_AGMT".equals(contractType)) {
  390 + result = "经销";
  391 + } else if ("INTL_STD_CONTRACT".equals(contractType) || "INTL_INVENTORY_AGMT".equals(contractType)
  392 + || "INTL_OPEN_SPEC_AGMT".equals(contractType)) {
  393 + result = "外贸";
  394 + } else if ("PROCESS_STD_AGMT".equals(contractType)) {
  395 + result = "加工";
  396 + }
  397 + return result;
  398 + }
  399 +
  400 +
  401 + /**
  402 + * 创建ZIP压缩包
  403 + */
  404 + private void createZipFile(List<File> excelFiles, String zipFileName) throws IOException {
  405 + File zipFile = File.createTempFile("/tmp/shipments_order_export", ".zip");
  406 + try (FileOutputStream fos = new FileOutputStream(zipFile);
  407 + ZipOutputStream zos = new ZipOutputStream(fos)) {
  408 + byte[] buffer = new byte[1024];
  409 + for (File excelFile : excelFiles) {
  410 + try (FileInputStream fis = new FileInputStream(excelFile)) {
  411 + ZipEntry zipEntry = new ZipEntry(excelFile.getName());
  412 + zos.putNextEntry(zipEntry);
  413 + int length;
  414 + while ((length = fis.read(buffer)) > 0) {
  415 + zos.write(buffer, 0, length);
  416 + }
  417 + zos.closeEntry();
  418 + }
  419 + }
  420 + }
  421 + }
  422 +
  423 + /**
  424 + * 清理临时文件
  425 + */
  426 + private void cleanupTempFiles(Path tempDir, File zipFile) {
  427 + try {
  428 + // 删除临时目录
  429 + if (tempDir != null && Files.exists(tempDir)) {
  430 + Files.walk(tempDir)
  431 + .sorted(Comparator.reverseOrder())
  432 + .map(Path::toFile)
  433 + .forEach(File::delete);
  434 + }
  435 + // 清理
  436 + if (zipFile != null && zipFile.exists()) {
  437 + zipFile.delete();
  438 + }
  439 + } catch (IOException e) {
  440 + log.warn("清理临时文件失败", e);
  441 + }
  442 + }
167 } 443 }
@@ -386,29 +386,29 @@ public class CustomerDevelopPlanServiceImpl extends BaseMpServiceImpl<CustomerDe @@ -386,29 +386,29 @@ public class CustomerDevelopPlanServiceImpl extends BaseMpServiceImpl<CustomerDe
386 if ("一分厂".equals(workshopName)) { 386 if ("一分厂".equals(workshopName)) {
387 // 经营办主管 387 // 经营办主管
388 roleCodeList.add("yfcjybzg"); 388 roleCodeList.add("yfcjybzg");
389 - // 生产经理  
390 - roleCodeList.add("yfcscjl"); 389 + // 生产分管
  390 + roleCodeList.add("yfcscfg");
391 // 品质经理 391 // 品质经理
392 roleCodeList.add("yfcpzjl"); 392 roleCodeList.add("yfcpzjl");
393 } else if ("二分厂".equals(workshopName)) { 393 } else if ("二分厂".equals(workshopName)) {
394 // 经营办主管 394 // 经营办主管
395 roleCodeList.add("efcjybzg"); 395 roleCodeList.add("efcjybzg");
396 - // 生产经理  
397 - roleCodeList.add("efcscjl"); 396 + // 生产分管
  397 + roleCodeList.add("efcscfg");
398 // 品质经理 398 // 品质经理
399 roleCodeList.add("efcpzjl"); 399 roleCodeList.add("efcpzjl");
400 } else if ("三分厂".equals(workshopName)) { 400 } else if ("三分厂".equals(workshopName)) {
401 // 经营办主管 401 // 经营办主管
402 roleCodeList.add("sfcjybzg"); 402 roleCodeList.add("sfcjybzg");
403 - // 生产经理  
404 - roleCodeList.add("sfcscjl"); 403 + // 生产分管
  404 + roleCodeList.add("sfcscfg");
405 // 品质经理 405 // 品质经理
406 roleCodeList.add("sfcpzjl"); 406 roleCodeList.add("sfcpzjl");
407 } else if ("四分厂".equals(workshopName) || "紫铜厂".equals(workshopName)) { 407 } else if ("四分厂".equals(workshopName) || "紫铜厂".equals(workshopName)) {
408 // 经营办主管 408 // 经营办主管
409 roleCodeList.add("ztcjybzg"); 409 roleCodeList.add("ztcjybzg");
410 - // 生产经理  
411 - roleCodeList.add("ztcscjl"); 410 + // 生产分管
  411 + roleCodeList.add("ztcscfg");
412 // 品质经理 412 // 品质经理
413 roleCodeList.add("ztcpzjl"); 413 roleCodeList.add("ztcpzjl");
414 } 414 }
1 package com.lframework.xingyun.sc.impl.shipments; 1 package com.lframework.xingyun.sc.impl.shipments;
2 2
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
3 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 4 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
4 import com.baomidou.mybatisplus.core.toolkit.Wrappers; 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5 import com.github.pagehelper.PageInfo; 6 import com.github.pagehelper.PageInfo;
@@ -84,6 +85,17 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr @@ -84,6 +85,17 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
84 85
85 @Override 86 @Override
86 public List<ShipmentsOrderInfo> query(QueryShipmentsOrderInfoVo vo) { 87 public List<ShipmentsOrderInfo> query(QueryShipmentsOrderInfoVo vo) {
  88 + if (StringUtils.isNotBlank(vo.getDeptName())) {
  89 + // 办事处模糊查询处理
  90 + LambdaQueryWrapper<SysDept> queryWrapper = Wrappers.lambdaQuery(SysDept.class);
  91 + queryWrapper.like(SysDept::getName, vo.getDeptName());
  92 + List<SysDept> deptList = sysDeptService.getBaseMapper().selectList(queryWrapper);
  93 + if (CollectionUtils.isEmpty(deptList)) {
  94 + return Collections.emptyList();
  95 + }
  96 + List<String> deptIds = deptList.stream().map(SysDept::getId).collect(Collectors.toList());
  97 + vo.setDeptIds(deptIds);
  98 + }
87 List<ShipmentsOrderInfo> shipmentsOrderList = getBaseMapper().query(vo); 99 List<ShipmentsOrderInfo> shipmentsOrderList = getBaseMapper().query(vo);
88 if (CollectionUtils.isEmpty(shipmentsOrderList)) { 100 if (CollectionUtils.isEmpty(shipmentsOrderList)) {
89 return Collections.emptyList(); 101 return Collections.emptyList();
@@ -297,7 +297,15 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP @@ -297,7 +297,15 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
297 if (StringUtils.isBlank(shipmentOrderId)) { 297 if (StringUtils.isBlank(shipmentOrderId)) {
298 return Collections.emptyList(); 298 return Collections.emptyList();
299 } 299 }
300 - return getBaseMapper().listByShipmentOrderId(shipmentOrderId); 300 + return getBaseMapper().listByShipmentOrderId(Collections.singletonList(shipmentOrderId));
  301 + }
  302 +
  303 + @Override
  304 + public List<ShipmentsPlanDetail> listByShipmentOrderId(List<String> shipmentOrderIds) {
  305 + if (CollectionUtils.isEmpty(shipmentOrderIds)) {
  306 + return Collections.emptyList();
  307 + }
  308 + return getBaseMapper().listByShipmentOrderId(shipmentOrderIds);
301 } 309 }
302 310
303 @Override 311 @Override
@@ -43,10 +43,10 @@ public interface ShipmentsPlanDetailMapper extends BaseMapper<ShipmentsPlanDetai @@ -43,10 +43,10 @@ public interface ShipmentsPlanDetailMapper extends BaseMapper<ShipmentsPlanDetai
43 /** 43 /**
44 * 根据发货单ID查询 44 * 根据发货单ID查询
45 * 45 *
46 - * @param shipmentOrderId 发货单ID 46 + * @param shipmentOrderIds 发货单ID集合
47 * @return List<ShipmentsPlanDetail> 47 * @return List<ShipmentsPlanDetail>
48 */ 48 */
49 - List<ShipmentsPlanDetail> listByShipmentOrderId(String shipmentOrderId); 49 + List<ShipmentsPlanDetail> listByShipmentOrderId(@Param("shipmentOrderIds") List<String> shipmentOrderIds);
50 50
51 /** 51 /**
52 * 根据计划ID查询 52 * 根据计划ID查询
@@ -88,6 +88,7 @@ public interface ShipmentsPlanDetailService extends BaseMpService<ShipmentsPlanD @@ -88,6 +88,7 @@ public interface ShipmentsPlanDetailService extends BaseMpService<ShipmentsPlanD
88 * @return List<ShipmentsPlanDetail> 88 * @return List<ShipmentsPlanDetail>
89 */ 89 */
90 List<ShipmentsPlanDetail> listByShipmentOrderId(String shipmentOrderId); 90 List<ShipmentsPlanDetail> listByShipmentOrderId(String shipmentOrderId);
  91 + List<ShipmentsPlanDetail> listByShipmentOrderId(List<String> shipmentOrderIds);
91 92
92 /** 93 /**
93 * 批量设置发货单ID 94 * 批量设置发货单ID
@@ -2,6 +2,7 @@ package com.lframework.xingyun.sc.utils; @@ -2,6 +2,7 @@ package com.lframework.xingyun.sc.utils;
2 2
3 import lombok.extern.slf4j.Slf4j; 3 import lombok.extern.slf4j.Slf4j;
4 import org.apache.poi.ss.usermodel.*; 4 import org.apache.poi.ss.usermodel.*;
  5 +import org.springframework.http.HttpHeaders;
5 6
6 import javax.servlet.http.HttpServletResponse; 7 import javax.servlet.http.HttpServletResponse;
7 import javax.swing.*; 8 import javax.swing.*;
@@ -15,8 +16,9 @@ public class ResponseUtil { @@ -15,8 +16,9 @@ public class ResponseUtil {
15 16
16 /** 17 /**
17 * 设置HTTP响应头 18 * 设置HTTP响应头
  19 + * excel
18 */ 20 */
19 - public static void setResponseHead(HttpServletResponse response, String fileName) throws IOException { 21 + public static void setExcelResponseHead(HttpServletResponse response, String fileName) throws IOException {
20 String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); 22 String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
21 23
22 response.setContentType("application/vnd.ms-excel"); 24 response.setContentType("application/vnd.ms-excel");
@@ -26,4 +28,18 @@ public class ResponseUtil { @@ -26,4 +28,18 @@ public class ResponseUtil {
26 } 28 }
27 29
28 30
  31 + /**
  32 + * 设置HTTP响应头
  33 + * zip
  34 + */
  35 + public static void setZipResponseHead(HttpServletResponse response, String fileName) throws IOException {
  36 + String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
  37 +
  38 + response.setContentType("application/zip");
  39 + response.setCharacterEncoding("UTF-8");
  40 + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\"");
  41 + response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate");
  42 + }
  43 +
  44 +
29 } 45 }
  1 +package com.lframework.xingyun.sc.vo.shipments.order;
  2 +
  3 +import com.lframework.starter.web.core.vo.BaseVo;
  4 +import com.lframework.starter.web.core.vo.PageVo;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +
  8 +import javax.validation.constraints.NotBlank;
  9 +import javax.validation.constraints.NotEmpty;
  10 +import java.io.Serializable;
  11 +import java.util.List;
  12 +
  13 +@Data
  14 +public class ExportShipmentsOrderVo extends PageVo implements BaseVo, Serializable {
  15 +
  16 + private static final long serialVersionUID = 1L;
  17 +
  18 + /**
  19 + * ID集合
  20 + */
  21 + @ApiModelProperty("ID集合")
  22 + @NotEmpty(message = "id不能为空!")
  23 + private List<String> ids;
  24 +
  25 + /**
  26 + * 类型
  27 + * TYPE_1:记账联
  28 + * TYPE_2:客户联
  29 + */
  30 + @ApiModelProperty("类型")
  31 + @NotBlank(message = "打印类型不能为空!")
  32 + private String type;
  33 +}
@@ -7,6 +7,7 @@ import com.lframework.starter.web.core.vo.BaseVo; @@ -7,6 +7,7 @@ import com.lframework.starter.web.core.vo.BaseVo;
7 import com.lframework.starter.web.core.components.validation.TypeMismatch; 7 import com.lframework.starter.web.core.components.validation.TypeMismatch;
8 import io.swagger.annotations.ApiModelProperty; 8 import io.swagger.annotations.ApiModelProperty;
9 import java.io.Serializable; 9 import java.io.Serializable;
  10 +import java.util.List;
10 11
11 @Data 12 @Data
12 public class QueryShipmentsOrderInfoVo extends PageVo implements BaseVo, Serializable { 13 public class QueryShipmentsOrderInfoVo extends PageVo implements BaseVo, Serializable {
@@ -38,6 +39,7 @@ public class QueryShipmentsOrderInfoVo extends PageVo implements BaseVo, Seriali @@ -38,6 +39,7 @@ public class QueryShipmentsOrderInfoVo extends PageVo implements BaseVo, Seriali
38 */ 39 */
39 @ApiModelProperty("办事处ID") 40 @ApiModelProperty("办事处ID")
40 private String deptId; 41 private String deptId;
  42 + private List<String> deptIds;
41 43
42 /** 44 /**
43 * 办事处名称 45 * 办事处名称
@@ -54,8 +54,12 @@ @@ -54,8 +54,12 @@
54 <if test="vo.shipmentsDateEnd != null"> 54 <if test="vo.shipmentsDateEnd != null">
55 AND tb.shipments_date &lt;= #{vo.shipmentsDateEnd} 55 AND tb.shipments_date &lt;= #{vo.shipmentsDateEnd}
56 </if> 56 </if>
57 - <if test="vo.deptId != null and vo.deptId != ''">  
58 - AND tb.dept_id = #{vo.deptId} 57 + <if test="vo.deptIds != null and vo.deptIds.size() > 0">
  58 + AND (
  59 + <foreach collection="vo.deptIds" item="deptId" separator=" OR ">
  60 + FIND_IN_SET(#{deptId}, tb.dept_id) > 0
  61 + </foreach>
  62 + )
59 </if> 63 </if>
60 <if test="vo.status != null and vo.status != ''"> 64 <if test="vo.status != null and vo.status != ''">
61 AND tb.status = #{vo.status} 65 AND tb.status = #{vo.status}
@@ -212,7 +212,10 @@ @@ -212,7 +212,10 @@
212 LEFT JOIN base_data_customer c ON o.ordering_unit = c.id 212 LEFT JOIN base_data_customer c ON o.ordering_unit = c.id
213 LEFT JOIN tbl_purchase_order_line ol ON tb.order_spec_id = ol.id 213 LEFT JOIN tbl_purchase_order_line ol ON tb.order_spec_id = ol.id
214 WHERE tb.del_flag = false 214 WHERE tb.del_flag = false
215 - AND tb.shipment_order_id = #{shipmentOrderId} 215 + AND tb.shipment_order_id in
  216 + <foreach collection="shipmentOrderIds" open="(" separator="," close=")" item="item">
  217 + #{item}
  218 + </foreach>
216 </select> 219 </select>
217 220
218 <select id="listByPlanId" resultType="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail"> 221 <select id="listByPlanId" resultType="com.lframework.xingyun.sc.entity.ShipmentsPlanDetail">