|
@@ -1,15 +1,10 @@
|
|
package com.sd.business.service.purchase.impl;
|
|
package com.sd.business.service.purchase.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
-import com.alibaba.excel.EasyExcel;
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.fjhx.file.entity.FileInfo;
|
|
|
|
-import com.fjhx.file.entity.ObsFile;
|
|
|
|
-import com.fjhx.file.service.FileInfoService;
|
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
@@ -17,11 +12,7 @@ import com.ruoyi.common.core.domain.BaseIdPo;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
import com.sd.business.entity.apply.po.ApplyBuyBom;
|
|
import com.sd.business.entity.apply.po.ApplyBuyBom;
|
|
-import com.sd.business.entity.apply.vo.ApplyBuyBomAccessoryVo;
|
|
|
|
-import com.sd.business.entity.bom.po.BomSpec;
|
|
|
|
-import com.sd.business.entity.department.constant.DepartmentConstant;
|
|
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
import com.sd.business.entity.in.po.InOutStorageBom;
|
|
-import com.sd.business.entity.inventory.po.Inventory;
|
|
|
|
import com.sd.business.entity.purchase.dto.PurchaseDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseSelectDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseSelectDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseSelectListDto;
|
|
import com.sd.business.entity.purchase.dto.PurchaseSelectListDto;
|
|
@@ -34,20 +25,13 @@ import com.sd.business.entity.supplier.po.Supplier;
|
|
import com.sd.business.mapper.purchase.PurchaseMapper;
|
|
import com.sd.business.mapper.purchase.PurchaseMapper;
|
|
import com.sd.business.service.apply.ApplyBuyBomService;
|
|
import com.sd.business.service.apply.ApplyBuyBomService;
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
-import com.sd.business.service.inventory.InventoryService;
|
|
|
|
-import com.sd.business.service.order.OrderService;
|
|
|
|
import com.sd.business.service.purchase.PurchaseBomService;
|
|
import com.sd.business.service.purchase.PurchaseBomService;
|
|
import com.sd.business.service.purchase.PurchaseService;
|
|
import com.sd.business.service.purchase.PurchaseService;
|
|
-import com.sd.business.upload.ObsUploadService;
|
|
|
|
import com.sd.business.util.CodeEnum;
|
|
import com.sd.business.util.CodeEnum;
|
|
-import com.sd.framework.util.StreamUtil;
|
|
|
|
-import com.sd.framework.util.excel.util.ExcelUtil;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.*;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
-import java.math.RoundingMode;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -72,18 +56,6 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
@Autowired
|
|
@Autowired
|
|
private ApplyBuyBomService applyBuyBomService;
|
|
private ApplyBuyBomService applyBuyBomService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private OrderService orderService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private InventoryService inventoryService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private FileInfoService fileInfoService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ObsUploadService obsUploadService;
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
public Page<PurchaseVo> getPage(PurchaseSelectDto dto) {
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
IWrapper<Purchase> wrapper = getWrapper();
|
|
@@ -186,39 +158,6 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
ArrayList<ApplyBuyBom> applyBuyBomList = new ArrayList<>(applyBuyBomMap.values());
|
|
ArrayList<ApplyBuyBom> applyBuyBomList = new ArrayList<>(applyBuyBomMap.values());
|
|
applyBuyBomService.updateBatchById(applyBuyBomList);
|
|
applyBuyBomService.updateBatchById(applyBuyBomList);
|
|
|
|
|
|
- // 新增备货需求附件
|
|
|
|
- List<ApplyBuyBomAccessoryVo> applyData = this.getApplyData(purchaseDto.getApplyBuyId());
|
|
|
|
- // 修改表头
|
|
|
|
- Map<String, String> keys = new HashMap<>();
|
|
|
|
- Date date = DateUtil.date();
|
|
|
|
- Date lastMonthDate = DateUtil.offsetMonth(date, -1);
|
|
|
|
- Date beforeLastMonthDate = DateUtil.offsetMonth(date, -2);
|
|
|
|
- keys.put("currentMonthSales", (DateUtil.month(date) + 1) + "月销量");
|
|
|
|
- keys.put("lastMonthSales", (DateUtil.month(lastMonthDate) + 1) + "月销量");
|
|
|
|
- keys.put("beforeLastMonthSales", (DateUtil.month(beforeLastMonthDate) + 1) + "月销量");
|
|
|
|
-
|
|
|
|
- ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
|
- EasyExcel.write(os, ExcelUtil.getClassNew(new ApplyBuyBomAccessoryVo(), keys)).sheet("sheetName").doWrite(applyData);
|
|
|
|
- String fileName = "胜德体育备货需求.xlsx";
|
|
|
|
- // 上传文件
|
|
|
|
- ByteArrayInputStream bis = new ByteArrayInputStream(os.toByteArray());
|
|
|
|
- String fileUrl = obsUploadService.uploadFileByte(bis, fileName);
|
|
|
|
-
|
|
|
|
- // 保存文件
|
|
|
|
- FileInfo fileInfo = new FileInfo();
|
|
|
|
- fileInfo.setFileUrl(fileUrl);
|
|
|
|
- fileInfo.setFileName(fileName);
|
|
|
|
- fileInfoService.save(fileInfo);
|
|
|
|
- // 新增附件列表
|
|
|
|
- ObsFile obsFile = new ObsFile();
|
|
|
|
- obsFile.setId(fileInfo.getId());
|
|
|
|
- obsFile.setFileName(fileName);
|
|
|
|
- obsFile.setFileUrl(fileUrl);
|
|
|
|
- if (purchaseDto.getFileList() == null) {
|
|
|
|
- purchaseDto.setFileList(new ArrayList<>());
|
|
|
|
- }
|
|
|
|
- purchaseDto.getFileList().add(obsFile);
|
|
|
|
-
|
|
|
|
ObsFileUtil.saveFile(purchaseDto.getFileList(), purchaseDto.getId());
|
|
ObsFileUtil.saveFile(purchaseDto.getFileList(), purchaseDto.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -357,87 +296,4 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> i
|
|
// 查询采购单数据
|
|
// 查询采购单数据
|
|
return this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
return this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取需求单数据
|
|
|
|
- * @param applyBuyId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<ApplyBuyBomAccessoryVo> getApplyData(Long applyBuyId) {
|
|
|
|
- List<ApplyBuyBomAccessoryVo> accessoryList = new ArrayList<>();
|
|
|
|
- List<ApplyBuyBom> list = applyBuyBomService.list(q -> q.eq(ApplyBuyBom::getApplyBuyId, applyBuyId));
|
|
|
|
- Map<Long, BomSpec> bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, list.stream().map(ApplyBuyBom::getBomSpecId).collect(Collectors.toList())));
|
|
|
|
- for (ApplyBuyBom applyBuyBom : list) {
|
|
|
|
- Long bomSpecId = applyBuyBom.getBomSpecId();
|
|
|
|
- BomSpec bomSpec = bomSpecMap.get(bomSpecId);
|
|
|
|
- ApplyBuyBomAccessoryVo vo = new ApplyBuyBomAccessoryVo();
|
|
|
|
- // 当月时间
|
|
|
|
- Date date = DateUtil.date();
|
|
|
|
- Date currentMonthBeginDate = DateUtil.beginOfMonth(date);
|
|
|
|
- BigDecimal currentMonthSalesQuantity = orderService.getOrderBomSpecOutStorageQuantity(bomSpecId, currentMonthBeginDate, date);
|
|
|
|
- // 上个月时间
|
|
|
|
- Date lastMonthDate = DateUtil.offsetMonth(date, -1);
|
|
|
|
- Date lastMonthBeginDate = DateUtil.beginOfMonth(lastMonthDate);
|
|
|
|
- Date lastMonthEndDate = DateUtil.endOfMonth(lastMonthDate);
|
|
|
|
- BigDecimal lastMonthSalesQuantity = orderService.getOrderBomSpecOutStorageQuantity(bomSpecId, lastMonthBeginDate, lastMonthEndDate);
|
|
|
|
- // 上上个月时间
|
|
|
|
- Date beforeLastMonthDate = DateUtil.offsetMonth(date, -2);
|
|
|
|
- Date beforeLastMonthBeginDate = DateUtil.beginOfMonth(beforeLastMonthDate);
|
|
|
|
- Date beforeLastMonthEndDate = DateUtil.endOfMonth(beforeLastMonthDate);
|
|
|
|
- BigDecimal beforeLastMonth00Quantity = orderService.getOrderBomSpecOutStorageQuantity(bomSpecId, beforeLastMonthBeginDate, beforeLastMonthEndDate);
|
|
|
|
- List<Inventory> inventoryList = inventoryService.list(q -> q
|
|
|
|
- .eq(Inventory::getBomSpecId, bomSpecId)
|
|
|
|
- .eq(Inventory::getDepartmentId, DepartmentConstant.SD_SPORTS));
|
|
|
|
- // 当前库存数
|
|
|
|
- BigDecimal inventoryQuantity = ObjectUtil.isEmpty(inventoryList) ? BigDecimal.ZERO : StreamUtil.bigDecimalAdd(inventoryList, Inventory::getQuantity);
|
|
|
|
- // 在途数量
|
|
|
|
- BigDecimal inTransitSum = purchaseBomService.getPurchaseBomInTransitSum(bomSpecId);
|
|
|
|
- // 月平均消耗
|
|
|
|
- BigDecimal averageMonthSales = currentMonthSalesQuantity
|
|
|
|
- .add(lastMonthSalesQuantity)
|
|
|
|
- .add(beforeLastMonth00Quantity)
|
|
|
|
- .divide(new BigDecimal(90), 2, RoundingMode.HALF_UP);
|
|
|
|
- // 实际销量可消耗天数
|
|
|
|
- BigDecimal actualSalesDays;
|
|
|
|
- if (ObjectUtil.equals(averageMonthSales, BigDecimal.ZERO)) {
|
|
|
|
- actualSalesDays = BigDecimal.ZERO;
|
|
|
|
- } else {
|
|
|
|
- actualSalesDays = inventoryQuantity.divide(averageMonthSales, 0, RoundingMode.HALF_UP);
|
|
|
|
- }
|
|
|
|
- // 短缺数量合计
|
|
|
|
- BigDecimal shortageQuantity;
|
|
|
|
- if (ObjectUtil.equals(currentMonthSalesQuantity, BigDecimal.ZERO)) {
|
|
|
|
- shortageQuantity = BigDecimal.ZERO;
|
|
|
|
- } else {
|
|
|
|
- shortageQuantity = inventoryQuantity
|
|
|
|
- .add(inTransitSum)
|
|
|
|
- .subtract(currentMonthSalesQuantity
|
|
|
|
- .divide(new BigDecimal(90), 2, RoundingMode.HALF_UP)
|
|
|
|
- .multiply(new BigDecimal(60))
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- // 规格
|
|
|
|
- String length = bomSpec.getLength() == null ? "0" : bomSpec.getLength().stripTrailingZeros().toPlainString();
|
|
|
|
- String width = bomSpec.getWidth() == null ? "0" : bomSpec.getWidth().stripTrailingZeros().toPlainString();
|
|
|
|
- String height = bomSpec.getHeight() == null ? "0" : bomSpec.getHeight().stripTrailingZeros().toPlainString();
|
|
|
|
- // 赋值
|
|
|
|
- vo.setBomSpecCode(bomSpec.getCode());
|
|
|
|
- vo.setBomSpecName(bomSpec.getName());
|
|
|
|
- vo.setSpecification(length + " * " + width + " * " + height);
|
|
|
|
- vo.setColour(bomSpec.getColour());
|
|
|
|
- vo.setStockQuantity(inventoryQuantity);
|
|
|
|
- vo.setInTransitQuantity(inTransitSum);
|
|
|
|
- vo.setCurrentMonthSales(currentMonthSalesQuantity);
|
|
|
|
- vo.setLastMonthSales(lastMonthSalesQuantity);
|
|
|
|
- vo.setBeforeLastMonthSales(beforeLastMonth00Quantity);
|
|
|
|
- vo.setAverageMonthSales(averageMonthSales);
|
|
|
|
- vo.setActualSalesDays(actualSalesDays);
|
|
|
|
- vo.setShortageQuantity(shortageQuantity);
|
|
|
|
- vo.setApplyBuyQuantity(applyBuyBom.getQuantity());
|
|
|
|
- vo.setApplyBuyQuantity(applyBuyBom.getQuantity());
|
|
|
|
- accessoryList.add(vo);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return accessoryList;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|