【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
业务数据类
### in
内部接口
内部接口controller
### out
登录
登录等外部接口controller
### queryies
订单查询方法工具类
### 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;
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("保存职级和差标映射")
@Autowired
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")
public Result<Ranks> 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);
public Result<Ranks> saveRanks(@RequestBody RanksDto dto) {
Ranks ranks=new Ranks();
BeanUtils.copyProperties(dto,ranks);
return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks));
}
// @Transactional
// @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("修改差标")
@ApiOperation("修改等级")
@PostMapping("/update")
public Result<Ranks> 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<Ranks> updateRanks(@RequestBody Ranks ranks) {
return Result.Success(CommonMessageConstant.SUCCESS, jdbcRanksRepository.save(ranks));
}
@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 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;
}
}

View File

@ -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, Integer> {
Ranks findByCompanyCodeAndRankName(String companyCode, String rankName);
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
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