|
|
@@ -26,13 +26,16 @@ import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.los.Util.IDeptUtils;
|
|
|
+import org.springblade.los.basic.cur.entity.BCurExrate;
|
|
|
+import org.springblade.los.basic.cur.mapper.CurExrateMapper;
|
|
|
import org.springblade.los.basic.fees.entity.BFees;
|
|
|
import org.springblade.los.basic.fees.service.IBFeesService;
|
|
|
import org.springblade.los.business.sea.entity.Bills;
|
|
|
+import org.springblade.los.business.sea.entity.PreContainers;
|
|
|
import org.springblade.los.business.sea.mapper.BillsMapper;
|
|
|
+import org.springblade.los.business.sea.mapper.PreContainersMapper;
|
|
|
import org.springblade.los.finance.fee.entity.FeeCenter;
|
|
|
import org.springblade.los.finance.fee.mapper.FeeCenterMapper;
|
|
|
-import org.springblade.los.finance.fee.service.IFeeCenterService;
|
|
|
import org.springblade.los.trade.entity.AgentItems;
|
|
|
import org.springblade.los.trade.entity.InOutStorage;
|
|
|
import org.springblade.los.trade.entity.StorageFee;
|
|
|
@@ -49,9 +52,13 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 贸易代理-出入库明细表 服务实现类
|
|
|
@@ -79,6 +86,10 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
|
|
|
private final FeeCenterMapper feeCenterMapper;
|
|
|
|
|
|
+ private final PreContainersMapper preContainersMapper;
|
|
|
+
|
|
|
+ private final CurExrateMapper curExrateMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<InOutStorageVO> selectInOutStoragePage(IPage<InOutStorageVO> page, InOutStorageVO inOutStorage) {
|
|
|
return page.setRecords(baseMapper.selectInOutStoragePage(page, inOutStorage));
|
|
|
@@ -95,21 +106,121 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
if ("RK".equals(inOutStorage.getBillType())) {
|
|
|
Bills bills = billsMapper.selectById(inOutStorage.getPid());
|
|
|
if (ObjectUtils.isNotNull(bills.getMconsigneeCntyName())) {
|
|
|
+ List<FeeCenter> feeCenterList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .eq(FeeCenter::getPid, bills.getId())
|
|
|
+ .eq(FeeCenter::getDc, "C")
|
|
|
+ .apply("find_in_set(fee_code,'ZZS,GS')"));
|
|
|
+ if (feeCenterList.stream().noneMatch(e -> "GS".equals(e.getFeeCode()))) {
|
|
|
+ throw new RuntimeException("请先维护关税费用");
|
|
|
+ }
|
|
|
+ BigDecimal amountGS = feeCenterList.stream().filter(e -> "GS".equals(e.getFeeCode())).map(FeeCenter::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (feeCenterList.stream().noneMatch(e -> "ZZS".equals(e.getFeeCode()))) {
|
|
|
+ throw new RuntimeException("请先维护增值税费用");
|
|
|
+ }
|
|
|
+ BigDecimal amountZZS = feeCenterList.stream().filter(e -> "ZZS".equals(e.getFeeCode())).map(FeeCenter::getAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ List<FeeCenter> feeCenterTradeList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .eq(FeeCenter::getDc, "C")
|
|
|
+ .apply("find_in_set(fee_code,'SXF,YDF')")
|
|
|
+ .apply("find_in_set(" + bills.getMblno() + ",'mblno')"));
|
|
|
+ if (feeCenterTradeList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到提单号:" + bills.getMblno() + "对应贸易代理费用信息");
|
|
|
+ }
|
|
|
List<AgentItems> agentItemsList = agentItemsMapper.selectList(new LambdaQueryWrapper<AgentItems>()
|
|
|
- .apply("find_in_set(id,'" + bills.getMconsigneeCntyName() + "')")
|
|
|
+ .eq(AgentItems::getPid, feeCenterTradeList.get(0).getPid())
|
|
|
.eq(AgentItems::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(AgentItems::getIsDeleted, 0));
|
|
|
- for (AgentItems items : agentItemsList) {
|
|
|
- items.setUpdateTime(new Date());
|
|
|
- items.setUpdateUser(AuthUtil.getUserId());
|
|
|
- items.setUpdateUserName(AuthUtil.getUserName());
|
|
|
- items.setWhetherComplete("已入库");
|
|
|
- items.setDispatchDate(new Date());
|
|
|
- agentItemsMapper.updateById(items);
|
|
|
+ if (agentItemsList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到提单号:" + bills.getMblno() + "对应贸易代理明细信息");
|
|
|
+ }
|
|
|
+ if (feeCenterTradeList.stream().noneMatch(e -> "SXF".equals(e.getFeeCode()) && "1".equals(e.getFeeType()))) {
|
|
|
+ throw new RuntimeException("请先维护首款手续费用");
|
|
|
+ }
|
|
|
+ BigDecimal amountSkSxf = feeCenterTradeList.stream().filter(e -> "SXF".equals(e.getFeeCode()) && "1".equals(e.getFeeType()))
|
|
|
+ .map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (feeCenterTradeList.stream().noneMatch(e -> "SXF".equals(e.getFeeCode()) && "2".equals(e.getFeeType()))) {
|
|
|
+ throw new RuntimeException("请先维护尾款手续费用");
|
|
|
+ }
|
|
|
+ if (feeCenterTradeList.stream().noneMatch(e -> "YDF".equals(e.getFeeCode()) && "1".equals(e.getFeeType()))) {
|
|
|
+ throw new RuntimeException("请先维护首款邮电费用");
|
|
|
+ }
|
|
|
+ BigDecimal amountSkYdf = feeCenterTradeList.stream().filter(e -> "YDF".equals(e.getFeeCode()) && "1".equals(e.getFeeType()))
|
|
|
+ .map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (feeCenterTradeList.stream().noneMatch(e -> "YDF".equals(e.getFeeCode()) && "2".equals(e.getFeeType()))) {
|
|
|
+ throw new RuntimeException("请先维护尾款邮电费用");
|
|
|
+ }
|
|
|
+ long count = agentItemsList.stream().map(AgentItems::getBillNo).distinct().count();
|
|
|
+
|
|
|
+ //首款手续费平摊金额 = 手续费 ÷ 总提单数量
|
|
|
+ BigDecimal singleSkSxf = amountSkSxf.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
|
|
|
+ //首款邮电费平摊金额 = 邮电费 ÷ 总提单数量
|
|
|
+ BigDecimal singleSkYdf = amountSkYdf.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
|
|
|
+ //单个提单号尾款手续费金额 = 手续费 ÷ 提单数量
|
|
|
+ BigDecimal singleWkSxf = new BigDecimal("0.00");
|
|
|
+ //单个提单号尾款邮电费金额 = 邮电费 ÷ 提单数量
|
|
|
+ BigDecimal singleWkYdf = new BigDecimal("0.00");
|
|
|
+ for (FeeCenter item : feeCenterTradeList) {
|
|
|
+ if ("SXF".equals(item.getFeeCode()) && "2".equals(item.getFeeType())) {
|
|
|
+ String[] arr = item.getMblno().split(",");
|
|
|
+ singleWkSxf = singleWkSxf.add(item.getAmount().divide(new BigDecimal(arr.length), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ if ("YDF".equals(item.getFeeCode()) && "2".equals(item.getFeeType())) {
|
|
|
+ String[] arr = item.getMblno().split(",");
|
|
|
+ singleWkYdf = singleWkYdf.add(item.getAmount().divide(new BigDecimal(arr.length), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //总的分摊金额 = 关税 + 增值税 + 单个提单号手续费金额 + 单个提单号邮电费金额
|
|
|
+ BigDecimal sharedAmountSum = singleSkSxf.add(singleSkYdf).add(singleWkSxf).add(singleWkYdf).add(amountGS).add(amountZZS);
|
|
|
+ //箱的货值
|
|
|
+ BigDecimal amount = inOutStorage.getQuantity().multiply(inOutStorage.getPrice());
|
|
|
+ List<PreContainers> preContainersList = preContainersMapper.selectList(new LambdaQueryWrapper<PreContainers>()
|
|
|
+ .eq(PreContainers::getIsDeleted, 0)
|
|
|
+ .eq(PreContainers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PreContainers::getPid, bills.getId()));
|
|
|
+ //提单号的总货值
|
|
|
+ BigDecimal amountSum = preContainersList.stream().reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getNumber().multiply(y.getPrice())), BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ LocalDate localDate = bills.getEta().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ int year = localDate.getYear();
|
|
|
+ int month = localDate.getMonthValue();
|
|
|
+ int day = localDate.getDayOfMonth();
|
|
|
+ LambdaQueryWrapper<BCurExrate> lambdaQueryWrapper = new LambdaQueryWrapper<BCurExrate>()
|
|
|
+ .eq(BCurExrate::getCode, "USD")
|
|
|
+ .eq(BCurExrate::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCurExrate::getIsDeleted, 0)
|
|
|
+ .eq(BCurExrate::getExrateYear, year)
|
|
|
+ .eq(BCurExrate::getExrateMonth, month)
|
|
|
+ .eq(BCurExrate::getExrateDay, day)
|
|
|
+ .eq(BCurExrate::getType, "日汇率");
|
|
|
+ BCurExrate bCurExrate = curExrateMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (bCurExrate == null) {
|
|
|
+ throw new RuntimeException("未找到" + year + "年-" + month + "月-" + day + "日实付汇率");
|
|
|
+ }
|
|
|
+ //分摊比例 = 箱的货值 ÷ 提单号的总货值 * 汇率
|
|
|
+ BigDecimal sharingRatio = amount.divide(amountSum, 2, RoundingMode.HALF_UP).multiply(bCurExrate.getExratePayment());
|
|
|
+ //本次分摊金额 = 总的分摊金额 * 分摊比例 ÷ 件数
|
|
|
+ BigDecimal sharedAmount = sharedAmountSum.multiply(sharingRatio).divide(inOutStorage.getQuantity(), 2, RoundingMode.HALF_UP);
|
|
|
+ //仓储单价 = 单价 + 本次分摊金额
|
|
|
+ inOutStorage.setWarehouseUnitPrice(inOutStorage.getPrice().add(sharedAmount));
|
|
|
+ List<AgentItems> agentItems = agentItemsList.stream().filter(e -> bills.getMconsigneeCntyName().contains(e.getId() + ""))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!agentItems.isEmpty()) {
|
|
|
+ for (AgentItems items : agentItems) {
|
|
|
+ items.setUpdateTime(new Date());
|
|
|
+ items.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ items.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ items.setWhetherComplete("已入库");
|
|
|
+ items.setDispatchDate(new Date());
|
|
|
+ agentItemsMapper.updateById(items);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- if (ObjectUtils.isNotNull(inOutStorage.getOutStorageDate())){
|
|
|
+ if (ObjectUtils.isNotNull(inOutStorage.getOutStorageDate())) {
|
|
|
inOutStorage.setOutStorageDate(new Date());
|
|
|
}
|
|
|
InOutStorage inStorage = baseMapper.selectById(inOutStorage.getSrcId());
|
|
|
@@ -220,11 +331,11 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
feeCenter.setPrice(amount);
|
|
|
feeCenter.setAmount(amount);
|
|
|
feeCenter.setRemarks(remark.toString());
|
|
|
- feeCenter.setDays(Integer.parseInt(day+""));
|
|
|
+ feeCenter.setDays(Integer.parseInt(day + ""));
|
|
|
feeCenter.setStorageDate(inOutStorage.getOutStorageDate());
|
|
|
feeCenter.setOutboundDate(inStorage.getStorageDate());
|
|
|
feeCenterMapper.insert(feeCenter);
|
|
|
- inOutStorage.setStorageDays(Integer.parseInt(day+""));
|
|
|
+ inOutStorage.setStorageDays(Integer.parseInt(day + ""));
|
|
|
inOutStorage.setStorageFeesAmount(amount);
|
|
|
}
|
|
|
}
|