From f76d46a1798a207648b987bc7ddb8d33d92ecff2 Mon Sep 17 00:00:00 2001 From: Stanic <1576302867@qq.com> Date: Sat, 16 Dec 2023 15:45:20 +0000 Subject: [PATCH] =?UTF-8?q?!14=20=E5=AE=8C=E5=96=84=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=B9=B6=E6=8F=90=E4=BA=A4=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=20*=20=E4=BF=AE=E6=94=B9=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=9A=84=E4=BF=9D=E5=AD=98=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=20*=20=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E7=BC=96=E8=AF=91=E9=83=A8=E7=BD=B2=E6=B5=81?= =?UTF-8?q?=E6=B0=B4=E7=BA=BF=20*=20=E8=A7=A3=E5=86=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=99=A8=E7=94=9F=E6=88=90=E7=9A=84Vo?= =?UTF-8?q?=E7=9A=84=E7=89=88=E6=9C=AC=E5=8F=B7=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qing-codegen-plugin/Jenkinsfile | 40 +++++++ .../handller/dto/GenVoCodeProcessor.java | 52 ++++----- .../controller/TestDomainController.java | 100 ++++++++++++++++++ .../domain/dto/creator/TestDomainCreator.java | 20 ++++ .../domain/dto/query/TestDomainQuery.java | 9 ++ .../dto/request/TestDomainCreateRequest.java | 21 ++++ .../dto/request/TestDomainQueryRequest.java | 10 ++ .../dto/request/TestDomainUpdateRequest.java | 31 ++++++ .../dto/response/TestDomainResponse.java | 25 +++++ .../domain/dto/updater/TestDomainUpdater.java | 38 +++++++ .../codegen/domain/dto/vo/TestDomainVO.java | 45 ++++++++ .../domain/mapper/TestDomainMapper.java | 41 +++++++ .../repository/TestDomainRepository.java | 7 ++ .../domain/service/ITestDomainService.java | 40 +++++++ .../service/TestDomainFeignService.java | 58 ++++++++++ .../service/impl/TestDomainServiceImpl.java | 95 +++++++++++++++++ 16 files changed, 607 insertions(+), 25 deletions(-) create mode 100644 qing-codegen-plugin/Jenkinsfile create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/controller/TestDomainController.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/creator/TestDomainCreator.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/query/TestDomainQuery.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainCreateRequest.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainQueryRequest.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainUpdateRequest.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/response/TestDomainResponse.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/updater/TestDomainUpdater.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/vo/TestDomainVO.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/mapper/TestDomainMapper.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/repository/TestDomainRepository.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/ITestDomainService.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/TestDomainFeignService.java create mode 100644 qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/impl/TestDomainServiceImpl.java diff --git a/qing-codegen-plugin/Jenkinsfile b/qing-codegen-plugin/Jenkinsfile new file mode 100644 index 000000000..7bb70c81d --- /dev/null +++ b/qing-codegen-plugin/Jenkinsfile @@ -0,0 +1,40 @@ +pipeline { + agent { + docker { + image 'maven:3.9.5-eclipse-temurin-17-alpine' + args '-v /root/.m2:/root/.m2' + } + } + stages { + stage('编译打包') { + steps { + sh '''mvn clean install -pl qing-codegen-plugin/qing-codegen-apt -am -f pom.xml''' + } + } + stage('代码生成器单元测试') { + steps { + sh '''echo 清理工作空间''' + sh '''mvn clean -pl qing-codegen-plugin/qing-codegen-samples -f pom.xml''' + sh '''echo 开始测试''' + sh '''mvn clean test -pl qing-codegen-plugin/qing-codegen-samples -f pom.xml''' + } + post { + always { + // 收集测试报告 + junit 'qing-codegen-plugin/qing-codegen-samples/target/surefire-reports/*.xml' + } + } + } + stage('代码生成器示例项目单元测试') { + steps { + sh '''mvn clean test -pl qing-codegen-plugin/qing-codegen-samples -f pom.xml''' + } + post { + always { + // 收集测试报告 + junit 'qing-codegen-plugin/qing-codegen-samples/target/surefire-reports/*.xml' + } + } + } + } +} \ No newline at end of file diff --git a/qing-codegen-plugin/qing-codegen-apt/src/main/java/cn/chenyunlong/codegen/handller/dto/GenVoCodeProcessor.java b/qing-codegen-plugin/qing-codegen-apt/src/main/java/cn/chenyunlong/codegen/handller/dto/GenVoCodeProcessor.java index ccd6cbbd9..c1e7aef51 100644 --- a/qing-codegen-plugin/qing-codegen-apt/src/main/java/cn/chenyunlong/codegen/handller/dto/GenVoCodeProcessor.java +++ b/qing-codegen-plugin/qing-codegen-apt/src/main/java/cn/chenyunlong/codegen/handller/dto/GenVoCodeProcessor.java @@ -26,17 +26,18 @@ import com.squareup.javapoet.TypeSpec; import com.squareup.javapoet.TypeSpec.Builder; import io.swagger.v3.oas.annotations.media.Schema; -import java.util.Objects; -import java.util.Set; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; import lombok.AccessLevel; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import java.util.Objects; +import java.util.Set; + /** * vo 代码生成器。 * @@ -53,37 +54,38 @@ public class GenVoCodeProcessor extends AbstractCodeGenProcessor { public void generateClass(TypeElement typeElement, RoundEnvironment roundEnv, boolean useLombok) { Set fields = - findFields(typeElement, - variableElement -> Objects.isNull(variableElement.getAnnotation(IgnoreVo.class))); + findFields(typeElement, + variableElement -> Objects.isNull(variableElement.getAnnotation(IgnoreVo.class))); String sourceClassName = typeElement.getSimpleName() + SUFFIX; Builder builder = TypeSpec - .classBuilder(sourceClassName) - .superclass(AbstractBaseJpaVo.class) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Schema.class); + .classBuilder(sourceClassName) + .superclass(AbstractBaseJpaVo.class) + .addModifiers(Modifier.PUBLIC) + .addAnnotation(Schema.class); if (useLombok) { builder.addAnnotation(Data.class); builder.addAnnotation(/////////// - AnnotationSpec.builder(EqualsAndHashCode.class).addMember("callSuper", "$L", true) - .build()); + AnnotationSpec.builder(EqualsAndHashCode.class).addMember("callSuper", "$L", true) + .build()); builder.addAnnotation(AnnotationSpec - .builder(NoArgsConstructor.class) - .addMember("access", "$T.PROTECTED", AccessLevel.class) - .build()); + .builder(NoArgsConstructor.class) + .addMember("access", "$T.PROTECTED", AccessLevel.class) + .build()); } addSetterAndGetterMethod(builder, fields); MethodSpec.Builder constructorSpecBuilder = MethodSpec - .constructorBuilder() - .addParameter(TypeName.get(typeElement.asType()), "source") - .addModifiers(Modifier.PUBLIC); + .constructorBuilder() + .addParameter(TypeName.get(typeElement.asType()), "source") + .addModifiers(Modifier.PUBLIC); constructorSpecBuilder.addStatement("super()") - .addStatement("this.setId(source.getId());") - .addStatement("this.setCreatedAt(source.getCreatedAt());") - .addStatement("this.setUpdatedAt(source.getCreatedAt());"); + .addStatement("this.setId(source.getId());") + .addStatement("this.setCreatedAt(source.getCreatedAt());") + .addStatement("this.setUpdatedAt(source.getCreatedAt());") + .addStatement("this.setVersion(source.getVersion());"); fields.forEach( - variableElement -> constructorSpecBuilder.addStatement("this.set$L(source.get$L())", - getFieldDefaultName(variableElement), getFieldDefaultName(variableElement))); + variableElement -> constructorSpecBuilder.addStatement("this.set$L(source.get$L())", + getFieldDefaultName(variableElement), getFieldDefaultName(variableElement))); builder.addMethod(constructorSpecBuilder.build()); genJavaSourceFile(typeElement, builder); } diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/controller/TestDomainController.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/controller/TestDomainController.java new file mode 100644 index 000000000..ded8a86b0 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/controller/TestDomainController.java @@ -0,0 +1,100 @@ +package cn.chenyunlong.qing.samples.codegen.domain.controller; + +import cn.chenyunlong.common.constants.CodeEnum; +import cn.chenyunlong.common.model.JsonResult; +import cn.chenyunlong.common.model.PageRequestWrapper; +import cn.chenyunlong.common.model.PageResult; +import cn.chenyunlong.qing.samples.codegen.domain.dto.creator.TestDomainCreator; +import cn.chenyunlong.qing.samples.codegen.domain.dto.query.TestDomainQuery; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainCreateRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainQueryRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainUpdateRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.response.TestDomainResponse; +import cn.chenyunlong.qing.samples.codegen.domain.dto.updater.TestDomainUpdater; +import cn.chenyunlong.qing.samples.codegen.domain.dto.vo.TestDomainVO; +import cn.chenyunlong.qing.samples.codegen.domain.mapper.TestDomainMapper; +import cn.chenyunlong.qing.samples.codegen.domain.service.ITestDomainService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +import java.util.stream.Collectors; + +@RestController +@Slf4j +@RequestMapping("api/v1/test-domain") +@RequiredArgsConstructor +public class TestDomainController { + private final ITestDomainService testDomainService; + + /** + * createRequest + */ + @PostMapping + public JsonResult createTestDomain(@RequestBody TestDomainCreateRequest request) { + TestDomainCreator creator = TestDomainMapper.INSTANCE.request2Dto(request); + return JsonResult.success(testDomainService.createTestDomain(creator)); + } + + /** + * update request + */ + @PostMapping("updateTestDomain") + public JsonResult updateTestDomain(@RequestBody TestDomainUpdateRequest request) { + TestDomainUpdater updater = TestDomainMapper.INSTANCE.request2Updater(request); + testDomainService.updateTestDomain(updater); + return JsonResult.success(CodeEnum.Success.getName()); + } + + /** + * valid + */ + @PostMapping("valid/{id}") + public JsonResult validTestDomain(@PathVariable Long id) { + testDomainService.validTestDomain(id); + return JsonResult.success(CodeEnum.Success.getName()); + } + + /** + * invalid + */ + @PostMapping("invalid/{id}") + public JsonResult invalidTestDomain(@PathVariable Long id) { + testDomainService.invalidTestDomain(id); + return JsonResult.success(CodeEnum.Success.getName()); + } + + /** + * findById + */ + @GetMapping("findById/{id}") + public JsonResult findById(@PathVariable Long id) { + TestDomainVO vo = testDomainService.findById(id); + TestDomainResponse response = TestDomainMapper.INSTANCE.vo2CustomResponse(vo); + return JsonResult.success(response); + } + + /** + * findByPage request + */ + @PostMapping("page") + public JsonResult> page( + @RequestBody PageRequestWrapper request) { + PageRequestWrapper wrapper = new PageRequestWrapper<>(); + wrapper.setBean(TestDomainMapper.INSTANCE.request2Query(request.getBean())); + wrapper.setSorts(request.getSorts()); + wrapper.setPageSize(request.getPageSize()); + wrapper.setPage(request.getPage()); + Page page = testDomainService.findByPage(wrapper); + return JsonResult.success( + PageResult.of( + page.getContent().stream() + .map(TestDomainMapper.INSTANCE::vo2CustomResponse) + .collect(Collectors.toList()), + page.getTotalElements(), + page.getSize(), + page.getNumber()) + ); + } +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/creator/TestDomainCreator.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/creator/TestDomainCreator.java new file mode 100644 index 000000000..1e7f9ac55 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/creator/TestDomainCreator.java @@ -0,0 +1,20 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.creator; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema +@Data +public class TestDomainCreator { + @Schema( + title = "username", + description = "username" + ) + private String username; + + @Schema( + title = "password", + description = "password" + ) + private String password; +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/query/TestDomainQuery.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/query/TestDomainQuery.java new file mode 100644 index 000000000..5d441f713 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/query/TestDomainQuery.java @@ -0,0 +1,9 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.query; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema +@Data +public class TestDomainQuery { +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainCreateRequest.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainCreateRequest.java new file mode 100644 index 000000000..aa5ac1e56 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainCreateRequest.java @@ -0,0 +1,21 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.request; + +import cn.chenyunlong.common.model.Request; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema +@Data +public class TestDomainCreateRequest implements Request { + @Schema( + title = "username", + description = "username" + ) + private String username; + + @Schema( + title = "password", + description = "password" + ) + private String password; +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainQueryRequest.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainQueryRequest.java new file mode 100644 index 000000000..591131ae7 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainQueryRequest.java @@ -0,0 +1,10 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.request; + +import cn.chenyunlong.common.model.Request; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema +@Data +public class TestDomainQueryRequest implements Request { +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainUpdateRequest.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainUpdateRequest.java new file mode 100644 index 000000000..83470b769 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/request/TestDomainUpdateRequest.java @@ -0,0 +1,31 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.request; + +import cn.chenyunlong.common.model.Request; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema +@Data +public class TestDomainUpdateRequest implements Request { + @Schema( + title = "username", + description = "username" + ) + private String username; + + @Schema( + title = "password", + description = "password" + ) + private String password; + + private Long id; + + public Long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/response/TestDomainResponse.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/response/TestDomainResponse.java new file mode 100644 index 000000000..0266e15df --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/response/TestDomainResponse.java @@ -0,0 +1,25 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.response; + +import cn.chenyunlong.common.model.AbstractJpaResponse; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@Schema +@EqualsAndHashCode( + callSuper = true +) +public class TestDomainResponse extends AbstractJpaResponse { + @Schema( + title = "username", + description = "username" + ) + private String username; + + @Schema( + title = "password", + description = "password" + ) + private String password; +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/updater/TestDomainUpdater.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/updater/TestDomainUpdater.java new file mode 100644 index 000000000..0ba75e28f --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/updater/TestDomainUpdater.java @@ -0,0 +1,38 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.updater; + +import cn.chenyunlong.qing.samples.codegen.domain.TestDomain; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.Optional; + +@Schema +@Data +public class TestDomainUpdater { + @Schema( + title = "username", + description = "username" + ) + private String username; + + @Schema( + title = "password", + description = "password" + ) + private String password; + + private Long id; + + public void updateTestDomain(TestDomain param) { + Optional.ofNullable(getUsername()).ifPresent(param::setUsername); + Optional.ofNullable(getPassword()).ifPresent(param::setPassword); + } + + public Long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/vo/TestDomainVO.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/vo/TestDomainVO.java new file mode 100644 index 000000000..ef81e2218 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/dto/vo/TestDomainVO.java @@ -0,0 +1,45 @@ +package cn.chenyunlong.qing.samples.codegen.domain.dto.vo; + +import cn.chenyunlong.common.model.AbstractBaseJpaVo; +import cn.chenyunlong.qing.samples.codegen.domain.TestDomain; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Schema +@Data +@EqualsAndHashCode( + callSuper = true +) +@NoArgsConstructor( + access = AccessLevel.PROTECTED +) +public class TestDomainVO extends AbstractBaseJpaVo { + @Schema( + title = "username", + description = "username" + ) + private String username; + + @Schema( + title = "password", + description = "password" + ) + private String password; + + public TestDomainVO(TestDomain source) { + super(); + this.setId(source.getId()); + ; + this.setCreatedAt(source.getCreatedAt()); + ; + this.setUpdatedAt(source.getCreatedAt()); + ; + this.setVersion(source.getVersion()); + ; + this.setUsername(source.getUsername()); + this.setPassword(source.getPassword()); + } +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/mapper/TestDomainMapper.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/mapper/TestDomainMapper.java new file mode 100644 index 000000000..0b0a28e59 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/mapper/TestDomainMapper.java @@ -0,0 +1,41 @@ +package cn.chenyunlong.qing.samples.codegen.domain.mapper; + +import cn.chenyunlong.qing.samples.codegen.domain.TestDomain; +import cn.chenyunlong.qing.samples.codegen.domain.dto.creator.TestDomainCreator; +import cn.chenyunlong.qing.samples.codegen.domain.dto.query.TestDomainQuery; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainCreateRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainQueryRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainUpdateRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.response.TestDomainResponse; +import cn.chenyunlong.qing.samples.codegen.domain.dto.updater.TestDomainUpdater; +import cn.chenyunlong.qing.samples.codegen.domain.dto.vo.TestDomainVO; +import cn.hutool.core.bean.BeanUtil; + +public interface TestDomainMapper { + TestDomainMapper INSTANCE = new TestDomainMapper() { + }; + + default TestDomain dtoToEntity(TestDomainCreator dto) { + return BeanUtil.copyProperties(dto, TestDomain.class); + } + + default TestDomainUpdater request2Updater(TestDomainUpdateRequest request) { + return BeanUtil.copyProperties(request, TestDomainUpdater.class); + } + + default TestDomainCreator request2Dto(TestDomainCreateRequest request) { + return BeanUtil.copyProperties(request, TestDomainCreator.class); + } + + default TestDomainQuery request2Query(TestDomainQueryRequest request) { + return BeanUtil.copyProperties(request, TestDomainQuery.class); + } + + default TestDomainResponse vo2Response(TestDomainVO vo) { + return BeanUtil.copyProperties(vo, TestDomainResponse.class); + } + + default TestDomainResponse vo2CustomResponse(TestDomainVO vo) { + return vo2Response(vo); + } +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/repository/TestDomainRepository.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/repository/TestDomainRepository.java new file mode 100644 index 000000000..d6cd77b6a --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/repository/TestDomainRepository.java @@ -0,0 +1,7 @@ +package cn.chenyunlong.qing.samples.codegen.domain.repository; + +import cn.chenyunlong.jpa.support.BaseRepository; +import cn.chenyunlong.qing.samples.codegen.domain.TestDomain; + +public interface TestDomainRepository extends BaseRepository { +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/ITestDomainService.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/ITestDomainService.java new file mode 100644 index 000000000..8db5a3935 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/ITestDomainService.java @@ -0,0 +1,40 @@ +package cn.chenyunlong.qing.samples.codegen.domain.service; + +import cn.chenyunlong.common.model.PageRequestWrapper; +import cn.chenyunlong.qing.samples.codegen.domain.dto.creator.TestDomainCreator; +import cn.chenyunlong.qing.samples.codegen.domain.dto.query.TestDomainQuery; +import cn.chenyunlong.qing.samples.codegen.domain.dto.updater.TestDomainUpdater; +import cn.chenyunlong.qing.samples.codegen.domain.dto.vo.TestDomainVO; +import org.springframework.data.domain.Page; + +public interface ITestDomainService { + /** + * create + */ + Long createTestDomain(TestDomainCreator creator); + + /** + * update + */ + void updateTestDomain(TestDomainUpdater updater); + + /** + * valid + */ + void validTestDomain(Long id); + + /** + * invalid + */ + void invalidTestDomain(Long id); + + /** + * findById + */ + TestDomainVO findById(Long id); + + /** + * findByPage + */ + Page findByPage(PageRequestWrapper query); +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/TestDomainFeignService.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/TestDomainFeignService.java new file mode 100644 index 000000000..2ee8c6278 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/TestDomainFeignService.java @@ -0,0 +1,58 @@ +package cn.chenyunlong.qing.samples.codegen.domain.service; + +import cn.chenyunlong.common.model.JsonResult; +import cn.chenyunlong.common.model.PageRequestWrapper; +import cn.chenyunlong.common.model.PageResult; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainCreateRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainQueryRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.request.TestDomainUpdateRequest; +import cn.chenyunlong.qing.samples.codegen.domain.dto.response.TestDomainResponse; +import org.springframework.cloud.openfeign.FeignClient; +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.RequestBody; + +@FeignClient( + value = "stanic", + contextId = "testDomainClient", + path = "testDomain/v1" +) +public interface TestDomainFeignService { + /** + * 创建 + */ + @PostMapping("createTestDomain") + JsonResult createTestDomain(@RequestBody TestDomainCreateRequest request); + + /** + * 更新请求 + */ + @PostMapping("updateTestDomain") + JsonResult updateTestDomain(@RequestBody TestDomainUpdateRequest request); + + /** + * 有效 + */ + @PostMapping("valid/{id}") + JsonResult validTestDomain(@PathVariable("id") Long id); + + /** + * 无效 + */ + @PostMapping("invalid/{id}") + JsonResult invalidTestDomain(@PathVariable("id") Long id); + + /** + * 根据ID查询 + */ + @GetMapping("findById/{id}") + JsonResult findById(@PathVariable("id") Long id); + + /** + * 分页查询 + */ + @PostMapping("findByPage") + JsonResult> page( + @RequestBody PageRequestWrapper request); +} diff --git a/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/impl/TestDomainServiceImpl.java b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/impl/TestDomainServiceImpl.java new file mode 100644 index 000000000..b897848b8 --- /dev/null +++ b/qing-codegen-plugin/qing-codegen-samples/src/main/java/cn/chenyunlong/qing/samples/codegen/domain/service/impl/TestDomainServiceImpl.java @@ -0,0 +1,95 @@ +package cn.chenyunlong.qing.samples.codegen.domain.service.impl; + +import cn.chenyunlong.common.constants.CodeEnum; +import cn.chenyunlong.common.exception.BusinessException; +import cn.chenyunlong.common.model.PageRequestWrapper; +import cn.chenyunlong.jpa.support.BaseJpaAggregate; +import cn.chenyunlong.jpa.support.EntityOperations; +import cn.chenyunlong.qing.samples.codegen.domain.TestDomain; +import cn.chenyunlong.qing.samples.codegen.domain.dto.creator.TestDomainCreator; +import cn.chenyunlong.qing.samples.codegen.domain.dto.query.TestDomainQuery; +import cn.chenyunlong.qing.samples.codegen.domain.dto.updater.TestDomainUpdater; +import cn.chenyunlong.qing.samples.codegen.domain.dto.vo.TestDomainVO; +import cn.chenyunlong.qing.samples.codegen.domain.mapper.TestDomainMapper; +import cn.chenyunlong.qing.samples.codegen.domain.repository.TestDomainRepository; +import cn.chenyunlong.qing.samples.codegen.domain.service.ITestDomainService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +@Transactional +@Service +@Slf4j +@RequiredArgsConstructor +public class TestDomainServiceImpl implements ITestDomainService { + private final TestDomainRepository testDomainRepository; + + /** + * createImpl + */ + @Override + public Long createTestDomain(TestDomainCreator creator) { + Optional testDomain = EntityOperations.doCreate(testDomainRepository) + .create(() -> TestDomainMapper.INSTANCE.dtoToEntity(creator)) + .update(TestDomain::init) + .execute(); + return testDomain.isPresent() ? testDomain.get().getId() : 0; + } + + /** + * update + */ + @Override + public void updateTestDomain(TestDomainUpdater updater) { + EntityOperations.doUpdate(testDomainRepository) + .loadById(updater.getId()) + .update(updater::updateTestDomain) + .execute(); + } + + /** + * valid + */ + @Override + public void validTestDomain(Long id) { + EntityOperations.doUpdate(testDomainRepository) + .loadById(id) + .update(BaseJpaAggregate::valid) + .execute(); + } + + /** + * invalid + */ + @Override + public void invalidTestDomain(Long id) { + EntityOperations.doUpdate(testDomainRepository) + .loadById(id) + .update(BaseJpaAggregate::invalid) + .execute(); + } + + /** + * findById + */ + @Override + public TestDomainVO findById(Long id) { + Optional testDomain = testDomainRepository.findById(id); + return new TestDomainVO(testDomain.orElseThrow(() -> new BusinessException(CodeEnum.NotFindError))); + } + + /** + * findByPage + */ + @Override + public Page findByPage(PageRequestWrapper query) { + PageRequest pageRequest = PageRequest.of(query.getPage(), query.getPageSize(), Sort.Direction.DESC, "createdAt"); + return testDomainRepository.findAll(pageRequest).map(TestDomainVO::new); + } +}