From f9602b1e85a5b12ccad931315df0ffaceb11ece9 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 19 Mar 2025 23:22:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(company):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=85=AC=E5=8F=B8=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=AC=A6=E5=92=8C=E5=88=86=E9=A1=B5=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构了公司列表的查询逻辑,支持动态操作符(如=、like、>、<)进行过滤,并增加了分页大小的调整功能。同时,优化了后端查询接口,使其更灵活和高效。 --- .../pms/repository/CompanyRepository.java | 19 ++++- .../com/vxnet/pms/service/CompanyService.java | 12 ++- .../vxnet/pms/web/rest/CompanyResource.java | 13 +++- .../app/entities/company/company.component.ts | 25 ++++--- .../webapp/app/entities/company/company.vue | 74 ++++++++++++++++--- 5 files changed, 114 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/vxnet/pms/repository/CompanyRepository.java b/src/main/java/com/vxnet/pms/repository/CompanyRepository.java index d3173a2..fb0d002 100644 --- a/src/main/java/com/vxnet/pms/repository/CompanyRepository.java +++ b/src/main/java/com/vxnet/pms/repository/CompanyRepository.java @@ -3,15 +3,19 @@ package com.vxnet.pms.repository; import com.vxnet.pms.domain.Company; import java.util.Map; import org.springframework.data.domain.Pageable; +import org.springframework.data.r2dbc.convert.R2dbcConverter; +import org.springframework.data.r2dbc.core.R2dbcEntityTemplate; import org.springframework.data.r2dbc.repository.Query; import org.springframework.data.r2dbc.repository.R2dbcRepository; import org.springframework.data.repository.query.Param; +import org.springframework.r2dbc.core.DatabaseClient; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @Repository -public interface CompanyRepository extends R2dbcRepository { +public interface CompanyRepository extends R2dbcRepository, CompanyRepositoryInternal { @Query( "SELECT * FROM jhi_company WHERE (:#{#organization} = '*' OR organization = :#{#organization}) " + "AND (:#{#params['number']} IS NULL OR number = :#{#params['number']}) " + @@ -57,3 +61,16 @@ public interface CompanyRepository extends R2dbcRepository { @Query("DELETE FROM jhi_company WHERE id = :id") Mono deleteByIdWithTableName(@Param("id") Long id); } + +interface CompanyRepositoryInternal { + Mono countRows(String organization, String table, Map params); + Flux> getRows(String organization, String table, Map params, Pageable pageable); +} + +@Component +class CompanyRepositoryInternalImpl extends BaseRepository implements CompanyRepositoryInternal { + + public CompanyRepositoryInternalImpl(DatabaseClient db, R2dbcEntityTemplate r2dbcEntityTemplate, R2dbcConverter r2dbcConverter) { + super(db, r2dbcEntityTemplate, r2dbcConverter); + } +} diff --git a/src/main/java/com/vxnet/pms/service/CompanyService.java b/src/main/java/com/vxnet/pms/service/CompanyService.java index 24c231f..fc4ca6a 100644 --- a/src/main/java/com/vxnet/pms/service/CompanyService.java +++ b/src/main/java/com/vxnet/pms/service/CompanyService.java @@ -90,11 +90,15 @@ public class CompanyService { * @return the list of entities. */ @Transactional(readOnly = true) - public Flux getCompanies(Map params, Pageable pageable) { - log.info("Pageable Sort: " + pageable.getSort().toString().replace(':', ' ')); + public Mono countCompanies(String table, Map params) { + return SecurityUtils.getCurrentOrganization().flatMap(organization -> companyRepository.countRows(organization, table, params)); + } + + @Transactional(readOnly = true) + public Flux> getCompanies(String table, Map params, Pageable pageable) { return SecurityUtils.getCurrentOrganization() - .map(organization -> companyRepository.findCompanies(organization, params, pageable)) - .flatMapMany(companys -> companys); + .map(organization -> companyRepository.getRows(organization, table, params, pageable)) + .flatMapMany(companies -> companies); } /** diff --git a/src/main/java/com/vxnet/pms/web/rest/CompanyResource.java b/src/main/java/com/vxnet/pms/web/rest/CompanyResource.java index cf4e968..fe71b89 100644 --- a/src/main/java/com/vxnet/pms/web/rest/CompanyResource.java +++ b/src/main/java/com/vxnet/pms/web/rest/CompanyResource.java @@ -41,7 +41,7 @@ public class CompanyResource { "property", "remark", "status", - "sortNo", + "sort_no", "createdBy", "createdDate", "updatedBy", @@ -90,14 +90,21 @@ public class CompanyResource { * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of companies in body. */ @GetMapping("/companies") - public Mono>> getCompanies( + public Mono>>> getCompanies( @RequestParam Map params, @org.springdoc.core.annotations.ParameterObject Pageable pageable ) { if (!onlyContainsAllowedProperties(pageable)) { return Mono.just(ResponseEntity.badRequest().build()); } - return Mono.just(ResponseEntity.ok().body(companyService.getCompanies(params, pageable))); + String table = "jhi_company"; + return companyService + .countCompanies(table, params) + .map(total -> + ResponseEntity.ok() + .header("X-Total-Count", String.valueOf(total)) + .body(companyService.getCompanies(table, params, pageable)) + ); } /** diff --git a/src/main/webapp/app/entities/company/company.component.ts b/src/main/webapp/app/entities/company/company.component.ts index 9b380a8..ab61345 100644 --- a/src/main/webapp/app/entities/company/company.component.ts +++ b/src/main/webapp/app/entities/company/company.component.ts @@ -32,9 +32,9 @@ export default defineComponent({ // 过滤参数 const filterParams = ref({ - number: null, - name: null, - licenseNo: null, + number: { op: '=', value: null }, + name: { op: '=', value: null }, + licenseNo: { op: '=', value: null }, }); const openDialog = () => { @@ -67,20 +67,22 @@ export default defineComponent({ try { isFetching.value = true; const processedParams = showFilter.value - ? Object.entries(filterParams.value).reduce((acc, [key, value]) => { - acc[key] = value === '' ? null : value; + ? Object.entries(filterParams.value).reduce((acc, [key, { op, value }]) => { + if (value !== null && value !== '') { + acc[key] = { op, value }; + } return acc; }, {}) : {}; - const companyRes = await axios.get('api/companies', { - params: { + const companyRes = await axios.get( + `api/companies?${buildPaginationQuery({ page: page.value - 1, size: itemsPerPage.value, sort: sort(), ...processedParams, - }, - }); + })}`, + ); companies.value = companyRes.data; totalItems.value = companyRes.headers['x-total-count'] || companyRes.data.length; } catch (err) { @@ -123,6 +125,11 @@ export default defineComponent({ loadAll(); }; + const handlePageSizeChange = () => { + page.value = 1; // 重置页码 + loadAll(); + }; + const changeOrder = (prop: string): void => { propOrder.value = prop; reverse.value = !reverse.value; diff --git a/src/main/webapp/app/entities/company/company.vue b/src/main/webapp/app/entities/company/company.vue index 93a613f..db5e19a 100644 --- a/src/main/webapp/app/entities/company/company.vue +++ b/src/main/webapp/app/entities/company/company.vue @@ -28,15 +28,39 @@
- +
+ + +
- +
+ + +
- +
+ + +
@@ -49,12 +73,30 @@ - - - - - - + + + + + + @@ -88,18 +130,26 @@
-
+
+ +
+
{{ $t('global.item-count', { first: (page - 1) * itemsPerPage + 1, - second: page * itemsPerPage < totalItems ? page * itemsPerPage : totalItems, + second: itemsPerPage > 0 && page * itemsPerPage < totalItems ? page * itemsPerPage : totalItems, total: totalItems, }) }}
-
+
+ + + + + + + + + + + + + + + + + +