fix:删掉枚举类

上级 361d64ca
package com.kwan.springbootkwan.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import java.util.Date;
/**
* 字典表(DictionaryManagement)表实体类
*
* @author makejava
* @since 2023-10-07 17:54:39
*/
@Data
public class DictionaryManagement extends Model<DictionaryManagement> {
//主键id
private Integer id;
//字典类型
private Integer dictType;
//字典code
private Integer code;
//字典名称
private String name;
//创建时间
private Date createTime;
//逻辑删除,0未删除,1已删除
private Integer isDelete;
}
\ No newline at end of file
package com.kwan.springbootkwan.enums;
import com.kwan.springbootkwan.entity.dto.AlgorithmicQuestionTypeDTO;
import lombok.Getter;
import lombok.ToString;
import java.util.LinkedList;
@Getter
@ToString
public enum AlgorithmicProblemTypeEnum {
/**
* 全部
*/
type_00(0, "全部"),
/**
* 链表
*/
type_01(1, "链表"),
/**
* 数组
*/
type_02(2, "数组"),
/**
* 二叉树
*/
type_03(3, "二叉树"),
/**
* 贪心
*/
type_04(4, "贪心"),
/**
* 动态规划
*/
type_05(5, "动态规划"),
/**
* 其他
*/
type_99(99, "其他");
private Integer code;
private String name;
AlgorithmicProblemTypeEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
/**
* 通过code获取name
*
* @param code
* @return
*/
public static String getNameByCode(Integer code) {
for (AlgorithmicProblemTypeEnum enums : AlgorithmicProblemTypeEnum.values()) {
if (enums.getCode().equals(code)) {
return enums.getName();
}
}
return null;
}
/**
* 获取所有枚举
*
* @return
*/
public static LinkedList<AlgorithmicQuestionTypeDTO> getAll() {
LinkedList<AlgorithmicQuestionTypeDTO> list = new LinkedList<>();
for (AlgorithmicProblemTypeEnum enums : AlgorithmicProblemTypeEnum.values()) {
AlgorithmicQuestionTypeDTO algorithmicQuestionTypeDTO = new AlgorithmicQuestionTypeDTO(enums.getCode(), enums.getName(), 0);
list.add(algorithmicQuestionTypeDTO);
}
return list;
}
}
package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.DictionaryManagement;
/**
* 字典表(DictionaryManagement)表数据库访问层
*
* @author makejava
* @since 2023-10-07 17:54:37
*/
public interface DictionaryManagementMapper extends BaseMapper<DictionaryManagement> {
}
package com.kwan.springbootkwan.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kwan.springbootkwan.entity.DictionaryManagement;
/**
* 字典表(DictionaryManagement)表服务接口
*
* @author makejava
* @since 2023-10-07 17:54:39
*/
public interface DictionaryManagementService extends IService<DictionaryManagement> {
}
package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.AlgorithmicProblem;
import com.kwan.springbootkwan.entity.DictionaryManagement;
import com.kwan.springbootkwan.entity.dto.AlgorithmicQuestionTypeDTO;
import com.kwan.springbootkwan.enums.AlgorithmicProblemTypeEnum;
import com.kwan.springbootkwan.mapper.AlgorithmicProblemMapper;
import com.kwan.springbootkwan.service.AlgorithmicProblemService;
import com.kwan.springbootkwan.service.DictionaryManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 算法题(AlgorithmicProblem)表服务实现类
......@@ -23,22 +26,36 @@ public class AlgorithmicProblemServiceImpl extends ServiceImpl<AlgorithmicProble
@Autowired
private AlgorithmicProblemMapper interviewQuestionMapper;
@Autowired
private DictionaryManagementService dictionaryManagementService;
@Override
public List<AlgorithmicQuestionTypeDTO> questionType() {
final List<AlgorithmicQuestionTypeDTO> algorithmicQuestionTypeDTOS = this.allQuestionType();
//获取种类,并按数量排序
LinkedList<AlgorithmicQuestionTypeDTO> types = interviewQuestionMapper.questionType();
types.addFirst(new AlgorithmicQuestionTypeDTO(0, "全部", 0));
for (AlgorithmicQuestionTypeDTO algorithmicQuestionTypeDTO : types) {
//数据库存的是问题类型的编码
algorithmicQuestionTypeDTO.setName(AlgorithmicProblemTypeEnum.getNameByCode(algorithmicQuestionTypeDTO.getQuestionType()));
final AlgorithmicQuestionTypeDTO item = algorithmicQuestionTypeDTOS.stream().filter(x -> x.getQuestionType().equals(algorithmicQuestionTypeDTO.getQuestionType())).findFirst().get();
algorithmicQuestionTypeDTO.setName(item.getName());
}
return types;
}
@Override
public List<AlgorithmicQuestionTypeDTO> allQuestionType() {
return AlgorithmicProblemTypeEnum.getAll();
QueryWrapper<DictionaryManagement> wrapper = new QueryWrapper<>();
wrapper.eq("dict_type", 2);
wrapper.eq("is_delete", 0);
final List<DictionaryManagement> list = dictionaryManagementService.list(wrapper);
return list.stream()
.map(item -> {
AlgorithmicQuestionTypeDTO algorithmicQuestionTypeDTO = new AlgorithmicQuestionTypeDTO();
algorithmicQuestionTypeDTO.setQuestionType(item.getCode());
algorithmicQuestionTypeDTO.setName(item.getName());
return algorithmicQuestionTypeDTO;
}).collect(Collectors.toList());
}
}
package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.DictionaryManagement;
import com.kwan.springbootkwan.mapper.DictionaryManagementMapper;
import com.kwan.springbootkwan.service.DictionaryManagementService;
import org.springframework.stereotype.Service;
/**
* 字典表(DictionaryManagement)表服务实现类
*
* @author makejava
* @since 2023-10-07 17:54:39
*/
@Service("dictionaryManagementService")
public class DictionaryManagementServiceImpl extends ServiceImpl<DictionaryManagementMapper, DictionaryManagement> implements DictionaryManagementService {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册