Prechádzať zdrojové kódy

修改出入库导出字段

fgd 1 rok pred
rodič
commit
1d8812ffa5

+ 2 - 12
sd-business/src/main/java/com/sd/business/controller/in/InOutStorageBomController.java

@@ -50,18 +50,8 @@ public class InOutStorageBomController {
      * 出入库bom导出
      */
     @PostMapping("/exportExcel")
-    public void exportExcel(HttpServletResponse response, @RequestBody InOutStorageBomSelectDto dto) {
-        dto.setPageNum(1);
-        dto.setPageSize(9999999);
-        Page<InOutStorageBomVo> page = inOutStorageBomService.getPage(dto);
-        List<InOutStorageBomVo> list = page.getRecords();
-        String fileName;
-        if (Objects.equals(dto.getType(), 1)) {
-            fileName = "入库单";
-        } else {
-            fileName = "出库单";
-        }
-        TemplateExcelUtil.writeBrowser("inOutStorageDetails.xlsx", fileName, response, list);
+    public void exportExcel(@RequestBody InOutStorageBomSelectDto dto) {
+        inOutStorageBomService.exportExcel(dto);
     }
 
     /**

+ 52 - 0
sd-business/src/main/java/com/sd/business/entity/in/vo/InOutStorageBomErpExportVo.java

@@ -0,0 +1,52 @@
+package com.sd.business.entity.in.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 出入库bom信息 erp导出实体
+ *
+ * @author
+ * @since 2023-10-23
+ */
+@Getter
+@Setter
+public class InOutStorageBomErpExportVo {
+
+    /**
+     * 单号
+     */
+    private String code;
+
+    /**
+     * 序号
+     */
+    private Integer serialNumber;
+
+    /**
+     * 产品规格品号
+     */
+    private String bomSpecCode;
+
+    /**
+     * 业务单位
+     */
+    private String pieces;
+
+    /**
+     * 业务单位
+     */
+    private String unit;
+
+    /**
+     * 数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * 仓库编号
+     */
+    private String warehouseCode;
+}

+ 6 - 0
sd-business/src/main/java/com/sd/business/entity/in/vo/InOutStorageBomExportVo.java

@@ -13,6 +13,12 @@ import java.math.BigDecimal;
 import java.util.Date;
 import java.util.Objects;
 
+/**
+ * 出入库流水导出实体
+ *
+ * @author
+ * @since 2023-10-08
+ */
 @Getter
 @Setter
 @ExcelIgnoreUnannotated

+ 43 - 0
sd-business/src/main/java/com/sd/business/entity/in/vo/InOutStorageErpExportVo.java

@@ -0,0 +1,43 @@
+package com.sd.business.entity.in.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * 出入库信息 erp导出实体
+ *
+ * @author
+ * @since 2023-10-23
+ */
+@Getter
+@Setter
+public class InOutStorageErpExportVo {
+
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 工厂编号
+     */
+    private String plantCode;
+
+    /**
+     * 单号
+     */
+    private String code;
+
+    /**
+     * 单据日期
+     */
+    private Date createTime;
+
+    /**
+     * 单据类型
+     */
+    private String docCode;
+
+}

+ 5 - 0
sd-business/src/main/java/com/sd/business/service/in/InOutStorageBomService.java

@@ -43,4 +43,9 @@ public interface InOutStorageBomService extends BaseService<InOutStorageBom> {
      */
     void delete(Long id);
 
+    /**
+     * 出入库bom导出
+     * @param dto
+     */
+    void exportExcel(InOutStorageBomSelectDto dto);
 }

+ 84 - 0
sd-business/src/main/java/com/sd/business/service/in/impl/InOutStorageBomServiceImpl.java

@@ -1,21 +1,34 @@
 package com.sd.business.service.in.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.bom.po.BomSpec;
 import com.sd.business.entity.in.dto.InOutStorageBomDto;
 import com.sd.business.entity.in.dto.InOutStorageBomSelectDto;
+import com.sd.business.entity.in.emums.InOutTypeEnum;
 import com.sd.business.entity.in.po.InOutStorage;
 import com.sd.business.entity.in.po.InOutStorageBom;
+import com.sd.business.entity.in.vo.InOutStorageBomErpExportVo;
 import com.sd.business.entity.in.vo.InOutStorageBomVo;
+import com.sd.business.entity.in.vo.InOutStorageErpExportVo;
 import com.sd.business.entity.purchase.po.Purchase;
 import com.sd.business.entity.warehouse.po.Warehouse;
 import com.sd.business.mapper.in.InOutStorageBomMapper;
 import com.sd.business.service.in.InOutStorageBomService;
+import com.sd.business.service.in.InOutStorageService;
+import com.sd.framework.util.TemplateExcelUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+import java.util.stream.Collectors;
+
 
 /**
  * <p>
@@ -28,6 +41,12 @@ import org.springframework.stereotype.Service;
 @Service
 public class InOutStorageBomServiceImpl extends ServiceImpl<InOutStorageBomMapper, InOutStorageBom> implements InOutStorageBomService {
 
+    @Autowired
+    private InOutStorageService inOutStorageService;
+
+    @Autowired
+    private HttpServletResponse response;
+
     @Override
     public Page<InOutStorageBomVo> getPage(InOutStorageBomSelectDto dto) {
         IWrapper<InOutStorageBom> wrapper = getWrapper();
@@ -69,4 +88,69 @@ public class InOutStorageBomServiceImpl extends ServiceImpl<InOutStorageBomMappe
         this.removeById(id);
     }
 
+    @Override
+    public void exportExcel(InOutStorageBomSelectDto dto) {
+        dto.setPageNum(1);
+        dto.setPageSize(9999999);
+        Page<InOutStorageBomVo> page = this.getPage(dto);
+        List<InOutStorageBomVo> list = page.getRecords();
+        // 查询详情信息
+        Set<Long> inOutStorageIds = list.stream().map(InOutStorageBom::getInOutStorageId).collect(Collectors.toSet());
+        if (ObjectUtil.isEmpty(inOutStorageIds)) {
+            inOutStorageIds.add(-1L);
+        }
+        List<InOutStorage> inOutStorageList = inOutStorageService.list(q -> q
+                .in(BaseIdPo::getId, inOutStorageIds)
+                .orderByAsc(InOutStorage::getCreateTime));
+
+        List<InOutStorageErpExportVo> inOutStorageErpExportVoList = new ArrayList<>();
+        int codeNum = 1;
+        String dateFormat = "";
+        for (InOutStorage inOutStorage : inOutStorageList) {
+            InOutStorageErpExportVo inOutStorageErpExportVo = new InOutStorageErpExportVo();
+            inOutStorageErpExportVo.setId(inOutStorage.getId());
+            inOutStorageErpExportVo.setPlantCode("SDTY");
+            if (Objects.equals(inOutStorage.getType(), InOutTypeEnum.OUT.getKey())) {
+                inOutStorageErpExportVo.setDocCode("T118");
+            } else {
+                inOutStorageErpExportVo.setDocCode("T119");
+            }
+            // 获取单号
+            String format = DateUtil.format(inOutStorage.getCreateTime(), "-yyyyMM");
+            if (!Objects.equals(dateFormat, format)) {
+                dateFormat = format;
+                codeNum = 1;
+            }
+            String code = inOutStorageErpExportVo.getDocCode() + format + String.format("%04d", codeNum);
+            inOutStorageErpExportVo.setCode(code);
+            inOutStorageErpExportVo.setCreateTime(inOutStorage.getCreateTime());
+
+            inOutStorageErpExportVoList.add(inOutStorageErpExportVo);
+            codeNum++;
+        }
+
+        Map<Long, String> map = inOutStorageErpExportVoList.stream()
+                .collect(Collectors.toMap(InOutStorageErpExportVo::getId, InOutStorageErpExportVo::getCode));
+        Integer[] serialNumber = {1};
+        List<InOutStorageBomErpExportVo> inOutStorageBomErpExportVoList = list.stream().map(item -> {
+            InOutStorageBomErpExportVo inOutStorageBomErpExportVo = new InOutStorageBomErpExportVo();
+            inOutStorageBomErpExportVo.setCode(map.get(item.getInOutStorageId()));
+            inOutStorageBomErpExportVo.setBomSpecCode(item.getBomSpecCode());
+            inOutStorageBomErpExportVo.setQuantity(item.getQuantity());
+            inOutStorageBomErpExportVo.setWarehouseCode(item.getWarehouseCode());
+            inOutStorageBomErpExportVo.setUnit("PCS");
+            inOutStorageBomErpExportVo.setPieces("0");
+            inOutStorageBomErpExportVo.setSerialNumber(serialNumber[0]++);
+            return inOutStorageBomErpExportVo;
+        }).collect(Collectors.toList());
+
+        String fileName;
+        if (Objects.equals(dto.getType(), 1)) {
+            fileName = "入库单";
+        } else {
+            fileName = "出库单";
+        }
+        TemplateExcelUtil.writeBrowserMultiSheet("inOutStorageDetails.xlsx", 2, fileName, response, inOutStorageErpExportVoList, inOutStorageBomErpExportVoList);
+    }
+
 }

+ 51 - 0
sd-framework/src/main/java/com/sd/framework/util/TemplateExcelUtil.java

@@ -16,6 +16,8 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
 
 @Slf4j
 public class TemplateExcelUtil {
@@ -65,6 +67,55 @@ public class TemplateExcelUtil {
         }
 
     }
+    /**
+     * 自定义模板excel写入浏览器
+     *
+     * @param templateName 模板名称
+     * @param sheetNum     写入sheet的数量
+     * @param fileName     文件名称
+     * @param response     response
+     * @param data         模板字段替换数据
+     */
+    public static void writeBrowserMultiSheet(String templateName, int sheetNum, String fileName, HttpServletResponse response, Object... data) {
+
+        ExcelWriter excelWriter = null;
+        InputStream is = null;
+        ServletOutputStream os = null;
+        try {
+            String fileNameCn = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
+
+            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+            response.setCharacterEncoding("utf-8");
+            response.setHeader("Content-disposition", "attachment;filename=" + fileNameCn + ".xlsx");
+
+            ClassPathResource classPathResource = new ClassPathResource("template" + File.separator + templateName);
+            is = classPathResource.getInputStream();
+            os = response.getOutputStream();
+
+            excelWriter = EasyExcel.write(os).withTemplate(is).build();
+            List<WriteSheet> writeSheetList = new ArrayList<>();
+            for (int i = 0; i < sheetNum; i++) {
+                writeSheetList.add(EasyExcel.writerSheet(i).build());
+            }
+            FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
+
+            for (int i = 0; i < writeSheetList.size(); i++) {
+                excelWriter.fill(data[i], fillConfig, writeSheetList.get(i));
+            }
+
+        } catch (IOException e) {
+            log.error("excel导出失败", e);
+            throw new ServiceException("excel导出失败");
+        } finally {
+            if (excelWriter != null) {
+                excelWriter.finish();
+            }
+            IoUtil.close(excelWriter);
+            IoUtil.close(is);
+            IoUtil.close(os);
+        }
+
+    }
 
     /**
      * 自定义模板excel写入浏览器

BIN
sd-starter/src/main/resources/template/inOutStorageDetails.xlsx