|
@@ -4,24 +4,21 @@ import com.lianda.backend.config.DataSource;
|
|
|
import com.lianda.backend.config.RoutingDataSourceConfig;
|
|
import com.lianda.backend.config.RoutingDataSourceConfig;
|
|
|
import com.lianda.backend.dto.PortDTO;
|
|
import com.lianda.backend.dto.PortDTO;
|
|
|
import com.lianda.backend.dto.ShippingCompanyDTO;
|
|
import com.lianda.backend.dto.ShippingCompanyDTO;
|
|
|
-import com.lianda.backend.model.BusCustomerCompany;
|
|
|
|
|
import com.lianda.backend.model.BusCustomerCompanyBusiness;
|
|
import com.lianda.backend.model.BusCustomerCompanyBusiness;
|
|
|
-import com.lianda.backend.model.BusCustomerCustomerType;
|
|
|
|
|
import com.lianda.backend.model.DispPort;
|
|
import com.lianda.backend.model.DispPort;
|
|
|
import com.lianda.backend.repository.BusCustomerCompanyBusinessRepository;
|
|
import com.lianda.backend.repository.BusCustomerCompanyBusinessRepository;
|
|
|
-import com.lianda.backend.repository.BusCustomerCompanyRepository;
|
|
|
|
|
-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.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,10 +35,8 @@ public class CommonDataService {
|
|
|
private BusCustomerCompanyBusinessRepository busCustomerCompanyBusinessRepository;
|
|
private BusCustomerCompanyBusinessRepository busCustomerCompanyBusinessRepository;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private BusCustomerCompanyRepository busCustomerCompanyRepository;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private BusCustomerCustomerTypeRepository busCustomerCustomerTypeRepository;
|
|
|
|
|
|
|
+ @Qualifier("readJdbcTemplate")
|
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取有效的港口列表(RecordStatus=1)
|
|
* 获取有效的港口列表(RecordStatus=1)
|
|
@@ -98,46 +93,69 @@ public class CommonDataService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 搜索船公司(支持分页和模糊搜索)
|
|
|
|
|
- *
|
|
|
|
|
|
|
+ * 搜索船公司列表(支持分页和模糊搜索)
|
|
|
* @param companyName 船公司名称(支持模糊搜索)
|
|
* @param companyName 船公司名称(支持模糊搜索)
|
|
|
* @param pageable 分页参数
|
|
* @param pageable 分页参数
|
|
|
* @return 船公司分页列表
|
|
* @return 船公司分页列表
|
|
|
*/
|
|
*/
|
|
|
public Page<ShippingCompanyDTO> searchShippingCompanies(String companyName, Pageable pageable) {
|
|
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());
|
|
|
|
|
-
|
|
|
|
|
- // 查询对应的客户公司信息(支持模糊搜索和分页)
|
|
|
|
|
- Page<BusCustomerCompany> companyPage;
|
|
|
|
|
|
|
+ // 构建SQL查询
|
|
|
|
|
+ StringBuilder sql = new StringBuilder(
|
|
|
|
|
+ "SELECT ccb.CustomerCompanyBusinessId, cc.Name, ccb.BusinessCode " +
|
|
|
|
|
+ "FROM Bus_CustomerCompanyBusiness ccb " +
|
|
|
|
|
+ "INNER JOIN Bus_CustomerCompany cc ON ccb.CustomerCompanyID = cc.CustomerCompanyID " +
|
|
|
|
|
+ "INNER JOIN Bus_Customer_CustomerType cct ON cc.CustomerCompanyID = cct.CustomerID " +
|
|
|
|
|
+ "WHERE cct.CustomerType = 2 " +
|
|
|
|
|
+ "AND ccb.RecordStatus = 1 " +
|
|
|
|
|
+ "AND cc.RecordStatus = 1"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 添加模糊搜索条件
|
|
|
|
|
+ if (companyName != null && !companyName.isEmpty()) {
|
|
|
|
|
+ sql.append(" AND (LOWER(ccb.BusinessCode) LIKE CONCAT('%', LOWER(?), '%') OR LOWER(cc.Name) LIKE CONCAT('%', LOWER(?), '%'))");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询总数
|
|
|
|
|
+ String countSql = "SELECT COUNT(*) " + sql.substring(sql.indexOf("FROM"));
|
|
|
|
|
+ Integer total;
|
|
|
if (companyName != null && !companyName.isEmpty()) {
|
|
if (companyName != null && !companyName.isEmpty()) {
|
|
|
- companyPage = busCustomerCompanyRepository.findByNameContainingAndRecordStatus(
|
|
|
|
|
- companyName, 1, pageable);
|
|
|
|
|
|
|
+ total = jdbcTemplate.queryForObject(countSql, Integer.class, companyName, companyName);
|
|
|
} else {
|
|
} else {
|
|
|
- Sort sort = Sort.by(Sort.Direction.ASC, "name");
|
|
|
|
|
- Pageable sortedPageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
|
|
|
|
|
- companyPage = busCustomerCompanyRepository.findByRecordStatus(1, sortedPageable);
|
|
|
|
|
|
|
+ total = jdbcTemplate.queryForObject(countSql, Integer.class);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 过滤出船公司类型的数据并转换为DTO
|
|
|
|
|
- List<ShippingCompanyDTO> filteredCompanies = companyPage.getContent().stream()
|
|
|
|
|
- .filter(company -> shippingCompanyCustomerIds.contains(company.getCustomerCompanyId()))
|
|
|
|
|
- .map(company -> new ShippingCompanyDTO(
|
|
|
|
|
- company.getCustomerCompanyId(),
|
|
|
|
|
- company.getName(),
|
|
|
|
|
- company.getContact(),
|
|
|
|
|
- company.getTel(),
|
|
|
|
|
- company.getMobile()))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 添加排序和分页
|
|
|
|
|
+ sql.append(" ORDER BY cc.Name");
|
|
|
|
|
+ sql.append(" LIMIT ").append(pageable.getPageSize());
|
|
|
|
|
+ sql.append(" OFFSET ").append(pageable.getOffset());
|
|
|
|
|
+
|
|
|
|
|
+ // 查询数据
|
|
|
|
|
+ List<ShippingCompanyDTO> shippingCompanies;
|
|
|
|
|
+ if (companyName != null && !companyName.isEmpty()) {
|
|
|
|
|
+ shippingCompanies = jdbcTemplate.query(sql.toString(),
|
|
|
|
|
+ (rs, rowNum) -> new ShippingCompanyDTO(
|
|
|
|
|
+ rs.getString("CustomerCompanyBusinessId"),
|
|
|
|
|
+ rs.getString("Name"),
|
|
|
|
|
+ null,
|
|
|
|
|
+ null,
|
|
|
|
|
+ null
|
|
|
|
|
+ ), companyName, companyName);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ shippingCompanies = jdbcTemplate.query(sql.toString(),
|
|
|
|
|
+ (rs, rowNum) -> new ShippingCompanyDTO(
|
|
|
|
|
+ rs.getString("CustomerCompanyBusinessId"),
|
|
|
|
|
+ rs.getString("Name"),
|
|
|
|
|
+ null,
|
|
|
|
|
+ null,
|
|
|
|
|
+ null
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 创建新的Page对象
|
|
// 创建新的Page对象
|
|
|
- return new org.springframework.data.domain.PageImpl<>(
|
|
|
|
|
- filteredCompanies,
|
|
|
|
|
|
|
+ return new PageImpl<>(
|
|
|
|
|
+ shippingCompanies,
|
|
|
pageable,
|
|
pageable,
|
|
|
- companyPage.getTotalElements()
|
|
|
|
|
|
|
+ total
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|