4 Commits

Author SHA1 Message Date
caojia 68426dc615 更改 收货实重(kg) 字段取值 2026-10-12 11:26:59 +08:00
caojia 980ab1d251 🐛 修复应收账单收货时间范围导出类型异常 2026-10-12 11:19:43 +08:00
caojia 35cbeb8adc 🐛 固定应收账单导出费用类型为运费 2026-10-12 11:19:43 +08:00
caojia 3ef6ea78a9 🐛 修正应收账单收货时间来源为订单扩展表 2026-10-12 11:19:42 +08:00
9 changed files with 95 additions and 27 deletions
@@ -32,6 +32,8 @@ public class ArBillDetail implements Serializable {
private String countryName;
private String destPostcode;
private BigDecimal actualWeight;
/** prc_order_bill.weight 来源快照。 */
private BigDecimal weight;
private BigDecimal volumeWeight;
private BigDecimal chargeWeight;
/** 订单计费时命中的运费单价快照,对应 prc_order_bill.freight_rate。 */
@@ -1,6 +1,7 @@
package com.bms.ar.mapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.bms.ar.domain.ArBillDetail;
@@ -19,6 +20,8 @@ public interface ArBillDetailMapper {
List<ArBillDetail> selectExportPage(@Param("arBillId") Long arBillId,
@Param("lastDetailNo") Integer lastDetailNo, @Param("pageSize") Integer pageSize);
Map<String, Object> selectReceiveTimeRangeByBillId(@Param("arBillId") Long arBillId);
int insert(ArBillDetail detail);
int insertBatch(List<ArBillDetail> details);
@@ -12,6 +12,8 @@ import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -1159,7 +1161,7 @@ public class ArBillServiceImpl implements IArBillService {
detail.setOrderNo(source.getOrderNo());
detail.setTrackingNo(source.getTrackingNo());
detail.setTransferNo(source.getTransferNo());
detail.setReceiveTime(source.getOrderTime());
detail.setReceiveTime(source.getPickupDate());
detail.setProductCode(source.getProductCode());
detail.setProductName(source.getProductName());
detail.setGoodsDescription(source.getOrderRemark());
@@ -1167,6 +1169,7 @@ public class ArBillServiceImpl implements IArBillService {
detail.setCountryName(source.getCountryName());
detail.setDestPostcode(source.getDestPostcode());
detail.setActualWeight(source.getActualWeight());
detail.setWeight(source.getWeight());
detail.setVolumeWeight(source.getVolumeWeight());
detail.setChargeWeight(source.getChargeWeight() == null ? source.getWeight() : source.getChargeWeight());
detail.setFreightRate(source.getFreightRate());
@@ -1319,6 +1322,7 @@ public class ArBillServiceImpl implements IArBillService {
}
Map<Integer, String> templateRows = extractTemplateRows(templateXml.substring(sheetDataOpenEnd + 1, sheetDataEnd));
Map<String, Object> receiveTimeRange = detailMapper.selectReceiveTimeRangeByBillId(bill.getArBillId());
String prefix = adjustExportColumnWidths(
removeSheetDimension(templateXml.substring(0, sheetDataOpenEnd + 1)));
writeUtf8(output, prefix);
@@ -1329,7 +1333,7 @@ public class ArBillServiceImpl implements IArBillService {
writeUtf8(output, templateRows.get(2));
String customerRow = replaceCellXml(templateRows.get(3), "C3", bill.getCustomerName(), false);
// 账单所属期区域为 O3:T3 合并单元格,必须写入左上角 O3 才能显示。
customerRow = replaceCellXml(customerRow, "O3", exportPeriod(bill), false);
customerRow = replaceCellXml(customerRow, "O3", exportReceiveTimeRange(receiveTimeRange), false);
writeUtf8(output, customerRow);
writeUtf8(output, templateRows.get(4));
@@ -1493,10 +1497,10 @@ public class ArBillServiceImpl implements IArBillService {
detail.getOrderNo(), detail.getTrackingNo(),
StringUtils.isEmpty(detail.getProductName()) ? detail.getProductCode() : detail.getProductName(),
StringUtils.isEmpty(detail.getCountryName()) ? detail.getCountryCode() : detail.getCountryName(),
detail.getDestPostcode(), decimal(detail.getActualWeight(), 3), decimal(detail.getPkgLength(), 2),
detail.getDestPostcode(), decimal(detail.getWeight(), 3), decimal(detail.getPkgLength(), 2),
decimal(detail.getPkgHeight(), 2), decimal(detail.getPkgWidth(), 2), decimal(detail.getVolumeWeight(), 3),
decimal(detail.getChargeWeight(), 3), exportUnitPrice(detail), exportProcessingFee(detail),
exportFormula(detail), exportFeeTypes(detail), detail.getCurrency(), detail.getTotalAmount(), exportRemark(detail)
exportFormula(detail), exportFeeType(), detail.getCurrency(), detail.getTotalAmount(), exportRemark(detail)
};
StringBuilder row = new StringBuilder(2048);
row.append("<row r=\"").append(rowNumber).append("\" ht=\"24.0\" customHeight=\"true\" spans=\"1:20\">");
@@ -1731,17 +1735,32 @@ public class ArBillServiceImpl implements IArBillService {
return StringUtils.isEmpty(detail.getRemark()) ? detail.getGoodsDescription() : detail.getRemark();
}
private String exportPeriod(ArBill bill) {
Date start = bill.getBillPeriodStart();
Date end = bill.getBillPeriodEnd();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
if (start != null && end != null) {
return format.format(start) + " 至 " + format.format(end);
private String exportReceiveTimeRange(Map<String, Object> receiveTimeRange) {
if (receiveTimeRange == null) {
return "";
}
if (start != null) {
return format.format(start) + " 起";
String start = formatReceiveDate(receiveTimeRange.get("minReceiveTime"));
String end = formatReceiveDate(receiveTimeRange.get("maxReceiveTime"));
return StringUtils.isEmpty(start) || StringUtils.isEmpty(end) ? "" : start + " 至 " + end;
}
private String formatReceiveDate(Object value) {
if (value instanceof LocalDateTime) {
return ((LocalDateTime) value).toLocalDate().toString();
}
return end == null ? "" : "截至 " + format.format(end);
if (value instanceof LocalDate) {
return value.toString();
}
if (value instanceof java.sql.Date) {
return ((java.sql.Date) value).toLocalDate().toString();
}
if (value instanceof Date) {
return new SimpleDateFormat("yyyy-MM-dd").format((Date) value);
}
if (value == null) {
return "";
}
throw new IllegalArgumentException("不支持的收货时间类型: " + value.getClass().getName());
}
private BigDecimal exportUnitPrice(ArBillDetail detail) {
@@ -1766,8 +1785,8 @@ public class ArBillServiceImpl implements IArBillService {
return "结算重量*公斤价" + (processing ? "+处理费" : "") + (surcharge ? "+附加费" : "");
}
private String exportFeeTypes(ArBillDetail detail) {
return joinFeeText(detail.getFees(), false);
private String exportFeeType() {
return "运费";
}
private String joinFeeText(List<ArBillDetailFee> fees, boolean formula) {
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.bms.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -59,6 +60,9 @@ public class PrcOrderBill extends BaseEntity
private String warehouseCode;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date orderTime;
/** 应收来源查询专用:从 prc_order_bill_ext.pickup_date 读取的收件时间。 */
@JsonIgnore
private Date pickupDate;
private String orderRemark;
private String productCode;
private String productName;
@@ -20,6 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="countryName" column="country_name"/>
<result property="destPostcode" column="dest_postcode"/>
<result property="actualWeight" column="actual_weight"/>
<result property="weight" column="weight"/>
<result property="volumeWeight" column="volume_weight"/>
<result property="chargeWeight" column="charge_weight"/>
<result property="freightRate" column="freight_rate"/>
@@ -39,7 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByBillId" parameterType="long" resultMap="ArBillDetailResult">
select detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
actual_weight, weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, remark, create_by, create_time
from ar_bill_detail where ar_bill_id = #{arBillId} order by detail_no
</select>
@@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByBillIdAndSourceIds" resultMap="ArBillDetailResult">
select detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
actual_weight, weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, remark, create_by, create_time
from ar_bill_detail
where ar_bill_id = #{arBillId}
@@ -85,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByBillIdWithFees" parameterType="long" resultMap="ArBillDetailWithFeesResult">
select d.detail_id, d.ar_bill_id, d.prc_order_bill_id, d.detail_no, d.order_no, d.tracking_no, d.transfer_no, d.receive_time,
d.product_code, d.product_name, d.goods_description, d.country_code, d.country_name, d.dest_postcode,
d.actual_weight, d.volume_weight, d.charge_weight, d.freight_rate, d.registration_fee, d.pkg_length, d.pkg_width, d.pkg_height,
d.actual_weight, d.weight, d.volume_weight, d.charge_weight, d.freight_rate, d.registration_fee, d.pkg_length, d.pkg_width, d.pkg_height,
d.currency, d.total_amount, d.product_amount, d.redline_amount, d.remark, d.create_by, d.create_time,
f.detail_fee_id as fee_detail_id, f.detail_id as fee_parent_detail_id,
f.prc_income_bill_fee_id as fee_prc_income_bill_fee_id,
@@ -104,7 +105,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectExportPage" resultMap="ArBillDetailResult">
select detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
actual_weight, weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
currency, total_amount, product_amount, redline_amount, remark, create_by, create_time
from ar_bill_detail
where ar_bill_id = #{arBillId} and detail_no &gt; #{lastDetailNo}
@@ -112,24 +113,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
limit #{pageSize}
</select>
<select id="selectReceiveTimeRangeByBillId" resultType="map">
select min(receive_time) as minReceiveTime, max(receive_time) as maxReceiveTime
from ar_bill_detail
where ar_bill_id = #{arBillId}
</select>
<insert id="insert" parameterType="ArBillDetail" useGeneratedKeys="true" keyProperty="detailId">
insert into ar_bill_detail (ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time,
product_code,
product_name, goods_description, country_code, country_name, dest_postcode,
actual_weight,
actual_weight, weight,
volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height, currency,
total_amount, product_amount, redline_amount,
remark, create_by, create_time)
values (#{arBillId}, #{prcOrderBillId}, #{detailNo}, #{orderNo}, #{trackingNo}, #{transferNo}, #{receiveTime},
#{productCode}, #{productName}, #{goodsDescription}, #{countryCode}, #{countryName},
#{destPostcode}, #{actualWeight}, #{volumeWeight}, #{chargeWeight}, #{freightRate}, #{registrationFee}, #{pkgLength}, #{pkgWidth},
#{destPostcode}, #{actualWeight}, #{weight}, #{volumeWeight}, #{chargeWeight}, #{freightRate}, #{registrationFee}, #{pkgLength}, #{pkgWidth},
#{pkgHeight}, #{currency}, #{totalAmount}, #{productAmount}, #{redlineAmount}, #{remark}, #{createBy}, sysdate())
</insert>
<insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="detailId">
insert into ar_bill_detail (
ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time, product_code,
product_name, goods_description, country_code, country_name, dest_postcode, actual_weight,
product_name, goods_description, country_code, country_name, dest_postcode, actual_weight, weight,
volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height, currency, total_amount,
product_amount, redline_amount,
remark, create_by, create_time
@@ -137,7 +144,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<foreach collection="list" item="item" separator=",">
(#{item.arBillId}, #{item.prcOrderBillId}, #{item.detailNo}, #{item.orderNo}, #{item.trackingNo},
#{item.transferNo}, #{item.receiveTime}, #{item.productCode}, #{item.productName}, #{item.goodsDescription},
#{item.countryCode}, #{item.countryName}, #{item.destPostcode}, #{item.actualWeight},
#{item.countryCode}, #{item.countryName}, #{item.destPostcode}, #{item.actualWeight}, #{item.weight},
#{item.volumeWeight}, #{item.chargeWeight}, #{item.freightRate}, #{item.registrationFee}, #{item.pkgLength}, #{item.pkgWidth}, #{item.pkgHeight},
#{item.currency}, #{item.totalAmount}, #{item.productAmount}, #{item.redlineAmount},
#{item.remark}, #{item.createBy}, sysdate())
@@ -76,6 +76,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateTime" column="update_time" />
</resultMap>
<resultMap type="PrcOrderBill" id="PrcOrderBillArSourceResult" extends="PrcOrderBillResult">
<result property="pickupDate" column="pickup_date"/>
</resultMap>
<sql id="selectPrcOrderBillVo">
select bill_id, bill_key, order_no, tracking_no, transfer_no,
belong_saler, belong_saler_code, settlement_man, settlement_man_code, service_man, service_man_code,
@@ -99,7 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
p.belong_saler, p.belong_saler_code, p.settlement_man, p.settlement_man_code, p.service_man, p.service_man_code,
p.customer_id, p.customer_code, p.customer_name,
p.pieces, p.actual_weight, p.volume, p.volume_weight, p.pkg_length, p.pkg_width, p.pkg_height,
p.shipper_name, p.consignee_name, p.dest_postcode, p.warehouse_code, p.order_time, p.order_remark,
p.shipper_name, p.consignee_name, p.dest_postcode, p.warehouse_code, p.order_time, e.pickup_date, p.order_remark,
p.product_code, p.product_name, p.country_code, p.country_name, p.weight, p.biz_date, p.tms_id,
p.match_source, p.match_message, p.price_set_id, p.price_set_code, p.price_set_name,
p.set_type, p.bind_priority, p.customer_priceset_id, p.psv_id, p.psd_id, p.product_country_id,
@@ -114,6 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
p.customer_active_status, p.credit_arrears_status, p.round_mode,
p.created_by, p.create_time, p.updated_by, p.update_time
from prc_order_bill p
left join prc_order_bill_ext e on e.bill_id = p.bill_id
</sql>
<select id="selectPrcOrderBillByOrderNo" parameterType="String" resultMap="PrcOrderBillResult">
@@ -341,7 +346,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</sql>
<select id="selectPrcOrderBillByCustomerPeriod" resultMap="PrcOrderBillResult">
<select id="selectPrcOrderBillByCustomerPeriod" resultMap="PrcOrderBillArSourceResult">
<include refid="selectArBillSourceVo"/>
where p.customer_id = #{customerId}
<if test="customerCode != null and customerCode != ''">
@@ -457,7 +462,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<!-- 异步生成使用 bill_id 游标批量读取,避免深分页和一次加载全量订单。 -->
<select id="selectPrcOrderBillByCustomerPeriodCursor" resultMap="PrcOrderBillResult">
<select id="selectPrcOrderBillByCustomerPeriodCursor" resultMap="PrcOrderBillArSourceResult">
<include refid="selectArBillSourceVo"/>
<include refid="customerPeriodConditions"/>
<if test="lastSourceBillId != null and lastSourceBillId != ''">
@@ -474,7 +479,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="customerPeriodConditions"/>
</select>
<select id="selectPrcOrderBillByCustomerCutoffAndIds" resultMap="PrcOrderBillResult">
<select id="selectPrcOrderBillByCustomerCutoffAndIds" resultMap="PrcOrderBillArSourceResult">
<include refid="selectArBillSourceVo"/>
where p.customer_id = #{customerId}
and p.biz_date &lt;= #{cutoffDate}
@@ -0,0 +1,6 @@
-- 应收账单的收货时间应取订单扩展表 pickup_date,而非订单主表 order_time。
-- 只修正存在扩展表来源的快照;pickup_date 为空时保留 NULL,不回退到 order_time。
UPDATE `ar_bill_detail` d
INNER JOIN `prc_order_bill_ext` e ON e.`bill_id` = d.`prc_order_bill_id`
SET d.`receive_time` = e.`pickup_date`
WHERE NOT (d.`receive_time` <=> e.`pickup_date`);
@@ -0,0 +1,21 @@
-- 应收账单订单明细冗余 prc_order_bill.weight,供账单导出使用。
-- 来源字段为空时快照保留 NULL,不伪造为 0。
SET @column_exists := (
SELECT COUNT(1) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ar_bill_detail'
AND COLUMN_NAME = 'weight'
);
SET @sql := IF(@column_exists = 0,
'ALTER TABLE `ar_bill_detail` ADD COLUMN `weight` decimal(10,3) DEFAULT NULL COMMENT ''prc_order_bill.weight来源快照'' AFTER `actual_weight`',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
UPDATE `ar_bill_detail` d
INNER JOIN `prc_order_bill` p ON p.`bill_id` = d.`prc_order_bill_id`
SET d.`weight` = p.`weight`
WHERE d.`weight` IS NULL AND p.`weight` IS NOT NULL;
+1
View File
@@ -116,6 +116,7 @@ CREATE TABLE `ar_bill_detail` (
`country_name` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '目的国家名称',
`dest_postcode` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '目的邮编',
`actual_weight` decimal(12,3) DEFAULT NULL COMMENT '实际重量KG',
`weight` decimal(10,3) DEFAULT NULL COMMENT 'prc_order_bill.weight来源快照',
`volume_weight` decimal(12,3) DEFAULT NULL COMMENT '材积重量KG',
`charge_weight` decimal(12,3) DEFAULT NULL COMMENT '计费重量KG',
`freight_rate` decimal(10,4) DEFAULT NULL COMMENT '运费单价快照',