|
|
@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.box.tube.dto.TradingBoxItemRentExcelEnter;
|
|
|
import org.springblade.box.tube.entity.*;
|
|
|
import org.springblade.box.tube.mapper.*;
|
|
|
import org.springblade.box.tube.service.ITradingBoxService;
|
|
|
@@ -32,13 +33,8 @@ import org.springblade.check.dto.AuditProecessDTO;
|
|
|
import org.springblade.check.entity.AuditPathsActs;
|
|
|
import org.springblade.check.entity.AuditPathsLevels;
|
|
|
import org.springblade.check.feign.ICheckClient;
|
|
|
-import org.springblade.client.entity.CorpsDesc;
|
|
|
-import org.springblade.client.entity.FeesDesc;
|
|
|
-import org.springblade.client.entity.Message;
|
|
|
-import org.springblade.client.feign.ICorpsDescClient;
|
|
|
-import org.springblade.client.feign.IFeesDescClient;
|
|
|
-import org.springblade.client.feign.IMessageClient;
|
|
|
-import org.springblade.client.feign.ISerialClient;
|
|
|
+import org.springblade.client.entity.*;
|
|
|
+import org.springblade.client.feign.*;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
@@ -58,10 +54,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -102,6 +95,10 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
|
|
|
private final ArchivesFilesMapper archivesFilesMapper;
|
|
|
|
|
|
+ private final IContainerDescClient containerDescClient;
|
|
|
+
|
|
|
+ private final IPortClient portClient;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<TradingBoxVO> selectTradingBoxPage(IPage<TradingBoxVO> page, TradingBoxVO tradingBox) {
|
|
|
return page.setRecords(baseMapper.selectTradingBoxPage(page, tradingBox));
|
|
|
@@ -113,6 +110,14 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
throw new RuntimeException("缺少必要参数");
|
|
|
}
|
|
|
TradingBox details = baseMapper.selectById(tradingBox.getId());
|
|
|
+
|
|
|
+ Long feesId = null;
|
|
|
+
|
|
|
+ //获取费用id
|
|
|
+ R<FeesDesc> fees = feesDescClient.getFeesByName("租金");
|
|
|
+ if (fees.isSuccess() && fees.getData() != null) {
|
|
|
+ feesId = fees.getData().getId();
|
|
|
+ }
|
|
|
if (ObjectUtils.isNotNull(details)) {
|
|
|
//获取明细信息
|
|
|
LambdaQueryWrapper<TradingBoxItem> tradingBoxItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
@@ -121,6 +126,15 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
.eq(TradingBoxItem::getPid, details.getId());
|
|
|
List<TradingBoxItem> tradingBoxItemList = tradingBoxItemMapper.selectList(tradingBoxItemLambdaQueryWrapper);
|
|
|
for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ //获取费用信息
|
|
|
+ LambdaQueryWrapper<TradingBoxFees> tradingBoxFeesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.eq(TradingBoxFees::getIsDeleted, 0)
|
|
|
+ .eq(TradingBoxFees::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(TradingBoxFees::getCode, tradingBoxItem.getCode())
|
|
|
+ .eq(ObjectUtils.isNotNull(feesId), TradingBoxFees::getItemId, feesId)
|
|
|
+ .eq(TradingBoxFees::getPid, details.getId());
|
|
|
+ int count = tradingBoxFeesMapper.selectCount(tradingBoxFeesLambdaQueryWrapper);
|
|
|
+ tradingBoxItem.setCount(count);
|
|
|
//获取明细图片
|
|
|
LambdaQueryWrapper<TradingBoxFiles> tradingBoxFilesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
tradingBoxFilesLambdaQueryWrapper.eq(TradingBoxFiles::getIsDeleted, 0)
|
|
|
@@ -394,6 +408,12 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
List<TradingBoxItem> tradingBoxItemList = tradingBox.getTradingBoxItemsList();
|
|
|
if (ObjectUtils.isNotNull(tradingBoxItemList) && tradingBoxItemList.size() > 0) {
|
|
|
for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ if (tradingBox.getType().equals("ZR")) {
|
|
|
+ tradingBoxItem.setStatus("待使用");
|
|
|
+ tradingBoxItem.setBoxSource("租入");
|
|
|
+ } else if (tradingBox.getType().equals("ZC")) {
|
|
|
+ tradingBoxItem.setStatus("使用中");
|
|
|
+ }
|
|
|
if (tradingBoxItem.getId() == null) {
|
|
|
tradingBoxItem.setCreateUser(AuthUtil.getUserId());
|
|
|
tradingBoxItem.setCreateTime(new Date());
|
|
|
@@ -794,17 +814,33 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
public TradingBox startingRent(TradingBox tradingBox) {
|
|
|
- if ("1".equals(tradingBox.getRentType())) {
|
|
|
- List<TradingBoxItem> tradingBoxItemList = tradingBox.getTradingBoxItemsList();
|
|
|
- if (tradingBoxItemList.size() < 1) {
|
|
|
- throw new RuntimeException("明细不能为空");
|
|
|
- }
|
|
|
- for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ List<TradingBoxItem> tradingBoxItemList = tradingBox.getTradingBoxItemsList();
|
|
|
+ if (tradingBoxItemList.size() < 1) {
|
|
|
+ throw new RuntimeException("明细不能为空");
|
|
|
+ }
|
|
|
+ Long pid = tradingBox.getId();
|
|
|
+
|
|
|
+ //账单数据
|
|
|
+ ApplyDTO applyDTO = new ApplyDTO();
|
|
|
+ if ("ZR".equals(tradingBox.getType())) {
|
|
|
+ applyDTO.setBillType("申请");
|
|
|
+ } else {
|
|
|
+ applyDTO.setBillType("收费");
|
|
|
+ }
|
|
|
+ applyDTO.setTradeType("BOX");
|
|
|
+ applyDTO.setBelongCompany(tradingBox.getPurchaseCompanyName());
|
|
|
+ //账单明细
|
|
|
+ List<Items> itemsList = new ArrayList<>();
|
|
|
+ List<TradingBoxFees> tradingBoxFeesList = new ArrayList<>();
|
|
|
+ for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ ArchivesTrajectory archivesTrajectory = new ArchivesTrajectory();
|
|
|
+ tradingBoxItem.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxItem.setUpdateTime(new Date());
|
|
|
+ tradingBoxItem.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ if ("1".equals(tradingBox.getRentType())) {
|
|
|
tradingBoxItem.setLeaseCommencementDate(tradingBox.getRentDate());
|
|
|
- tradingBoxItem.setUpdateUser(AuthUtil.getUserId());
|
|
|
- tradingBoxItem.setUpdateTime(new Date());
|
|
|
- tradingBoxItem.setUpdateUserName(AuthUtil.getUserName());
|
|
|
- tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+ tradingBoxItem.setBoxStatus("租入");
|
|
|
+ tradingBoxItem.setStatus("待使用");
|
|
|
if (ObjectUtils.isNotNull(tradingBoxItem.getCode())) {
|
|
|
//更新箱档案信息
|
|
|
Archives archivesR = archivesMapper.selectOne(new LambdaQueryWrapper<Archives>().eq(Archives::getIsDeleted, 0).eq(Archives::getTenantId, AuthUtil.getTenantId()).eq(Archives::getCode, tradingBoxItem.getCode()));
|
|
|
@@ -812,8 +848,7 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
if (ObjectUtils.isNotNull(archivesR)) {
|
|
|
BeanUtil.copy(archivesR, archives);
|
|
|
}
|
|
|
-
|
|
|
- if (tradingBox.getType().equals("ZR")){
|
|
|
+ if (tradingBox.getType().equals("ZR")) {
|
|
|
archives.setCode(tradingBoxItem.getCode());
|
|
|
archives.setName(tradingBoxItem.getBoxType());
|
|
|
archives.setVolume(tradingBoxItem.getVolume());
|
|
|
@@ -833,8 +868,9 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
archives.setBoxAge(tradingBoxItem.getBoxAge());
|
|
|
archives.setPurchaseDate(tradingBox.getPurchaseDate());
|
|
|
archives.setContractNo(tradingBox.getContractNo());
|
|
|
+ archives.setBoxAccessStatus("空箱入场");
|
|
|
archives.setBoxSource("租入");
|
|
|
- archives.setBoxStatus("待使用");
|
|
|
+ archives.setStatus("待使用");
|
|
|
archives.setLeasingCompanyId(tradingBox.getPurchaseCompanyId());
|
|
|
archives.setLeasingCompany(tradingBox.getPurchaseCompanyName());
|
|
|
if (ObjectUtils.isNotNull(archivesR)) {
|
|
|
@@ -842,7 +878,6 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
archives.setUpdateUserName(AuthUtil.getUserName());
|
|
|
archives.setUpdateUser(AuthUtil.getUserId());
|
|
|
archivesMapper.updateById(archives);
|
|
|
-
|
|
|
} else {
|
|
|
archives.setBoxSource(tradingBoxItem.getBoxSource());
|
|
|
archives.setBoxStatus(tradingBoxItem.getBoxStatus());
|
|
|
@@ -862,39 +897,475 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
archivesFilesMapper.insert(archivesFiles);
|
|
|
}
|
|
|
}
|
|
|
- }else{
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //记录箱轨迹信息
|
|
|
- ArchivesTrajectory archivesTrajectory = new ArchivesTrajectory();
|
|
|
- if ("ZR".equals(tradingBox.getType())) {
|
|
|
archivesTrajectory.setStatus("租入");
|
|
|
- } else if ("ZC".equals(tradingBox.getType())) {
|
|
|
+ } else {
|
|
|
+ archives.setBoxAccessStatus("空箱离场");
|
|
|
+ archives.setStatus("使用");
|
|
|
+ archives.setLeasingCompanyId(tradingBox.getPurchaseCompanyId());
|
|
|
+ archives.setLeasingCompany(tradingBox.getPurchaseCompanyName());
|
|
|
+ archives.setUpdateTime(new Date());
|
|
|
+ archives.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ archives.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ archivesMapper.updateById(archives);
|
|
|
archivesTrajectory.setStatus("租出");
|
|
|
}
|
|
|
- archivesTrajectory.setContractNo(tradingBox.getContractNo());
|
|
|
- archivesTrajectory.setBillType(tradingBox.getType());
|
|
|
- archivesTrajectory.setCode(tradingBoxItem.getCode());
|
|
|
- archivesTrajectory.setAddress(tradingBoxItem.getAddress());
|
|
|
- archivesTrajectory.setNewDate(tradingBoxItem.getNewDate());
|
|
|
- archivesTrajectory.setCreateTime(new Date());
|
|
|
- archivesTrajectory.setCreateUser(AuthUtil.getUserId());
|
|
|
- archivesTrajectory.setCreateUserName(AuthUtil.getUserName());
|
|
|
- archivesTrajectory.setTenantId(AuthUtil.getTenantId());
|
|
|
- archivesTrajectoryMapper.insert(archivesTrajectory);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("箱号不能为空");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tradingBoxItem.setRentEndDate(tradingBox.getRentDate());
|
|
|
+ tradingBoxItem.setStatus("退租");
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItem.getCode())) {
|
|
|
+ //更新箱档案信息
|
|
|
+ Archives archivesR = archivesMapper.selectOne(new LambdaQueryWrapper<Archives>().eq(Archives::getIsDeleted, 0).eq(Archives::getTenantId, AuthUtil.getTenantId()).eq(Archives::getCode, tradingBoxItem.getCode()));
|
|
|
+ if (ObjectUtils.isNull(archivesR)) {
|
|
|
+ throw new RuntimeException("未查到箱信息");
|
|
|
+ }
|
|
|
+ if (tradingBox.getType().equals("ZR")) {
|
|
|
+ archivesR.setStatus("退租");
|
|
|
+ archivesR.setBoxAccessStatus("空箱离场");
|
|
|
+ archivesR.setUpdateTime(new Date());
|
|
|
+ archivesR.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ archivesR.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ archivesR.setAddress(tradingBoxItem.getAddress());
|
|
|
+ archivesR.setAddressId(tradingBoxItem.getAddressId());
|
|
|
+ archivesMapper.updateById(archivesR);
|
|
|
+ } else {
|
|
|
+ archivesR.setBoxAccessStatus("空箱入场");
|
|
|
+ archivesR.setStatus("待使用");
|
|
|
+ archivesR.setUpdateTime(new Date());
|
|
|
+ archivesR.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ archivesR.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ archivesR.setAddress(tradingBoxItem.getAddress());
|
|
|
+ archivesR.setAddressId(tradingBoxItem.getAddressId());
|
|
|
+ archivesMapper.updateById(archivesR);
|
|
|
+ }
|
|
|
+ archivesTrajectory.setStatus("退租");
|
|
|
} else {
|
|
|
throw new RuntimeException("箱号不能为空");
|
|
|
}
|
|
|
|
|
|
+ int days = 0;
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItem.getRentEndDate()) && ObjectUtils.isNotNull(tradingBox.getRentDate())) {
|
|
|
+ days = (int) ((tradingBox.getRentDate().getTime() - tradingBoxItem.getRentEndDate().getTime()) / (1000 * 3600 * 24)) + 1;
|
|
|
+ }
|
|
|
+ tradingBoxItem.setPrice(tradingBoxItem.getPrice() == null ? new BigDecimal(0) : tradingBoxItem.getPrice());
|
|
|
+ TradingBoxFees tradingBoxFees = new TradingBoxFees();
|
|
|
+ tradingBoxFees.setCorpId(tradingBox.getPurchaseCompanyId());
|
|
|
+ tradingBoxFees.setCorpName(tradingBox.getPurchaseCompanyName());
|
|
|
+ tradingBoxFees.setAmount(tradingBoxItem.getPrice().multiply(BigDecimal.valueOf(days)));
|
|
|
+ tradingBoxFees.setPrice(tradingBoxItem.getPrice());
|
|
|
+ tradingBoxFees.setQuantity(BigDecimal.valueOf(days));
|
|
|
+ tradingBoxFees.setCurrency(tradingBoxItem.getCurrency());
|
|
|
+ tradingBoxFees.setCode(tradingBoxItem.getCode());
|
|
|
+ //获取费用id
|
|
|
+ R<FeesDesc> fees = feesDescClient.getFeesByName("租金");
|
|
|
+ if (fees.isSuccess() && fees.getData() != null) {
|
|
|
+ tradingBoxFees.setItemId(fees.getData().getId());
|
|
|
+ }
|
|
|
+ if ("ZR".equals(tradingBox.getType())) {
|
|
|
+ tradingBoxFees.setFeesType(2);
|
|
|
+ } else {
|
|
|
+ tradingBoxFees.setFeesType(1);
|
|
|
+ }
|
|
|
+ tradingBoxFees.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFees.setSrcOrderNo(tradingBox.getContractNo());
|
|
|
+ tradingBoxFees.setUnit(tradingBoxItem.getBoxType());
|
|
|
+ tradingBoxFees.setExchangeRate(new BigDecimal(1));
|
|
|
+ tradingBoxFees.setRentStartDate(tradingBoxItem.getRentEndDate());
|
|
|
+ tradingBoxFees.setRentEndDate(tradingBox.getRentDate());
|
|
|
+ tradingBoxFees.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFees.setCreateTime(new Date());
|
|
|
+ tradingBoxFees.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBoxFees.setSubmitPay(1);
|
|
|
+ tradingBoxFeesMapper.insert(tradingBoxFees);
|
|
|
+ tradingBoxFeesList.add(tradingBoxFees);
|
|
|
+
|
|
|
+ Items items = new Items();
|
|
|
+ if (1 == tradingBoxFees.getFeesType()) {
|
|
|
+ items.setSrcFeesType("收费");
|
|
|
+ } else {
|
|
|
+ items.setSrcFeesType("付费");
|
|
|
+ }
|
|
|
+ items.setItemType(tradingBox.getType());
|
|
|
+ items.setPrice(tradingBoxFees.getPrice());
|
|
|
+ //账单数据
|
|
|
+ items.setAmount(tradingBoxFees.getAmount());
|
|
|
+ items.setQuantity(tradingBoxFees.getQuantity());
|
|
|
+ items.setSrcOrderno(tradingBox.getSysNo());
|
|
|
+ items.setCorpId(tradingBoxFees.getCorpId());
|
|
|
+ items.setSrcParentId(pid);
|
|
|
+ items.setCurrency(tradingBoxFees.getCurrency());
|
|
|
+ items.setSrcType(5);
|
|
|
+ items.setTradeType("BOX");
|
|
|
+ items.setUnit(tradingBoxFees.getUnit());
|
|
|
+ items.setSrcSysNo(tradingBoxFees.getCode());
|
|
|
+ items.setRemarks(tradingBoxFees.getRemarks());
|
|
|
+ items.setSrcBillNo(tradingBox.getContractNo());
|
|
|
+ items.setStatusJT(0);
|
|
|
+ items.setBillNo(tradingBox.getContractNo());
|
|
|
+ items.setStockTime(tradingBox.getPurchaseDate());
|
|
|
+ //获取费用id
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxFees.getItemId())) {
|
|
|
+ items.setCostType(tradingBoxFees.getItemId().toString());
|
|
|
+ }
|
|
|
+ items.setSrcFeesId(tradingBoxFees.getId());
|
|
|
+ itemsList.add(items);
|
|
|
+ applyDTO.setItemsList(itemsList);
|
|
|
}
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+ //记录箱轨迹信息
|
|
|
+ archivesTrajectory.setContractNo(tradingBox.getContractNo());
|
|
|
+ archivesTrajectory.setBillType(tradingBox.getType());
|
|
|
+ archivesTrajectory.setCode(tradingBoxItem.getCode());
|
|
|
+ archivesTrajectory.setCreateTime(new Date());
|
|
|
+ archivesTrajectory.setCreateUser(AuthUtil.getUserId());
|
|
|
+ archivesTrajectory.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ archivesTrajectory.setTenantId(AuthUtil.getTenantId());
|
|
|
+ archivesTrajectoryMapper.insert(archivesTrajectory);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(itemsList)) {
|
|
|
+ //生成账单
|
|
|
+ R paymentApply = financeClient.paymentApplyBoxTube(applyDTO);
|
|
|
+ if (!paymentApply.isSuccess()) {
|
|
|
+ throw new RuntimeException(paymentApply.getMsg());
|
|
|
+ }
|
|
|
+ //给角色为财务的人发送消息
|
|
|
+ R<String> clientDeptIds = sysClient.getRoleIds(SecureUtil.getTenantId(), "财务");
|
|
|
+ if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(Long.valueOf(clientDeptIds.getData()));
|
|
|
+ if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
+ for (User datum : userList.getData()) {
|
|
|
+ //循环发送消息
|
|
|
+ Message sendMessage = new Message();
|
|
|
+ sendMessage.setParameter(String.valueOf(pid));
|
|
|
+ sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
+ sendMessage.setUserId(AuthUtil.getUserId());
|
|
|
+ sendMessage.setToUserId(datum.getId());
|
|
|
+ sendMessage.setToUserName(datum.getName());
|
|
|
+ sendMessage.setMessageType(1);
|
|
|
+ sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setCreateUser(AuthUtil.getUserId());
|
|
|
+ sendMessage.setCreateTime(new Date());
|
|
|
+ sendMessage.setUrl(tradingBox.getUrl());
|
|
|
+ sendMessage.setPageLabel(tradingBox.getPageLabel());
|
|
|
+ sendMessage.setPageStatus(tradingBox.getPageStatus());
|
|
|
+ sendMessage.setMessageBody("您订单" + tradingBox.getSysNo() + "审核通过,请查看");
|
|
|
+ R save = messageClient.save(sendMessage);
|
|
|
+ if (!save.isSuccess()) {
|
|
|
+ throw new SecurityException("发送消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxItemsList(tradingBoxItemList);
|
|
|
+ return tradingBox;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public TradingBox rentCalculation(TradingBox tradingBox) {
|
|
|
+ List<TradingBoxItem> tradingBoxItemList = tradingBox.getTradingBoxItemsList();
|
|
|
+ if (tradingBoxItemList.size() < 1) {
|
|
|
+ throw new RuntimeException("明细不能为空");
|
|
|
+ }
|
|
|
+ int days = 0;
|
|
|
+ if (tradingBox.getRentCalculationDateList().size() > 0) {
|
|
|
+ days = (int) ((tradingBox.getRentCalculationDateList().get(1).getTime() - tradingBox.getRentCalculationDateList().get(0).getTime()) / (1000 * 3600 * 24)) + 1;
|
|
|
+ }
|
|
|
+ Long pid = tradingBox.getId();
|
|
|
+
|
|
|
+ //账单数据
|
|
|
+ ApplyDTO applyDTO = new ApplyDTO();
|
|
|
+ if ("ZR".equals(tradingBox.getType())) {
|
|
|
+ applyDTO.setBillType("申请");
|
|
|
} else {
|
|
|
+ applyDTO.setBillType("收费");
|
|
|
+ }
|
|
|
+ applyDTO.setTradeType("BOX");
|
|
|
+ applyDTO.setBelongCompany(tradingBox.getPurchaseCompanyName());
|
|
|
+ //账单明细
|
|
|
+ List<Items> itemsList = new ArrayList<>();
|
|
|
+ List<TradingBoxFees> tradingBoxFeesList = new ArrayList<>();
|
|
|
+ for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ TradingBoxFees tradingBoxFees = new TradingBoxFees();
|
|
|
+ tradingBoxFees.setCorpId(tradingBox.getPurchaseCompanyId());
|
|
|
+ tradingBoxFees.setCorpName(tradingBox.getPurchaseCompanyName());
|
|
|
+ tradingBoxFees.setAmount(tradingBoxItem.getPrice().multiply(BigDecimal.valueOf(days)));
|
|
|
+ tradingBoxFees.setPrice(tradingBoxItem.getPrice());
|
|
|
+ tradingBoxFees.setQuantity(BigDecimal.valueOf(days));
|
|
|
+ tradingBoxFees.setCurrency(tradingBoxItem.getCurrency());
|
|
|
+ tradingBoxFees.setCode(tradingBoxItem.getCode());
|
|
|
+ //获取费用id
|
|
|
+ R<FeesDesc> fees = feesDescClient.getFeesByName("租金");
|
|
|
+ if (fees.isSuccess() && fees.getData() != null) {
|
|
|
+ tradingBoxFees.setItemId(fees.getData().getId());
|
|
|
+ }
|
|
|
+ if ("ZR".equals(tradingBox.getType())) {
|
|
|
+ tradingBoxFees.setFeesType(2);
|
|
|
+ } else {
|
|
|
+ tradingBoxFees.setFeesType(1);
|
|
|
+ }
|
|
|
+ tradingBoxFees.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFees.setSrcOrderNo(tradingBox.getContractNo());
|
|
|
+ tradingBoxFees.setUnit(tradingBoxItem.getBoxType());
|
|
|
+ tradingBoxFees.setExchangeRate(new BigDecimal(1));
|
|
|
+ tradingBoxFees.setRentStartDate(tradingBox.getRentCalculationDateList().get(0));
|
|
|
+ tradingBoxFees.setRentEndDate(tradingBox.getRentCalculationDateList().get(1));
|
|
|
+ tradingBoxFees.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFees.setCreateTime(new Date());
|
|
|
+ tradingBoxFees.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBoxFees.setSubmitPay(1);
|
|
|
+ tradingBoxFeesMapper.insert(tradingBoxFees);
|
|
|
+ tradingBoxFeesList.add(tradingBoxFees);
|
|
|
+ tradingBoxItem.setAmount(tradingBoxItem.getPrice().multiply(BigDecimal.valueOf(days)));
|
|
|
+ tradingBoxItem.setUpdateTime(new Date());
|
|
|
+ tradingBoxItem.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxItem.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ tradingBoxItem.setRentEndDate(tradingBox.getRentCalculationDateList().get(1));
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+
|
|
|
+ Items items = new Items();
|
|
|
+ if (1 == tradingBoxFees.getFeesType()) {
|
|
|
+ items.setSrcFeesType("收费");
|
|
|
+ } else {
|
|
|
+ items.setSrcFeesType("付费");
|
|
|
+ }
|
|
|
+ items.setItemType(tradingBox.getType());
|
|
|
+ items.setPrice(tradingBoxFees.getPrice());
|
|
|
+ //账单数据
|
|
|
+ items.setAmount(tradingBoxFees.getAmount());
|
|
|
+ items.setQuantity(tradingBoxFees.getQuantity());
|
|
|
+ items.setSrcOrderno(tradingBox.getSysNo());
|
|
|
+ items.setCorpId(tradingBoxFees.getCorpId());
|
|
|
+ items.setSrcParentId(pid);
|
|
|
+ items.setCurrency(tradingBoxFees.getCurrency());
|
|
|
+ items.setSrcType(5);
|
|
|
+ items.setTradeType("BOX");
|
|
|
+ items.setUnit(tradingBoxFees.getUnit());
|
|
|
+ items.setSrcSysNo(tradingBoxFees.getCode());
|
|
|
+ items.setRemarks(tradingBoxFees.getRemarks());
|
|
|
+ items.setSrcBillNo(tradingBox.getContractNo());
|
|
|
+ items.setStatusJT(0);
|
|
|
+ items.setBillNo(tradingBox.getContractNo());
|
|
|
+ items.setStockTime(tradingBox.getPurchaseDate());
|
|
|
+ //获取费用id
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxFees.getItemId())) {
|
|
|
+ items.setCostType(tradingBoxFees.getItemId().toString());
|
|
|
+ }
|
|
|
+ items.setSrcFeesId(tradingBoxFees.getId());
|
|
|
+ itemsList.add(items);
|
|
|
+ applyDTO.setItemsList(itemsList);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(itemsList)) {
|
|
|
+ //生成账单
|
|
|
+ R paymentApply = financeClient.paymentApplyBoxTube(applyDTO);
|
|
|
+ if (!paymentApply.isSuccess()) {
|
|
|
+ throw new RuntimeException(paymentApply.getMsg());
|
|
|
+ }
|
|
|
+ //给角色为财务的人发送消息
|
|
|
+ R<String> clientDeptIds = sysClient.getRoleIds(SecureUtil.getTenantId(), "财务");
|
|
|
+ if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(Long.valueOf(clientDeptIds.getData()));
|
|
|
+ if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
+ for (User datum : userList.getData()) {
|
|
|
+ //循环发送消息
|
|
|
+ Message sendMessage = new Message();
|
|
|
+ sendMessage.setParameter(String.valueOf(pid));
|
|
|
+ sendMessage.setUserName(AuthUtil.getUserName());
|
|
|
+ sendMessage.setUserId(AuthUtil.getUserId());
|
|
|
+ sendMessage.setToUserId(datum.getId());
|
|
|
+ sendMessage.setToUserName(datum.getName());
|
|
|
+ sendMessage.setMessageType(1);
|
|
|
+ sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setCreateUser(AuthUtil.getUserId());
|
|
|
+ sendMessage.setCreateTime(new Date());
|
|
|
+ sendMessage.setUrl(tradingBox.getUrl());
|
|
|
+ sendMessage.setPageLabel(tradingBox.getPageLabel());
|
|
|
+ sendMessage.setPageStatus(tradingBox.getPageStatus());
|
|
|
+ sendMessage.setMessageBody("您订单" + tradingBox.getSysNo() + "审核通过,请查看");
|
|
|
+ R save = messageClient.save(sendMessage);
|
|
|
+ if (!save.isSuccess()) {
|
|
|
+ throw new SecurityException("发送消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxFeesList(tradingBoxFeesList);
|
|
|
+ return tradingBox;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public TradingBox revokeRentCalculation(TradingBox tradingBox) {
|
|
|
+ List<TradingBoxItem> tradingBoxItemList = tradingBox.getTradingBoxItemsList();
|
|
|
+ if (tradingBoxItemList.size() < 1) {
|
|
|
+ throw new RuntimeException("明细不能为空");
|
|
|
+ }
|
|
|
+ for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ //获取订单费用信息
|
|
|
+ LambdaQueryWrapper<TradingBoxFees> tradingBoxFeesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.eq(TradingBoxFees::getIsDeleted, 0);
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.eq(TradingBoxFees::getPid, tradingBox.getId());
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.eq(TradingBoxFees::getTenantId, AuthUtil.getTenantId());
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.eq(TradingBoxFees::getSubmitPay, 1);
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.eq(TradingBoxFees::getCode, tradingBoxItem.getCode());
|
|
|
+ tradingBoxFeesLambdaQueryWrapper.orderByDesc(TradingBoxFees::getCreateTime);
|
|
|
+ List<TradingBoxFees> tradingBoxFeesList = tradingBoxFeesMapper.selectList(tradingBoxFeesLambdaQueryWrapper);
|
|
|
+ if (tradingBoxFeesList.size() > 0) {
|
|
|
+ tradingBoxFeesMapper.deleteById(tradingBoxFeesList.get(0).getId());
|
|
|
+ //获取账单信息
|
|
|
+ Acc acc = new Acc();
|
|
|
+ acc.setSrcParentId(tradingBox.getId());
|
|
|
+ acc.setSrcFeesId(tradingBoxFeesList.get(0).getId());
|
|
|
+ if ("ZR".equals(tradingBox.getType())) {
|
|
|
+ acc.setBillType("申请");
|
|
|
+ } else {
|
|
|
+ acc.setBillType("收费");
|
|
|
+ }
|
|
|
+ acc.setTradeType("BOX");
|
|
|
+ acc.setSrcType(5);
|
|
|
+ R<List<Acc>> r = financeClient.getAccListByCondition(acc);
|
|
|
+ if (r.isSuccess() && ObjectUtils.isNotNull(r.getData())) {
|
|
|
+ for (Acc acc_ : r.getData()) {
|
|
|
+ //判断是否有结算 true 不允许撤销审核 false 删除账单信息并撤销审核
|
|
|
+ if (!acc_.getSettlementAmount().equals(new BigDecimal("0.00"))) {
|
|
|
+ throw new SecurityException("订单已结算,不允许撤销");
|
|
|
+ } else {
|
|
|
+ financeClient.remove(acc_.getId() + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new SecurityException("箱号:" + tradingBoxItem.getCode() + "未计算租金,撤销失败");
|
|
|
+ }
|
|
|
+ tradingBoxItem.setUpdateTime(new Date());
|
|
|
+ tradingBoxItem.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxItem.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ tradingBoxItem.setRentEndDate(tradingBoxFeesList.get(0).getRentStartDate());
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxItemsList(tradingBoxItemList);
|
|
|
+ return tradingBox;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R importTradingBoxInfo(List<TradingBoxItemRentExcelEnter> excelList, boolean b, Long corpId, String corpName, String billType) {
|
|
|
+ List<TradingBoxItem> tradingBoxItemList = new ArrayList<>();
|
|
|
+ List<TradingBoxFees> tradingBoxFeesList = new ArrayList<>();
|
|
|
+ for (TradingBoxItemRentExcelEnter tradingBoxItemExcelEnter : excelList) {
|
|
|
+ TradingBoxItem tradingBoxItem = new TradingBoxItem();
|
|
|
+ BeanUtil.copy(tradingBoxItemExcelEnter, tradingBoxItem);
|
|
|
+ if (ObjectUtils.isNull(tradingBoxItem.getCode())) {
|
|
|
+ throw new RuntimeException("箱号不能为空");
|
|
|
+ }
|
|
|
+ if ("SELL".equals(billType) || "ZC".equals(billType)) {
|
|
|
+ LambdaQueryWrapper<Archives> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(Archives::getIsDeleted, 0)
|
|
|
+ .eq(Archives::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Archives::getCode, tradingBoxItem.getCode());
|
|
|
+ Archives archives = archivesMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (ObjectUtils.isNull(archives)) {
|
|
|
+ throw new RuntimeException("箱号:" + tradingBoxItem.getCode() + "不存在,请修改后再进行操作!");
|
|
|
+ }
|
|
|
+ BeanUtil.copy(archives, tradingBoxItem);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(tradingBoxItem.getAddress())) {
|
|
|
+ throw new RuntimeException("最新地点不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(tradingBoxItem.getNewDate())) {
|
|
|
+ throw new RuntimeException("最新时间不能为空");
|
|
|
+ }
|
|
|
+ //箱类型
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItemExcelEnter.getBoxType())) {
|
|
|
+ R<BasicContainerDesc> detail = containerDescClient.getContainer(tradingBoxItemExcelEnter.getBoxType());
|
|
|
+ if (detail.isSuccess() && ObjectUtils.isNotNull(detail.getData())) {
|
|
|
+ tradingBoxItem.setBoxType(detail.getData().getName());
|
|
|
+ tradingBoxItem.setBoxTypeId(detail.getData().getId());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("箱型不存在");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("箱型不能为空");
|
|
|
+ }
|
|
|
+ //最新地点
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItem.getAddress())) {
|
|
|
+ BasicPortDesc basicPortDesc = new BasicPortDesc();
|
|
|
+ basicPortDesc.setName(tradingBoxItem.getAddress());
|
|
|
+ BasicPortDesc detail = portClient.getPortData(basicPortDesc);
|
|
|
+ if (ObjectUtils.isNotNull(detail)) {
|
|
|
+ tradingBoxItem.setAddress(detail.getName());
|
|
|
+ tradingBoxItem.setAddressId(detail.getId());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tradingBoxItem.setAddress(null);
|
|
|
+ tradingBoxItem.setAddressId(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //租赁公司
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItemExcelEnter.getBoxMakingCompany())) {
|
|
|
+ CorpsDesc detail = corpsDescClient.getCorpsDesc(tradingBoxItemExcelEnter.getBoxMakingCompany(), "KH");
|
|
|
+ if (ObjectUtils.isNotNull(detail)) {
|
|
|
+ tradingBoxItem.setBoxMakingCompany(detail.getCname());
|
|
|
+ tradingBoxItem.setBoxMakingCompanyId(detail.getId());
|
|
|
+ } else {
|
|
|
+ tradingBoxItem.setBoxMakingCompany(null);
|
|
|
+ tradingBoxItem.setBoxMakingCompanyId(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("SELL".equals(billType) || "BUY".equals(billType)){
|
|
|
+ tradingBoxItem.setAmount(tradingBoxItem.getPrice());
|
|
|
+ TradingBoxFees tradingBoxFees = new TradingBoxFees();
|
|
|
+ tradingBoxFees.setCorpId(corpId);
|
|
|
+ tradingBoxFees.setCorpName(corpName);
|
|
|
+ tradingBoxFees.setAmount(tradingBoxItem.getPrice());
|
|
|
+ if ("SELL".equals(billType)){
|
|
|
+ //获取费用id
|
|
|
+ R<FeesDesc> fees = feesDescClient.getFeesByName("卖箱费");
|
|
|
+ if (fees.isSuccess() && fees.getData() != null) {
|
|
|
+ tradingBoxFees.setItemId(fees.getData().getId());
|
|
|
+ tradingBoxFees.setItemName("卖箱费");
|
|
|
+ }
|
|
|
+ tradingBoxFees.setFeesType(1);
|
|
|
+ }else{
|
|
|
+ //获取费用id
|
|
|
+ R<FeesDesc> fees = feesDescClient.getFeesByName("买箱费");
|
|
|
+ if (fees.isSuccess() && fees.getData() != null) {
|
|
|
+ tradingBoxFees.setItemId(fees.getData().getId());
|
|
|
+ tradingBoxFees.setItemName("买箱费");
|
|
|
+ }
|
|
|
+ tradingBoxFees.setFeesType(2);
|
|
|
+ }
|
|
|
+ tradingBoxFees.setUnit(tradingBoxItem.getBoxType());
|
|
|
+ tradingBoxFees.setCurrency(tradingBoxItem.getCurrency());
|
|
|
+ if ("CYN".equals(tradingBoxItem.getCurrency())){
|
|
|
+ tradingBoxFees.setExchangeRate(new BigDecimal(1));
|
|
|
+ }else{
|
|
|
+ tradingBoxFees.setExchangeRate(new BigDecimal(6.30));
|
|
|
+ }
|
|
|
+ tradingBoxFees.setAutoGenerate("1");
|
|
|
+ tradingBoxFees.setGenerationSource(tradingBoxItem.getCode());
|
|
|
+ tradingBoxFees.setQuantity(new BigDecimal(1));
|
|
|
+ tradingBoxFees.setPrice(tradingBoxItem.getPrice());
|
|
|
+ tradingBoxFees.setCode(tradingBoxItem.getCode());
|
|
|
+ tradingBoxFeesList.add(tradingBoxFees);
|
|
|
+ }
|
|
|
+ tradingBoxItemList.add(tradingBoxItem);
|
|
|
+ }
|
|
|
+ if ("SELL".equals(billType) || "BUY".equals(billType)){
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("tradingBoxItemList",tradingBoxItemList);
|
|
|
+ map.put("tradingBoxFeesList",tradingBoxFeesList);
|
|
|
+ return R.data(map);
|
|
|
+ }else{
|
|
|
+ return R.data(tradingBoxItemList);
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -965,8 +1436,8 @@ public class TradingBoxServiceImpl extends ServiceImpl<TradingBoxMapper, Trading
|
|
|
//获取费用id
|
|
|
if (ObjectUtils.isNotNull(tradingBoxFees.getItemId())) {
|
|
|
items.setCostType(tradingBoxFees.getItemId().toString());
|
|
|
- items.setSrcFeesId(tradingBoxFees.getId());
|
|
|
}
|
|
|
+ items.setSrcFeesId(tradingBoxFees.getId());
|
|
|
itemsList.add(items);
|
|
|
applyDTO.setItemsList(itemsList);
|
|
|
}
|