mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善删除逻辑
This commit is contained in:
@@ -12,6 +12,12 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface CoalInfoRepository extends BaseRepository<CoalInfoEntity> {
|
||||
|
||||
@Query("select exists(select 1 from CoalAnalysisEntity e where e.coalInfo.id in :ids)")
|
||||
@Query("""
|
||||
select exists(
|
||||
select 1 from CoalAnalysisEntity e where e.coalInfo.id in :ids
|
||||
union all
|
||||
select 1 from PurchaseOrderEntity p where p.coalInfo.id in :ids
|
||||
union all
|
||||
select 1 from InventoryCheckDetailEntity d where d.coalInfo.id in :ids)""")
|
||||
boolean isLinked(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.lihongjie.coal.inventoryCheck.dto.UpdateInventoryCheckDto;
|
||||
import cn.lihongjie.coal.inventoryCheck.entity.InventoryCheckEntity;
|
||||
import cn.lihongjie.coal.inventoryCheck.mapper.InventoryCheckMapper;
|
||||
import cn.lihongjie.coal.inventoryCheck.repository.InventoryCheckRepository;
|
||||
import cn.lihongjie.coal.inventoryCheckDetail.service.InventoryCheckDetailService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -47,8 +48,13 @@ public class InventoryCheckService
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@Autowired InventoryCheckDetailService inventoryCheckDetailService;
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
|
||||
inventoryCheckDetailService.deleteByInventoryCheckId(request.getIds());
|
||||
|
||||
}
|
||||
|
||||
public InventoryCheckDto getById(String id) {
|
||||
|
||||
@@ -10,6 +10,9 @@ import cn.lihongjie.coal.inventoryCheckDetail.entity.InventoryCheckDetailEntity;
|
||||
import cn.lihongjie.coal.inventoryCheckDetail.mapper.InventoryCheckDetailMapper;
|
||||
import cn.lihongjie.coal.inventoryCheckDetail.repository.InventoryCheckDetailRepository;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,6 +23,8 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -68,4 +73,16 @@ public class InventoryCheckDetailService
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
public void deleteByInventoryCheckId(List<String> ids) {
|
||||
|
||||
em.createQuery(
|
||||
"delete from InventoryCheckDetailEntity e where e.inventoryCheck.id in :ids")
|
||||
.setParameter("ids", ids)
|
||||
.executeUpdate();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,24 @@ package cn.lihongjie.coal.product.service;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.coalWashingDailyAnalysis.entity.CoalWashingDailyAnalysisEntity;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.product.dto.CreateProductDto;
|
||||
import cn.lihongjie.coal.product.dto.ProductDto;
|
||||
import cn.lihongjie.coal.product.dto.UpdateProductDto;
|
||||
import cn.lihongjie.coal.product.entity.ProductEntity;
|
||||
import cn.lihongjie.coal.product.mapper.ProductMapper;
|
||||
import cn.lihongjie.coal.product.repository.ProductRepository;
|
||||
import cn.lihongjie.coal.saleOrder.entity.SaleOrderEntity;
|
||||
|
||||
import io.vavr.collection.Stream;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -20,6 +29,8 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -46,7 +57,34 @@ public class ProductService extends BaseService<ProductEntity, ProductRepository
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@PersistenceContext EntityManager em;
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
List<SaleOrderEntity> list =
|
||||
em.createQuery(
|
||||
"select e from SaleOrderEntity e where e.productInfo.id in :ids",
|
||||
SaleOrderEntity.class)
|
||||
.setParameter("ids", request.getIds())
|
||||
.getResultList();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
|
||||
throw new BizException(String.format("产品信息被销售订单 %s 关联, 无法删除", Stream.ofAll(list).take(3).map(SaleOrderEntity::getCode).mkString(",")));
|
||||
}
|
||||
|
||||
List<CoalWashingDailyAnalysisEntity> list2 =
|
||||
em.createQuery(
|
||||
"select e from CoalWashingDailyAnalysisEntity e where e.product.id in :ids",
|
||||
CoalWashingDailyAnalysisEntity.class)
|
||||
.setParameter("ids", request.getIds())
|
||||
.getResultList();
|
||||
if (CollectionUtils.isNotEmpty(list2)) {
|
||||
|
||||
throw new BizException(String.format("产品信息被生产报表 %s 关联, 无法删除", Stream.ofAll(list2).take(3).map(CoalWashingDailyAnalysisEntity::getDate).mkString(",")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,23 @@ public class PurchaseOrderService
|
||||
@PersistenceContext private EntityManager entityManager;
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
|
||||
List<Tuple> resultList = entityManager.createQuery("select p.id, p.name, p.code, size(p.weightDataList) as wsize from PurchaseOrderEntity p where p.id in :ids", Tuple.class)
|
||||
.setParameter("ids", request.getIds())
|
||||
.getResultList();
|
||||
|
||||
|
||||
for (Tuple tuple : resultList) {
|
||||
|
||||
if (tuple.get("wsize", Long.class) > 0){
|
||||
throw new BizException("采购单 " + tuple.get("code", String.class) + "已经关联过磅数据, 无法删除");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,23 @@ public class SaleOrderService extends BaseService<SaleOrderEntity, SaleOrderRepo
|
||||
@Autowired private CommonMapper commonMapper;
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
List<Tuple> resultList =
|
||||
entityManager
|
||||
.createQuery(
|
||||
"select p.id, p.name, p.code, size(p.weightDataList) as wsize from SaleOrderEntity p where p.id in :ids",
|
||||
Tuple.class)
|
||||
.setParameter("ids", request.getIds())
|
||||
.getResultList();
|
||||
|
||||
for (Tuple tuple : resultList) {
|
||||
|
||||
if (tuple.get("wsize", Long.class) > 0) {
|
||||
throw new BizException(
|
||||
"销售订单 " + tuple.get("code", String.class) + "已经关联过磅数据, 无法删除");
|
||||
}
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user