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; //员工名称