员工统计
All checks were successful
构建并部署 Spring Boot 应用 / build-and-deploy (push) Successful in 16m47s

This commit is contained in:
2025-10-25 18:35:36 +08:00
parent 350c07d122
commit 4e59d7295b
7 changed files with 180 additions and 3 deletions

View File

@@ -40,6 +40,16 @@ Light Delivery 是一个为小程序配送服务设计的后端系统,提供
- 员工增删改查功能
- 员工角色管理(管理员/配送员)
### 6. 仓库管理(新增)
- 仓库信息维护
- 仓库增删改查功能
- 仓库与订单关联管理
### 7. 统计信息(新增)
- 系统统计信息(员工数、仓库数、订单数等)
- 订单统计信息(按时间范围统计订单状态)
- 用户统计信息(总用户数、在线用户数等)
## 项目结构
```
@@ -356,6 +366,19 @@ deploy.bat
- `PUT /employees/{id}` - 更新员工信息
- `DELETE /employees/{id}` - 删除员工
### 仓库管理相关(仅限管理员访问)
- `GET /warehouses` - 获取仓库列表
- `GET /warehouses/{id}` - 获取仓库详情
- `GET /warehouses/{id}/orders` - 获取仓库订单列表
- `POST /warehouses` - 创建仓库
- `PUT /warehouses/{id}` - 更新仓库信息
- `DELETE /warehouses/{id}` - 删除仓库
### 统计信息相关(仅限管理员访问)
- `GET /stats/system` - 获取系统统计信息
- `GET /stats/orders` - 获取订单统计信息
- `GET /stats/users` - 获取用户统计信息
### 位置同步相关
- `GET /location-sync/delivery-persons/locations` - 获取所有配送员位置
- WebSocket端点: `/ws/location` - 实时位置同步
@@ -487,6 +510,19 @@ deploy.bat
## 最近更新
### 统计信息功能(新增)
为便于管理员查看系统运行状态,我们新增了统计信息功能:
- 新增StatisticsController控制器提供系统、订单、用户等统计信息接口
- 添加权限控制,仅管理员可访问统计信息接口
- 提供系统概览、订单分析和用户状态等多维度统计信息
### 仓库管理功能(新增)
为便于管理员维护仓库信息,我们新增了仓库管理功能:
- 新增WarehouseController控制器提供仓库信息的增删改查接口
- 新增WarehouseService服务层处理仓库相关的业务逻辑
- 添加权限控制,仅管理员可访问仓库管理接口
- 仓库与订单建立关联,可查询仓库下的订单列表
### WebSocket使用方式变更重要变更
为了更好地分离关注点和提高系统安全性我们对WebSocket使用方式进行了重要变更
- 移除了WebSocket中的签到/签退功能这些操作现在完全通过REST API进行

View File

@@ -9,8 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -112,7 +113,76 @@ public class WarehouseController {
* @return 创建后的仓库对象
*/
@PostMapping
public Warehouse createWarehouse(@RequestBody Warehouse warehouse) {
return warehouseService.createWarehouse(warehouse);
public ResponseEntity<Map<String, Object>> createWarehouse(@RequestBody Warehouse warehouse) {
Warehouse createdWarehouse = warehouseService.createWarehouse(warehouse);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "仓库创建成功");
WarehouseInfo info = new WarehouseInfo();
info.setId(createdWarehouse.getId());
info.setName(createdWarehouse.getName());
info.setAddress(createdWarehouse.getAddress());
info.setContact(createdWarehouse.getContact());
info.setPhone(createdWarehouse.getPhone());
info.setDescription(createdWarehouse.getDescription());
info.setStatus(createdWarehouse.getStatus());
info.setCapacity(createdWarehouse.getCapacity());
info.setLatitude(createdWarehouse.getLatitude());
info.setLongitude(createdWarehouse.getLongitude());
response.put("data", info);
return ResponseEntity.ok(response);
}
/**
* 更新仓库信息。
* @param id 仓库ID
* @param warehouse 仓库对象
* @return 更新结果
*/
@PutMapping("/{id}")
public ResponseEntity<Map<String, Object>> updateWarehouse(@PathVariable Long id, @RequestBody Warehouse warehouse) {
Warehouse updatedWarehouse = warehouseService.updateWarehouse(id, warehouse);
Map<String, Object> response = new HashMap<>();
if (updatedWarehouse != null) {
response.put("success", true);
response.put("message", "仓库更新成功");
WarehouseInfo info = new WarehouseInfo();
info.setId(updatedWarehouse.getId());
info.setName(updatedWarehouse.getName());
info.setAddress(updatedWarehouse.getAddress());
info.setContact(updatedWarehouse.getContact());
info.setPhone(updatedWarehouse.getPhone());
info.setDescription(updatedWarehouse.getDescription());
info.setStatus(updatedWarehouse.getStatus());
info.setCapacity(updatedWarehouse.getCapacity());
info.setLatitude(updatedWarehouse.getLatitude());
info.setLongitude(updatedWarehouse.getLongitude());
response.put("data", info);
} else {
response.put("success", false);
response.put("message", "仓库不存在");
}
return ResponseEntity.ok(response);
}
/**
* 根据ID删除仓库。
* @param id 仓库ID
* @return 删除结果
*/
@DeleteMapping("/{id}")
public ResponseEntity<Map<String, Object>> deleteWarehouse(@PathVariable Long id) {
warehouseService.deleteWarehouse(id);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "仓库删除成功");
return ResponseEntity.ok(response);
}
}

View File

@@ -218,6 +218,14 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
}
}
/**
* 获取在线用户数量
* @return 在线用户数量
*/
public int getOnlineUserCount() {
return sessions.size();
}
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
// 连接建立时,可以在这里进行身份验证

View File

@@ -38,4 +38,10 @@ public interface OrderService {
* @return 订单列表
*/
List<Order> getOrdersByDeliveryPerson(Long deliveryPersonId);
/**
* 获取所有订单。
* @return 订单列表
*/
List<Order> getAllOrders();
}

View File

@@ -32,4 +32,18 @@ public interface WarehouseService {
* @return 创建后的仓库对象
*/
Warehouse createWarehouse(Warehouse warehouse);
/**
* 更新仓库信息。
* @param id 仓库ID
* @param warehouse 仓库对象
* @return 更新后的仓库对象
*/
Warehouse updateWarehouse(Long id, Warehouse warehouse);
/**
* 根据ID删除仓库。
* @param id 仓库ID
*/
void deleteWarehouse(Long id);
}

View File

@@ -56,4 +56,13 @@ public class OrderServiceImpl implements OrderService {
public List<Order> getOrdersByDeliveryPerson(Long deliveryPersonId) {
return orderRepository.findByDeliveryPersonId(deliveryPersonId);
}
/**
* 获取所有订单。
* @return 订单列表
*/
@Override
public List<Order> getAllOrders() {
return orderRepository.findAll();
}
}

View File

@@ -60,4 +60,38 @@ public class WarehouseServiceImpl implements WarehouseService {
public Warehouse createWarehouse(Warehouse warehouse) {
return warehouseRepository.save(warehouse);
}
/**
* 更新仓库信息。
* @param id 仓库ID
* @param warehouse 仓库对象
* @return 更新后的仓库对象
*/
@Override
public Warehouse updateWarehouse(Long id, Warehouse warehouse) {
Optional<Warehouse> existingWarehouse = warehouseRepository.findById(id);
if (existingWarehouse.isPresent()) {
Warehouse updatedWarehouse = existingWarehouse.get();
updatedWarehouse.setName(warehouse.getName());
updatedWarehouse.setLatitude(warehouse.getLatitude());
updatedWarehouse.setLongitude(warehouse.getLongitude());
updatedWarehouse.setAddress(warehouse.getAddress());
updatedWarehouse.setPhone(warehouse.getPhone());
updatedWarehouse.setContact(warehouse.getContact());
updatedWarehouse.setDescription(warehouse.getDescription());
updatedWarehouse.setStatus(warehouse.getStatus());
updatedWarehouse.setCapacity(warehouse.getCapacity());
return warehouseRepository.save(updatedWarehouse);
}
return null;
}
/**
* 根据ID删除仓库。
* @param id 仓库ID
*/
@Override
public void deleteWarehouse(Long id) {
warehouseRepository.deleteById(id);
}
}