|
|
|
|
@ -34,10 +34,8 @@ import org.springframework.context.event.EventListener;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -336,4 +334,79 @@ public class WmsShippingBillServiceImpl implements IWmsShippingBillService {
|
|
|
|
|
baseMapper.updateById(shippingBill);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 组装发货单 Word 导出数据。
|
|
|
|
|
* <p>
|
|
|
|
|
* 根据 {@code word.md} 中定义的模板结构,组装主表字段和明细列表数据,供 poi-tl 渲染使用。
|
|
|
|
|
* 约定如下:
|
|
|
|
|
* <ul>
|
|
|
|
|
* <li>主表字段:如 customerName、receiverName、receiverPhone、shippingDate、contractCode 等,对应 Word 模板中的
|
|
|
|
|
* {{customerName}}、{{receiverName}}、{{receiverPhone}}、{{shippingDate}}、{{contractCode}} 等占位符;</li>
|
|
|
|
|
* <li>明细列表:使用 {@code details} 作为列表占位符,内部每一行包含 seq、materialName、quantity、unit、remark 等字段,
|
|
|
|
|
* 对应 Word 模板表格中的 {{seq}}、{{materialName}}、{{quantity}}、{{unit}}、{{remark}}。</li>
|
|
|
|
|
* </ul>
|
|
|
|
|
*
|
|
|
|
|
* @param shippingBillId 发货单ID
|
|
|
|
|
* @return Word 模板数据 Map,建议直接传给 {@link org.dromara.common.word.util.WordTemplateUtil}
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> buildWordExportData(Long shippingBillId) {
|
|
|
|
|
// 查询发货单(包含明细列表)
|
|
|
|
|
WmsShippingBillVo vo = queryById(shippingBillId);
|
|
|
|
|
if (vo == null) {
|
|
|
|
|
throw new ServiceException("发货单不存在,ID:" + shippingBillId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// === 主表字段 ===
|
|
|
|
|
// 客户名称
|
|
|
|
|
data.put("customerName", StringUtils.blankToDefault(vo.getCustomerName(), ""));
|
|
|
|
|
// 收货联系人(客户侧)
|
|
|
|
|
data.put("receiverName", StringUtils.blankToDefault(vo.getReceiverName(), ""));
|
|
|
|
|
// 收货联系电话(客户侧)
|
|
|
|
|
data.put("receiverPhone", StringUtils.blankToDefault(vo.getReceiverPhone(), ""));
|
|
|
|
|
// 发货日期(实际发货时间)
|
|
|
|
|
data.put("shippingDate", vo.getShippingTime() != null ? sdf.format(vo.getShippingTime()) : "");
|
|
|
|
|
// 合同编号
|
|
|
|
|
data.put("contractCode", StringUtils.blankToDefault(vo.getContractCode(), ""));
|
|
|
|
|
// 收货日期(留空,由客户签收时填写)
|
|
|
|
|
data.put("receivedDate", "");
|
|
|
|
|
// === 落款信息(供应商/发货方) ===
|
|
|
|
|
// 发货单位(供应商名称)
|
|
|
|
|
data.put("shippingUnit", StringUtils.blankToDefault(vo.getSupplier(), ""));
|
|
|
|
|
// 发货人(供应商联系人)
|
|
|
|
|
data.put("shipper", StringUtils.blankToDefault(vo.getContactUser(), ""));
|
|
|
|
|
// 发货方联系电话
|
|
|
|
|
data.put("contactNumber", StringUtils.blankToDefault(vo.getContactNumber(), ""));
|
|
|
|
|
|
|
|
|
|
// === 明细列表 ===
|
|
|
|
|
// 对应 Word 模板中的 {{#details}}...{{/details}} 循环表格:
|
|
|
|
|
// - seq → {{seq}} (行号)
|
|
|
|
|
// - materialName → {{materialName}}(物料名称)
|
|
|
|
|
// - quantity → {{quantity}} (发货数量)
|
|
|
|
|
// - unit → {{unit}} (计量单位)
|
|
|
|
|
// - remark → {{remark}} (备注)
|
|
|
|
|
// 如需在模板中添加单价、金额、合计行等字段,可在此处扩展 row 中的字段,并在 data 中追加 totalQuantity、totalAmount 等汇总字段。
|
|
|
|
|
List<Map<String, Object>> details = new ArrayList<>();
|
|
|
|
|
List<WmsShippingDetailsVo> itemsVo = vo.getItemsVo();
|
|
|
|
|
if (CollUtil.isNotEmpty(itemsVo)) {
|
|
|
|
|
int seq = 1;
|
|
|
|
|
for (WmsShippingDetailsVo item : itemsVo) {
|
|
|
|
|
Map<String, Object> row = new HashMap<>();
|
|
|
|
|
row.put("seq", String.valueOf(seq++));
|
|
|
|
|
row.put("materialName", StringUtils.blankToDefault(item.getMaterialName(), ""));
|
|
|
|
|
row.put("quantity", item.getShippingStockAmount() != null ? item.getShippingStockAmount().toPlainString() : "");
|
|
|
|
|
row.put("unit", StringUtils.blankToDefault(item.getUnitName(), ""));
|
|
|
|
|
row.put("remark", StringUtils.blankToDefault(item.getRemark(), ""));
|
|
|
|
|
details.add(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// poi-tl 列表占位符,对应 Word 模板中的 {{#details}}...{{/details}}
|
|
|
|
|
data.put("details", details);
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|