feat(wms): 新增按实际库区查询钢卷分布功能
- 在 IWmsMaterialCoilService 接口中新增 getDistributionByActualWarehouse 方法 - 实现钢卷按实际库区统计数量和重量的查询逻辑 - 添加对应的 Mapper XML 查询语句,支持按物品类型和 ID 过滤 - 在 Controller 中暴露新的 REST 接口 /distributionByActualWarehouse - 扩展 WmsStockBo 和 WmsStockVo 类以支持实际库区相关字段 - 新增 queryPageListActual 方法用于分页查询实际库区库存数据 - 实现递归查询子实际库区的功能,并应用到查询条件中 - 更新 Mapper 文件及服务实现类以支持新查询逻辑
This commit is contained in:
@@ -135,6 +135,18 @@ public class WmsMaterialCoilController extends BaseController {
|
|||||||
return R.ok(distribution);
|
return R.ok(distribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询各个库区中不同类型的钢卷分布情况
|
||||||
|
* 按库区分组,统计每种物品类型和物品ID的钢卷数量和重量
|
||||||
|
*/
|
||||||
|
@GetMapping("/distributionByActualWarehouse")
|
||||||
|
public R<List<WmsMaterialCoilVo>> getDistributionByActualWarehouse(
|
||||||
|
@RequestParam(required = false) String itemType,
|
||||||
|
@RequestParam(required = false) Long itemId) {
|
||||||
|
List<WmsMaterialCoilVo> distribution = iWmsMaterialCoilService.getDistributionByActualWarehouse(itemType, itemId);
|
||||||
|
return R.ok(distribution);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询不同类型的钢卷在不同库区的分布情况
|
* 查询不同类型的钢卷在不同库区的分布情况
|
||||||
* 按物品类型和物品ID分组,统计每个库区的钢卷数量和重量
|
* 按物品类型和物品ID分组,统计每个库区的钢卷数量和重量
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ public class WmsStockController extends BaseController {
|
|||||||
public TableDataInfo<WmsStockVo> list(WmsStockBo bo, PageQuery pageQuery) {
|
public TableDataInfo<WmsStockVo> list(WmsStockBo bo, PageQuery pageQuery) {
|
||||||
return iWmsStockService.queryPageList(bo, pageQuery);
|
return iWmsStockService.queryPageList(bo, pageQuery);
|
||||||
}
|
}
|
||||||
|
@GetMapping("/listActual")
|
||||||
|
public TableDataInfo<WmsStockVo> listActual(WmsStockBo bo, PageQuery pageQuery) {
|
||||||
|
return iWmsStockService.queryPageListActual(bo, pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出库存:原材料/产品与库区/库位的存放关系列表
|
* 导出库存:原材料/产品与库区/库位的存放关系列表
|
||||||
|
|||||||
@@ -49,5 +49,7 @@ public class WmsStockBo extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
private Long actualWarehouseId;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,4 +95,8 @@ public class WmsStockVo {
|
|||||||
*/
|
*/
|
||||||
private java.util.List<WmsStockVo> stockDistribution;
|
private java.util.List<WmsStockVo> stockDistribution;
|
||||||
|
|
||||||
|
|
||||||
|
//实际库区/库位自关联
|
||||||
|
private Long actualWarehouseId;
|
||||||
|
private String actualWarehouseName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,5 +41,7 @@ public interface WmsMaterialCoilMapper extends BaseMapperPlus<WmsMaterialCoilMap
|
|||||||
Page<WmsMaterialCoilVo> selectVoPagePlus(Page<Object> build,@Param("ew") QueryWrapper<WmsMaterialCoil> lqw);
|
Page<WmsMaterialCoilVo> selectVoPagePlus(Page<Object> build,@Param("ew") QueryWrapper<WmsMaterialCoil> lqw);
|
||||||
|
|
||||||
List<WmsMaterialCoilVo> selectVoListWithDynamicJoin(@Param("ew")QueryWrapper<WmsMaterialCoil> lqw);
|
List<WmsMaterialCoilVo> selectVoListWithDynamicJoin(@Param("ew")QueryWrapper<WmsMaterialCoil> lqw);
|
||||||
|
|
||||||
|
List<Map<String, Object>> getDistributionByActualWarehouse(@Param("itemType") String itemType, @Param("itemId") Long itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.klp.mapper;
|
package com.klp.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.klp.common.core.validate.AddGroup;
|
import com.klp.common.core.validate.AddGroup;
|
||||||
import com.klp.common.core.validate.EditGroup;
|
import com.klp.common.core.validate.EditGroup;
|
||||||
import com.klp.domain.WmsStock;
|
import com.klp.domain.WmsStock;
|
||||||
@@ -34,4 +35,5 @@ public interface WmsStockMapper extends BaseMapperPlus<WmsStockMapper, WmsStock,
|
|||||||
*/
|
*/
|
||||||
List<WmsStockVo> selectStockDistribution(@Param("itemType") String itemType, @Param("itemId") Long itemId);
|
List<WmsStockVo> selectStockDistribution(@Param("itemType") String itemType, @Param("itemId") Long itemId);
|
||||||
|
|
||||||
|
Page<WmsStockVo> selectVoPagePlusActual(Page<Object> build,@Param("ew") Wrapper<WmsStock> lqw);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,5 +84,7 @@ public interface IWmsMaterialCoilService {
|
|||||||
* @return 分布情况列表,包含物品类型、物品ID、库区信息、数量、重量等
|
* @return 分布情况列表,包含物品类型、物品ID、库区信息、数量、重量等
|
||||||
*/
|
*/
|
||||||
List<WmsMaterialCoilVo> getDistributionByItemType(String itemType, Long itemId);
|
List<WmsMaterialCoilVo> getDistributionByItemType(String itemType, Long itemId);
|
||||||
|
|
||||||
|
List<WmsMaterialCoilVo> getDistributionByActualWarehouse(String itemType, Long itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,4 +58,5 @@ public interface IWmsStockService {
|
|||||||
*/
|
*/
|
||||||
WmsStockVo queryStockDistribution(WmsStockBo bo);
|
WmsStockVo queryStockDistribution(WmsStockBo bo);
|
||||||
|
|
||||||
|
TableDataInfo<WmsStockVo> queryPageListActual(WmsStockBo bo, PageQuery pageQuery);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1125,6 +1125,26 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
|||||||
return convertMapListToVoList(mapList);
|
return convertMapListToVoList(mapList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WmsMaterialCoilVo> getDistributionByActualWarehouse(String itemType, Long itemId) {
|
||||||
|
List<Map<String, Object>> mapList = baseMapper.getDistributionByActualWarehouse(itemType, itemId);
|
||||||
|
return convertMapListToVoListActual(mapList);
|
||||||
|
}
|
||||||
|
private List<WmsMaterialCoilVo> convertMapListToVoListActual(List<Map<String, Object>> mapList) {
|
||||||
|
List<WmsMaterialCoilVo> voList = new ArrayList<>();
|
||||||
|
for (Map<String, Object> map : mapList) {
|
||||||
|
WmsMaterialCoilVo vo = new WmsMaterialCoilVo();
|
||||||
|
vo.setActualWarehouseId(map.get("actual_warehouse_id") != null ? Long.valueOf(map.get("actual_warehouse_id").toString()) : null);
|
||||||
|
vo.setActualWarehouseName(map.get("actual_warehouse_name") != null ? map.get("actual_warehouse_name").toString() : null);
|
||||||
|
vo.setItemType(map.get("item_type") != null ? map.get("item_type").toString() : null);
|
||||||
|
vo.setItemId(map.get("item_id") != null ? Long.valueOf(map.get("item_id").toString()) : null);
|
||||||
|
vo.setCoilCount(map.get("coil_count") != null ? Long.valueOf(map.get("coil_count").toString()) : 0L);
|
||||||
|
vo.setTotalGrossWeight(map.get("total_gross_weight") != null ? new BigDecimal(map.get("total_gross_weight").toString()) : BigDecimal.ZERO);
|
||||||
|
vo.setTotalNetWeight(map.get("total_net_weight") != null ? new BigDecimal(map.get("total_net_weight").toString()) : BigDecimal.ZERO);
|
||||||
|
voList.add(vo);
|
||||||
|
}
|
||||||
|
return voList;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询不同类型的钢卷在不同库区的分布情况
|
* 查询不同类型的钢卷在不同库区的分布情况
|
||||||
* 按物品类型和物品ID分组,统计每个库区的钢卷数量和重量
|
* 按物品类型和物品ID分组,统计每个库区的钢卷数量和重量
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.klp.common.utils.StringUtils;
|
import com.klp.common.utils.StringUtils;
|
||||||
|
import com.klp.domain.WmsActualWarehouse;
|
||||||
|
import com.klp.mapper.WmsActualWarehouseMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.klp.domain.bo.WmsStockBo;
|
import com.klp.domain.bo.WmsStockBo;
|
||||||
@@ -33,6 +35,7 @@ public class WmsStockServiceImpl implements IWmsStockService {
|
|||||||
|
|
||||||
private final WmsStockMapper baseMapper;
|
private final WmsStockMapper baseMapper;
|
||||||
private final WmsWarehouseMapper warehouseMapper;
|
private final WmsWarehouseMapper warehouseMapper;
|
||||||
|
private final WmsActualWarehouseMapper actualWarehouseMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +56,70 @@ public class WmsStockServiceImpl implements IWmsStockService {
|
|||||||
return TableDataInfo.build(result);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<WmsStockVo> queryPageListActual(WmsStockBo bo, PageQuery pageQuery) {
|
||||||
|
QueryWrapper<WmsStock> lqw = buildQueryWrapperPlusActual(bo);
|
||||||
|
Page<WmsStockVo> result = baseMapper.selectVoPagePlusActual(pageQuery.build(), lqw);
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
private QueryWrapper<WmsStock> buildQueryWrapperPlusActual(WmsStockBo bo) { // 注意:这里改用 QueryWrapper 而非 LambdaQueryWrapper
|
||||||
|
QueryWrapper<WmsStock> qw = Wrappers.query(); // 使用普通 QueryWrapper
|
||||||
|
|
||||||
|
// 固定条件:未删除的现存数据
|
||||||
|
qw.eq("mc.del_flag", 0);
|
||||||
|
qw.eq("mc.data_type", 1);
|
||||||
|
|
||||||
|
// 处理仓库ID查询,支持递归查询子节点
|
||||||
|
if (bo.getActualWarehouseId() != null) {
|
||||||
|
List<Long> warehouseIds = getActualWarehouseIdsWithChildren(bo.getActualWarehouseId());
|
||||||
|
if (warehouseIds.size() == 1) {
|
||||||
|
qw.eq("mc.actual_warehouse_id", warehouseIds.get(0));
|
||||||
|
} else {
|
||||||
|
qw.in("mc.actual_warehouse_id", warehouseIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qw.eq(StringUtils.isNotBlank(bo.getItemType()), "mc.item_type", bo.getItemType());
|
||||||
|
qw.eq(bo.getItemId() != null, "mc.item_id", bo.getItemId());
|
||||||
|
qw.like(StringUtils.isNotBlank(bo.getBatchNo()), "mc.enter_coil_no", bo.getBatchNo());
|
||||||
|
|
||||||
|
// 使用 groupBy 进行分组
|
||||||
|
qw.groupBy(
|
||||||
|
"mc.actual_warehouse_id",
|
||||||
|
"mc.item_type",
|
||||||
|
"mc.item_id",
|
||||||
|
"w.actual_warehouse_name",
|
||||||
|
"CASE WHEN mc.item_type = 'product' THEN p.product_name WHEN mc.item_type = 'raw_material' THEN r.raw_material_name ELSE NULL END",
|
||||||
|
"CASE WHEN mc.item_type = 'product' THEN p.product_code WHEN mc.item_type = 'raw_material' THEN r.raw_material_code ELSE NULL END"
|
||||||
|
);
|
||||||
|
|
||||||
|
return qw;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Long> getActualWarehouseIdsWithChildren(Long actualWarehouseId) {
|
||||||
|
|
||||||
|
List<Long> actualWarehouseIds = new ArrayList<>();
|
||||||
|
actualWarehouseIds.add(actualWarehouseId); // 添加当前仓库ID
|
||||||
|
|
||||||
|
// 递归获取所有子仓库ID
|
||||||
|
getChildActualWarehouseIds(actualWarehouseId,actualWarehouseIds);
|
||||||
|
|
||||||
|
return actualWarehouseIds;
|
||||||
|
}
|
||||||
|
private void getChildActualWarehouseIds(Long parentId, List<Long> actualWarehouseIds) {
|
||||||
|
// 查询直接子仓库
|
||||||
|
List<WmsActualWarehouse> children = actualWarehouseMapper.selectList(
|
||||||
|
Wrappers.<WmsActualWarehouse>lambdaQuery()
|
||||||
|
.eq(WmsActualWarehouse::getActualParentId, parentId)
|
||||||
|
.eq(WmsActualWarehouse::getDelFlag, 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 递归处理每个子仓库
|
||||||
|
for (WmsActualWarehouse child : children) {
|
||||||
|
actualWarehouseIds.add(child.getActualWarehouseId());
|
||||||
|
getChildActualWarehouseIds(child.getActualWarehouseId(), actualWarehouseIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询库存:原材料/产品与库区/库位的存放关系列表
|
* 查询库存:原材料/产品与库区/库位的存放关系列表
|
||||||
*/
|
*/
|
||||||
@@ -182,6 +249,8 @@ public class WmsStockServiceImpl implements IWmsStockService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定仓库ID及其所有子仓库ID
|
* 获取指定仓库ID及其所有子仓库ID
|
||||||
* @param warehouseId 仓库ID
|
* @param warehouseId 仓库ID
|
||||||
|
|||||||
@@ -138,7 +138,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
LEFT JOIN wms_actual_warehouse aw ON mc.actual_warehouse_id = aw.actual_warehouse_id
|
LEFT JOIN wms_actual_warehouse aw ON mc.actual_warehouse_id = aw.actual_warehouse_id
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getDistributionByActualWarehouse" resultType="java.util.Map">
|
||||||
|
SELECT
|
||||||
|
w.actual_warehouse_id,
|
||||||
|
w.actual_warehouse_name,
|
||||||
|
COUNT(mc.coil_id) as coil_count,
|
||||||
|
COALESCE(SUM(mc.gross_weight), 0) as total_gross_weight,
|
||||||
|
COALESCE(SUM(mc.net_weight), 0) as total_net_weight
|
||||||
|
FROM wms_actual_warehouse w
|
||||||
|
LEFT JOIN wms_material_coil mc ON w.actual_warehouse_id = mc.actual_warehouse_id
|
||||||
|
AND mc.data_type = 1
|
||||||
|
AND mc.del_flag = '0'
|
||||||
|
WHERE w.del_flag = '0'
|
||||||
|
<if test="itemType != null and itemType != ''">
|
||||||
|
AND mc.item_type = #{itemType}
|
||||||
|
</if>
|
||||||
|
<if test="itemId != null">
|
||||||
|
AND mc.item_id = #{itemId}
|
||||||
|
</if>
|
||||||
|
GROUP BY w.actual_warehouse_id, w.actual_warehouse_name
|
||||||
|
ORDER BY w.actual_warehouse_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -65,5 +65,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
GROUP BY mc.warehouse_id, w.warehouse_name, mc.item_type, mc.item_id
|
GROUP BY mc.warehouse_id, w.warehouse_name, mc.item_type, mc.item_id
|
||||||
ORDER BY totalQuantity DESC
|
ORDER BY totalQuantity DESC
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectVoPagePlusActual" resultType="com.klp.domain.vo.WmsStockVo">
|
||||||
|
SELECT mc.actual_warehouse_id AS actualWarehouseId,
|
||||||
|
mc.item_type AS itemType,
|
||||||
|
mc.item_id AS itemId,
|
||||||
|
w.actual_warehouse_name AS actualWarehouseName,
|
||||||
|
CASE
|
||||||
|
WHEN mc.item_type = 'product' THEN p.product_name
|
||||||
|
WHEN mc.item_type = 'raw_material' THEN r.raw_material_name
|
||||||
|
ELSE NULL
|
||||||
|
END AS itemName,
|
||||||
|
CASE
|
||||||
|
WHEN mc.item_type = 'product' THEN p.product_code
|
||||||
|
WHEN mc.item_type = 'raw_material' THEN r.raw_material_code
|
||||||
|
ELSE NULL
|
||||||
|
END AS itemCode,
|
||||||
|
COUNT(*) AS totalQuantity,
|
||||||
|
SUM(CASE WHEN mc.status = 1 THEN 1 ELSE 0 END) AS onTheWay
|
||||||
|
FROM wms_material_coil mc
|
||||||
|
LEFT JOIN wms_actual_warehouse w ON mc.actual_warehouse_id = w.actual_warehouse_id AND w.del_flag = 0
|
||||||
|
LEFT JOIN wms_product p ON mc.item_type = 'product' AND mc.item_id = p.product_id AND p.del_flag = 0
|
||||||
|
LEFT JOIN wms_raw_material r
|
||||||
|
ON mc.item_type = 'raw_material' AND mc.item_id = r.raw_material_id AND r.del_flag = 0
|
||||||
|
${ew.customSqlSegment}
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user