【add】等级管理功能实现

This commit is contained in:
nixj 2024-05-23 10:39:49 +08:00
parent 0b98847092
commit 6059df2995
8 changed files with 127 additions and 73 deletions

View File

@ -5,9 +5,9 @@
### dtos ### dtos
业务数据类 业务数据类
### in ### in
内部接口 内部接口controller
### out ### out
登录 登录等外部接口controller
### queryies ### queryies
订单查询方法工具类 订单查询方法工具类
### services ### services

View File

@ -0,0 +1,17 @@
package com.chint.application.dtos;
import lombok.Data;
/**
*
* @Authornxj
* @Date2024/5/23 10:12
*/
@Data
public class RanksDto {
private String rankName;
private String industry;
private String companyCode;
private String standardLevel;
private String uniqueWord;
}

View File

@ -1,26 +1,36 @@
package com.chint.application.in; package com.chint.application.in;
import com.chint.application.dtos.RanksDto;
import com.chint.domain.aggregates.standards.DifferenceStandards; import com.chint.domain.aggregates.standards.DifferenceStandards;
import com.chint.domain.aggregates.standards.Ranks; 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.aggregates.standards.TravelStandards;
import com.chint.domain.exceptions.DuplicateException; import com.chint.domain.exceptions.DuplicateException;
import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.factoriy.ranks.RanksFactory; import com.chint.domain.factoriy.ranks.RanksFactory;
import com.chint.domain.repository.RanksRepository; import com.chint.domain.repository.RanksRepository;
import com.chint.domain.repository.TravelStandardsRepository; 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.RanksData;
import com.chint.domain.value_object.TravelStandardsData; import com.chint.domain.value_object.TravelStandardsData;
import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.CommonMessageConstant;
import com.chint.infrastructure.constant.RankConstant; 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.chint.infrastructure.util.Result;
import com.sun.net.httpserver.Authenticator;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Comparator;
import java.util.List; import java.util.List;
@RestController @RestController
@ -28,58 +38,40 @@ import java.util.List;
public class RankController { public class RankController {
@Autowired @Autowired
private RanksRepository ranksRepository; private JdbcRanksRepository jdbcRanksRepository;
@Autowired
private RanksFactory ranksFactory;
@Autowired @Autowired
private TravelStandardsRepository travelStandardsRepository; private TravelStandardsRepository travelStandardsRepository;
@Transactional @Autowired
@ApiOperation("保存职级和差标映射") private JdbcRanksStandardLevelRepository jdbcRanksStandardLevelRepository;
@ApiOperation("分页查询等级")
@PostMapping("/pageQuery")
public Result<PageResult<Ranks>> pageQuery(@RequestBody BaseQuery query) {
Page<Ranks> ranksPage=jdbcRanksRepository.findAll(query.getPageResult());
return Result.Success(CommonMessageConstant.SUCCESS,PageResult.totalPageNum(ranksPage.getTotalElements(),ranksPage.getContent()));
}
@ApiOperation("查询可选等级列表")
@PostMapping("/level/query")
public Result<List<RanksStandardLevel>> levelQuery() {
return Result.Success(CommonMessageConstant.SUCCESS,jdbcRanksStandardLevelRepository.findAll().stream().sorted(Comparator.comparing(RanksStandardLevel::getId)).toList());
}
@ApiOperation("保存等级")
@PostMapping("/save") @PostMapping("/save")
public Result<Ranks> saveRanks(@RequestBody RanksData ranksdata) { public Result<Ranks> saveRanks(@RequestBody RanksDto dto) {
Ranks ranks = ranksFactory.createRanks(ranksdata); Ranks ranks=new Ranks();
Ranks save = null; BeanUtils.copyProperties(dto,ranks);
try { return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks));
save = ranksRepository.save(ranks);
} catch (Exception e) {
throw new DuplicateException(CommonMessageConstant.DUPLICATE_ERROR);
}
return Result.Success(CommonMessageConstant.SUCCESS, save);
} }
// @Transactional @ApiOperation("修改等级")
// @ApiOperation("添加差标")
// @PostMapping("/add/standards")
// public Result<Ranks> addStandardsToRanks(@RequestBody StandardsData standardsData) {
// Ranks ranks = ranksRepository.queryById(standardsData.getRanksId());
// DifferenceStandards differenceStandards = ranksFactory.createDifferenceStandards(standardsData);
// ranks.addStandards(differenceStandards);
// return Result.Success(SUCCESS, ranks);
// }
@Transactional
@ApiOperation("修改差标")
@PostMapping("/update") @PostMapping("/update")
public Result<Ranks> updateRanks(@RequestBody RanksData ranksdata) { public Result<Ranks> updateRanks(@RequestBody Ranks ranks) {
Ranks ranks = ranksRepository.queryById(ranksdata.getRankId()); return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks));
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);
} }
@Transactional @Transactional

View File

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

View File

@ -3,9 +3,9 @@ package com.chint.domain.value_object;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.data.domain.PageRequest;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
@Data @Data
public class BaseQuery { public class BaseQuery {
@ -17,4 +17,10 @@ public class BaseQuery {
private LocalDate endDate; private LocalDate endDate;
@ApiModelProperty("排序字段") @ApiModelProperty("排序字段")
private Integer sort = 0; private Integer sort = 0;
public PageRequest getPageResult() {
PageRequest pageRequest = PageRequest
.of(pageNum - 1, pageSize);
return pageRequest;
}
} }

View File

@ -1,6 +1,8 @@
package com.chint.infrastructure.repository.jdbc; package com.chint.infrastructure.repository.jdbc;
import com.chint.domain.aggregates.standards.Ranks; 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.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -11,4 +13,6 @@ public interface JdbcRanksRepository extends CrudRepository<Ranks, Integer> {
Ranks findByCompanyCodeAndRankName(String companyCode, String rankName); Ranks findByCompanyCodeAndRankName(String companyCode, String rankName);
List<Ranks> findByCompanyCode(String companyCode); List<Ranks> findByCompanyCode(String companyCode);
Page<Ranks> findAll(Pageable pageable);
} }

View File

@ -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<RanksStandardLevel, Long> {
List<RanksStandardLevel> findAll();
}

View File

@ -1309,32 +1309,32 @@ class RouteApplicationTests {
// @Test // @Test
void addRanks() { void addRanks() {
RanksData ranksData = new RanksData(); // RanksData ranksData = new RanksData();
ranksData.setIndustry("正泰电气股份有限公司"); // ranksData.setIndustry("正泰电气股份有限公司");
ranksData.setCompanyCode("A20000001"); // ranksData.setCompanyCode("A20000001");
for (int i = 1; i < 13; i++) { // for (int i = 1; i < 13; i++) {
if (i <= 1) { // if (i <= 1) {
ranksData.setLevel(3); // ranksData.setLevel(3);
} else if (i <= 4) { // } else if (i <= 4) {
ranksData.setLevel(3); // ranksData.setLevel(3);
} else if (i <= 8) { // } else if (i <= 8) {
ranksData.setLevel(2); // ranksData.setLevel(2);
} else { // } else {
ranksData.setLevel(1); // ranksData.setLevel(1);
} // }
ranksData.setRankName("P" + i); // ranksData.setRankName("P" + i);
rankController.saveRanks(ranksData); // rankController.saveRanks(ranksData);
ranksData.setRankName("M" + i); // ranksData.setRankName("M" + i);
rankController.saveRanks(ranksData); // rankController.saveRanks(ranksData);
ranksData.setRankName("L" + i); // ranksData.setRankName("L" + i);
rankController.saveRanks(ranksData); // rankController.saveRanks(ranksData);
} // }
//
for (int i = 1; i < 6; i++) { // for (int i = 1; i < 6; i++) {
ranksData.setLevel(4); // ranksData.setLevel(4);
ranksData.setRankName("PR" + i); // ranksData.setRankName("PR" + i);
rankController.saveRanks(ranksData); // rankController.saveRanks(ranksData);
} // }
} }
// @Test // @Test