|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|