mirror of
https://github.com/zccbbg/wms-ruoyi.git
synced 2024-09-20 11:05:54 +08:00
库存看板分仓库维度、库区维度和物料维度
This commit is contained in:
parent
07f4918164
commit
575b342ed1
|
@ -1,35 +1,27 @@
|
|||
package com.cyl.wms.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.cyl.wms.convert.InventoryConvert;
|
||||
import com.cyl.wms.domain.Inventory;
|
||||
import com.cyl.wms.pojo.query.InventoryQuery;
|
||||
import com.cyl.wms.service.InventoryService;
|
||||
import com.cyl.wms.pojo.vo.InventoryVO;
|
||||
import com.cyl.wms.service.InventoryService;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* 库存Controller
|
||||
*
|
||||
*
|
||||
* @author zcc
|
||||
* @date 2022-08-05
|
||||
*/
|
||||
|
|
|
@ -1,19 +1,47 @@
|
|||
package com.cyl.wms.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.cyl.wms.domain.Inventory;
|
||||
import com.cyl.wms.domain.InventoryHistory;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cyl.wms.domain.InventoryHistory;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.cyl.wms.domain.Inventory;
|
||||
|
||||
/**
|
||||
* 库存Mapper接口
|
||||
*
|
||||
*
|
||||
* @author zcc
|
||||
*/
|
||||
public interface InventoryMapper extends BaseMapper<Inventory> {
|
||||
/**
|
||||
* 查询库存
|
||||
*
|
||||
* @param queryWrapper 库存
|
||||
* @return 库存集合
|
||||
*/
|
||||
List<Inventory> selectListGroupByWarehouseId(@Param(Constants.WRAPPER) Wrapper<Inventory> queryWrapper);
|
||||
|
||||
/**
|
||||
* 查询库存
|
||||
*
|
||||
* @param queryWrapper 库存
|
||||
* @return 库存集合
|
||||
*/
|
||||
List<Inventory> selectListGroupByAreaId(@Param(Constants.WRAPPER) QueryWrapper<Inventory> queryWrapper);
|
||||
|
||||
/**
|
||||
* 查询库存
|
||||
*
|
||||
* @param queryWrapper 库存
|
||||
* @return 库存集合
|
||||
*/
|
||||
List<Inventory> selectListGroupByItemTypeId(@Param(Constants.WRAPPER) QueryWrapper<Inventory> queryWrapper);
|
||||
|
||||
/**
|
||||
* 查询库存列表
|
||||
*
|
||||
|
@ -24,18 +52,23 @@ public interface InventoryMapper extends BaseMapper<Inventory> {
|
|||
|
||||
/**
|
||||
* 批量软删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
*/
|
||||
int updateDelFlagByIds(@Param("ids") Long[] ids);
|
||||
|
||||
int batchUpdateQuantityById(@Param("list") Collection<Inventory> list, @Param("updateTime") LocalDateTime updateTime, @Param("userId") Long userId);
|
||||
|
||||
List<Inventory> selectAllByWarehouseAndItemId(@Param("list") Collection<InventoryHistory> list);
|
||||
|
||||
List<Inventory> selectAllByAreaAndItemId(@Param("list") Collection<InventoryHistory> list);
|
||||
|
||||
List<Inventory> selectAllByRackAndItemId(@Param("list") Collection<InventoryHistory> list);
|
||||
|
||||
int batchInsert(@Param("list") Collection<Inventory> list);
|
||||
|
||||
List<Inventory> selectWarning();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.cyl.wms.pojo.query;
|
||||
|
||||
/*
|
||||
* 库存看盘类型
|
||||
* */
|
||||
public interface InventoryPanelType {
|
||||
// 仓库
|
||||
Long WAREHOUSE = 5L;
|
||||
|
||||
Long AREA = 10L;
|
||||
Long ITEMTYPE = 15L;
|
||||
|
||||
Long ITEM = 20L;
|
||||
}
|
|
@ -13,13 +13,16 @@ import java.math.BigDecimal;
|
|||
*/
|
||||
@ApiModel(description = "库存 查询 对象")
|
||||
@Data
|
||||
public class InventoryQuery {
|
||||
public class InventoryQuery implements InventoryPanelType {
|
||||
@ApiModelProperty("物料ID 精确匹配")
|
||||
private Long itemId;
|
||||
|
||||
@ApiModelProperty("货架id 精确匹配")
|
||||
private Long warehouseId;
|
||||
|
||||
@ApiModelProperty("看板类型")
|
||||
private Long panelType;
|
||||
|
||||
@ApiModelProperty("区 id")
|
||||
private Long areaId;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.cyl.wms.pojo.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.domain.BaseAudit;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
/**
|
||||
* 库存 数据视图对象
|
||||
*
|
||||
|
@ -22,6 +22,9 @@ public class InventoryVO extends BaseAudit implements AreaAndItemInfo {
|
|||
// 物料名称
|
||||
@Excel(name = "物料名称")
|
||||
private String itemName;
|
||||
// 物料类型
|
||||
@Excel(name = "物料类型")
|
||||
private String itemTypeName;
|
||||
/** 货架id */
|
||||
private Long rackId;
|
||||
// 货架 名称
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.cyl.wms.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.cyl.wms.convert.InventoryConvert;
|
||||
import com.cyl.wms.domain.*;
|
||||
|
@ -17,7 +18,6 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|||
import com.ruoyi.common.utils.SortUtil;
|
||||
import com.ruoyi.system.service.ISysDictDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -49,6 +49,8 @@ public class InventoryService {
|
|||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private ItemTypeService itemTypeService;
|
||||
@Autowired
|
||||
private ISysDictDataService sysDictDataService;
|
||||
|
||||
/**
|
||||
|
@ -70,31 +72,31 @@ public class InventoryService {
|
|||
*/
|
||||
public List<Inventory> selectList(InventoryQuery query, Pageable page) {
|
||||
if (page != null) {
|
||||
PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize(), SortUtil.sort2stringOrDefault(page.getSort()));
|
||||
PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
|
||||
}
|
||||
QueryWrapper<Inventory> qw = new QueryWrapper<>();
|
||||
qw.eq("del_flag" , 0);
|
||||
qw.eq("del_flag", 0);
|
||||
Long itemId = query.getItemId();
|
||||
if (itemId != null) {
|
||||
qw.eq("item_id" , itemId);
|
||||
qw.eq("item_id", itemId);
|
||||
}
|
||||
Long rackId = query.getRackId();
|
||||
if (rackId != null) {
|
||||
qw.eq("rack_id" , rackId);
|
||||
qw.eq("rack_id", rackId);
|
||||
}
|
||||
if (query.getWarehouseId() != null) {
|
||||
qw.eq("warehouse_id" , query.getWarehouseId());
|
||||
qw.eq("warehouse_id", query.getWarehouseId());
|
||||
}
|
||||
if (query.getAreaId() != null) {
|
||||
qw.eq("area_id" , query.getAreaId());
|
||||
qw.eq("area_id", query.getAreaId());
|
||||
}
|
||||
if (query.getQuantityStart() != null) {
|
||||
qw.ge("quantity" , query.getQuantityStart());
|
||||
qw.ge("quantity", query.getQuantityStart());
|
||||
}
|
||||
if (query.getQuantityEnd() != null) {
|
||||
qw.le("quantity" , query.getQuantityEnd());
|
||||
qw.le("quantity", query.getQuantityEnd());
|
||||
}
|
||||
return getInventoryList(qw);
|
||||
return getInventoryList(query.getPanelType(), qw);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,24 +151,51 @@ public class InventoryService {
|
|||
return inventoryMapper.updateDelFlagByIds(ids);
|
||||
}
|
||||
|
||||
public List<Inventory> getInventoryList(QueryWrapper<Inventory> qw){
|
||||
List<Inventory> items = inventoryMapper.selectList(qw);
|
||||
public List<Inventory> getInventoryList(Long panelType, QueryWrapper<Inventory> qw) {
|
||||
List<Inventory> items;
|
||||
if (Objects.equals(panelType, InventoryQuery.WAREHOUSE)) {
|
||||
items = inventoryMapper.selectListGroupByWarehouseId(qw);
|
||||
} else if (Objects.equals(panelType, InventoryQuery.AREA)) {
|
||||
items = inventoryMapper.selectListGroupByAreaId(qw);
|
||||
} else if (Objects.equals(panelType, InventoryQuery.ITEMTYPE)) {
|
||||
items = inventoryMapper.selectListGroupByItemTypeId(qw);
|
||||
} else {
|
||||
items = inventoryMapper.selectList(qw);
|
||||
}
|
||||
if (CollUtil.isEmpty(items)) {
|
||||
return items;
|
||||
}
|
||||
injectItemNoAndItemName(items);
|
||||
injectWarehouseName(items);
|
||||
injectAreaName(items);
|
||||
return items;
|
||||
}
|
||||
|
||||
private void injectItemType(List<InventoryVO> items) {
|
||||
if (CollUtil.isEmpty(items)) {
|
||||
return;
|
||||
}
|
||||
Set<Long> itemIds = items.stream().map(InventoryVO::getItemId).collect(Collectors.toSet());
|
||||
Map<Long,Long> itemIdAndTypeId = itemService.selectByIdIn(itemIds).stream().filter(item -> StrUtil.isNotBlank(item.getItemType())).collect(Collectors.toMap(Item::getId, it -> Long.parseLong(it.getItemType())));
|
||||
Map<Long, ItemType> itemTypeMap = itemTypeService.selectByIdIn(itemIdAndTypeId.values()).stream().collect(Collectors.toMap(ItemType::getItemTypeId, it -> it));
|
||||
items.forEach(it -> {
|
||||
Long type_key = itemIdAndTypeId.get(it.getItemId());
|
||||
if (it.getItemId() != null && itemTypeMap.containsKey(type_key)) {
|
||||
it.setItemTypeName(itemTypeMap.get(type_key).getTypeName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean canOutStock(Long itemId, Long warehouseId, Long areaId, Long rackId, BigDecimal quantity) {
|
||||
QueryWrapper<Inventory> qw = new QueryWrapper<>();
|
||||
qw.eq("item_id" , itemId)
|
||||
.eq("warehouse_id" , warehouseId)
|
||||
.ge("quantity" , quantity);
|
||||
qw.eq("item_id", itemId)
|
||||
.eq("warehouse_id", warehouseId)
|
||||
.ge("quantity", quantity);
|
||||
if (rackId != null) {
|
||||
qw.eq("rack_id" , rackId);
|
||||
qw.eq("rack_id", rackId);
|
||||
}
|
||||
if (areaId != null) {
|
||||
qw.eq("area_id" , areaId);
|
||||
qw.eq("area_id", areaId);
|
||||
}
|
||||
return inventoryMapper.selectCount(qw) > 0;
|
||||
}
|
||||
|
@ -271,6 +300,7 @@ public class InventoryService {
|
|||
List<Inventory> list = selectList(query, page);
|
||||
List<InventoryVO> res = inventoryConvert.dos2vos(list);
|
||||
injectAreaAndItemInfo(res);
|
||||
injectItemType(res);
|
||||
return new PageImpl<>(res, page, ((com.github.pagehelper.Page) list).getTotal());
|
||||
}
|
||||
|
||||
|
@ -325,7 +355,7 @@ public class InventoryService {
|
|||
}
|
||||
|
||||
public Page<InventoryVO> queryWarning(Pageable page) {
|
||||
if (page != null){
|
||||
if (page != null) {
|
||||
PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize(), SortUtil.sort2string(page.getSort()));
|
||||
}
|
||||
List<Inventory> inventories = inventoryMapper.selectWarning();
|
||||
|
@ -342,7 +372,7 @@ public class InventoryService {
|
|||
|
||||
public List<InventoryVO> queryAll() {
|
||||
InventoryQuery query = new InventoryQuery();
|
||||
List<Inventory> list = selectList(query,null);
|
||||
List<Inventory> list = selectList(query, null);
|
||||
List<InventoryVO> res = inventoryConvert.dos2vos(list);
|
||||
injectAreaAndItemInfo(res);
|
||||
return res;
|
||||
|
@ -369,16 +399,17 @@ public class InventoryService {
|
|||
|
||||
/**
|
||||
* 注入仓库名称
|
||||
*
|
||||
* @param res 物料
|
||||
*/
|
||||
public void injectWarehouseName(List<Inventory> res){
|
||||
if (CollUtil.isEmpty(res)){
|
||||
public void injectWarehouseName(List<Inventory> res) {
|
||||
if (CollUtil.isEmpty(res)) {
|
||||
return;
|
||||
}
|
||||
Set<Long> warehouses = res.stream().map(Inventory::getWarehouseId).collect(Collectors.toSet());
|
||||
Map<Long, Warehouse> warehouseMap = warehouseService.selectByIdIn(warehouses).stream().collect(Collectors.toMap(Warehouse::getId, it -> it));
|
||||
res.forEach(it -> {
|
||||
if (it.getWarehouseId() != null && warehouseMap.containsKey(it.getWarehouseId())){
|
||||
if (it.getWarehouseId() != null && warehouseMap.containsKey(it.getWarehouseId())) {
|
||||
it.setWarehouseName(warehouseMap.get(it.getWarehouseId()).getWarehouseName());
|
||||
}
|
||||
});
|
||||
|
@ -386,30 +417,31 @@ public class InventoryService {
|
|||
|
||||
/**
|
||||
* 注入库区名称
|
||||
*
|
||||
* @param res 物料
|
||||
*/
|
||||
public void injectAreaName(List<Inventory> res){
|
||||
if (CollUtil.isEmpty(res)){
|
||||
public void injectAreaName(List<Inventory> res) {
|
||||
if (CollUtil.isEmpty(res)) {
|
||||
return;
|
||||
}
|
||||
Set<Long> areas = res.stream().map(Inventory::getAreaId).collect(Collectors.toSet());
|
||||
Map<Long, Area> areaMap = areaService.selectByIdIn(areas).stream().collect(Collectors.toMap(Area::getId, it -> it));
|
||||
res.forEach(it -> {
|
||||
if (it.getAreaId() != null && areaMap.containsKey(it.getAreaId())){
|
||||
if (it.getAreaId() != null && areaMap.containsKey(it.getAreaId())) {
|
||||
it.setAreaName(areaMap.get(it.getAreaId()).getAreaName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void injectDictDataLabel(List<InventoryHistoryVO> res){
|
||||
if (CollUtil.isEmpty(res)){
|
||||
public void injectDictDataLabel(List<InventoryHistoryVO> res) {
|
||||
if (CollUtil.isEmpty(res)) {
|
||||
return;
|
||||
}
|
||||
Set<String> dictTypes = new HashSet<>();
|
||||
dictTypes.add("wms_inventory_oper_type");
|
||||
Map<String, SysDictData> sysDictDataMap = sysDictDataService.selectDictDataByTypes(dictTypes).stream().collect(Collectors.toMap(SysDictData::getDictValue, it -> it));
|
||||
res.forEach(it -> {
|
||||
if (it.getFormType() != null && sysDictDataMap.containsKey(String.valueOf(it.getFormType()))){
|
||||
if (it.getFormType() != null && sysDictDataMap.containsKey(String.valueOf(it.getFormType()))) {
|
||||
it.setFormTypeName(sysDictDataMap.get(String.valueOf(it.getFormType())).getDictLabel());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -98,6 +98,44 @@
|
|||
a.quantity<b.quantity
|
||||
]]>
|
||||
</select>
|
||||
<!-- -->
|
||||
<select id="selectListGroupByWarehouseId" resultMap="InventoryResult">
|
||||
SELECT wi.warehouse_id,
|
||||
wi.item_id,
|
||||
sum(wi.quantity) AS quantity
|
||||
FROM wms_inventory wi
|
||||
WHERE wi.del_flag = 0
|
||||
group by wi.warehouse_id,
|
||||
wi.item_id
|
||||
ORDER BY wi.warehouse_id,
|
||||
wi.item_id
|
||||
</select>
|
||||
<select id="selectListGroupByAreaId" resultMap="InventoryResult">
|
||||
SELECT wi.warehouse_id,
|
||||
wi.area_id,
|
||||
wi.item_id,
|
||||
sum(wi.quantity) AS quantity
|
||||
FROM wms_inventory wi
|
||||
WHERE wi.del_flag = 0
|
||||
group by wi.warehouse_id,
|
||||
wi.area_id,
|
||||
wi.item_id
|
||||
ORDER BY wi.warehouse_id,
|
||||
wi.area_id,
|
||||
wi.item_id
|
||||
</select>
|
||||
<select id="selectListGroupByItemTypeId" resultMap="InventoryResult">
|
||||
SELECT wi.warehouse_id,
|
||||
wi.area_id,
|
||||
wi.item_id,
|
||||
wi.quantity
|
||||
FROM wms_inventory wi
|
||||
left join wms_item_type wit on wit.item_type_id = wi.item_id
|
||||
WHERE wi.del_flag = 0
|
||||
|
||||
ORDER BY wit.item_type_id,
|
||||
wi.item_id desc
|
||||
</select>
|
||||
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
|
||||
insert into wms_inventory
|
||||
(item_id, rack_id, quantity, remark, del_flag, create_by, create_time, update_by, update_time, warehouse_id,
|
||||
|
|
Loading…
Reference in a new issue