|
@@ -0,0 +1,171 @@
|
|
|
+package com.fdkankan.manage.service.impl;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.manage.common.PageInfo;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.entity.*;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.mapper.ICaseOverviewMapper;
|
|
|
+import com.fdkankan.manage.service.*;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage.util.FileWriterUtil;
|
|
|
+import com.fdkankan.manage.vo.request.CaseOverviewParam;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2025-07-15
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@DS("db2")
|
|
|
+public class CaseOverviewServiceImpl extends ServiceImpl<ICaseOverviewMapper, CaseOverview> implements ICaseOverviewService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IJyUserPlatformService jyUserPlatformService;
|
|
|
+ @Autowired
|
|
|
+ ISysRoleService sysRoleService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ ICaseService caseService;
|
|
|
+ @Autowired
|
|
|
+ ICaseTabulationService caseTabulationService;
|
|
|
+ @Autowired
|
|
|
+ FYunFileServiceInterface fYunFileServiceInterface;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(CaseOverviewParam param) {
|
|
|
+ Long sysUserId = Long.valueOf(StpUtil.getLoginId().toString());
|
|
|
+ Integer loginPlatformId = jyUserPlatformService.getLoginPlatformId();
|
|
|
+ Boolean flag = sysRoleService.isAdmin();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CaseOverview::getPlatformId,loginPlatformId);
|
|
|
+ if(!flag){
|
|
|
+ wrapper.eq(CaseOverview::getSysUserId,sysUserId);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(param.getTitle())){
|
|
|
+ wrapper.like(CaseOverview::getTitle,param.getTitle());
|
|
|
+ }
|
|
|
+ Page<CaseOverview> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
|
|
|
+
|
|
|
+ List<Integer> caseIds = page.getRecords().stream().map(CaseOverview::getCaseId).collect(Collectors.toList());
|
|
|
+ HashMap<Integer, Case> map = caseService.getMapByCaseIds(caseIds);
|
|
|
+
|
|
|
+ for (CaseOverview record : page.getRecords()) {
|
|
|
+ if(record.getCaseId() != null && map.get(record.getCaseId()) != null){
|
|
|
+ record.setResource(map.get(record.getCaseId()).getCaseTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void copy(Integer overviewId) {
|
|
|
+ if(overviewId == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ CaseOverview caseOverview = this.getById(overviewId);
|
|
|
+ if(caseOverview == null){
|
|
|
+ throw new BusinessException(ResultCode.OVERVIEW_NOT_EXIST);
|
|
|
+ }
|
|
|
+ caseOverview.setId(null);
|
|
|
+ caseOverview.setTitle(caseOverview.getTitle() +"(copy)");
|
|
|
+ caseOverview.setIsCopy(1);
|
|
|
+// if(StringUtils.isNotBlank(caseOverview.getListCover())){
|
|
|
+// String newPath = FileWriterUtil.getCpFilePath(caseOverview.getListCover());
|
|
|
+// fYunFileServiceInterface.copyFileInBucket(caseOverview.getListCover(),newPath);
|
|
|
+// caseOverview.setListCover(newPath);
|
|
|
+// }
|
|
|
+// if(StringUtils.isNotBlank(caseOverview.getKankanCover())){
|
|
|
+// String newPath = FileWriterUtil.getCpFilePath(caseOverview.getKankanCover());
|
|
|
+// fYunFileServiceInterface.copyFileInBucket(caseOverview.getKankanCover(),newPath);
|
|
|
+// caseOverview.setKankanCover(newPath);
|
|
|
+// }
|
|
|
+
|
|
|
+ this.save(caseOverview);
|
|
|
+
|
|
|
+ List<CaseTabulation> caseTabulations = caseTabulationService.getByOverId(caseOverview.getId());
|
|
|
+ for (CaseTabulation caseTabulation : caseTabulations) {
|
|
|
+ caseTabulation.setId(null);
|
|
|
+ caseTabulation.setOverviewId(caseOverview.getId());
|
|
|
+ caseTabulationService.save(caseTabulation);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void rename(Integer overviewId, String newTitle) {
|
|
|
+ if(overviewId == null || StringUtils.isBlank(newTitle)){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<CaseOverview> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(CaseOverview::getId,overviewId);
|
|
|
+ wrapper.set(CaseOverview::getTitle,newTitle);
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void del(Integer overviewId) {
|
|
|
+ if(overviewId == null ){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ CaseOverview caseOverview = this.getById(overviewId);
|
|
|
+ if(caseOverview == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.removeById(overviewId);
|
|
|
+ this.delFile(caseOverview);
|
|
|
+
|
|
|
+ List<CaseTabulation> caseTabulations = caseTabulationService.getByOverId(overviewId);
|
|
|
+ if(!caseTabulations.isEmpty()){
|
|
|
+ caseTabulationService.delByIds(caseTabulations.stream().map(CaseTabulation::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void delFile(CaseOverview caseOverview) {
|
|
|
+ List<CaseOverview> list = this.getByCover(caseOverview.getListCover());
|
|
|
+ if(list.isEmpty()){
|
|
|
+ try {
|
|
|
+ fYunFileServiceInterface.deleteFile(caseOverview.getListCover());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CaseOverview> list2 = this.getByCover(caseOverview.getKankanCover());
|
|
|
+ if(list2.isEmpty()){
|
|
|
+ try {
|
|
|
+ fYunFileServiceInterface.deleteFile(caseOverview.getKankanCover());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CaseOverview> getByCover(String listCover) {
|
|
|
+ LambdaQueryWrapper<CaseOverview> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.and(e -> e.eq(CaseOverview::getListCover,listCover).or().eq(CaseOverview::getKankanCover,listCover));
|
|
|
+ return this.list(wrapper);
|
|
|
+ }
|
|
|
+}
|