|
|
@ -2,16 +2,20 @@ package org.nl.wms.stat.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil; |
|
|
|
import cn.hutool.core.map.MapUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.b_lms.pdm.subpackagerelation.dao.PdmBiSubpackagerelationrecord; |
|
|
|
import org.nl.b_lms.pdm.subpackagerelation.service.IPdmBiSubpackagerelationrecordService; |
|
|
|
import org.nl.b_lms.pdm.subpackagerelation.service.IpdmBiSubpackagerelationService; |
|
|
|
import org.nl.b_lms.storage_manage.ios.service.iostorInv.IStIvtIostorinvdisService; |
|
|
|
import org.nl.common.domain.query.PageQuery; |
|
|
|
import org.nl.common.utils.SecurityUtils; |
|
|
|
import org.nl.modules.common.exception.BadRequestException; |
|
|
|
import org.nl.modules.common.utils.FileUtil; |
|
|
@ -20,16 +24,19 @@ import org.nl.modules.wql.core.bean.WQLObject; |
|
|
|
import org.nl.modules.wql.util.WqlUtil; |
|
|
|
import org.nl.wms.sch.service.dto.PointDto; |
|
|
|
import org.nl.wms.stat.service.OutBillQueryService; |
|
|
|
import org.nl.wms.stat.service.dto.OutBillPageParam; |
|
|
|
import org.nl.wms.stat.service.enums.OutBillTypeEnum; |
|
|
|
import org.nl.wms.stat.service.vo.OutBillPageVo; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentLinkedDeque; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -46,6 +53,10 @@ public class OutBillQueryServiceImpl implements OutBillQueryService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IpdmBiSubpackagerelationService ipdmBiSubpackagerelationService; |
|
|
|
@Resource |
|
|
|
private IStIvtIostorinvdisService iostorinvdisService; |
|
|
|
@Resource |
|
|
|
private IPdmBiSubpackagerelationrecordService subpackagerelationrecordService; |
|
|
|
@Override |
|
|
|
public Map<String, Object> queryAll(Map whereJson, Pageable page, String[] bill_types) { |
|
|
|
String stor_id = MapUtil.getStr(whereJson, "stor_id"); |
|
|
@ -467,4 +478,148 @@ public class OutBillQueryServiceImpl implements OutBillQueryService { |
|
|
|
new FileUtil().downloadExcelIO(list,col,response); |
|
|
|
// FileUtil.downloadExcel(list, response);
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public IPage<OutBillPageVo> getPage2(OutBillPageParam paramMap, PageQuery page) { |
|
|
|
IPage<OutBillPageVo> pages = iostorinvdisService.getOutBillPage(paramMap, page); |
|
|
|
// 查询此子卷转单之前的销售订单号
|
|
|
|
List<OutBillPageVo> pageRecords = pages.getRecords(); |
|
|
|
// 获取所有子卷号
|
|
|
|
List<String> pcsns = pageRecords.stream() |
|
|
|
.map(OutBillPageVo::getPcsn) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
if (pcsns.size() == 0) { |
|
|
|
return pages; |
|
|
|
} |
|
|
|
List<PdmBiSubpackagerelationrecord> recodes = subpackagerelationrecordService.getAllByPcsn(pcsns); |
|
|
|
pages.getRecords().forEach(bill -> { |
|
|
|
PdmBiSubpackagerelationrecord subpackagerelationrecord = recodes.stream() |
|
|
|
.filter(r -> r.getContainer_name().equals(bill.getPcsn())) |
|
|
|
.min(Comparator.comparing(PdmBiSubpackagerelationrecord::getInsert_time)) |
|
|
|
.orElse(null); |
|
|
|
bill.setOld_sale_order_name(ObjectUtil.isEmpty(subpackagerelationrecord) |
|
|
|
? bill.getSale_order_name() |
|
|
|
: subpackagerelationrecord.getSale_order_name()); |
|
|
|
}); |
|
|
|
return pages; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void downloadOutBillData(OutBillPageParam paramMap, HttpServletResponse response) { |
|
|
|
List<OutBillPageVo> outBillPageVos = iostorinvdisService.getOutBillData(paramMap); |
|
|
|
// 获取所有子卷号
|
|
|
|
List<String> pcsns = outBillPageVos.stream() |
|
|
|
.map(OutBillPageVo::getPcsn) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
ConcurrentLinkedDeque<List<JSONObject>> deque = new ConcurrentLinkedDeque<>(); |
|
|
|
Lists.partition(pcsns,500).stream() |
|
|
|
.map((Function<List<String>, CompletableFuture>) o->CompletableFuture.runAsync(() -> { |
|
|
|
List<JSONObject> subList = ipdmBiSubpackagerelationService.recordQuery(o); |
|
|
|
deque.add(subList); |
|
|
|
})).parallel().forEach(CompletableFuture::join); |
|
|
|
List<JSONObject> datas = new ArrayList<>(); |
|
|
|
for (List<JSONObject> jsonObjects : deque) { |
|
|
|
datas.addAll(jsonObjects); |
|
|
|
} |
|
|
|
List<Map<String, String>> list = new ArrayList<>(); |
|
|
|
for (int i = 0; i < outBillPageVos.size(); i++) { |
|
|
|
OutBillPageVo outBillPageVo = outBillPageVos.get(i); |
|
|
|
Map<String, String> mp = new LinkedHashMap<>(); |
|
|
|
// 查询第一次入库的源销售订单
|
|
|
|
JSONObject jsonSub = datas.stream() |
|
|
|
.filter(row -> row.getString("container_name").equals(outBillPageVo.getPcsn())) |
|
|
|
.min(Comparator.comparing(row -> row.getString("insert_time"))) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
mp.put("仓库", outBillPageVo.getStor_name()); |
|
|
|
if (ObjectUtil.isNotEmpty(outBillPageVo.getBill_type()) && "1004".equals(outBillPageVo.getBill_type())) { |
|
|
|
mp.put("移入仓库", outBillPageVo.getIn_stor_name()); |
|
|
|
} |
|
|
|
mp.put("库区", outBillPageVo.getSect_name()); |
|
|
|
mp.put("生产区域", outBillPageVo.getPcsn().substring(0, 2)); |
|
|
|
mp.put("业务类型", OutBillTypeEnum.getNameByCode(outBillPageVo.getBill_type())); |
|
|
|
mp.put("交货单号", outBillPageVo.getVbeln()); |
|
|
|
mp.put("物流公司", outBillPageVo.getCust_name()); |
|
|
|
mp.put("运费", outBillPageVo.getEstimated_freight()); |
|
|
|
mp.put("木箱号", outBillPageVo.getBox_no()); |
|
|
|
mp.put("物料编码", outBillPageVo.getMaterial_code()); |
|
|
|
mp.put("物料名称", outBillPageVo.getMaterial_name()); |
|
|
|
mp.put("子卷号", outBillPageVo.getPcsn()); |
|
|
|
mp.put("sap批次", outBillPageVo.getSap_pcsn()); |
|
|
|
mp.put("净重", outBillPageVo.getNet_weight()); |
|
|
|
mp.put("单位", outBillPageVo.getQty_unit_name()); |
|
|
|
mp.put("管件类型", outBillPageVo.getPaper_type()); |
|
|
|
mp.put("管件编码", outBillPageVo.getPaper_code()); |
|
|
|
mp.put("管件描述", outBillPageVo.getPaper_name()); |
|
|
|
mp.put("客户编码", outBillPageVo.getCustomer_name()); |
|
|
|
mp.put("发货客户名称", outBillPageVo.getCustomer_description()); |
|
|
|
mp.put("销售订单", outBillPageVo.getSale_order_name()); |
|
|
|
mp.put("行号", ""); |
|
|
|
mp.put("原销售订单", outBillPageVo.getSale_order_name()); |
|
|
|
mp.put("原行号", ""); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(outBillPageVo.getSale_order_name())) { |
|
|
|
try { |
|
|
|
mp.put("销售订单", outBillPageVo.getSale_order_name().substring(0, outBillPageVo.getSale_order_name().indexOf("-"))); |
|
|
|
mp.put("行号", outBillPageVo.getSale_order_name().substring(outBillPageVo.getSale_order_name().indexOf("-") + 1, outBillPageVo.getSale_order_name().length())); |
|
|
|
} catch (Exception e) { |
|
|
|
mp.put("销售订单", outBillPageVo.getSale_order_name()); |
|
|
|
mp.put("行号", ""); |
|
|
|
} |
|
|
|
} |
|
|
|
// 原销售订单
|
|
|
|
if (ObjectUtil.isEmpty(jsonSub)) { |
|
|
|
if (ObjectUtil.isNotEmpty(outBillPageVo.getSale_order_name())) { |
|
|
|
try { |
|
|
|
mp.put("原销售订单", outBillPageVo.getSale_order_name().substring(0, outBillPageVo.getSale_order_name().indexOf("-"))); |
|
|
|
mp.put("原行号", outBillPageVo.getSale_order_name().substring(outBillPageVo.getSale_order_name().indexOf("-") + 1, outBillPageVo.getSale_order_name().length())); |
|
|
|
} catch (Exception e) { |
|
|
|
mp.put("原销售订单", outBillPageVo.getSale_order_name()); |
|
|
|
mp.put("原行号", ""); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (ObjectUtil.isNotEmpty(jsonSub.getString("sale_order_name"))) { |
|
|
|
try { |
|
|
|
mp.put("原销售订单", jsonSub.getString("sale_order_name").substring(0, jsonSub.getString("sale_order_name").indexOf("-"))); |
|
|
|
mp.put("原行号", jsonSub.getString("sale_order_name").substring(jsonSub.getString("sale_order_name").indexOf("-") + 1, jsonSub.getString("sale_order_name").length())); |
|
|
|
} catch (Exception e) { |
|
|
|
mp.put("原销售订单", jsonSub.getString("sale_order_name")); |
|
|
|
mp.put("原行号", ""); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
mp.put("业务员", outBillPageVo.getSales_owner()); |
|
|
|
mp.put("出库日期", outBillPageVo.getInput_time()); |
|
|
|
mp.put("产品规格", String.format("%.0f", getWidthValue(outBillPageVo.getWidth()))); |
|
|
|
mp.put("产品厚度", outBillPageVo.getThickness()); |
|
|
|
mp.put("单位面积", outBillPageVo.getMass_per_unit_area()); |
|
|
|
mp.put("制单人", outBillPageVo.getInput_optname()); |
|
|
|
mp.put("备注", outBillPageVo.getRemark()); |
|
|
|
list.add(mp); |
|
|
|
} |
|
|
|
Set<String> set = list.get(0).keySet(); |
|
|
|
int colIndex = 0; |
|
|
|
String[] col = new String[set.size()]; |
|
|
|
for (String s : set) { |
|
|
|
col[colIndex]=s; |
|
|
|
colIndex++; |
|
|
|
} |
|
|
|
new FileUtil().downloadExcelIO(list,col,response); |
|
|
|
} |
|
|
|
|
|
|
|
private static double getWidthValue(String widthStr) { |
|
|
|
double widthValue = 0.0; |
|
|
|
if (widthStr != null && !widthStr.trim().isEmpty()) { |
|
|
|
try { |
|
|
|
// 移除逗号并解析为Double
|
|
|
|
String cleanedStr = widthStr.replaceAll(",", ""); |
|
|
|
widthValue = Double.parseDouble(cleanedStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 解析失败时使用默认值(或根据业务需求处理)
|
|
|
|
widthValue = 0.0; |
|
|
|
} |
|
|
|
} |
|
|
|
return widthValue; |
|
|
|
} |
|
|
|
} |
|
|
|