From 66c53b2faa74bc8a71bde92a1f40039d46e1b691 Mon Sep 17 00:00:00 2001 From: nixj Date: Thu, 11 Jul 2024 13:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90update=E3=80=91=E8=81=8C=E7=BA=A7?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/chint/application/dtos/RanksDto.java | 10 +++++++++- .../chint/application/in/RankController.java | 19 +++++++++++-------- .../application/in/StaffRankController.java | 16 +++++----------- .../domain/value_object/StaffRankData.java | 1 + 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/chint/application/dtos/RanksDto.java b/src/main/java/com/chint/application/dtos/RanksDto.java index f06171e8..f821826f 100644 --- a/src/main/java/com/chint/application/dtos/RanksDto.java +++ b/src/main/java/com/chint/application/dtos/RanksDto.java @@ -1,7 +1,11 @@ package com.chint.application.dtos; +import jakarta.validation.constraints.NotNull; import lombok.Data; + + + /** * * @Author:nxj @@ -9,9 +13,13 @@ import lombok.Data; */ @Data public class RanksDto { + private Integer rankId; + @NotNull private String rankName; + @NotNull private String industry; + @NotNull private String companyCode; + @NotNull private String standardLevel; - private String uniqueWord; } diff --git a/src/main/java/com/chint/application/in/RankController.java b/src/main/java/com/chint/application/in/RankController.java index 67199a94..3b7f2360 100644 --- a/src/main/java/com/chint/application/in/RankController.java +++ b/src/main/java/com/chint/application/in/RankController.java @@ -21,10 +21,12 @@ import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; import com.sun.net.httpserver.Authenticator; import io.swagger.annotations.ApiOperation; +import jakarta.validation.Valid; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -68,16 +70,17 @@ public class RankController { @ApiOperation("保存等级") @PostMapping("/save") - public Result saveRanks(@RequestBody RanksDto dto) { + public Result saveRanks(@Valid @RequestBody RanksDto dto) { Ranks ranks=new Ranks(); BeanUtils.copyProperties(dto,ranks); - return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks)); - } - - @ApiOperation("修改等级") - @PostMapping("/update") - public Result updateRanks(@RequestBody Ranks ranks) { - return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks)); + ranks.setUniqueWord(dto.getRankName() + "-" + dto.getCompanyCode()); + Ranks save = null; + try { + save = ranksRepository.save(ranks); + } catch (Exception e) { + throw new DuplicateException(CommonMessageConstant.DUPLICATE_ERROR); + } + return Result.Success(CommonMessageConstant.SUCCESS, save); } @Transactional diff --git a/src/main/java/com/chint/application/in/StaffRankController.java b/src/main/java/com/chint/application/in/StaffRankController.java index e0371e4f..46b94c5e 100644 --- a/src/main/java/com/chint/application/in/StaffRankController.java +++ b/src/main/java/com/chint/application/in/StaffRankController.java @@ -8,14 +8,14 @@ import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; import com.chint.route.service.UserDepartmentInfoBasicService; import io.swagger.annotations.ApiOperation; +import jakarta.validation.Valid; 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; - import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; @RestController @@ -28,27 +28,21 @@ public class StaffRankController { @Autowired private UserDepartmentInfoBasicService userDepartmentInfoBasicService; - @ApiOperation("新增职级") + @ApiOperation("保存职级") @PostMapping("/save") - public Result save(@RequestBody @Valid StaffRankData staffRankData) { + public Result save(@Valid @RequestBody StaffRankData staffRankData) { StaffRank staffRank = new StaffRank(); BeanUtils.copyProperties(staffRankData,staffRank); return Result.Success(SUCCESS, jdbcStaffRankRepository.save(staffRank)); } - @ApiOperation("新增职级") + @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) { diff --git a/src/main/java/com/chint/domain/value_object/StaffRankData.java b/src/main/java/com/chint/domain/value_object/StaffRankData.java index e2925138..f78fc2dc 100644 --- a/src/main/java/com/chint/domain/value_object/StaffRankData.java +++ b/src/main/java/com/chint/domain/value_object/StaffRankData.java @@ -7,6 +7,7 @@ import lombok.Data; @Data public class StaffRankData { + private Integer id; @NotNull private String employeeNo; //员工名称