提交价格套餐功能

This commit is contained in:
wuweihua
2026-09-04 14:56:05 +08:00
parent f8b9681583
commit 5e15ab9c44
47 changed files with 6243 additions and 9 deletions
@@ -0,0 +1,53 @@
package com.ruoyi.price.service;
import java.util.List;
import com.ruoyi.price.domain.PrcCustomerPriceSet;
import com.ruoyi.price.domain.PrcPriceSet;
import com.ruoyi.price.domain.PrcPriceSetCheckItem;
import com.ruoyi.price.domain.PrcPriceSetDetail;
/**
* 价格套餐 服务层
*
* @author ruoyi
*/
public interface IPrcPriceSetService
{
public PrcPriceSet selectPrcPriceSetById(Long priceSetId);
public List<PrcPriceSet> selectPrcPriceSetList(PrcPriceSet set);
public Long savePrcPriceSet(PrcPriceSet set);
public int updatePrcPriceSet(PrcPriceSet set);
public int deletePrcPriceSetByIds(Long[] priceSetIds);
public int submit(Long priceSetId, String updateBy);
public int approve(Long priceSetId, String updateBy);
public int reject(Long priceSetId, String updateBy);
public int disable(Long priceSetId, String updateBy);
public Long copy(Long priceSetId, String createBy);
public List<PrcPriceSetCheckItem> validate(PrcPriceSet set);
public List<PrcPriceSetDetail> selectDetailList(PrcPriceSetDetail detail);
public int insertDetail(PrcPriceSetDetail detail);
public int updateDetail(PrcPriceSetDetail detail);
public int deleteDetailByIds(Long[] psdIds);
public List<PrcCustomerPriceSet> selectCustomerList(PrcCustomerPriceSet customer);
public int insertCustomer(PrcCustomerPriceSet customer);
public int updateCustomer(PrcCustomerPriceSet customer);
public int deleteCustomerByIds(Long[] customerPricesetIds);
}
@@ -0,0 +1,33 @@
package com.ruoyi.price.service;
import java.util.List;
import com.ruoyi.price.domain.PrcWeightSectionDetail;
import com.ruoyi.price.domain.PrcWeightSectionTemplate;
/**
* 重量段管理 服务层
*
* @author ruoyi
*/
public interface IPrcWeightService
{
public PrcWeightSectionTemplate selectPrcWeightSectionTemplateById(Long wstId);
public List<PrcWeightSectionTemplate> selectPrcWeightSectionTemplateList(PrcWeightSectionTemplate template);
public int insertPrcWeightSectionTemplate(PrcWeightSectionTemplate template);
public int updatePrcWeightSectionTemplate(PrcWeightSectionTemplate template);
public int deletePrcWeightSectionTemplateByIds(Long[] wstIds);
public PrcWeightSectionDetail selectPrcWeightSectionDetailById(Long wsdId);
public List<PrcWeightSectionDetail> selectPrcWeightSectionDetailList(PrcWeightSectionDetail detail);
public int insertPrcWeightSectionDetail(PrcWeightSectionDetail detail);
public int updatePrcWeightSectionDetail(PrcWeightSectionDetail detail);
public int deletePrcWeightSectionDetailByIds(Long[] wsdIds);
}
@@ -0,0 +1,44 @@
package com.ruoyi.price.service;
import java.util.List;
import com.ruoyi.price.domain.XtdZoneCountry;
import com.ruoyi.price.domain.XtdZoneDivision;
import com.ruoyi.price.domain.XtdZoneScheme;
/**
* 分区管理 服务层
*
* @author ruoyi
*/
public interface IXtdZoneService
{
public XtdZoneScheme selectXtdZoneSchemeById(Long zsId);
public List<XtdZoneScheme> selectXtdZoneSchemeList(XtdZoneScheme scheme);
public int insertXtdZoneScheme(XtdZoneScheme scheme);
public int updateXtdZoneScheme(XtdZoneScheme scheme);
public int deleteXtdZoneSchemeByIds(Long[] zsIds);
public XtdZoneDivision selectXtdZoneDivisionById(Long zdId);
public List<XtdZoneDivision> selectXtdZoneDivisionList(XtdZoneDivision division);
public int insertXtdZoneDivision(XtdZoneDivision division);
public int updateXtdZoneDivision(XtdZoneDivision division);
public int deleteXtdZoneDivisionByIds(Long[] zdIds);
public XtdZoneCountry selectXtdZoneCountryById(Long zcId);
public List<XtdZoneCountry> selectXtdZoneCountryList(XtdZoneCountry country);
public int insertXtdZoneCountry(XtdZoneCountry country);
public int updateXtdZoneCountry(XtdZoneCountry country);
public int deleteXtdZoneCountryByIds(Long[] zcIds);
}
@@ -0,0 +1,751 @@
package com.ruoyi.price.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.PrcCustomerPriceSet;
import com.ruoyi.price.domain.PrcPriceSet;
import com.ruoyi.price.domain.PrcPriceSetCheckItem;
import com.ruoyi.price.domain.PrcPriceSetDetail;
import com.ruoyi.price.mapper.PrcCustomerPriceSetMapper;
import com.ruoyi.price.mapper.PrcPriceSetDetailMapper;
import com.ruoyi.price.mapper.PrcPriceSetMapper;
import com.ruoyi.price.service.IPrcPriceSetService;
/**
* 价格套餐 服务层实现
*
* @author ruoyi
*/
@Service
public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
private static final String STATUS_DRAFT = "D";
private static final String STATUS_AUDIT = "A";
private static final String STATUS_EFFECT = "E";
private static final String STATUS_REJECT = "R";
private static final String STATUS_STOP = "S";
private static final String TYPE_FIXED = "FIXED";
private static final String TYPE_DISCOUNT = "DISCOUNT";
@Autowired
private PrcPriceSetMapper setMapper;
@Autowired
private PrcPriceSetDetailMapper detailMapper;
@Autowired
private PrcCustomerPriceSetMapper customerMapper;
@Override
public PrcPriceSet selectPrcPriceSetById(Long priceSetId)
{
PrcPriceSet set = setMapper.selectPrcPriceSetById(priceSetId);
if (set != null)
{
fillExpired(set);
PrcPriceSetDetail query = new PrcPriceSetDetail();
query.setPriceSetId(priceSetId);
set.setDetails(detailMapper.selectPrcPriceSetDetailList(query));
PrcCustomerPriceSet cquery = new PrcCustomerPriceSet();
cquery.setPriceSetId(priceSetId);
set.setCustomers(customerMapper.selectPrcCustomerPriceSetList(cquery));
}
return set;
}
@Override
public List<PrcPriceSet> selectPrcPriceSetList(PrcPriceSet set)
{
List<PrcPriceSet> list = setMapper.selectPrcPriceSetList(set);
for (PrcPriceSet item : list)
{
fillExpired(item);
}
return list;
}
@Override
@Transactional
public Long savePrcPriceSet(PrcPriceSet set)
{
validateBasic(set, false);
if (set.getPriceSetId() == null)
{
if (StringUtils.isEmpty(set.getStatus()))
{
set.setStatus(STATUS_DRAFT);
}
if (!STATUS_DRAFT.equals(set.getStatus()) && !STATUS_AUDIT.equals(set.getStatus()))
{
set.setStatus(STATUS_DRAFT);
}
if (StringUtils.isEmpty(set.getSetType()))
{
set.setSetType(TYPE_FIXED);
}
setMapper.insertPrcPriceSet(set);
if (StringUtils.isEmpty(set.getPriceSetCode()))
{
set.setPriceSetCode(String.format("SET%04d", set.getPriceSetId()));
setMapper.updatePrcPriceSet(set);
}
}
else
{
PrcPriceSet db = requireSet(set.getPriceSetId());
assertBasicEditable(db);
set.setStatus(db.getStatus());
setMapper.updatePrcPriceSet(set);
}
replaceChildren(set);
if ("Y".equalsIgnoreCase(set.getSubmitFlag()))
{
submit(set.getPriceSetId(), set.getUpdateBy() != null ? set.getUpdateBy() : set.getCreateBy());
}
return set.getPriceSetId();
}
@Override
public int updatePrcPriceSet(PrcPriceSet set)
{
PrcPriceSet db = requireSet(set.getPriceSetId());
assertBasicEditable(db);
validateBasic(set, false);
set.setStatus(db.getStatus());
return setMapper.updatePrcPriceSet(set);
}
@Override
@Transactional
public int deletePrcPriceSetByIds(Long[] priceSetIds)
{
for (Long id : priceSetIds)
{
PrcPriceSet db = requireSet(id);
if (!STATUS_DRAFT.equals(db.getStatus()) && !STATUS_REJECT.equals(db.getStatus()))
{
throw new ServiceException("仅草稿或驳回状态的套餐允许删除:" + displayName(db));
}
int bound = customerMapper.countByPriceSetId(id);
if (bound > 0)
{
throw new ServiceException("套餐【" + displayName(db) + "】已绑定客户,请先解绑后再删除");
}
detailMapper.deletePrcPriceSetDetailByPriceSetId(id);
}
return setMapper.deletePrcPriceSetByIds(priceSetIds);
}
@Override
public int submit(Long priceSetId, String updateBy)
{
PrcPriceSet db = requireSet(priceSetId);
if (!STATUS_DRAFT.equals(db.getStatus()) && !STATUS_REJECT.equals(db.getStatus()))
{
throw new ServiceException("当前状态不允许提交审核");
}
PrcPriceSet payload = selectPrcPriceSetById(priceSetId);
List<PrcPriceSetCheckItem> items = validate(payload);
assertNoFail(items);
PrcPriceSet upd = new PrcPriceSet();
upd.setPriceSetId(priceSetId);
upd.setStatus(STATUS_AUDIT);
upd.setUpdateBy(updateBy);
return setMapper.updatePrcPriceSetStatus(upd);
}
@Override
public int approve(Long priceSetId, String updateBy)
{
PrcPriceSet db = requireSet(priceSetId);
if (!STATUS_AUDIT.equals(db.getStatus()))
{
throw new ServiceException("仅审核中的套餐可以生效");
}
PrcPriceSet upd = new PrcPriceSet();
upd.setPriceSetId(priceSetId);
upd.setStatus(STATUS_EFFECT);
upd.setUpdateBy(updateBy);
return setMapper.updatePrcPriceSetStatus(upd);
}
@Override
public int reject(Long priceSetId, String updateBy)
{
PrcPriceSet db = requireSet(priceSetId);
if (!STATUS_AUDIT.equals(db.getStatus()))
{
throw new ServiceException("仅审核中的套餐可以驳回");
}
PrcPriceSet upd = new PrcPriceSet();
upd.setPriceSetId(priceSetId);
upd.setStatus(STATUS_REJECT);
upd.setUpdateBy(updateBy);
return setMapper.updatePrcPriceSetStatus(upd);
}
@Override
public int disable(Long priceSetId, String updateBy)
{
PrcPriceSet db = requireSet(priceSetId);
if (!STATUS_EFFECT.equals(db.getStatus()))
{
throw new ServiceException("仅生效中的套餐可以停用");
}
PrcPriceSet upd = new PrcPriceSet();
upd.setPriceSetId(priceSetId);
upd.setStatus(STATUS_STOP);
upd.setUpdateBy(updateBy);
return setMapper.updatePrcPriceSetStatus(upd);
}
@Override
@Transactional
public Long copy(Long priceSetId, String createBy)
{
PrcPriceSet src = selectPrcPriceSetById(priceSetId);
if (src == null)
{
throw new ServiceException("套餐不存在");
}
PrcPriceSet copy = new PrcPriceSet();
copy.setPriceSetName(src.getPriceSetName() + "-副本");
copy.setPriceSetNote(src.getPriceSetNote());
copy.setSetType(src.getSetType());
copy.setDefaultDiscount(src.getDefaultDiscount());
copy.setDefaultType(src.getDefaultType());
copy.setCalculateSign(src.getCalculateSign());
copy.setEffectiveDate(src.getEffectiveDate());
copy.setExpireDate(src.getExpireDate());
copy.setStatus(STATUS_DRAFT);
copy.setTmsId(src.getTmsId());
copy.setCreateBy(createBy);
List<PrcPriceSetDetail> details = new ArrayList<PrcPriceSetDetail>();
if (src.getDetails() != null)
{
for (PrcPriceSetDetail d : src.getDetails())
{
PrcPriceSetDetail nd = new PrcPriceSetDetail();
nd.setProductCode(d.getProductCode());
nd.setProductName(d.getProductName());
nd.setCountryCode(d.getCountryCode());
nd.setCountryName(d.getCountryName());
nd.setZdId(d.getZdId());
nd.setWsdId(d.getWsdId());
nd.setWeightLabel(d.getWeightLabel());
nd.setFvValue(d.getFvValue());
nd.setFvRegistrationFee(d.getFvRegistrationFee());
nd.setDiscountValue(d.getDiscountValue());
nd.setPrId(d.getPrId());
details.add(nd);
}
}
copy.setDetails(details);
copy.setCustomers(new ArrayList<PrcCustomerPriceSet>());
return savePrcPriceSet(copy);
}
@Override
public List<PrcPriceSetCheckItem> validate(PrcPriceSet set)
{
List<PrcPriceSetCheckItem> items = new ArrayList<PrcPriceSetCheckItem>();
if (set.getPriceSetId() != null && (set.getDetails() == null || set.getCustomers() == null))
{
PrcPriceSet db = selectPrcPriceSetById(set.getPriceSetId());
if (db != null)
{
if (StringUtils.isEmpty(set.getPriceSetName()))
{
set.setPriceSetName(db.getPriceSetName());
}
if (set.getSetType() == null)
{
set.setSetType(db.getSetType());
}
if (set.getEffectiveDate() == null)
{
set.setEffectiveDate(db.getEffectiveDate());
}
if (set.getExpireDate() == null)
{
set.setExpireDate(db.getExpireDate());
}
if (set.getDefaultDiscount() == null)
{
set.setDefaultDiscount(db.getDefaultDiscount());
}
if (set.getDetails() == null)
{
set.setDetails(db.getDetails());
}
if (set.getCustomers() == null)
{
set.setCustomers(db.getCustomers());
}
}
}
int nameCount = setMapper.countByName(set);
if (StringUtils.isEmpty(set.getPriceSetName()))
{
items.add(new PrcPriceSetCheckItem("套餐名称是否重复", "FAIL", "套餐名称不能为空"));
}
else if (nameCount > 0)
{
items.add(new PrcPriceSetCheckItem("套餐名称是否重复", "FAIL", "当前名称已被占用"));
}
else
{
items.add(new PrcPriceSetCheckItem("套餐名称是否重复", "PASS", "当前名称未占用"));
}
if (set.getEffectiveDate() == null)
{
items.add(new PrcPriceSetCheckItem("生效日期 ≤ 失效日期", "FAIL", "生效日期不能为空"));
}
else if (set.getExpireDate() != null && set.getEffectiveDate().after(set.getExpireDate()))
{
items.add(new PrcPriceSetCheckItem("生效日期 ≤ 失效日期", "FAIL", "生效日期不能晚于失效日期"));
}
else
{
String msg = DateUtils.parseDateToStr("yyyy-MM-dd", set.getEffectiveDate())
+ " ≤ "
+ (set.getExpireDate() == null ? "长期" : DateUtils.parseDateToStr("yyyy-MM-dd", set.getExpireDate()));
items.add(new PrcPriceSetCheckItem("生效日期 ≤ 失效日期", "PASS", msg));
}
String setType = StringUtils.isEmpty(set.getSetType()) ? TYPE_FIXED : set.getSetType();
List<PrcPriceSetDetail> details = filterDetails(set.getDetails());
if (TYPE_FIXED.equals(setType))
{
int incomplete = 0;
for (PrcPriceSetDetail d : details)
{
if (StringUtils.isEmpty(d.getProductCode()) || StringUtils.isEmpty(d.getCountryCode())
|| (d.getWsdId() == null && StringUtils.isEmpty(d.getWeightLabel()))
|| d.getFvValue() == null || d.getFvRegistrationFee() == null)
{
incomplete++;
}
}
if (details.isEmpty())
{
items.add(new PrcPriceSetCheckItem("FIXED 明细完整性", "FAIL", "固定价模式至少需要 1 条明细"));
}
else if (incomplete > 0)
{
items.add(new PrcPriceSetCheckItem("FIXED 明细完整性", "FAIL", incomplete + " 条明细缺少产品/国家/重量段/运费/挂号费"));
}
else
{
items.add(new PrcPriceSetCheckItem("FIXED 明细完整性", "PASS", details.size() + " 条明细,运费与挂号费均填写"));
}
}
else
{
if (set.getDefaultDiscount() == null
|| set.getDefaultDiscount().compareTo(BigDecimal.ONE) < 0
|| set.getDefaultDiscount().compareTo(new BigDecimal("99")) > 0)
{
items.add(new PrcPriceSetCheckItem("DISCOUNT 默认折扣", "FAIL", "折扣模式默认折扣需在 1~99"));
}
else
{
items.add(new PrcPriceSetCheckItem("DISCOUNT 默认折扣", "PASS", "默认折扣 " + set.getDefaultDiscount().stripTrailingZeros().toPlainString() + "%"));
}
}
Set<String> uniq = new HashSet<String>();
boolean dup = false;
for (PrcPriceSetDetail d : details)
{
String key;
if (TYPE_FIXED.equals(setType))
{
key = nvl(d.getProductCode()) + "|" + nvl(d.getCountryCode()) + "|"
+ (d.getWsdId() != null ? d.getWsdId() : nvl(d.getWeightLabel()));
}
else
{
key = nvl(d.getProductCode());
}
if (!uniq.add(key) && StringUtils.isNotEmpty(d.getProductCode()))
{
dup = true;
break;
}
}
if (dup)
{
items.add(new PrcPriceSetCheckItem("同产品同国家同重量段是否重复", "FAIL", "存在重复明细"));
}
else
{
items.add(new PrcPriceSetCheckItem("同产品同国家同重量段是否重复", "PASS", "无重复明细"));
}
List<PrcCustomerPriceSet> customers = filterCustomers(set.getCustomers());
int overlap = 0;
for (PrcCustomerPriceSet c : customers)
{
overlap += customerMapper.countOverlap(c.getCustomerId(), set.getPriceSetId(),
c.getPrBegindate() != null ? c.getPrBegindate() : set.getEffectiveDate(),
c.getPrEnddate() != null ? c.getPrEnddate() : set.getExpireDate());
}
if (overlap > 0)
{
items.add(new PrcPriceSetCheckItem("与同客户现有套餐是否冲突", "WARN", "存在 " + overlap + " 条与已生效套餐日期重叠的客户绑定,可共存但需确认优先级"));
}
else if (customers.isEmpty())
{
items.add(new PrcPriceSetCheckItem("与同客户现有套餐是否冲突", "INFO", "暂未绑定客户,可后续补充"));
}
else
{
items.add(new PrcPriceSetCheckItem("与同客户现有套餐是否冲突", "PASS", "未发现与已生效套餐的日期重叠"));
}
if (TYPE_FIXED.equals(setType) && !details.isEmpty())
{
items.add(new PrcPriceSetCheckItem("运费单价 vs 默认等级价偏差", "INFO", "默认等级价对照将在计费试算上线后自动计算"));
}
else if (TYPE_DISCOUNT.equals(setType))
{
items.add(new PrcPriceSetCheckItem("运费单价 vs 默认等级价偏差", "INFO", "折扣模式按下单时默认等级价 × 折扣计费"));
}
return items;
}
@Override
public List<PrcPriceSetDetail> selectDetailList(PrcPriceSetDetail detail)
{
return detailMapper.selectPrcPriceSetDetailList(detail);
}
@Override
public int insertDetail(PrcPriceSetDetail detail)
{
PrcPriceSet db = requireSet(detail.getPriceSetId());
assertChildEditable(db);
validateDetail(db, detail);
return detailMapper.insertPrcPriceSetDetail(detail);
}
@Override
public int updateDetail(PrcPriceSetDetail detail)
{
PrcPriceSetDetail old = detailMapper.selectPrcPriceSetDetailById(detail.getPsdId());
if (old == null)
{
throw new ServiceException("套餐明细不存在");
}
PrcPriceSet db = requireSet(old.getPriceSetId());
assertChildEditable(db);
detail.setPriceSetId(old.getPriceSetId());
validateDetail(db, detail);
return detailMapper.updatePrcPriceSetDetail(detail);
}
@Override
public int deleteDetailByIds(Long[] psdIds)
{
for (Long id : psdIds)
{
PrcPriceSetDetail old = detailMapper.selectPrcPriceSetDetailById(id);
if (old == null)
{
continue;
}
PrcPriceSet db = requireSet(old.getPriceSetId());
assertChildEditable(db);
}
return detailMapper.deletePrcPriceSetDetailByIds(psdIds);
}
@Override
public List<PrcCustomerPriceSet> selectCustomerList(PrcCustomerPriceSet customer)
{
return customerMapper.selectPrcCustomerPriceSetList(customer);
}
@Override
public int insertCustomer(PrcCustomerPriceSet customer)
{
PrcPriceSet db = requireSet(customer.getPriceSetId());
assertChildEditable(db);
validateCustomer(customer, db);
if (customer.getBindPriority() == null)
{
customer.setBindPriority(1);
}
return customerMapper.insertPrcCustomerPriceSet(customer);
}
@Override
public int updateCustomer(PrcCustomerPriceSet customer)
{
PrcCustomerPriceSet old = customerMapper.selectPrcCustomerPriceSetById(customer.getCustomerPricesetId());
if (old == null)
{
throw new ServiceException("客户绑定不存在");
}
PrcPriceSet db = requireSet(old.getPriceSetId());
assertChildEditable(db);
customer.setPriceSetId(old.getPriceSetId());
validateCustomer(customer, db);
return customerMapper.updatePrcCustomerPriceSet(customer);
}
@Override
public int deleteCustomerByIds(Long[] customerPricesetIds)
{
for (Long id : customerPricesetIds)
{
PrcCustomerPriceSet old = customerMapper.selectPrcCustomerPriceSetById(id);
if (old == null)
{
continue;
}
PrcPriceSet db = requireSet(old.getPriceSetId());
if (STATUS_AUDIT.equals(db.getStatus()))
{
throw new ServiceException("审核中的套餐不允许解绑客户");
}
}
return customerMapper.deletePrcCustomerPriceSetByIds(customerPricesetIds);
}
private void replaceChildren(PrcPriceSet set)
{
if (set.getDetails() != null)
{
detailMapper.deletePrcPriceSetDetailByPriceSetId(set.getPriceSetId());
for (PrcPriceSetDetail d : filterDetails(set.getDetails()))
{
validateDetail(set, d);
d.setPsdId(null);
d.setPriceSetId(set.getPriceSetId());
detailMapper.insertPrcPriceSetDetail(d);
}
}
if (set.getCustomers() != null)
{
customerMapper.deletePrcCustomerPriceSetByPriceSetId(set.getPriceSetId());
for (PrcCustomerPriceSet c : filterCustomers(set.getCustomers()))
{
validateCustomer(c, set);
c.setCustomerPricesetId(null);
c.setPriceSetId(set.getPriceSetId());
c.setCreateBy(set.getCreateBy());
if (c.getBindPriority() == null)
{
c.setBindPriority(1);
}
customerMapper.insertPrcCustomerPriceSet(c);
}
}
}
private void validateBasic(PrcPriceSet set, boolean strictSubmit)
{
if (StringUtils.isEmpty(set.getPriceSetName()))
{
throw new ServiceException("套餐名称不能为空");
}
if (set.getEffectiveDate() == null)
{
throw new ServiceException("生效日期不能为空");
}
if (set.getExpireDate() != null && set.getEffectiveDate().after(set.getExpireDate()))
{
throw new ServiceException("生效日期不能晚于失效日期");
}
if (TYPE_DISCOUNT.equals(set.getSetType()))
{
if (set.getDefaultDiscount() == null
|| set.getDefaultDiscount().compareTo(BigDecimal.ONE) < 0
|| set.getDefaultDiscount().compareTo(new BigDecimal("99")) > 0)
{
throw new ServiceException("折扣模式默认折扣需在 1~99");
}
}
if (setMapper.countByName(set) > 0)
{
throw new ServiceException("套餐名称已存在");
}
if (strictSubmit)
{
assertNoFail(validate(set));
}
}
private void validateDetail(PrcPriceSet set, PrcPriceSetDetail detail)
{
if (StringUtils.isEmpty(detail.getProductCode()))
{
throw new ServiceException("明细产品代码不能为空");
}
if (TYPE_FIXED.equals(set.getSetType()))
{
if (StringUtils.isEmpty(detail.getCountryCode()))
{
throw new ServiceException("固定价明细必须填写国家");
}
if (detail.getWsdId() == null && StringUtils.isEmpty(detail.getWeightLabel()))
{
throw new ServiceException("固定价明细必须填写重量段");
}
if (detail.getFvValue() == null)
{
throw new ServiceException("固定价明细必须填写运费单价");
}
if (detail.getFvRegistrationFee() == null)
{
throw new ServiceException("固定价明细必须填写挂号费");
}
}
if (StringUtils.isNotEmpty(detail.getCountryCode()))
{
detail.setCountryCode(detail.getCountryCode().toUpperCase());
}
}
private void validateCustomer(PrcCustomerPriceSet customer, PrcPriceSet set)
{
if (customer.getCustomerId() == null || customer.getCustomerId().longValue() <= 0)
{
throw new ServiceException("客户ID不能为空");
}
if (customer.getPrBegindate() == null)
{
customer.setPrBegindate(set.getEffectiveDate());
}
if (customer.getPrBegindate() == null)
{
throw new ServiceException("客户绑定生效日期不能为空");
}
if (customer.getPrEnddate() != null && customer.getPrBegindate().after(customer.getPrEnddate()))
{
throw new ServiceException("客户绑定生效日期不能晚于失效日期");
}
if (customer.getBindPriority() != null && customer.getBindPriority().intValue() < 1)
{
throw new ServiceException("优先级必须大于等于 1");
}
}
private void assertBasicEditable(PrcPriceSet db)
{
if (STATUS_AUDIT.equals(db.getStatus()))
{
throw new ServiceException("审核中的套餐不允许修改");
}
if (STATUS_STOP.equals(db.getStatus()))
{
throw new ServiceException("已停用的套餐不允许修改,请使用复用新建");
}
}
private void assertChildEditable(PrcPriceSet db)
{
if (STATUS_AUDIT.equals(db.getStatus()))
{
throw new ServiceException("审核中的套餐不允许改明细或客户");
}
if (STATUS_STOP.equals(db.getStatus()))
{
throw new ServiceException("已停用的套餐不允许改明细或客户");
}
}
private void assertNoFail(List<PrcPriceSetCheckItem> items)
{
for (PrcPriceSetCheckItem item : items)
{
if ("FAIL".equals(item.getResult()))
{
throw new ServiceException(item.getItem() + ":" + item.getMessage());
}
}
}
private PrcPriceSet requireSet(Long priceSetId)
{
PrcPriceSet db = setMapper.selectPrcPriceSetById(priceSetId);
if (db == null)
{
throw new ServiceException("套餐不存在");
}
return db;
}
private void fillExpired(PrcPriceSet set)
{
Date today = DateUtils.parseDate(DateUtils.getDate());
boolean expired = STATUS_EFFECT.equals(set.getStatus())
&& set.getExpireDate() != null
&& today != null
&& set.getExpireDate().before(today);
set.setExpired(Boolean.valueOf(expired));
}
private List<PrcPriceSetDetail> filterDetails(List<PrcPriceSetDetail> details)
{
List<PrcPriceSetDetail> list = new ArrayList<PrcPriceSetDetail>();
if (details == null)
{
return list;
}
for (PrcPriceSetDetail d : details)
{
if (d != null && StringUtils.isNotEmpty(d.getProductCode()))
{
list.add(d);
}
}
return list;
}
private List<PrcCustomerPriceSet> filterCustomers(List<PrcCustomerPriceSet> customers)
{
List<PrcCustomerPriceSet> list = new ArrayList<PrcCustomerPriceSet>();
if (customers == null)
{
return list;
}
for (PrcCustomerPriceSet c : customers)
{
if (c != null && c.getCustomerId() != null && c.getCustomerId().longValue() > 0)
{
list.add(c);
}
}
return list;
}
private String displayName(PrcPriceSet set)
{
if (StringUtils.isNotEmpty(set.getPriceSetCode()))
{
return set.getPriceSetCode() + " " + set.getPriceSetName();
}
return set.getPriceSetName();
}
private String nvl(String val)
{
return val == null ? "" : val;
}
}
@@ -0,0 +1,116 @@
package com.ruoyi.price.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.PrcWeightSectionDetail;
import com.ruoyi.price.domain.PrcWeightSectionTemplate;
import com.ruoyi.price.mapper.PrcWeightSectionDetailMapper;
import com.ruoyi.price.mapper.PrcWeightSectionTemplateMapper;
import com.ruoyi.price.service.IPrcWeightService;
/**
* 重量段管理 服务层实现
*
* @author ruoyi
*/
@Service
public class PrcWeightServiceImpl implements IPrcWeightService
{
@Autowired
private PrcWeightSectionTemplateMapper templateMapper;
@Autowired
private PrcWeightSectionDetailMapper detailMapper;
@Override
public PrcWeightSectionTemplate selectPrcWeightSectionTemplateById(Long wstId)
{
PrcWeightSectionTemplate template = templateMapper.selectPrcWeightSectionTemplateById(wstId);
if (template != null)
{
template.setDetailCount(detailMapper.countByWstId(wstId));
}
return template;
}
@Override
public List<PrcWeightSectionTemplate> selectPrcWeightSectionTemplateList(PrcWeightSectionTemplate template)
{
List<PrcWeightSectionTemplate> list = templateMapper.selectPrcWeightSectionTemplateList(template);
for (PrcWeightSectionTemplate item : list)
{
item.setDetailCount(detailMapper.countByWstId(item.getWstId()));
}
return list;
}
@Override
public int insertPrcWeightSectionTemplate(PrcWeightSectionTemplate template)
{
if (StringUtils.isEmpty(template.getSsCode()))
{
template.setSsCode("on");
}
return templateMapper.insertPrcWeightSectionTemplate(template);
}
@Override
public int updatePrcWeightSectionTemplate(PrcWeightSectionTemplate template)
{
// ss_code=on 时仍允许编辑(当前阶段)
return templateMapper.updatePrcWeightSectionTemplate(template);
}
@Override
public int deletePrcWeightSectionTemplateByIds(Long[] wstIds)
{
return templateMapper.deletePrcWeightSectionTemplateByIds(wstIds);
}
@Override
public PrcWeightSectionDetail selectPrcWeightSectionDetailById(Long wsdId)
{
return detailMapper.selectPrcWeightSectionDetailById(wsdId);
}
@Override
public List<PrcWeightSectionDetail> selectPrcWeightSectionDetailList(PrcWeightSectionDetail detail)
{
return detailMapper.selectPrcWeightSectionDetailList(detail);
}
@Override
public int insertPrcWeightSectionDetail(PrcWeightSectionDetail detail)
{
validateWeightRange(detail);
return detailMapper.insertPrcWeightSectionDetail(detail);
}
@Override
public int updatePrcWeightSectionDetail(PrcWeightSectionDetail detail)
{
validateWeightRange(detail);
return detailMapper.updatePrcWeightSectionDetail(detail);
}
@Override
public int deletePrcWeightSectionDetailByIds(Long[] wsdIds)
{
return detailMapper.deletePrcWeightSectionDetailByIds(wsdIds);
}
private void validateWeightRange(PrcWeightSectionDetail detail)
{
if (detail.getWlStartweight() == null || detail.getWlEndweight() == null)
{
throw new ServiceException("起始重量和结束重量不能为空");
}
if (detail.getWlStartweight().compareTo(detail.getWlEndweight()) >= 0)
{
throw new ServiceException("起始重量必须小于结束重量");
}
}
}
@@ -0,0 +1,160 @@
package com.ruoyi.price.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.XtdZoneCountry;
import com.ruoyi.price.domain.XtdZoneDivision;
import com.ruoyi.price.domain.XtdZoneScheme;
import com.ruoyi.price.mapper.XtdZoneCountryMapper;
import com.ruoyi.price.mapper.XtdZoneDivisionMapper;
import com.ruoyi.price.mapper.XtdZoneSchemeMapper;
import com.ruoyi.price.service.IXtdZoneService;
/**
* 分区管理 服务层实现
*
* @author ruoyi
*/
@Service
public class XtdZoneServiceImpl implements IXtdZoneService
{
@Autowired
private XtdZoneSchemeMapper schemeMapper;
@Autowired
private XtdZoneDivisionMapper divisionMapper;
@Autowired
private XtdZoneCountryMapper countryMapper;
@Override
public XtdZoneScheme selectXtdZoneSchemeById(Long zsId)
{
XtdZoneScheme scheme = schemeMapper.selectXtdZoneSchemeById(zsId);
if (scheme != null)
{
scheme.setDivisionCount(divisionMapper.countByZsId(zsId));
}
return scheme;
}
@Override
public List<XtdZoneScheme> selectXtdZoneSchemeList(XtdZoneScheme scheme)
{
List<XtdZoneScheme> list = schemeMapper.selectXtdZoneSchemeList(scheme);
for (XtdZoneScheme item : list)
{
item.setDivisionCount(divisionMapper.countByZsId(item.getZsId()));
}
return list;
}
@Override
public int insertXtdZoneScheme(XtdZoneScheme scheme)
{
if (StringUtils.isEmpty(scheme.getSsCode()))
{
scheme.setSsCode("on");
}
return schemeMapper.insertXtdZoneScheme(scheme);
}
@Override
public int updateXtdZoneScheme(XtdZoneScheme scheme)
{
return schemeMapper.updateXtdZoneScheme(scheme);
}
@Override
public int deleteXtdZoneSchemeByIds(Long[] zsIds)
{
for (Long zsId : zsIds)
{
int count = divisionMapper.countByZsId(zsId);
if (count > 0)
{
XtdZoneScheme scheme = schemeMapper.selectXtdZoneSchemeById(zsId);
String name = scheme != null ? scheme.getZsName() : String.valueOf(zsId);
throw new ServiceException("分区方案【" + name + "】存在区划明细,不允许删除");
}
}
return schemeMapper.deleteXtdZoneSchemeByIds(zsIds);
}
@Override
public XtdZoneDivision selectXtdZoneDivisionById(Long zdId)
{
XtdZoneDivision division = divisionMapper.selectXtdZoneDivisionById(zdId);
if (division != null)
{
division.setCountryCount(countryMapper.countByZdId(zdId));
}
return division;
}
@Override
public List<XtdZoneDivision> selectXtdZoneDivisionList(XtdZoneDivision division)
{
List<XtdZoneDivision> list = divisionMapper.selectXtdZoneDivisionList(division);
for (XtdZoneDivision item : list)
{
item.setCountryCount(countryMapper.countByZdId(item.getZdId()));
}
return list;
}
@Override
public int insertXtdZoneDivision(XtdZoneDivision division)
{
return divisionMapper.insertXtdZoneDivision(division);
}
@Override
public int updateXtdZoneDivision(XtdZoneDivision division)
{
return divisionMapper.updateXtdZoneDivision(division);
}
@Override
public int deleteXtdZoneDivisionByIds(Long[] zdIds)
{
return divisionMapper.deleteXtdZoneDivisionByIds(zdIds);
}
@Override
public XtdZoneCountry selectXtdZoneCountryById(Long zcId)
{
return countryMapper.selectXtdZoneCountryById(zcId);
}
@Override
public List<XtdZoneCountry> selectXtdZoneCountryList(XtdZoneCountry country)
{
return countryMapper.selectXtdZoneCountryList(country);
}
@Override
public int insertXtdZoneCountry(XtdZoneCountry country)
{
if (StringUtils.isEmpty(country.getZcDividekind()))
{
country.setZcDividekind("C");
}
return countryMapper.insertXtdZoneCountry(country);
}
@Override
public int updateXtdZoneCountry(XtdZoneCountry country)
{
return countryMapper.updateXtdZoneCountry(country);
}
@Override
public int deleteXtdZoneCountryByIds(Long[] zcIds)
{
return countryMapper.deleteXtdZoneCountryByIds(zcIds);
}
}