|
|
@@ -0,0 +1,556 @@
|
|
|
+/*
|
|
|
+ * 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.box.tube.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import io.seata.spring.annotation.GlobalTransactional;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.box.tube.entity.*;
|
|
|
+import org.springblade.box.tube.mapper.*;
|
|
|
+import org.springblade.box.tube.service.ITransferService;
|
|
|
+import org.springblade.check.feign.ICheckClient;
|
|
|
+import org.springblade.client.entity.FeesDesc;
|
|
|
+import org.springblade.client.entity.Message;
|
|
|
+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;
|
|
|
+import org.springblade.finance.dto.ApplyDTO;
|
|
|
+import org.springblade.finance.feign.IFinanceClient;
|
|
|
+import org.springblade.finance.vojo.Acc;
|
|
|
+import org.springblade.finance.vojo.Items;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 买(卖)箱表 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2022-11-14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class TransferServiceImpl implements ITransferService {
|
|
|
+
|
|
|
+ private final TradingBoxFeesMapper tradingBoxFeesMapper;
|
|
|
+
|
|
|
+ private final TradingBoxItemMapper tradingBoxItemMapper;
|
|
|
+
|
|
|
+ private final TradingBoxFilesMapper tradingBoxFilesMapper;
|
|
|
+
|
|
|
+ private final TradingBoxMapper tradingBoxMapper;
|
|
|
+
|
|
|
+ private final ICheckClient iCheckClient;
|
|
|
+
|
|
|
+ private final IFinanceClient financeClient;//财务
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private IUserClient userClient;//获取用户信息
|
|
|
+
|
|
|
+ private final IMessageClient messageClient;//消息
|
|
|
+
|
|
|
+ private final ArchivesMapper archivesMapper;
|
|
|
+
|
|
|
+ private ISerialClient serialClient;//生成系统编号
|
|
|
+
|
|
|
+ private IFeesDescClient feesDescClient;//费用
|
|
|
+
|
|
|
+ private ICorpsDescClient corpsDescClient;//公司
|
|
|
+
|
|
|
+ private final ArchivesTrajectoryMapper archivesTrajectoryMapper;
|
|
|
+
|
|
|
+ private final ArchivesFilesMapper archivesFilesMapper;
|
|
|
+
|
|
|
+ private final IContainerDescClient containerDescClient;
|
|
|
+
|
|
|
+ private final IPortClient portClient;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public TradingBox submit(TradingBox tradingBox) {
|
|
|
+ if (tradingBox.getId() == null) {
|
|
|
+ //获取系统编号
|
|
|
+ R billNo = serialClient.getBillNo(tradingBox.getType(), "BOX", tradingBox.getType());
|
|
|
+ if (!billNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ throw new Error("生成系统编号失败");
|
|
|
+ }
|
|
|
+ tradingBox.setSysNo(billNo.getData().toString());
|
|
|
+ tradingBox.setCreateTime(new Date());
|
|
|
+ tradingBox.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBox.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ tradingBox.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBox.setStatus(0);
|
|
|
+ tradingBox.setPurchaseDate(new Date());
|
|
|
+ tradingBoxMapper.insert(tradingBox);
|
|
|
+ } else {
|
|
|
+ tradingBox.setUpdateTime(new Date());
|
|
|
+ tradingBox.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBox.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ tradingBoxMapper.updateById(tradingBox);
|
|
|
+ }
|
|
|
+ //明细数据
|
|
|
+ List<TradingBoxItem> tradingBoxItemList = tradingBox.getTradingBoxItemsList();
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItemList) && tradingBoxItemList.size() > 0) {
|
|
|
+ //箱号拼接字符串
|
|
|
+ List<String> codes = tradingBoxItemList.stream().map(TradingBoxItem::getCode).distinct().collect(Collectors.toList());
|
|
|
+ tradingBox.setCode(String.join(",", codes));
|
|
|
+ for (TradingBoxItem tradingBoxItem : tradingBoxItemList) {
|
|
|
+ tradingBoxItem.setAddress(tradingBox.getAddress());
|
|
|
+ tradingBoxItem.setAddressId(tradingBox.getAddressId());
|
|
|
+ //明细数据修改添加
|
|
|
+ if (tradingBoxItem.getId() == null) {
|
|
|
+ tradingBoxItem.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxItem.setCreateTime(new Date());
|
|
|
+ tradingBoxItem.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ tradingBoxItem.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBoxItem.setPid(tradingBox.getId());
|
|
|
+ tradingBoxItem.setStatus("待使用");
|
|
|
+ tradingBoxItem.setStockpilingStatus("0");
|
|
|
+ tradingBoxItemMapper.insert(tradingBoxItem);
|
|
|
+ } else {
|
|
|
+ tradingBoxItem.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxItem.setUpdateTime(new Date());
|
|
|
+ tradingBoxItem.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ tradingBoxItem.setPid(tradingBox.getId());
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+ }
|
|
|
+ //更新箱档案信息
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItem.getCode())) {
|
|
|
+ Archives archives = new Archives();
|
|
|
+ archives.setStatus("待使用");
|
|
|
+ archives.setCode(tradingBoxItem.getCode());
|
|
|
+ archives.setAddress(tradingBox.getAddress());
|
|
|
+ archives.setAddressId(tradingBox.getAddressId());
|
|
|
+ archives.setNewDate(new Date());
|
|
|
+ archivesMapper.updateCode(archives);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("箱号不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxItemsList(tradingBoxItemList);
|
|
|
+ }
|
|
|
+ tradingBox.setBoxNumber(tradingBoxItemList.size());
|
|
|
+ tradingBoxMapper.updateById(tradingBox);
|
|
|
+ //费用明细
|
|
|
+ List<TradingBoxFees> tradingBoxFeesList = tradingBox.getTradingBoxFeesList();
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxFeesList) && tradingBoxFeesList.size() > 0) {
|
|
|
+ for (TradingBoxFees tradingBoxFees : tradingBoxFeesList) {
|
|
|
+ if (tradingBoxFees.getId() == null) {
|
|
|
+ if ("ZR".equals(tradingBox.getType())) {
|
|
|
+ tradingBoxFees.setBillType("租入");
|
|
|
+ } else {
|
|
|
+ tradingBoxFees.setBillType("租出");
|
|
|
+ }
|
|
|
+ tradingBoxFees.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFees.setCreateTime(new Date());
|
|
|
+ tradingBoxFees.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBoxFees.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFeesMapper.insert(tradingBoxFees);
|
|
|
+ } else {
|
|
|
+ tradingBoxFees.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFees.setUpdateTime(new Date());
|
|
|
+ tradingBoxFees.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFeesMapper.updateById(tradingBoxFees);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxFeesList(tradingBoxFeesList);
|
|
|
+ }
|
|
|
+ //主表附件
|
|
|
+ List<TradingBoxFiles> tradingBoxFilesList = tradingBox.getTradingBoxFilesList();
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxFilesList) && tradingBoxFilesList.size() > 0) {
|
|
|
+ for (TradingBoxFiles tradingBoxFiles : tradingBoxFilesList) {
|
|
|
+ if (tradingBoxFiles.getId() == null) {
|
|
|
+ tradingBoxFiles.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFiles.setCreateTime(new Date());
|
|
|
+ tradingBoxFiles.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBoxFiles.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFiles.setType("1");
|
|
|
+ tradingBoxFilesMapper.insert(tradingBoxFiles);
|
|
|
+ } else {
|
|
|
+ tradingBoxFiles.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFiles.setUpdateTime(new Date());
|
|
|
+ tradingBoxFiles.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFiles.setType("1");
|
|
|
+ tradingBoxFilesMapper.updateById(tradingBoxFiles);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxFilesList(tradingBoxFilesList);
|
|
|
+ }
|
|
|
+ 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 (ObjectUtils.isNotNull(tradingBox.getRentCalculationDate()) && ObjectUtils.isNotNull(tradingBox.getRentStartDate())) {
|
|
|
+ days = (int) ((tradingBox.getRentCalculationDate().getTime() - tradingBox.getRentStartDate().getTime()) / (1000 * 3600 * 24)) + 1;
|
|
|
+ }
|
|
|
+ Long pid = tradingBox.getId();
|
|
|
+
|
|
|
+ //账单数据
|
|
|
+ ApplyDTO applyDTO = new ApplyDTO();
|
|
|
+ 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 ("DCF".equals(tradingBox.getType())) {
|
|
|
+ tradingBoxFees.setFeesType(1);
|
|
|
+ tradingBoxFees.setBillType("堆存费");
|
|
|
+ }
|
|
|
+ tradingBoxFees.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFees.setSrcOrderNo(tradingBox.getContractNo());
|
|
|
+ tradingBoxFees.setUnit(tradingBoxItem.getBoxType());
|
|
|
+ tradingBoxFees.setExchangeRate(new BigDecimal(1));
|
|
|
+ tradingBoxFees.setRentStartDate(tradingBox.getRentStartDate());
|
|
|
+ tradingBoxFees.setRentEndDate(tradingBox.getRentCalculationDate());
|
|
|
+ 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.getRentCalculationDate());
|
|
|
+ tradingBoxItem.setRentStartDate(tradingBox.getRentStartDate());
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+
|
|
|
+ Items items = new Items();
|
|
|
+ if (1 == tradingBoxFees.getFeesType()) {
|
|
|
+ items.setSrcFeesType("收费");
|
|
|
+ } else {
|
|
|
+ items.setSrcFeesType("付费");
|
|
|
+ }
|
|
|
+ items.setSrcBoxBillType(tradingBoxFees.getBillType());
|
|
|
+ items.setItemType(tradingBox.getType());
|
|
|
+ items.setPrice(tradingBoxFees.getPrice());
|
|
|
+ //账单数据
|
|
|
+ items.setAmount(tradingBoxFees.getAmount());
|
|
|
+ items.setQuantity(tradingBoxFees.getQuantity());
|
|
|
+ items.setSrcOrderno(tradingBox.getContractNo());
|
|
|
+ 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.getSysNo());
|
|
|
+ items.setStatusJT(0);
|
|
|
+ items.setBillNo(tradingBox.getSysNo());
|
|
|
+ items.setStockTime(tradingBox.getPurchaseDate());
|
|
|
+ items.setRentStartDate(tradingBox.getRentStartDate());
|
|
|
+ items.setRentEndDate(tradingBox.getRentCalculationDate());
|
|
|
+ //获取费用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());
|
|
|
+ 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());
|
|
|
+ if (tradingBoxFeesList.size() == 1) {
|
|
|
+ tradingBoxItem.setRentEndDate(tradingBoxItem.getLeaseCommencementDate());
|
|
|
+ tradingBoxItem.setRentStartDate(tradingBoxItem.getLeaseCommencementDate());
|
|
|
+ } else {
|
|
|
+ tradingBoxItem.setRentEndDate(tradingBoxFeesList.get(0).getRentEndDate());
|
|
|
+ tradingBoxItem.setRentStartDate(tradingBoxFeesList.get(0).getRentStartDate());
|
|
|
+ }
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem);
|
|
|
+ }
|
|
|
+ tradingBox.setTradingBoxItemsList(tradingBoxItemList);
|
|
|
+ return tradingBox;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public void stockpilingFee(List<String> codeList) {
|
|
|
+
|
|
|
+ if (ObjectUtils.isNull(codeList) || codeList.size() < 1) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<TradingBoxItem> tradingBoxItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ tradingBoxItemLambdaQueryWrapper.eq(TradingBoxItem::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(TradingBoxItem::getIsDeleted, 0)
|
|
|
+ .eq(TradingBoxItem::getCode, codeList.get(0))
|
|
|
+ .eq(TradingBoxItem::getStockpilingStatus, "0");
|
|
|
+ TradingBoxItem tradingBoxItemDetail = tradingBoxItemMapper.selectOne(tradingBoxItemLambdaQueryWrapper);
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItemDetail)) {
|
|
|
+ TradingBox tradingBox = tradingBoxMapper.selectById(tradingBoxItemDetail.getPid());
|
|
|
+ if (ObjectUtils.isNull(tradingBox)) {
|
|
|
+ throw new RuntimeException("未找到单据信息");
|
|
|
+ }else{
|
|
|
+ //账单数据
|
|
|
+ ApplyDTO applyDTO = new ApplyDTO();
|
|
|
+ applyDTO.setBillType("申请");
|
|
|
+ applyDTO.setTradeType("BOX");
|
|
|
+ //账单明细
|
|
|
+ List<Items> itemsList = new ArrayList<>();
|
|
|
+ for (String code : codeList) {
|
|
|
+ LambdaQueryWrapper<TradingBoxItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(TradingBoxItem::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(TradingBoxItem::getIsDeleted, 0)
|
|
|
+ .eq(TradingBoxItem::getCode, code)
|
|
|
+ .eq(TradingBoxItem::getStockpilingStatus, "0");
|
|
|
+ TradingBoxItem tradingBoxItem1 = tradingBoxItemMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (ObjectUtils.isNotNull()) {
|
|
|
+ tradingBoxItem1.setStockpilingStatus("1");
|
|
|
+ tradingBoxItem1.setUpdateTime(new Date());
|
|
|
+ tradingBoxItem1.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxItem1.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ int days = 0;
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxItem1.getRentEndDate())) {
|
|
|
+ tradingBoxItem1.setRentStartDate(tradingBoxItem1.getRentEndDate());
|
|
|
+ days = (int) ((new Date().getTime() - tradingBoxItem1.getRentEndDate().getTime()) / (1000 * 3600 * 24)) + 1;
|
|
|
+ } else {
|
|
|
+ tradingBoxItem1.setRentStartDate(tradingBoxItem1.getCreateTime());
|
|
|
+ days = (int) ((new Date().getTime() - tradingBoxItem1.getCreateTime().getTime()) / (1000 * 3600 * 24)) + 1;
|
|
|
+ }
|
|
|
+ tradingBoxItem1.setRentEndDate(new Date());
|
|
|
+ tradingBoxItemMapper.updateById(tradingBoxItem1);
|
|
|
+ TradingBoxFees tradingBoxFees = new TradingBoxFees();
|
|
|
+ tradingBoxFees.setCorpId(tradingBox.getPurchaseCompanyId());
|
|
|
+ tradingBoxFees.setCorpName(tradingBox.getPurchaseCompanyName());
|
|
|
+ tradingBoxFees.setAmount(tradingBoxItem1.getPrice().multiply(BigDecimal.valueOf(days)));
|
|
|
+ tradingBoxFees.setPrice(tradingBoxItem1.getPrice());
|
|
|
+ tradingBoxFees.setQuantity(BigDecimal.valueOf(days));
|
|
|
+ tradingBoxFees.setCurrency(tradingBoxItem1.getCurrency());
|
|
|
+ tradingBoxFees.setCode(tradingBoxItem1.getCode());
|
|
|
+ //获取费用id
|
|
|
+ R<FeesDesc> fees = feesDescClient.getFeesByName("堆存费");
|
|
|
+ if (fees.isSuccess() && fees.getData() != null) {
|
|
|
+ tradingBoxFees.setItemId(fees.getData().getId());
|
|
|
+ }
|
|
|
+ if ("DCF".equals(tradingBox.getType())) {
|
|
|
+ tradingBoxFees.setFeesType(1);
|
|
|
+ tradingBoxFees.setBillType("堆存费");
|
|
|
+ }
|
|
|
+ tradingBoxFees.setPid(tradingBox.getId());
|
|
|
+ tradingBoxFees.setSrcOrderNo(tradingBox.getContractNo());
|
|
|
+ tradingBoxFees.setUnit(tradingBoxItem1.getBoxType());
|
|
|
+ tradingBoxFees.setExchangeRate(new BigDecimal(1));
|
|
|
+ tradingBoxFees.setRentStartDate(tradingBox.getRentStartDate());
|
|
|
+ tradingBoxFees.setRentEndDate(tradingBox.getRentCalculationDate());
|
|
|
+ tradingBoxFees.setCreateUser(AuthUtil.getUserId());
|
|
|
+ tradingBoxFees.setCreateTime(new Date());
|
|
|
+ tradingBoxFees.setTenantId(AuthUtil.getTenantId());
|
|
|
+ tradingBoxFees.setSubmitPay(1);
|
|
|
+ tradingBoxFeesMapper.insert(tradingBoxFees);
|
|
|
+
|
|
|
+ Items items = new Items();
|
|
|
+ if (1 == tradingBoxFees.getFeesType()) {
|
|
|
+ items.setSrcFeesType("收费");
|
|
|
+ } else {
|
|
|
+ items.setSrcFeesType("付费");
|
|
|
+ }
|
|
|
+ items.setSrcBoxBillType(tradingBoxFees.getBillType());
|
|
|
+ items.setItemType(tradingBox.getType());
|
|
|
+ items.setPrice(tradingBoxFees.getPrice());
|
|
|
+ //账单数据
|
|
|
+ items.setAmount(tradingBoxFees.getAmount());
|
|
|
+ items.setQuantity(tradingBoxFees.getQuantity());
|
|
|
+ items.setSrcOrderno(tradingBox.getContractNo());
|
|
|
+ items.setCorpId(tradingBoxFees.getCorpId());
|
|
|
+ items.setSrcParentId(tradingBox.getId());
|
|
|
+ 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.getSysNo());
|
|
|
+ items.setStatusJT(0);
|
|
|
+ items.setBillNo(tradingBox.getSysNo());
|
|
|
+ items.setStockTime(tradingBox.getPurchaseDate());
|
|
|
+ items.setRentStartDate(tradingBox.getRentStartDate());
|
|
|
+ items.setRentEndDate(tradingBox.getRentCalculationDate());
|
|
|
+ //获取费用id
|
|
|
+ if (ObjectUtils.isNotNull(tradingBoxFees.getItemId())) {
|
|
|
+ items.setCostType(tradingBoxFees.getItemId().toString());
|
|
|
+ }
|
|
|
+ items.setSrcFeesId(tradingBoxFees.getId());
|
|
|
+ itemsList.add(items);
|
|
|
+ applyDTO.setItemsList(itemsList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ applyDTO.setBelongCompany(tradingBox.getPurchaseCompanyName());
|
|
|
+ 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(tradingBox.getId()));
|
|
|
+ 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("发送消息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|