|
|
@ -1,11 +1,37 @@ |
|
|
|
package com.yxt.supervise.report.biz.stock; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.yxt.supervise.report.ds.crm.CrmMapper; |
|
|
|
import com.yxt.supervise.report.ds.crm.ProjectInfo; |
|
|
|
import com.yxt.supervise.report.ds.warehouse.ProdStock; |
|
|
|
import com.yxt.supervise.report.ds.warehouse.StoreHouse; |
|
|
|
import com.yxt.supervise.report.ds.warehouse.WarehouseMapper; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class ReportStockDayService extends ServiceImpl<ReportStockDayMapper, ReportStockDay> { |
|
|
|
|
|
|
|
private static final Logger L = LoggerFactory.getLogger(ReportStockDayService.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ReportStockDayStoreService reportStockDayStoreService; |
|
|
|
@Autowired |
|
|
|
private ReportStockDayProductService reportStockDayProductService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CrmMapper crmMapper; |
|
|
|
@Autowired |
|
|
|
private WarehouseMapper warehouseMapper; |
|
|
|
|
|
|
|
public ReportStockDay fetchByProjectAndDay(String projectSid, String orderDate) { |
|
|
|
|
|
|
|
QueryWrapper<ReportStockDay> qw = new QueryWrapper<>(); |
|
|
@ -15,8 +41,51 @@ public class ReportStockDayService extends ServiceImpl<ReportStockDayMapper, Rep |
|
|
|
return baseMapper.selectOne(qw); |
|
|
|
} |
|
|
|
|
|
|
|
public ReportStockDay buildReportByProjectAndDay(String projectSid, String orderDate) { |
|
|
|
public ReportStockDay buildReportByProjectAndDay(String projectSid) { |
|
|
|
// TODO: 根据项目Sid获取关联仓库,根据仓库Sid获取库存数据
|
|
|
|
ProjectInfo pi = crmMapper.fetchBySid(projectSid); |
|
|
|
List<StoreHouse> shList = warehouseMapper.listStoreHouseByProjectSid(projectSid); |
|
|
|
|
|
|
|
|
|
|
|
Date currentDate = new Date(); |
|
|
|
String orderDate = DateUtil.format(currentDate, "yyyy-MM-dd"); |
|
|
|
String reportTime = DateUtil.format(currentDate, "yyyy-MM-dd HH:mm"); |
|
|
|
ReportStockDay rsd = new ReportStockDay(orderDate, projectSid); |
|
|
|
rsd.setProjectName(pi.getEntryName()); |
|
|
|
rsd.setReportTime(reportTime); |
|
|
|
rsd.setStockNumber(shList.size()); |
|
|
|
|
|
|
|
double countAmount = 0; |
|
|
|
|
|
|
|
List<ReportStockDayStore> insertStoreList = new ArrayList<>(); |
|
|
|
List<ReportStockDayProduct> insertProductList = new ArrayList<>(); |
|
|
|
|
|
|
|
L.info("PPPPPP:{},{}", pi.getSid(), pi.getEntryName()); |
|
|
|
for (StoreHouse sh : shList) { |
|
|
|
|
|
|
|
ReportStockDayStore rsds = new ReportStockDayStore(); |
|
|
|
|
|
|
|
double amount = warehouseMapper.sumAmount(sh.getSid()); |
|
|
|
rsds.setProductAmount(amount); |
|
|
|
|
|
|
|
insertStoreList.add(rsds); |
|
|
|
|
|
|
|
|
|
|
|
List<ProdStock> prodStockList = warehouseMapper.listStock(sh.getSid()); |
|
|
|
for (ProdStock ps : prodStockList) { |
|
|
|
ReportStockDayProduct rsdp = new ReportStockDayProduct(); |
|
|
|
rsdp.setReportStoreSid(rsds.getSid()); |
|
|
|
|
|
|
|
insertProductList.add(rsdp); |
|
|
|
} |
|
|
|
|
|
|
|
countAmount = countAmount + amount; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
baseMapper.insert(rsd); |
|
|
|
reportStockDayStoreService.saveBatch(insertStoreList); |
|
|
|
reportStockDayProductService.saveBatch(insertProductList); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|