CaseOverviewServiceImpl.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package com.fdkankan.fusion.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  8. import com.fdkankan.fusion.common.FilePath;
  9. import com.fdkankan.fusion.common.ResultCode;
  10. import com.fdkankan.fusion.common.util.UploadToOssUtil;
  11. import com.fdkankan.fusion.config.SecurityUtil;
  12. import com.fdkankan.fusion.entity.CaseFiles;
  13. import com.fdkankan.fusion.entity.CaseOverview;
  14. import com.fdkankan.fusion.entity.CaseTabulation;
  15. import com.fdkankan.fusion.exception.BusinessException;
  16. import com.fdkankan.fusion.httpClient.FdService;
  17. import com.fdkankan.fusion.mapper.ICaseOverviewMapper;
  18. import com.fdkankan.fusion.request.ExportOverviewParam;
  19. import com.fdkankan.fusion.service.ICaseFilesService;
  20. import com.fdkankan.fusion.service.ICaseOverviewService;
  21. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  22. import com.fdkankan.fusion.service.ICaseTabulationService;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import java.io.File;
  28. import java.nio.charset.StandardCharsets;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. import java.util.stream.Collectors;
  32. /**
  33. * <p>
  34. * 服务实现类
  35. * </p>
  36. *
  37. * @author
  38. * @since 2025-05-13
  39. */
  40. @Service
  41. @Slf4j
  42. public class CaseOverviewServiceImpl extends ServiceImpl<ICaseOverviewMapper, CaseOverview> implements ICaseOverviewService {
  43. @Autowired
  44. ICaseFilesService caseFilesService;
  45. @Autowired
  46. ICaseTabulationService caseTabulationService;
  47. @Override
  48. public List<CaseOverview> getByCaseId(String caseId) {
  49. LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
  50. wrapper.eq(CaseOverview::getCaseId,caseId);
  51. wrapper.orderByDesc(CaseOverview::getId);
  52. return this.list(wrapper);
  53. }
  54. @Override
  55. public void updateTitleById(Integer overviewId, String filesTitle) {
  56. LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
  57. wrapper.eq(CaseOverview::getId,overviewId);
  58. wrapper.set(CaseOverview::getTitle,filesTitle);
  59. this.update(wrapper);
  60. }
  61. @Override
  62. public void updateCaseByIds(List<Integer> overviewIds, Integer caseId) {
  63. LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
  64. wrapper.in(CaseOverview::getId,overviewIds);
  65. wrapper.set(CaseOverview::getCaseId,caseId);
  66. this.update(wrapper);
  67. }
  68. @Override
  69. public void updateListCoverById(Integer overviewId, String listCover) {
  70. LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
  71. wrapper.eq(CaseOverview::getId,overviewId);
  72. wrapper.set(CaseOverview::getListCover,listCover);
  73. this.update(wrapper);
  74. }
  75. @Override
  76. public CaseOverview getByNumAndSubGroup(String num, Integer subGroup) {
  77. LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
  78. wrapper.eq(CaseOverview::getNum,num);
  79. wrapper.eq(CaseOverview::getSubGroup,subGroup);
  80. List<CaseOverview> list = this.list(wrapper);
  81. if(list ==null || list.isEmpty()){
  82. return null;
  83. }
  84. return list.get(0);
  85. }
  86. @Override
  87. public Long getNo(Long sysUserId) {
  88. LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
  89. wrapper.eq(CaseOverview::getSysUserId,sysUserId);
  90. return this.count(wrapper);
  91. }
  92. @Override
  93. public void export(ExportOverviewParam param) {
  94. if(!param.getOverviewIds().isEmpty()){
  95. List<CaseOverview> caseOverviews = this.listByIds(param.getOverviewIds());
  96. for (CaseOverview caseOverview : caseOverviews) {
  97. Integer tabulationId = null;
  98. List<CaseTabulation> byOverviewId = caseTabulationService.getByOverviewId(String.valueOf(caseOverview.getId()));
  99. for (CaseTabulation caseTabulation : byOverviewId) {
  100. tabulationId = caseTabulation.getId();
  101. }
  102. CaseFiles caseFiles = new CaseFiles();
  103. caseFiles.setCaseId(param.getCaseId());
  104. caseFiles.setFilesUrl(caseOverview.getListCover());
  105. caseFiles.setFilesTypeId(41);
  106. caseFiles.setFilesTitle(caseOverview.getTitle());
  107. caseFiles.setOverviewId(caseOverview.getId());
  108. caseFiles.setTabulationId(tabulationId);
  109. caseFilesService.saveOrUpdate(caseFiles);
  110. }
  111. }
  112. if(!param.getTabulationIds().isEmpty()){
  113. List<CaseTabulation> caseTabulationList = caseTabulationService.listByIds(param.getTabulationIds());
  114. for (CaseTabulation caseTabulation : caseTabulationList) {
  115. CaseFiles caseFiles = new CaseFiles();
  116. caseFiles.setCaseId(param.getCaseId());
  117. caseFiles.setFilesUrl(caseTabulation.getListCover());
  118. caseFiles.setFilesTypeId(42);
  119. caseFiles.setFilesTitle(caseTabulation.getTitle());
  120. caseFiles.setTabulationId(caseTabulation.getId());
  121. caseFilesService.saveOrUpdate(caseFiles);
  122. }
  123. }
  124. }
  125. @Autowired
  126. UploadToOssUtil uploadToOssUtil;
  127. @Override
  128. public void toMeshEdit(String num, Integer subGroup, String listCover) {
  129. String filePath = String.format(FilePath.MESH_SCENE_FLOOR_PNG_PATH,num);
  130. String fileName = String.format(FilePath.MESH_SCENE_FLOOR_PNG_PATH_NAME,subGroup);
  131. String jsonPathSource = String.format(FilePath.MESH_SCENE_FLOOR_JSON_PATH_SOURCE,num);
  132. String jsonPath = String.format(FilePath.MESH_SCENE_FLOOR_JSON_PATH,num);
  133. String localPath = String.format(FilePath.MESH_SCENE_FLOOR_JSON_PATH_LOCAL,num);
  134. try {
  135. uploadToOssUtil.copyFile(uploadToOssUtil.getOssPath(listCover),filePath + fileName);
  136. String content = uploadToOssUtil.readFile(jsonPathSource);
  137. JSONObject jsonObject = JSONObject.parseObject(content);
  138. JSONArray jsonArray = jsonObject.getJSONArray("floors");
  139. for (Object object : jsonArray) {
  140. JSONObject obj = (JSONObject) object;
  141. Integer subgroupjs = obj.getInteger("subgroup");
  142. if(subgroupjs.equals(subGroup)){
  143. obj.put("filename",fileName);
  144. }
  145. }
  146. FileUtil.writeString(jsonObject.toJSONString(),new File(localPath), StandardCharsets.UTF_8);
  147. uploadToOssUtil.uploadOss(localPath,jsonPath);
  148. }catch (Exception e){
  149. log.info("同步mesh编辑器失败:{}",e);
  150. }finally {
  151. FileUtil.del(localPath);
  152. }
  153. }
  154. @Autowired
  155. FdService fdService;
  156. @Override
  157. public void checkLoginUser(CaseOverview caseOverview, CaseTabulation caseTabulation,String pageType) {
  158. if(caseOverview == null && caseTabulation == null){
  159. throw new BusinessException(ResultCode.RECORD_NOT_EXIST);
  160. }
  161. List<Integer> caseIds = new ArrayList<>();
  162. String num = null;
  163. if(caseOverview != null){
  164. caseIds = caseFilesService.getByOverviewId(caseOverview.getId()).stream().map(CaseFiles::getCaseId).collect(Collectors.toList());
  165. if(caseOverview.getCaseId() != null){
  166. caseIds.add(caseOverview.getCaseId());
  167. }
  168. num = caseOverview.getNum();
  169. }
  170. if(caseTabulation != null){
  171. caseIds = caseFilesService.getByTabulation(caseTabulation.getId()).stream().map(CaseFiles::getCaseId).collect(Collectors.toList());
  172. if(caseTabulation.getCaseId() != null){
  173. caseIds.add(caseTabulation.getCaseId());
  174. }
  175. }
  176. Long sysUserId = caseOverview != null ? caseOverview.getSysUserId() : caseTabulation.getSysUserId();
  177. if(fdService.cheUserAuth(sysUserId)){
  178. return;
  179. }
  180. if(StringUtils.isNotBlank(num) && fdService.checkNum(num,pageType,StpUtil.getTokenValue())){
  181. return;
  182. }
  183. if(!caseIds.isEmpty()){
  184. Boolean flag = false;
  185. for (Integer caseId : caseIds) {
  186. try {
  187. fdService.checkCaseAuth(caseId.toString(),null,pageType,StpUtil.getTokenValue());
  188. flag = true;
  189. }catch (Exception e){
  190. }
  191. }
  192. if(flag){
  193. return;
  194. }
  195. }
  196. throw new BusinessException(ResultCode.NOT_PER);
  197. }
  198. }