package com.gkhy.exam.institutionalaccess.service.serviceImpl;
|
|
import com.alibaba.fastjson2.JSONArray;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gkhy.exam.institutionalaccess.entity.ThSubjectType;
|
import com.gkhy.exam.institutionalaccess.mapper.ThSubjectTypeMapper;
|
import com.gkhy.exam.institutionalaccess.model.vo.ThSubjectTypeVO;
|
import com.gkhy.exam.institutionalaccess.service.ThSubjectTypeService;
|
import com.ruoyi.common.constant.CacheConstants;
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author zf
|
* @email 1603559716@qq.com
|
* @date 2024/8/6 15:09
|
* @description ThSubjectTypeServiceImpl
|
*/
|
@Service("ThSubjectTypeService")
|
public class ThSubjectTypeServiceImpl extends ServiceImpl<ThSubjectTypeMapper, ThSubjectType> implements ThSubjectTypeService {
|
@Autowired
|
private RedisCache redisCache;
|
@Override
|
public void subjectTypeCache() {
|
List<ThSubjectType> thSubjectTypes = baseMapper.selectList(new LambdaQueryWrapper<>());
|
redisCache.setCacheObject(CacheConstants.THREE_SUBJECT_TYPE, thSubjectTypes);
|
}
|
|
@Override
|
public List<ThSubjectType> getSubjectTypeList() {
|
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(CacheConstants.THREE_SUBJECT_TYPE);
|
if (StringUtils.isNotNull(arrayCache))
|
{
|
return arrayCache.toList(ThSubjectType.class);
|
}else {
|
return baseMapper.selectList(new LambdaQueryWrapper<>());
|
|
}
|
|
}
|
|
@Override
|
public List<ThSubjectTypeVO> getTree() {
|
List<ThSubjectType> subjectTypeList = getSubjectTypeList();
|
List<ThSubjectTypeVO> children = getChildren(subjectTypeList, "0");
|
|
return children;
|
}
|
private List<ThSubjectTypeVO> getChildren(List<ThSubjectType> thSubjectTypes, String parentCode){
|
|
List<ThSubjectTypeVO> thSubjectTypeVOList = new ArrayList<>();
|
List<ThSubjectType> selectList = thSubjectTypes
|
.stream()
|
.filter(thSubjectType -> thSubjectType.getParentCode().equals(parentCode))
|
.collect(Collectors.toList());
|
for (ThSubjectType thSubjectType : selectList) {
|
ThSubjectTypeVO thSubjectTypeVO = new ThSubjectTypeVO();
|
thSubjectTypeVO.setId(thSubjectType.getId());
|
thSubjectTypeVO.setName(thSubjectType.getName());
|
thSubjectTypeVO.setCode(thSubjectType.getCode());
|
thSubjectTypeVO.setParentCode(thSubjectType.getParentCode());
|
//获取孩子节点
|
thSubjectTypeVO.setChildren(getChildren(thSubjectTypes, thSubjectType.getCode()));
|
thSubjectTypeVOList.add(thSubjectTypeVO);
|
}
|
return thSubjectTypeVOList;
|
}
|
|
|
|
}
|