|
@@ -13,6 +13,8 @@ import com.lianda.backend.repository.BusCustomerCompanyRepository;
|
|
|
import com.lianda.backend.repository.BusCustomerCustomerTypeRepository;
|
|
import com.lianda.backend.repository.BusCustomerCustomerTypeRepository;
|
|
|
import com.lianda.backend.repository.DispPortRepository;
|
|
import com.lianda.backend.repository.DispPortRepository;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -91,4 +93,57 @@ public class CommonDataService {
|
|
|
company.getMobile()))
|
|
company.getMobile()))
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 搜索船公司(支持分页和模糊搜索)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param companyName 船公司名称(支持模糊搜索)
|
|
|
|
|
+ * @param pageable 分页参数
|
|
|
|
|
+ * @return 船公司分页列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public Page<ShippingCompanyDTO> searchShippingCompanies(String companyName, Pageable pageable) {
|
|
|
|
|
+ // 查询CustomerType=2的所有客户ID
|
|
|
|
|
+ List<BusCustomerCustomerType> customerTypeRecords = busCustomerCustomerTypeRepository.findByCustomerType(2);
|
|
|
|
|
+ Set<String> shippingCompanyCustomerIds = customerTypeRecords.stream()
|
|
|
|
|
+ .map(BusCustomerCustomerType::getCustomerId)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询所有有效的船公司业务记录(RecordStatus=1)
|
|
|
|
|
+ List<BusCustomerCompanyBusiness> validBusinessRecords = busCustomerCompanyBusinessRepository.findAll().stream()
|
|
|
|
|
+ .filter(business -> business.getRecordStatus() != null && business.getRecordStatus() == 1)
|
|
|
|
|
+ .filter(business -> shippingCompanyCustomerIds.contains(business.getCustomerCompanyId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ // 获取这些业务记录对应的客户公司ID
|
|
|
|
|
+ Set<String> customerCompanyIds = validBusinessRecords.stream()
|
|
|
|
|
+ .map(BusCustomerCompanyBusiness::getCustomerCompanyId)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询对应的客户公司信息(支持模糊搜索和分页)
|
|
|
|
|
+ Page<BusCustomerCompany> companyPage;
|
|
|
|
|
+ if (companyName != null && !companyName.isEmpty()) {
|
|
|
|
|
+ companyPage = busCustomerCompanyRepository.findByNameContainingAndRecordStatus(
|
|
|
|
|
+ companyName, 1, pageable);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ companyPage = busCustomerCompanyRepository.findAll(pageable);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 过滤出船公司类型的数据并转换为DTO
|
|
|
|
|
+ List<ShippingCompanyDTO> filteredCompanies = companyPage.getContent().stream()
|
|
|
|
|
+ .filter(company -> customerCompanyIds.contains(company.getCustomerCompanyId()))
|
|
|
|
|
+ .map(company -> new ShippingCompanyDTO(
|
|
|
|
|
+ company.getCustomerCompanyId(),
|
|
|
|
|
+ company.getName(),
|
|
|
|
|
+ company.getContact(),
|
|
|
|
|
+ company.getTel(),
|
|
|
|
|
+ company.getMobile()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ // 创建新的Page对象,只包含过滤后的数据
|
|
|
|
|
+ return new org.springframework.data.domain.PageImpl<>(
|
|
|
|
|
+ filteredCompanies,
|
|
|
|
|
+ pageable,
|
|
|
|
|
+ filteredCompanies.size()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|