|
|
@@ -36,6 +36,7 @@ import com.sckw.transport.model.*;
|
|
|
import com.sckw.transport.model.param.*;
|
|
|
import com.sckw.transport.model.vo.OrderTotalTakeVo;
|
|
|
import com.sckw.transport.model.vo.StatisticsWaybillResp;
|
|
|
+import com.sckw.transport.model.vo.WaybillOrderRawOreReportRespExcelVO;
|
|
|
import com.sckw.transport.model.vo.WaybillOrderReportRespExcelVO;
|
|
|
import com.sckw.transport.repository.*;
|
|
|
import com.sckw.transport.service.KwtWaybillOrderV1Service;
|
|
|
@@ -1983,7 +1984,7 @@ public class WaybillOrderService {
|
|
|
* @return
|
|
|
*/
|
|
|
public List<WaybillOrderReportResp> queryWaybillOrderReport(WaybillOrderReportQueryParam param) {
|
|
|
- log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
|
|
|
+ log.info("[报表]开始查询销售运单每日报表:{}", JSON.toJSONString(param));
|
|
|
// 查询运单数据
|
|
|
List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
|
|
|
// 过滤
|
|
|
@@ -2098,6 +2099,7 @@ public class WaybillOrderService {
|
|
|
.ge(KwtWaybillOrder::getCreateTime, startOfDay)
|
|
|
.le(KwtWaybillOrder::getCreateTime, endOfDay)
|
|
|
.eq(KwtWaybillOrder::getStatus,25)
|
|
|
+ .isNull(KwtWaybillOrder::getRemark)
|
|
|
.eq(KwtWaybillOrder::getDelFlag, 0)
|
|
|
.orderByDesc(KwtWaybillOrder::getUpdateTime);
|
|
|
|
|
|
@@ -2171,7 +2173,7 @@ public class WaybillOrderService {
|
|
|
* 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
|
|
|
*/
|
|
|
public List<WaybillOrderReportResp> filter(WaybillOrderReportQueryParam param, List<WaybillOrderReportResp> orderRepoost) {
|
|
|
- log.info("[报表]开始每日报表模糊查询,size:{}", orderRepoost.size());
|
|
|
+ log.info("[报表]开始每日销售报表模糊查询,size:{}", orderRepoost.size());
|
|
|
if (orderRepoost == null || orderRepoost.isEmpty()) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
@@ -2195,7 +2197,7 @@ public class WaybillOrderService {
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- log.info("[报表]每日报表模糊查询结束,size:{}", reportResps.size());
|
|
|
+ log.info("[报表]每日销售报表模糊查询结束,size:{}", reportResps.size());
|
|
|
return reportResps;
|
|
|
}
|
|
|
|
|
|
@@ -2204,7 +2206,7 @@ public class WaybillOrderService {
|
|
|
* 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
|
|
|
*/
|
|
|
public List<WaybillOrderReportResp> buildGroupedReport(List<WaybillOrderReportResp> rawList) {
|
|
|
- log.info("[报表]开始分组汇总!");
|
|
|
+ log.info("[报表]开始销售报表分组汇总!");
|
|
|
if (rawList == null || rawList.isEmpty()) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
@@ -2239,7 +2241,7 @@ public class WaybillOrderService {
|
|
|
WaybillOrderReportResp summaryRow = createSummaryRow(firstItem, details);
|
|
|
resultList.add(summaryRow);
|
|
|
}
|
|
|
- log.info("[报表]分组汇总结束!");
|
|
|
+ log.info("[报表]销售报表分组汇总结束!");
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
@@ -2284,14 +2286,269 @@ public class WaybillOrderService {
|
|
|
* @return
|
|
|
*/
|
|
|
public List<WaybillOrderReportRespExcelVO> exportReport(WaybillOrderReportQueryParam param) {
|
|
|
- log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
|
|
|
+ log.info("[报表]导出销售运单每日报表:{}", JSON.toJSONString(param));
|
|
|
// 查询运单数据
|
|
|
- List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
|
|
|
+ List<WaybillOrderReportResp> orderGroupedReportList = queryWaybillOrderReport(param);
|
|
|
+
|
|
|
+ return BeanUtils.copyToList(orderGroupedReportList, WaybillOrderReportRespExcelVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询运单每日内转报表
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<WaybillOrderRawOreReportResp> queryWaybillOrderRawOreReport(WaybillOrderReportQueryParam param) {
|
|
|
+ log.info("[报表]开始查询原矿运单每日报表:{}", JSON.toJSONString(param));
|
|
|
+ // 查询运单数据
|
|
|
+ List<WaybillOrderRawOreReportResp> orderRepoost = getWaybillOrderRawOreRepoost(param);
|
|
|
// 过滤
|
|
|
- List<WaybillOrderReportResp> filterOrderRepoost = filter(param, orderRepoost);
|
|
|
+ List<WaybillOrderRawOreReportResp> filterOrderRepoost = filterRawOre(param, orderRepoost);
|
|
|
+
|
|
|
//汇总数据
|
|
|
- List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(filterOrderRepoost);
|
|
|
- return BeanUtils.copyToList(orderGroupedReportList, WaybillOrderReportRespExcelVO.class);
|
|
|
+ List<WaybillOrderRawOreReportResp> orderGroupedReportList = buildGroupedRawOreReport(filterOrderRepoost);
|
|
|
+
|
|
|
+ return orderGroupedReportList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 原矿订单
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<WaybillOrderRawOreReportResp> getWaybillOrderRawOreRepoost(WaybillOrderReportQueryParam param) {
|
|
|
+ // 1. 物流企业
|
|
|
+ List<KwtLogisticsOrderUnit> logOrderUnits = logisticsOrderUnitRepository.queryByEntIdAndUnitType(param.getEntId(), Global.NUMERICAL_ONE);
|
|
|
+ if (CollectionUtils.isEmpty(logOrderUnits)) {
|
|
|
+ log.info("当前企业无物流订单企业信息!,entId:{}", param.getEntId());
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ log.info("物流关联企业,size:{}", logOrderUnits.size());
|
|
|
+ Set<Long> logOrderIds = logOrderUnits.stream().map(KwtLogisticsOrderUnit::getLOrderId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 2. 物流订单
|
|
|
+ List<KwtLogisticsOrder> logisticsOrders = logisticsOrderRepository.queryByIdsAndOrderType(logOrderIds);
|
|
|
+ if (CollectionUtils.isEmpty(logisticsOrders)) {
|
|
|
+ log.info("当前无物流订单信息!,entId:{}", JSON.toJSONString(logisticsOrders));
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ log.info("物流订单,size:{}", logisticsOrders.size());
|
|
|
+
|
|
|
+ Set<Long> lOrderIds= logisticsOrders.stream().map(KwtLogisticsOrder::getId).collect(Collectors.toSet());
|
|
|
+ Map<Long, KwtLogisticsOrder> logOrderMap = logisticsOrders.stream()
|
|
|
+ .collect(Collectors.toMap(KwtLogisticsOrder::getId, Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+
|
|
|
+ // 3.运单
|
|
|
+ List<KwtWaybillOrder> waybillOrderList = queryWaybillOrders(param, lOrderIds);
|
|
|
+ if (CollectionUtils.isEmpty(waybillOrderList)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<Long> wOrderIds = waybillOrderList.stream().map(KwtWaybillOrder::getId).collect(Collectors.toList());
|
|
|
+ log.info("运单,size:{}", wOrderIds.size());
|
|
|
+
|
|
|
+ // 4. 运单装货单
|
|
|
+ List<KwtWaybillOrderTicket> ticketList = waybillOrderTicketRepository.queryByWOrderIds(wOrderIds);
|
|
|
+ if (CollectionUtils.isEmpty(ticketList)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "运单装货单不存在,wOrderIds:" + JSON.toJSONString(wOrderIds));
|
|
|
+ }
|
|
|
+ log.info("运单装货单,size:{}", ticketList.size());
|
|
|
+ Map<String, KwtWaybillOrderTicket> ticketMap = ticketList.stream().collect(Collectors
|
|
|
+ .toMap(ticket -> ticket.getWOrderId() + "-" + ticket.getType(), Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+ // 5.门卫
|
|
|
+ List<KwtGatekeeperWaybillOrder> gatekeepers = gatekeeperWaybillOrderRepository.queryGatekeeperByWaybillOrders(wOrderIds, Global.ADDRESS_LOAD);
|
|
|
+ if (CollectionUtils.isEmpty(gatekeepers)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "门卫运单不存在,wOrderIds:" + JSON.toJSONString(wOrderIds));
|
|
|
+ }
|
|
|
+ log.info("门卫,size:{}", gatekeepers.size());
|
|
|
+ Map<String, KwtGatekeeperWaybillOrder> gatekeeperMap = gatekeepers.stream().collect(Collectors
|
|
|
+ .toMap(gate ->gate.getWOrderId() + "-" + gate.getType(), Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+ //6.铲车
|
|
|
+ List<KwtForkliftWaybillOrder> forklifts = forkliftWaybillOrderRepository.queryForkliftByWOrderIdsAndType(wOrderIds, Global.NUMERICAL_ZERO);
|
|
|
+ if (CollectionUtils.isEmpty(forklifts)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "铲车订单不存在,wOrderIds:" + JSON.toJSONString(wOrderIds));
|
|
|
+ }
|
|
|
+ log.info("铲车,size:{}", forklifts.size());
|
|
|
+ Map<Long, KwtForkliftWaybillOrder> forkliftMap = forklifts.stream().collect(Collectors.toMap(KwtForkliftWaybillOrder::getWOrderId, Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+ //组装参数
|
|
|
+ List<WaybillOrderRawOreReportResp> orderList = waybillOrderList.stream()
|
|
|
+ .map(waybillOrder -> {
|
|
|
+ return getWaybillOrderRawOreReport(waybillOrder,logOrderMap, ticketMap, gatekeeperMap, forkliftMap);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ log.info("[报表]查询运单每日报表结束,还未分组, size:{}",orderList.size());
|
|
|
+ return orderList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询正常流程物流运单
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private WaybillOrderRawOreReportResp getWaybillOrderRawOreReport(KwtWaybillOrder waybillOrder,
|
|
|
+ Map<Long, KwtLogisticsOrder> logOrderMap,
|
|
|
+ Map<String, KwtWaybillOrderTicket> ticketMap,
|
|
|
+ Map<String, KwtGatekeeperWaybillOrder> gatekeeperMap,
|
|
|
+ Map<Long, KwtForkliftWaybillOrder> forkliftMap) {
|
|
|
+
|
|
|
+ //订单
|
|
|
+ KwtLogisticsOrder logOrder = logOrderMap.getOrDefault(waybillOrder.getLOrderId(), new KwtLogisticsOrder());
|
|
|
+ //运单装货单
|
|
|
+ KwtWaybillOrderTicket loadTicket = ticketMap.getOrDefault(waybillOrder.getId() + "-" + 1, new KwtWaybillOrderTicket());
|
|
|
+ //运单卸货单
|
|
|
+ KwtWaybillOrderTicket unLoadTicket = ticketMap.getOrDefault(waybillOrder.getId() + "-" + 2, new KwtWaybillOrderTicket());
|
|
|
+ //门卫装货单
|
|
|
+ KwtGatekeeperWaybillOrder loadGatekeeper = gatekeeperMap.getOrDefault(waybillOrder.getId() + "-" + 1, new KwtGatekeeperWaybillOrder());
|
|
|
+ //门卫卸货单
|
|
|
+ KwtGatekeeperWaybillOrder unLoadGatekeeper = gatekeeperMap.getOrDefault(waybillOrder.getId() + "-" + 2, new KwtGatekeeperWaybillOrder());
|
|
|
+ //铲车
|
|
|
+ KwtForkliftWaybillOrder forklift = forkliftMap.getOrDefault(waybillOrder.getId(), new KwtForkliftWaybillOrder());
|
|
|
+
|
|
|
+ WaybillOrderRawOreReportResp resp = new WaybillOrderRawOreReportResp();
|
|
|
+ resp.setId(waybillOrder.getId());
|
|
|
+ resp.setLogisticsNo(logOrder.getLOrderNo());
|
|
|
+ resp.setTruckNo(waybillOrder.getTruckNo());
|
|
|
+ resp.setAcceptTime(forklift.getWaybillAcceptTime());
|
|
|
+ resp.setLoadTareAmount(loadTicket.getTareAmount());
|
|
|
+ resp.setLoadGrossAmount(loadTicket.getGrossAmount());
|
|
|
+ resp.setLoadAmount(loadTicket.getAmount());
|
|
|
+ resp.setLoadTareAmountTime(loadTicket.getUpdateTime()); // todo 修改
|
|
|
+ resp.setLoadGrossTime(loadTicket.getUpdateTime());
|
|
|
+ resp.setLoadPerson(loadGatekeeper.getGatekeeperName());
|
|
|
+
|
|
|
+ resp.setUnLoadTareAmount(unLoadTicket.getTareAmount());
|
|
|
+ resp.setUnLoadGrossAmount(unLoadTicket.getGrossAmount());
|
|
|
+ resp.setUnLoadAmount(unLoadTicket.getAmount());
|
|
|
+ resp.setUnLoadTareAmountTime(unLoadTicket.getUpdateTime());
|
|
|
+ resp.setUnLoadGrossTime(unLoadTicket.getUpdateTime()); // todo 修改
|
|
|
+ resp.setUnLoadPerson(unLoadGatekeeper.getGatekeeperName());
|
|
|
+
|
|
|
+ resp.setDictId(forklift.getDictId());
|
|
|
+ String goodsName = loadGatekeeper.getGoodsName();
|
|
|
+ // 商品名称
|
|
|
+ if (StringUtils.isNotBlank(goodsName)) {
|
|
|
+ int lastSlashIndex = goodsName.lastIndexOf("/");
|
|
|
+ String dictName = lastSlashIndex >= 0 ? goodsName.substring(lastSlashIndex + 1) : goodsName;
|
|
|
+ resp.setGoodsName(dictName);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resp;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
|
|
|
+ */
|
|
|
+ public List<WaybillOrderRawOreReportResp> filterRawOre(WaybillOrderReportQueryParam param, List<WaybillOrderRawOreReportResp> orderRepoost) {
|
|
|
+ log.info("[报表]开始每日原矿报表模糊查询,size:{}", orderRepoost.size());
|
|
|
+ if (orderRepoost == null || orderRepoost.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ //过滤
|
|
|
+ List<WaybillOrderRawOreReportResp> reportResps = orderRepoost.stream().filter(
|
|
|
+ report ->
|
|
|
+ // 商品ID过滤
|
|
|
+ CollectionUtils.isNotEmpty(param.getDictIds()) || param.getDictIds().contains(report.getDictId())
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+
|
|
|
+ log.info("[报表]每日原矿报表模糊查询结束,size:{}", reportResps.size());
|
|
|
+ return reportResps;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
|
|
|
+ */
|
|
|
+ public List<WaybillOrderRawOreReportResp> buildGroupedRawOreReport(List<WaybillOrderRawOreReportResp> rawList) {
|
|
|
+ log.info("[报表]开始原矿运单分组汇总!");
|
|
|
+ if (CollectionUtils.isEmpty(rawList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 排序优先级:商品名称 -> 离场时间(倒序或正序均可)
|
|
|
+ rawList.sort(Comparator.comparing(WaybillOrderRawOreReportResp::getGoodsName, Comparator.nullsLast(String::compareTo))
|
|
|
+ .thenComparing(WaybillOrderRawOreReportResp::getAcceptTime, Comparator.nullsLast(Date::compareTo)));
|
|
|
+
|
|
|
+ // 2. 分组:LinkedHashMap保持插入顺序
|
|
|
+ Map<String, List<WaybillOrderRawOreReportResp>> groupedMap = rawList.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ WaybillOrderRawOreReportResp::getGoodsName,
|
|
|
+ LinkedHashMap::new,
|
|
|
+ Collectors.toList()
|
|
|
+ ));
|
|
|
+
|
|
|
+ List<WaybillOrderRawOreReportResp> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 3. 遍历组装:【汇总行】 -> 【明细行】
|
|
|
+ for (Map.Entry<String, List<WaybillOrderRawOreReportResp>> entry : groupedMap.entrySet()) {
|
|
|
+ List<WaybillOrderRawOreReportResp> details = entry.getValue();
|
|
|
+ if (details.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ WaybillOrderRawOreReportResp firstItem = details.get(0);
|
|
|
+ // A. 添加【明细行】 ---
|
|
|
+ resultList.addAll(details);
|
|
|
+
|
|
|
+ // B. 创建并添加【汇总行】 ---
|
|
|
+ WaybillOrderRawOreReportResp summaryRow = createRawOreSummaryRow(firstItem, details);
|
|
|
+ resultList.add(summaryRow);
|
|
|
+ }
|
|
|
+ log.info("[报表]原矿运单分组汇总结束!");
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算并生成一行汇总数据
|
|
|
+ */
|
|
|
+ private WaybillOrderRawOreReportResp createRawOreSummaryRow(WaybillOrderRawOreReportResp sample, List<WaybillOrderRawOreReportResp> details) {
|
|
|
+ log.info("[报表]开始生成一行汇总数据!");
|
|
|
+ WaybillOrderRawOreReportResp summary = new WaybillOrderRawOreReportResp();
|
|
|
+
|
|
|
+ // 复制分组维度的信息
|
|
|
+ summary.setId(-1L);
|
|
|
+
|
|
|
+ BigDecimal totalLoadTareAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalLoadGrossAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalLoadNetAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalUnLoadTareAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalUnLoadGrossAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalUnLoadAmountt = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 累加计算
|
|
|
+ for (WaybillOrderRawOreReportResp item : details) {
|
|
|
+ totalLoadTareAmount = totalLoadTareAmount.add(item.getLoadTareAmount() != null ? item.getLoadTareAmount() : BigDecimal.ZERO);
|
|
|
+ totalLoadGrossAmount = totalLoadGrossAmount.add(item.getLoadGrossAmount() != null ? item.getLoadGrossAmount() : BigDecimal.ZERO);
|
|
|
+ totalLoadNetAmount = totalLoadNetAmount.add(item.getLoadAmount() != null ? item.getLoadAmount() : BigDecimal.ZERO);
|
|
|
+ totalUnLoadTareAmount = totalUnLoadTareAmount.add(item.getUnLoadTareAmount() != null ? item.getUnLoadTareAmount() : BigDecimal.ZERO);
|
|
|
+ totalUnLoadGrossAmount = totalUnLoadGrossAmount.add(item.getUnLoadGrossAmount() != null ? item.getUnLoadGrossAmount() : BigDecimal.ZERO);
|
|
|
+ totalUnLoadAmountt = totalUnLoadAmountt.add(item.getUnLoadAmount() != null ? item.getUnLoadAmount() : BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值给汇总行
|
|
|
+ summary.setLoadTareAmount(totalLoadTareAmount);
|
|
|
+ summary.setLoadGrossAmount(totalLoadGrossAmount);
|
|
|
+ summary.setLoadAmount(totalLoadNetAmount);
|
|
|
+ summary.setUnLoadTareAmount(totalUnLoadTareAmount);
|
|
|
+ summary.setUnLoadGrossAmount(totalUnLoadGrossAmount);
|
|
|
+ summary.setUnLoadAmount(totalUnLoadAmountt);
|
|
|
+
|
|
|
+ log.info("[报表]生成一行汇总数据结束!");
|
|
|
+ return summary;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询运单每日报表
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<WaybillOrderRawOreReportRespExcelVO> exportRawOreReport(WaybillOrderReportQueryParam param) {
|
|
|
+ log.info("[报表]导出原矿运单每日报表:{}", JSON.toJSONString(param));
|
|
|
+ List<WaybillOrderRawOreReportResp> orderGroupedRawOreReportList = queryWaybillOrderRawOreReport(param);
|
|
|
+ return BeanUtils.copyToList(orderGroupedRawOreReportList, WaybillOrderRawOreReportRespExcelVO.class);
|
|
|
}
|
|
|
|
|
|
|