package cn.cslg.pas.service;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.domain.SystemDict;
import cn.cslg.pas.mapper.SystemDictMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*
* 系统字典 服务类
*
*
* @author 王岩
* @since 2022-03-30
*/
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class SystemDictService extends ServiceImpl {
public List getSystemDictListByType(List type) {
if (type == null || type.size() == 0) {
return new ArrayList<>();
}
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SystemDict::getType, type);
return this.list(queryWrapper);
}
public String getSystemDictLabelByTypeAndValue(String type, Object value) {
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SystemDict::getType, type);
queryWrapper.eq(SystemDict::getValue, value);
SystemDict systemDict = this.getOne(queryWrapper);
if (systemDict != null) {
return systemDict.getLabel();
}
return "";
}
public String getDictMessage() {
List systemDictList = this.list();
Map map = new HashMap<>();
for (SystemDict systemDict : systemDictList) {
map.put(systemDict.getType(), systemDictList.stream().filter(item -> item.getType().equals(systemDict.getType())).collect(Collectors.toList()));
}
return Response.success(map);
}
}