CaseTabulationServiceImpl.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.entity.CaseFiles;
  5. import com.fdkankan.fusion.entity.CaseOverview;
  6. import com.fdkankan.fusion.entity.CaseTabulation;
  7. import com.fdkankan.fusion.mapper.ICaseTabulationMapper;
  8. import com.fdkankan.fusion.service.ICaseFilesService;
  9. import com.fdkankan.fusion.service.ICaseOverviewService;
  10. import com.fdkankan.fusion.service.ICaseTabulationService;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.io.IOException;
  17. import java.util.List;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author
  24. * @since 2025-05-13
  25. */
  26. @Service
  27. public class CaseTabulationServiceImpl extends ServiceImpl<ICaseTabulationMapper, CaseTabulation> implements ICaseTabulationService {
  28. @Autowired
  29. ICaseFilesService caseFilesService;
  30. @Autowired
  31. ICaseOverviewService caseOverviewService;
  32. @Autowired
  33. FYunFileServiceInterface fYunFileServiceInterface;
  34. @Override
  35. public List<CaseTabulation> getByCaseId(Integer caseId) {
  36. LambdaQueryWrapper<CaseTabulation> wrapper = new LambdaQueryWrapper<>();
  37. wrapper.eq(CaseTabulation::getCaseId,caseId);
  38. wrapper.isNull(CaseTabulation::getOverviewId);
  39. wrapper.orderByDesc(CaseTabulation::getId);
  40. return this.list(wrapper);
  41. }
  42. @Override
  43. public List<CaseTabulation> getByOverviewId(String overviewId) {
  44. LambdaQueryWrapper<CaseTabulation> wrapper = new LambdaQueryWrapper<>();
  45. wrapper.eq(CaseTabulation::getOverviewId,overviewId);
  46. wrapper.orderByDesc(CaseTabulation::getId);
  47. return this.list(wrapper);
  48. }
  49. @Override
  50. public List<CaseTabulation> getByOverId(Integer overId) {
  51. LambdaQueryWrapper<CaseTabulation> wrapper = new LambdaQueryWrapper<>();
  52. wrapper.eq(CaseTabulation::getOverviewId,overId);
  53. return this.list(wrapper);
  54. }
  55. @Override
  56. public void delByIds(List<Integer> ids) {
  57. if(!ids.isEmpty()){
  58. List<CaseTabulation> caseTabulations = this.listByIds(ids);
  59. this.removeByIds(ids);
  60. for (CaseTabulation caseTabulation : caseTabulations) {
  61. delFile(caseTabulation);
  62. }
  63. }
  64. }
  65. private void delFile(CaseTabulation caseTabulation) {
  66. List<CaseTabulation> list = this.getByCover(caseTabulation.getListCover());
  67. if(list.isEmpty()){
  68. try {
  69. fYunFileServiceInterface.deleteFile(caseTabulation.getListCover());
  70. } catch (IOException e) {
  71. throw new RuntimeException(e);
  72. }
  73. }
  74. List<CaseTabulation> list2 = this.getByCover(caseTabulation.getMapUrl());
  75. if(list2.isEmpty()){
  76. try {
  77. fYunFileServiceInterface.deleteFile(caseTabulation.getMapUrl());
  78. } catch (IOException e) {
  79. throw new RuntimeException(e);
  80. }
  81. }
  82. List<CaseTabulation> list3 = this.getByCover(caseTabulation.getCover());
  83. if(list3.isEmpty()){
  84. try {
  85. fYunFileServiceInterface.deleteFile(caseTabulation.getCover());
  86. } catch (IOException e) {
  87. throw new RuntimeException(e);
  88. }
  89. }
  90. }
  91. private List<CaseTabulation> getByCover(String listCover) {
  92. LambdaQueryWrapper<CaseTabulation> wrapper = new LambdaQueryWrapper<>();
  93. wrapper.and(e -> e.eq(CaseTabulation::getListCover,listCover).or().eq(CaseTabulation::getMapUrl,listCover).or().like(CaseTabulation::getCover,listCover));
  94. return this.list(wrapper);
  95. }
  96. @Override
  97. public void addOrUpdate(CaseTabulation caseTabulation) {
  98. this.saveOrUpdate(caseTabulation);
  99. if(StringUtils.isNotBlank(caseTabulation.getListCover()) || caseTabulation.getOverviewId() != null){
  100. CaseFiles caseFiles = new CaseFiles();
  101. if(caseTabulation.getId()!=null){
  102. CaseTabulation db = this.getById(caseTabulation.getId());
  103. if(caseTabulation.getOverviewId() == null){
  104. caseTabulation.setOverviewId(db.getOverviewId());
  105. }
  106. CaseFiles dbCaseFile = caseFilesService.getByTabulation(caseTabulation.getId());
  107. if(dbCaseFile != null){
  108. caseFiles.setFilesId(dbCaseFile.getFilesId());
  109. }
  110. }
  111. if(caseTabulation.getOverviewId()!=null){
  112. CaseFiles dbCaseFile = caseFilesService.getByOverviewId(caseTabulation.getOverviewId());
  113. if(dbCaseFile != null){
  114. caseFiles.setFilesId(dbCaseFile.getFilesId());
  115. }
  116. }
  117. caseFiles.setCaseId(caseTabulation.getCaseId());
  118. caseFiles.setFilesUrl(caseTabulation.getListCover());
  119. if(StringUtils.isBlank(caseTabulation.getListCover())){
  120. CaseOverview caseOverview = caseOverviewService.getById(caseTabulation.getOverviewId());
  121. caseFiles.setFilesUrl(caseOverview.getListCover());
  122. }
  123. if(caseFiles.getFilesId() == null){
  124. if(caseTabulation.getOverviewId() != null){ //平面图
  125. caseFiles.setFilesTitle("平面图");
  126. caseFiles.setFilesTypeId(1);
  127. caseFiles.setOverviewId(caseTabulation.getOverviewId() );
  128. caseFiles.setTabulationId(caseTabulation.getId() );
  129. }else {
  130. caseFiles.setFilesTypeId(1);
  131. caseFiles.setFilesTitle("方位图");
  132. caseFiles.setTabulationId(caseTabulation.getId() );
  133. }
  134. }
  135. caseFilesService.saveOrUpdate(caseFiles);
  136. }
  137. }
  138. @Override
  139. public void updateTitleById(Integer tabulationId, String filesTitle) {
  140. LambdaUpdateWrapper<CaseTabulation> wrapper = new LambdaUpdateWrapper<>();
  141. wrapper.eq(CaseTabulation::getId,tabulationId);
  142. wrapper.set(CaseTabulation::getTitle,filesTitle);
  143. this.update(wrapper);
  144. }
  145. }