|
@@ -295,50 +295,56 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
@Override
|
|
|
@Transactional // 确保此方法在事务中执行
|
|
|
public RPCBaseResponse<ShopWarehouseVo> saveAllForm(ShopWarehouseSaveDto entity) {
|
|
|
- // 保存仓库信息
|
|
|
+ // 创建并设置仓库信息
|
|
|
ShopWarehouse warehouse = new ShopWarehouse();
|
|
|
- warehouse.setParentId(entity.getParentId());
|
|
|
- warehouse.setWarehouseName(entity.getWarehouseName());
|
|
|
- warehouse.setLongitude(entity.getLongitude());
|
|
|
- warehouse.setLatitude(entity.getLatitude());
|
|
|
- warehouse.setCountryServeId(entity.getCountryServeId());
|
|
|
- warehouse.setCreateTime(entity.getCreateTime());
|
|
|
- warehouse.setUpdateUserId(entity.getUpdateUserId());
|
|
|
- warehouse.setUpdateTime(new Date());
|
|
|
- warehouse.setCreateUserId(entity.getCreateUserId());
|
|
|
- warehouse.setDetailedAddress(entity.getDetailedAddress());
|
|
|
- warehouse.setProject(entity.getProject());
|
|
|
- warehouse.setStatus(entity.getStatus());
|
|
|
- warehouse.setDeleteFlag(entity.getDeleteFlag());
|
|
|
+ copyWarehouseProperties(entity, warehouse);
|
|
|
|
|
|
// 插入仓库信息
|
|
|
shopWarehouseMapper.insert(warehouse);
|
|
|
|
|
|
- // 获取新插入的仓库ID
|
|
|
- Long warehouseId = warehouse.getId();
|
|
|
-
|
|
|
// 保存员工角色信息
|
|
|
- List<ShopWarehouseStaffDto> staffList = entity.getStaffList();
|
|
|
+ saveStaffRoles(entity.getStaffList(), warehouse.getId());
|
|
|
+
|
|
|
+ // 构建返回对象
|
|
|
+ return buildWarehouseResponse(warehouse);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从 DTO 复制属性到实体
|
|
|
+ private void copyWarehouseProperties(ShopWarehouseSaveDto source, ShopWarehouse target) {
|
|
|
+ target.setParentId(source.getParentId());
|
|
|
+ target.setWarehouseName(source.getWarehouseName());
|
|
|
+ target.setLongitude(source.getLongitude());
|
|
|
+ target.setLatitude(source.getLatitude());
|
|
|
+ target.setCountryServeId(source.getCountryServeId());
|
|
|
+ target.setDetailedAddress(source.getDetailedAddress());
|
|
|
+ target.setStatus(source.getStatus());
|
|
|
+ // 其他需要设置的字段...
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存员工角色
|
|
|
+ private void saveStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId) {
|
|
|
if (staffList != null && !staffList.isEmpty()) {
|
|
|
for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
- staff.setWarehouseId(warehouseId); // 设置外键为新保存仓库的ID
|
|
|
+ staff.setWarehouseId(warehouseId);
|
|
|
staff.setUserId(staffDto.getUserId());
|
|
|
staff.setRoleId(staffDto.getRoleId());
|
|
|
- shopWarehouseStaffMapper.insert(staff); // 保存员工角色信息
|
|
|
+ shopWarehouseStaffMapper.insert(staff);
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 将保存的仓库信息转换为返回对象
|
|
|
+ // 构建返回对象
|
|
|
+ private RPCBaseResponse<ShopWarehouseVo> buildWarehouseResponse(ShopWarehouse warehouse) {
|
|
|
ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
warehouseVo.setId(warehouse.getId());
|
|
|
warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
- // 添加更多的字段映射,根据需要
|
|
|
-
|
|
|
+ // 其他字段映射...
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 更新
|
|
|
*/
|
|
@@ -347,47 +353,25 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
public RPCBaseResponse<ShopWarehouseVo> updateWarehouse(ShopWarehouseSaveDto entity) {
|
|
|
// 更新仓库信息
|
|
|
ShopWarehouse warehouse = new ShopWarehouse();
|
|
|
- warehouse.setId(entity.getId()); // 要更新的ID
|
|
|
- warehouse.setParentId(entity.getParentId());
|
|
|
- warehouse.setWarehouseName(entity.getWarehouseName());
|
|
|
- warehouse.setLongitude(entity.getLongitude());
|
|
|
- warehouse.setLatitude(entity.getLatitude());
|
|
|
- warehouse.setCountryServeId(entity.getCountryServeId());
|
|
|
- warehouse.setDetailedAddress(entity.getDetailedAddress());
|
|
|
- warehouse.setProject(entity.getProject());
|
|
|
- warehouse.setCreateTime(entity.getCreateTime());
|
|
|
- warehouse.setUpdateUserId(entity.getUpdateUserId());
|
|
|
- warehouse.setUpdateTime(new Date());
|
|
|
- warehouse.setCreateUserId(entity.getCreateUserId());
|
|
|
- warehouse.setStatus(entity.getStatus());
|
|
|
- warehouse.setDeleteFlag(entity.getDeleteFlag());
|
|
|
-
|
|
|
- // 执行更新操作
|
|
|
+ warehouse.setId(entity.getId());
|
|
|
+ copyWarehouseProperties(entity, warehouse);
|
|
|
shopWarehouseMapper.updateById(warehouse);
|
|
|
|
|
|
// 更新员工角色信息
|
|
|
- List<ShopWarehouseStaffDto> staffList = entity.getStaffList();
|
|
|
- if (staffList != null && !staffList.isEmpty()) {
|
|
|
- // 可以先删除原有的员工记录
|
|
|
- shopWarehouseStaffMapper.deleteByWarehouseId(entity.getId()); // 这需要您在 Mapper 中实现
|
|
|
+ updateStaffRoles(entity.getStaffList(), entity.getId());
|
|
|
|
|
|
- // 插入新的员工角色信息
|
|
|
- for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
- ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
- staff.setWarehouseId(entity.getId()); // 设置外键为更新的仓库ID
|
|
|
- staff.setUserId(staffDto.getUserId());
|
|
|
- staff.setRoleId(staffDto.getRoleId());
|
|
|
- shopWarehouseStaffMapper.insert(staff); // 保存员工角色信息
|
|
|
- }
|
|
|
- }
|
|
|
+ // 构建返回对象
|
|
|
+ return buildWarehouseResponse(warehouse);
|
|
|
+ }
|
|
|
|
|
|
- // 将保存的仓库信息转换为返回对象
|
|
|
- ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
- warehouseVo.setId(warehouse.getId());
|
|
|
- warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
- // 添加更多的字段映射,根据需要
|
|
|
+ // 更新员工角色
|
|
|
+ private void updateStaffRoles(List<ShopWarehouseStaffDto> staffList, Long warehouseId) {
|
|
|
+ // 删除原有的员工记录
|
|
|
+ shopWarehouseStaffMapper.deleteByWarehouseId(warehouseId);
|
|
|
|
|
|
- return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
+ // 插入新的员工角色信息
|
|
|
+ saveStaffRoles(staffList, warehouseId);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|