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); }