|
@@ -7,6 +7,8 @@ import edu.travel.adapter.service.country.CountryAdapter;
|
|
|
import edu.travel.adapter.service.tenant.SysRoleAdapter;
|
|
|
import edu.travel.adapter.service.tenant.TenantAdapter;
|
|
|
import edu.travel.dto.ShopWarehouseDto;
|
|
|
+import edu.travel.dto.ShopWarehouseSaveDto;
|
|
|
+import edu.travel.dto.ShopWarehouseStaffDto;
|
|
|
import edu.travel.remote.feign.mode.vo.tenant.EduTenantVo;
|
|
|
import edu.travel.remote.feign.mode.vo.tenant.SysRoleVo;
|
|
|
import edu.travel.rpc.RPCBaseResponse;
|
|
@@ -22,6 +24,7 @@ import edu.travel.warehouse.service.ShopWarehouseService;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -40,13 +43,6 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
private ShopWarehouseStaffMapper shopWarehouseStaffMapper;
|
|
|
/**
|
|
|
* 树形结构查询(连表)
|
|
|
- * @param dto
|
|
|
- * @return
|
|
|
- */
|
|
|
- /**
|
|
|
- * 树形结构查询(连表)
|
|
|
- * @param dto
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public RPCBaseResponse<List<ShopWarehouseVo>> getWarehouseCountryForm(ShopWarehouseDto dto) {
|
|
@@ -82,6 +78,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", tree);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分页动态查询(连表)
|
|
|
+ */
|
|
|
@Override
|
|
|
public RPCBaseResponse<IPage<ShopWarehouseVo>> getWarehouseCountryPageForm(ShopWarehouseDto dto) {
|
|
|
// 创建分页对象
|
|
@@ -93,7 +92,7 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
dto.getStatus(),
|
|
|
dto.getParentId(),
|
|
|
dto.getPageSize(),
|
|
|
- (int) ((dto.getCurrentPage() - 1) * dto.getPageSize())
|
|
|
+ (dto.getCurrentPage() - 1) * dto.getPageSize()
|
|
|
);
|
|
|
int total = shopWarehouseMapper.countWarehouseWithCountry(dto.getWarehouseName(), dto.getStatus(), dto.getParentId());
|
|
|
|
|
@@ -134,6 +133,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 提取国家数据
|
|
|
+ */
|
|
|
private Map<String, BaseCountryServeVo> fetchCountryData(Set<String> countryServeIds) {
|
|
|
Map<String, BaseCountryServeVo> countryMap = new HashMap<>();
|
|
|
if (!countryServeIds.isEmpty()) {
|
|
@@ -147,6 +149,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return countryMap;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 提取仓库数据
|
|
|
+ */
|
|
|
private Map<Long, List<ShopWarehouseStaffVo>> fetchWarehouseTenantRoles(Set<Long> ids) {
|
|
|
Map<Long, List<ShopWarehouseStaffVo>> staffMap = new HashMap<>();
|
|
|
if (!ids.isEmpty()) {
|
|
@@ -160,6 +165,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return staffMap;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *生成map
|
|
|
+ */
|
|
|
private ShopWarehouseVo mapToWarehouseVo(ShopWarehouse shopWarehouse,
|
|
|
Map<String, BaseCountryServeVo> countryMap,
|
|
|
Map<Long, List<ShopWarehouseStaffVo>> staffMap) {
|
|
@@ -171,6 +179,7 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
shopWarehouseVo.setLatitude(shopWarehouse.getLatitude());
|
|
|
shopWarehouseVo.setDetailedAddress(shopWarehouse.getDetailedAddress());
|
|
|
shopWarehouseVo.setStatus(shopWarehouse.getStatus());
|
|
|
+ shopWarehouseVo.setProject(shopWarehouse.getProject());
|
|
|
shopWarehouseVo.setParentId(shopWarehouse.getParentId());
|
|
|
shopWarehouseVo.setDeleteFlag(shopWarehouse.getDeleteFlag());
|
|
|
shopWarehouseVo.setMap(new HashMap<>());
|
|
@@ -184,6 +193,9 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return shopWarehouseVo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 构建树
|
|
|
+ */
|
|
|
private void addToTree(List<ShopWarehouseVo> tree, ShopWarehouseVo warehouseVo, Map<Long, ShopWarehouseVo> warehouseVoMap) {
|
|
|
if (warehouseVo.getParentId() == null || warehouseVo.getParentId() == 0) {
|
|
|
tree.add(warehouseVo);
|
|
@@ -201,7 +213,6 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
|
|
|
/**
|
|
|
* 库房关联人员(角色)查询,通过库房id,查询用户以及角色
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public RPCBaseResponse<List<ShopWarehouseStaffVo>> getWarehouseTenantRole(String id) {
|
|
@@ -278,4 +289,105 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", resultList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 连表新增
|
|
|
+ */
|
|
|
+ @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());
|
|
|
+
|
|
|
+ // 插入仓库信息
|
|
|
+ shopWarehouseMapper.insert(warehouse);
|
|
|
+
|
|
|
+ // 获取新插入的仓库ID
|
|
|
+ Long warehouseId = warehouse.getId();
|
|
|
+
|
|
|
+ // 保存员工角色信息
|
|
|
+ List<ShopWarehouseStaffDto> staffList = entity.getStaffList();
|
|
|
+ if (staffList != null && !staffList.isEmpty()) {
|
|
|
+ for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
+ ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
+ staff.setWarehouseId(warehouseId); // 设置外键为新保存仓库的ID
|
|
|
+ staff.setUserId(staffDto.getUserId());
|
|
|
+ staff.setRoleId(staffDto.getRoleId());
|
|
|
+ shopWarehouseStaffMapper.insert(staff); // 保存员工角色信息
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将保存的仓库信息转换为返回对象
|
|
|
+ ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
+ warehouseVo.setId(warehouse.getId());
|
|
|
+ warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
+ // 添加更多的字段映射,根据需要
|
|
|
+
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional // 确保此方法在事务中执行
|
|
|
+ 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());
|
|
|
+
|
|
|
+ // 执行更新操作
|
|
|
+ shopWarehouseMapper.updateById(warehouse);
|
|
|
+
|
|
|
+ // 更新员工角色信息
|
|
|
+ List<ShopWarehouseStaffDto> staffList = entity.getStaffList();
|
|
|
+ if (staffList != null && !staffList.isEmpty()) {
|
|
|
+ // 可以先删除原有的员工记录
|
|
|
+ shopWarehouseStaffMapper.deleteByWarehouseId(entity.getId()); // 这需要您在 Mapper 中实现
|
|
|
+
|
|
|
+ // 插入新的员工角色信息
|
|
|
+ for (ShopWarehouseStaffDto staffDto : staffList) {
|
|
|
+ ShopWarehouseStaff staff = new ShopWarehouseStaff();
|
|
|
+ staff.setWarehouseId(entity.getId()); // 设置外键为更新的仓库ID
|
|
|
+ staff.setUserId(staffDto.getUserId());
|
|
|
+ staff.setRoleId(staffDto.getRoleId());
|
|
|
+ shopWarehouseStaffMapper.insert(staff); // 保存员工角色信息
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将保存的仓库信息转换为返回对象
|
|
|
+ ShopWarehouseVo warehouseVo = new ShopWarehouseVo();
|
|
|
+ warehouseVo.setId(warehouse.getId());
|
|
|
+ warehouseVo.setWarehouseName(warehouse.getWarehouseName());
|
|
|
+ // 添加更多的字段映射,根据需要
|
|
|
+
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", warehouseVo);
|
|
|
+ }
|
|
|
+
|
|
|
}
|