fix:仓库、库区和库位增加删除校验(当还有相关库存时不能删除)
This commit is contained in:
parent
bf3d142ef8
commit
f1fceb2dc6
@ -106,8 +106,6 @@ public class WmStorageAreaController extends BaseController
|
||||
@DeleteMapping("/{areaIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] areaIds)
|
||||
{
|
||||
//TODO:库位删除之前的逻辑校验
|
||||
|
||||
return toAjax(wmStorageAreaService.deleteWmStorageAreaByAreaIds(areaIds));
|
||||
return wmStorageAreaService.deleteWmStorageAreaByAreaIds(areaIds);
|
||||
}
|
||||
}
|
||||
|
@ -112,12 +112,6 @@ public class WmStorageLocationController extends BaseController
|
||||
@DeleteMapping("/{locationIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] locationIds)
|
||||
{
|
||||
// //TODO:库区删除之前的逻辑校验
|
||||
//
|
||||
// for (Long locationId: locationIds
|
||||
// ) {
|
||||
// wmStorageAreaService.deleteByLocationId(locationId);
|
||||
// }
|
||||
return wmStorageLocationService.deleteWmStorageLocationByLocationIds(locationIds);
|
||||
}
|
||||
|
||||
|
@ -139,15 +139,6 @@ public class WmWarehouseController extends BaseController
|
||||
@DeleteMapping("/{warehouseIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] warehouseIds)
|
||||
{
|
||||
|
||||
//TODO:仓库删除之前的逻辑校验
|
||||
|
||||
for (Long wahouseId: warehouseIds
|
||||
) {
|
||||
wmStorageLocationService.deleteByWarehouseId(wahouseId);
|
||||
wmStorageAreaService.deleteByWarehouseId(wahouseId);
|
||||
}
|
||||
|
||||
return toAjax(wmWarehouseService.deleteWmWarehouseByWarehouseIds(warehouseIds));
|
||||
return wmWarehouseService.deleteWmWarehouseByWarehouseIds(warehouseIds);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.ktg.mes.wm.mapper;
|
||||
|
||||
import com.ktg.mes.wm.domain.WmMaterialStock;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -70,4 +71,20 @@ public interface WmMaterialStockMapper
|
||||
* @return 结果
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.ktg.mes.wm.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ktg.mes.wm.domain.WmStorageArea;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 库位设置Mapper接口
|
||||
@ -90,4 +91,8 @@ public interface WmStorageAreaMapper
|
||||
* @return
|
||||
*/
|
||||
public int deleteByLocationId(Long locationId);
|
||||
|
||||
List<WmStorageArea> selectByAreaIds(@Param("ids") Long[] areaIds);
|
||||
|
||||
int deleteByLocationIds(@Param("ids") Long[] locationIds);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.ktg.mes.wm.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ktg.mes.wm.domain.WmWarehouse;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 仓库设置Mapper接口
|
||||
@ -72,4 +73,10 @@ public interface WmWarehouseMapper
|
||||
*/
|
||||
public int deleteWmWarehouseByWarehouseIds(Long[] warehouseIds);
|
||||
|
||||
/**
|
||||
* 根据仓库id查询相关仓库数据
|
||||
* @param warehouseIds
|
||||
* @return
|
||||
*/
|
||||
List<WmWarehouse> selectByWarehouseId(@Param("ids") Long[] warehouseIds);
|
||||
}
|
||||
|
@ -100,4 +100,34 @@ public class WmMaterialStockServiceImpl implements IWmMaterialStockService
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
package com.ktg.mes.wm.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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.mes.wm.domain.WmMaterialStock;
|
||||
import com.ktg.mes.wm.service.IWmMaterialStockService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ktg.mes.wm.mapper.WmStorageAreaMapper;
|
||||
@ -20,6 +27,9 @@ public class WmStorageAreaServiceImpl implements IWmStorageAreaService
|
||||
@Autowired
|
||||
private WmStorageAreaMapper wmStorageAreaMapper;
|
||||
|
||||
@Autowired
|
||||
private IWmMaterialStockService wmMaterialStockService;
|
||||
|
||||
/**
|
||||
* 查询库位设置
|
||||
*
|
||||
@ -98,9 +108,34 @@ public class WmStorageAreaServiceImpl implements IWmStorageAreaService
|
||||
* @return 结果
|
||||
*/
|
||||
@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) {
|
||||
return wmStorageAreaMapper.deleteByLocationId(locationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByLocationIds(Long[] locationIds) {
|
||||
return wmStorageAreaMapper.deleteByLocationIds(locationIds);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,23 @@
|
||||
package com.ktg.mes.wm.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.common.utils.DateUtils;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ktg.mes.wm.mapper.WmStorageLocationMapper;
|
||||
import com.ktg.mes.wm.domain.WmStorageLocation;
|
||||
import com.ktg.mes.wm.service.IWmStorageLocationService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 库区设置Service业务层处理
|
||||
@ -28,6 +34,9 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
|
||||
@Autowired
|
||||
private IWmStorageAreaService wmStorageAreaService;
|
||||
|
||||
@Autowired
|
||||
private IWmMaterialStockService wmMaterialStockService;
|
||||
|
||||
/**
|
||||
* 查询库区设置
|
||||
*
|
||||
@ -110,6 +119,7 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public AjaxResult deleteWmStorageLocationByLocationIds(Long[] locationIds)
|
||||
{
|
||||
// 查询所有需要删除的数据
|
||||
@ -117,14 +127,27 @@ public class WmStorageLocationServiceImpl implements IWmStorageLocationService
|
||||
for (WmStorageLocation item : list) {
|
||||
String locationCode = item.getLocationCode();
|
||||
if (locationCode.contains("VIRTUAL")) {
|
||||
return AjaxResult.error("线边库库区不能被删除");
|
||||
return AjaxResult.error("虚拟库区不能被删除");
|
||||
}
|
||||
}
|
||||
|
||||
for (Long locationId: locationIds
|
||||
) {
|
||||
wmStorageAreaService.deleteByLocationId(locationId);
|
||||
// 校验库区中是否存在物料
|
||||
for (Long locationId : locationIds) {
|
||||
// 根据库区查询相关数据
|
||||
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);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
@ -1,21 +1,28 @@
|
||||
package com.ktg.mes.wm.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.common.utils.DateUtils;
|
||||
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.WmStorageLocation;
|
||||
import com.ktg.mes.wm.mapper.WmStorageAreaMapper;
|
||||
import com.ktg.mes.wm.mapper.WmStorageLocationMapper;
|
||||
import org.apache.catalina.User;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import com.ktg.mes.wm.service.IWmMaterialStockService;
|
||||
import com.ktg.mes.wm.service.IWmStorageAreaService;
|
||||
import com.ktg.mes.wm.service.IWmStorageLocationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ktg.mes.wm.mapper.WmWarehouseMapper;
|
||||
import com.ktg.mes.wm.domain.WmWarehouse;
|
||||
import com.ktg.mes.wm.service.IWmWarehouseService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 仓库设置Service业务层处理
|
||||
@ -35,6 +42,15 @@ public class WmWarehouseServiceImpl implements IWmWarehouseService
|
||||
@Autowired
|
||||
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 结果
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,6 +144,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</where>
|
||||
and 1=1 limit 1
|
||||
</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 into wm_material_stock
|
||||
|
@ -60,6 +60,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectWmStorageAreaVo"/>
|
||||
where area_code = #{areaCode}
|
||||
</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 into wm_storage_area
|
||||
@ -169,5 +176,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<delete id="deleteByLocationId" parameterType="Long">
|
||||
delete from wm_storage_area where location_id = #{locationId}
|
||||
</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>
|
@ -90,6 +90,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectWmWarehouseVo"/>
|
||||
where warehouse_name = #{warehouseName} limit 1
|
||||
</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 into wm_warehouse
|
||||
|
Loading…
Reference in New Issue
Block a user