diff --git a/README.md b/README.md index 274f0450..5acee48a 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ ### dtos 业务数据类 ### in -内部接口 +内部接口controller ### out -登录 +登录等外部接口controller ### queryies 订单查询方法工具类 ### services diff --git a/src/main/java/com/chint/application/dtos/RanksDto.java b/src/main/java/com/chint/application/dtos/RanksDto.java new file mode 100644 index 00000000..f06171e8 --- /dev/null +++ b/src/main/java/com/chint/application/dtos/RanksDto.java @@ -0,0 +1,17 @@ +package com.chint.application.dtos; + +import lombok.Data; + +/** + * + * @Author:nxj + * @Date:2024/5/23 10:12 + */ +@Data +public class RanksDto { + private String rankName; + private String industry; + private String companyCode; + 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 91c65637..f8e8ab64 100644 --- a/src/main/java/com/chint/application/in/RankController.java +++ b/src/main/java/com/chint/application/in/RankController.java @@ -1,26 +1,36 @@ package com.chint.application.in; +import com.chint.application.dtos.RanksDto; import com.chint.domain.aggregates.standards.DifferenceStandards; import com.chint.domain.aggregates.standards.Ranks; +import com.chint.domain.aggregates.standards.RanksStandardLevel; import com.chint.domain.aggregates.standards.TravelStandards; import com.chint.domain.exceptions.DuplicateException; import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.factoriy.ranks.RanksFactory; import com.chint.domain.repository.RanksRepository; import com.chint.domain.repository.TravelStandardsRepository; +import com.chint.domain.value_object.BaseQuery; import com.chint.domain.value_object.RanksData; import com.chint.domain.value_object.TravelStandardsData; import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.RankConstant; +import com.chint.infrastructure.repository.jdbc.JdbcRanksRepository; +import com.chint.infrastructure.repository.jdbc.JdbcRanksStandardLevelRepository; +import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; +import com.sun.net.httpserver.Authenticator; 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.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Comparator; import java.util.List; @RestController @@ -28,58 +38,40 @@ import java.util.List; public class RankController { @Autowired - private RanksRepository ranksRepository; - - @Autowired - private RanksFactory ranksFactory; + private JdbcRanksRepository jdbcRanksRepository; @Autowired private TravelStandardsRepository travelStandardsRepository; - @Transactional - @ApiOperation("保存职级和差标映射") - @PostMapping("/save") - public Result saveRanks(@RequestBody RanksData ranksdata) { - Ranks ranks = ranksFactory.createRanks(ranksdata); - Ranks save = null; - try { - save = ranksRepository.save(ranks); - } catch (Exception e) { - throw new DuplicateException(CommonMessageConstant.DUPLICATE_ERROR); - } - return Result.Success(CommonMessageConstant.SUCCESS, save); + @Autowired + private JdbcRanksStandardLevelRepository jdbcRanksStandardLevelRepository; + + + @ApiOperation("分页查询等级") + @PostMapping("/pageQuery") + public Result> pageQuery(@RequestBody BaseQuery query) { + Page ranksPage=jdbcRanksRepository.findAll(query.getPageResult()); + return Result.Success(CommonMessageConstant.SUCCESS,PageResult.totalPageNum(ranksPage.getTotalElements(),ranksPage.getContent())); } -// @Transactional -// @ApiOperation("添加差标") -// @PostMapping("/add/standards") -// public Result addStandardsToRanks(@RequestBody StandardsData standardsData) { -// Ranks ranks = ranksRepository.queryById(standardsData.getRanksId()); -// DifferenceStandards differenceStandards = ranksFactory.createDifferenceStandards(standardsData); -// ranks.addStandards(differenceStandards); -// return Result.Success(SUCCESS, ranks); -// } + @ApiOperation("查询可选等级列表") + @PostMapping("/level/query") + public Result> levelQuery() { + return Result.Success(CommonMessageConstant.SUCCESS,jdbcRanksStandardLevelRepository.findAll().stream().sorted(Comparator.comparing(RanksStandardLevel::getId)).toList()); + } - @Transactional - @ApiOperation("修改差标") + @ApiOperation("保存等级") + @PostMapping("/save") + public Result saveRanks(@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 RanksData ranksdata) { - Ranks ranks = ranksRepository.queryById(ranksdata.getRankId()); - ranks.setStandardLevel( - switch (ranksdata.getLevel()) { - case 1 -> RankConstant.STANDARD_LEVEL_ONE; - case 2 -> RankConstant.STANDARD_LEVEL_TWO; - case 3 -> RankConstant.STANDARD_LEVEL_THREE; - case 4 -> RankConstant.STANDARD_LEVEL_FOUR; - default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND); - }); - ranks.setIndustry(ranksdata.getIndustry()); - if (ranksdata.getStandardsData() != null) { - DifferenceStandards differenceStandards = ranksFactory.createDifferenceStandards(ranksdata.getStandardsData()); -// ranks.addStandards(differenceStandards); - } - ranksRepository.save(ranks); - return Result.Success(CommonMessageConstant.SUCCESS, ranks); + public Result updateRanks(@RequestBody Ranks ranks) { + return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks)); } @Transactional diff --git a/src/main/java/com/chint/domain/aggregates/standards/RanksStandardLevel.java b/src/main/java/com/chint/domain/aggregates/standards/RanksStandardLevel.java new file mode 100644 index 00000000..3d17c149 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/standards/RanksStandardLevel.java @@ -0,0 +1,22 @@ +package com.chint.domain.aggregates.standards; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + + +@Data +@Table("ranks_standard_level") +public class RanksStandardLevel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + @Id + private Long id; + /** + * 差标等级 + */ + private String standardLevel; +} \ No newline at end of file diff --git a/src/main/java/com/chint/domain/value_object/BaseQuery.java b/src/main/java/com/chint/domain/value_object/BaseQuery.java index ef1ad27e..c556bda2 100644 --- a/src/main/java/com/chint/domain/value_object/BaseQuery.java +++ b/src/main/java/com/chint/domain/value_object/BaseQuery.java @@ -3,9 +3,9 @@ package com.chint.domain.value_object; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.data.domain.PageRequest; import java.time.LocalDate; -import java.time.LocalDateTime; @Data public class BaseQuery { @@ -17,4 +17,10 @@ public class BaseQuery { private LocalDate endDate; @ApiModelProperty("排序字段") private Integer sort = 0; + + public PageRequest getPageResult() { + PageRequest pageRequest = PageRequest + .of(pageNum - 1, pageSize); + return pageRequest; + } } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksRepository.java index c914c056..fae3a04e 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksRepository.java @@ -1,6 +1,8 @@ package com.chint.infrastructure.repository.jdbc; import com.chint.domain.aggregates.standards.Ranks; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @@ -11,4 +13,6 @@ public interface JdbcRanksRepository extends CrudRepository { Ranks findByCompanyCodeAndRankName(String companyCode, String rankName); List findByCompanyCode(String companyCode); + Page findAll(Pageable pageable); + } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksStandardLevelRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksStandardLevelRepository.java new file mode 100644 index 00000000..bff1ddbe --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksStandardLevelRepository.java @@ -0,0 +1,13 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.standards.RanksStandardLevel; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface JdbcRanksStandardLevelRepository extends CrudRepository { + + List findAll(); +} diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index fc4228ff..503a0950 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -1309,32 +1309,32 @@ class RouteApplicationTests { // @Test void addRanks() { - RanksData ranksData = new RanksData(); - ranksData.setIndustry("正泰电气股份有限公司"); - ranksData.setCompanyCode("A20000001"); - for (int i = 1; i < 13; i++) { - if (i <= 1) { - ranksData.setLevel(3); - } else if (i <= 4) { - ranksData.setLevel(3); - } else if (i <= 8) { - ranksData.setLevel(2); - } else { - ranksData.setLevel(1); - } - ranksData.setRankName("P" + i); - rankController.saveRanks(ranksData); - ranksData.setRankName("M" + i); - rankController.saveRanks(ranksData); - ranksData.setRankName("L" + i); - rankController.saveRanks(ranksData); - } - - for (int i = 1; i < 6; i++) { - ranksData.setLevel(4); - ranksData.setRankName("PR" + i); - rankController.saveRanks(ranksData); - } +// RanksData ranksData = new RanksData(); +// ranksData.setIndustry("正泰电气股份有限公司"); +// ranksData.setCompanyCode("A20000001"); +// for (int i = 1; i < 13; i++) { +// if (i <= 1) { +// ranksData.setLevel(3); +// } else if (i <= 4) { +// ranksData.setLevel(3); +// } else if (i <= 8) { +// ranksData.setLevel(2); +// } else { +// ranksData.setLevel(1); +// } +// ranksData.setRankName("P" + i); +// rankController.saveRanks(ranksData); +// ranksData.setRankName("M" + i); +// rankController.saveRanks(ranksData); +// ranksData.setRankName("L" + i); +// rankController.saveRanks(ranksData); +// } +// +// for (int i = 1; i < 6; i++) { +// ranksData.setLevel(4); +// ranksData.setRankName("PR" + i); +// rankController.saveRanks(ranksData); +// } } // @Test