|
@@ -66,17 +66,20 @@ public class ReplenisherOperationController {
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/device/list")
|
|
@GetMapping("/device/list")
|
|
|
public Result<List<Map<String, Object>>> getDeviceList() {
|
|
public Result<List<Map<String, Object>>> getDeviceList() {
|
|
|
- Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
-
|
|
|
|
|
- // 获取补货员绑定的设备ID列表
|
|
|
|
|
- List<String> deviceIds = replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
|
|
+ List<String> deviceIds = getAccessibleDeviceIds();
|
|
|
if (deviceIds.isEmpty()) {
|
|
if (deviceIds.isEmpty()) {
|
|
|
return Result.success("查询成功", new ArrayList<>());
|
|
return Result.success("查询成功", new ArrayList<>());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ boolean isAdmin = isAdmin();
|
|
|
|
|
+ Long operatorId = null;
|
|
|
|
|
+ if (!isAdmin) {
|
|
|
|
|
+ operatorId = getCurrentReplenisher().getId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 批量统计各设备补货单数量
|
|
// 批量统计各设备补货单数量
|
|
|
- Map<String, Long> pendingOrderCountMap = new java.util.HashMap<>(); // 草稿+已提交+已同步
|
|
|
|
|
- Map<String, Long> submittedOrderCountMap = new java.util.HashMap<>(); // 已提交+已同步(不含草稿)
|
|
|
|
|
|
|
+ Map<String, Long> pendingOrderCountMap = new java.util.HashMap<>();
|
|
|
|
|
+ Map<String, Long> submittedOrderCountMap = new java.util.HashMap<>();
|
|
|
if (!deviceIds.isEmpty()) {
|
|
if (!deviceIds.isEmpty()) {
|
|
|
var qwAll = new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<ReplenishmentOrder>()
|
|
var qwAll = new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<ReplenishmentOrder>()
|
|
|
.select("device_id", "status", "COUNT(*) as cnt")
|
|
.select("device_id", "status", "COUNT(*) as cnt")
|
|
@@ -123,15 +126,15 @@ public class ReplenisherOperationController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 批量统计今日已补货设备(上货类型、当前补货员、今天)
|
|
|
|
|
|
|
+ // 批量统计今日已补货设备
|
|
|
java.time.LocalDate today = java.time.LocalDate.now();
|
|
java.time.LocalDate today = java.time.LocalDate.now();
|
|
|
Map<String, Boolean> todayRestockedMap = new java.util.HashMap<>();
|
|
Map<String, Boolean> todayRestockedMap = new java.util.HashMap<>();
|
|
|
- if (!deviceIds.isEmpty()) {
|
|
|
|
|
|
|
+ if (!deviceIds.isEmpty() && !isAdmin) {
|
|
|
var logQw = new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<InventoryLog>()
|
|
var logQw = new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<InventoryLog>()
|
|
|
.select("DISTINCT device_id")
|
|
.select("DISTINCT device_id")
|
|
|
.in("device_id", deviceIds)
|
|
.in("device_id", deviceIds)
|
|
|
.eq("change_type", InventoryLog.TYPE_RESTOCK)
|
|
.eq("change_type", InventoryLog.TYPE_RESTOCK)
|
|
|
- .eq("operator_id", replenisher.getId())
|
|
|
|
|
|
|
+ .eq("operator_id", operatorId)
|
|
|
.ge("create_time", today.atStartOfDay())
|
|
.ge("create_time", today.atStartOfDay())
|
|
|
.lt("create_time", today.plusDays(1).atStartOfDay());
|
|
.lt("create_time", today.plusDays(1).atStartOfDay());
|
|
|
List<Map<String, Object>> logRows = inventoryLogService.listMaps(logQw);
|
|
List<Map<String, Object>> logRows = inventoryLogService.listMaps(logQw);
|
|
@@ -204,9 +207,7 @@ public class ReplenisherOperationController {
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/device/{deviceId}/pending-orders")
|
|
@GetMapping("/device/{deviceId}/pending-orders")
|
|
|
public Result<List<Map<String, Object>>> getDevicePendingOrders(@PathVariable String deviceId) {
|
|
public Result<List<Map<String, Object>>> getDevicePendingOrders(@PathVariable String deviceId) {
|
|
|
- Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
- List<String> boundIds = replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
- if (!boundIds.contains(deviceId)) {
|
|
|
|
|
|
|
+ if (!canAccessDevice(deviceId)) {
|
|
|
return Result.error(403, "您无权查看此设备");
|
|
return Result.error(403, "您无权查看此设备");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -247,6 +248,24 @@ public class ReplenisherOperationController {
|
|
|
return success ? Result.success("开门指令已发送", null) : Result.error(500, "开门失败");
|
|
return success ? Result.success("开门指令已发送", null) : Result.error(500, "开门失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询设备门状态(轻量轮询用)
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/device/{deviceId}/status")
|
|
|
|
|
+ public Result<Map<String, Object>> getDeviceStatus(@PathVariable String deviceId) {
|
|
|
|
|
+ if (!canAccessDevice(deviceId)) {
|
|
|
|
|
+ return Result.error(403, "您无权查看此设备");
|
|
|
|
|
+ }
|
|
|
|
|
+ Device device = deviceService.getDeviceBySn(deviceId);
|
|
|
|
|
+ if (device == null) {
|
|
|
|
|
+ return Result.error(404, "设备不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("status", device.getStatus());
|
|
|
|
|
+ result.put("statusLabel", getDeviceStatusLabel(device.getStatus()));
|
|
|
|
|
+ return Result.success("查询成功", result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取设备库存详情
|
|
* 获取设备库存详情
|
|
|
*
|
|
*
|
|
@@ -254,12 +273,7 @@ public class ReplenisherOperationController {
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/device/inventory/{deviceId}")
|
|
@GetMapping("/device/inventory/{deviceId}")
|
|
|
public Result<Map<String, Object>> getDeviceInventory(@PathVariable String deviceId) {
|
|
public Result<Map<String, Object>> getDeviceInventory(@PathVariable String deviceId) {
|
|
|
- // 验证当前登录用户是补货员
|
|
|
|
|
- Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
-
|
|
|
|
|
- // 验证该设备是否绑定到此补货员
|
|
|
|
|
- List<String> boundDeviceIds = replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
- if (!boundDeviceIds.contains(deviceId)) {
|
|
|
|
|
|
|
+ if (!canAccessDevice(deviceId)) {
|
|
|
return Result.error(403, "您无权查看此设备的库存");
|
|
return Result.error(403, "您无权查看此设备的库存");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -369,15 +383,13 @@ public class ReplenisherOperationController {
|
|
|
@RequestParam(defaultValue = "1") int page,
|
|
@RequestParam(defaultValue = "1") int page,
|
|
|
@RequestParam(defaultValue = "10") int pageSize,
|
|
@RequestParam(defaultValue = "10") int pageSize,
|
|
|
@RequestParam(required = false) Integer status) {
|
|
@RequestParam(required = false) Integer status) {
|
|
|
- Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
- List<String> deviceIds = replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
-
|
|
|
|
|
- if (deviceIds.isEmpty()) {
|
|
|
|
|
- return Result.success("查询成功", new PageResult<>());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
LambdaQueryWrapper<ReplenishmentOrder> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<ReplenishmentOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.in(ReplenishmentOrder::getDeviceId, deviceIds);
|
|
|
|
|
|
|
+ if (!isAdmin()) {
|
|
|
|
|
+ Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
+ List<String> deviceIds = replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
+ if (deviceIds.isEmpty()) return Result.success("查询成功", new PageResult<>());
|
|
|
|
|
+ wrapper.in(ReplenishmentOrder::getDeviceId, deviceIds);
|
|
|
|
|
+ }
|
|
|
if (status != null) {
|
|
if (status != null) {
|
|
|
wrapper.eq(ReplenishmentOrder::getStatus, status);
|
|
wrapper.eq(ReplenishmentOrder::getStatus, status);
|
|
|
}
|
|
}
|
|
@@ -406,15 +418,12 @@ public class ReplenisherOperationController {
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/orders/{id}")
|
|
@GetMapping("/orders/{id}")
|
|
|
public Result<Map<String, Object>> getOrderDetail(@PathVariable Long id) {
|
|
public Result<Map<String, Object>> getOrderDetail(@PathVariable Long id) {
|
|
|
- Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
ReplenishmentOrder order = replenishmentOrderService.getDetailWithItems(id);
|
|
ReplenishmentOrder order = replenishmentOrderService.getDetailWithItems(id);
|
|
|
if (order == null) {
|
|
if (order == null) {
|
|
|
return Result.error(404, "补货单不存在");
|
|
return Result.error(404, "补货单不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 验证该补货单关联的设备是否绑定到当前补货员
|
|
|
|
|
- List<String> deviceIds = replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
- if (!deviceIds.contains(order.getDeviceId())) {
|
|
|
|
|
|
|
+ if (!isAdmin() && !canAccessDevice(order.getDeviceId())) {
|
|
|
return Result.error(403, "您无权查看此补货单");
|
|
return Result.error(403, "您无权查看此补货单");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -426,17 +435,20 @@ public class ReplenisherOperationController {
|
|
|
return Result.success("查询成功", result);
|
|
return Result.success("查询成功", result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean isAdmin() {
|
|
|
|
|
+ String userType = StpUtil.getTokenSession().getString("userType");
|
|
|
|
|
+ return !"REPLENISHER".equals(userType);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 获取当前登录的补货员
|
|
|
|
|
|
|
+ * 获取当前登录的补货员(仅补货员可调用,运营人员返回null)
|
|
|
*/
|
|
*/
|
|
|
private Replenisher getCurrentReplenisher() {
|
|
private Replenisher getCurrentReplenisher() {
|
|
|
- // 验证当前登录用户是否为补货员
|
|
|
|
|
String userType = StpUtil.getTokenSession().getString("userType");
|
|
String userType = StpUtil.getTokenSession().getString("userType");
|
|
|
if (!"REPLENISHER".equals(userType)) {
|
|
if (!"REPLENISHER".equals(userType)) {
|
|
|
- log.warn("非补货员用户尝试访问补货员接口");
|
|
|
|
|
- throw new BusinessException(403, "无访问权限");
|
|
|
|
|
|
|
+ log.warn("非补货员用户尝试访问补货员专用接口");
|
|
|
|
|
+ throw new BusinessException(403, "仅补货员可执行此操作");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
String loginId = StpUtil.getLoginIdAsString();
|
|
String loginId = StpUtil.getLoginIdAsString();
|
|
|
Replenisher replenisher = replenisherService.getById(loginId);
|
|
Replenisher replenisher = replenisherService.getById(loginId);
|
|
|
if (replenisher == null) {
|
|
if (replenisher == null) {
|
|
@@ -445,6 +457,29 @@ public class ReplenisherOperationController {
|
|
|
return replenisher;
|
|
return replenisher;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取补货员绑定的设备ID列表,运营人员返回全部设备ID
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<String> getAccessibleDeviceIds() {
|
|
|
|
|
+ if (isAdmin()) {
|
|
|
|
|
+ return deviceService.list().stream()
|
|
|
|
|
+ .map(Device::getDeviceId)
|
|
|
|
|
+ .filter(id -> id != null && !id.isEmpty())
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+ Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
+ return replenisherService.getBoundDeviceIds(replenisher.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 验证设备访问权限(运营人员可访问全部,补货员仅可访问已绑定设备)
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean canAccessDevice(String deviceId) {
|
|
|
|
|
+ if (isAdmin()) return true;
|
|
|
|
|
+ Replenisher replenisher = getCurrentReplenisher();
|
|
|
|
|
+ return replenisherService.getBoundDeviceIds(replenisher.getId()).contains(deviceId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取设备状态标签
|
|
* 获取设备状态标签
|
|
|
*/
|
|
*/
|