|
@@ -305,12 +305,12 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public RPCBaseResponse<ShopWarehouseVo> saveAllForm(@RequestBody ShopWarehouseSaveDto entity, HttpServletRequest request) {
|
|
|
+ public RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity) {
|
|
|
// 创建一个新的 ShopWarehouse 实体
|
|
|
ShopWarehouse warehouse = new ShopWarehouse();
|
|
|
|
|
|
- // 从请求头中获取 project 的值
|
|
|
- String project = request.getHeader("Project");
|
|
|
+ // 获取项目值(现在从 DTO 中获取)
|
|
|
+ String project = entity.getProject();
|
|
|
warehouse.setProject(project); // 设置 project
|
|
|
|
|
|
// 获取当前用户 ID
|
|
@@ -339,39 +339,40 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(@RequestBody ShopWarehouseSaveDto entity, HttpServletRequest request) {
|
|
|
- // 根据 ID 查找现有的仓库信息
|
|
|
- ShopWarehouse existingWarehouse = shopWarehouseMapper.selectById(entity.getId());
|
|
|
+ public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity) {
|
|
|
+ // 创建一个新的 ShopWarehouse 实体
|
|
|
+ ShopWarehouse warehouse = shopWarehouseMapper.selectById(entity.getId());
|
|
|
|
|
|
// 如果找不到该仓库,返回错误响应
|
|
|
- if (existingWarehouse == null) {
|
|
|
+ if (warehouse == null) {
|
|
|
return new RPCBaseResponse<>(404, "找不到仓库", null);
|
|
|
}
|
|
|
|
|
|
- // 从请求头中获取 project 的值
|
|
|
- String project = request.getHeader("Project");
|
|
|
- existingWarehouse.setProject(project); // 设置 project
|
|
|
-
|
|
|
- // 更新现有仓库的属性
|
|
|
- copyWarehouseProperties(entity, existingWarehouse);
|
|
|
+ // 从 DTO 中复制属性
|
|
|
+ copyWarehouseProperties(entity, warehouse);
|
|
|
|
|
|
// 获取当前用户 ID
|
|
|
Long currentUserId = getCurrentUserId();
|
|
|
- existingWarehouse.setUpdateUserId(String.valueOf(currentUserId));
|
|
|
+ warehouse.setUpdateUserId(String.valueOf(currentUserId));
|
|
|
+
|
|
|
+ // 检查项目是否存在
|
|
|
+ if (warehouse.getProject() == null) {
|
|
|
+ return new RPCBaseResponse<>(400, "项目不能为空", null);
|
|
|
+ }
|
|
|
|
|
|
// 更新仓库信息到数据库
|
|
|
- shopWarehouseMapper.updateById(existingWarehouse);
|
|
|
+ shopWarehouseMapper.updateById(warehouse);
|
|
|
|
|
|
// 更新员工角色信息
|
|
|
if (entity.getStaffList() != null) {
|
|
|
// 先删除原有员工信息
|
|
|
- shopWarehouseStaffMapper.deleteByWarehouseId(existingWarehouse.getId());
|
|
|
+ shopWarehouseStaffMapper.deleteByWarehouseId(warehouse.getId());
|
|
|
// 然后插入新的员工角色信息
|
|
|
- saveStaffRoles(entity.getStaffList(), existingWarehouse.getId(), currentUserId, project); // 传入 project
|
|
|
+ saveStaffRoles(entity.getStaffList(), warehouse.getId(), currentUserId, entity.getProject());
|
|
|
}
|
|
|
|
|
|
// 构建并返回响应对象
|
|
|
- return buildWarehouseResponse(existingWarehouse);
|
|
|
+ return buildWarehouseResponse(warehouse);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -410,8 +411,8 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
staff.setWarehouseId(warehouseId);
|
|
|
- staff.setUserId(staffDto.getUserId());
|
|
|
- staff.setRoleId(staffDto.getRoleId());
|
|
|
+ staff.setUserId(Long.valueOf(staffDto.getUserId()));
|
|
|
+ staff.setRoleId(Long.valueOf(staffDto.getRoleId()));
|
|
|
staff.setCreateUserId(String.valueOf(currentUserId)); // 设置创建用户 ID
|
|
|
staff.setProject(project); // 设置项目
|
|
|
|