|
@@ -0,0 +1,251 @@
|
|
|
+package edu.travel.warehouse.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+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.remote.feign.mode.vo.tenant.EduTenantVo;
|
|
|
+import edu.travel.remote.feign.mode.vo.tenant.SysRoleVo;
|
|
|
+import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import edu.travel.service.SysServiceImpl;
|
|
|
+import edu.travel.vo.BaseCountryServeVo;
|
|
|
+import edu.travel.vo.ShopWarehouseStaffVo;
|
|
|
+import edu.travel.vo.ShopWarehouseVo;
|
|
|
+import edu.travel.warehouse.entity.ShopWarehouse;
|
|
|
+import edu.travel.warehouse.entity.ShopWarehouseStaff;
|
|
|
+import edu.travel.warehouse.mapper.ShopWarehouseMapper;
|
|
|
+import edu.travel.warehouse.mapper.ShopWarehouseStaffMapper;
|
|
|
+import edu.travel.warehouse.service.ShopWarehouseService;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper, ShopWarehouse> implements ShopWarehouseService {
|
|
|
+ @Autowired
|
|
|
+ private CountryAdapter countryAdapter;
|
|
|
+ @Autowired
|
|
|
+ private TenantAdapter tenantAdapter;
|
|
|
+ @Autowired
|
|
|
+ private SysRoleAdapter sysRoleAdapter;
|
|
|
+ @Autowired
|
|
|
+ private ShopWarehouseMapper shopWarehouseMapper;
|
|
|
+ @Autowired
|
|
|
+ private ShopWarehouseStaffMapper shopWarehouseStaffMapper;
|
|
|
+ /**
|
|
|
+ * 树形结构查询(连表)
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RPCBaseResponse<List<ShopWarehouseVo>> getWarehouseCountryForm(ShopWarehouseDto dto) {
|
|
|
+ // 查询所有库房数据
|
|
|
+ LambdaQueryWrapper<ShopWarehouse> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ List<ShopWarehouse> shopWarehouseList = super.getListLink(queryWrapper);
|
|
|
+
|
|
|
+ // 提取国家服务ID
|
|
|
+ Set<String> countryServeIds = shopWarehouseList.stream()
|
|
|
+ .map(ShopWarehouse::getCountryServeId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 创建一个 Map 以便通过 countryServeId 查询到对应的国家数据
|
|
|
+ Map<String, BaseCountryServeVo> baseCountryServeVoMap = new HashMap<>();
|
|
|
+ if (!countryServeIds.isEmpty()) {
|
|
|
+ // 使用 getFormId 方法查询国家信息
|
|
|
+ for (String countryServeId : countryServeIds) {
|
|
|
+ RPCBaseResponse<BaseCountryServeVo> response = countryAdapter.getFormId(countryServeId);
|
|
|
+ if (response != null && response.getData() != null) {
|
|
|
+ baseCountryServeVoMap.put(countryServeId, response.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个 Map 用于快速查找每个仓库的父子关系
|
|
|
+ Map<Long, ShopWarehouseVo> warehouseVoMap = new HashMap<>();
|
|
|
+ List<ShopWarehouseVo> tree = new ArrayList<>();
|
|
|
+
|
|
|
+ // 一次性处理以创建树形结构
|
|
|
+ for (ShopWarehouse shopWarehouse : shopWarehouseList) {
|
|
|
+ ShopWarehouseVo shopWarehouseVo = new ShopWarehouseVo();
|
|
|
+ shopWarehouseVo.setId(shopWarehouse.getId());
|
|
|
+ shopWarehouseVo.setCountryServeId(shopWarehouse.getCountryServeId());
|
|
|
+ shopWarehouseVo.setWarehouseName(shopWarehouse.getWarehouseName());
|
|
|
+ shopWarehouseVo.setLongitude(shopWarehouse.getLongitude());
|
|
|
+ shopWarehouseVo.setLatitude(shopWarehouse.getLatitude());
|
|
|
+ shopWarehouseVo.setDetailedAddress(shopWarehouse.getDetailedAddress());
|
|
|
+ shopWarehouseVo.setStatus(shopWarehouse.getStatus());
|
|
|
+ shopWarehouseVo.setParentId(shopWarehouse.getParentId());
|
|
|
+ shopWarehouseVo.setDeleteFlag(shopWarehouse.getDeleteFlag());
|
|
|
+ shopWarehouseVo.setMap(new HashMap<>());
|
|
|
+
|
|
|
+ // 将国家信息放入 Map 中
|
|
|
+ if (baseCountryServeVoMap.containsKey(shopWarehouse.getCountryServeId())) {
|
|
|
+ shopWarehouseVo.getMap().put("countryServe", baseCountryServeVoMap.get(shopWarehouse.getCountryServeId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存储到 warehouseVoMap
|
|
|
+ warehouseVoMap.put(shopWarehouse.getId(), shopWarehouseVo);
|
|
|
+
|
|
|
+ // 添加到树或其父节点
|
|
|
+ if (shopWarehouse.getParentId() == null || shopWarehouse.getParentId() == 0) {
|
|
|
+ // 顶级节点
|
|
|
+ tree.add(shopWarehouseVo);
|
|
|
+ } else {
|
|
|
+ // 非顶级节点,查找其父节点并添加到 children
|
|
|
+ ShopWarehouseVo parentVo = warehouseVoMap.get(shopWarehouse.getParentId());
|
|
|
+ if (parentVo != null) {
|
|
|
+ if (parentVo.getChildren() == null) {
|
|
|
+ parentVo.setChildren(new ArrayList<>());
|
|
|
+ }
|
|
|
+ parentVo.getChildren().add(shopWarehouseVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回树形结构
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", tree);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页动态查询(连表)
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RPCBaseResponse<IPage<ShopWarehouseVo>> getWarehouseCountryPageForm(ShopWarehouseDto dto) {
|
|
|
+ // 创建分页对象
|
|
|
+ Page<ShopWarehouseVo> shopWarehousePage = new Page<>(dto.getCurrentPage(), dto.getPageSize());
|
|
|
+
|
|
|
+ // 计算 OFFSET
|
|
|
+ int offset = (int) ((dto.getCurrentPage() - 1) * dto.getPageSize());
|
|
|
+
|
|
|
+ // 创建查询包装器
|
|
|
+ LambdaQueryWrapper<ShopWarehouse> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ // 动态添加查询条件
|
|
|
+ if (dto.getWarehouseName() != null && !dto.getWarehouseName().isEmpty()) {
|
|
|
+ queryWrapper.like(ShopWarehouse::getWarehouseName, dto.getWarehouseName());
|
|
|
+ }
|
|
|
+ if (dto.getCreateTime() != null) {
|
|
|
+ queryWrapper.ge(ShopWarehouse::getCreateTime, dto.getCreateTime());
|
|
|
+ }
|
|
|
+ if (dto.getParentId() != null) {
|
|
|
+ queryWrapper.eq(ShopWarehouse::getParentId, dto.getParentId());
|
|
|
+ }
|
|
|
+ if (dto.getDetailedAddress() != null && !dto.getDetailedAddress().isEmpty()) {
|
|
|
+ queryWrapper.like(ShopWarehouse::getDetailedAddress, dto.getDetailedAddress());
|
|
|
+ }
|
|
|
+ if (dto.getStatus() != null) {
|
|
|
+ queryWrapper.eq(ShopWarehouse::getStatus, dto.getStatus());
|
|
|
+ }
|
|
|
+ queryWrapper.eq(ShopWarehouse::getDeleteFlag, 0); // 查询未删除的记录
|
|
|
+
|
|
|
+ // 执行查询,获取分页的库房数据
|
|
|
+ List<ShopWarehouseVo> warehouseList = shopWarehouseMapper.selectWarehouseWithCountry(
|
|
|
+ dto.getWarehouseName(),
|
|
|
+ dto.getStatus(),
|
|
|
+ dto.getParentId(),
|
|
|
+ dto.getPageSize(),
|
|
|
+ offset
|
|
|
+ );
|
|
|
+
|
|
|
+ // 计算总记录数
|
|
|
+ int total = shopWarehouseMapper.countWarehouseWithCountry(dto.getWarehouseName(), dto.getStatus(), dto.getParentId());
|
|
|
+
|
|
|
+ // 创建新的分页对象用于存储 ShopWarehouseVo
|
|
|
+ IPage<ShopWarehouseVo> pageVoLink = new Page<>();
|
|
|
+ pageVoLink.setRecords(warehouseList); // 设置转换后的记录列表
|
|
|
+ pageVoLink.setTotal(total); // 设置总条数
|
|
|
+ pageVoLink.setCurrent(shopWarehousePage.getCurrent()); // 设置当前页
|
|
|
+ pageVoLink.setSize(shopWarehousePage.getSize()); // 设置每页大小
|
|
|
+
|
|
|
+ // 封装返回
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 库房关联人员(角色)查询
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RPCBaseResponse<List<ShopWarehouseStaffVo>> getWarehouseTenantRole(String id) {
|
|
|
+ // 查询所有库房扩展数据
|
|
|
+ LambdaQueryWrapper<ShopWarehouseStaff> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ List<ShopWarehouseStaff> shopWarehouseStaffList = shopWarehouseStaffMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ // 提取用户id和角色id
|
|
|
+ List<Long> userIdList = shopWarehouseStaffList.stream()
|
|
|
+ .filter(staff -> staff.getWarehouseId().toString().equals(id))
|
|
|
+ .map(ShopWarehouseStaff::getUserId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Long> roleIdList = shopWarehouseStaffList.stream()
|
|
|
+ .filter(staff -> staff.getWarehouseId().toString().equals(id))
|
|
|
+ .map(ShopWarehouseStaff::getRoleId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 创建 map 以便通过 userId 和 roleId 查询出用户和角色信息
|
|
|
+ Map<Long, EduTenantVo> tenantMap = new HashMap<>();
|
|
|
+ if (!userIdList.isEmpty()) {
|
|
|
+ for (Long userId : userIdList) {
|
|
|
+ RPCBaseResponse<EduTenantVo> tenantVoRPCBaseResponse = tenantAdapter.getTenantById(userId);
|
|
|
+ if (tenantVoRPCBaseResponse != null && tenantVoRPCBaseResponse.getData() != null) {
|
|
|
+ tenantMap.put(userId, tenantVoRPCBaseResponse.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, SysRoleVo> roleMap = new HashMap<>();
|
|
|
+ if (!roleIdList.isEmpty()) {
|
|
|
+ for (Long roleId : roleIdList) {
|
|
|
+ RPCBaseResponse<SysRoleVo> roleVoRPCBaseResponse = sysRoleAdapter.getFormId(String.valueOf(roleId));
|
|
|
+ if (roleVoRPCBaseResponse != null && roleVoRPCBaseResponse.getData() != null) {
|
|
|
+ roleMap.put(roleId, roleVoRPCBaseResponse.getData());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组合结果
|
|
|
+ List<ShopWarehouseStaffVo> resultList = new ArrayList<>();
|
|
|
+ for (ShopWarehouseStaff staff : shopWarehouseStaffList) {
|
|
|
+ if (staff.getWarehouseId().toString().equals(id)) {
|
|
|
+ Long userId = staff.getUserId();
|
|
|
+ Long roleId = staff.getRoleId();
|
|
|
+
|
|
|
+ EduTenantVo user = tenantMap.get(userId);
|
|
|
+ SysRoleVo role = roleMap.get(roleId);
|
|
|
+
|
|
|
+ // 封装用户和角色信息
|
|
|
+ ShopWarehouseStaffVo result = new ShopWarehouseStaffVo();
|
|
|
+ result.setUserId(userId);
|
|
|
+ result.setRoleId(roleId);
|
|
|
+ result.setWarehouseId(staff.getWarehouseId());
|
|
|
+
|
|
|
+ if (user != null) {
|
|
|
+ result.setTenantSurname(user.getTenantSurname());
|
|
|
+ result.setTenantName(user.getTenantName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (role != null) {
|
|
|
+ result.setRoleId(roleId);
|
|
|
+ result.setName(role.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList.add(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回成功响应
|
|
|
+ return new RPCBaseResponse<>(200, "SUCCESS", resultList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|