优化代码,针对增改场景使用传统方式实现
This commit is contained in:
20
.idea/compiler.xml
generated
20
.idea/compiler.xml
generated
@@ -7,9 +7,27 @@
|
|||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="spring-boot-server-template" />
|
|
||||||
<module name="spring-boot-apijson-server" />
|
<module name="spring-boot-apijson-server" />
|
||||||
</profile>
|
</profile>
|
||||||
|
<profile name="Annotation profile for spring-boot-server-template" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<option name="mapstruct.defaultComponentModel" value="spring" />
|
||||||
|
<option name="mapstruct.defaultInjectionStrategy" value="constructor" />
|
||||||
|
<processorPath useClasspath="false">
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/mapstruct/mapstruct-processor/1.6.3/mapstruct-processor-1.6.3.jar" />
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/mapstruct/mapstruct/1.6.3/mapstruct-1.6.3.jar" />
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/unknown/lombok-unknown.jar" />
|
||||||
|
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok-mapstruct-binding/0.2.0/lombok-mapstruct-binding-0.2.0.jar" />
|
||||||
|
</processorPath>
|
||||||
|
<module name="spring-boot-server-template" />
|
||||||
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="JavacSettings">
|
||||||
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
<module name="spring-boot-server-template" options="-Amapstruct.defaultComponentModel=spring -Amapstruct.defaultInjectionStrategy=constructor" />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -28,18 +28,10 @@ onMounted(() => {
|
|||||||
type: 'form',
|
type: 'form',
|
||||||
api: {
|
api: {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: `${information.baseUrl}/jsonapi`,
|
url: `${information.baseUrl}/organization/save`,
|
||||||
data: {
|
data: {
|
||||||
data: {
|
name: '${name}',
|
||||||
type: 'organization',
|
|
||||||
attributes: {
|
|
||||||
name: '${name}'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/vnd.api+json'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
body: [
|
body: [
|
||||||
{
|
{
|
||||||
@@ -60,7 +52,7 @@ onMounted(() => {
|
|||||||
page: {
|
page: {
|
||||||
size: '${perPage|default:undefined}',
|
size: '${perPage|default:undefined}',
|
||||||
number: '${page|default:undefined}',
|
number: '${page|default:undefined}',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
columns: [
|
columns: [
|
||||||
|
|||||||
49
pom.xml
49
pom.xml
@@ -16,7 +16,7 @@
|
|||||||
<spring-boot.version>3.4.0</spring-boot.version>
|
<spring-boot.version>3.4.0</spring-boot.version>
|
||||||
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
||||||
<hutool.version>5.8.32</hutool.version>
|
<hutool.version>5.8.32</hutool.version>
|
||||||
<elide.version>7.1.4</elide.version>
|
<mapstruct.version>1.6.3</mapstruct.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -45,7 +45,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.yahoo.elide</groupId>
|
<groupId>com.yahoo.elide</groupId>
|
||||||
<artifactId>elide-spring-boot-starter</artifactId>
|
<artifactId>elide-spring-boot-starter</artifactId>
|
||||||
<version>${elide.version}</version>
|
<version>7.1.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.blinkfox</groupId>
|
||||||
|
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -53,6 +58,15 @@
|
|||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>${hutool.version}</version>
|
<version>${hutool.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<version>${mapstruct.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
@@ -62,10 +76,6 @@
|
|||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -90,6 +100,33 @@
|
|||||||
<build>
|
<build>
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.12.1</version>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>${mapstruct.version}</version>
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||||
|
<version>0.2.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
<compilerArgs>
|
||||||
|
<arg>-Amapstruct.defaultComponentModel=spring</arg>
|
||||||
|
<arg>-Amapstruct.defaultInjectionStrategy=constructor</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-build</artifactId>
|
<artifactId>spring-boot-build</artifactId>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.lanyuanxiaoyao.server;
|
package com.lanyuanxiaoyao.server;
|
||||||
|
|
||||||
|
import com.blinkfox.fenix.EnableFenix;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
@@ -13,6 +16,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||||||
* @since 2025-03-03
|
* @since 2025-03-03
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@EnableFenix
|
||||||
|
@EnableConfigurationProperties
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ServerApplication {
|
public class ServerApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.controller;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.controller.base.AbstractController;
|
||||||
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
|
import com.lanyuanxiaoyao.server.service.OrganizationService;
|
||||||
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("organization")
|
||||||
|
public class OrganizationController extends AbstractController<Organization, Long> {
|
||||||
|
private final OrganizationService organizationService;
|
||||||
|
|
||||||
|
public OrganizationController(OrganizationService organizationService) {
|
||||||
|
this.organizationService = organizationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractService<Organization, Long> getService() {
|
||||||
|
return organizationService;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.controller.base;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
public abstract class AbstractController<ENTITY, ID> {
|
||||||
|
public abstract AbstractService<ENTITY, ID> getService();
|
||||||
|
|
||||||
|
@PostMapping("save")
|
||||||
|
public ID save(@RequestBody ENTITY entity) {
|
||||||
|
return getService().save(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,4 +37,12 @@ public class Organization {
|
|||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private Set<Department> departments;
|
private Set<Department> departments;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public static final class SaveVO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
|
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 org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门bean转换
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250327
|
||||||
|
*/
|
||||||
|
@Mapper(
|
||||||
|
uses = {
|
||||||
|
OrganizationQualifier.class,
|
||||||
|
DepartmentQualifier.class,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public abstract class DepartmentMapper implements EntityMapper<Department, DepartmentSaveVO> {
|
||||||
|
@Mapping(target = "organization", source = "organizationId")
|
||||||
|
@Mapping(target = "parent", source = "parentId")
|
||||||
|
@Override
|
||||||
|
public abstract Department fromVO(DepartmentSaveVO saveVO);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
|
interface EntityMapper<SE, CE> {
|
||||||
|
SE fromVO(CE creationVO);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织bean转换
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250327
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface OrganizationMapper extends EntityMapper<Organization, Organization.SaveVO> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity.mapper.qualifier;
|
||||||
|
|
||||||
|
public interface EntityQualifier<E, ID> {
|
||||||
|
E get(ID id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
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,15 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity.vo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class DepartmentSaveVO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Long organizationId;
|
||||||
|
private Long parentId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.repository;
|
||||||
|
|
||||||
|
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||||
|
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||||
|
import com.lanyuanxiaoyao.server.entity.Department;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface DepartmentRepository extends FenixJpaRepository<Department, Long>, FenixJpaSpecificationExecutor<Department> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.repository;
|
||||||
|
|
||||||
|
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||||
|
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||||
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface OrganizationRepository extends FenixJpaRepository<Organization, Long>, FenixJpaSpecificationExecutor<Organization> {
|
||||||
|
@Override
|
||||||
|
Organization getReferenceById(Long aLong);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.service;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
|
import com.lanyuanxiaoyao.server.repository.OrganizationRepository;
|
||||||
|
import com.lanyuanxiaoyao.server.service.base.AbstractService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class OrganizationService extends AbstractService<Organization, Long> {
|
||||||
|
private final OrganizationRepository organizationRepository;
|
||||||
|
|
||||||
|
public OrganizationService(OrganizationRepository organizationRepository) {
|
||||||
|
this.organizationRepository = organizationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long save(Organization organization) {
|
||||||
|
Organization save = organizationRepository.saveOrUpdateByNotNullProperties(organization);
|
||||||
|
return save.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.service.base;
|
||||||
|
|
||||||
|
public abstract class AbstractService<ENTITY, ID> {
|
||||||
|
public abstract ID save(ENTITY entity);
|
||||||
|
}
|
||||||
@@ -28,4 +28,6 @@ logging:
|
|||||||
datastores:
|
datastores:
|
||||||
jpql:
|
jpql:
|
||||||
query:
|
query:
|
||||||
DefaultQueryLogger: debug
|
DefaultQueryLogger: debug
|
||||||
|
fenix:
|
||||||
|
print-banner: false
|
||||||
Reference in New Issue
Block a user