优化套餐编辑逻辑

This commit is contained in:
wuweihua
2026-10-21 14:51:44 +08:00
parent 26a3285571
commit 1e8a449dda
11 changed files with 217 additions and 111 deletions
@@ -30,6 +30,9 @@ public interface PrcPriceSetDetailMapper
public int deletePrcPriceSetDetailByPsvId(Long psvId);
/** Hard delete detail rows by ids (draft / pending). */
public int physicalDeleteByIds(Long[] psdIds);
/** Hard delete all detail rows under a version. */
public int physicalDeleteByPsvId(@Param("psvId") Long psvId);
@@ -23,6 +23,9 @@ public interface PrcPriceSetProductMapper
public int deleteByPsvIdAndCode(@Param("psvId") Long psvId, @Param("productCode") String productCode);
/** Hard delete one product under a version (draft / pending). */
public int physicalDeleteByPsvIdAndCode(@Param("psvId") Long psvId, @Param("productCode") String productCode);
/** Hard delete all product rows under a version. */
public int physicalDeleteByPsvId(@Param("psvId") Long psvId);
@@ -35,6 +35,16 @@ public interface PrcSurchargeRelMapper
@Param("productIds") List<Long> productIds,
@Param("priceType") String priceType);
/** Hard delete surcharge rows by detail ids (draft / pending). */
public int physicalDeleteByDetailIdsAndPriceType(
@Param("detailIds") List<Long> detailIds,
@Param("priceType") String priceType);
/** Hard delete surcharge rows by set-product ids (draft / pending). */
public int physicalDeleteByProductIdsAndPriceType(
@Param("productIds") List<Long> productIds,
@Param("priceType") String priceType);
/** Hard delete surcharge rows linked to products/details under a version. */
public int physicalDeleteByPsvId(@Param("psvId") Long psvId);
@@ -547,9 +547,8 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
throw new ServiceException(MessageUtils.message("price.set.version.delete.statusNotAllowed"));
}
requireSet(version.getPriceSetId());
deleteSalesRelsByPsvId(psvId);
detailMapper.deletePrcPriceSetDetailByPsvId(psvId);
setProductMapper.deleteByPsvId(psvId);
// Draft / pending only reach here: hard-delete children with the version row
wipeVersionChildren(psvId, version.getStatus());
int rows = versionMapper.deletePrcPriceSetVersionByIds(new Long[] { psvId });
// Rechain expire_time / status for remaining versions (e.g. reopen previous effect window)
refreshVersionStatus(version.getPriceSetId());
@@ -1506,7 +1505,8 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
if (!deleteIds.isEmpty())
{
detailMapper.deletePrcPriceSetDetailByIds(deleteIds.toArray(new Long[0]));
// Draft/pending: hard delete covered rows; effect/expired: soft delete.
deleteDetailRowsByIds(deleteIds, isDraftOrPendingVersionStatus(resolveVersionStatus(psvId)));
}
removeDetailsByReplaceScopes(details, detailIndex, replaceScopes);
}
@@ -2122,9 +2122,20 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
@Override
public int deleteDetailByIds(Long[] psdIds)
{
Set<String> touchKeys = new HashSet<String>();
if (psdIds == null || psdIds.length == 0)
{
return 0;
}
List<Long> hardIds = new ArrayList<Long>();
List<Long> softIds = new ArrayList<Long>();
Set<String> hardTouchKeys = new HashSet<String>();
Set<String> softTouchKeys = new HashSet<String>();
for (Long id : psdIds)
{
if (id == null)
{
continue;
}
PrcPriceSetDetail old = detailMapper.selectPrcPriceSetDetailById(id);
if (old == null)
{
@@ -2132,27 +2143,84 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
PrcPriceSet db = requireSet(resolvePriceSetIdByPsvId(old.getPsvId()));
assertChildEditable(db);
boolean hard = isDraftOrPendingVersionStatus(resolveVersionStatus(old.getPsvId()));
if (hard)
{
hardIds.add(id);
if (old.getPsvId() != null && StringUtils.isNotEmpty(old.getProductCode()))
{
touchKeys.add(old.getPsvId() + "|" + old.getProductCode());
hardTouchKeys.add(old.getPsvId() + "|" + old.getProductCode());
}
}
if (psdIds != null && psdIds.length > 0)
else
{
List<Long> ids = new ArrayList<Long>();
for (Long id : psdIds)
softIds.add(id);
if (old.getPsvId() != null && StringUtils.isNotEmpty(old.getProductCode()))
{
if (id != null)
{
ids.add(id);
softTouchKeys.add(old.getPsvId() + "|" + old.getProductCode());
}
}
if (!ids.isEmpty())
}
int rows = 0;
if (!hardIds.isEmpty())
{
rows += deleteDetailRowsByIds(hardIds, true);
cleanupOrphanSetProducts(hardTouchKeys, true);
}
if (!softIds.isEmpty())
{
rows += deleteDetailRowsByIds(softIds, false);
cleanupOrphanSetProducts(softTouchKeys, false);
}
return rows;
}
/**
* Delete detail rows (+ SALES surcharge rels).
* hard=true: physical delete (draft/pending); false: soft delete (effect/expired).
*/
private int deleteDetailRowsByIds(List<Long> ids, boolean hard)
{
if (ids == null || ids.isEmpty())
{
return 0;
}
Long[] arr = ids.toArray(new Long[0]);
if (hard)
{
surchargeRelMapper.physicalDeleteByDetailIdsAndPriceType(ids, PrcSurchargeRel.PRICE_TYPE_SALES);
return detailMapper.physicalDeleteByIds(arr);
}
surchargeRelMapper.deleteByDetailIdsAndPriceType(ids, PrcSurchargeRel.PRICE_TYPE_SALES);
return detailMapper.deletePrcPriceSetDetailByIds(arr);
}
/** Version status draft(0) / pending(3): hard delete children. */
private boolean isDraftOrPendingVersionStatus(String status)
{
return VER_DRAFT.equals(status) || VER_PENDING.equals(status);
}
private String resolveVersionStatus(Long psvId)
{
if (psvId == null)
{
return null;
}
PrcPriceSetVersion ver = versionMapper.selectPrcPriceSetVersionById(psvId);
return ver == null ? null : ver.getStatus();
}
/**
* After detail delete: if no detail left for product, remove set-product + its SALES rels.
* hard=true uses physical delete (draft/pending); otherwise soft delete (effect/expired).
*/
private void cleanupOrphanSetProducts(Set<String> touchKeys, boolean hard)
{
if (touchKeys == null || touchKeys.isEmpty())
{
return;
}
int rows = detailMapper.deletePrcPriceSetDetailByIds(psdIds);
for (String key : touchKeys)
{
int sep = key.indexOf('|');
@@ -2166,18 +2234,51 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
q.setPsvId(psvId);
q.setProductCode(productCode);
List<PrcPriceSetDetail> left = detailMapper.selectPrcPriceSetDetailList(q);
if (left == null || left.isEmpty())
if (left != null && !left.isEmpty())
{
continue;
}
Long pspId = lookupSetProductId(psvId, productCode);
if (pspId != null)
{
surchargeRelMapper.deleteByProductIdsAndPriceType(
java.util.Collections.singletonList(pspId), PrcSurchargeRel.PRICE_TYPE_SALES);
List<Long> pspIds = java.util.Collections.singletonList(pspId);
if (hard)
{
surchargeRelMapper.physicalDeleteByProductIdsAndPriceType(pspIds, PrcSurchargeRel.PRICE_TYPE_SALES);
}
else
{
surchargeRelMapper.deleteByProductIdsAndPriceType(pspIds, PrcSurchargeRel.PRICE_TYPE_SALES);
}
}
if (hard)
{
setProductMapper.physicalDeleteByPsvIdAndCode(psvId, productCode);
}
else
{
setProductMapper.deleteByPsvIdAndCode(psvId, productCode);
}
}
return rows;
}
/** Wipe version products/details/SALES rels: physical for draft/pending, soft otherwise. */
private void wipeVersionChildren(Long psvId, String versionStatus)
{
if (psvId == null)
{
return;
}
if (isDraftOrPendingVersionStatus(versionStatus))
{
surchargeRelMapper.physicalDeleteByPsvId(psvId);
detailMapper.physicalDeleteByPsvId(psvId);
setProductMapper.physicalDeleteByPsvId(psvId);
return;
}
deleteSalesRelsByPsvId(psvId);
detailMapper.deletePrcPriceSetDetailByPsvId(psvId);
setProductMapper.deleteByPsvId(psvId);
}
@Override
@@ -3207,9 +3308,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
return;
}
Long psvId = db.getPsvId();
deleteSalesRelsByPsvId(psvId);
detailMapper.deletePrcPriceSetDetailByPsvId(psvId);
setProductMapper.deleteByPsvId(psvId);
wipeVersionChildren(psvId, db.getStatus());
if ("IMPORT".equalsIgnoreCase(newMode))
{
copyLatestPriorVersionChildren(db.getPriceSetId(), psvId);
@@ -3332,9 +3431,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
set.setDetails(new ArrayList<PrcPriceSetDetail>());
return;
}
deleteSalesRelsByPsvId(version.getPsvId());
detailMapper.deletePrcPriceSetDetailByPsvId(version.getPsvId());
setProductMapper.deleteByPsvId(version.getPsvId());
wipeVersionChildren(version.getPsvId(), version.getStatus());
// clean legacy rows without psv_id under this set (would look like duplicates in UI)
detailMapper.deleteOrphanDetailsByPriceSetId(set.getPriceSetId());
int productRows = setProductMapper.insertFromLibrary(version.getPsvId());
@@ -3481,8 +3578,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
if (!orphanIds.isEmpty())
{
surchargeRelMapper.deleteByDetailIdsAndPriceType(orphanIds, PrcSurchargeRel.PRICE_TYPE_SALES);
detailMapper.deletePrcPriceSetDetailByIds(orphanIds.toArray(new Long[0]));
deleteDetailRowsByIds(orphanIds, isDraftOrPendingVersionStatus(version.getStatus()));
}
Set<String> keepCodes = new HashSet<String>();
if (details != null)
@@ -426,6 +426,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</update>
<delete id="physicalDeleteByIds" parameterType="Long">
delete from prc_price_set_detail
where psd_id in
<foreach item="psdId" collection="array" open="(" separator="," close=")">
#{psdId}
</foreach>
</delete>
<update id="deletePrcPriceSetDetailByPriceSetId" parameterType="Long">
update prc_price_set_detail d
inner join prc_price_set_version v on v.psv_id = d.psv_id
@@ -105,6 +105,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and ifnull(is_del, '0') = '0'
</update>
<delete id="physicalDeleteByPsvIdAndCode">
delete from prc_price_set_product
where psv_id = #{psvId}
and product_code = #{productCode}
</delete>
<insert id="copyFromVersion">
insert into prc_price_set_product (
price_type, psv_id, product_code, product_name, service_level, cargo_attr,
@@ -136,6 +136,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</update>
<delete id="physicalDeleteByDetailIdsAndPriceType">
delete from prc_surcharge_rel
where price_type = #{priceType}
and detail_id in
<foreach item="id" collection="detailIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="physicalDeleteByProductIdsAndPriceType">
delete from prc_surcharge_rel
where price_type = #{priceType}
and product_id in
<foreach item="id" collection="productIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="physicalDeleteByPsvId">
delete r from prc_surcharge_rel r
where exists (
@@ -1,6 +1,6 @@
<template>
<el-card shadow="never" class="step-card">
<template #header><span>第 1 步 · 基本信息</span></template>
<template #header><span>基本信息</span></template>
<el-form ref="formRef" :model="basic" :rules="rules" label-width="120px" class="max-form">
<el-form-item label="套餐名称" prop="priceSetName">
<el-input v-model="basic.priceSetName" maxlength="50" placeholder="如:金牌电商专属套餐" />
@@ -15,7 +15,7 @@
</template>
<script setup name="StepBasicInfo">
/** Step1 basic info. setType always FIXED on save; priceBuildMode chosen on Step2. */
/** Basic info. setType always FIXED on save; priceBuildMode chosen in details panel. */
const basic = defineModel({ type: Object, required: true })
const formRef = ref()
@@ -223,7 +223,7 @@ const props = defineProps({
effectiveTime: { type: String, default: undefined },
versionNo: { type: String, default: '' },
refData: { type: Object, required: true },
headerTitle: { type: String, default: '第 2 步 · 编辑产品价格' },
headerTitle: { type: String, default: '编辑产品价格' },
/** true=edit live DB; false=create local draft until finish */
livePersist: { type: Boolean, default: true },
/** Version status: draft can change build mode; started versions lock it */
@@ -15,7 +15,7 @@
</div>
<el-alert type="info" :closable="false" show-icon class="mb12" :title="hint" />
<el-empty v-if="!filteredProducts.length" :description="emptyProduct" :image-size="72" />
<el-table v-else :data="filteredProducts" border height="calc(100vh - 280px)" @row-click="openProductDetail">
<el-table v-else :data="filteredProducts" border height="calc(100vh - 280px)">
<el-table-column :label="colCode" min-width="100">
<template #default="{ row }"><b>{{ row.productCode }}</b></template>
</el-table-column>
@@ -151,7 +151,7 @@ const activeProduct = ref(null)
const phSearch = '产品代码/名称'
const phDetailSearch = '搜索国家/分区'
const hint = '点击产品行查看国家/重量段明细(仅查看)'
const hint = '点击「查看明细」查看国家/重量段明细(仅查看)'
const emptyProduct = '暂无产品'
const emptyDetail = '暂无明细'
const colCode = '产品代码'
+16 -54
View File
@@ -1,22 +1,11 @@
<template>
<div class="app-container">
<el-steps
v-if="!newVersionMode"
:active="active"
finish-status="success"
align-center
class="wizard-steps"
>
<el-step :title="step1Title" />
<el-step :title="step2Title" />
</el-steps>
<div v-show="active === 0">
<div v-if="showBasic" class="create-section">
<step-basic-info ref="basicRef" v-model="form.basic" />
</div>
<div class="create-section">
<step-details
v-show="active === 1"
ref="detailsRef"
:details="form.details"
:products="form.products"
@@ -34,13 +23,12 @@
:build-mode-dirty="buildModeDirty"
:header-title="detailsHeaderTitle"
/>
</div>
<div class="wizard-actions">
<el-button @click="goBack">取消</el-button>
<el-button v-if="active > 0 && !directStep2" @click="active--">上一步</el-button>
<el-button v-if="active === 0" type="primary" :loading="creating" @click="goStep2">创建套餐价格</el-button>
<el-button v-if="active === 0" type="info" :loading="saving" @click="saveDraft">保存</el-button>
<el-button v-if="active === 1" type="primary" :loading="creating" @click="finishEdit">完成</el-button>
<el-button v-if="showBasic" type="info" :loading="saving" @click="saveDraft">保存</el-button>
<el-button type="primary" :loading="creating" @click="finishEdit">完成</el-button>
</div>
<el-dialog
@@ -79,7 +67,6 @@ const route = useRoute()
const refData = usePriceSetRefData()
const active = ref(0)
const saving = ref(false)
const creating = ref(false)
const progressVisible = ref(false)
@@ -90,18 +77,14 @@ const basicRef = ref()
const detailsRef = ref()
const copyMode = computed(() => String(route.query.copyVersion || '') === '1')
const newVersionMode = computed(() => String(route.query.newVersion || '') === '1')
/** copy / newVersion: defer DB write until finish (same as create step2) */
/** copy / newVersion: defer DB write until finish */
const deferPersist = computed(() => copyMode.value || newVersionMode.value)
/** Entered from detail: continue-config / copy-version / new-version jump to step2 */
const directStep2 = computed(() => deferPersist.value || String(route.query.step || '') === '2')
/** Continue-config / copy / new-version: hide basic (package already exists) */
const showBasic = computed(() => !deferPersist.value && String(route.query.step || '') !== '2')
/** Edit existing version: live PUT/pull/import. New create / copy / newVersion: defer until finish. */
const livePersist = computed(() => !!form.priceSetId && !deferPersist.value)
const step1Title = '基本信息'
const step2Title = '编辑产品价格'
const detailsHeaderTitle = computed(() =>
newVersionMode.value ? '编辑产品价格' : '第 2 步 · 编辑产品价格'
)
const detailsHeaderTitle = '编辑产品价格'
const form = reactive({
priceSetId: undefined,
@@ -172,18 +155,7 @@ async function runSaveWithProgress(payload) {
}
}
/** Step1 -> Step2: validate only; no DB write on create (defer until finish). */
async function goStep2() {
const validBasic = await basicRef.value.validate()
if (!validBasic) return
if (!(form.products || []).some(p => p && p.productCode) && !form.version.priceBuildMode) {
form.details = []
form.products = []
}
active.value = 1
}
/** Step2 finish: create/copy async save all; edit already live-saved. */
/** Finish: create/copy async save all; edit already live-saved. */
async function finishEdit() {
if (livePersist.value) {
if (!form.priceSetId) {
@@ -235,10 +207,9 @@ async function finishEdit() {
}
return
}
if (showBasic.value) {
const validBasic = await basicRef.value.validate()
if (!validBasic) {
active.value = 0
return
if (!validBasic) return
}
if (!form.version.priceBuildMode) {
proxy.$modal.msgWarning('请先选择创建价格方式')
@@ -277,13 +248,10 @@ async function finishEdit() {
}
}
/** Step0 only: persist basic draft (no detail wipe). */
/** Persist basic draft (no detail wipe). */
async function saveDraft() {
const validBasic = await basicRef.value.validate()
if (!validBasic) {
active.value = 0
return
}
if (!validBasic) return
saving.value = true
try {
const priceSetId = await runSaveWithProgress(buildPayload())
@@ -532,9 +500,6 @@ function applySetData(data, asCopy, asNewVersion) {
function loadExisting(id, asCopy, asNewVersion) {
getPriceSet(id).then(res => {
applySetData(res.data || {}, asCopy, asNewVersion)
if (asCopy || asNewVersion || String(route.query.step || '') === '2') {
active.value = 1
}
})
}
@@ -549,11 +514,8 @@ onMounted(() => {
</script>
<style scoped>
.wizard-steps {
margin-bottom: 20px;
background: #fff;
padding: 20px 12px 12px;
border-radius: 6px;
.create-section {
margin-bottom: 16px;
}
.wizard-actions {
text-align: center;