diff --git a/src/main/java/com/gaotao/modules/warehouse/controller/WarehouseController.java b/src/main/java/com/gaotao/modules/warehouse/controller/WarehouseController.java index 33b199b..50cd1f8 100644 --- a/src/main/java/com/gaotao/modules/warehouse/controller/WarehouseController.java +++ b/src/main/java/com/gaotao/modules/warehouse/controller/WarehouseController.java @@ -3,9 +3,11 @@ package com.gaotao.modules.warehouse.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.gaotao.common.utils.PageUtils; import com.gaotao.common.utils.R; +import com.gaotao.modules.sys.entity.SysUserEntity; import com.gaotao.modules.warehouse.entity.*; import com.gaotao.modules.warehouse.service.WarehouseService; import io.lettuce.core.ScriptOutputType; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Map; @RequestMapping("/warehouse") @RestController @@ -251,4 +254,27 @@ public class WarehouseController { R r = warehouseService.transferInventoryStock(data); return r; } + + /** + * 根据用户名和工厂获取授权的仓库列表 + * @param params 包含site的参数 + * @return 仓库列表 + */ + @PostMapping("getUserAuthorizedWarehouses") + public R getUserAuthorizedWarehouses(@RequestBody Map params) { + try { + SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String userName = sysUserEntity.getUsername(); + String site = (String) params.get("site"); + + if (site == null || site.trim().isEmpty()) { + return R.error("工厂参数不能为空"); + } + + List> warehouseList = warehouseService.getUserAuthorizedWarehouses(userName, site.trim()); + return R.ok().put("data", warehouseList); + } catch (Exception e) { + return R.error("获取仓库列表失败"); + } + } } diff --git a/src/main/java/com/gaotao/modules/warehouse/dao/WarehouseMapper.java b/src/main/java/com/gaotao/modules/warehouse/dao/WarehouseMapper.java index 70837d2..8bd6dfe 100644 --- a/src/main/java/com/gaotao/modules/warehouse/dao/WarehouseMapper.java +++ b/src/main/java/com/gaotao/modules/warehouse/dao/WarehouseMapper.java @@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Map; @Mapper public interface WarehouseMapper extends BaseMapper { @@ -44,4 +45,12 @@ public interface WarehouseMapper extends BaseMapper { IPage getInventoryStockList(Page locationPage, @Param("params")InventoryPart data); IPage getInventoryStockManageList(Page page, @Param("params")InventoryStock data); + + /** + * 根据用户名和工厂获取用户授权的仓库列表(包含仓库名称) + * @param userName 用户名 + * @param site 工厂编码 + * @return 仓库列表 + */ + List> getUserAuthorizedWarehouses(@Param("userName") String userName, @Param("site") String site); } diff --git a/src/main/java/com/gaotao/modules/warehouse/service/WarehouseService.java b/src/main/java/com/gaotao/modules/warehouse/service/WarehouseService.java index ca0f203..6ff026b 100644 --- a/src/main/java/com/gaotao/modules/warehouse/service/WarehouseService.java +++ b/src/main/java/com/gaotao/modules/warehouse/service/WarehouseService.java @@ -6,6 +6,7 @@ import com.gaotao.common.utils.R; import com.gaotao.modules.warehouse.entity.*; import java.util.List; +import java.util.Map; public interface WarehouseService { List getWarehouseList(Warehouse data); @@ -45,4 +46,12 @@ public interface WarehouseService { InventoryStock getInventoryStockDetail(InventoryStock data); R transferInventoryStock(java.util.Map data); + + /** + * 根据用户名和工厂获取用户授权的仓库列表(包含仓库名称) + * @param userName 用户名 + * @param site 工厂编码 + * @return 仓库列表 + */ + List> getUserAuthorizedWarehouses(String userName, String site); } diff --git a/src/main/java/com/gaotao/modules/warehouse/service/impl/WarehouseServiceImpl.java b/src/main/java/com/gaotao/modules/warehouse/service/impl/WarehouseServiceImpl.java index b6cd23d..03d45e8 100644 --- a/src/main/java/com/gaotao/modules/warehouse/service/impl/WarehouseServiceImpl.java +++ b/src/main/java/com/gaotao/modules/warehouse/service/impl/WarehouseServiceImpl.java @@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Map; @Service public class WarehouseServiceImpl implements WarehouseService { @@ -137,7 +138,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, data.getPartNo()) .eq(InventoryStock::getBatchNo, data.getBatchNo()) .eq(InventoryStock::getLocationId, data.getLocationId()); - + InventoryStock existingStock = inventoryStockMapper.selectOne(queryWrapper); if (existingStock != null) { @@ -145,14 +146,14 @@ public class WarehouseServiceImpl implements WarehouseService { data.setFirstInDate(existingStock.getFirstInDate()); // 保持首次入库日期不变 data.setLatestInDate(new java.util.Date()); // 更新最近入库日期 data.setActiveDate(new java.util.Date()); // 更新活动日期 - + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.eq(InventoryStock::getSite, data.getSite()) .eq(InventoryStock::getWarehouseId, data.getWarehouseId()) .eq(InventoryStock::getPartNo, data.getPartNo()) .eq(InventoryStock::getBatchNo, data.getBatchNo()) .eq(InventoryStock::getLocationId, data.getLocationId()); - + inventoryStockMapper.update(data, updateWrapper); } else { // 创建新记录 @@ -179,7 +180,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, data.getPartNo()) .eq(InventoryStock::getBatchNo, data.getBatchNo()) .eq(InventoryStock::getLocationId, data.getLocationId()); - + int result = inventoryStockMapper.delete(queryWrapper); if (result > 0) { return R.ok().put("msg", "删除成功"); @@ -209,7 +210,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, partNo) .eq(InventoryStock::getBatchNo, batchNo) .eq(InventoryStock::getLocationId, locationId); - + InventoryStock existingStock = inventoryStockMapper.selectOne(queryWrapper); if (existingStock == null) { @@ -257,7 +258,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, data.getPartNo()) .eq(InventoryStock::getBatchNo, data.getBatchNo()) .eq(InventoryStock::getLocationId, data.getLocationId()); - + inventoryStockMapper.update(null, updateWrapper); String status = "Y".equals(data.getFreezeFlag()) ? "冻结" : "解冻"; return R.ok().put("msg", "库存" + status + "成功"); @@ -282,7 +283,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, partNo) .eq(InventoryStock::getBatchNo, batchNo) .eq(InventoryStock::getLocationId, locationId); - + InventoryStock existingStock = inventoryStockMapper.selectOne(queryWrapper); if (existingStock == null) { @@ -315,7 +316,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, data.getPartNo()) .eq(InventoryStock::getBatchNo, data.getBatchNo()) .eq(InventoryStock::getLocationId, data.getLocationId()); - + return inventoryStockMapper.selectOne(queryWrapper); } @@ -337,7 +338,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, partNo) .eq(InventoryStock::getBatchNo, batchNo) .eq(InventoryStock::getLocationId, fromLocationId); - + InventoryStock fromStock = inventoryStockMapper.selectOne(fromQueryWrapper); if (fromStock == null) { @@ -362,7 +363,7 @@ public class WarehouseServiceImpl implements WarehouseService { .eq(InventoryStock::getPartNo, partNo) .eq(InventoryStock::getBatchNo, batchNo) .eq(InventoryStock::getLocationId, toLocationId); - + InventoryStock toStock = inventoryStockMapper.selectOne(toQueryWrapper); if (toStock == null) { @@ -403,4 +404,9 @@ public class WarehouseServiceImpl implements WarehouseService { } } + @Override + public List> getUserAuthorizedWarehouses(String userName, String site) { + return warehouseMapper.getUserAuthorizedWarehouses(userName, site); + } + } diff --git a/src/main/resources/mapper/warehouse/WarehouseMapper.xml b/src/main/resources/mapper/warehouse/WarehouseMapper.xml index dc2d259..31b94bd 100644 --- a/src/main/resources/mapper/warehouse/WarehouseMapper.xml +++ b/src/main/resources/mapper/warehouse/WarehouseMapper.xml @@ -318,4 +318,19 @@ ORDER BY site, warehouse_id, part_no, batch_no, location_id + + +