forked from gzzfw/backEnd/gz-dyh

liyj
2024-08-31 67bc268ffdc203fd0f3081261c8778bd61a23541
dyh-service/dyh-sys/src/main/java/cn/huge/module/file/service/FileRelateService.java
@@ -5,7 +5,10 @@
import cn.huge.base.common.utils.IdUtils;
import cn.huge.module.client.api.impl.UtilsClientImpl;
import cn.huge.module.file.dao.mapper.FileRelateMapper;
import cn.huge.module.file.domain.dto.UploaderDTO;
import cn.huge.module.file.domain.po.FileInfo;
import cn.huge.module.file.domain.po.FileRelate;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -130,4 +133,43 @@
        }
    }
    /**
     * 根据所属业务编号和类型统计
     * @param ownerId 所属业务编号
     * @param ownerType 所属业务类型
     * @return int 统计数
     */
    public int countByOwnerIdAndType(String ownerId, String ownerType){
        QueryWrapper<FileRelate> fileRelateQueryWrapper = new QueryWrapper<>();
        fileRelateQueryWrapper.eq("owner_id", ownerId).eq("owner_type", ownerType);
        return mapper.selectCount(fileRelateQueryWrapper);
    }
    /**
     * 根据附件信息新增附件业务关系
     * @param fileInfo 附件信息
     */
    public void saveByFileInfo(FileInfo fileInfo) {
        try {
            // 保存业务关系
            FileRelate fileRelate = new FileRelate();
            fileRelate.setId(utilsClient.getNewTimeId());
            fileRelate.setFileId(fileInfo.getId());
            fileRelate.setOwnerId(fileInfo.getOwnerId());
            fileRelate.setOwnerCat(fileInfo.getOwnerCat());
            fileRelate.setOwnerType(fileInfo.getOwnerType());
            fileRelate.setUploaderId(fileInfo.getUploaderId());
            fileRelate.setUploaderName(fileInfo.getUploaderName());
            fileRelate.setUploaderType(fileInfo.getUploaderType());
            fileRelate.setCustId(fileInfo.getCustId());
            Date nowDate = DateUtils.getNowDate();
            fileRelate.setCreateTime(nowDate);
            fileRelate.setUpdateTime(nowDate);
            mapper.insert(fileRelate);
        } catch (Exception e) {
            log.error("service方法[FileRelateService.uploadFile]调用异常:"+e, e);
            throw new ServiceException("FileRelateService.uploadFile", e);
        }
    }
}