|
|
@@ -40,9 +40,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.time.Period;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -129,17 +129,15 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public TradingBox add(TradingBox tradingBox) {
|
|
|
List<TradingBox> tradingBoxList = new ArrayList<>();
|
|
|
- if (ObjectUtils.isNotNull(tradingBox.getContractNo())) {
|
|
|
- LambdaQueryWrapper<TradingBox> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lambdaQueryWrapper.eq(TradingBox::getIsDeleted, 0)
|
|
|
- .eq(TradingBox::getTenantId, AuthUtil.getTenantId());
|
|
|
- if ("OW-N,OW-F".contains(tradingBox.getType())) {
|
|
|
- lambdaQueryWrapper.eq(TradingBox::getContainerNumber, tradingBox.getContainerNumber());
|
|
|
- } else {
|
|
|
- lambdaQueryWrapper.eq(TradingBox::getContractNo, tradingBox.getContractNo());
|
|
|
- }
|
|
|
- tradingBoxList = baseMapper.selectList(lambdaQueryWrapper);
|
|
|
+ LambdaQueryWrapper<TradingBox> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(TradingBox::getIsDeleted, 0)
|
|
|
+ .eq(TradingBox::getTenantId, AuthUtil.getTenantId());
|
|
|
+ if ("OW-N,OW-F".contains(tradingBox.getType())) {
|
|
|
+ lambdaQueryWrapper.eq(TradingBox::getContainerNumber, tradingBox.getContainerNumber());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(TradingBox::getContractNo, tradingBox.getContractNo());
|
|
|
}
|
|
|
+ tradingBoxList = baseMapper.selectList(lambdaQueryWrapper);
|
|
|
if (ObjectUtils.isNotNull(tradingBox.getActualBoxNumber())) {
|
|
|
tradingBox.setActualBoxNumber(0);
|
|
|
}
|
|
|
@@ -229,7 +227,7 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
//判断id是否为空
|
|
|
if (tradingBox.getId() == null) {
|
|
|
if (!tradingBoxList.isEmpty()) {
|
|
|
- throw new Error(text);
|
|
|
+ throw new RuntimeException(text);
|
|
|
}
|
|
|
BusinessBillNo businessBillNo = new BusinessBillNo();
|
|
|
businessBillNo.setBusinessTypeId(businessType.getId());
|
|
|
@@ -272,14 +270,16 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
.map(TradingBoxItem::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
BigDecimal amountUsd = tradingBox.getTradingBoxItemsList().stream().filter(e -> "USD".equals(e.getCurrency()))
|
|
|
.map(TradingBoxItem::getAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if ("BUY".equals(tradingBox.getType()) || "ZR".equals(tradingBox.getType()) || "DL".equals(tradingBox.getType())) {
|
|
|
- tradingBox.setAmountC(amount);
|
|
|
- tradingBox.setAmountCUsd(amountUsd);
|
|
|
- tradingBox.setTotalAmountC(amount.add(amountUsd.multiply(exrateC)));
|
|
|
- } else if ("SELL".equals(tradingBox.getType()) || "ZC".equals(tradingBox.getType())) {
|
|
|
- tradingBox.setAmountD(amount);
|
|
|
- tradingBox.setAmountDUsd(amountUsd);
|
|
|
- tradingBox.setTotalAmountD(amount.add(amountUsd.multiply(exrateD)));
|
|
|
+ if (!"ZR".equals(tradingBox.getType())) {
|
|
|
+ if ("BUY".equals(tradingBox.getType()) || "DL".equals(tradingBox.getType())) {
|
|
|
+ tradingBox.setAmountC(amount);
|
|
|
+ tradingBox.setAmountCUsd(amountUsd);
|
|
|
+ tradingBox.setTotalAmountC(amount.add(amountUsd.multiply(exrateC)));
|
|
|
+ } else if ("SELL".equals(tradingBox.getType()) || "ZC".equals(tradingBox.getType())) {
|
|
|
+ tradingBox.setAmountD(amount);
|
|
|
+ tradingBox.setAmountDUsd(amountUsd);
|
|
|
+ tradingBox.setTotalAmountD(amount.add(amountUsd.multiply(exrateD)));
|
|
|
+ }
|
|
|
}
|
|
|
//箱号拼接字符串
|
|
|
List<String> codes = tradingBox.getTradingBoxItemsList().stream().map(TradingBoxItem::getCode).distinct().collect(Collectors.toList());
|
|
|
@@ -340,7 +340,6 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
tradingBoxItemService.saveOrUpdateBatch(tradingBox.getTradingBoxItemsList());
|
|
|
tradingBox.setCode(String.join(",", codes));
|
|
|
tradingBox.setTradingBoxItemsList(tradingBox.getTradingBoxItemsList());
|
|
|
- baseMapper.updateById(tradingBox);
|
|
|
}
|
|
|
//费用数据
|
|
|
if (ObjectUtils.isNotNull(tradingBox.getFeeCenterList()) && !tradingBox.getFeeCenterList().isEmpty()) {
|
|
|
@@ -386,18 +385,19 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
item.setUpdateTime(new Date());
|
|
|
}
|
|
|
}
|
|
|
- tradingBox.setAmountC(tradingBox.getAmountC().add(amountC));
|
|
|
- tradingBox.setAmountCUsd(tradingBox.getAmountCUsd().add(amountCUsd));
|
|
|
- tradingBox.setAmountD(tradingBox.getAmountD().add(amountD));
|
|
|
- tradingBox.setAmountDUsd(tradingBox.getAmountDUsd().add(amountDUsd));
|
|
|
- tradingBox.setProfit(amountD.subtract(amountC));
|
|
|
- tradingBox.setProfitUsd(amountDUsd.subtract(amountCUsd));
|
|
|
- BigDecimal totalAmountD = amountD.add(amountDUsd.multiply(exrateD));
|
|
|
- tradingBox.setTotalAmountD(tradingBox.getTotalAmountD().add(totalAmountD));
|
|
|
- BigDecimal totalAmountC = amountC.add(amountCUsd.multiply(exrateC));
|
|
|
- tradingBox.setTotalAmountC(tradingBox.getTotalAmountC().add(totalAmountC));
|
|
|
- tradingBox.setTotalProfit(totalAmountD.subtract(totalAmountC));
|
|
|
- baseMapper.updateById(tradingBox);
|
|
|
+ if (!"ZR".equals(tradingBox.getType())) {
|
|
|
+ tradingBox.setAmountC(tradingBox.getAmountC().add(amountC));
|
|
|
+ tradingBox.setAmountCUsd(tradingBox.getAmountCUsd().add(amountCUsd));
|
|
|
+ tradingBox.setAmountD(tradingBox.getAmountD().add(amountD));
|
|
|
+ tradingBox.setAmountDUsd(tradingBox.getAmountDUsd().add(amountDUsd));
|
|
|
+ tradingBox.setProfit(amountD.subtract(amountC));
|
|
|
+ tradingBox.setProfitUsd(amountDUsd.subtract(amountCUsd));
|
|
|
+ BigDecimal totalAmountD = amountD.add(amountDUsd.multiply(exrateD));
|
|
|
+ tradingBox.setTotalAmountD(tradingBox.getTotalAmountD().add(totalAmountD));
|
|
|
+ BigDecimal totalAmountC = amountC.add(amountCUsd.multiply(exrateC));
|
|
|
+ tradingBox.setTotalAmountC(tradingBox.getTotalAmountC().add(totalAmountC));
|
|
|
+ tradingBox.setTotalProfit(totalAmountD.subtract(totalAmountC));
|
|
|
+ }
|
|
|
feeCenterService.saveOrUpdateBatch(tradingBox.getFeeCenterList());
|
|
|
}
|
|
|
//主表附件
|
|
|
@@ -466,7 +466,7 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
rentTermService.saveOrUpdateBatch(rentTermList);
|
|
|
tradingBox.setRentTermList(rentTermList);
|
|
|
}
|
|
|
-
|
|
|
+ baseMapper.updateById(tradingBox);
|
|
|
return tradingBox;
|
|
|
}
|
|
|
|
|
|
@@ -505,19 +505,19 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
throw new RuntimeException("未查到单据");
|
|
|
}
|
|
|
if ("1".equals(tradingBox.getRentType())) {
|
|
|
- tradingBox.setBuxStaus("已启租");
|
|
|
- tradingBox.setRentEndDate(tradingBox.getRentDate());
|
|
|
- tradingBox.setPurchaseDate(tradingBox.getRentDate());
|
|
|
+ detail.setBuxStaus("已启租");
|
|
|
+ detail.setRentEndDate(tradingBox.getRentDate());
|
|
|
+ detail.setPurchaseDate(tradingBox.getRentDate());
|
|
|
for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
ArchivesTrajectory archivesTrajectory = new ArchivesTrajectory();
|
|
|
archivesTrajectory.setPortId(tradingBox.getAddressId());
|
|
|
archivesTrajectory.setPortCode(tradingBox.getAddressCode());
|
|
|
archivesTrajectory.setPortCname(tradingBox.getAddressCname());
|
|
|
archivesTrajectory.setPortEname(tradingBox.getAddressEname());
|
|
|
- archivesTrajectory.setStationId(tradingBox.getAddressId());
|
|
|
- archivesTrajectory.setStationCode(tradingBox.getAddressCode());
|
|
|
- archivesTrajectory.setStationCname(tradingBox.getAddressCname());
|
|
|
- archivesTrajectory.setStationEname(tradingBox.getAddressEname());
|
|
|
+ archivesTrajectory.setStationId(tradingBox.getStationId());
|
|
|
+ archivesTrajectory.setStationCode(tradingBox.getStationCode());
|
|
|
+ archivesTrajectory.setStationCname(tradingBox.getStationCname());
|
|
|
+ archivesTrajectory.setStationEname(tradingBox.getStationEname());
|
|
|
archivesTrajectory.setContainerNumber(tradingBoxItem.getContainerNumber());
|
|
|
archivesTrajectory.setBoxType(tradingBoxItem.getBoxType());
|
|
|
archivesTrajectory.setBoxCategory(tradingBoxItem.getBoxCategory());
|
|
|
@@ -649,7 +649,7 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
feeCenterList.add(feeCenter);
|
|
|
}
|
|
|
} else {
|
|
|
- tradingBox.setBuxStaus("已退租");
|
|
|
+ detail.setBuxStaus("已退租");
|
|
|
BFees fees = bFeesService.getOne(new LambdaQueryWrapper<BFees>()
|
|
|
.eq(BFees::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(BFees::getIsDeleted, 0)
|
|
|
@@ -683,14 +683,14 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
Instant instant2 = tradingBox.getRentDate().toInstant();
|
|
|
LocalDate date1 = instant1.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
LocalDate date2 = instant2.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- Period period = Period.between(date1, date2);
|
|
|
+ Duration duration = Duration.between(date1.atStartOfDay(), date2.atStartOfDay());
|
|
|
if (ObjectUtils.isNotNull(tradingBox.getRentEndDate())) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(tradingBox.getRentEndDate());
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
feeCenter.setStorageDate(calendar.getTime());
|
|
|
}
|
|
|
- feeCenter.setDays(period.getDays());
|
|
|
+ feeCenter.setDays(Integer.parseInt(duration.toDays() + ""));
|
|
|
feeCenter.setPrice(item.getPrice());
|
|
|
feeCenter.setQuantity(new BigDecimal(tradingBoxItems.size() + ""));
|
|
|
if ("CNY".equals(feeCenter.getCurCode())) {
|
|
|
@@ -783,8 +783,8 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- tradingBox.setRentEndDate(tradingBox.getRentDate());
|
|
|
- tradingBox.setRentingOutDate(tradingBox.getRentDate());
|
|
|
+ detail.setRentEndDate(tradingBox.getRentDate());
|
|
|
+ detail.setRentingOutDate(tradingBox.getRentDate());
|
|
|
}
|
|
|
if (!itemList.isEmpty()) {
|
|
|
tradingBoxItemService.updateBatchById(itemList);
|
|
|
@@ -798,7 +798,7 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
if (!feeCenterList.isEmpty()) {
|
|
|
feeCenterService.saveOrUpdateBatch(feeCenterList);
|
|
|
}
|
|
|
- baseMapper.updateById(tradingBox);
|
|
|
+ baseMapper.updateById(detail);
|
|
|
tradingBox.setTradingBoxItemsList(tradingBoxItemList);
|
|
|
return tradingBox;
|
|
|
}
|
|
|
@@ -850,17 +850,17 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
Instant instant2 = tradingBox.getRentDate().toInstant();
|
|
|
LocalDate date1 = instant1.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
LocalDate date2 = instant2.atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- Period period = Period.between(date1, date2);
|
|
|
+ Duration duration = Duration.between(date1.atStartOfDay(), date2.atStartOfDay());
|
|
|
if (ObjectUtils.isNotNull(tradingBox.getRentEndDate()) &&
|
|
|
tradingBoxItems.get(0).getLeaseCommencementDate().compareTo(tradingBox.getRentEndDate()) != 0) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(tradingBox.getRentEndDate());
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
feeCenter.setStorageDate(calendar.getTime());
|
|
|
- feeCenter.setDays(period.getDays());
|
|
|
+ feeCenter.setDays(Integer.parseInt(duration.toDays() + ""));
|
|
|
} else {
|
|
|
feeCenter.setStorageDate(tradingBox.getRentEndDate());
|
|
|
- feeCenter.setDays(period.getDays() + 1);
|
|
|
+ feeCenter.setDays(Integer.parseInt(duration.toDays() + "") + 1);
|
|
|
}
|
|
|
feeCenter.setPrice(item.getPrice());
|
|
|
feeCenter.setQuantity(new BigDecimal(tradingBoxItems.size() + ""));
|
|
|
@@ -1006,6 +1006,8 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
details.setBoxNumber(0);
|
|
|
details.setActualBoxNumber(0);
|
|
|
details.setRemainingBoxNumber(0);
|
|
|
+ details.setRentEndDate(null);
|
|
|
+ details.setPurchaseDate(null);
|
|
|
return details;
|
|
|
}
|
|
|
|
|
|
@@ -1444,6 +1446,8 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
putBox.setBoxEastId(tradingBox.getPurchaseCompanyId() + "");
|
|
|
putBox.setBoxEastName(tradingBox.getPurchaseCompanyName());
|
|
|
putBox.setContainerNumber(detail.getContainerNumber());
|
|
|
+ putBox.setBoxBelongsTo("SOC");
|
|
|
+ putBox.setCabinType("非固定");
|
|
|
if ("OW-N".equals(tradingBox.getType())) {
|
|
|
putBox.setBusType("OW(拿)");
|
|
|
putBox.setBoxClass("OW(拿)");
|
|
|
@@ -1613,8 +1617,8 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
archives1.setContainerNumber(detail.getContainerNumber());
|
|
|
archives1.setBoxBelongsTo(item.getBoxBelongsTo());
|
|
|
archives1.setBoxType(item.getBoxCategory());
|
|
|
- archives1.setBoxEastId(tradingBox.getPurchaseCompanyId());
|
|
|
- archives1.setBoxEastName(tradingBox.getPurchaseCompanyName());
|
|
|
+ archives1.setBoxEastId(item.getBoxEastId());
|
|
|
+ archives1.setBoxEastName(item.getBoxEastName());
|
|
|
archives1.setOriginalBoxEastId(item.getOriginalBoxEastId());
|
|
|
archives1.setOriginalBoxEastName(item.getOriginalBoxEastName());
|
|
|
archives1.setRestrictedPortsIds(item.getRestrictedPortsIds());
|
|
|
@@ -1674,10 +1678,10 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
archivesTrajectory.setPortCode(tradingBox.getAddressCode());
|
|
|
archivesTrajectory.setPortCname(tradingBox.getAddressCname());
|
|
|
archivesTrajectory.setPortEname(tradingBox.getAddressEname());
|
|
|
- archivesTrajectory.setStationId(tradingBox.getAddressId());
|
|
|
- archivesTrajectory.setStationCode(tradingBox.getAddressCode());
|
|
|
- archivesTrajectory.setStationCname(tradingBox.getAddressCname());
|
|
|
- archivesTrajectory.setStationEname(tradingBox.getAddressEname());
|
|
|
+ archivesTrajectory.setStationId(tradingBox.getStationId());
|
|
|
+ archivesTrajectory.setStationCode(tradingBox.getStationCode());
|
|
|
+ archivesTrajectory.setStationCname(tradingBox.getStationCname());
|
|
|
+ archivesTrajectory.setStationEname(tradingBox.getStationEname());
|
|
|
archivesTrajectory.setContainerNumber(item.getContainerNumber());
|
|
|
archivesTrajectory.setBoxType(item.getBoxType());
|
|
|
archivesTrajectory.setBoxCategory(item.getBoxCategory());
|