2021与蓝度共同重构项目,服务端
Van333
2022-12-29 727a69f859060093e685582fa10e5de82dcc138a
ximon-admin/src/main/java/com/sandu/ximon/admin/service/IpVolumeFileService.java
@@ -1,6 +1,7 @@
package com.sandu.ximon.admin.service;
import com.alibaba.fastjson.JSON;
import com.alipay.service.schema.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
@@ -16,6 +17,7 @@
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.dao.domain.IpVolumeFile;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.IpVolumeFileMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@@ -39,15 +41,10 @@
    public boolean addFile(IpVolumeFileParam fileParam) {
        IpVolumeFile file = new IpVolumeFile();
//        if(SecurityUtils.getClientId()!=null){
//            file.setUserName(SecurityUtils.getUsername());
//        }
//
        if (SecurityUtils.getClientId() != null) {
            file.setUserName(SecurityUtils.getUsername());
            file.setUserId(SecurityUtils.getClientId());
            file.setClientId(clientService.getClientId());
        }
        file.setUserName(SecurityUtils.getUsername());
        file.setUserId(SecurityUtils.getClientId());
        file.setClientId(clientService.getClientId());
        file.setFileName(fileParam.getFileName());
        file.setFileUrl(fileParam.getFileUrl());
@@ -64,37 +61,37 @@
        return save(file);
    }
    public boolean deleteFile(Long fileId) {
        IpVolumeFile byId = getById(fileId);
        String bucketName;
        if (SecurityUtils.getClientId() == null) {
            bucketName = MinIoConstant.ADMIN_BROADCAST_FILE.getBucketName();
        } else {
            bucketName = MinIoConstant.BROADCAST_FILE.getBucketName() + SecurityUtils.getUserId();
        }
        if (byId == null) {
            throw new BusinessException("找不到对应文件");
        }
        boolean b = minIoUtil.deleteFile(bucketName, byId.getFileName());
    public boolean deleteFile(List<Long> fileIds) {
        fileIds.forEach(fileId -> {
            IpVolumeFile byId = getById(fileId);
            String bucketName;
            if (SecurityUtils.getClientId() == null) {
                bucketName = MinIoConstant.ADMIN_BROADCAST_FILE.getBucketName();
            } else {
                bucketName = MinIoConstant.BROADCAST_FILE.getBucketName() + SecurityUtils.getUserId();
            }
            if (byId == null) {
                throw new BusinessException("找不到对应文件");
            }
            boolean b = minIoUtil.deleteFile(bucketName, byId.getFileName());
//        if (!b) {
//            throw new BusinessException("服务器删除失败");
//        }
        /**
         * 音柱文件删除 日志记录开始
         */
        String content = "删除文件id:" + fileId + "音柱文件名称:" + byId.getFileName() + ",文件大小:" + byId.getOriginSize() + ",文件路径:" + byId.getFileUrl();
        StoreOperationRecordsUtils.storeOperationData(null, null, "音柱文件删除", content);
        /**
         * 音柱文件删除 日志记录结束
         */
            /**
             * 音柱文件删除 日志记录开始
             */
            String content = "删除文件id:" + fileId + "音柱文件名称:" + byId.getFileName() + ",文件大小:" + byId.getOriginSize() + ",文件路径:" + byId.getFileUrl();
            StoreOperationRecordsUtils.storeOperationData(null, null, "音柱文件删除", content);
            /**
             * 音柱文件删除 日志记录结束
             */
        return removeById(fileId);
        });
        return removeByIds(fileIds);
    }
    public LambdaQueryWrapper<IpVolumeFile> listFile(BaseConditionVO baseConditionVO, String keyword) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
    public List<IpVolumeFile> ipVolumeFileList(BaseConditionVO baseConditionVO, String keyword, Integer order, Integer seq) {
        LambdaQueryWrapper<IpVolumeFile> wrapper = Wrappers.lambdaQuery(IpVolumeFile.class);
        //不是超管
        if (SecurityUtils.getClientId() != null) {
            wrapper = wrapper.eq(IpVolumeFile::getClientId, SecurityUtils.getUserId())
@@ -106,10 +103,43 @@
        if (keyword != null && !keyword.isEmpty()) {
            wrapper.like(IpVolumeFile::getFileName, keyword);
        }
        return wrapper;
        //排序字段
        String orderByResult = "id";
        //正序、倒叙
        String orderBySeq = OrderByEnums.ASC.getCode();
        if (order != null) {
            switch (order) {
                case 1:
                    orderByResult = OrderByEnums.IP_VOLUME_FILE_CREATE_TIME.getCode();
                    break;
                default:
            }
        }
        if (seq != null) {
            switch (seq) {
                case 1:
                    orderBySeq = OrderByEnums.ASC.getCode();
                    break;
                case 2:
                    orderBySeq = OrderByEnums.DESC.getCode();
                    break;
                default:
                    break;
            }
        }
        //排序方式
        String orderBy = orderByResult + " " + orderBySeq;
        if (baseConditionVO != null) {
            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
        }
        List<IpVolumeFile> list = list(wrapper);
        return list;
    }
    public List<IpVolumeFile> listFiles() {
    public List<IpVolumeFile> listFiles(String keyword) {
        LambdaQueryWrapper<IpVolumeFile> wrapper = Wrappers.lambdaQuery(IpVolumeFile.class);
        //不是超管
@@ -119,6 +149,9 @@
                        file.eq(IpVolumeFile::getUserId, SecurityUtils.getUserId());
                    });
        }
        if (keyword != null && !StringUtil.isEmpty(keyword)) {
            wrapper.like(IpVolumeFile::getFileName, keyword);
        }
        return list(wrapper);
    }