feat: 仓库管理相关数据校验

This commit is contained in:
2024-12-11 20:50:17 +08:00
parent 920e045a70
commit 2e1ad4cc8f
13 changed files with 116 additions and 25 deletions

View File

@@ -3,7 +3,15 @@ package cn.lihongjie.coal.warehouse.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouse.entity.WarehouseEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface WarehouseRepository extends BaseRepository<WarehouseEntity> {}
public interface WarehouseRepository extends BaseRepository<WarehouseEntity> {
@Query("select exists (select 1 from WarehouseGoodsEntity e where e.defaultWarehouse.id in :ids union all select 1 from WarehouseReceiptDetailEntity d where d.warehouse.id in :ids or d.warehouse2.id in :ids) ")
boolean isLinked(@Param("ids") List<String> ids);
}

View File

@@ -3,6 +3,7 @@ package cn.lihongjie.coal.warehouse.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.exception.BizException;
import cn.lihongjie.coal.warehouse.dto.CreateWarehouseDto;
import cn.lihongjie.coal.warehouse.dto.UpdateWarehouseDto;
import cn.lihongjie.coal.warehouse.dto.WarehouseDto;
@@ -61,6 +62,11 @@ public class WarehouseService extends BaseService<WarehouseEntity, WarehouseRepo
}
public void delete(IdRequest request) {
if (this.repository.isLinked(request.getIds())) {
throw new BizException("删除失败,该仓库已被使用");
}
this.repository.deleteAllById(request.getIds());
}

View File

@@ -5,12 +5,14 @@ import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.common.Ctx;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.warehouseGoods.dto.CreateWarehouseGoodsDto;
import cn.lihongjie.coal.warehouseGoods.dto.UpdateWarehouseGoodsDto;
import cn.lihongjie.coal.warehouseGoods.dto.WarehouseGoodsDto;
import cn.lihongjie.coal.warehouseGoods.entity.WarehouseGoodsEntity;
import cn.lihongjie.coal.warehouseGoods.mapper.WarehouseGoodsMapper;
import cn.lihongjie.coal.warehouseGoods.repository.WarehouseGoodsRepository;
import cn.lihongjie.coal.warehouseReceipt.service.WarehouseReceiptService;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -64,7 +66,16 @@ public class WarehouseGoodsService
return getById(entity.getId());
}
@Autowired
WarehouseReceiptService warehouseReceiptService;
public void delete(IdRequest request) {
if (warehouseReceiptService.countByGoodsId(request.getIds()) > 0) {
throw new BizException("该商品已经被使用,无法删除");
}
this.repository.deleteAllById(request.getIds());
}

View File

@@ -3,7 +3,16 @@ package cn.lihongjie.coal.warehouseGoodsBrand.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouseGoodsBrand.entity.WarehouseGoodsBrandEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface WarehouseGoodsBrandRepository extends BaseRepository<WarehouseGoodsBrandEntity> {}
public interface WarehouseGoodsBrandRepository extends BaseRepository<WarehouseGoodsBrandEntity> {
@Query("select exists (select 1 from WarehouseGoodsEntity e where e.brand.id in :ids ) ")
boolean isLinked(@Param("ids") List<String> ids);
}

View File

@@ -59,6 +59,12 @@ public class WarehouseGoodsBrandService
}
public void delete(IdRequest request) {
if (this.repository.isLinked(request.getIds())){
throw new RuntimeException("品牌已被关联,无法删除");
}
this.repository.deleteAllById(request.getIds());
}

View File

@@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouseGoodsCategory.entity.WarehouseGoodsCategoryEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@@ -11,6 +12,6 @@ import java.util.List;
@Repository
public interface WarehouseGoodsCategoryRepository
extends BaseRepository<WarehouseGoodsCategoryEntity> {
@Query("select false")
boolean isLinked(List<String> ids);
@Query("select exists (select 1 from WarehouseGoodsEntity e where e.category.id in :ids ) ")
boolean isLinked(@Param("ids") List<String> ids);
}

View File

@@ -3,7 +3,14 @@ package cn.lihongjie.coal.warehouseGoodsUnit.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouseGoodsUnit.entity.WarehouseGoodsUnitEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface WarehouseGoodsUnitRepository extends BaseRepository<WarehouseGoodsUnitEntity> {}
public interface WarehouseGoodsUnitRepository extends BaseRepository<WarehouseGoodsUnitEntity> {
@Query("select exists (select 1 from WarehouseGoodsEntity e where e.unit.id in :ids ) ")
boolean isLinked(@Param("ids")List<String> ids);
}

View File

@@ -4,6 +4,7 @@ import cn.lihongjie.coal.base.dto.CommonQuery;
import cn.lihongjie.coal.base.dto.IdRequest;
import cn.lihongjie.coal.base.mapper.CommonMapper;
import cn.lihongjie.coal.base.service.BaseService;
import cn.lihongjie.coal.exception.BizException;
import cn.lihongjie.coal.warehouseGoodsUnit.dto.BatchAddRequest;
import cn.lihongjie.coal.warehouseGoodsUnit.dto.CreateWarehouseGoodsUnitDto;
import cn.lihongjie.coal.warehouseGoodsUnit.dto.UpdateWarehouseGoodsUnitDto;
@@ -60,6 +61,11 @@ public class WarehouseGoodsUnitService
}
public void delete(IdRequest request) {
if (this.repository.isLinked(request.getIds())) {
throw new BizException("已经关联了商品,不能删除");
}
this.repository.deleteAllById(request.getIds());
}

View File

@@ -82,7 +82,6 @@ public class WarehouseReceiptService
createType2Receipt(entity);
}
return getById(entity.getId());
}
@@ -266,15 +265,18 @@ public class WarehouseReceiptService
WarehouseGoodsDto goods =
warehouseGoodsService.getById(
warehouseReceiptDetailEntity.getGoods().getId());
// if (ObjectUtils.notEqual(
// goodsCount, warehouseReceiptDetailEntity.getStock().intValue())) {
//
// throw new BizException("商品 " + goods.getName() + " 库存数量发生变化, 请重新操作");
// }
// if (ObjectUtils.notEqual(
// goodsCount,
// warehouseReceiptDetailEntity.getStock().intValue())) {
//
// throw new BizException("商品 " + goods.getName() + " 库存数量发生变化,
// 请重新操作");
// }
if (StringUtils.equals(entity.getReceiptType(), "1")) {
if (goodsCount < warehouseReceiptDetailEntity.getNumber()) {
throw new BizException("商品 " + goods.getName() + " 库存数量不足: 当前库存数量为 " + goodsCount);
throw new BizException(
"商品 " + goods.getName() + " 库存数量不足: 当前库存数量为 " + goodsCount);
}
}
}
@@ -343,20 +345,13 @@ public class WarehouseReceiptService
this.repository.deleteById(request.getId());
CreateWarehouseReceiptDto dto = new CreateWarehouseReceiptDto();
BeanUtil.copyProperties(request, dto);
dto.setId(null);
dto.getDetail().forEach(x -> x.setId(null));
return this.create(dto);
}
public void delete(IdRequest dto) {
/** 获取所有单据 1。 用户选中的 2. 用户选中的单据的子单据 */
@@ -574,17 +569,19 @@ public class WarehouseReceiptService
round((sum(d.amount)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id<#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type1_amount,
round((sum(d.amount)
case when (sum(d.number)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric !=0 then round((sum(d.amount)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>) /
sum(d.number)
filter (where d.receipt_type = '0') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type0_price,
2) else 0 end as type0_price,
round((sum(d.amount)
case when (sum(d.number)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric !=0 then round((sum(d.amount)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>) /
sum(d.number)
filter (where d.receipt_type = '1') over (partition by w.id, gs.id <#if shelveSummary>,ws.id</#if>))::::numeric,
2) as type1_price
2) else 0 end as type1_price
from t_warehouse_goods gs
inner join t_warehouse w on 1 = 1
<#if excludeEmpty>
@@ -882,4 +879,17 @@ from (
return new PageImpl<>(ans, PageRequest.of(0, request.getPageSize()), count);
}
public int countByGoodsId(List<String> ids) {
return (int)
this.repository.count(
(Specification<WarehouseReceiptEntity>)
(root, query, criteriaBuilder) ->
criteriaBuilder.and(
root.get("detail")
.get("goods")
.get("id")
.in(ids)));
}
}

View File

@@ -3,7 +3,14 @@ package cn.lihongjie.coal.warehouseShelve.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouseShelve.entity.WarehouseShelveEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface WarehouseShelveRepository extends BaseRepository<WarehouseShelveEntity> {}
public interface WarehouseShelveRepository extends BaseRepository<WarehouseShelveEntity> {
@Query("select exists (select 1 from WarehouseGoodsEntity e where e.defaultShelve.id in :ids union all select 1 from WarehouseReceiptDetailEntity d where d.shelve.id in :ids or d.shelve2.id in :ids) ")
boolean isLinked(@Param("ids") List<String> ids);
}

View File

@@ -3,6 +3,7 @@ package cn.lihongjie.coal.warehouseShelve.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.exception.BizException;
import cn.lihongjie.coal.warehouseShelve.dto.CreateWarehouseShelveDto;
import cn.lihongjie.coal.warehouseShelve.dto.UpdateWarehouseShelveDto;
import cn.lihongjie.coal.warehouseShelve.dto.WarehouseShelveDto;
@@ -48,6 +49,11 @@ public class WarehouseShelveService
}
public void delete(IdRequest request) {
if (this.repository.isLinked(request.getIds())) {
throw new BizException("删除失败,该货架已被使用");
}
this.repository.deleteAllById(request.getIds());
}

View File

@@ -3,7 +3,14 @@ package cn.lihongjie.coal.warehouseSupplier.repository;
import cn.lihongjie.coal.base.dao.BaseRepository;
import cn.lihongjie.coal.warehouseSupplier.entity.WarehouseSupplierEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface WarehouseSupplierRepository extends BaseRepository<WarehouseSupplierEntity> {}
public interface WarehouseSupplierRepository extends BaseRepository<WarehouseSupplierEntity> {
@Query("select exists (select 1 from WarehouseReceiptDetailEntity e where e.supplier.id in :ids union all select 1 from WarehouseGoodsEntity g where g.defaultSupplier.id in :ids) ")
boolean isLinked(@Param("ids") List<String> ids);
}

View File

@@ -3,6 +3,7 @@ package cn.lihongjie.coal.warehouseSupplier.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.exception.BizException;
import cn.lihongjie.coal.warehouseSupplier.dto.CreateWarehouseSupplierDto;
import cn.lihongjie.coal.warehouseSupplier.dto.UpdateWarehouseSupplierDto;
import cn.lihongjie.coal.warehouseSupplier.dto.WarehouseSupplierDto;
@@ -48,6 +49,12 @@ public class WarehouseSupplierService
}
public void delete(IdRequest request) {
if (this.repository.isLinked(request.getIds())) {
throw new BizException("删除失败,该供应商已被使用");
}
this.repository.deleteAllById(request.getIds());
}