DictFileServiceImpl.java 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.fdkankan.manage.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.fdkankan.manage.common.PageInfo;
  6. import com.fdkankan.manage.common.ResultCode;
  7. import com.fdkankan.manage.constant.FileTypeEnum;
  8. import com.fdkankan.manage.entity.CommonUpload;
  9. import com.fdkankan.manage.entity.DictFile;
  10. import com.fdkankan.manage.exception.BusinessException;
  11. import com.fdkankan.manage.mapper.IDictFileMapper;
  12. import com.fdkankan.manage.service.ICommonUploadService;
  13. import com.fdkankan.manage.service.IDictFileService;
  14. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  15. import com.fdkankan.manage.vo.request.DictFileParam;
  16. import com.fdkankan.manage.vo.response.DictFileVo;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.springframework.beans.BeanUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 服务实现类
  28. * </p>
  29. *
  30. * @author
  31. * @since 2024-12-02
  32. */
  33. @Service
  34. public class DictFileServiceImpl extends ServiceImpl<IDictFileMapper, DictFile> implements IDictFileService {
  35. @Autowired
  36. ICommonUploadService commonUploadService;
  37. @Override
  38. public Object pageList(DictFileParam param) {
  39. if(StringUtils.isBlank(param.getTypeKey())){
  40. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  41. }
  42. LambdaQueryWrapper<DictFile> wrapper = new LambdaQueryWrapper<>();
  43. if(StringUtils.isNotBlank(param.getName())){
  44. wrapper.like(DictFile::getName,param.getName());
  45. }
  46. if(param.getDictId() != null){
  47. wrapper.eq(DictFile::getDictId,param.getDictId());
  48. }
  49. wrapper.eq(DictFile::getSysUserId, StpUtil.getLoginId());
  50. wrapper.orderByDesc(DictFile::getId);
  51. Page<DictFile> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  52. List<Integer> uploadIds = page.getRecords().stream().map(DictFile::getUploadId).collect(Collectors.toList());
  53. HashMap<Integer,CommonUpload> map = new HashMap<>();
  54. if(!uploadIds.isEmpty()){
  55. List<CommonUpload> commonUploads = commonUploadService.listByIds(uploadIds);
  56. commonUploads.forEach(e -> map.put(e.getId(),e));
  57. }
  58. List<DictFileVo> voList = new ArrayList<>();
  59. for (DictFile record : page.getRecords()) {
  60. DictFileVo vo = new DictFileVo();
  61. BeanUtils.copyProperties(record,vo);
  62. CommonUpload upload = map.get(record.getUploadId());
  63. if(upload != null){
  64. BeanUtils.copyProperties(upload,vo);
  65. }
  66. voList.add(vo);
  67. }
  68. Page<DictFileVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  69. voPage.setTotal(page.getTotal());
  70. voPage.setRecords(voList);
  71. return PageInfo.PageInfo(voPage);
  72. }
  73. @Override
  74. public void addOrUpdate(DictFile dictFile) {
  75. if(StringUtils.isBlank(dictFile.getName()) || StringUtils.isBlank(dictFile.getTypeKey())
  76. || dictFile.getDictId() == null ){
  77. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  78. }
  79. this.saveOrUpdate(dictFile);
  80. }
  81. @Override
  82. public void del(DictFile dictFile) {
  83. if(dictFile.getId() == null){
  84. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  85. }
  86. this.removeById(dictFile.getId());
  87. }
  88. }