DictServiceImpl.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.fdkankan.fusion.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.fdkankan.fusion.common.PageInfo;
  5. import com.fdkankan.fusion.common.ResultCode;
  6. import com.fdkankan.fusion.entity.Dict;
  7. import com.fdkankan.fusion.entity.DictFile;
  8. import com.fdkankan.fusion.exception.BusinessException;
  9. import com.fdkankan.fusion.mapper.IDictMapper;
  10. import com.fdkankan.fusion.request.DictParam;
  11. import com.fdkankan.fusion.service.IDictFileService;
  12. import com.fdkankan.fusion.service.IDictService;
  13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import java.util.List;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author
  24. * @since 2025-02-10
  25. */
  26. @Service
  27. public class DictServiceImpl extends ServiceImpl<IDictMapper, Dict> implements IDictService {
  28. @Autowired
  29. IDictFileService dictFileService;
  30. @Override
  31. public List<Dict> getByKey(String dictKey) {
  32. if(StringUtils.isBlank(dictKey)){
  33. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  34. }
  35. LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
  36. wrapper.eq(Dict::getDictKey,dictKey);
  37. wrapper.orderByAsc(Dict::getSort);
  38. wrapper.orderByDesc(Dict::getId);
  39. return list(wrapper);
  40. }
  41. @Override
  42. public Object pageList(DictParam param) {
  43. if(StringUtils.isBlank(param.getDictKey())){
  44. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  45. }
  46. LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
  47. wrapper.eq(Dict::getDictKey,param.getDictKey());
  48. if(StringUtils.isNotBlank(param.getDictName())){
  49. wrapper.like(Dict::getDictName,param.getDictName());
  50. }
  51. wrapper.orderByAsc(Dict::getSort);
  52. wrapper.orderByDesc(Dict::getId);
  53. Page<Dict> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  54. return PageInfo.PageInfo(page);
  55. }
  56. @Override
  57. public void addOrUpdate(Dict dict) {
  58. if(StringUtils.isBlank(dict.getDictName()) || StringUtils.isBlank(dict.getDictKey())){
  59. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  60. }
  61. this.saveOrUpdate(dict);
  62. }
  63. @Override
  64. public void del(Dict dict) {
  65. if(dict.getId() == null){
  66. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  67. }
  68. dictFileService.updateDictId(dict.getId(),null);
  69. this.removeById(dict.getId());
  70. }
  71. }