|
|
|
@ -1,18 +1,18 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2019-2020 Zheng Jie
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
* Copyright 2019-2020 Zheng Jie
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package me.zhengjie.modules.uploadnew.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
@ -50,11 +50,11 @@ import static me.zhengjie.modules.uploadnew.consts.SysConstNew.TEST_USER_NAME;
|
|
|
|
|
import static me.zhengjie.modules.uploadnew.consts.UploadFileNewConst.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @website https://el-admin.vip
|
|
|
|
|
* @description 服务实现
|
|
|
|
|
* @author weizhongxi
|
|
|
|
|
* @date 2021-04-14
|
|
|
|
|
**/
|
|
|
|
|
* @author weizhongxi
|
|
|
|
|
* @website https://el-admin.vip
|
|
|
|
|
* @description 服务实现
|
|
|
|
|
* @date 2021-04-14
|
|
|
|
|
**/
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
@ -82,21 +82,21 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
private final TbUploadFileNewMapper tbUploadFileNewMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String,Object> queryAll(TbUploadFileNewQueryCriteria criteria, Pageable pageable){
|
|
|
|
|
Page<TbUploadFileNew> page = tbUploadFileNewRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
|
|
|
|
public Map<String, Object> queryAll(TbUploadFileNewQueryCriteria criteria, Pageable pageable) {
|
|
|
|
|
Page<TbUploadFileNew> page = tbUploadFileNewRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
|
|
|
|
return PageUtil.toPage(page.map(tbUploadFileNewMapper::toDto));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TbUploadFileNewDto> queryAll(TbUploadFileNewQueryCriteria criteria){
|
|
|
|
|
return tbUploadFileNewMapper.toDto(tbUploadFileNewRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
|
|
|
|
public List<TbUploadFileNewDto> queryAll(TbUploadFileNewQueryCriteria criteria) {
|
|
|
|
|
return tbUploadFileNewMapper.toDto(tbUploadFileNewRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public TbUploadFileNewDto findById(Integer id) {
|
|
|
|
|
TbUploadFileNew tbUploadFileNew = tbUploadFileNewRepository.findById(id).orElseGet(TbUploadFileNew::new);
|
|
|
|
|
ValidationUtil.isNull(tbUploadFileNew.getId(),"TbUploadFileNew","id",id);
|
|
|
|
|
ValidationUtil.isNull(tbUploadFileNew.getId(), "TbUploadFileNew", "id", id);
|
|
|
|
|
return tbUploadFileNewMapper.toDto(tbUploadFileNew);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -110,7 +110,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void update(TbUploadFileNew resources) {
|
|
|
|
|
TbUploadFileNew tbUploadFileNew = tbUploadFileNewRepository.findById(resources.getId()).orElseGet(TbUploadFileNew::new);
|
|
|
|
|
ValidationUtil.isNull( tbUploadFileNew.getId(),"TbUploadFileNew","id",resources.getId());
|
|
|
|
|
ValidationUtil.isNull(tbUploadFileNew.getId(), "TbUploadFileNew", "id", resources.getId());
|
|
|
|
|
tbUploadFileNew.copy(resources);
|
|
|
|
|
tbUploadFileNewRepository.save(tbUploadFileNew);
|
|
|
|
|
}
|
|
|
|
@ -126,7 +126,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
public void download(List<TbUploadFileNewDto> all, HttpServletResponse response) throws IOException {
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
for (TbUploadFileNewDto tbUploadFileNew : all) {
|
|
|
|
|
Map<String,Object> map = new LinkedHashMap<>();
|
|
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
|
map.put("创建时间", tbUploadFileNew.getGmtCreate());
|
|
|
|
|
map.put("修改时间", tbUploadFileNew.getGmtModified());
|
|
|
|
|
map.put("上传任务名称", tbUploadFileNew.getUploadFileTaskName());
|
|
|
|
@ -163,10 +163,10 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
file.transferTo(Paths.get(eachFilePath));
|
|
|
|
|
baseStr = "";
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("============== [transferTo file fail, path is {} ] ==============", eachFilePath,e);
|
|
|
|
|
log.error("============== [transferTo file fail, path is {} ] ==============", eachFilePath, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String name=file.getOriginalFilename();
|
|
|
|
|
String name = file.getOriginalFilename();
|
|
|
|
|
int lastIndexOf = name.lastIndexOf(".");
|
|
|
|
|
String nameStr = name.substring(lastIndexOf);
|
|
|
|
|
//记录文件格式
|
|
|
|
@ -175,24 +175,24 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
//根据文件类型进行解析
|
|
|
|
|
try {
|
|
|
|
|
// FIXME: 2021/4/23 0023
|
|
|
|
|
if(nameStr.equals(".xlsx")||nameStr.equals(".xls")){
|
|
|
|
|
if (nameStr.equals(".xlsx") || nameStr.equals(".xls")) {
|
|
|
|
|
fileFormat = "excel文件";
|
|
|
|
|
ExcelUtils excelUtils = new ExcelUtils();
|
|
|
|
|
list = excelUtils.excelParseList(file.getInputStream());
|
|
|
|
|
|
|
|
|
|
}else if (nameStr.equals(".txt")){
|
|
|
|
|
} else if (nameStr.equals(".txt")) {
|
|
|
|
|
fileFormat = "txt文件";
|
|
|
|
|
list = FileUtil.readLines(eachFilePath, "UTF-8");
|
|
|
|
|
}else if (nameStr.equals(".csv")){
|
|
|
|
|
} else if (nameStr.equals(".csv")) {
|
|
|
|
|
fileFormat = "csv文件";
|
|
|
|
|
list = TxtUtils.csvParseList(file.getInputStream());
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 统计行数
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)){
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) {
|
|
|
|
|
count += list.size();
|
|
|
|
|
}
|
|
|
|
|
// 保存所有的临时存放路径
|
|
|
|
@ -205,9 +205,9 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
tbUploadFileNew.setUploadFileTaskName(taskName);
|
|
|
|
|
tbUploadFileNew.setUploadTime(new Timestamp(new Date().getTime()));
|
|
|
|
|
String currentUsername;
|
|
|
|
|
if (SysConst.sysDebug){
|
|
|
|
|
if (SysConst.sysDebug) {
|
|
|
|
|
tbUploadFileNew.setOperation(TEST_USER_NAME);//fixme 这边测试环境补充一下需要的操作人
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
currentUsername = SecurityUtils.getCurrentUsername();
|
|
|
|
|
tbUploadFileNew.setOperation(currentUsername);
|
|
|
|
|
}
|
|
|
|
@ -221,7 +221,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
tbUploadFileNew.setGmtCreate(nousedate);
|
|
|
|
|
tbUploadFileNew.setGmtModified(nousedate);
|
|
|
|
|
String tempFilesPath = pathBuilder.toString().substring(0, pathBuilder.length() - 1);
|
|
|
|
|
if (StringUtils.isNotBlank(tempFilesPath)){
|
|
|
|
|
if (StringUtils.isNotBlank(tempFilesPath)) {
|
|
|
|
|
tbUploadFileNew.setLocalSavePath(tempFilesPath); // 去掉最后的那个通配符 FILE_PATH_SPLIT
|
|
|
|
|
}
|
|
|
|
|
TbUploadFileNewDto tbUploadFileNewDto = create(tbUploadFileNew);
|
|
|
|
@ -240,20 +240,20 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService {
|
|
|
|
|
String dirPath;
|
|
|
|
|
// 生成一个随机文件夹目录,方便整理和打包
|
|
|
|
|
|
|
|
|
|
String filePath = RandomUtil.randomString(6) + FILE_NAME_SPLIT + baseStr + FILE_SPLIT + extName;
|
|
|
|
|
String filePath = RandomUtil.randomString(6) + FILE_NAME_SPLIT + baseStr + FILE_SPLIT + extName;
|
|
|
|
|
|
|
|
|
|
if (osInfo.isWindows()) {
|
|
|
|
|
dirPath = remoteLinkFileBasePathWindows + timeFormate + File.separator;
|
|
|
|
|
dirPath = remoteLinkFileBasePathWindows + timeFormate + File.separator;
|
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
|
// 构建存储文件
|
|
|
|
|
return dirPath + filePath;
|
|
|
|
|
} else if (osInfo.isLinux()) {
|
|
|
|
|
dirPath = remoteLinkFileBasePathLinux + timeFormate + File.separator;
|
|
|
|
|
dirPath = remoteLinkFileBasePathLinux + timeFormate + File.separator;
|
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
|
// 构建存储文件
|
|
|
|
|
return dirPath + filePath;
|
|
|
|
|
} else if (osInfo.isMac()) {
|
|
|
|
|
dirPath = remoteLinkFileBasePathMac + timeFormate + File.separator;
|
|
|
|
|
dirPath = remoteLinkFileBasePathMac + timeFormate + File.separator;
|
|
|
|
|
FileUtil.mkdir(new File(dirPath));
|
|
|
|
|
// 构建存储文件
|
|
|
|
|
return dirPath + filePath;
|
|
|
|
|