|
@@ -1,26 +1,36 @@
|
|
|
package com.fjhx.sale.service.pack.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.enums.CodingRuleEnum;
|
|
|
+import com.fjhx.common.enums.PushBusinessTypeEnum;
|
|
|
import com.fjhx.common.service.coding.CodingRuleService;
|
|
|
+import com.fjhx.sale.entity.contract.po.Contract;
|
|
|
+import com.fjhx.sale.entity.documents.po.Documents;
|
|
|
+import com.fjhx.sale.entity.documents.po.DocumentsPdf;
|
|
|
+import com.fjhx.sale.entity.documents.po.DocumentsProduct;
|
|
|
+import com.fjhx.sale.entity.documents.po.DocumentsTransport;
|
|
|
import com.fjhx.sale.entity.pack.dto.PackDto;
|
|
|
import com.fjhx.sale.entity.pack.dto.PackSelectDto;
|
|
|
-import com.fjhx.sale.entity.pack.po.Pack;
|
|
|
-import com.fjhx.sale.entity.pack.po.PackDetail;
|
|
|
-import com.fjhx.sale.entity.pack.po.PackDetailGoods;
|
|
|
-import com.fjhx.sale.entity.pack.po.PackDetailProduct;
|
|
|
+import com.fjhx.sale.entity.pack.po.*;
|
|
|
import com.fjhx.sale.entity.pack.vo.PackVo;
|
|
|
import com.fjhx.sale.mapper.pack.PackMapper;
|
|
|
-import com.fjhx.sale.service.pack.PackDetailGoodsService;
|
|
|
-import com.fjhx.sale.service.pack.PackDetailProductService;
|
|
|
-import com.fjhx.sale.service.pack.PackDetailService;
|
|
|
-import com.fjhx.sale.service.pack.PackService;
|
|
|
+import com.fjhx.sale.service.contract.ContractService;
|
|
|
+import com.fjhx.sale.service.documents.DocumentsPdfService;
|
|
|
+import com.fjhx.sale.service.documents.DocumentsProductService;
|
|
|
+import com.fjhx.sale.service.documents.DocumentsService;
|
|
|
+import com.fjhx.sale.service.documents.DocumentsTransportService;
|
|
|
+import com.fjhx.sale.service.pack.*;
|
|
|
+import com.fjhx.socket.core.PushTypeEnum;
|
|
|
+import com.fjhx.socket.core.WebSocketPush;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -28,6 +38,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@@ -52,6 +64,18 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, Pack> implements Pa
|
|
|
|
|
|
@Autowired
|
|
|
private CodingRuleService codingRuleService;
|
|
|
+ @Autowired
|
|
|
+ private PackShipmentService packShipmentService;
|
|
|
+ @Autowired
|
|
|
+ private DocumentsService documentsService;
|
|
|
+ @Autowired
|
|
|
+ private DocumentsPdfService documentsPdfService;
|
|
|
+ @Autowired
|
|
|
+ private DocumentsProductService documentsProductService;
|
|
|
+ @Autowired
|
|
|
+ private DocumentsTransportService documentsTransportService;
|
|
|
+ @Autowired
|
|
|
+ private ContractService contractService;
|
|
|
|
|
|
@Override
|
|
|
public Page<PackVo> getPage(PackSelectDto dto) {
|
|
@@ -133,9 +157,89 @@ public class PackServiceImpl extends ServiceImpl<PackMapper, Pack> implements Pa
|
|
|
this.updateById(packDto);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 删除装箱
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
this.removeById(id);
|
|
|
+
|
|
|
+ List<PackDetail> packDetailList = packDetailService.list(q -> q.eq(PackDetail::getPackId, id));
|
|
|
+ if (ObjectUtil.isEmpty(packDetailList)) {
|
|
|
+ throw new ServiceException("装箱明细不存在");
|
|
|
+ }
|
|
|
+ List<Long> packDetailIds = packDetailList.stream().map(PackDetail::getId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ packDetailService.remove(q -> q.eq(PackDetail::getPackId, id));
|
|
|
+
|
|
|
+ packDetailGoodsService.remove(q -> q.in(PackDetailGoods::getPackDetailId, packDetailIds));
|
|
|
+
|
|
|
+ packDetailProductService.remove(q -> q.in(PackDetailProduct::getPackDetailId, packDetailIds));
|
|
|
+
|
|
|
+ IWrapper<PackShipment> wrapper = IWrapper.getWrapper();
|
|
|
+ packDetailIds.forEach(item -> wrapper.like(PackShipment::getPackDetailIds, item).or());
|
|
|
+ List<PackShipment> packShipmentList = packShipmentService.list(wrapper);
|
|
|
+ if (ObjectUtil.isEmpty(packShipmentList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ packShipmentService.remove(wrapper);
|
|
|
+
|
|
|
+ List<Long> packShipmentIds = packShipmentList.stream().map(PackShipment::getId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Documents> documentsList = documentsService.list(q -> q.in(Documents::getPackShipmentId, packShipmentIds));
|
|
|
+ if (ObjectUtil.isEmpty(documentsList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ documentsService.remove(q -> q.in(Documents::getPackShipmentId, packShipmentIds));
|
|
|
+ List<Long> documentsIds = documentsList.stream().map(Documents::getId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ documentsPdfService.remove(q -> q.in(DocumentsPdf::getDocumentId, documentsIds));
|
|
|
+
|
|
|
+ documentsProductService.remove(q -> q.in(DocumentsProduct::getDocumentsId, documentsIds));
|
|
|
+
|
|
|
+ documentsTransportService.remove(q -> q.in(DocumentsTransport::getDocumentsId, documentsIds));
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> cIds = documentsList.stream().map(Documents::getContractId).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, Contract> contractMap = contractService.mapKEntity(Contract::getId, q -> q.in(Contract::getId, cIds));
|
|
|
+ for (Documents documents : documentsList) {
|
|
|
+ Contract contract = contractMap.get(documents.getContractId());
|
|
|
+ String contractCode = ObjectUtil.isNotEmpty(contract) ? contract.getCode() : String.valueOf(documents.getContractId());
|
|
|
+ String userName = SecurityUtils.getLoginUser().getUser().getNickName();
|
|
|
+ String msg = "您创建的单证,主合同号:({})被({})删除,原因:装箱信息被({})删除";
|
|
|
+ WebSocketPush.byTenant(
|
|
|
+ PushTypeEnum.MESSAGE,
|
|
|
+ StrUtil.format(msg, contractCode, userName, userName),
|
|
|
+ PushBusinessTypeEnum.DOCUMENTS_DEL.getType()
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|