Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
liuminghui
2026-11-18 13:34:24 +08:00
20 changed files with 385 additions and 99 deletions
@@ -129,6 +129,8 @@ public class PrcOrderBill extends BaseEntity
private String errorMessage;
/** 批量查询:多个计费失败状态(仅查询用,非表字段) */
private List<Integer> billingFailStatuses;
/** 计费列表:仅返回 prc_income_bill 存在的订单(仅查询用,非表字段) */
private Boolean requireIncomeBill;
private String roundMode;
private List<PrcIncomeBillFee> incomeFees;
@@ -39,6 +39,8 @@ public class PrcPriceSet extends BaseEntity
private Date expireDate;
/** D/A/E/R/S */
private String status;
/** 仅查询用:状态多选(如 D、E) */
private List<String> statuses;
private Long tmsId;
private Integer productCount;
@@ -88,4 +88,13 @@ public interface LblProductMapper
int expireOtherActive(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo,
@Param("endDate") java.util.Date endDate, @Param("operator") String operator);
/** 恢复指定版本为生效:清空失效时间并将 status 置为 1 */
int reopenVersionRows(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo,
@Param("operator") String operator);
/** 按生效窗口写回失效时间与状态(整版号) */
int updateVersionWindowBySetAndNo(@Param("priceSetId") Long priceSetId, @Param("versionNo") Integer versionNo,
@Param("effectiveEnd") java.util.Date effectiveEnd, @Param("status") String status,
@Param("operator") String operator);
}
@@ -350,6 +350,21 @@ public class LblProductServiceImpl implements ILblProductService
{
return Collections.emptyList();
}
// 旧数据或历史错误串联时,查询时自动按生效时间重串
if (labelVersionWindowsNeedRelink(groups))
{
refreshLabelVersionWindows(priceSetId);
groups = lblProductMapper.selectLabelVersionGroups(priceSetId);
if (groups == null || groups.isEmpty())
{
return Collections.emptyList();
}
}
return decorateLabelVersions(priceSetId, groups);
}
private List<LabelPackageVersion> decorateLabelVersions(Long priceSetId, List<LabelPackageVersion> groups)
{
Date now = new Date();
for (LabelPackageVersion ver : groups)
{
@@ -376,9 +391,87 @@ public class LblProductServiceImpl implements ILblProductService
ver.setStatus(TERM_EFFECT);
}
}
// 按生效时间倒序;未设生效时间的待启动版排前
groups.sort((a, b) -> {
Date ta = a.getEffectiveTime();
Date tb = b.getEffectiveTime();
if (ta == null && tb == null)
{
return Integer.compare(
b.getVersionNo() == null ? 0 : b.getVersionNo(),
a.getVersionNo() == null ? 0 : a.getVersionNo());
}
if (ta == null)
{
return -1;
}
if (tb == null)
{
return 1;
}
int c = tb.compareTo(ta);
if (c != 0)
{
return c;
}
return Integer.compare(
b.getVersionNo() == null ? 0 : b.getVersionNo(),
a.getVersionNo() == null ? 0 : a.getVersionNo());
});
return groups;
}
/** 检查各版失效时间是否已按生效时间升序串联 */
private boolean labelVersionWindowsNeedRelink(List<LabelPackageVersion> groups)
{
List<LabelPackageVersion> timed = new ArrayList<LabelPackageVersion>();
for (LabelPackageVersion ver : groups)
{
if (ver != null && ver.getVersionNo() != null && ver.getEffectiveTime() != null)
{
timed.add(ver);
}
}
if (timed.size() <= 1)
{
// 单版若还挂着失效时间,也需清掉
return timed.size() == 1 && timed.get(0).getExpireTime() != null;
}
timed.sort((a, b) -> {
int c = a.getEffectiveTime().compareTo(b.getEffectiveTime());
if (c != 0)
{
return c;
}
return Integer.compare(
a.getVersionNo() == null ? 0 : a.getVersionNo(),
b.getVersionNo() == null ? 0 : b.getVersionNo());
});
for (int i = 0; i < timed.size(); i++)
{
Date nextStart = (i + 1 < timed.size()) ? timed.get(i + 1).getEffectiveTime() : null;
Date end = timed.get(i).getExpireTime();
if (!sameLabelTime(end, nextStart))
{
return true;
}
}
return false;
}
private static boolean sameLabelTime(Date a, Date b)
{
if (a == null && b == null)
{
return true;
}
if (a == null || b == null)
{
return false;
}
return a.getTime() == b.getTime();
}
@Override
@Transactional(rollbackFor = Exception.class)
public String activateVersion(Long priceSetId, Integer versionNo, Date effectiveTime)
@@ -389,8 +482,9 @@ public class LblProductServiceImpl implements ILblProductService
throw new ServiceException("请指定版本号");
}
Date start = effectiveTime == null ? new Date() : effectiveTime;
lblProductMapper.expireOtherActive(priceSetId, versionNo, yesterday(), SecurityUtils.getUsername());
// 先写入本版生效时间,再按生效时间串联各版失效窗/状态
lblProductMapper.activateVersionRows(priceSetId, versionNo, start, SecurityUtils.getUsername());
refreshLabelVersionWindows(priceSetId);
PrcPriceSet set = priceSetMapper.selectPrcPriceSetById(priceSetId);
if (set != null && !"E".equalsIgnoreCase(String.valueOf(set.getStatus())))
{
@@ -406,16 +500,116 @@ public class LblProductServiceImpl implements ILblProductService
public int deleteVersion(Long priceSetId, Integer versionNo)
{
assertLabelSet(priceSetId);
List<Long> ids = lblProductMapper.selectVersionIdsBySetAndNo(priceSetId, versionNo);
if (ids != null)
if (versionNo == null)
{
for (Long versionId : ids)
throw new ServiceException("请指定版本号");
}
LabelPackageVersion target = null;
for (LabelPackageVersion ver : selectVersions(priceSetId))
{
if (versionNo.equals(ver.getVersionNo()))
{
lblProductMapper.deleteWeightBandsByVersion(versionId);
lblProductMapper.deleteSurchargesByVersion(versionId);
target = ver;
break;
}
}
return lblProductMapper.deletePendingVersionsBySetAndNo(priceSetId, versionNo);
if (target == null)
{
throw new ServiceException("版本不存在");
}
String status = target.getStatus();
// 待生效/已生效可删;已失效仅可查看
if (!TERM_PENDING.equals(status) && !TERM_EFFECT.equals(status))
{
throw new ServiceException("已失效版本不可删除");
}
List<Long> ids = lblProductMapper.selectVersionIdsBySetAndNo(priceSetId, versionNo);
if (ids == null || ids.isEmpty())
{
throw new ServiceException("版本不存在");
}
for (Long versionId : ids)
{
lblProductMapper.deleteWeightBandsByVersion(versionId);
lblProductMapper.deleteSurchargesByVersion(versionId);
}
int rows = lblProductMapper.deleteAllVersionsBySetAndNo(priceSetId, versionNo);
if (rows <= 0)
{
throw new ServiceException("删除失败,版本不存在或已删除");
}
// 删除后按生效时间重新串联失效窗,最新窗口自动恢复为生效
refreshLabelVersionWindows(priceSetId);
return rows;
}
/**
* 按生效时间升序串联各版:本版失效时间 = 下一版生效时间;最后一版无失效时间。
* 状态按当前时间落在哪个窗口判定(待生效/已生效/已失效)。
*/
private void refreshLabelVersionWindows(Long priceSetId)
{
if (priceSetId == null)
{
return;
}
List<LabelPackageVersion> groups = lblProductMapper.selectLabelVersionGroups(priceSetId);
if (groups == null || groups.isEmpty())
{
return;
}
List<LabelPackageVersion> timed = new ArrayList<LabelPackageVersion>();
for (LabelPackageVersion ver : groups)
{
if (ver != null && ver.getVersionNo() != null && ver.getEffectiveTime() != null)
{
timed.add(ver);
}
}
timed.sort((a, b) -> {
int c = a.getEffectiveTime().compareTo(b.getEffectiveTime());
if (c != 0)
{
return c;
}
return Integer.compare(
a.getVersionNo() == null ? 0 : a.getVersionNo(),
b.getVersionNo() == null ? 0 : b.getVersionNo());
});
Date now = new Date();
String operator = safeLabelOperator();
for (int i = 0; i < timed.size(); i++)
{
LabelPackageVersion ver = timed.get(i);
Date nextStart = (i + 1 < timed.size()) ? timed.get(i + 1).getEffectiveTime() : null;
String status;
Date start = ver.getEffectiveTime();
if (start.after(now))
{
status = TERM_PENDING;
}
else if (nextStart != null && !nextStart.after(now))
{
status = TERM_EXPIRED;
}
else
{
status = TERM_EFFECT;
}
lblProductMapper.updateVersionWindowBySetAndNo(priceSetId, ver.getVersionNo(), nextStart, status, operator);
}
}
private static String safeLabelOperator()
{
try
{
return SecurityUtils.getUsername();
}
catch (Exception ex)
{
return "system";
}
}
@Override
@@ -165,7 +165,7 @@
from prc_label_product_version
where price_set_id = #{priceSetId}
group by price_set_id, version_no
order by version_no desc
order by (min(effective_start) is null) desc, min(effective_start) desc, version_no desc
</select>
<insert id="insertWeightBand" useGeneratedKeys="true" keyProperty="bandId">
@@ -329,4 +329,24 @@
and version_no &lt;&gt; #{versionNo}
and status = '1'
</update>
<update id="reopenVersionRows">
update prc_label_product_version
set status = '1',
effective_end = null,
updated_by = #{operator},
update_time = sysdate()
where price_set_id = #{priceSetId}
and version_no = #{versionNo}
</update>
<update id="updateVersionWindowBySetAndNo">
update prc_label_product_version
set effective_end = #{effectiveEnd},
status = #{status},
updated_by = #{operator},
update_time = sysdate()
where price_set_id = #{priceSetId}
and version_no = #{versionNo}
</update>
</mapper>
@@ -516,6 +516,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{bfs}
</foreach>
</if>
<if test="requireIncomeBill != null and requireIncomeBill">
AND EXISTS (
SELECT 1 FROM prc_income_bill i WHERE i.bill_id = p.bill_id
)
</if>
<if test="refundStatus != null and refundStatus != ''">
AND p.refund_status = #{refundStatus}
</if>
@@ -80,7 +80,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="setCategory != null and setCategory != ''">
AND ifnull(s.set_category, 'PACKAGE') = #{setCategory}
</if>
<if test="status != null and status != ''">
<if test="statuses != null and statuses.size() &gt; 0">
AND s.status in
<foreach collection="statuses" item="st" open="(" separator="," close=")">
#{st}
</foreach>
</if>
<if test="(statuses == null or statuses.size() == 0) and status != null and status != ''">
AND s.status = #{status}
</if>
<if test="tmsId != null">