|
|
@@ -973,10 +973,21 @@ public class RouteCostServiceImpl extends ServiceImpl<RouteCostMapper, RouteCost
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R batchCopy(String ids) {
|
|
|
- if (ObjectUtils.isNull(ids)) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R batchCopy(String ids, BigDecimal exrate, Date effectiveStartDate, Date effectiveEndDate,String type,String curCode) {
|
|
|
+ if (ObjectUtils.isNull(ids) || ObjectUtils.isNull(exrate) || ObjectUtils.isNull(effectiveStartDate)
|
|
|
+ || ObjectUtils.isNull(effectiveEndDate)) {
|
|
|
throw new RuntimeException("缺少必要参数");
|
|
|
}
|
|
|
+ BusinessType businessType = bBusinessTypeService.getOne(new LambdaQueryWrapper<BusinessType>()
|
|
|
+ .select(BusinessType::getId)
|
|
|
+ .eq(BusinessType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BusinessType::getIsDeleted, 0)
|
|
|
+ .eq(BusinessType::getStatus, 0)
|
|
|
+ .eq(BusinessType::getCode, type));
|
|
|
+ if (businessType == null) {
|
|
|
+ throw new RuntimeException("未找到可用业务类型");
|
|
|
+ }
|
|
|
List<RouteCost> routeCostList = baseMapper.selectList(new LambdaQueryWrapper<RouteCost>()
|
|
|
.eq(RouteCost::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(RouteCost::getIsDeleted, 0)
|
|
|
@@ -984,117 +995,144 @@ public class RouteCostServiceImpl extends ServiceImpl<RouteCostMapper, RouteCost
|
|
|
if (routeCostList.isEmpty()) {
|
|
|
throw new RuntimeException("未查到数据");
|
|
|
}
|
|
|
+ List<RouteCostFee> costFeesList = routeCostFeeService.list(new LambdaQueryWrapper<RouteCostFee>()
|
|
|
+ .eq(RouteCostFee::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(RouteCostFee::getIsDeleted, 0)
|
|
|
+ .in(RouteCostFee::getPid, Func.toLongList(ids)));
|
|
|
+ List<RouteCostItem> costItemList = routeCostItemService.list(new LambdaQueryWrapper<RouteCostItem>()
|
|
|
+ .eq(RouteCostItem::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(RouteCostItem::getIsDeleted, 0)
|
|
|
+ .in(RouteCostItem::getPid, Func.toLongList(ids)));
|
|
|
+ List<RouteCost> routeCostListNew = new ArrayList<>();
|
|
|
for (RouteCost item : routeCostList) {
|
|
|
- Long id = item.getId();
|
|
|
+ item.setCopyId(item.getId());
|
|
|
item.setId(null);
|
|
|
- item.setCreateTime(null);
|
|
|
- item.setCreateUser(null);
|
|
|
- item.setCreateUserName(null);
|
|
|
+ BusinessBillNo businessBillNo = new BusinessBillNo();
|
|
|
+ businessBillNo.setBusinessTypeId(businessType.getId());
|
|
|
+ businessBillNo.setCode(type);
|
|
|
+ R clientBillNo = businessBillNoService.getBillNoLos(businessBillNo);
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.fail(500, "生成订单编号失败");
|
|
|
+ }
|
|
|
+ item.setBusinessNo((String) clientBillNo.getData());
|
|
|
+ item.setBusinessDate(new Date());
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setCreateUserName(AuthUtil.getUserName());
|
|
|
item.setUpdateUser(null);
|
|
|
item.setUpdateTime(null);
|
|
|
item.setUpdateUserName(null);
|
|
|
item.setStatus("录入");
|
|
|
- item.setBusinessNo(null);
|
|
|
- item.setExrateDate(new Date());
|
|
|
-
|
|
|
- String exrateType = currencyUtils.standardCurrency(item.getBelongingCompanyId() + "");
|
|
|
- List<BCurExrate> curExrateList = currencyUtils.obtainRate(item.getExrateDate(), "1", item.getBelongingCompanyId() + "");
|
|
|
- List<RouteCostFee> costFeesList = routeCostFeeService.list(new LambdaQueryWrapper<RouteCostFee>()
|
|
|
- .eq(RouteCostFee::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(RouteCostFee::getIsDeleted, 0)
|
|
|
- .eq(RouteCostFee::getPid, id));
|
|
|
- for (RouteCostFee costFeeItem : costFeesList) {
|
|
|
- costFeeItem.setId(null);
|
|
|
- costFeeItem.setPid(null);
|
|
|
- costFeeItem.setCreateTime(null);
|
|
|
- costFeeItem.setCreateUser(null);
|
|
|
- costFeeItem.setCreateUserName(null);
|
|
|
- costFeeItem.setUpdateUser(null);
|
|
|
- costFeeItem.setUpdateTime(null);
|
|
|
- costFeeItem.setUpdateUserName(null);
|
|
|
- costFeeItem.setExrate(currencyUtils.obtainExrate("D", curExrateList, costFeeItem.getCurCode(), "1"));
|
|
|
- }
|
|
|
- item.setCostFeeList(costFeesList.isEmpty() ? new ArrayList<>() : costFeesList);
|
|
|
- List<RouteCostItem> costItemList = routeCostItemService.list(new LambdaQueryWrapper<RouteCostItem>()
|
|
|
- .eq(RouteCostItem::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(RouteCostItem::getIsDeleted, 0)
|
|
|
- .eq(RouteCostItem::getPid, id));
|
|
|
- for (RouteCostItem costItem : costItemList) {
|
|
|
- costItem.setId(null);
|
|
|
- costItem.setPid(null);
|
|
|
- costItem.setCreateTime(null);
|
|
|
- costItem.setCreateUser(null);
|
|
|
- costItem.setCreateUserName(null);
|
|
|
- costItem.setUpdateUser(null);
|
|
|
- costItem.setUpdateTime(null);
|
|
|
- costItem.setUpdateUserName(null);
|
|
|
- }
|
|
|
- item.setCostItemList(costItemList.isEmpty() ? new ArrayList<>() : costItemList);
|
|
|
- if (ObjectUtils.isNotNull(item.getCostItemList())) {
|
|
|
- int days = item.getNavigateDay() + item.getExistStationDay();
|
|
|
- List<RouteCostFee> costFeeList = item.getCostFeeList();
|
|
|
- for (RouteCostItem routeCostItem : item.getCostItemList()) {
|
|
|
- routeCostItem.setExrate(currencyUtils.obtainExrate("D", curExrateList, routeCostItem.getCurCode(), "1"));
|
|
|
- //一程POL杂费成本
|
|
|
- routeCostItem.setPolCost(computationalCost(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
- //一程POL杂费收入
|
|
|
- routeCostItem.setPolIncome(computationalIncome(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
- //一程POD杂费成本
|
|
|
- routeCostItem.setPodCost(computationalCost(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
- //一程POD杂费收入
|
|
|
- routeCostItem.setPodIncome(computationalIncome(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
- //一程用箱成本
|
|
|
- if (0 != days && ObjectUtils.isNotNull(routeCostItem.getBoxCost()) &&
|
|
|
- routeCostItem.getBoxCost().compareTo(new BigDecimal("0.00")) != 0) {
|
|
|
- BigDecimal boxCost = new BigDecimal(days).multiply(routeCostItem.getBoxCost());
|
|
|
- routeCostItem.setUseBoxCost(boxCost);
|
|
|
- } else {
|
|
|
- routeCostItem.setUseBoxCost(new BigDecimal("0.00"));
|
|
|
+ item.setExrateDate(effectiveStartDate);
|
|
|
+ item.setEffectiveStartDate(effectiveStartDate);
|
|
|
+ item.setEffectiveEndDate(effectiveEndDate);
|
|
|
+ routeCostListNew.add(item);
|
|
|
+ }
|
|
|
+ if (!routeCostListNew.isEmpty()){
|
|
|
+ this.saveBatch(routeCostListNew);
|
|
|
+ List<RouteCostFee> costFeesListNew = new ArrayList<>();
|
|
|
+ List<RouteCostItem> costItemListNew = new ArrayList<>();
|
|
|
+ for (RouteCost item : routeCostListNew){
|
|
|
+ if (!costFeesList.isEmpty()){
|
|
|
+ List<RouteCostFee> costFeesListNews = new ArrayList<>();
|
|
|
+ List<RouteCostFee> costFees = costFeesList.stream().filter(e-> e.getPid().equals(item.getCopyId())).collect(Collectors.toList());
|
|
|
+ for (RouteCostFee costFeeItem : costFees){
|
|
|
+ costFeeItem.setId(null);
|
|
|
+ costFeeItem.setPid(item.getId());
|
|
|
+ costFeeItem.setCreateTime(new Date());
|
|
|
+ costFeeItem.setCreateUser(AuthUtil.getUserId());
|
|
|
+ costFeeItem.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ costFeeItem.setUpdateUser(null);
|
|
|
+ costFeeItem.setUpdateTime(null);
|
|
|
+ costFeeItem.setUpdateUserName(null);
|
|
|
+ costFeeItem.setExrate(exrate);
|
|
|
+ costFeeItem.setCurCode(curCode);
|
|
|
+ costFeesListNew.add(costFeeItem);
|
|
|
+ costFeesListNews.add(costFeeItem);
|
|
|
}
|
|
|
- // 一程成本价 = 一程海运费+一程用箱成本+一程pol杂费+一程pod成本+附加费
|
|
|
- routeCostItem.setCostPrice(routeCostItem.getOceanFreight().add(routeCostItem.getPodCost()).add(routeCostItem.getPolCost())
|
|
|
- .add(routeCostItem.getUseBoxCost()).add(routeCostItem.getAdditionalFee()));
|
|
|
- //一程合计利润
|
|
|
- routeCostItem.setTotalProfit(routeCostItem.getSalesPrice().add(routeCostItem.getPolIncome())
|
|
|
- .add(routeCostItem.getPodIncome()).subtract(routeCostItem.getCostPrice()));
|
|
|
- if ("转船".equals(item.getFlightType()) && "自转".equals(item.getChangeShipType())) {
|
|
|
- //二程POL杂费成本
|
|
|
- routeCostItem.setPolCostTwo(computationalCost(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
- //二程POL杂费收入
|
|
|
- routeCostItem.setPolIncomeTwo(computationalIncome(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
- //二程POD杂费成本
|
|
|
- routeCostItem.setPodCostTwo(computationalCost(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
- //二程POD杂费收入
|
|
|
- routeCostItem.setPodIncomeTwo(computationalIncome(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
- // 二程成本价 = 二程海运费+二程pol杂费+二程pod成本
|
|
|
- routeCostItem.setCostPriceTwo(routeCostItem.getOceanFreightTwo().add(routeCostItem.getPodCostTwo()).add(routeCostItem.getPolCostTwo()));
|
|
|
- //二程合计利润
|
|
|
- routeCostItem.setTotalProfitTwo(routeCostItem.getSalesPriceTwo().add(routeCostItem.getPolIncomeTwo())
|
|
|
- .add(routeCostItem.getPodIncomeTwo()).subtract(routeCostItem.getCostPriceTwo()));
|
|
|
+ item.setCostFeeList(costFeesListNews.isEmpty() ? new ArrayList<>() : costFeesListNews);
|
|
|
+ }
|
|
|
+ if (!costItemList.isEmpty()){
|
|
|
+ List<RouteCostItem> costItemListNews = new ArrayList<>();
|
|
|
+ List<RouteCostItem> costItems = costItemList.stream().filter(e-> e.getPid().equals(item.getCopyId())).collect(Collectors.toList());
|
|
|
+ for (RouteCostItem costItem : costItems){
|
|
|
+ costItem.setId(null);
|
|
|
+ costItem.setPid(item.getId());
|
|
|
+ costItem.setCreateTime(new Date());
|
|
|
+ costItem.setCreateUser(AuthUtil.getUserId());
|
|
|
+ costItem.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ costItem.setUpdateUser(null);
|
|
|
+ costItem.setUpdateTime(null);
|
|
|
+ costItem.setUpdateUserName(null);
|
|
|
+ costItem.setExrate(exrate);
|
|
|
+ costItem.setCurCode(curCode);
|
|
|
+ costItemListNews.add(costItem);
|
|
|
}
|
|
|
- routeCostItem.setTotalProfitTwo(routeCostItem.getTotalProfitTwo() != null ? routeCostItem.getTotalProfitTwo() : new BigDecimal("0.00"));
|
|
|
- //合计利润
|
|
|
- routeCostItem.setProfit(routeCostItem.getTotalProfit().add(routeCostItem.getTotalProfitTwo()));
|
|
|
-
|
|
|
- if (routeCostItem.getId() == null) {
|
|
|
- routeCostItem.setPid(id);
|
|
|
- routeCostItem.setCreateTime(new Date());
|
|
|
- routeCostItem.setCreateUser(AuthUtil.getUserId());
|
|
|
- routeCostItem.setCreateUserName(AuthUtil.getUserName());
|
|
|
- } else {
|
|
|
- routeCostItem.setUpdateUser(AuthUtil.getUserId());
|
|
|
- routeCostItem.setUpdateTime(new Date());
|
|
|
- routeCostItem.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ item.setCostItemList(costItemListNews.isEmpty() ? new ArrayList<>() : costItemListNews);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getCostItemList())) {
|
|
|
+ int days = item.getNavigateDay() + item.getExistStationDay();
|
|
|
+ List<RouteCostFee> costFeeList = item.getCostFeeList();
|
|
|
+ for (RouteCostItem routeCostItem : item.getCostItemList()) {
|
|
|
+ routeCostItem.setExrate(exrate);
|
|
|
+ //一程POL杂费成本
|
|
|
+ routeCostItem.setPolCost(computationalCost(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
+ //一程POL杂费收入
|
|
|
+ routeCostItem.setPolIncome(computationalIncome(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
+ //一程POD杂费成本
|
|
|
+ routeCostItem.setPodCost(computationalCost(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
+ //一程POD杂费收入
|
|
|
+ routeCostItem.setPodIncome(computationalIncome(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "0"));
|
|
|
+ //一程用箱成本
|
|
|
+ if (0 != days && ObjectUtils.isNotNull(routeCostItem.getBoxCost()) &&
|
|
|
+ routeCostItem.getBoxCost().compareTo(new BigDecimal("0.00")) != 0) {
|
|
|
+ BigDecimal boxCost = new BigDecimal(days).multiply(routeCostItem.getBoxCost());
|
|
|
+ routeCostItem.setUseBoxCost(boxCost);
|
|
|
+ } else {
|
|
|
+ routeCostItem.setUseBoxCost(new BigDecimal("0.00"));
|
|
|
+ }
|
|
|
+ // 一程成本价 = 一程海运费+一程用箱成本+一程pol杂费+一程pod成本+附加费
|
|
|
+ routeCostItem.setCostPrice(routeCostItem.getOceanFreight().add(routeCostItem.getPodCost()).add(routeCostItem.getPolCost())
|
|
|
+ .add(routeCostItem.getUseBoxCost()).add(routeCostItem.getAdditionalFee()));
|
|
|
+ //一程合计利润
|
|
|
+ routeCostItem.setTotalProfit(routeCostItem.getSalesPrice().add(routeCostItem.getPolIncome())
|
|
|
+ .add(routeCostItem.getPodIncome()).subtract(routeCostItem.getCostPrice()));
|
|
|
+ if ("转船".equals(item.getFlightType()) && "自转".equals(item.getChangeShipType())) {
|
|
|
+ //二程POL杂费成本
|
|
|
+ routeCostItem.setPolCostTwo(computationalCost(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
+ //二程POL杂费收入
|
|
|
+ routeCostItem.setPolIncomeTwo(computationalIncome(costFeeList, "POL", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
+ //二程POD杂费成本
|
|
|
+ routeCostItem.setPodCostTwo(computationalCost(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
+ //二程POD杂费收入
|
|
|
+ routeCostItem.setPodIncomeTwo(computationalIncome(costFeeList, "POD", routeCostItem.getBoxType(), routeCostItem.getExrate(), "1"));
|
|
|
+ // 二程成本价 = 二程海运费+二程pol杂费+二程pod成本
|
|
|
+ routeCostItem.setCostPriceTwo(routeCostItem.getOceanFreightTwo().add(routeCostItem.getPodCostTwo()).add(routeCostItem.getPolCostTwo()));
|
|
|
+ //二程合计利润
|
|
|
+ routeCostItem.setTotalProfitTwo(routeCostItem.getSalesPriceTwo().add(routeCostItem.getPolIncomeTwo())
|
|
|
+ .add(routeCostItem.getPodIncomeTwo()).subtract(routeCostItem.getCostPriceTwo()));
|
|
|
+ }
|
|
|
+ routeCostItem.setTotalProfitTwo(routeCostItem.getTotalProfitTwo() != null ? routeCostItem.getTotalProfitTwo() : new BigDecimal("0.00"));
|
|
|
+ //合计利润
|
|
|
+ routeCostItem.setProfit(routeCostItem.getTotalProfit().add(routeCostItem.getTotalProfitTwo()));
|
|
|
+ costItemListNew.add(routeCostItem);
|
|
|
}
|
|
|
+ item.setProfit20(totalProfit(item.getCostItemList(), "20"));
|
|
|
+ item.setProfit40(totalProfit(item.getCostItemList(), "40"));
|
|
|
+ item.setProfitHc(totalProfit(item.getCostItemList(), "40HC"));
|
|
|
+ item.setOtherProfit(totalProfit(item.getCostItemList(), "other"));
|
|
|
+ item.setTotalProfit(item.getProfit20().add(item.getProfit40()).add(item.getProfitHc()).add(item.getOtherProfit()));
|
|
|
}
|
|
|
- item.setProfit20(totalProfit(item.getCostItemList(), "20"));
|
|
|
- item.setProfit40(totalProfit(item.getCostItemList(), "40"));
|
|
|
- item.setProfitHc(totalProfit(item.getCostItemList(), "40HC"));
|
|
|
- item.setOtherProfit(totalProfit(item.getCostItemList(), "other"));
|
|
|
- item.setTotalProfit(item.getProfit20().add(item.getProfit40()).add(item.getProfitHc()).add(item.getOtherProfit()));
|
|
|
+ }
|
|
|
+ if (!costFeesListNew.isEmpty()){
|
|
|
+ routeCostFeeService.saveBatch(costFeesListNew);
|
|
|
+ }
|
|
|
+ if (!costItemListNew.isEmpty()){
|
|
|
+ routeCostItemService.saveBatch(costItemListNew);
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+ return R.success("操作成功");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1108,7 +1146,7 @@ public class RouteCostServiceImpl extends ServiceImpl<RouteCostMapper, RouteCost
|
|
|
*/
|
|
|
public BigDecimal computationalCost(List<RouteCostFee> routeCostFeeList, String type, String boxType, BigDecimal exrate, String srcType) {
|
|
|
BigDecimal amount = new BigDecimal("0.00");
|
|
|
- if (!routeCostFeeList.isEmpty()) {
|
|
|
+ if (ObjectUtils.isNotNull(routeCostFeeList)&&!routeCostFeeList.isEmpty()) {
|
|
|
amount = routeCostFeeList.stream().filter(e -> boxType.equals(e.getBoxType())
|
|
|
&& type.equals(e.getBusType()) && srcType.equals(e.getSrcType())).reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getExrate().multiply(y.getCostPrice())), BigDecimal::add);
|
|
|
if (new BigDecimal("0.00").compareTo(amount) != 0) {
|
|
|
@@ -1130,7 +1168,7 @@ public class RouteCostServiceImpl extends ServiceImpl<RouteCostMapper, RouteCost
|
|
|
*/
|
|
|
public BigDecimal computationalIncome(List<RouteCostFee> routeCostFeeList, String type, String boxType, BigDecimal exrate, String srcType) {
|
|
|
BigDecimal amount = new BigDecimal("0.00");
|
|
|
- if (!routeCostFeeList.isEmpty()) {
|
|
|
+ if (ObjectUtils.isNotNull(routeCostFeeList)&&!routeCostFeeList.isEmpty()) {
|
|
|
amount = routeCostFeeList.stream().filter(e -> boxType.equals(e.getBoxType())
|
|
|
&& type.equals(e.getBusType()) && srcType.equals(e.getSrcType())).reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getExrate().multiply(y.getSalesPrice())), BigDecimal::add);
|
|
|
if (new BigDecimal("0.00").compareTo(amount) != 0) {
|
|
|
@@ -1150,7 +1188,7 @@ public class RouteCostServiceImpl extends ServiceImpl<RouteCostMapper, RouteCost
|
|
|
*/
|
|
|
public BigDecimal totalProfit(List<RouteCostItem> routeCostItemList, String type) {
|
|
|
BigDecimal profit;
|
|
|
- if (!routeCostItemList.isEmpty()) {
|
|
|
+ if (ObjectUtils.isNotNull(routeCostItemList)&&!routeCostItemList.isEmpty()) {
|
|
|
if ("20".equals(type)) {
|
|
|
profit = routeCostItemList.stream().filter(e -> ObjectUtils.isNotNull(e.getBoxType()) && e.getBoxType().contains("20"))
|
|
|
.map(RouteCostItem::getProfit).reduce(BigDecimal.ZERO, BigDecimal::add);
|