123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- package com.fdkankan.scene.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateTime;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.util.ArrayUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.fdkankan.common.constant.CommonOperStatus;
- import com.fdkankan.common.constant.CommonStatus;
- import com.fdkankan.common.constant.SceneAsynFuncType;
- import com.fdkankan.common.constant.SceneAsynModuleType;
- import com.fdkankan.common.constant.SceneAsynOperType;
- import com.fdkankan.common.constant.*;
- import com.fdkankan.common.exception.BusinessException;
- import com.fdkankan.scene.entity.SceneAsynOperLog;
- import com.fdkankan.scene.entity.ScenePlus;
- import com.fdkankan.scene.entity.ScenePlusExt;
- import com.fdkankan.scene.mapper.ISceneAsynOperLogMapper;
- import com.fdkankan.scene.oss.OssUtil;
- import com.fdkankan.scene.service.ISceneAsynOperLogService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.scene.service.IScenePlusExtService;
- import com.fdkankan.scene.service.IScenePlusService;
- import com.fdkankan.scene.vo.SceneAsynOperLogParamVO;
- import com.fdkankan.web.response.ResultData;
- import java.io.IOException;
- import java.nio.file.FileSystemException;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.List;
- import java.util.stream.Collectors;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-12-07
- */
- @Slf4j
- @Service
- public class SceneAsynOperLogServiceImpl extends ServiceImpl<ISceneAsynOperLogMapper, SceneAsynOperLog> implements ISceneAsynOperLogService {
- @Autowired
- private OssUtil ossUtil;
- @Autowired
- private IScenePlusService scenePlusService;
- @Autowired
- private IScenePlusExtService scenePlusExtService;
- @Override
- public ResultData getAsynOperLog(SceneAsynOperLogParamVO param) {
- LambdaQueryWrapper<SceneAsynOperLog> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(SceneAsynOperLog::getNum, param.getNum());
- if(StrUtil.isNotEmpty(param.getOperType())){
- queryWrapper.eq(SceneAsynOperLog::getOperType, param.getOperType());
- }
- if(StrUtil.isNotEmpty(param.getModule())){
- queryWrapper.eq(SceneAsynOperLog::getModule, param.getModule());
- }
- if(StrUtil.isNotEmpty(param.getFunc())){
- queryWrapper.eq(SceneAsynOperLog::getFunc, param.getFunc());
- }
- //需要弹窗的异步操作列表
- List<SceneAsynOperLog> list = this.list(queryWrapper);
- //如果列表中有需要弹窗并且处理完毕的,需要把这些数据改为不需要弹窗了,因为前端请求到之后就会弹出提示,下次不需要弹窗了
- if(CollUtil.isNotEmpty(list)){
- List<Long> idList = list.stream().filter(log -> {
- if(!log.getState().equals(CommonOperStatus.WAITING.code())){
- return true;
- }
- return false;
- }).map(log->log.getId()).collect(Collectors.toList());
- if(CollUtil.isNotEmpty(idList)){
- this.update(new LambdaUpdateWrapper<SceneAsynOperLog>()
- .set(SceneAsynOperLog::getPop, CommonStatus.NO.code())
- .in(SceneAsynOperLog::getId, idList));
- }
- }
- return ResultData.ok(list);
- }
- @Override
- public void cleanDownloadOssPage(String asynFuncType, int preMonth) {
- List<SceneAsynOperLog> downloadList = this.list(
- new LambdaQueryWrapper<SceneAsynOperLog>()
- .eq(SceneAsynOperLog::getOperType, SceneAsynOperType.DOWNLOAD.code())
- .eq(SceneAsynOperLog::getModule, SceneAsynModuleType.UPLOAD_DOWNLOAD.code())
- .eq(SceneAsynOperLog::getFunc, asynFuncType));
- if(CollUtil.isEmpty(downloadList)){
- return;
- }
- DateTime preDate = DateUtil.offsetMonth(Calendar.getInstance().getTime(), -preMonth);
- List<SceneAsynOperLog> deleteList = downloadList.parallelStream().filter(log -> {
- if (log.getCreateTime().before(preDate)) {
- return true;
- }
- return false;
- }).collect(Collectors.toList());
- if(CollUtil.isEmpty(deleteList)){
- return;
- }
- //删除数据库记录
- List<Long> deleteIdList = deleteList.parallelStream().map(item -> item.getId()).collect(Collectors.toList());
- this.removeByIds(deleteIdList);
- deleteList.parallelStream().forEach(item -> {
- if(StrUtil.isNotEmpty(item.getUrl())){
- try{
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(item.getNum());
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
- ossUtil.deleteObject(scenePlusExt.getYunFileBucket(), item.getUrl());
- }catch (FileSystemException e){
- log.warn("删除oss下载压缩包失败,key:{}", item.getUrl());
- }
- }
- });
- }
- @Override
- public void checkSceneAsynOper(String num, String operType, String module, String function) {
- LambdaQueryWrapper<SceneAsynOperLog> queryWrapper =
- new LambdaQueryWrapper<SceneAsynOperLog>()
- .eq(SceneAsynOperLog::getNum,num)
- .eq(SceneAsynOperLog::getState, CommonOperStatus.WAITING.code());
- if(StrUtil.isNotEmpty(operType)){
- queryWrapper.eq(SceneAsynOperLog::getOperType, operType);
- }
- if(StrUtil.isNotEmpty(module)){
- queryWrapper.eq(SceneAsynOperLog::getModule, module);
- }
- if(StrUtil.isNotEmpty(function)){
- queryWrapper.eq(SceneAsynOperLog::getFunc, function);
- }
- List<SceneAsynOperLog> waittingLogList = this.list(queryWrapper);
- if(CollUtil.isNotEmpty(waittingLogList)){
- throw new BusinessException(ErrorCode.FAILURE_CODE_5066);
- }
- }
- @Override
- public void cleanLog(String num, String moduleType, String funcType, String... operTypes) {
- LambdaQueryWrapper<SceneAsynOperLog> wrapper = new LambdaQueryWrapper<SceneAsynOperLog>()
- .eq(SceneAsynOperLog::getNum, num)
- .eq(SceneAsynOperLog::getModule, moduleType)
- .eq(SceneAsynOperLog::getFunc, funcType);
- if(ArrayUtil.isNotEmpty(operTypes)){
- wrapper.in(SceneAsynOperLog::getOperType, operTypes);
- }
- this.remove(wrapper);
- }
- }
|