Merge branch 'claude/sharp-rubin' into claude/gallant-shamir

This commit is contained in:
panchengyong
2026-03-14 14:27:21 +08:00
3 changed files with 104 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
package com.ktg.mes.po.controller;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@@ -26,6 +28,11 @@ import com.ktg.mes.po.service.IPoOrderService;
import com.ktg.mes.po.service.IPoOrderLineService;
import com.ktg.mes.mp.domain.MpPurchase;
import com.ktg.mes.mp.mapper.MpPurchaseMapper;
import com.ktg.mes.wm.domain.WmArrivalNotice;
import com.ktg.mes.wm.domain.WmArrivalNoticeLine;
import com.ktg.mes.wm.service.IWmArrivalNoticeService;
import com.ktg.mes.wm.service.IWmArrivalNoticeLineService;
import com.ktg.system.strategy.AutoCodeUtil;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
@@ -48,6 +55,15 @@ public class PoOrderController extends BaseController
@Autowired
private MpPurchaseMapper mpPurchaseMapper;
@Autowired
private IWmArrivalNoticeService wmArrivalNoticeService;
@Autowired
private IWmArrivalNoticeLineService wmArrivalNoticeLineService;
@Autowired
private AutoCodeUtil autoCodeUtil;
/**
* 查询采购订单列表(明细视图 - 按行级别JOIN 订单表头+明细行)
*/
@@ -264,4 +280,73 @@ public class PoOrderController extends BaseController
}
return AjaxResult.success("成功反审核 " + count + " 条订单");
}
/**
* 根据采购订单自动生成到货通知单
*/
@Log(title = "采购订单", businessType = BusinessType.INSERT)
@Transactional
@PostMapping("/genArrivalNotice/{orderId}")
public AjaxResult genArrivalNotice(@PathVariable Long orderId)
{
// 1. 查询采购订单及明细
PoOrder order = poOrderService.selectPoOrderByOrderId(orderId);
if (order == null) {
return AjaxResult.error("采购订单不存在!");
}
if (!UserConstants.ORDER_STATUS_APPROVED.equals(order.getStatus())) {
return AjaxResult.error("只有已审核的采购订单才能生成到货通知单!");
}
List<PoOrderLine> lines = poOrderLineService.selectPoOrderLineByOrderId(orderId);
if (CollUtil.isEmpty(lines)) {
return AjaxResult.error("采购订单没有物料明细,无法生成到货通知单!");
}
// 过滤出仍有未到货数量的明细行
List<PoOrderLine> pendingLines = new java.util.ArrayList<>();
for (PoOrderLine line : lines) {
BigDecimal qty = line.getQuantity() != null ? line.getQuantity() : BigDecimal.ZERO;
BigDecimal arrived = line.getArrivedQuantity() != null ? line.getArrivedQuantity() : BigDecimal.ZERO;
if (qty.subtract(arrived).compareTo(BigDecimal.ZERO) > 0) {
pendingLines.add(line);
}
}
if (pendingLines.isEmpty()) {
return AjaxResult.error("所有物料已全部到货,无需生成到货通知单!");
}
// 2. 创建到货通知单表头
WmArrivalNotice notice = new WmArrivalNotice();
notice.setNoticeCode(autoCodeUtil.genSerialCode(UserConstants.ARRIVAL_NOTICE_CODE, ""));
notice.setNoticeName("采购订单[" + order.getOrderCode() + "]到货通知单");
notice.setPoCode(order.getOrderCode());
notice.setVendorId(order.getSupplierId());
notice.setVendorCode(order.getSupplierCode());
notice.setVendorName(order.getSupplierName());
notice.setArrivalDate(order.getDeliveryDate() != null ? order.getDeliveryDate() : new Date());
notice.setStatus(UserConstants.ORDER_STATUS_PREPARE);
notice.setCreateBy(getUsername());
wmArrivalNoticeService.insertWmArrivalNotice(notice);
// 3. 创建到货通知单明细行
for (PoOrderLine line : pendingLines) {
WmArrivalNoticeLine noticeLine = new WmArrivalNoticeLine();
noticeLine.setNoticeId(notice.getNoticeId());
noticeLine.setItemId(line.getItemId());
noticeLine.setItemCode(line.getItemCode());
noticeLine.setItemName(line.getItemName());
noticeLine.setSpecification(line.getSpecification());
noticeLine.setUnitOfMeasure(line.getUnitName());
noticeLine.setUnitName(line.getUnitName());
BigDecimal qty = line.getQuantity() != null ? line.getQuantity() : BigDecimal.ZERO;
BigDecimal arrived = line.getArrivedQuantity() != null ? line.getArrivedQuantity() : BigDecimal.ZERO;
noticeLine.setQuantityArrival(qty.subtract(arrived));
noticeLine.setIqcCheck(UserConstants.NO);
noticeLine.setCreateBy(getUsername());
wmArrivalNoticeLineService.insertWmArrivalNoticeLine(noticeLine);
}
return AjaxResult.success("到货通知单生成成功", notice.getNoticeId());
}
}