|
|
@@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
|
import org.springblade.los.Util.CurrencyUtils;
|
|
|
import org.springblade.los.basic.corps.entity.BCorps;
|
|
|
@@ -42,6 +43,8 @@ import org.springblade.los.box.mapper.TradingBoxMapper;
|
|
|
import org.springblade.los.box.service.IRouteCostItemService;
|
|
|
import org.springblade.los.business.amends.entity.Amends;
|
|
|
import org.springblade.los.business.amends.mapper.AmendsMapper;
|
|
|
+import org.springblade.los.business.mktSlot.entity.MktSlotQuotation;
|
|
|
+import org.springblade.los.business.mktSlot.service.IMktSlotQuotationService;
|
|
|
import org.springblade.los.business.sea.entity.Bills;
|
|
|
import org.springblade.los.business.sea.entity.PreContainers;
|
|
|
import org.springblade.los.business.sea.mapper.BillsMapper;
|
|
|
@@ -95,6 +98,8 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
|
|
|
private final CurrencyUtils currencyUtils;
|
|
|
|
|
|
+ private final IMktSlotQuotationService mktSlotQuotationService;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<FeeCenterVO> selectFeeCenterPage(IPage<FeeCenterVO> page, FeeCenterVO feeCenter) {
|
|
|
return page.setRecords(baseMapper.selectFeeCenterPage(page, feeCenter));
|
|
|
@@ -1283,7 +1288,6 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
feeCenter.setFeeCode(items.getFeeCode());
|
|
|
feeCenter.setFeeCnName(items.getFeeCnName());
|
|
|
feeCenter.setFeeEnName(items.getFeeEnName());
|
|
|
- feeCenter.setUnitNo(items.getUnitNo());
|
|
|
feeCenter.setPrice(items.getSalesPrice());
|
|
|
feeCenter.setCurCode(items.getCurCode());
|
|
|
if (exrateType.equals(items.getCurCode())) {
|
|
|
@@ -1292,6 +1296,7 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
feeCenter.setExrate(currencyUtils.obtainExrate(feeCenter.getDc(), curExrateList, feeCenter.getCurCode(), "1"));
|
|
|
}
|
|
|
if ("按箱型".equals(items.getQuantityRule())) {
|
|
|
+ feeCenter.setUnitNo(items.getUnitNo());
|
|
|
if (preContainers.isEmpty()) {
|
|
|
text.append("费用:").append(items.getFeeCnName()).append("未找到集装箱信息!");
|
|
|
continue;
|
|
|
@@ -1307,12 +1312,15 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
feeCenter.setQuantity(new BigDecimal(quantity + ""));
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
} else if ("按票".equals(items.getQuantityRule())) {
|
|
|
+ feeCenter.setUnitNo(templateItems.getUnitNo());
|
|
|
feeCenter.setQuantity(new BigDecimal("1"));
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(new BigDecimal("1")));
|
|
|
} else if ("按重量".equals(items.getQuantityRule())) {
|
|
|
+ feeCenter.setUnitNo(templateItems.getUnitNo());
|
|
|
feeCenter.setQuantity(bills.getGrossWeight());
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
} else if ("按TEU".equals(items.getQuantityRule())) {
|
|
|
+ feeCenter.setUnitNo(items.getUnitNo());
|
|
|
if (preContainers.isEmpty()) {
|
|
|
text.append("费用:").append(items.getFeeCnName()).append("未找到集装箱信息!");
|
|
|
continue;
|
|
|
@@ -1330,6 +1338,7 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
feeCenter.setQuantity(new BigDecimal(quantity + ""));
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
} else if ("按箱量".equals(items.getQuantityRule())) {
|
|
|
+ feeCenter.setUnitNo(templateItems.getUnitNo());
|
|
|
if (preContainers.isEmpty()) {
|
|
|
text.append("费用:").append(items.getFeeCnName()).append("未找到集装箱信息!");
|
|
|
continue;
|
|
|
@@ -1343,9 +1352,11 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
feeCenter.setQuantity(new BigDecimal(quantity + ""));
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
} else if ("按尺码".equals(items.getQuantityRule())) {
|
|
|
+ feeCenter.setUnitNo(templateItems.getUnitNo());
|
|
|
feeCenter.setQuantity(bills.getMeasurement());
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
} else {
|
|
|
+ feeCenter.setUnitNo(templateItems.getUnitNo());
|
|
|
feeCenter.setQuantity(new BigDecimal("1"));
|
|
|
feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
}
|
|
|
@@ -1527,6 +1538,259 @@ public class FeeCenterServiceImpl extends ServiceImpl<FeeCenterMapper, FeeCenter
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R quotationImportBatch(String billsIds, String quotationId) {
|
|
|
+ List<MktSlotQuotation> mktSlotQuotationList = mktSlotQuotationService.list(new LambdaQueryWrapper<MktSlotQuotation>()
|
|
|
+ .eq(MktSlotQuotation::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(MktSlotQuotation::getIsDeleted, 0)
|
|
|
+ .eq(MktSlotQuotation::getPid, Func.toLongList(quotationId)));
|
|
|
+ if (mktSlotQuotationList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到成本明细");
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(id,'" + billsIds + "')"));
|
|
|
+ if (billsList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到单据信息");
|
|
|
+ }
|
|
|
+ List<PreContainers> preContainersList = preContainersService.list(new LambdaQueryWrapper<PreContainers>()
|
|
|
+ .eq(PreContainers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PreContainers::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(pid,'" + billsIds + "')"));
|
|
|
+ BFees fees = bFeesService.getOne(new LambdaQueryWrapper<BFees>()
|
|
|
+ .eq(BFees::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BFees::getIsDeleted, 0)
|
|
|
+ .eq(BFees::getCode, "HYF"));
|
|
|
+ if (fees == null) {
|
|
|
+ throw new RuntimeException("未查到海运费信息,请先维护基础资料");
|
|
|
+ }
|
|
|
+ BFees feesD = bFeesService.getOne(new LambdaQueryWrapper<BFees>()
|
|
|
+ .eq(BFees::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BFees::getIsDeleted, 0)
|
|
|
+ .eq(BFees::getCode, "XSJ"));
|
|
|
+ if (feesD == null) {
|
|
|
+ throw new RuntimeException("未查到销售价信息,请先维护基础资料");
|
|
|
+ }
|
|
|
+ String deptName = "";
|
|
|
+ String branchId = AuthUtil.getDeptId();
|
|
|
+ if (ObjectUtils.isNotNull(branchId)) {
|
|
|
+ R<String> res = sysClient.getDeptName(Long.parseLong(branchId));
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ deptName = res.getData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<FeeCenter> list = new ArrayList<>();
|
|
|
+ StringBuilder text = new StringBuilder();
|
|
|
+ for (Bills bills : billsList) {
|
|
|
+ if (0 != bills.getStatus()) {
|
|
|
+ throw new RuntimeException("单号:" + bills.getBillNo() + ",已提交审核或审核通过,导入失败");
|
|
|
+ }
|
|
|
+ String texts = "";
|
|
|
+ if (ObjectUtils.isNull(bills.getMblno())) {
|
|
|
+ texts = texts + "提单号、";
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(bills.getVesselId())) {
|
|
|
+ texts = texts + "船名、";
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(bills.getVoyageNo())) {
|
|
|
+ texts = texts + "航次、";
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(bills.getPodId())) {
|
|
|
+ texts = texts + "卸货港、";
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(bills.getCarrierId())) {
|
|
|
+ texts = texts + "船公司、";
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(bills.getBoxBelongsTo())) {
|
|
|
+ texts = texts + "箱属、";
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(texts)) {
|
|
|
+ throw new RuntimeException("单号:" + bills.getBillNo() + "," + texts + "不能为空");
|
|
|
+ }
|
|
|
+ List<PreContainers> preContainers = new ArrayList<>();
|
|
|
+ if (!preContainersList.isEmpty()) {
|
|
|
+ preContainers = preContainersList.stream().filter(e -> e.getPid().equals(bills.getId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (preContainers.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Date date;
|
|
|
+ if ("SE".equals(bills.getBusinessType())) {
|
|
|
+ if (ObjectUtils.isNotNull(bills.getActualEtd())) {
|
|
|
+ date = bills.getActualEtd();
|
|
|
+ } else {
|
|
|
+ date = bills.getEtd();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (ObjectUtils.isNotNull(bills.getActualEta())) {
|
|
|
+ date = bills.getActualEta();
|
|
|
+ } else {
|
|
|
+ date = bills.getEta();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<MktSlotQuotation> mktSlotQuotations = mktSlotQuotationList.stream().filter(e -> e.getEtd().equals(date)
|
|
|
+ && e.getBoxBelongsTo().equals(bills.getBoxBelongsTo())).collect(Collectors.toList());
|
|
|
+ String exrateType = currencyUtils.standardCurrency(branchId);
|
|
|
+ List<BCurExrate> curExrateList = currencyUtils.obtainRate(date, "1", branchId);
|
|
|
+ int count = 1;
|
|
|
+ for (PreContainers item : preContainers) {
|
|
|
+ FeeCenter feeCenter = this.addFeeCenterQuotation(bills, "D", count, fees, "国内直接客户", item,
|
|
|
+ curExrateList, mktSlotQuotations, exrateType, "1");
|
|
|
+ if (feeCenter != null) {
|
|
|
+ feeCenter.setBranchId(branchId);
|
|
|
+ feeCenter.setBranchName(deptName);
|
|
|
+ list.add(feeCenter);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ if ("SOC".equals(bills.getBoxBelongsTo())) {
|
|
|
+ FeeCenter feeCenterD = this.addFeeCenterQuotation(bills, "D", count, feesD, "国内直接客户", item,
|
|
|
+ curExrateList, mktSlotQuotations, exrateType, "2");
|
|
|
+ if (feeCenterD != null) {
|
|
|
+ feeCenterD.setBranchId(branchId);
|
|
|
+ feeCenterD.setBranchName(deptName);
|
|
|
+ list.add(feeCenterD);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ } else if ("COC".equals(bills.getBoxBelongsTo())) {
|
|
|
+ FeeCenter feeCenterD = this.addFeeCenterQuotation(bills, "D", count, feesD, "国内直接客户", item,
|
|
|
+ curExrateList, mktSlotQuotations, exrateType, "2");
|
|
|
+ if (feeCenterD != null) {
|
|
|
+ feeCenterD.setBranchId(branchId);
|
|
|
+ feeCenterD.setBranchName(deptName);
|
|
|
+ list.add(feeCenterD);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("单号:" + bills.getBillNo() + "单据类型非分单,请选择分单数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ this.saveOrUpdateBatch(list);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(text.toString())) {
|
|
|
+ return R.data(list, text + "未导入!!!");
|
|
|
+ } else {
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FeeCenter addFeeCenterQuotation(Bills bills, String dc, int count, BFees fees, String corpType,
|
|
|
+ PreContainers items, List<BCurExrate> curExrateList,
|
|
|
+ List<MktSlotQuotation> mktSlotQuotations, String exrateType, String type) {
|
|
|
+ FeeCenter feeCenter = new FeeCenter();
|
|
|
+ feeCenter.setBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setPid(bills.getId());
|
|
|
+ feeCenter.setCntrNo(bills.getQuantityCntrTypesDescr());
|
|
|
+ feeCenter.setBillNo(bills.getBillNo());
|
|
|
+ feeCenter.setBusinessType(bills.getBusinessType());
|
|
|
+ feeCenter.setBillType(bills.getBillType());
|
|
|
+ feeCenter.setBillDate(bills.getBillDate());
|
|
|
+ feeCenter.setBillCorpId(bills.getCorpId());
|
|
|
+ feeCenter.setBillCorpCnName(bills.getCorpCnName());
|
|
|
+ feeCenter.setBillCorpEnName(bills.getCorpEnName());
|
|
|
+ feeCenter.setBillShortName(bills.getCorpCnName());
|
|
|
+ feeCenter.setLineId(bills.getLineId());
|
|
|
+ feeCenter.setLineCnName(bills.getLineCnName());
|
|
|
+ feeCenter.setLineEnName(bills.getLineEnName());
|
|
|
+ feeCenter.setVesselId(bills.getVesselId());
|
|
|
+ feeCenter.setVesselCnName(bills.getVesselCnName());
|
|
|
+ feeCenter.setVesselEnName(bills.getVesselEnName());
|
|
|
+ feeCenter.setVoyageNo(bills.getVoyageNo());
|
|
|
+ feeCenter.setMblno(bills.getMblno());
|
|
|
+ feeCenter.setHblno(bills.getHblno());
|
|
|
+ feeCenter.setEtd(bills.getEtd());
|
|
|
+ feeCenter.setEta(bills.getEta());
|
|
|
+ feeCenter.setPolId(bills.getPolId());
|
|
|
+ feeCenter.setPolCode(bills.getPolCode());
|
|
|
+ feeCenter.setPolCnName(bills.getPolCnName());
|
|
|
+ feeCenter.setPolEnName(bills.getPolEnName());
|
|
|
+ feeCenter.setPodId(bills.getPodId());
|
|
|
+ feeCenter.setPodCode(bills.getPodCode());
|
|
|
+ feeCenter.setPodCnName(bills.getPodCnName());
|
|
|
+ feeCenter.setPodEnName(bills.getPodEnName());
|
|
|
+ feeCenter.setDc(dc);
|
|
|
+ feeCenter.setPaymode(bills.getMpaymode());
|
|
|
+ feeCenter.setSort(count);
|
|
|
+ feeCenter.setFeeId(fees.getId());
|
|
|
+ feeCenter.setCorpType(corpType);
|
|
|
+ feeCenter.setFeeCode(fees.getCode());
|
|
|
+ feeCenter.setFeeCnName(fees.getCnName());
|
|
|
+ feeCenter.setFeeEnName(fees.getEnName());
|
|
|
+ feeCenter.setUnitNo(fees.getUnitNo());
|
|
|
+ feeCenter.setCurCode(fees.getCurNo());
|
|
|
+ feeCenter.setExrate(currencyUtils.obtainExrate(feeCenter.getDc(), curExrateList, feeCenter.getCurCode(), "1"));
|
|
|
+ feeCenter.setQuantity(new BigDecimal(items.getQuantity() + ""));
|
|
|
+ if ("1".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCorpId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCorpCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCorpEnName());
|
|
|
+ feeCenter.setShortName(bills.getShortName());
|
|
|
+ if ("20GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getGp20).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else if ("40GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getGp40).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else if ("40HC".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getHc40).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if ("2".equals(type)) {
|
|
|
+ BCorps bCorps = bCorpsService.getOne(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .eq(BCorps::getCode, "ZBYF"));
|
|
|
+ if (bCorps == null) {
|
|
|
+ throw new RuntimeException("基础资料未查到编码为‘ZBYF’往来单位");
|
|
|
+ }
|
|
|
+ feeCenter.setCorpId(bCorps.getId());
|
|
|
+ feeCenter.setCorpCnName(bCorps.getCnName());
|
|
|
+ feeCenter.setCorpEnName(bCorps.getEnName());
|
|
|
+ feeCenter.setShortName(bCorps.getShortName());
|
|
|
+ if ("20GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getGp20Cost).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else if ("40GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getGp40Cost).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else if ("40HC".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getHc40Cost).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if ("3".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCarrierId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCarrierCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCarrierEnName());
|
|
|
+ feeCenter.setShortName(bills.getCarrierShortName());
|
|
|
+ if ("20GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getGp20Cost).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else if ("40GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getGp40Cost).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else if ("40HC".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.stream().map(MktSlotQuotation::getHc40Cost).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ feeCenter.setAmount(feeCenter.getPrice().multiply(feeCenter.getQuantity()));
|
|
|
+ if (ObjectUtils.isNull(feeCenter.getAmount())) {
|
|
|
+ feeCenter.setAmount(new BigDecimal("0"));
|
|
|
+ }
|
|
|
+ if (exrateType.equals(feeCenter.getCurCode())) {
|
|
|
+ feeCenter.setAmountLoc(feeCenter.getAmount());
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0").compareTo(feeCenter.getAmount()) != 0) {
|
|
|
+ feeCenter.setAmountLoc(feeCenter.getAmount().multiply(feeCenter.getExrate()));
|
|
|
+ } else {
|
|
|
+ feeCenter.setAmountLoc(new BigDecimal("0"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return feeCenter;
|
|
|
+ }
|
|
|
+
|
|
|
private FeeCenter addFeeCenter(Bills bills, String dc, int count, BFees fees, String corpType, RouteCostItem items,
|
|
|
List<BCurExrate> curExrateList, List<PreContainers> preContainers,
|
|
|
String exrateType, String type) {
|