调整报告模板修改接口
This commit is contained in:
@@ -124,7 +124,7 @@ public class AdPlanController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
|
||||||
@PostMapping("/downloadTemplate")
|
@PostMapping("/downloadTemplate")
|
||||||
@ApiOperation("下载二楼检测计划导出模板")
|
@ApiOperation("下载检测计划导出模板")
|
||||||
public void downloadTemplate() {
|
public void downloadTemplate() {
|
||||||
adPlanService.downloadTemplate();
|
adPlanService.downloadTemplate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ public enum ReportResponseEnum {
|
|||||||
DEVICE_NOT_EXIST("A012007", "请检查装置是否存在!"),
|
DEVICE_NOT_EXIST("A012007", "请检查装置是否存在!"),
|
||||||
DEVICE_TYPE_NOT_EXIST("A012008", "设备类型缺失,请联系管理员!"),
|
DEVICE_TYPE_NOT_EXIST("A012008", "设备类型缺失,请联系管理员!"),
|
||||||
REPORT_TEMPLATE_NOT_EXIST("A012009", "报告模板缺失,请联系管理员!"),
|
REPORT_TEMPLATE_NOT_EXIST("A012009", "报告模板缺失,请联系管理员!"),
|
||||||
NO_CHECK_DATA("A012010", "没有检测数据,无法生成报告!");
|
NO_CHECK_DATA("A012010", "没有检测数据,无法生成报告!"),
|
||||||
|
FILE_RENAME_FAILED("A012011", "文件重命名失败");
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
private String message;
|
private String message;
|
||||||
|
|||||||
@@ -190,9 +190,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public boolean update(ReportParam.UpdateParam reportParam) {
|
public boolean update(ReportParam.UpdateParam reportParam) {
|
||||||
this.checkRepeat(reportParam, true);
|
this.checkRepeat(reportParam, true);
|
||||||
this.deleteFile(Collections.singletonList(reportParam.getId()));
|
|
||||||
PqReport pqReport = new PqReport();
|
PqReport pqReport = new PqReport();
|
||||||
BeanUtils.copyProperties(reportParam, pqReport);
|
BeanUtils.copyProperties(reportParam, pqReport);
|
||||||
|
|
||||||
@@ -231,13 +231,14 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
* @param pqReport
|
* @param pqReport
|
||||||
* @param isAdd
|
* @param isAdd
|
||||||
*/
|
*/
|
||||||
private void uploadFile(ReportParam reportParam, PqReport pqReport, Boolean isAdd) {
|
private void uploadFile(ReportParam reportParam, PqReport pqReport, boolean isAdd) {
|
||||||
String uploadDir = templatePath + File.separator + reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
|
String uploadDir = templatePath + File.separator + reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
|
||||||
|
|
||||||
//校验文件后缀
|
//校验文件后缀
|
||||||
MultipartFile baseFile = reportParam.getBaseFile();
|
MultipartFile baseFile = reportParam.getBaseFile();
|
||||||
MultipartFile detailFile = reportParam.getDetailFile();
|
MultipartFile detailFile = reportParam.getDetailFile();
|
||||||
if (ObjectUtil.isNotNull(baseFile) && ObjectUtil.isNotNull(detailFile) && !baseFile.isEmpty() && !detailFile.isEmpty()) {
|
if (ObjectUtil.isNotNull(baseFile) && ObjectUtil.isNotNull(detailFile) && !baseFile.isEmpty() && !detailFile.isEmpty()) {
|
||||||
|
this.deleteFile(Collections.singletonList(pqReport.getId()));
|
||||||
String baseOriginalFilename = baseFile.getOriginalFilename();
|
String baseOriginalFilename = baseFile.getOriginalFilename();
|
||||||
String baseFileName = baseOriginalFilename.substring(0, baseOriginalFilename.lastIndexOf("."));
|
String baseFileName = baseOriginalFilename.substring(0, baseOriginalFilename.lastIndexOf("."));
|
||||||
String baseSuffix = baseOriginalFilename.substring(baseOriginalFilename.lastIndexOf(".") + 1);
|
String baseSuffix = baseOriginalFilename.substring(baseOriginalFilename.lastIndexOf(".") + 1);
|
||||||
@@ -252,23 +253,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
throw new BusinessException(ReportResponseEnum.FILE_NAME_SAME_ERROR);
|
throw new BusinessException(ReportResponseEnum.FILE_NAME_SAME_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
pqReport.setBasePath(uploadDir + baseFileName + "_" + pqReport.getVersion() + ".docx");
|
pqReport.setBasePath(uploadDir + baseFileName + ".docx");
|
||||||
pqReport.setDetailPath(uploadDir + detailFileName + "_" + pqReport.getVersion() + ".docx");
|
pqReport.setDetailPath(uploadDir + detailFileName + ".docx");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 创建上传目录(如果不存在)
|
this.createDirectory(uploadDir);
|
||||||
Path uploadPath = Paths.get(uploadDir);
|
|
||||||
if (!Files.exists(uploadPath)) {
|
|
||||||
Files.createDirectories(uploadPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
//清空目录下的文件
|
|
||||||
File[] files = uploadPath.toFile().listFiles();
|
|
||||||
if (ArrayUtil.isNotEmpty(files)) {
|
|
||||||
for (int i = 0; i < files.length; i++) {
|
|
||||||
files[i].delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存文件
|
// 保存文件
|
||||||
byte[] baseBytes = baseFile.getBytes();
|
byte[] baseBytes = baseFile.getBytes();
|
||||||
@@ -290,6 +279,71 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
} else {
|
} else {
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
throw new BusinessException(ReportResponseEnum.FILE_NOT_NULL);
|
throw new BusinessException(ReportResponseEnum.FILE_NOT_NULL);
|
||||||
|
} else {
|
||||||
|
PqReport oldPqReport = this.getById(pqReport.getId());
|
||||||
|
String newDir = templatePath + File.separator + reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
|
||||||
|
String oldDir = oldPqReport.getBasePath().substring(0, oldPqReport.getBasePath().lastIndexOf(File.separator) + 1);
|
||||||
|
|
||||||
|
//若修改了文件名称、版本号,则需要重命名文件
|
||||||
|
if (!oldDir.equals(newDir)) {
|
||||||
|
// 文件夹重命名
|
||||||
|
String oldBasePathStr = oldPqReport.getBasePath();
|
||||||
|
String baseName = oldBasePathStr.substring(oldBasePathStr.lastIndexOf(File.separator) + 1);
|
||||||
|
Path oldBasePath = Paths.get(oldBasePathStr);
|
||||||
|
Path newBasePath = Paths.get(newDir + baseName);
|
||||||
|
pqReport.setBasePath(newDir + baseName);
|
||||||
|
|
||||||
|
String oldDetailPathStr = oldPqReport.getDetailPath();
|
||||||
|
String detailName = oldDetailPathStr.substring(oldDetailPathStr.lastIndexOf(File.separator) + 1);
|
||||||
|
Path oldDetailPath = Paths.get(oldDetailPathStr);
|
||||||
|
Path newDetailPath = Paths.get(newDir + detailName);
|
||||||
|
pqReport.setDetailPath(newDir + detailName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.createDirectory(newDir);
|
||||||
|
Files.move(oldBasePath, newBasePath);
|
||||||
|
Files.move(oldDetailPath, newDetailPath);
|
||||||
|
if (!oldPqReport.getName().equals(reportParam.getName()) && !this.existSameName(pqReport.getId(), oldPqReport.getName())) {
|
||||||
|
this.recursionDeleteDirectory(templatePath + File.separator + oldPqReport.getName());
|
||||||
|
} else {
|
||||||
|
Paths.get(oldDir).toFile().delete();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(ReportResponseEnum.FILE_RENAME_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回是否存在同名的报告
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean existSameName(String id, String name) {
|
||||||
|
return this.lambdaQuery().eq(PqReport::getName, name).ne(PqReport::getId, id).count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建目录并清空目录下的文件
|
||||||
|
*
|
||||||
|
* @param dirPath
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void createDirectory(String dirPath) throws IOException {
|
||||||
|
// 创建上传目录(如果不存在)
|
||||||
|
Path uploadPath = Paths.get(dirPath);
|
||||||
|
if (!Files.exists(uploadPath)) {
|
||||||
|
Files.createDirectories(uploadPath);
|
||||||
|
}
|
||||||
|
//清空目录下的文件
|
||||||
|
File[] files = uploadPath.toFile().listFiles();
|
||||||
|
if (ArrayUtil.isNotEmpty(files)) {
|
||||||
|
for (int i = 0; i < files.length; i++) {
|
||||||
|
files[i].delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,6 +379,21 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归删除目录
|
||||||
|
*
|
||||||
|
* @param dirPath
|
||||||
|
*/
|
||||||
|
private void recursionDeleteDirectory(String dirPath) throws IOException {
|
||||||
|
Path path = Paths.get(dirPath);
|
||||||
|
if (Files.exists(path)) {
|
||||||
|
Files.walk(path)
|
||||||
|
.sorted(Comparator.reverseOrder())
|
||||||
|
.map(Path::toFile)
|
||||||
|
.forEach(File::delete);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateReport(DevReportParam devReportParam) {
|
public void generateReport(DevReportParam devReportParam) {
|
||||||
AdPlan plan = adPlanService.getById(devReportParam.getPlanId());
|
AdPlan plan = adPlanService.getById(devReportParam.getPlanId());
|
||||||
|
|||||||
Reference in New Issue
Block a user