|
@@ -29,7 +29,9 @@ import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -118,8 +120,10 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
|
|
|
// 将国家信息和用户角色信息放入对应的仓库列表项中
|
|
|
for (ShopWarehouseVo warehouseVo : warehouseList) {
|
|
|
+ if (warehouseVo.getMap() == null) {
|
|
|
+ warehouseVo.setMap(new HashMap<>()); // 确保 map 被初始化
|
|
|
+ }
|
|
|
if (baseCountryServeVoMap.containsKey(warehouseVo.getCountryServeId())) {
|
|
|
- warehouseVo.setMap(new HashMap<>()); // 初始化 map
|
|
|
warehouseVo.getMap().put("countryServe", baseCountryServeVoMap.get(warehouseVo.getCountryServeId()));
|
|
|
}
|
|
|
if (staffMap.containsKey(warehouseVo.getId())) {
|
|
@@ -299,65 +303,60 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- @Transactional // 确保方法在事务中执行
|
|
|
- public RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity) {
|
|
|
+ @Transactional
|
|
|
+ public RPCBaseResponse<ShopWarehouseVo> saveAllForm(@RequestBody ShopWarehouseSaveDto entity, HttpServletRequest request) {
|
|
|
// 创建一个新的 ShopWarehouse 实体
|
|
|
ShopWarehouse warehouse = new ShopWarehouse();
|
|
|
|
|
|
+ // 从请求头中获取 project 的值
|
|
|
+ String project = request.getHeader("Project");
|
|
|
+ warehouse.setProject(project); // 设置 project
|
|
|
+
|
|
|
// 获取当前用户 ID
|
|
|
- Long currentUserId = getCurrentUserId(); // 获取当前用户 ID
|
|
|
+ Long currentUserId = getCurrentUserId();
|
|
|
|
|
|
// 将 DTO 中的属性复制到实体对象中
|
|
|
copyWarehouseProperties(entity, warehouse);
|
|
|
- warehouse.setCreateUserId(String.valueOf(currentUserId)); // 填充创建人 ID
|
|
|
+ warehouse.setCreateUserId(String.valueOf(currentUserId));
|
|
|
+
|
|
|
+ // 检查项目是否存在
|
|
|
+ if (warehouse.getProject() == null) {
|
|
|
+ return new RPCBaseResponse<>(400, "项目不能为空", null);
|
|
|
+ }
|
|
|
|
|
|
// 插入仓库信息到数据库
|
|
|
shopWarehouseMapper.insert(warehouse);
|
|
|
|
|
|
// 如果存在员工列表,则保存员工角色信息
|
|
|
if (entity.getStaffList() != null && !entity.getStaffList().isEmpty()) {
|
|
|
- saveStaffRoles(entity.getStaffList(), warehouse.getId(), currentUserId); // 传入用户 ID
|
|
|
+ saveStaffRoles(entity.getStaffList(), warehouse.getId(), currentUserId, project); // 传入 project
|
|
|
}
|
|
|
|
|
|
// 构建并返回响应对象
|
|
|
- ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
- warehouseVo.setId(warehouse.getId());
|
|
|
- warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
- warehouseVo.setProject(warehouse.getProject());
|
|
|
- warehouseVo.setCreateTime(warehouse.getCreateTime());
|
|
|
- warehouseVo.setCreateUserId(warehouse.getCreateUserId());
|
|
|
- warehouseVo.setUpdateTime(warehouse.getUpdateTime());
|
|
|
- warehouseVo.setUpdateUserId(warehouse.getUpdateUserId());
|
|
|
- warehouseVo.setDeleteFlag(warehouse.getDeleteFlag());
|
|
|
- warehouseVo.setParentId(warehouse.getParentId());
|
|
|
- warehouseVo.setLongitude(warehouse.getLongitude());
|
|
|
- warehouseVo.setLatitude(warehouse.getLatitude());
|
|
|
- warehouseVo.setCountryServeId(warehouse.getCountryServeId());
|
|
|
- warehouseVo.setDetailedAddress(warehouse.getDetailedAddress());
|
|
|
- warehouseVo.setStatus(warehouse.getStatus());
|
|
|
- // 其他字段映射...
|
|
|
-
|
|
|
- // 返回成功的响应
|
|
|
- return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
+ return buildWarehouseResponse(warehouse);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional // 确保方法在事务中执行
|
|
|
- public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity) {
|
|
|
+ @Transactional
|
|
|
+ public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(@RequestBody ShopWarehouseSaveDto entity, HttpServletRequest request) {
|
|
|
// 根据 ID 查找现有的仓库信息
|
|
|
ShopWarehouse existingWarehouse = shopWarehouseMapper.selectById(entity.getId());
|
|
|
|
|
|
// 如果找不到该仓库,返回错误响应
|
|
|
if (existingWarehouse == null) {
|
|
|
- return new RPCBaseResponse<>(404, "NULL", null);
|
|
|
+ return new RPCBaseResponse<>(404, "找不到仓库", null);
|
|
|
}
|
|
|
|
|
|
+ // 从请求头中获取 project 的值
|
|
|
+ String project = request.getHeader("Project");
|
|
|
+ existingWarehouse.setProject(project); // 设置 project
|
|
|
+
|
|
|
// 更新现有仓库的属性
|
|
|
copyWarehouseProperties(entity, existingWarehouse);
|
|
|
|
|
|
// 获取当前用户 ID
|
|
|
- Long currentUserId = getCurrentUserId(); // 获取当前用户 ID
|
|
|
- existingWarehouse.setUpdateUserId(String.valueOf(currentUserId)); // 填充更新人 ID
|
|
|
+ Long currentUserId = getCurrentUserId();
|
|
|
+ existingWarehouse.setUpdateUserId(String.valueOf(currentUserId));
|
|
|
|
|
|
// 更新仓库信息到数据库
|
|
|
shopWarehouseMapper.updateById(existingWarehouse);
|
|
@@ -367,31 +366,14 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
// 先删除原有员工信息
|
|
|
shopWarehouseStaffMapper.deleteByWarehouseId(existingWarehouse.getId());
|
|
|
// 然后插入新的员工角色信息
|
|
|
- saveStaffRoles(entity.getStaffList(), existingWarehouse.getId(), currentUserId); // 传入用户 ID
|
|
|
+ saveStaffRoles(entity.getStaffList(), existingWarehouse.getId(), currentUserId, project); // 传入 project
|
|
|
}
|
|
|
|
|
|
// 构建并返回响应对象
|
|
|
- ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
- warehouseVo.setId(existingWarehouse.getId());
|
|
|
- warehouseVo.setWarehouseName(existingWarehouse.getWarehouseName());
|
|
|
- warehouseVo.setProject(existingWarehouse.getProject());
|
|
|
- warehouseVo.setCreateTime(existingWarehouse.getCreateTime());
|
|
|
- warehouseVo.setCreateUserId(existingWarehouse.getCreateUserId());
|
|
|
- warehouseVo.setUpdateTime(existingWarehouse.getUpdateTime());
|
|
|
- warehouseVo.setUpdateUserId(existingWarehouse.getUpdateUserId());
|
|
|
- warehouseVo.setDeleteFlag(existingWarehouse.getDeleteFlag());
|
|
|
- warehouseVo.setParentId(existingWarehouse.getParentId());
|
|
|
- warehouseVo.setLongitude(existingWarehouse.getLongitude());
|
|
|
- warehouseVo.setLatitude(existingWarehouse.getLatitude());
|
|
|
- warehouseVo.setCountryServeId(existingWarehouse.getCountryServeId());
|
|
|
- warehouseVo.setDetailedAddress(existingWarehouse.getDetailedAddress());
|
|
|
- warehouseVo.setStatus(existingWarehouse.getStatus());
|
|
|
- // 其他字段映射...
|
|
|
-
|
|
|
- // 返回成功的响应
|
|
|
- return new RPCBaseResponse<>(200, "更新成功", warehouseVo);
|
|
|
+ return buildWarehouseResponse(existingWarehouse);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 复制仓库属性的方法
|
|
|
private void copyWarehouseProperties(ShopWarehouseSaveDto source, ShopWarehouse target) {
|
|
|
target.setParentId(source.getParentId());
|
|
@@ -422,14 +404,39 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return userId;
|
|
|
}
|
|
|
// 保存员工角色信息的方法
|
|
|
- private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId, Long currentUserId) {
|
|
|
+ private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId, Long currentUserId, String project) {
|
|
|
for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
staff.setWarehouseId(warehouseId);
|
|
|
staff.setUserId(staffDto.getUserId());
|
|
|
staff.setRoleId(staffDto.getRoleId());
|
|
|
staff.setCreateUserId(String.valueOf(currentUserId)); // 设置创建用户 ID
|
|
|
+ staff.setProject(project); // 设置项目
|
|
|
+
|
|
|
+ // 插入员工角色信息
|
|
|
shopWarehouseStaffMapper.insert(staff);
|
|
|
}
|
|
|
}
|
|
|
+ //返回方法
|
|
|
+ private RPCBaseResponse<ShopWarehouseVo> buildWarehouseResponse(ShopWarehouse warehouse) {
|
|
|
+ ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
+ warehouseVo.setId(warehouse.getId());
|
|
|
+ warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
+ warehouseVo.setProject(warehouse.getProject()); // 设置项目
|
|
|
+ warehouseVo.setCreateTime(warehouse.getCreateTime());
|
|
|
+ warehouseVo.setCreateUserId(warehouse.getCreateUserId());
|
|
|
+ warehouseVo.setUpdateTime(warehouse.getUpdateTime());
|
|
|
+ warehouseVo.setUpdateUserId(warehouse.getUpdateUserId());
|
|
|
+ warehouseVo.setDeleteFlag(warehouse.getDeleteFlag());
|
|
|
+ warehouseVo.setParentId(warehouse.getParentId());
|
|
|
+ warehouseVo.setLongitude(warehouse.getLongitude());
|
|
|
+ warehouseVo.setLatitude(warehouse.getLatitude());
|
|
|
+ warehouseVo.setCountryServeId(warehouse.getCountryServeId());
|
|
|
+ warehouseVo.setDetailedAddress(warehouse.getDetailedAddress());
|
|
|
+ warehouseVo.setStatus(warehouse.getStatus());
|
|
|
+ // 其他字段映射...
|
|
|
+
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
+ }
|
|
|
+
|
|
|
}
|