package cn.cslg.pas.service.business;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.domain.business.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.*;
import java.util.stream.Collectors;
/**
*
* 系统字典 服务类
*
*
* @author 王岩
* @since 2022-03-30
*/
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class SystemDictService extends ServiceImpl {
public Map> getOsSystemDict(List types) {
Map> systemDictMap = new HashMap<>();
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
if (types != null && types.size() > 0) {
queryWrapper.in(SystemDict::getType, types);
}
List systemDictList = this.list(queryWrapper);
types = systemDictList.stream().map(SystemDict::getType).collect(Collectors.toList());
types = types.stream().distinct().collect(Collectors.toList());
Set set = new HashSet();
set.addAll(systemDictList);
types.forEach(item -> {
List systemDictList1 = systemDictList.stream().filter(t -> t.getType().equals(item)).collect(Collectors.toList());
systemDictMap.put(item, systemDictList1);
});
return systemDictMap;
}
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 List getScenarioOrderIds(Integer orderType) {
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(SystemDict::getValue);
queryWrapper.eq(SystemDict::getType, "ENTERPRISE_APPLICATION_SCENARIO");
if (orderType != null && orderType.equals(0)) {
queryWrapper.orderByAsc(SystemDict::getLabel);
} else {
queryWrapper.orderByDesc(SystemDict::getLabel);
}
java.util.function.Function