优化检索
This commit is contained in:
@@ -52,6 +52,9 @@ onMounted(() => {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
url: `${information.baseUrl}/jsonapi/organization`,
|
url: `${information.baseUrl}/jsonapi/organization`,
|
||||||
data: {
|
data: {
|
||||||
|
fields: {
|
||||||
|
organization: 'name'
|
||||||
|
},
|
||||||
page: {
|
page: {
|
||||||
size: '${perPage|default:undefined}',
|
size: '${perPage|default:undefined}',
|
||||||
number: '${page|default:undefined}',
|
number: '${page|default:undefined}',
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
package com.lanyuanxiaoyao.server.controller.base;
|
package com.lanyuanxiaoyao.server.controller.base;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
public abstract class AbstractController<ENTITY, ID> {
|
public abstract class AbstractController<ENTITY, ID> {
|
||||||
public abstract AbstractService<ENTITY, ID> getService();
|
public abstract AbstractService<ENTITY, ID> getService();
|
||||||
|
|
||||||
@PostMapping("save")
|
@GetMapping("/get/{id}")
|
||||||
|
public ENTITY get(@PathVariable("id") ID id) {
|
||||||
|
return getService().get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/save")
|
||||||
public ID save(@RequestBody ENTITY entity) {
|
public ID save(@RequestBody ENTITY entity) {
|
||||||
return getService().save(entity);
|
return getService().save(entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper;
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.server.entity.Department;
|
import com.lanyuanxiaoyao.server.entity.Department;
|
||||||
import com.lanyuanxiaoyao.server.entity.mapper.qualifier.DepartmentQualifier;
|
|
||||||
import com.lanyuanxiaoyao.server.entity.mapper.qualifier.OrganizationQualifier;
|
|
||||||
import com.lanyuanxiaoyao.server.entity.vo.DepartmentSaveVO;
|
import com.lanyuanxiaoyao.server.entity.vo.DepartmentSaveVO;
|
||||||
|
import com.lanyuanxiaoyao.server.service.DepartmentService;
|
||||||
|
import com.lanyuanxiaoyao.server.service.OrganizationService;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ import org.mapstruct.Mapping;
|
|||||||
*/
|
*/
|
||||||
@Mapper(
|
@Mapper(
|
||||||
uses = {
|
uses = {
|
||||||
OrganizationQualifier.class,
|
OrganizationService.class,
|
||||||
DepartmentQualifier.class,
|
DepartmentService.class,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public abstract class DepartmentMapper implements EntityMapper<Department, DepartmentSaveVO> {
|
public abstract class DepartmentMapper implements EntityMapper<Department, DepartmentSaveVO> {
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper.qualifier;
|
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.server.entity.Department;
|
|
||||||
import com.lanyuanxiaoyao.server.repository.DepartmentRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class DepartmentQualifier implements EntityQualifier<Department, Long> {
|
|
||||||
private final DepartmentRepository departmentRepository;
|
|
||||||
|
|
||||||
public DepartmentQualifier(DepartmentRepository departmentRepository) {
|
|
||||||
this.departmentRepository = departmentRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Department get(Long id) {
|
|
||||||
return departmentRepository.getReferenceById(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper.qualifier;
|
|
||||||
|
|
||||||
public interface EntityQualifier<E, ID> {
|
|
||||||
E get(ID id);
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper.qualifier;
|
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.server.entity.Organization;
|
|
||||||
import com.lanyuanxiaoyao.server.repository.OrganizationRepository;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class OrganizationQualifier implements EntityQualifier<Organization, Long> {
|
|
||||||
private final OrganizationRepository organizationRepository;
|
|
||||||
|
|
||||||
public OrganizationQualifier(OrganizationRepository organizationRepository) {
|
|
||||||
this.organizationRepository = organizationRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Organization get(Long id) {
|
|
||||||
return organizationRepository.getReferenceById(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.service;
|
||||||
|
|
||||||
|
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||||
|
import com.lanyuanxiaoyao.server.entity.Department;
|
||||||
|
import com.lanyuanxiaoyao.server.repository.DepartmentRepository;
|
||||||
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class DepartmentService extends AbstractService<Department, Long> {
|
||||||
|
private final DepartmentRepository departmentRepository;
|
||||||
|
|
||||||
|
public DepartmentService(DepartmentRepository departmentRepository) {
|
||||||
|
this.departmentRepository = departmentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FenixJpaRepository<Department, Long> getRepository() {
|
||||||
|
return departmentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId(Department department) {
|
||||||
|
return department.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.server.service;
|
package com.lanyuanxiaoyao.server.service;
|
||||||
|
|
||||||
|
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||||
import com.lanyuanxiaoyao.server.entity.Organization;
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
import com.lanyuanxiaoyao.server.repository.OrganizationRepository;
|
import com.lanyuanxiaoyao.server.repository.OrganizationRepository;
|
||||||
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
@@ -16,8 +17,12 @@ public class OrganizationService extends AbstractService<Organization, Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long save(Organization organization) {
|
public FenixJpaRepository<Organization, Long> getRepository() {
|
||||||
Organization save = organizationRepository.saveOrUpdateByNotNullProperties(organization);
|
return organizationRepository;
|
||||||
return save.getId();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId(Organization organization) {
|
||||||
|
return organization.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
package com.lanyuanxiaoyao.server.service.base;
|
package com.lanyuanxiaoyao.server.service.base;
|
||||||
|
|
||||||
|
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||||
|
|
||||||
public abstract class AbstractService<ENTITY, ID> {
|
public abstract class AbstractService<ENTITY, ID> {
|
||||||
public abstract ID save(ENTITY entity);
|
public abstract FenixJpaRepository<ENTITY, ID> getRepository();
|
||||||
|
|
||||||
|
public abstract ID getId(ENTITY entity);
|
||||||
|
|
||||||
|
public ENTITY get(ID id) {
|
||||||
|
return getRepository().getReferenceById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ID save(ENTITY entity) {
|
||||||
|
ENTITY saved = getRepository().saveOrUpdateByNotNullProperties(entity);
|
||||||
|
return getId(saved);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user