|
|
@@ -0,0 +1,1275 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.los.finance.agency.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+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.los.Util.CurrencyUtils;
|
|
|
+import org.springblade.los.basic.business.entity.BusinessType;
|
|
|
+import org.springblade.los.basic.business.service.IBusinessTypeService;
|
|
|
+import org.springblade.los.basic.corps.entity.BCorps;
|
|
|
+import org.springblade.los.basic.corps.service.IBCorpsService;
|
|
|
+import org.springblade.los.basic.cur.entity.BCurExrate;
|
|
|
+import org.springblade.los.basic.fees.entity.BFees;
|
|
|
+import org.springblade.los.basic.fees.service.IBFeesService;
|
|
|
+import org.springblade.los.billno.entity.BusinessBillNo;
|
|
|
+import org.springblade.los.billno.service.IBusinessBillNoService;
|
|
|
+import org.springblade.los.box.entity.Archives;
|
|
|
+import org.springblade.los.box.entity.RouteCostItem;
|
|
|
+import org.springblade.los.box.service.IArchivesService;
|
|
|
+import org.springblade.los.box.service.IRouteCostItemService;
|
|
|
+import org.springblade.los.box.service.ITradingBoxService;
|
|
|
+import org.springblade.los.business.mktSlot.entity.MktSlotQuotation;
|
|
|
+import org.springblade.los.business.sea.entity.Bills;
|
|
|
+import org.springblade.los.business.sea.entity.Containers;
|
|
|
+import org.springblade.los.business.sea.entity.PreContainers;
|
|
|
+import org.springblade.los.business.sea.service.IBillsService;
|
|
|
+import org.springblade.los.business.sea.service.IContainersService;
|
|
|
+import org.springblade.los.business.sea.service.IPreContainersService;
|
|
|
+import org.springblade.los.finance.agency.dto.AgencyFeeSettingDTO;
|
|
|
+import org.springblade.los.finance.agency.entity.AgencyFeeSetting;
|
|
|
+import org.springblade.los.finance.agency.mapper.AgencyFeeSettingMapper;
|
|
|
+import org.springblade.los.finance.agency.service.IAgencyFeeSettingService;
|
|
|
+import org.springblade.los.finance.agency.vo.AgencyFeeSettingVO;
|
|
|
+import org.springblade.los.finance.fee.entity.FeeCenter;
|
|
|
+import org.springblade.los.finance.fee.service.ICostProfitCalculationService;
|
|
|
+import org.springblade.los.finance.fee.service.IFeeCenterService;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.MathContext;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 代理费设置 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2026-01-05
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class AgencyFeeSettingServiceImpl extends ServiceImpl<AgencyFeeSettingMapper, AgencyFeeSetting> implements IAgencyFeeSettingService {
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private final IBillsService billsService;
|
|
|
+
|
|
|
+ private final IBCorpsService bCorpsService;
|
|
|
+
|
|
|
+ private final IPreContainersService preContainersService;
|
|
|
+
|
|
|
+ private final IContainersService containersService;
|
|
|
+
|
|
|
+ private final ITradingBoxService tradingBoxService;
|
|
|
+
|
|
|
+ private final IArchivesService archivesService;
|
|
|
+
|
|
|
+ private final IRouteCostItemService routeCostItemService;
|
|
|
+
|
|
|
+ private final IBFeesService bFeesService;
|
|
|
+
|
|
|
+ private final CurrencyUtils currencyUtils;
|
|
|
+
|
|
|
+ private final ICostProfitCalculationService costProfitCalculationService;
|
|
|
+
|
|
|
+ private final IFeeCenterService feeCenterService;
|
|
|
+
|
|
|
+ private final IBusinessBillNoService businessBillNoService;
|
|
|
+
|
|
|
+ private final IBusinessTypeService bBusinessTypeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<AgencyFeeSettingVO> selectAgencyFeeSettingPage(IPage<AgencyFeeSettingVO> page, AgencyFeeSettingVO agencyFeeSetting) {
|
|
|
+ return page.setRecords(baseMapper.selectAgencyFeeSettingPage(page, agencyFeeSetting));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R costImportBatch(String billsIds, String costId) {
|
|
|
+ List<RouteCostItem> routeCostItemList = routeCostItemService.list(new LambdaQueryWrapper<RouteCostItem>()
|
|
|
+ .eq(RouteCostItem::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(RouteCostItem::getIsDeleted, 0)
|
|
|
+ .eq(RouteCostItem::getPid, costId));
|
|
|
+ if (routeCostItemList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到成本明细");
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsService.list(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<Long> idList = billsList.stream().map(Bills::getId).collect(Collectors.toList());
|
|
|
+ List<Bills> billsListFD = billsService.list(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .in(Bills::getMasterId, billsList.stream().map(Bills::getId).collect(Collectors.toList())));
|
|
|
+ if (billsListFD.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到分单单据信息");
|
|
|
+ }
|
|
|
+ List<Long> fDIdList = billsListFD.stream().map(Bills::getId).collect(Collectors.toList());
|
|
|
+ List<Containers> containersList = containersService.list(new LambdaQueryWrapper<Containers>()
|
|
|
+ .eq(Containers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Containers::getIsDeleted, 0)
|
|
|
+ .in(Containers::getPid, fDIdList));
|
|
|
+ if (containersList.isEmpty()) {
|
|
|
+ throw new RuntimeException("请先维护配箱信息");
|
|
|
+ }
|
|
|
+ List<String> boxCodeList = containersList.stream().map(Containers::getCntrNo).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ List<Archives> archivesList = archivesService.list(new LambdaQueryWrapper<Archives>()
|
|
|
+ .eq(Archives::getIsDeleted, 0)
|
|
|
+ .eq(Archives::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .in(Archives::getCode, boxCodeList));
|
|
|
+ if (archivesList.isEmpty()) {
|
|
|
+ throw new RuntimeException("箱信息未查到");
|
|
|
+ }
|
|
|
+ String polId = billsListFD.stream().map(Bills::getPolId).filter(Objects::nonNull).distinct().map(String::valueOf)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ if (ObjectUtils.isNull(polId)) {
|
|
|
+ throw new RuntimeException("请先维护分单装货港信息");
|
|
|
+ }
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<AgencyFeeSetting> agencyFeeSettingList = baseMapper.selectListByPolId(polId, formatter.format(new Date()), AuthUtil.getTenantId());
|
|
|
+ if (agencyFeeSettingList.isEmpty()) {
|
|
|
+ throw new RuntimeException("请先维护分单对应起运港代理费费率设置");
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListFD = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .in(FeeCenter::getPid, fDIdList));
|
|
|
+ List<PreContainers> preContainersList = preContainersService.list(new LambdaQueryWrapper<PreContainers>()
|
|
|
+ .eq(PreContainers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PreContainers::getIsDeleted, 0)
|
|
|
+ .in(PreContainers::getPid, idList));
|
|
|
+ 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 feesFjf = bFeesService.getOne(new LambdaQueryWrapper<BFees>()
|
|
|
+ .eq(BFees::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BFees::getIsDeleted, 0)
|
|
|
+ .eq(BFees::getCode, "FJF"));
|
|
|
+ if (feesFjf == 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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’往来单位");
|
|
|
+ }
|
|
|
+ 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.isNotNull(texts)) {
|
|
|
+ throw new RuntimeException("单号:" + bills.getBillNo() + "," + texts + "不能为空");
|
|
|
+ }
|
|
|
+ bills.setWhetherExtractCost("1");
|
|
|
+ billsService.updateById(bills);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AgencyFeeSetting agencyFeeSetting = agencyFeeSettingList.stream().filter(e -> e.getPolId().contains(bills.getPolId() + "")
|
|
|
+ && e.getPodId().contains(bills.getPodId() + "")).findFirst().orElse(null);
|
|
|
+ if (agencyFeeSetting == null) {
|
|
|
+ List<AgencyFeeSetting> agencyFeeSettings = agencyFeeSettingList.stream().filter(e -> e.getPolId().contains(bills.getPolId() + "")).collect(Collectors.toList());
|
|
|
+ if (!agencyFeeSettings.isEmpty()) {
|
|
|
+ agencyFeeSetting = agencyFeeSettings.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (agencyFeeSetting == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String exrateType = currencyUtils.standardCurrency(branchId);
|
|
|
+ List<BCurExrate> curExrateList = currencyUtils.obtainRate(date, "1", branchId);
|
|
|
+ List<FeeCenter> list1 = new ArrayList<>();
|
|
|
+ List<FeeCenter> feeCentersFdC = new ArrayList<>();
|
|
|
+ if (!billsListFD.isEmpty()) {
|
|
|
+ List<Bills> billsFd = billsListFD.stream().filter(e -> e.getMasterId().equals(bills.getId())).collect(Collectors.toList());
|
|
|
+ for (Bills item : billsFd) {
|
|
|
+ //判断主单下所有分单费用是否存在
|
|
|
+ if (feeCenterListFD.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //判断当前循环的分单费用是否存在
|
|
|
+ List<FeeCenter> feeCenterFDListSum = feeCenterListFD.stream().filter(e -> e.getPid().equals(item.getId())).collect(Collectors.toList());
|
|
|
+ if (feeCenterFDListSum.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //判断当前循环的分单费用是否存在应收海运费
|
|
|
+ List<FeeCenter> feeCenterFDListHYF = feeCenterFDListSum.stream().filter(e -> "D".equals(e.getDc()) &&
|
|
|
+ "HYF".equals(e.getFeeCode())).collect(Collectors.toList());
|
|
|
+ if (feeCenterFDListHYF.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取当前循环的分单配箱信息
|
|
|
+ List<Containers> containers = containersList.stream().filter(e -> e.getPid().equals(item.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (containers.isEmpty()) {
|
|
|
+ throw new RuntimeException("分单号:" + item.getHblno() + "未配箱");
|
|
|
+ }
|
|
|
+ //获取当前循环的分单箱型信息
|
|
|
+ List<String> boxType = new ArrayList<>();
|
|
|
+ if (!preContainersList.isEmpty()) {
|
|
|
+ boxType = preContainersList.stream().filter(e -> e.getPid().equals(item.getId())).map(PreContainers::getCntrTypeCode)
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //循环组装对应箱型海运费单价
|
|
|
+ List<AgencyFeeSettingDTO> dtoList = new ArrayList<>();
|
|
|
+ for (String type : boxType) {
|
|
|
+ AgencyFeeSettingDTO dto = new AgencyFeeSettingDTO();
|
|
|
+ List<FeeCenter> feeCenters = feeCenterFDListHYF.stream().filter(e -> type.equals(e.getUnitNo())).collect(Collectors.toList());
|
|
|
+ //判断是否一个箱型一条海运费
|
|
|
+ if (feeCenters.size() > 1) {
|
|
|
+ throw new RuntimeException("分单号:" + item.getHblno() + ",箱型:" + type + "应收海运费存在多条");
|
|
|
+ }
|
|
|
+ dto.setBoxType(type);
|
|
|
+ dto.setPrice(feeCenters.get(0).getPrice());
|
|
|
+ dtoList.add(dto);
|
|
|
+ }
|
|
|
+ //判断分单是否是基本港
|
|
|
+ boolean whetherBasePort = false;
|
|
|
+ if (agencyFeeSetting.getPolId().contains(item.getPolId() + "") && agencyFeeSetting.getPodId().contains(item.getPodId() + "")) {
|
|
|
+ whetherBasePort = true;
|
|
|
+ }
|
|
|
+ //分单本次海运费集合
|
|
|
+ List<FeeCenter> thisFeeCenterList = new ArrayList<>();
|
|
|
+ //分单所有费用集合
|
|
|
+ List<FeeCenter> feeCenterSum = new ArrayList<>(feeCenterFDListSum);
|
|
|
+ //计算分单对应箱型箱号海运费单价
|
|
|
+ for (AgencyFeeSettingDTO dto : dtoList) {
|
|
|
+ //分单对应箱型应收海运费
|
|
|
+ List<FeeCenter> feeCenters = feeCenterFDListHYF.stream().filter(e -> dto.getBoxType().equals(e.getUnitNo())).collect(Collectors.toList());
|
|
|
+ FeeCenter feeCenter = feeCenters.get(0);
|
|
|
+ //分单应付总部海运费数据组装
|
|
|
+ FeeCenter feeCenterC = new FeeCenter();
|
|
|
+ feeCenterC.setBranchId(item.getBranchId());
|
|
|
+ feeCenterC.setBranchName(item.getBranchName());
|
|
|
+ feeCenterC.setBookingAgentId(item.getBookingAgentId());
|
|
|
+ feeCenterC.setBookingAgentCnName(item.getBookingAgentCnName());
|
|
|
+ feeCenterC.setBookingAgentEnName(item.getBookingAgentEnName());
|
|
|
+ feeCenterC.setQuantityCntrDescr(item.getQuantityCntrDescr());
|
|
|
+ feeCenterC.setBillBranchId(item.getBranchId());
|
|
|
+ feeCenterC.setBillBranchName(item.getBranchName());
|
|
|
+ feeCenterC.setTeu(item.getTeu());
|
|
|
+ feeCenterC.setPid(item.getId());
|
|
|
+ feeCenterC.setCntrNo(item.getQuantityCntrTypesDescr());
|
|
|
+ feeCenterC.setBillNo(item.getBillNo());
|
|
|
+ feeCenterC.setBusinessType(item.getBusinessType());
|
|
|
+ feeCenterC.setBillType(item.getBillType());
|
|
|
+ feeCenterC.setBillDate(item.getBillDate());
|
|
|
+ feeCenterC.setBillCorpId(item.getCorpId());
|
|
|
+ feeCenterC.setBillCorpCnName(item.getCorpCnName());
|
|
|
+ feeCenterC.setBillCorpEnName(item.getCorpEnName());
|
|
|
+ feeCenterC.setBillShortName(item.getShortName());
|
|
|
+ feeCenterC.setLineId(item.getLineId());
|
|
|
+ feeCenterC.setLineCnName(item.getLineCnName());
|
|
|
+ feeCenterC.setLineEnName(item.getLineEnName());
|
|
|
+ feeCenterC.setVesselId(item.getVesselId());
|
|
|
+ feeCenterC.setVesselCnName(item.getVesselCnName());
|
|
|
+ feeCenterC.setVesselEnName(item.getVesselEnName());
|
|
|
+ feeCenterC.setVoyageNo(item.getVoyageNo());
|
|
|
+ feeCenterC.setMblno(item.getMblno());
|
|
|
+ feeCenterC.setHblno(item.getHblno());
|
|
|
+ feeCenterC.setEtd(item.getEtd());
|
|
|
+ feeCenterC.setEta(item.getEta());
|
|
|
+ feeCenterC.setPolId(item.getPolId());
|
|
|
+ feeCenterC.setPolCode(item.getPolCode());
|
|
|
+ feeCenterC.setPolCnName(item.getPolCnName());
|
|
|
+ feeCenterC.setPolEnName(item.getPolEnName());
|
|
|
+ feeCenterC.setPodId(item.getPodId());
|
|
|
+ feeCenterC.setPodCode(item.getPodCode());
|
|
|
+ feeCenterC.setPodCnName(item.getPodCnName());
|
|
|
+ feeCenterC.setPodEnName(item.getPodEnName());
|
|
|
+ feeCenterC.setPaymode(item.getMpaymode());
|
|
|
+ feeCenterC.setSort(1);
|
|
|
+ feeCenterC.setFeeId(feeCenter.getId());
|
|
|
+ feeCenterC.setFeeCode(feeCenter.getFeeCode());
|
|
|
+ feeCenterC.setFeeCnName(feeCenter.getFeeCnName());
|
|
|
+ feeCenterC.setFeeEnName(feeCenter.getFeeEnName());
|
|
|
+ feeCenterC.setUnitNo(feeCenter.getUnitNo());
|
|
|
+ feeCenterC.setCurCode(feeCenter.getCurCode());
|
|
|
+ feeCenterC.setExrate(feeCenter.getExrate());
|
|
|
+ feeCenterC.setDc("C");
|
|
|
+ feeCenterC.setCorpType("国内直接客户");
|
|
|
+ feeCenterC.setCorpId(bCorps.getId());
|
|
|
+ feeCenterC.setCorpCnName(bCorps.getCnName());
|
|
|
+ feeCenterC.setCorpEnName(bCorps.getEnName());
|
|
|
+ feeCenterC.setShortName(bCorps.getShortName());
|
|
|
+ feeCenterC.setGenerationCorpId(bCorps.getBookingAgentId());
|
|
|
+ feeCenterC.setGenerationCorpCnName(bCorps.getBookingAgentCnName());
|
|
|
+ feeCenterC.setGenerationCorpEnName(bCorps.getBookingAgentEnName());
|
|
|
+ feeCenterC.setQuantity(new BigDecimal("1"));
|
|
|
+ //获取分单箱型对应箱号数据
|
|
|
+ List<String> boxCode = containers.stream().filter(e -> e.getCntrTypeCode().equals(dto.getBoxType()))
|
|
|
+ .map(Containers::getCntrNo).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ //合计计算费率后海运费
|
|
|
+ BigDecimal amountPrice = new BigDecimal("0.00");
|
|
|
+ //应收海运费用单价
|
|
|
+ BigDecimal price = feeCenter.getPrice();
|
|
|
+ for (String cntrNo : boxCode) {
|
|
|
+ //获取箱号对应箱档案数据
|
|
|
+ Archives archives = archivesList.stream().filter(e -> e.getCode().equals(cntrNo)).findFirst().orElse(null);
|
|
|
+ if (archives == null) {
|
|
|
+ throw new RuntimeException("分单号:" + item.getHblno() + ",箱号:" + cntrNo + "在箱档案中未查到");
|
|
|
+ }
|
|
|
+ if (whetherBasePort) {
|
|
|
+ //基本港
|
|
|
+ if ("DF自营".equals(item.getCabinType())) {
|
|
|
+ //自营箱 需判断是否调拨
|
|
|
+ if ("1".equals(archives.getWhetherTransfer())) {
|
|
|
+ //调拨箱
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicDfSelfOperatedInvoke()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicDfSelfOperatedInvoke().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非调拨箱
|
|
|
+ if ("代理箱".equals(archives.getBoxType())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicDfSelfOperatedAgent()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicDfSelfOperatedAgent().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicDfSelfOperatedOwn()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicDfSelfOperatedOwn().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非自营箱 无需判断是否调拨
|
|
|
+ if ("DF合营".equals(item.getCabinType())) {
|
|
|
+ if ("代理箱".equals(archives.getBoxType())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicDfJointVentureAgent()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicDfJointVentureAgent().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicDfJointVentureOwn()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicDfJointVentureOwn().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("代理箱".equals(archives.getBoxType())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicOpenCsaAgent()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicOpenCsaAgent().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getBasicOpenCsaOwn()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getBasicOpenCsaOwn().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非基本港
|
|
|
+ if ("DF自营".equals(item.getCabinType())) {
|
|
|
+ //自营箱 需判断是否调拨
|
|
|
+ if ("1".equals(archives.getWhetherTransfer())) {
|
|
|
+ //调拨箱
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicDfSelfOperatedInvoke()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicDfSelfOperatedInvoke().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非调拨箱
|
|
|
+ if ("代理箱".equals(archives.getBoxType())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicDfSelfOperatedAgent()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicDfSelfOperatedAgent().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicDfSelfOperatedOwn()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicDfSelfOperatedOwn().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //非自营箱 无需判断是否调拨
|
|
|
+ if ("DF合营".equals(item.getCabinType())) {
|
|
|
+ if ("代理箱".equals(archives.getBoxType())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicDfJointVentureAgent()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicDfJointVentureAgent().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicDfJointVentureOwn()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicDfJointVentureOwn().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("代理箱".equals(archives.getBoxType())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicOpenCsaAgent()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicOpenCsaAgent().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(agencyFeeSetting.getNotBasicOpenCsaOwn()) == 0) {
|
|
|
+ amountPrice = amountPrice.add(price);
|
|
|
+ } else {
|
|
|
+ BigDecimal rate = agencyFeeSetting.getNotBasicOpenCsaOwn().divide(new BigDecimal("100"), MathContext.DECIMAL32)
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal thisPrice = price.subtract(price.multiply(rate));
|
|
|
+ amountPrice = amountPrice.add(thisPrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ feeCenterC.setPrice(amountPrice);
|
|
|
+ feeCenterC.setAmount(feeCenterC.getQuantity().multiply(feeCenterC.getPrice()));
|
|
|
+ feeCenterC.setAmountLoc(feeCenterC.getAmount().multiply(feeCenterC.getExrate()));
|
|
|
+ feeCenterC.setUnsettledAmount(feeCenterC.getAmount());
|
|
|
+ feeCenterC.setCreateUser(AuthUtil.getUserId());
|
|
|
+ feeCenterC.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ feeCenterC.setCreateTime(new Date());
|
|
|
+ feeCentersFdC.add(feeCenterC);
|
|
|
+ feeCenterSum.add(feeCenterC);
|
|
|
+ thisFeeCenterList.add(feeCenterC);
|
|
|
+ }
|
|
|
+ Bills billsAmount = costProfitCalculationService.costProfitCalculation(feeCenterSum, exrateType);
|
|
|
+ if (billsAmount != null) {
|
|
|
+ item.setAccountStatus(billsAmount.getAccountStatus());
|
|
|
+ item.setAmountDr(billsAmount.getAmountDr());
|
|
|
+ item.setOceanFreightDr(billsAmount.getOceanFreightDr());
|
|
|
+ item.setAmountCr(billsAmount.getAmountCr());
|
|
|
+ item.setOceanFreightCr(billsAmount.getOceanFreightCr());
|
|
|
+ item.setAmountProfit(billsAmount.getAmountProfit());
|
|
|
+ item.setOceanFreightProfit(billsAmount.getOceanFreightProfit());
|
|
|
+ item.setAmountDrUsd(billsAmount.getAmountDrUsd());
|
|
|
+ item.setAmountCrUsd(billsAmount.getAmountCrUsd());
|
|
|
+ item.setAmountProfitUsd(billsAmount.getAmountProfitUsd());
|
|
|
+ item.setAmountDrLoc(billsAmount.getAmountDrLoc());
|
|
|
+ item.setAmountCrLoc(billsAmount.getAmountCrLoc());
|
|
|
+ item.setAmountProfitLoc(billsAmount.getAmountProfitLoc());
|
|
|
+ billsService.updateById(item);
|
|
|
+ }
|
|
|
+ if (!thisFeeCenterList.isEmpty()) {
|
|
|
+ BigDecimal amount = thisFeeCenterList.stream().map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ FeeCenter feeCenterD = new FeeCenter();
|
|
|
+ feeCenterD.setBookingAgentId(bills.getBookingAgentId());
|
|
|
+ feeCenterD.setBookingAgentCnName(bills.getBookingAgentCnName());
|
|
|
+ feeCenterD.setBookingAgentEnName(bills.getBookingAgentEnName());
|
|
|
+ feeCenterD.setQuantityCntrDescr(bills.getQuantityCntrDescr());
|
|
|
+ feeCenterD.setBillBranchId(bills.getBranchId());
|
|
|
+ feeCenterD.setBillBranchName(bills.getBranchName());
|
|
|
+ feeCenterD.setTeu(bills.getTeu());
|
|
|
+ feeCenterD.setBranchId(bills.getBranchId());
|
|
|
+ feeCenterD.setBranchName(bills.getBranchName());
|
|
|
+ feeCenterD.setPid(bills.getId());
|
|
|
+ feeCenterD.setCntrNo(bills.getQuantityCntrTypesDescr());
|
|
|
+ feeCenterD.setBillNo(bills.getBillNo());
|
|
|
+ feeCenterD.setBusinessType(bills.getBusinessType());
|
|
|
+ feeCenterD.setBillType(bills.getBillType());
|
|
|
+ feeCenterD.setBillDate(bills.getBillDate());
|
|
|
+ feeCenterD.setBillCorpId(bills.getCorpId());
|
|
|
+ feeCenterD.setBillCorpCnName(bills.getCorpCnName());
|
|
|
+ feeCenterD.setBillCorpEnName(bills.getCorpEnName());
|
|
|
+ feeCenterD.setBillShortName(bills.getShortName());
|
|
|
+ feeCenterD.setLineId(bills.getLineId());
|
|
|
+ feeCenterD.setLineCnName(bills.getLineCnName());
|
|
|
+ feeCenterD.setLineEnName(bills.getLineEnName());
|
|
|
+ feeCenterD.setVesselId(bills.getVesselId());
|
|
|
+ feeCenterD.setVesselCnName(bills.getVesselCnName());
|
|
|
+ feeCenterD.setVesselEnName(bills.getVesselEnName());
|
|
|
+ feeCenterD.setVoyageNo(bills.getVoyageNo());
|
|
|
+ feeCenterD.setMblno(bills.getMblno());
|
|
|
+ feeCenterD.setHblno(item.getHblno());
|
|
|
+ feeCenterD.setSrcItemId(item.getId());
|
|
|
+ feeCenterD.setEtd(bills.getEtd());
|
|
|
+ feeCenterD.setEta(bills.getEta());
|
|
|
+ feeCenterD.setPolId(bills.getPolId());
|
|
|
+ feeCenterD.setPolCode(bills.getPolCode());
|
|
|
+ feeCenterD.setPolCnName(bills.getPolCnName());
|
|
|
+ feeCenterD.setPolEnName(bills.getPolEnName());
|
|
|
+ feeCenterD.setPodId(bills.getPodId());
|
|
|
+ feeCenterD.setPodCode(bills.getPodCode());
|
|
|
+ feeCenterD.setPodCnName(bills.getPodCnName());
|
|
|
+ feeCenterD.setPodEnName(bills.getPodEnName());
|
|
|
+ feeCenterD.setPaymode(bills.getMpaymode());
|
|
|
+ feeCenterD.setSort(1);
|
|
|
+ feeCenterD.setFeeId(fees.getId());
|
|
|
+ feeCenterD.setFeeCode(fees.getCode());
|
|
|
+ feeCenterD.setFeeCnName(fees.getCnName());
|
|
|
+ feeCenterD.setFeeEnName(fees.getEnName());
|
|
|
+ feeCenterD.setUnitNo("JOB");
|
|
|
+ feeCenterD.setCurCode(feeCenterSum.get(0).getCurCode());
|
|
|
+ feeCenterD.setExrate(feeCenterSum.get(0).getExrate());
|
|
|
+ feeCenterD.setDc("D");
|
|
|
+ feeCenterD.setCorpType("国内直接客户");
|
|
|
+ BCorps corps = bCorpsService.getOne(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .eq(BCorps::getEnName, item.getBranchName()));
|
|
|
+ if (corps == null) {
|
|
|
+ throw new RuntimeException("基础资料未查到往来单位" + bills.getBranchName());
|
|
|
+ }
|
|
|
+ feeCenterD.setCorpId(corps.getId());
|
|
|
+ feeCenterD.setCorpCnName(corps.getCnName());
|
|
|
+ feeCenterD.setCorpEnName(corps.getEnName());
|
|
|
+ feeCenterD.setShortName(corps.getShortName());
|
|
|
+ feeCenterD.setGenerationCorpId(corps.getBookingAgentId());
|
|
|
+ feeCenterD.setGenerationCorpCnName(corps.getBookingAgentCnName());
|
|
|
+ feeCenterD.setGenerationCorpEnName(corps.getBookingAgentEnName());
|
|
|
+ feeCenterD.setQuantity(new BigDecimal("1"));
|
|
|
+ feeCenterD.setPrice(amount);
|
|
|
+ feeCenterD.setAmount(amount);
|
|
|
+ feeCenterD.setAmountLoc(amount.multiply(feeCenterD.getExrate()));
|
|
|
+ feeCenterD.setUnsettledAmount(feeCenterD.getAmount());
|
|
|
+ feeCenterD.setCreateUser(AuthUtil.getUserId());
|
|
|
+ feeCenterD.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ feeCenterD.setCreateTime(new Date());
|
|
|
+ list.add(feeCenterD);
|
|
|
+ list1.add(feeCenterD);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!feeCentersFdC.isEmpty()) {
|
|
|
+ feeCenterService.saveBatch(feeCentersFdC);
|
|
|
+ }
|
|
|
+ int count = 1;
|
|
|
+ for (RouteCostItem items : routeCostItemList) {
|
|
|
+ if ("DD".equals(bills.getBillType())) {
|
|
|
+ FeeCenter feeCenter = this.addFeeCenter(bills, "C", count, fees, "船公司", items,
|
|
|
+ curExrateList, preContainers, exrateType, "1");
|
|
|
+ if (feeCenter != null) {
|
|
|
+ feeCenter.setBranchId(branchId);
|
|
|
+ feeCenter.setBranchName(deptName);
|
|
|
+ list.add(feeCenter);
|
|
|
+ list1.add(feeCenter);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ FeeCenter feeCenterD = this.addFeeCenter(bills, "D", count, fees, "国内直接客户", items,
|
|
|
+ curExrateList, preContainers, exrateType, "2");
|
|
|
+ if (feeCenterD != null) {
|
|
|
+ feeCenterD.setBranchId(branchId);
|
|
|
+ feeCenterD.setBranchName(deptName);
|
|
|
+ list.add(feeCenterD);
|
|
|
+ list1.add(feeCenterD);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ //二程费用
|
|
|
+ if (ObjectUtils.isNotNull(items.getOceanFreightTwo()) &&
|
|
|
+ new BigDecimal("0.00").compareTo(items.getOceanFreightTwo()) != 0) {
|
|
|
+ FeeCenter feeCenterChengBrothers = this.addFeeCenterChengBrothers(bills, "C", count, fees, "船公司", items,
|
|
|
+ curExrateList, preContainers, exrateType, "1");
|
|
|
+ if (feeCenterChengBrothers != null) {
|
|
|
+ feeCenterChengBrothers.setBranchId(branchId);
|
|
|
+ feeCenterChengBrothers.setBranchName(deptName);
|
|
|
+ list.add(feeCenterChengBrothers);
|
|
|
+ list1.add(feeCenterChengBrothers);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ FeeCenter feeCenterDChengBrothers = this.addFeeCenterChengBrothers(bills, "D", count, fees, "国内直接客户", items,
|
|
|
+ curExrateList, preContainers, exrateType, "2");
|
|
|
+ if (feeCenterDChengBrothers != null) {
|
|
|
+ feeCenterDChengBrothers.setBranchId(branchId);
|
|
|
+ feeCenterDChengBrothers.setBranchName(deptName);
|
|
|
+ list.add(feeCenterDChengBrothers);
|
|
|
+ list1.add(feeCenterDChengBrothers);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if ("MM".equals(bills.getBillType())) {
|
|
|
+ FeeCenter feeCenter = this.addFeeCenter(bills, "C", count, fees, "船公司", items,
|
|
|
+ curExrateList, preContainers, exrateType, "1");
|
|
|
+ if (feeCenter != null) {
|
|
|
+ feeCenter.setBranchId(branchId);
|
|
|
+ feeCenter.setBranchName(deptName);
|
|
|
+ list.add(feeCenter);
|
|
|
+ list1.add(feeCenter);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ if ("COC".equals(bills.getBoxBelongsTo())) {
|
|
|
+ FeeCenter feeCenterD = this.addFeeCenter(bills, "D", count, fees, "国内直接客户", items,
|
|
|
+ curExrateList, preContainers, exrateType, "3");
|
|
|
+ if (feeCenterD != null) {
|
|
|
+ feeCenterD.setBranchId(branchId);
|
|
|
+ feeCenterD.setBranchName(deptName);
|
|
|
+ list.add(feeCenterD);
|
|
|
+ list1.add(feeCenterD);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ FeeCenter feeCenter1 = this.addFeeCenter(bills, "C", count, feesFjf, "船公司", items,
|
|
|
+ curExrateList, preContainers, exrateType, "5");
|
|
|
+ if (feeCenter1 != null) {
|
|
|
+ feeCenter1.setBranchId(branchId);
|
|
|
+ feeCenter1.setBranchName(deptName);
|
|
|
+ list.add(feeCenter1);
|
|
|
+ list1.add(feeCenter1);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //二程费用
|
|
|
+ if (ObjectUtils.isNotNull(items.getOceanFreightTwo()) &&
|
|
|
+ new BigDecimal("0.00").compareTo(items.getOceanFreightTwo()) != 0) {
|
|
|
+ FeeCenter feeCenterChengBrothers = this.addFeeCenterChengBrothers(bills, "C", count, fees, "船公司", items,
|
|
|
+ curExrateList, preContainers, exrateType, "1");
|
|
|
+ if (feeCenterChengBrothers != null) {
|
|
|
+ feeCenterChengBrothers.setBranchId(branchId);
|
|
|
+ feeCenterChengBrothers.setBranchName(deptName);
|
|
|
+ list.add(feeCenterChengBrothers);
|
|
|
+ list1.add(feeCenterChengBrothers);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ if ("COC".equals(bills.getBoxBelongsTo())) {
|
|
|
+ FeeCenter feeCenterDChengBrothers = this.addFeeCenterChengBrothers(bills, "D", count, fees, "国内直接客户", items,
|
|
|
+ curExrateList, preContainers, exrateType, "3");
|
|
|
+ if (feeCenterDChengBrothers != null) {
|
|
|
+ feeCenterDChengBrothers.setBranchId(branchId);
|
|
|
+ feeCenterDChengBrothers.setBranchName(deptName);
|
|
|
+ list.add(feeCenterDChengBrothers);
|
|
|
+ list1.add(feeCenterDChengBrothers);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if ("MH".equals(bills.getBillType())) {
|
|
|
+ throw new RuntimeException("只能提取主单,直单单据成本");
|
|
|
+ /*FeeCenter feeCenter = this.addFeeCenter(bills, "C", count, fees, "国内直接客户", items,
|
|
|
+ curExrateList, preContainers, exrateType, "4");
|
|
|
+ if (feeCenter != null) {
|
|
|
+ feeCenter.setBranchId(branchId);
|
|
|
+ feeCenter.setBranchName(deptName);
|
|
|
+ list.add(feeCenter);
|
|
|
+ count++;
|
|
|
+ }*/
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("单据类型错误,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!list1.isEmpty()) {
|
|
|
+ LambdaQueryWrapper<FeeCenter> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .eq(FeeCenter::getPid, bills.getId());
|
|
|
+ List<FeeCenter> feeCenterOldList = feeCenterService.list(lambdaQueryWrapper);
|
|
|
+ if (!feeCenterOldList.isEmpty()) {
|
|
|
+ list1.addAll(feeCenterOldList);
|
|
|
+ }
|
|
|
+ Bills billsAmount = costProfitCalculationService.costProfitCalculation(list1, exrateType);
|
|
|
+ if (billsAmount != null) {
|
|
|
+ bills.setAccountStatus(billsAmount.getAccountStatus());
|
|
|
+ bills.setAmountDr(billsAmount.getAmountDr());
|
|
|
+ bills.setOceanFreightDr(billsAmount.getOceanFreightDr());
|
|
|
+ bills.setAmountCr(billsAmount.getAmountCr());
|
|
|
+ bills.setOceanFreightCr(billsAmount.getOceanFreightCr());
|
|
|
+ bills.setAmountProfit(billsAmount.getAmountProfit());
|
|
|
+ bills.setOceanFreightProfit(billsAmount.getOceanFreightProfit());
|
|
|
+ bills.setAmountDrUsd(billsAmount.getAmountDrUsd());
|
|
|
+ bills.setAmountCrUsd(billsAmount.getAmountCrUsd());
|
|
|
+ bills.setAmountProfitUsd(billsAmount.getAmountProfitUsd());
|
|
|
+ bills.setAmountDrLoc(billsAmount.getAmountDrLoc());
|
|
|
+ bills.setAmountCrLoc(billsAmount.getAmountCrLoc());
|
|
|
+ bills.setAmountProfitLoc(billsAmount.getAmountProfitLoc());
|
|
|
+ billsService.updateById(bills);
|
|
|
+ }
|
|
|
+// this.updateBills(list1, bills, exrateType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ feeCenterService.saveOrUpdateBatch(list);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("导入失败,箱型不符");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(text.toString())) {
|
|
|
+ return R.data(list, text + "未导入!!!");
|
|
|
+ } else {
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R submit(AgencyFeeSetting agencyFeeSetting) {
|
|
|
+ String deptName = "";
|
|
|
+ String branchId = AuthUtil.getDeptId();
|
|
|
+ //获取部门ids对应中文名
|
|
|
+ if (ObjectUtils.isNotNull(branchId)) {
|
|
|
+ R<String> res = sysClient.getDeptName(Long.parseLong(branchId));
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ deptName = res.getData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<AgencyFeeSetting> agencyFeeSettingList = baseMapper.selectListByPolId(agencyFeeSetting.getPolId(),
|
|
|
+ formatter.format(agencyFeeSetting.getValidityPeriodStart()), AuthUtil.getTenantId());
|
|
|
+ if (agencyFeeSetting.getId() == null) {
|
|
|
+ if (!agencyFeeSettingList.isEmpty()) {
|
|
|
+ throw new RuntimeException("港口存在重复添加");
|
|
|
+ }
|
|
|
+ BusinessType businessType = bBusinessTypeService.getOne(new LambdaQueryWrapper<BusinessType>()
|
|
|
+ .eq(BusinessType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BusinessType::getIsDeleted, 0)
|
|
|
+ .eq(BusinessType::getStatus, 0)
|
|
|
+ .eq(BusinessType::getCode, agencyFeeSetting.getBusinessTypeCode()));
|
|
|
+ if (businessType == null) {
|
|
|
+ throw new RuntimeException("未找到可用业务类型");
|
|
|
+ }
|
|
|
+ BusinessBillNo businessBillNo = new BusinessBillNo();
|
|
|
+ businessBillNo.setBusinessTypeId(businessType.getId());
|
|
|
+ businessBillNo.setCode(agencyFeeSetting.getBillNoFormat());
|
|
|
+ businessBillNo.setBranchId(branchId);
|
|
|
+ businessBillNo.setDate(new Date());
|
|
|
+ R<String> clientBillNo = businessBillNoService.getBillNoLos(businessBillNo);
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成订单编号失败");
|
|
|
+ }
|
|
|
+ agencyFeeSetting.setSysNo(clientBillNo.getData());
|
|
|
+ agencyFeeSetting.setCreateTime(new Date());
|
|
|
+ agencyFeeSetting.setCreateUser(AuthUtil.getUserId());
|
|
|
+ agencyFeeSetting.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ agencyFeeSetting.setBranchId(branchId);
|
|
|
+ agencyFeeSetting.setBranchName(deptName);
|
|
|
+ } else {
|
|
|
+ if (!agencyFeeSettingList.isEmpty() && agencyFeeSettingList.stream().filter(e -> !e.getId().equals(agencyFeeSetting.getId())).count() > 1) {
|
|
|
+ throw new RuntimeException("港口存在重复添加");
|
|
|
+ }
|
|
|
+ agencyFeeSetting.setUpdateTime(new Date());
|
|
|
+ agencyFeeSetting.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ agencyFeeSetting.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(agencyFeeSetting);
|
|
|
+ return R.data(agencyFeeSetting);
|
|
|
+ }
|
|
|
+
|
|
|
+ private FeeCenter addFeeCenterQuotation(Bills bills, String dc, int count, BFees fees, String corpType,
|
|
|
+ PreContainers items, List<BCurExrate> curExrateList,
|
|
|
+ MktSlotQuotation mktSlotQuotations, String exrateType, String type) {
|
|
|
+ FeeCenter feeCenter = new FeeCenter();
|
|
|
+ feeCenter.setCreateUser(AuthUtil.getUserId());
|
|
|
+ feeCenter.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ feeCenter.setCreateTime(new Date());
|
|
|
+ feeCenter.setBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setBillBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBillBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setBookingAgentId(bills.getBookingAgentId());
|
|
|
+ feeCenter.setBookingAgentCnName(bills.getBookingAgentCnName());
|
|
|
+ feeCenter.setBookingAgentEnName(bills.getBookingAgentEnName());
|
|
|
+ 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(mktSlotQuotations.getCurCode());
|
|
|
+ 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.getGp20());
|
|
|
+ } else if ("40GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.getGp40());
|
|
|
+ } else if ("40HC".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.getHc40());
|
|
|
+ } 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.getGp20Cost());
|
|
|
+ } else if ("40GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.getGp40Cost());
|
|
|
+ } else if ("40HC".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.getHc40Cost());
|
|
|
+ } 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.getGp20Cost());
|
|
|
+ } else if ("40GP".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.getGp40Cost());
|
|
|
+ } else if ("40HC".equals(items.getCntrTypeCode())) {
|
|
|
+ feeCenter.setPrice(mktSlotQuotations.getHc40Cost());
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BCorps corps = bCorpsService.getById(feeCenter.getCorpId());
|
|
|
+ if (corps != null) {
|
|
|
+ feeCenter.setGenerationCorpId(corps.getBookingAgentId());
|
|
|
+ feeCenter.setGenerationCorpCnName(corps.getBookingAgentCnName());
|
|
|
+ feeCenter.setGenerationCorpEnName(corps.getBookingAgentEnName());
|
|
|
+ }
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ feeCenter.setUnsettledAmount(feeCenter.getAmount());
|
|
|
+ if (new BigDecimal("0").compareTo(feeCenter.getAmount()) == 0) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ 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) {
|
|
|
+ FeeCenter feeCenter = new FeeCenter();
|
|
|
+ feeCenter.setCreateUser(AuthUtil.getUserId());
|
|
|
+ feeCenter.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ feeCenter.setCreateTime(new Date());
|
|
|
+ feeCenter.setBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setBookingAgentId(bills.getBookingAgentId());
|
|
|
+ feeCenter.setBookingAgentCnName(bills.getBookingAgentCnName());
|
|
|
+ feeCenter.setBookingAgentEnName(bills.getBookingAgentEnName());
|
|
|
+ feeCenter.setQuantityCntrDescr(bills.getQuantityCntrDescr());
|
|
|
+ feeCenter.setBillBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBillBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setTeu(bills.getTeu());
|
|
|
+ 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(items.getBoxType());
|
|
|
+ feeCenter.setCurCode(items.getCurCode());
|
|
|
+ feeCenter.setExrate(currencyUtils.obtainExrate(feeCenter.getDc(), curExrateList, feeCenter.getCurCode(), "1"));
|
|
|
+ Integer quantity = preContainers.stream().filter(e -> items.getBoxType().equals(e.getCntrTypeCode())).map(PreContainers::getQuantity).reduce(0, Integer::sum);
|
|
|
+ if (quantity == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ feeCenter.setQuantity(new BigDecimal(quantity + ""));
|
|
|
+ if ("1".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCarrierId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCarrierCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCarrierEnName());
|
|
|
+ feeCenter.setShortName(bills.getCarrierShortName());
|
|
|
+ feeCenter.setPrice(items.getOceanFreight());
|
|
|
+ } else if ("2".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCorpId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCorpCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCorpEnName());
|
|
|
+ feeCenter.setShortName(bills.getShortName());
|
|
|
+ feeCenter.setPrice(items.getSalesPrice());
|
|
|
+ } else if ("3".equals(type)) {
|
|
|
+ BCorps bCorps = bCorpsService.getOne(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .eq(BCorps::getEnName, bills.getBranchName()));
|
|
|
+ if (bCorps == null) {
|
|
|
+ throw new RuntimeException("基础资料未查到往来单位" + bills.getBranchName());
|
|
|
+ }
|
|
|
+ feeCenter.setCorpId(bCorps.getId());
|
|
|
+ feeCenter.setCorpCnName(bCorps.getCnName());
|
|
|
+ feeCenter.setCorpEnName(bCorps.getEnName());
|
|
|
+ feeCenter.setShortName(bCorps.getShortName());
|
|
|
+ feeCenter.setPrice(items.getSalesPrice());
|
|
|
+ } else if ("4".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());
|
|
|
+ feeCenter.setPrice(items.getSalesPrice());
|
|
|
+ } else if ("5".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCarrierId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCarrierCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCarrierEnName());
|
|
|
+ feeCenter.setShortName(bills.getCarrierShortName());
|
|
|
+ feeCenter.setPrice(items.getAdditionalFee());
|
|
|
+ }
|
|
|
+ BCorps corps = bCorpsService.getById(feeCenter.getCorpId());
|
|
|
+ if (corps != null) {
|
|
|
+ feeCenter.setGenerationCorpId(corps.getBookingAgentId());
|
|
|
+ feeCenter.setGenerationCorpCnName(corps.getBookingAgentCnName());
|
|
|
+ feeCenter.setGenerationCorpEnName(corps.getBookingAgentEnName());
|
|
|
+ }
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ feeCenter.setUnsettledAmount(feeCenter.getAmount());
|
|
|
+ if (new BigDecimal("0.00").compareTo(feeCenter.getAmount()) == 0) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return feeCenter;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FeeCenter addFeeCenterChengBrothers(Bills bills, String dc, int count, BFees fees, String corpType, RouteCostItem
|
|
|
+ items,
|
|
|
+ List<BCurExrate> curExrateList, List<PreContainers> preContainers,
|
|
|
+ String exrateType, String type) {
|
|
|
+ FeeCenter feeCenter = new FeeCenter();
|
|
|
+ feeCenter.setCreateUser(AuthUtil.getUserId());
|
|
|
+ feeCenter.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ feeCenter.setCreateTime(new Date());
|
|
|
+ feeCenter.setBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setBookingAgentId(bills.getBookingAgentId());
|
|
|
+ feeCenter.setBookingAgentCnName(bills.getBookingAgentCnName());
|
|
|
+ feeCenter.setBookingAgentEnName(bills.getBookingAgentEnName());
|
|
|
+ feeCenter.setQuantityCntrDescr(bills.getQuantityCntrDescr());
|
|
|
+ feeCenter.setBillBranchId(bills.getBranchId());
|
|
|
+ feeCenter.setBillBranchName(bills.getBranchName());
|
|
|
+ feeCenter.setTeu(bills.getTeu());
|
|
|
+ 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(items.getBoxType());
|
|
|
+ feeCenter.setCurCode(items.getCurCode());
|
|
|
+ feeCenter.setExrate(currencyUtils.obtainExrate(feeCenter.getDc(), curExrateList, feeCenter.getCurCode(), "1"));
|
|
|
+ Integer quantity = preContainers.stream().filter(e -> items.getBoxType().equals(e.getCntrTypeCode())).map(PreContainers::getQuantity).reduce(0, Integer::sum);
|
|
|
+ if (quantity == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ feeCenter.setQuantity(new BigDecimal(quantity + ""));
|
|
|
+ if ("1".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCarrierId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCarrierCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCarrierEnName());
|
|
|
+ feeCenter.setShortName(bills.getCarrierShortName());
|
|
|
+ feeCenter.setPrice(items.getOceanFreightTwo());
|
|
|
+ } else if ("2".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCorpId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCorpCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCorpEnName());
|
|
|
+ feeCenter.setShortName(bills.getShortName());
|
|
|
+ feeCenter.setPrice(items.getSalesPriceTwo());
|
|
|
+ } else if ("3".equals(type)) {
|
|
|
+ BCorps bCorps = bCorpsService.getOne(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .eq(BCorps::getEnName, bills.getBranchName()));
|
|
|
+ if (bCorps == null) {
|
|
|
+ throw new RuntimeException("基础资料未查到往来单位" + bills.getBranchName());
|
|
|
+ }
|
|
|
+ feeCenter.setCorpId(bCorps.getId());
|
|
|
+ feeCenter.setCorpCnName(bCorps.getCnName());
|
|
|
+ feeCenter.setCorpEnName(bCorps.getEnName());
|
|
|
+ feeCenter.setShortName(bCorps.getShortName());
|
|
|
+ feeCenter.setPrice(items.getSalesPriceTwo());
|
|
|
+ } else if ("4".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());
|
|
|
+ feeCenter.setPrice(items.getSalesPriceTwo());
|
|
|
+ } else if ("5".equals(type)) {
|
|
|
+ feeCenter.setCorpId(bills.getCarrierId());
|
|
|
+ feeCenter.setCorpCnName(bills.getCarrierCnName());
|
|
|
+ feeCenter.setCorpEnName(bills.getCarrierEnName());
|
|
|
+ feeCenter.setShortName(bills.getCarrierShortName());
|
|
|
+ feeCenter.setPrice(items.getAdditionalFee());
|
|
|
+ }
|
|
|
+ BCorps corps = bCorpsService.getById(feeCenter.getCorpId());
|
|
|
+ if (corps != null) {
|
|
|
+ feeCenter.setGenerationCorpId(corps.getBookingAgentId());
|
|
|
+ feeCenter.setGenerationCorpCnName(corps.getBookingAgentCnName());
|
|
|
+ feeCenter.setGenerationCorpEnName(corps.getBookingAgentEnName());
|
|
|
+ }
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ feeCenter.setUnsettledAmount(feeCenter.getAmount());
|
|
|
+ if (new BigDecimal("0.00").compareTo(feeCenter.getAmount()) == 0) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return feeCenter;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|