SystemDictService.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.utils.Response;
  3. import cn.cslg.pas.domain.SystemDict;
  4. import cn.cslg.pas.mapper.SystemDictMapper;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import lombok.RequiredArgsConstructor;
  8. import org.springframework.context.annotation.Lazy;
  9. import org.springframework.stereotype.Service;
  10. import java.util.ArrayList;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.stream.Collectors;
  15. /**
  16. * <p>
  17. * 系统字典 服务类
  18. * </p>
  19. *
  20. * @author 王岩
  21. * @since 2022-03-30
  22. */
  23. @Service
  24. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  25. public class SystemDictService extends ServiceImpl<SystemDictMapper, SystemDict> {
  26. public List<SystemDict> getSystemDictListByType(List<String> type) {
  27. if (type == null || type.size() == 0) {
  28. return new ArrayList<>();
  29. }
  30. LambdaQueryWrapper<SystemDict> queryWrapper = new LambdaQueryWrapper<>();
  31. queryWrapper.in(SystemDict::getType, type);
  32. return this.list(queryWrapper);
  33. }
  34. public String getSystemDictLabelByTypeAndValue(String type, Object value) {
  35. LambdaQueryWrapper<SystemDict> queryWrapper = new LambdaQueryWrapper<>();
  36. queryWrapper.eq(SystemDict::getType, type);
  37. queryWrapper.eq(SystemDict::getValue, value);
  38. SystemDict systemDict = this.getOne(queryWrapper);
  39. if (systemDict != null) {
  40. return systemDict.getLabel();
  41. }
  42. return "";
  43. }
  44. public String getDictMessage() {
  45. List<SystemDict> systemDictList = this.list();
  46. Map<String, Object> map = new HashMap<>();
  47. for (SystemDict systemDict : systemDictList) {
  48. map.put(systemDict.getType(), systemDictList.stream().filter(item -> item.getType().equals(systemDict.getType())).collect(Collectors.toList()));
  49. }
  50. return Response.success(map);
  51. }
  52. }