Commit 1fdb55bc by zhangtw

批次单号分组

parent 3238334f
...@@ -612,6 +612,7 @@ export default { ...@@ -612,6 +612,7 @@ export default {
getList() { getList() {
this.loading = true this.loading = true
listInbound(this.queryParams).then(response => { listInbound(this.queryParams).then(response => {
console.log(response.rows)
this.inboundList = response.rows this.inboundList = response.rows
this.total = response.total this.total = response.total
this.loading = false this.loading = false
......
...@@ -498,6 +498,8 @@ export default { ...@@ -498,6 +498,8 @@ export default {
if (!inboundOrderId) return if (!inboundOrderId) return
this.loading = true this.loading = true
this.queryParams.inboundOrderId = inboundOrderId this.queryParams.inboundOrderId = inboundOrderId
// 重置分页页码,避免切换入库单时使用之前的分页位置
this.queryParams.pageNum = 1
listInbound_itemsAndMname(this.queryParams).then(response => { listInbound_itemsAndMname(this.queryParams).then(response => {
this.displayData = response.rows.map(item => ({ this.displayData = response.rows.map(item => ({
...item, ...item,
......
...@@ -206,7 +206,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService ...@@ -206,7 +206,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
.stream() .stream()
.filter(Objects::nonNull) // 过滤null的VO对象 .filter(Objects::nonNull) // 过滤null的VO对象
.map(vo -> { .map(vo -> {
// 预处理:入库单号去空格,统一格式(反射调用get/setOrderId // 预处理:对入库单号和批次号去空格,统一格式(反射调用getter/setter
try { try {
// 反射获取getOrderId方法 // 反射获取getOrderId方法
Method getOrderIdMethod = vo.getClass().getMethod("getOrderId"); Method getOrderIdMethod = vo.getClass().getMethod("getOrderId");
...@@ -214,9 +214,19 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService ...@@ -214,9 +214,19 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
.map(Object::toString) .map(Object::toString)
.map(String::trim) // 去除首尾空格 .map(String::trim) // 去除首尾空格
.orElse(""); .orElse("");
// 反射获取getBatchId方法
Method getBatchId = vo.getClass().getMethod("getBatchId");
String batchId = Optional.ofNullable(getBatchId.invoke(vo))
.map(Object::toString)
.map(String::trim)
.orElse("");
// 反射调用setOrderId方法回写处理后的单号 // 反射调用setOrderId方法回写处理后的单号
Method setOrderIdMethod = vo.getClass().getMethod("setOrderId", String.class); Method setOrderIdMethod = vo.getClass().getMethod("setOrderId", String.class);
setOrderIdMethod.invoke(vo, orderId); setOrderIdMethod.invoke(vo, orderId);
// 反射调用setBatchId方法回写处理后的批次号
Method setBatchIdMethod = vo.getClass().getMethod("setBatchId",String.class);
setBatchIdMethod.invoke(vo,batchId);
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException("实体类缺少orderId的getter/setter方法" + e); throw new ServiceException("实体类缺少orderId的getter/setter方法" + e);
} }
...@@ -239,8 +249,13 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService ...@@ -239,8 +249,13 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
// 反射获取分组Key:处理后的入库单号 // 反射获取分组Key:处理后的入库单号
try { try {
Method getOrderIdMethod = vo.getClass().getMethod("getOrderId"); Method getOrderIdMethod = vo.getClass().getMethod("getOrderId");
Method getBatchIdMethod = vo.getClass().getMethod("getBatchId");
return Optional.ofNullable(getOrderIdMethod.invoke(vo)) return Optional.ofNullable(getOrderIdMethod.invoke(vo))
.map(Object::toString) .map(Object::toString)
.orElse("")
+ "--" +
Optional.ofNullable(getBatchIdMethod.invoke(vo))
.map(Object::toString)
.orElse(""); .orElse("");
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException("分组获取orderId失败" + e); throw new ServiceException("分组获取orderId失败" + e);
...@@ -256,7 +271,9 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService ...@@ -256,7 +271,9 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
// 4. 遍历每个入库单分组处理 // 4. 遍历每个入库单分组处理
for (Map.Entry<String, List<T>> entry : orderGroupMap.entrySet()) { for (Map.Entry<String, List<T>> entry : orderGroupMap.entrySet()) {
String orderId = entry.getKey(); String orderKey = entry.getKey();
String orderId = orderKey.split("--")[0];
String batchId = orderKey.split("--")[1];
List<T> voList = entry.getValue(); List<T> voList = entry.getValue();
InboundOrders mainDO = null; InboundOrders mainDO = null;
List<InboundOrderItems> itemDOList = new ArrayList<>(); List<InboundOrderItems> itemDOList = new ArrayList<>();
...@@ -265,18 +282,21 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService ...@@ -265,18 +282,21 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
// 4.1 处理主表(每个入库单号只处理一次主表) // 4.1 处理主表(每个入库单号只处理一次主表)
T firstVO = voList.get(0); // 取第一条VO的主表信息 T firstVO = voList.get(0); // 取第一条VO的主表信息
// 检查入库单是否已存在 // 检查入库单是否已存在
InboundOrders existMain = inboundOrdersMapper.selectInboundOrdersByOrderId(orderId); InboundOrders query = new InboundOrders();
query.setOrderId(orderId);
if (existMain != null) { query.setBatchId(batchId);
List<InboundOrders> existMain = inboundOrdersMapper.selectInboundOrdersList(query);
System.out.println(existMain);
if (existMain != null && !existMain.isEmpty()) {
if (isUpdateSupport == 0) { if (isUpdateSupport == 0) {
// 不支持更新,跳过该入库单 // 不支持更新,跳过该入库单
totalMainFailure++; totalMainFailure++;
failureMsg.append(String.format("入库单号【%s】已存在,且不支持更新,跳过导入;\n", orderId)); failureMsg.append(String.format("该批次的入库单号【%s】已存在,且不支持更新,跳过导入;\n", orderId));
totalItemFailure += voList.size(); // 该单的明细全部失败 totalItemFailure += voList.size(); // 该单的明细全部失败
continue; continue;
} }
// 支持更新,复用已有主表ID // 支持更新,复用已有主表ID
mainDO = existMain; mainDO = existMain.get(0);
// 反射复制VO中的主表字段到已有主表(只更新可修改的字段) // 反射复制VO中的主表字段到已有主表(只更新可修改的字段)
BeanUtils.copyProperties(firstVO, mainDO, "id", "createBy", "createTime"); // 排除不可更新字段 BeanUtils.copyProperties(firstVO, mainDO, "id", "createBy", "createTime"); // 排除不可更新字段
mainDO.setUpdateBy(operId); mainDO.setUpdateBy(operId);
...@@ -349,7 +369,6 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService ...@@ -349,7 +369,6 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
itemDO.setOrderId(orderId); // 关联入库单号 itemDO.setOrderId(orderId); // 关联入库单号
// 反射获取batchId并设置 // 反射获取batchId并设置
String batchId = "";
try { try {
Method getBatchIdMethod = vo.getClass().getMethod("getBatchId"); Method getBatchIdMethod = vo.getClass().getMethod("getBatchId");
batchId = Optional.ofNullable(getBatchIdMethod.invoke(vo)) batchId = Optional.ofNullable(getBatchIdMethod.invoke(vo))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论