105 lines
3.7 KiB
Java
105 lines
3.7 KiB
Java
|
|
package com.dbnt.faisp.fipTarget.service;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
import com.dbnt.faisp.config.BaseService;
|
||
|
|
import com.dbnt.faisp.equip.model.Equip;
|
||
|
|
import com.dbnt.faisp.equip.model.EquipLog;
|
||
|
|
import com.dbnt.faisp.fipTarget.mapper.FipTargetMapper;
|
||
|
|
import com.dbnt.faisp.fipTarget.model.PartInfo;
|
||
|
|
import com.dbnt.faisp.fipTarget.model.PartInfoFile;
|
||
|
|
import com.dbnt.faisp.fipTarget.repository.PartInfoFileRepository;
|
||
|
|
import com.dbnt.faisp.fipTarget.repository.PartInfoRepository;
|
||
|
|
import com.dbnt.faisp.publicBoard.model.PublicFile;
|
||
|
|
import com.dbnt.faisp.userInfo.model.UserInfo;
|
||
|
|
import com.dbnt.faisp.util.ParamMap;
|
||
|
|
import com.dbnt.faisp.util.Utils;
|
||
|
|
|
||
|
|
import lombok.RequiredArgsConstructor;
|
||
|
|
|
||
|
|
import org.springframework.beans.factory.annotation.Value;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
import org.springframework.transaction.annotation.Transactional;
|
||
|
|
import org.springframework.util.FileCopyUtils;
|
||
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||
|
|
import org.springframework.web.multipart.MultipartFile;
|
||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
import java.time.LocalDateTime;
|
||
|
|
import java.util.*;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
@RequiredArgsConstructor
|
||
|
|
public class FipTargetService extends BaseService {
|
||
|
|
@Value("${spring.servlet.multipart.location}")
|
||
|
|
protected String locationPath;
|
||
|
|
|
||
|
|
private final PartInfoRepository partInfoRepository;
|
||
|
|
private final PartInfoFileRepository partInfoFileRepository;
|
||
|
|
private final FipTargetMapper fipTargetMapper;
|
||
|
|
|
||
|
|
public List<ParamMap> selectPartInfoManagerList(ParamMap param) {
|
||
|
|
return fipTargetMapper.selectPartInfoManagerList(param);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Transactional
|
||
|
|
public void savePartInfo(PartInfo partInfo) {
|
||
|
|
PartInfo dbPart = partInfoRepository.findFirstByOrderByPiSeqDesc();
|
||
|
|
if(dbPart == null) {
|
||
|
|
partInfo.setPiSeq(1);
|
||
|
|
partInfo.setVersionNo(1);
|
||
|
|
partInfoRepository.save(partInfo);
|
||
|
|
} else {
|
||
|
|
partInfo.setPiSeq(dbPart.getPiSeq()+1);
|
||
|
|
partInfo.setVersionNo(1);
|
||
|
|
partInfoRepository.save(partInfo);
|
||
|
|
}
|
||
|
|
saveUploadFiles(partInfo.getPiSeq(),partInfo.getVersionNo(), partInfo.getMultipartFileList());
|
||
|
|
}
|
||
|
|
|
||
|
|
private void saveUploadFiles(Integer piSeq,Integer versionNo, List<MultipartFile> multipartFileList) {
|
||
|
|
PartInfoFile lastFileInfo = partInfoFileRepository.findTopByPiSeqOrderByFileSeq(piSeq);
|
||
|
|
int fileSeq = lastFileInfo==null?1:(lastFileInfo.getFileSeq()+1);
|
||
|
|
if(multipartFileList == null || multipartFileList.isEmpty()) {
|
||
|
|
PartInfoFile fileInfo = new PartInfoFile();
|
||
|
|
fileInfo.setFileSeq(fileSeq);
|
||
|
|
fileInfo.setPiSeq(piSeq);
|
||
|
|
fileInfo.setVersionNo(versionNo);
|
||
|
|
|
||
|
|
partInfoFileRepository.save(fileInfo);
|
||
|
|
} else {
|
||
|
|
for(MultipartFile file : multipartFileList){
|
||
|
|
String saveName = UUID.randomUUID().toString();
|
||
|
|
String path = locationPath+File.separator+"publicFile"+File.separator;
|
||
|
|
saveFile(file, new File(path+File.separator+saveName));
|
||
|
|
|
||
|
|
String originalFilename = file.getOriginalFilename();
|
||
|
|
int extnIdx = originalFilename.lastIndexOf(".");
|
||
|
|
PartInfoFile fileInfo = new PartInfoFile();
|
||
|
|
fileInfo.setFileSeq(fileSeq++);
|
||
|
|
fileInfo.setPiSeq(piSeq);
|
||
|
|
fileInfo.setVersionNo(versionNo);
|
||
|
|
fileInfo.setOrigNm(originalFilename.substring(0, extnIdx));
|
||
|
|
fileInfo.setFileExtn(originalFilename.substring(extnIdx+1));
|
||
|
|
fileInfo.setConvNm(saveName);
|
||
|
|
fileInfo.setFileSize(calculationSize(file.getSize()));
|
||
|
|
fileInfo.setFilePath(path);
|
||
|
|
partInfoFileRepository.save(fileInfo);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public List<PartInfo> selectPartInfoList(PartInfo partInfo) {
|
||
|
|
return fipTargetMapper.selectPartInfoList(partInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
public Integer selectPartInfoListCnt(PartInfo partInfo) {
|
||
|
|
return fipTargetMapper.selectPartInfoListCnt(partInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|