package com.zzg.system.service.system.impl;
|
|
import cn.hutool.core.text.StrPool;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.zzg.common.constant.SysConstants;
|
import com.zzg.common.utils.SecurityUtils;
|
import com.zzg.system.domain.AttachFile;
|
import com.zzg.system.mapper.system.AttachFileMapper;
|
import com.zzg.system.service.system.IAttachFileService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* attach_file
|
*/
|
@Slf4j
|
@Service
|
public class AttachFileServiceImpl extends ServiceImpl<AttachFileMapper, AttachFile> implements IAttachFileService {
|
|
@Override
|
public AttachFile transFile(String filePath, String foreignId, Integer fileType) {
|
return transFile(filePath, foreignId, fileType, AttachFile.UP_TYPE_PROJECT);
|
}
|
|
@Override
|
public AttachFile transFile(String filePath, String foreignId, Integer fileType, Integer upType) {
|
AttachFile file = new AttachFile();
|
file.setInventoryId(foreignId);
|
file.setFileType(fileType);
|
file.setFilePath(SysConstants.Path.UPLOAD + filePath.substring(filePath.lastIndexOf("/")));
|
file.setOriginName(filePath.substring(filePath.indexOf(StrPool.UNDERLINE) + 1));
|
file.setSuffix(filePath.substring(filePath.lastIndexOf(StrPool.DOT) + 1));
|
file.setUpType(upType);
|
file.setCreateTime(new Date());
|
file.setCreateName(SecurityUtils.getUsername());
|
return file;
|
}
|
|
@Override
|
public List<AttachFile> transFile(List<String> filePaths, String foreignId, Integer fileType) {
|
List<AttachFile> fileList = new ArrayList<>();
|
for (String path : filePaths) {
|
fileList.add(transFile(path, foreignId, fileType));
|
}
|
return fileList;
|
}
|
|
@Override
|
public List<AttachFile> transFile(List<String> filePaths, String foreignId, Integer fileType, Integer upType) {
|
List<AttachFile> fileList = new ArrayList<>();
|
for (String path : filePaths) {
|
fileList.add(transFile(path, foreignId, fileType, upType));
|
}
|
return fileList;
|
}
|
|
@Override
|
public AttachFile createByAgree(String surveyId, String inventoryId, Integer inventoryType, String path, Integer fileType) {
|
AttachFile file = new AttachFile();
|
file.setSurveyId(surveyId);
|
file.setInventoryId(inventoryId);
|
file.setInventoryType(inventoryType);
|
file.setFilePath(path);
|
file.setFileType(fileType);
|
file.setOriginName(path.substring(path.lastIndexOf(StrPool.SLASH) + 1));
|
file.setCreateName(SecurityUtils.getUsername());
|
file.setCreateTime(new Date());
|
return file;
|
}
|
|
}
|