CaseOverviewServiceImpl.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.fdkankan.fusion.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.fdkankan.fusion.common.ResultCode;
  5. import com.fdkankan.fusion.common.util.UploadToOssUtil;
  6. import com.fdkankan.fusion.entity.CaseOverview;
  7. import com.fdkankan.fusion.entity.CaseTabulation;
  8. import com.fdkankan.fusion.exception.BusinessException;
  9. import com.fdkankan.fusion.mapper.ICaseOverviewMapper;
  10. import com.fdkankan.fusion.service.ICaseOverviewService;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.fusion.service.ICaseTabulationService;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.io.IOException;
  16. import java.util.List;
  17. import java.util.stream.Collectors;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author
  24. * @since 2025-05-13
  25. */
  26. @Service
  27. public class CaseOverviewServiceImpl extends ServiceImpl<ICaseOverviewMapper, CaseOverview> implements ICaseOverviewService {
  28. @Autowired
  29. ICaseTabulationService caseTabulationService;
  30. @Autowired
  31. UploadToOssUtil uploadToOssUtil;
  32. @Override
  33. public List<CaseOverview> getByCaseId(Integer caseId) {
  34. LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
  35. wrapper.eq(CaseOverview::getCaseId,caseId);
  36. wrapper.orderByDesc(CaseOverview::getId);
  37. return this.list(wrapper);
  38. }
  39. @Override
  40. public void del(Integer overviewId) {
  41. if(overviewId == null ){
  42. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  43. }
  44. CaseOverview caseOverview = this.getById(overviewId);
  45. if(caseOverview == null){
  46. return;
  47. }
  48. this.removeById(overviewId);
  49. this.delFile(caseOverview);
  50. List<CaseTabulation> caseTabulations = caseTabulationService.getByOverId(overviewId);
  51. if(!caseTabulations.isEmpty()){
  52. caseTabulationService.delByIds(caseTabulations.stream().map(CaseTabulation::getId).collect(Collectors.toList()));
  53. }
  54. }
  55. private void delFile(CaseOverview caseOverview) {
  56. List<CaseOverview> list = this.getByCover(caseOverview.getListCover());
  57. if(list.isEmpty()){
  58. uploadToOssUtil.delete(caseOverview.getListCover());
  59. }
  60. List<CaseOverview> list2 = this.getByCover(caseOverview.getKankanCover());
  61. if(list2.isEmpty()){
  62. uploadToOssUtil.delete(caseOverview.getKankanCover());
  63. }
  64. }
  65. private List<CaseOverview> getByCover(String listCover) {
  66. LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
  67. wrapper.and(e -> e.eq(CaseOverview::getListCover,listCover).or().eq(CaseOverview::getKankanCover,listCover));
  68. return this.list(wrapper);
  69. }
  70. @Override
  71. public void updateTitleById(Integer overviewId, String filesTitle) {
  72. LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
  73. wrapper.eq(CaseOverview::getId,overviewId);
  74. wrapper.set(CaseOverview::getTitle,filesTitle);
  75. this.update(wrapper);
  76. }
  77. }