demand: 组批次新增/修改添加重复校验 TMS系统-报价管理-干线运输费:报价批量录入
committer: heyu
This commit is contained in:
parent
8b8512812a
commit
3bfffbb69e
@ -193,4 +193,30 @@ public class EmisQuotePriceController extends EmisBaseController
|
||||
{
|
||||
return toAjax(emisQuotePriceService.deleteEmisQuotePriceByQuoteIds(quoteIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 草稿导入费用报价
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisQuotePrice:draftQuotePrice')")
|
||||
@PostMapping("/draftQuotePrice")
|
||||
public AjaxResult draftQuotePrice(@RequestBody EmisQuotePrice emisQuotePrice) {
|
||||
JSONObject jObjOut = new JSONObject();
|
||||
String result = "success";
|
||||
String msg = "导入成功";
|
||||
try {
|
||||
emisQuotePriceService.importDraftQuotePrice(emisQuotePrice);
|
||||
jObjOut.put("quoteDetail", emisQuotePrice);
|
||||
} catch (EmisBizError ex) {
|
||||
ex.printStackTrace();
|
||||
result = "fail";
|
||||
msg = ex.getErrorCode() + ":" + ex.getMessage();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
result = "fail";
|
||||
msg = "系统异常:" + ex.getMessage();
|
||||
}
|
||||
jObjOut.put("result", result);
|
||||
jObjOut.put("msg", msg);
|
||||
return AjaxResult.success("成功", jObjOut);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,4 +78,9 @@ public interface IEmisQuotePriceService
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchUpdateEmisQuotePrice(List<EmisQuotePrice> emisQuotePriceList) throws EmisBizError;
|
||||
|
||||
/**
|
||||
* 草稿导入费用报价,带name-code转换、规则校验、重复校验
|
||||
*/
|
||||
void importDraftQuotePrice(EmisQuotePrice emisQuotePrice) throws EmisBizError;
|
||||
}
|
||||
|
||||
@ -14,15 +14,14 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.xdadan.erp.emis.domain.EmisQuoteExpression;
|
||||
import com.xdadan.erp.common.utils.DictUtils;
|
||||
import com.xdadan.erp.emis.domain.*;
|
||||
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import com.xdadan.erp.emis.mapper.EmisQuoteExpressionMapper;
|
||||
import com.xdadan.erp.emis.mapper.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.xdadan.erp.emis.domain.EmisQuotePrice;
|
||||
import com.xdadan.erp.emis.mapper.EmisQuotePriceMapper;
|
||||
import com.xdadan.erp.emis.service.IEmisQuotePriceService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -41,6 +40,18 @@ public class EmisQuotePriceServiceImpl implements IEmisQuotePriceService
|
||||
@Autowired
|
||||
private EmisQuoteExpressionMapper emisQuoteExpressionMapper;
|
||||
|
||||
@Autowired
|
||||
private EmisSiteMapper emisSiteMapper;
|
||||
|
||||
@Autowired
|
||||
private EmisTransLineMapper emisTransLineMapper;
|
||||
|
||||
@Autowired
|
||||
private EmisTransProductMapper emisTransProductMapper;
|
||||
|
||||
@Autowired
|
||||
private EmisRegionMapper emisRegionMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询费用报价
|
||||
@ -210,4 +221,191 @@ public class EmisQuotePriceServiceImpl implements IEmisQuotePriceService
|
||||
return successCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void importDraftQuotePrice(EmisQuotePrice emisQuotePrice) throws EmisBizError {
|
||||
// 必填项校验
|
||||
checkParam(emisQuotePrice);
|
||||
|
||||
// 校验日期
|
||||
checkDate(emisQuotePrice);
|
||||
|
||||
// name-code转换
|
||||
nameToCode(emisQuotePrice);
|
||||
|
||||
// 唯一性/重复校验
|
||||
List<EmisQuotePrice> listOld = emisQuotePriceMapper.checkUnique(emisQuotePrice);
|
||||
if (!CollectionUtil.isEmpty(listOld)) {
|
||||
String estNameStr = "";
|
||||
for (EmisQuotePrice item : listOld) {
|
||||
estNameStr = estNameStr + item.getQuoteName() + ",";
|
||||
}
|
||||
throw new EmisBizError(EmisBizErrorType.EXISTS, "报价重复[" + estNameStr + "]");
|
||||
}
|
||||
|
||||
// 保存报价
|
||||
insertEmisQuotePrice(emisQuotePrice);
|
||||
// 保存表达式
|
||||
if (!CollectionUtil.isEmpty(emisQuotePrice.getExprList())) {
|
||||
for (EmisQuoteExpression expr : emisQuotePrice.getExprList()) {
|
||||
expr.setId(null);
|
||||
expr.setQuoteId(emisQuotePrice.getQuoteId());
|
||||
emisQuoteExpressionMapper.insertEmisQuoteExpression(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void nameToCode(EmisQuotePrice emisQuotePrice) throws EmisBizError {
|
||||
EmisSite useSite = emisSiteMapper.getEmisSiteByName(emisQuotePrice.getUseSiteName());
|
||||
if (useSite == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的使用网点: " + emisQuotePrice.getUseSiteName());
|
||||
}
|
||||
emisQuotePrice.setUseSiteCode(useSite.getSiteCode());
|
||||
// 线路
|
||||
EmisTransLine transLine = emisTransLineMapper.selectTransLineByName(emisQuotePrice.getTransLine());
|
||||
if (transLine == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的线路: " + emisQuotePrice.getTransLine());
|
||||
}
|
||||
emisQuotePrice.setTransLineCode(transLine.getLineCode());
|
||||
// 产品类型
|
||||
EmisTransProduct prod = emisTransProductMapper.selectTransProductByName(transLine.getLineCode(),
|
||||
emisQuotePrice.getProdName());
|
||||
if (prod == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的产品类型: " + emisQuotePrice.getProdName());
|
||||
}
|
||||
emisQuotePrice.setProdCode(prod.getProdCode());
|
||||
// 派件区域 name-code
|
||||
if (emisQuotePrice.getDispAreaName() != null && !emisQuotePrice.getDispAreaName().trim().isEmpty()) {
|
||||
EmisRegion queryRegion = new EmisRegion();
|
||||
queryRegion.setRegionName(emisQuotePrice.getDispAreaName());
|
||||
List<EmisRegion> dispAreaList = emisRegionMapper.selectEmisRegionList(queryRegion);
|
||||
if (dispAreaList == null || dispAreaList.isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的派件区域: " + emisQuotePrice.getDispAreaName());
|
||||
}
|
||||
EmisRegion dispArea = dispAreaList.get(0);
|
||||
emisQuotePrice.setDispAreaId(dispArea.getId());
|
||||
emisQuotePrice.setDispAreaSiteCode(dispArea.getRegionCode());
|
||||
}
|
||||
// 寄件区域 name-code
|
||||
if (emisQuotePrice.getSendAreaName() != null && !emisQuotePrice.getSendAreaName().trim().isEmpty()) {
|
||||
EmisRegion queryRegion = new EmisRegion();
|
||||
queryRegion.setRegionName(emisQuotePrice.getSendAreaName());
|
||||
List<EmisRegion> sendAreaList = emisRegionMapper.selectEmisRegionList(queryRegion);
|
||||
if (sendAreaList == null || sendAreaList.isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的寄件区域: " + emisQuotePrice.getSendAreaName());
|
||||
}
|
||||
EmisRegion sendArea = sendAreaList.get(0);
|
||||
emisQuotePrice.setSendAreaId(sendArea.getId());
|
||||
emisQuotePrice.setSendAreaSiteCode(sendArea.getRegionCode());
|
||||
}
|
||||
// 费用类型 name-code
|
||||
if (emisQuotePrice.getFeeType() != null && !emisQuotePrice.getFeeType().isEmpty()) {
|
||||
String feeTypeCode = DictUtils.getDictValue("emis_fee_type", emisQuotePrice.getFeeType());
|
||||
if (feeTypeCode == null || feeTypeCode.isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "费用类型无效: " + emisQuotePrice.getFeeType());
|
||||
}
|
||||
emisQuotePrice.setFeeType(feeTypeCode);
|
||||
}
|
||||
// 币种 name-code
|
||||
if (emisQuotePrice.getCurrency() != null && !emisQuotePrice.getCurrency().isEmpty()) {
|
||||
String currencyCode = DictUtils.getDictValue("emis_currency", emisQuotePrice.getCurrency());
|
||||
if (currencyCode == null || currencyCode.isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "费用币种无效: " + emisQuotePrice.getCurrency());
|
||||
}
|
||||
emisQuotePrice.setCurrency(currencyCode);
|
||||
}
|
||||
// 计费类型 name-code
|
||||
if (emisQuotePrice.getBillType() != null && !emisQuotePrice.getBillType().isEmpty()) {
|
||||
String billType = emisQuotePrice.getBillType().trim();
|
||||
if ("重量计费".equals(billType)) {
|
||||
emisQuotePrice.setBillType("1");
|
||||
} else if ("体积计费".equals(billType)) {
|
||||
emisQuotePrice.setBillType("2");
|
||||
} else if (!"1".equals(billType) && !"2".equals(billType)) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "计费类型无效: " + emisQuotePrice.getBillType());
|
||||
}
|
||||
}
|
||||
// 启用状态 name-code
|
||||
if (emisQuotePrice.getStatus() != null) {
|
||||
Object statusObj = emisQuotePrice.getStatus();
|
||||
if (statusObj instanceof String) {
|
||||
String statusStr = ((String) statusObj).trim();
|
||||
if ("启用".equals(statusStr)) {
|
||||
emisQuotePrice.setStatus(0);
|
||||
} else if ("停用".equals(statusStr)) {
|
||||
emisQuotePrice.setStatus(1);
|
||||
} else {
|
||||
try {
|
||||
int statusInt = Integer.parseInt(statusStr);
|
||||
if (statusInt != 0 && statusInt != 1) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态无效: " + statusObj);
|
||||
}
|
||||
emisQuotePrice.setStatus(statusInt);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态无效: " + statusObj);
|
||||
}
|
||||
}
|
||||
} else if (statusObj instanceof Integer) {
|
||||
int statusInt = (Integer) statusObj;
|
||||
if (statusInt != 0 && statusInt != 1) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态无效: " + statusObj);
|
||||
}
|
||||
} else {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态无效: " + statusObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkDate(EmisQuotePrice emisQuotePrice) throws EmisBizError {
|
||||
Date startDate = emisQuotePrice.getStartDate();
|
||||
Date endDate = emisQuotePrice.getEndDate();
|
||||
if (startDate == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "开始日期不能为空");
|
||||
}
|
||||
if (endDate == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "结束日期不能为空");
|
||||
}
|
||||
if (startDate.after(endDate)) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "开始日期不能晚于结束日期");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkParam(EmisQuotePrice emisQuotePrice) throws EmisBizError {
|
||||
if (emisQuotePrice.getQuoteName() == null || emisQuotePrice.getQuoteName().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "报价名称不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getUseSiteName() == null || emisQuotePrice.getUseSiteName().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "使用网点不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getTransLine() == null || emisQuotePrice.getTransLine().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "线路不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getProdName() == null || emisQuotePrice.getProdName().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "产品类型不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getLeastPrice() == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "最低价格不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getPriceType() == null || emisQuotePrice.getPriceType().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "价格取值不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getBillType() == null || emisQuotePrice.getBillType().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "计费类型不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getStatus() == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getFeeType() == null || emisQuotePrice.getFeeType().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "费用类型不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getCurrency() == null || emisQuotePrice.getCurrency().trim().isEmpty()) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "费用币种不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getSendAreaId() == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "寄件区域不能为空");
|
||||
}
|
||||
if (emisQuotePrice.getDispAreaId() == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "派件区域不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ package com.xdadan.erp.emis.service.impl;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.xdadan.erp.common.core.redis.RedissonService;
|
||||
@ -220,7 +221,19 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
public int addAll(EmisTmsSiteBatch emisTmsSiteBatch) throws EmisBizError {
|
||||
// 插入明细数据
|
||||
if (!CollectionUtils.isEmpty(emisTmsSiteBatch.getBatchDtlList())) {
|
||||
for (EmisTmsSiteBatchDtl itemDtl : emisTmsSiteBatch.getBatchDtlList()) {
|
||||
List<EmisTmsSiteBatchDtl> distinctBatchDtlList = emisTmsSiteBatch.getBatchDtlList().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> StringUtils.isNotBlank(item.getBillCode()))
|
||||
.collect(Collectors.toMap(
|
||||
EmisTmsSiteBatchDtl::getBillCode,
|
||||
item -> item,
|
||||
(existing, replacement) -> existing
|
||||
))
|
||||
.values()
|
||||
.stream()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (EmisTmsSiteBatchDtl itemDtl : distinctBatchDtlList) {
|
||||
checkSiteBatch(emisTmsSiteBatch, itemDtl.getBillCode());
|
||||
itemDtl.setBatchNo(emisTmsSiteBatch.getBatchNo());
|
||||
emisTmsSiteBatchDtlMapper.insertEmisTmsSiteBatchDtl(itemDtl);
|
||||
@ -247,8 +260,20 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
@Override
|
||||
@Transactional
|
||||
public int editAll(EmisTmsSiteBatch emisTmsSiteBatch) throws EmisBizError {
|
||||
List<EmisTmsSiteBatchDtl> distinctBatchDtlList = null;
|
||||
if (!CollectionUtils.isEmpty(emisTmsSiteBatch.getBatchDtlList())) {
|
||||
for (EmisTmsSiteBatchDtl itemDtl : emisTmsSiteBatch.getBatchDtlList()) {
|
||||
distinctBatchDtlList = emisTmsSiteBatch.getBatchDtlList().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> StringUtils.isNotBlank(item.getBillCode()))
|
||||
.collect(Collectors.toMap(
|
||||
EmisTmsSiteBatchDtl::getBillCode,
|
||||
item -> item,
|
||||
(existing, replacement) -> existing
|
||||
))
|
||||
.values()
|
||||
.stream()
|
||||
.collect(Collectors.toList());
|
||||
for (EmisTmsSiteBatchDtl itemDtl : distinctBatchDtlList) {
|
||||
checkSiteBatch(emisTmsSiteBatch, itemDtl.getBillCode());
|
||||
}
|
||||
}
|
||||
@ -258,8 +283,8 @@ public class EmisTmsSiteBatchServiceImpl extends EmisBaseService implements IEmi
|
||||
if (StringUtil.isBlank(emisTmsSiteBatch.getBatchNo())) {
|
||||
return 1;
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(emisTmsSiteBatch.getBatchDtlList())) {
|
||||
for (EmisTmsSiteBatchDtl itemDtl : emisTmsSiteBatch.getBatchDtlList()) {
|
||||
if (CollectionUtil.isNotEmpty(distinctBatchDtlList)) {
|
||||
for (EmisTmsSiteBatchDtl itemDtl : distinctBatchDtlList) {
|
||||
itemDtl.setBatchNo(emisTmsSiteBatch.getBatchNo());
|
||||
emisTmsSiteBatchDtlMapper.insertEmisTmsSiteBatchDtl(itemDtl);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user