fix:仓库、库区和库位增加删除校验(当还有相关库存时不能删除)

This commit is contained in:
zhangxuanming 2025-02-10 15:09:28 +08:00
parent bf3d142ef8
commit f1fceb2dc6
13 changed files with 216 additions and 33 deletions

View File

@ -106,8 +106,6 @@ public class WmStorageAreaController extends BaseController
@DeleteMapping("/{areaIds}") @DeleteMapping("/{areaIds}")
public AjaxResult remove(@PathVariable Long[] areaIds) public AjaxResult remove(@PathVariable Long[] areaIds)
{ {
//TODO:库位删除之前的逻辑校验 return wmStorageAreaService.deleteWmStorageAreaByAreaIds(areaIds);
return toAjax(wmStorageAreaService.deleteWmStorageAreaByAreaIds(areaIds));
} }
} }

View File

@ -112,12 +112,6 @@ public class WmStorageLocationController extends BaseController
@DeleteMapping("/{locationIds}") @DeleteMapping("/{locationIds}")
public AjaxResult remove(@PathVariable Long[] locationIds) public AjaxResult remove(@PathVariable Long[] locationIds)
{ {
// //TODO:库区删除之前的逻辑校验
//
// for (Long locationId: locationIds
// ) {
// wmStorageAreaService.deleteByLocationId(locationId);
// }
return wmStorageLocationService.deleteWmStorageLocationByLocationIds(locationIds); return wmStorageLocationService.deleteWmStorageLocationByLocationIds(locationIds);
} }

View File

@ -139,15 +139,6 @@ public class WmWarehouseController extends BaseController
@DeleteMapping("/{warehouseIds}") @DeleteMapping("/{warehouseIds}")
public AjaxResult remove(@PathVariable Long[] warehouseIds) public AjaxResult remove(@PathVariable Long[] warehouseIds)
{ {
return wmWarehouseService.deleteWmWarehouseByWarehouseIds(warehouseIds);
//TODO:仓库删除之前的逻辑校验
for (Long wahouseId: warehouseIds
) {
wmStorageLocationService.deleteByWarehouseId(wahouseId);
wmStorageAreaService.deleteByWarehouseId(wahouseId);
}
return toAjax(wmWarehouseService.deleteWmWarehouseByWarehouseIds(warehouseIds));
} }
} }

View File

@ -1,6 +1,7 @@
package com.ktg.mes.wm.mapper; package com.ktg.mes.wm.mapper;
import com.ktg.mes.wm.domain.WmMaterialStock; import com.ktg.mes.wm.domain.WmMaterialStock;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -70,4 +71,20 @@ public interface WmMaterialStockMapper
* @return 结果 * @return 结果
*/ */
public int deleteWmMaterialStockByMaterialStockIds(Long[] materialStockIds); public int deleteWmMaterialStockByMaterialStockIds(Long[] materialStockIds);
/**
* 根据库位id查询相关库存现有量数据
* @param areaId
* @return
*/
List<WmMaterialStock> getByAreaId(@Param("areaId") Long areaId);
/**
* 根据库区id查询相关库存现有量
* @param locationId
* @return
*/
List<WmMaterialStock> getLocationId(@Param("locationId") Long locationId);
List<WmMaterialStock> getByWarehouseId(@Param("warehouseId") Long warehouseId);
} }

View File

@ -2,6 +2,7 @@ package com.ktg.mes.wm.mapper;
import java.util.List; import java.util.List;
import com.ktg.mes.wm.domain.WmStorageArea; import com.ktg.mes.wm.domain.WmStorageArea;
import org.apache.ibatis.annotations.Param;
/** /**
* 库位设置Mapper接口 * 库位设置Mapper接口
@ -90,4 +91,8 @@ public interface WmStorageAreaMapper
* @return * @return
*/ */
public int deleteByLocationId(Long locationId); public int deleteByLocationId(Long locationId);
List<WmStorageArea> selectByAreaIds(@Param("ids") Long[] areaIds);
int deleteByLocationIds(@Param("ids") Long[] locationIds);
} }

View File

@ -2,6 +2,7 @@ package com.ktg.mes.wm.mapper;
import java.util.List; import java.util.List;
import com.ktg.mes.wm.domain.WmWarehouse; import com.ktg.mes.wm.domain.WmWarehouse;
import org.apache.ibatis.annotations.Param;
/** /**
* 仓库设置Mapper接口 * 仓库设置Mapper接口
@ -72,4 +73,10 @@ public interface WmWarehouseMapper
*/ */
public int deleteWmWarehouseByWarehouseIds(Long[] warehouseIds); public int deleteWmWarehouseByWarehouseIds(Long[] warehouseIds);
/**
* 根据仓库id查询相关仓库数据
* @param warehouseIds
* @return
*/
List<WmWarehouse> selectByWarehouseId(@Param("ids") Long[] warehouseIds);
} }

View File

@ -100,4 +100,34 @@ public class WmMaterialStockServiceImpl implements IWmMaterialStockService
{ {
return wmMaterialStockMapper.deleteWmMaterialStockByMaterialStockId(materialStockId); return wmMaterialStockMapper.deleteWmMaterialStockByMaterialStockId(materialStockId);
} }
/**
* 根据库位id查询相关库存现有量数据
* @param areaId
* @return
*/
@Override
public List<WmMaterialStock> getByAreaId(Long areaId) {
return wmMaterialStockMapper.getByAreaId(areaId);
}
/**
* 根据库区id查询相关库存现有量
* @param locationId
* @return
*/
@Override
public List<WmMaterialStock> getLocationId(Long locationId) {
return wmMaterialStockMapper.getLocationId(locationId);
}
/**
* 根据仓库id查询相关库存现有量
* @param warehouseId
* @return
*/
@Override
public List<WmMaterialStock> getByWarehouseId(Long warehouseId) {
return wmMaterialStockMapper.getByWarehouseId(warehouseId);
}
} }

View File

@ -1,7 +1,14 @@
package com.ktg.mes.wm.service.impl; package com.ktg.mes.wm.service.impl;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.utils.DateUtils; import com.ktg.common.utils.DateUtils;
import com.ktg.mes.wm.domain.WmMaterialStock;
import com.ktg.mes.wm.service.IWmMaterialStockService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.WmStorageAreaMapper; import com.ktg.mes.wm.mapper.WmStorageAreaMapper;
@ -20,6 +27,9 @@ public class WmStorageAreaServiceImpl implements IWmStorageAreaService
@Autowired @Autowired
private WmStorageAreaMapper wmStorageAreaMapper; private WmStorageAreaMapper wmStorageAreaMapper;
@Autowired
private IWmMaterialStockService wmMaterialStockService;
/** /**
* 查询库位设置 * 查询库位设置
* *
@ -98,9 +108,34 @@ public class WmStorageAreaServiceImpl implements IWmStorageAreaService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteWmStorageAreaByAreaIds(Long[] areaIds) public AjaxResult deleteWmStorageAreaByAreaIds(Long[] areaIds)
{ {
return wmStorageAreaMapper.deleteWmStorageAreaByAreaIds(areaIds); // 查询所有删除数据
List<WmStorageArea> areaList = wmStorageAreaMapper.selectByAreaIds(areaIds);
for (WmStorageArea item : areaList) {
String areaCode = item.getAreaCode();
if (areaCode.contains("VIRTUAL")) {
return AjaxResult.error("虚拟库位不能删除");
}
}
// 校验库位中是否存在物料
for (Long areaId : areaIds) {
// 根据库位查询相关数据
List<WmMaterialStock> list = wmMaterialStockService.getByAreaId(areaId);
if (list != null && list.size() > 0) {
Map<Long, List<WmMaterialStock>> collect = list.stream()
.collect(Collectors.groupingBy(WmMaterialStock::getItemId));
for (Long l : collect.keySet()) {
List<WmMaterialStock> wmMaterialStocks = collect.get(l);
BigDecimal reduce = wmMaterialStocks.stream().map(WmMaterialStock::getQuantityOnhand).reduce(BigDecimal.ZERO, BigDecimal::add);
if (!(reduce.compareTo(BigDecimal.ZERO) == 0)) {
return AjaxResult.error("库位中还有库存不能删除");
}
}
}
}
return AjaxResult.success(wmStorageAreaMapper.deleteWmStorageAreaByAreaIds(areaIds));
} }
/** /**
@ -124,4 +159,9 @@ public class WmStorageAreaServiceImpl implements IWmStorageAreaService
public int deleteByLocationId(Long locationId) { public int deleteByLocationId(Long locationId) {
return wmStorageAreaMapper.deleteByLocationId(locationId); return wmStorageAreaMapper.deleteByLocationId(locationId);
} }
@Override
public int deleteByLocationIds(Long[] locationIds) {
return wmStorageAreaMapper.deleteByLocationIds(locationIds);
}
} }

View File

@ -1,17 +1,23 @@
package com.ktg.mes.wm.service.impl; package com.ktg.mes.wm.service.impl;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.ktg.common.constant.UserConstants; import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.AjaxResult; import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.utils.DateUtils; import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils; import com.ktg.common.utils.StringUtils;
import com.ktg.mes.wm.domain.WmMaterialStock;
import com.ktg.mes.wm.service.IWmMaterialStockService;
import com.ktg.mes.wm.service.IWmStorageAreaService; import com.ktg.mes.wm.service.IWmStorageAreaService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.WmStorageLocationMapper; import com.ktg.mes.wm.mapper.WmStorageLocationMapper;
import com.ktg.mes.wm.domain.WmStorageLocation; import com.ktg.mes.wm.domain.WmStorageLocation;
import com.ktg.mes.wm.service.IWmStorageLocationService; import com.ktg.mes.wm.service.IWmStorageLocationService;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 库区设置Service业务层处理 * 库区设置Service业务层处理
@ -28,6 +34,9 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
@Autowired @Autowired
private IWmStorageAreaService wmStorageAreaService; private IWmStorageAreaService wmStorageAreaService;
@Autowired
private IWmMaterialStockService wmMaterialStockService;
/** /**
* 查询库区设置 * 查询库区设置
* *
@ -110,6 +119,7 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional
public AjaxResult deleteWmStorageLocationByLocationIds(Long[] locationIds) public AjaxResult deleteWmStorageLocationByLocationIds(Long[] locationIds)
{ {
// 查询所有需要删除的数据 // 查询所有需要删除的数据
@ -117,14 +127,27 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
for (WmStorageLocation item : list) { for (WmStorageLocation item : list) {
String locationCode = item.getLocationCode(); String locationCode = item.getLocationCode();
if (locationCode.contains("VIRTUAL")) { if (locationCode.contains("VIRTUAL")) {
return AjaxResult.error("线边库库区不能被删除"); return AjaxResult.error("虚拟库区不能被删除");
} }
} }
// 校验库区中是否存在物料
for (Long locationId: locationIds for (Long locationId : locationIds) {
) { // 根据库区查询相关数据
wmStorageAreaService.deleteByLocationId(locationId); List<WmMaterialStock> materialStocks = wmMaterialStockService.getLocationId(locationId);
if (materialStocks != null && materialStocks.size() > 0) {
Map<Long, List<WmMaterialStock>> collect = materialStocks.stream()
.collect(Collectors.groupingBy(WmMaterialStock::getItemId));
for (Long l : collect.keySet()) {
List<WmMaterialStock> wmMaterialStocks = collect.get(l);
BigDecimal reduce = wmMaterialStocks.stream().map(WmMaterialStock::getQuantityOnhand).reduce(BigDecimal.ZERO, BigDecimal::add);
if (!(reduce.compareTo(BigDecimal.ZERO) == 0)) {
return AjaxResult.error("库区中还有库存不能删除");
} }
}
}
}
// 关联删除相关库位
wmStorageAreaService.deleteByLocationIds(locationIds);
wmStorageLocationMapper.deleteWmStorageLocationByLocationIds(locationIds); wmStorageLocationMapper.deleteWmStorageLocationByLocationIds(locationIds);
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -1,21 +1,28 @@
package com.ktg.mes.wm.service.impl; package com.ktg.mes.wm.service.impl;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.ktg.common.constant.UserConstants; import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.utils.DateUtils; import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils; import com.ktg.common.utils.StringUtils;
import com.ktg.mes.wm.domain.WmMaterialStock;
import com.ktg.mes.wm.domain.WmStorageArea; import com.ktg.mes.wm.domain.WmStorageArea;
import com.ktg.mes.wm.domain.WmStorageLocation; import com.ktg.mes.wm.domain.WmStorageLocation;
import com.ktg.mes.wm.mapper.WmStorageAreaMapper; import com.ktg.mes.wm.mapper.WmStorageAreaMapper;
import com.ktg.mes.wm.mapper.WmStorageLocationMapper; import com.ktg.mes.wm.mapper.WmStorageLocationMapper;
import org.apache.catalina.User; import com.ktg.mes.wm.service.IWmMaterialStockService;
import org.checkerframework.checker.units.qual.A; import com.ktg.mes.wm.service.IWmStorageAreaService;
import com.ktg.mes.wm.service.IWmStorageLocationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.WmWarehouseMapper; import com.ktg.mes.wm.mapper.WmWarehouseMapper;
import com.ktg.mes.wm.domain.WmWarehouse; import com.ktg.mes.wm.domain.WmWarehouse;
import com.ktg.mes.wm.service.IWmWarehouseService; import com.ktg.mes.wm.service.IWmWarehouseService;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 仓库设置Service业务层处理 * 仓库设置Service业务层处理
@ -35,6 +42,15 @@ public class WmWarehouseServiceImpl implements IWmWarehouseService
@Autowired @Autowired
private WmStorageAreaMapper wmStorageAreaMapper; private WmStorageAreaMapper wmStorageAreaMapper;
@Autowired
private IWmMaterialStockService wmMaterialStockService;
@Autowired
private IWmStorageLocationService wmStorageLocationService;
@Autowired
private IWmStorageAreaService wmStorageAreaService;
/** /**
* 查询仓库设置 * 查询仓库设置
* *
@ -122,9 +138,38 @@ public class WmWarehouseServiceImpl implements IWmWarehouseService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteWmWarehouseByWarehouseIds(Long[] warehouseIds) @Transactional
public AjaxResult deleteWmWarehouseByWarehouseIds(Long[] warehouseIds)
{ {
return wmWarehouseMapper.deleteWmWarehouseByWarehouseIds(warehouseIds); // 查询所有需要删除的数据
List<WmWarehouse> warehouseList = wmWarehouseMapper.selectByWarehouseId(warehouseIds);
for (WmWarehouse item : warehouseList) {
String warehouseCode = item.getWarehouseCode();
if (warehouseCode.contains("VIRTUAL")) {
return AjaxResult.error("虚拟仓库不能被删除");
}
}
// 校验仓库中是否存在物料
for (Long warehouseId : warehouseIds) {
// 根据仓库id查询相关数据
List<WmMaterialStock> materialStocks = wmMaterialStockService.getByWarehouseId(warehouseId);
if (materialStocks != null && materialStocks.size() > 0) {
Map<Long, List<WmMaterialStock>> collect = materialStocks.stream()
.collect(Collectors.groupingBy(WmMaterialStock::getItemId));
for (Long l : collect.keySet()) {
List<WmMaterialStock> wmMaterialStocks = collect.get(l);
BigDecimal reduce = wmMaterialStocks.stream().map(WmMaterialStock::getQuantityOnhand).reduce(BigDecimal.ZERO, BigDecimal::add);
if (!(reduce.compareTo(BigDecimal.ZERO) == 0)) {
return AjaxResult.error("库区中还有库存不能删除");
}
}
}
}
for (Long wahouseId: warehouseIds) {
wmStorageAreaService.deleteByWarehouseId(wahouseId);
wmStorageLocationService.deleteByWarehouseId(wahouseId);
}
return AjaxResult.success(wmWarehouseMapper.deleteWmWarehouseByWarehouseIds(warehouseIds));
} }
/** /**

View File

@ -144,6 +144,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> </where>
and 1=1 limit 1 and 1=1 limit 1
</select> </select>
<select id="getByAreaId" resultType="com.ktg.mes.wm.domain.WmMaterialStock" resultMap="WmMaterialStockResult">
select * from wm_material_stock
where area_id = #{areaId}
</select>
<select id="getLocationId" resultType="com.ktg.mes.wm.domain.WmMaterialStock" resultMap="WmMaterialStockResult">
select * from wm_material_stock
where location_id = #{locationId}
</select>
<select id="getByWarehouseId" resultType="com.ktg.mes.wm.domain.WmMaterialStock" resultMap="WmMaterialStockResult">
select * from wm_material_stock
where warehouse_id = #{warehouseId}
</select>
<insert id="insertWmMaterialStock" parameterType="WmMaterialStock" useGeneratedKeys="true" keyProperty="materialStockId"> <insert id="insertWmMaterialStock" parameterType="WmMaterialStock" useGeneratedKeys="true" keyProperty="materialStockId">
insert into wm_material_stock insert into wm_material_stock

View File

@ -60,6 +60,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectWmStorageAreaVo"/> <include refid="selectWmStorageAreaVo"/>
where area_code = #{areaCode} where area_code = #{areaCode}
</select> </select>
<select id="selectByAreaIds" resultType="com.ktg.mes.wm.domain.WmStorageArea" resultMap="WmStorageAreaResult">
<include refid="selectWmStorageAreaVo"/>
where area_id in
<foreach collection="ids" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</select>
<insert id="insertWmStorageArea" parameterType="WmStorageArea" useGeneratedKeys="true" keyProperty="areaId"> <insert id="insertWmStorageArea" parameterType="WmStorageArea" useGeneratedKeys="true" keyProperty="areaId">
insert into wm_storage_area insert into wm_storage_area
@ -169,5 +176,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deleteByLocationId" parameterType="Long"> <delete id="deleteByLocationId" parameterType="Long">
delete from wm_storage_area where location_id = #{locationId} delete from wm_storage_area where location_id = #{locationId}
</delete> </delete>
<delete id="deleteByLocationIds" parameterType="Long">
delete from wm_storage_area
where location_id in
<foreach collection="ids" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</delete>
</mapper> </mapper>

View File

@ -90,6 +90,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectWmWarehouseVo"/> <include refid="selectWmWarehouseVo"/>
where warehouse_name = #{warehouseName} limit 1 where warehouse_name = #{warehouseName} limit 1
</select> </select>
<select id="selectByWarehouseId" resultType="com.ktg.mes.wm.domain.WmWarehouse" resultMap="WmWarehouseResult">
<include refid="selectWmWarehouseVo"/>
where warehouse_id in
<foreach collection="ids" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</select>
<insert id="insertWmWarehouse" parameterType="WmWarehouse" useGeneratedKeys="true" keyProperty="warehouseId"> <insert id="insertWmWarehouse" parameterType="WmWarehouse" useGeneratedKeys="true" keyProperty="warehouseId">
insert into wm_warehouse insert into wm_warehouse