From 93c1d3f346b0a9ad2fc451cf8fb79ef4f7b167d3 Mon Sep 17 00:00:00 2001 From: nixj Date: Thu, 16 May 2024 13:31:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90add=E3=80=91=E8=81=8C=E7=BA=A7?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E5=8A=9F=E8=83=BD=E6=96=B0=E5=A2=9E=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9Espring-boot-starter-validation=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +- .../application/in/StaffRankController.java | 56 +++++++++++++++++++ .../application/queryies/StaffRankQuery.java | 10 ++++ .../domain/value_object/StaffRankData.java | 21 +++++++ .../jdbc/JdbcStaffRankRepository.java | 4 ++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chint/application/in/StaffRankController.java create mode 100644 src/main/java/com/chint/application/queryies/StaffRankQuery.java create mode 100644 src/main/java/com/chint/domain/value_object/StaffRankData.java diff --git a/pom.xml b/pom.xml index cffee4c2..e721b0ed 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,10 @@ minio 8.5.6 - + + org.springframework.boot + spring-boot-starter-validation + diff --git a/src/main/java/com/chint/application/in/StaffRankController.java b/src/main/java/com/chint/application/in/StaffRankController.java new file mode 100644 index 00000000..0b5d7214 --- /dev/null +++ b/src/main/java/com/chint/application/in/StaffRankController.java @@ -0,0 +1,56 @@ +package com.chint.application.in; + +import com.chint.application.queryies.StaffRankQuery; +import com.chint.domain.aggregates.standards.StaffRank; +import com.chint.domain.value_object.StaffRankData; +import com.chint.infrastructure.repository.jdbc.JdbcStaffRankRepository; +import com.chint.infrastructure.util.PageResult; +import com.chint.infrastructure.util.Result; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; + +@RestController +@RequestMapping("/staff/rank") +public class StaffRankController { + + @Autowired + private JdbcStaffRankRepository jdbcStaffRankRepository; + + @ApiOperation("新增职级") + @PostMapping("/save") + public Result save(@RequestBody @Valid StaffRankData staffRankData) { + StaffRank staffRank = new StaffRank(); + BeanUtils.copyProperties(staffRankData,staffRank); + return Result.Success(SUCCESS, jdbcStaffRankRepository.save(staffRank)); + } + + @ApiOperation("新增职级") + @PostMapping("/delete/{id}") + public Result delete(@PathVariable("id")Integer id) { + jdbcStaffRankRepository.deleteById(id); + return Result.Success(SUCCESS); + } + + @ApiOperation("修改职级") + @PostMapping("/update") + public Result save(@RequestBody @Valid StaffRank staffRank) { + return Result.Success(SUCCESS, jdbcStaffRankRepository.save(staffRank)); + } + + @ApiOperation("职级分页查询") + @PostMapping("/pageQuery") + public Result> save(@RequestBody StaffRankQuery staffRankQuery) { + PageRequest pageRequest = PageRequest + .of(staffRankQuery.getPageNum() - 1, staffRankQuery.getPageSize()); + Page page=jdbcStaffRankRepository.findAllByEmployeeNoContainsAndEmployeeNameContains(staffRankQuery.getEmployeeNo(),staffRankQuery.getEmployeeName(),pageRequest); + return Result.Success(SUCCESS, PageResult.totalPageNum(page.getTotalElements(), page.getContent())); + } +} diff --git a/src/main/java/com/chint/application/queryies/StaffRankQuery.java b/src/main/java/com/chint/application/queryies/StaffRankQuery.java new file mode 100644 index 00000000..bfbc5c2b --- /dev/null +++ b/src/main/java/com/chint/application/queryies/StaffRankQuery.java @@ -0,0 +1,10 @@ +package com.chint.application.queryies; + +import com.chint.domain.value_object.BaseQuery; +import lombok.Data; + +@Data +public class StaffRankQuery extends BaseQuery { + private String employeeNo=""; + private String employeeName=""; +} diff --git a/src/main/java/com/chint/domain/value_object/StaffRankData.java b/src/main/java/com/chint/domain/value_object/StaffRankData.java new file mode 100644 index 00000000..e2925138 --- /dev/null +++ b/src/main/java/com/chint/domain/value_object/StaffRankData.java @@ -0,0 +1,21 @@ +package com.chint.domain.value_object; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + + + +@Data +public class StaffRankData { + @NotNull + private String employeeNo; + //员工名称 + @NotNull + private String employeeName; + //员工职级 + @NotNull + private String employeeLevel; + //公司标识:1:集团,2:新能 + @NotNull + private String tag; +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcStaffRankRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcStaffRankRepository.java index 3b7dbf23..ae446d66 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcStaffRankRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcStaffRankRepository.java @@ -1,6 +1,8 @@ package com.chint.infrastructure.repository.jdbc; import com.chint.domain.aggregates.standards.StaffRank; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @@ -10,4 +12,6 @@ import java.util.List; public interface JdbcStaffRankRepository extends CrudRepository { List findByEmployeeNoAndTag(String employeeNo,String tag); List findByEmployeeNo(String employeeNo); + + Page findAllByEmployeeNoContainsAndEmployeeNameContains(String employeeNo, String employeeName, Pageable pageable); }