| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- package com.fdkankan.fusion.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.fdkankan.fusion.common.FilePath;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.util.UploadToOssUtil;
- import com.fdkankan.fusion.config.SecurityUtil;
- import com.fdkankan.fusion.entity.CaseFiles;
- import com.fdkankan.fusion.entity.CaseOverview;
- import com.fdkankan.fusion.entity.CaseTabulation;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.httpClient.FdService;
- import com.fdkankan.fusion.mapper.ICaseOverviewMapper;
- import com.fdkankan.fusion.request.ExportOverviewParam;
- import com.fdkankan.fusion.service.ICaseFilesService;
- import com.fdkankan.fusion.service.ICaseOverviewService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.fusion.service.ICaseTabulationService;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.nio.charset.StandardCharsets;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2025-05-13
- */
- @Service
- @Slf4j
- public class CaseOverviewServiceImpl extends ServiceImpl<ICaseOverviewMapper, CaseOverview> implements ICaseOverviewService {
- @Autowired
- ICaseFilesService caseFilesService;
- @Autowired
- ICaseTabulationService caseTabulationService;
- @Override
- public List<CaseOverview> getByCaseId(String caseId) {
- LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CaseOverview::getCaseId,caseId);
- wrapper.orderByDesc(CaseOverview::getId);
- return this.list(wrapper);
- }
- @Override
- public void updateTitleById(Integer overviewId, String filesTitle) {
- LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(CaseOverview::getId,overviewId);
- wrapper.set(CaseOverview::getTitle,filesTitle);
- this.update(wrapper);
- }
- @Override
- public void updateCaseByIds(List<Integer> overviewIds, Integer caseId) {
- LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
- wrapper.in(CaseOverview::getId,overviewIds);
- wrapper.set(CaseOverview::getCaseId,caseId);
- this.update(wrapper);
- }
- @Override
- public void updateListCoverById(Integer overviewId, String listCover) {
- LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(CaseOverview::getId,overviewId);
- wrapper.set(CaseOverview::getListCover,listCover);
- this.update(wrapper);
- }
- @Override
- public CaseOverview getByNumAndSubGroup(String num, Integer subGroup) {
- LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CaseOverview::getNum,num);
- wrapper.eq(CaseOverview::getSubGroup,subGroup);
- List<CaseOverview> list = this.list(wrapper);
- if(list ==null || list.isEmpty()){
- return null;
- }
- return list.get(0);
- }
- @Override
- public Long getNo(Long sysUserId) {
- LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(CaseOverview::getSysUserId,sysUserId);
- return this.count(wrapper);
- }
- @Override
- public void export(ExportOverviewParam param) {
- if(!param.getOverviewIds().isEmpty()){
- List<CaseOverview> caseOverviews = this.listByIds(param.getOverviewIds());
- for (CaseOverview caseOverview : caseOverviews) {
- Integer tabulationId = null;
- List<CaseTabulation> byOverviewId = caseTabulationService.getByOverviewId(String.valueOf(caseOverview.getId()));
- for (CaseTabulation caseTabulation : byOverviewId) {
- tabulationId = caseTabulation.getId();
- }
- CaseFiles caseFiles = new CaseFiles();
- caseFiles.setCaseId(param.getCaseId());
- caseFiles.setFilesUrl(caseOverview.getListCover());
- caseFiles.setFilesTypeId(41);
- caseFiles.setFilesTitle(caseOverview.getTitle());
- caseFiles.setOverviewId(caseOverview.getId());
- caseFiles.setTabulationId(tabulationId);
- caseFilesService.saveOrUpdate(caseFiles);
- }
- }
- if(!param.getTabulationIds().isEmpty()){
- List<CaseTabulation> caseTabulationList = caseTabulationService.listByIds(param.getTabulationIds());
- for (CaseTabulation caseTabulation : caseTabulationList) {
- CaseFiles caseFiles = new CaseFiles();
- caseFiles.setCaseId(param.getCaseId());
- caseFiles.setFilesUrl(caseTabulation.getListCover());
- caseFiles.setFilesTypeId(42);
- caseFiles.setFilesTitle(caseTabulation.getTitle());
- caseFiles.setTabulationId(caseTabulation.getId());
- caseFilesService.saveOrUpdate(caseFiles);
- }
- }
- }
- @Autowired
- UploadToOssUtil uploadToOssUtil;
- @Override
- public void toMeshEdit(String num, Integer subGroup, String listCover) {
- String filePath = String.format(FilePath.MESH_SCENE_FLOOR_PNG_PATH,num);
- String fileName = String.format(FilePath.MESH_SCENE_FLOOR_PNG_PATH_NAME,subGroup);
- String jsonPathSource = String.format(FilePath.MESH_SCENE_FLOOR_JSON_PATH_SOURCE,num);
- String jsonPath = String.format(FilePath.MESH_SCENE_FLOOR_JSON_PATH,num);
- String localPath = String.format(FilePath.MESH_SCENE_FLOOR_JSON_PATH_LOCAL,num);
- try {
- uploadToOssUtil.copyFile(uploadToOssUtil.getOssPath(listCover),filePath + fileName);
- String content = uploadToOssUtil.readFile(jsonPathSource);
- JSONObject jsonObject = JSONObject.parseObject(content);
- JSONArray jsonArray = jsonObject.getJSONArray("floors");
- for (Object object : jsonArray) {
- JSONObject obj = (JSONObject) object;
- Integer subgroupjs = obj.getInteger("subgroup");
- if(subgroupjs.equals(subGroup)){
- obj.put("filename",fileName);
- }
- }
- FileUtil.writeString(jsonObject.toJSONString(),new File(localPath), StandardCharsets.UTF_8);
- uploadToOssUtil.uploadOss(localPath,jsonPath);
- }catch (Exception e){
- log.info("同步mesh编辑器失败:{}",e);
- }finally {
- FileUtil.del(localPath);
- }
- }
- @Autowired
- FdService fdService;
- @Override
- public void checkLoginUser(CaseOverview caseOverview, CaseTabulation caseTabulation,String pageType) {
- if(caseOverview == null && caseTabulation == null){
- throw new BusinessException(ResultCode.RECORD_NOT_EXIST);
- }
- List<Integer> caseIds = new ArrayList<>();
- String num = null;
- if(caseOverview != null){
- caseIds = caseFilesService.getByOverviewId(caseOverview.getId()).stream().map(CaseFiles::getCaseId).collect(Collectors.toList());
- if(caseOverview.getCaseId() != null){
- caseIds.add(caseOverview.getCaseId());
- }
- num = caseOverview.getNum();
- }
- if(caseTabulation != null){
- caseIds = caseFilesService.getByTabulation(caseTabulation.getId()).stream().map(CaseFiles::getCaseId).collect(Collectors.toList());
- if(caseTabulation.getCaseId() != null){
- caseIds.add(caseTabulation.getCaseId());
- }
- }
- Long sysUserId = caseOverview != null ? caseOverview.getSysUserId() : caseTabulation.getSysUserId();
- if(fdService.cheUserAuth(sysUserId)){
- return;
- }
- if(StringUtils.isNotBlank(num) && fdService.checkNum(num,pageType,StpUtil.getTokenValue())){
- return;
- }
- if(!caseIds.isEmpty()){
- Boolean flag = false;
- for (Integer caseId : caseIds) {
- try {
- fdService.checkCaseAuth(caseId.toString(),null,pageType,StpUtil.getTokenValue());
- flag = true;
- }catch (Exception e){
- }
- }
- if(flag){
- return;
- }
- }
- throw new BusinessException(ResultCode.NOT_PER);
- }
- }
|