|
|
|
@ -6,7 +6,6 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.logpm.basicdata.entity.BasicdataWarehouseEntity; |
|
|
|
|
import com.logpm.basicdata.feign.IBasicdataWarehouseClient; |
|
|
|
|
import com.logpm.report.dto.DeliveryTrainLoadedScanDTO; |
|
|
|
|
import com.logpm.report.mapper.ReportDeliverMapeer; |
|
|
|
@ -19,22 +18,23 @@ import com.logpm.report.reader.DeliveryDetailReader;
|
|
|
|
|
import com.logpm.report.reader.DeliveryTrainReader; |
|
|
|
|
import com.logpm.report.reader.StockOrderReader; |
|
|
|
|
import com.logpm.report.service.ReportDeliverService; |
|
|
|
|
import com.logpm.report.util.CheckDataUtil; |
|
|
|
|
import com.logpm.report.util.QueryUtil; |
|
|
|
|
import com.logpm.report.util.ReportExcelUtil; |
|
|
|
|
import com.logpm.report.util.ReportUtil; |
|
|
|
|
import com.logpm.report.vo.ReportCustomerVO; |
|
|
|
|
import com.logpm.report.vo.ReportDetailVO; |
|
|
|
|
import com.logpm.report.vo.ReportDevilerVO; |
|
|
|
|
import com.logpm.report.vo.StockOrderVO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -49,6 +49,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class ReportDeliverServiceImpl implements ReportDeliverService { |
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ReportDeliverServiceImpl.class); |
|
|
|
|
private final ReportDeliverMapeer reportDeliverMapeer; |
|
|
|
|
private final DeliveryTrainReader deliveryTrainReader; |
|
|
|
|
private final DeliveryCustomerReader deliveryCustomerReader; |
|
|
|
@ -59,7 +60,7 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
@Override |
|
|
|
|
public IPage<ReportDevilerVO> deliveryTrainPage(ReportDevilerVO vo, ReportDevilerQuery query) { |
|
|
|
|
// 校验时间
|
|
|
|
|
dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime()); |
|
|
|
|
ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); |
|
|
|
|
IPage<ReportDevilerVO> page = Condition.getPage(query); |
|
|
|
|
QueryWrapper<ReportDevilerVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDevilerVO.class); |
|
|
|
|
// 自定义 sql 查询条件
|
|
|
|
@ -68,17 +69,15 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
// 1 如果用户页面选择了仓库,按选择的仓库查询。
|
|
|
|
|
// 2 用户页面没有选择仓库,但是切换了仓库,按切换的仓库查
|
|
|
|
|
// 3 用户没有选择仓库,也没有切换仓库,按用户当前所有仓查询
|
|
|
|
|
if (StrUtil.isEmpty(vo.getWarehouseName())) { |
|
|
|
|
BasicdataWarehouseEntity myCurrentWarehouse = warehouseClient.getMyCurrentWarehouse(); |
|
|
|
|
if (ObjectUtil.isNotEmpty(myCurrentWarehouse)) { |
|
|
|
|
queryWrapper.eq("warehouse_id", myCurrentWarehouse.getId()); |
|
|
|
|
} else { |
|
|
|
|
List<BasicdataWarehouseEntity> warehouseEntities = warehouseClient.getMyWarehouseList(); |
|
|
|
|
queryWrapper.in("warehouse_id", warehouseEntities.stream().map(BasicdataWarehouseEntity::getId).collect(Collectors.toList())); |
|
|
|
|
} |
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); |
|
|
|
|
// 查询数据
|
|
|
|
|
List<ReportDevilerVO> deliveryTrainPage = reportDeliverMapeer.getDeliveryTrainPage(page, queryWrapper); |
|
|
|
|
// 异步组装统计数据
|
|
|
|
|
asyncBuildDeliveryTrainPage(deliveryTrainPage); |
|
|
|
|
return page.setRecords(deliveryTrainPage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<ReportDevilerVO> deliveryTrainPage = reportDeliverMapeer.getDeliveryTrainPage(page, queryWrapper); |
|
|
|
|
private void asyncBuildDeliveryTrainPage(List<ReportDevilerVO> deliveryTrainPage) { |
|
|
|
|
List<Long> ids = deliveryTrainPage.stream().map(ReportDevilerVO::getId).collect(Collectors.toList()); |
|
|
|
|
// 异步查询扫描装车和异常扫描装车数据
|
|
|
|
|
if (CollUtil.isNotEmpty(ids)) { |
|
|
|
@ -93,12 +92,12 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); |
|
|
|
|
allFutures.join(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
|
log.error("系统异常:{}", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return page.setRecords(deliveryTrainPage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private @NotNull CompletableFuture<List<DeliveryTrainLoadedScanDTO>> getTrainLoadedScanInvnFuture(List<Long> idBatch, List<ReportDevilerVO> deliveryTrainPage) { |
|
|
|
|
CompletableFuture<List<DeliveryTrainLoadedScanDTO>> future = CompletableFuture.supplyAsync(() -> |
|
|
|
|
reportDeliverMapeer.getDeliveryTrainLoadSacnInvnByIds(idBatch)); |
|
|
|
@ -151,15 +150,6 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
return future; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void dateIsWithinOneMonth(String taskTime, Date startTaskTime, Date endTaskTime) { |
|
|
|
|
if (ObjectUtil.isEmpty(taskTime)) { |
|
|
|
|
boolean withinOneMonth = CheckDataUtil.isWithinOneMonth(startTaskTime, endTaskTime); |
|
|
|
|
if (!withinOneMonth) { |
|
|
|
|
throw new ServiceException("日期必选且日期只能选择一个月"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void trainCustomQuery(ReportDevilerQuery query, QueryWrapper<ReportDevilerVO> queryWrapper) { |
|
|
|
|
// 配送时间开始
|
|
|
|
|
QueryUtil.timeGe("task_time", query.getStartTaskTime(), queryWrapper); |
|
|
|
@ -179,19 +169,26 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void exportTrain(HttpServletResponse response, ReportDevilerVO vo, ReportDevilerQuery query) { |
|
|
|
|
dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime()); |
|
|
|
|
// 添加时间校验
|
|
|
|
|
ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); |
|
|
|
|
QueryWrapper<ReportDevilerVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDevilerVO.class); |
|
|
|
|
trainCustomQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); |
|
|
|
|
new ReportExcelUtil().export(response, deliveryTrainReader, ReportDevilerVO.class, queryWrapper, "配送车次维度报表"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<ReportCustomerVO> customerPage(ReportCustomerVO vo, ReportCustomerQuery query) { |
|
|
|
|
// 添加时间校验
|
|
|
|
|
ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); |
|
|
|
|
// 构建前端查询参数
|
|
|
|
|
IPage<ReportCustomerVO> page = Condition.getPage(query); |
|
|
|
|
QueryWrapper<ReportCustomerVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportCustomerVO.class); |
|
|
|
|
// 自定义查询
|
|
|
|
|
customerCustomQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); |
|
|
|
|
return page.setRecords(reportDeliverMapeer.getCustomerPage(page, queryWrapper)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -216,18 +213,26 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void exportCustomer(HttpServletResponse response, ReportCustomerVO vo, ReportCustomerQuery query) { |
|
|
|
|
// 添加时间校验
|
|
|
|
|
ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); |
|
|
|
|
QueryWrapper<ReportCustomerVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportCustomerVO.class); |
|
|
|
|
customerCustomQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); |
|
|
|
|
new ReportExcelUtil().export(response, deliveryCustomerReader, ReportCustomerVO.class, queryWrapper, "配送客户维度报表"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<ReportDetailVO> detailsPage(ReportDetailVO vo, DevilerDetailsQuery query) { |
|
|
|
|
// 添加时间校验
|
|
|
|
|
ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); |
|
|
|
|
Integer current = query.getCurrent(); |
|
|
|
|
Integer size = query.getSize(); |
|
|
|
|
IPage<ReportDetailVO> page = Condition.getPage(query); |
|
|
|
|
QueryWrapper<ReportDetailVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDetailVO.class); |
|
|
|
|
detailsCustomQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); |
|
|
|
|
List<ReportDetailVO> detailsPage = reportDeliverMapeer.getDetailsPage(page, queryWrapper); |
|
|
|
|
// 包件总数
|
|
|
|
|
long total = page.getTotal(); |
|
|
|
@ -273,16 +278,29 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void exportDetails(HttpServletResponse response, ReportDetailVO vo, DevilerDetailsQuery query) { |
|
|
|
|
// 添加时间校验
|
|
|
|
|
ReportUtil.dateIsWithinOneMonth(vo.getTaskTime(), query.getStartTaskTime(), query.getEndTaskTime(), "配送日期"); |
|
|
|
|
QueryWrapper<ReportDetailVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, ReportDetailVO.class); |
|
|
|
|
detailsCustomQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouseName(), query.getWarehouseNameRange(), queryWrapper, warehouseClient); |
|
|
|
|
new ReportExcelUtil().export(response, deliveryDetailReader, ReportDetailVO.class, queryWrapper, "配送明细报表"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<StockOrderVO> stockOrderPage(StockOrderVO vo, StockOrderQuery query) { |
|
|
|
|
// 添加时间校验
|
|
|
|
|
if (ObjectUtil.isEmpty(vo.getWarehouseEntryTime())) { |
|
|
|
|
boolean withinOneMonth = ReportUtil.isWithinOneMonth(query.getStartWarehouseEntryTime(), query.getEndWarehouseEntryTime()); |
|
|
|
|
if (!withinOneMonth) { |
|
|
|
|
throw new ServiceException("入库时间必选且时间不超过一个月"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
IPage<StockOrderVO> page = Condition.getPage(query); |
|
|
|
|
QueryWrapper<StockOrderVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, StockOrderVO.class); |
|
|
|
|
stockOrderQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); |
|
|
|
|
return page.setRecords(reportDeliverMapeer.getStockOrderPage(page, queryWrapper)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -304,8 +322,17 @@ public class ReportDeliverServiceImpl implements ReportDeliverService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void exportStockOrder(HttpServletResponse response, StockOrderVO vo, StockOrderQuery query) { |
|
|
|
|
// 添加时间校验
|
|
|
|
|
if (ObjectUtil.isEmpty(vo.getWarehouseEntryTime())) { |
|
|
|
|
boolean withinOneMonth = ReportUtil.isWithinOneMonth(query.getStartWarehouseEntryTime(), query.getEndWarehouseEntryTime()); |
|
|
|
|
if (!withinOneMonth) { |
|
|
|
|
throw new ServiceException("入库时间必选且时间不超过一个月"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
QueryWrapper<StockOrderVO> queryWrapper = QueryUtil.buildQueryWrapper(vo, StockOrderVO.class); |
|
|
|
|
stockOrderQuery(query, queryWrapper); |
|
|
|
|
// 仓库权限
|
|
|
|
|
ReportUtil.buildReportWarehouseAuth(vo.getWarehouse(), query.getWarehouseRange(), queryWrapper, warehouseClient); |
|
|
|
|
new ReportExcelUtil().export(response, stockOrderReader, StockOrderVO.class, queryWrapper, "在库订单表"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|