|
@@ -21,12 +21,14 @@ import cn.com.ty.lift.business.project.dao.entity.Project;
|
|
|
import cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance;
|
|
|
import cn.com.ty.lift.business.project.service.ProjectLiftRelevanceService;
|
|
|
import cn.com.ty.lift.business.project.service.ProjectService;
|
|
|
+import cn.com.ty.lift.common.aliservice.aliyunoss.AliyunOSS;
|
|
|
import cn.com.ty.lift.common.constants.CommonEnum;
|
|
|
import cn.com.ty.lift.common.utils.DateUtils;
|
|
|
import cn.com.ty.lift.common.utils.MapHelper;
|
|
|
import cn.com.ty.lift.common.utils.ValuePool;
|
|
|
import cn.com.ty.lift.common.verify.Val;
|
|
|
import cn.com.ty.lift.common.verify.Validate;
|
|
|
+import cn.com.ty.lift.common.verify.ValidateException;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.IterUtil;
|
|
@@ -58,7 +60,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.HttpURLConnection;
|
|
@@ -197,8 +198,10 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
|
|
|
if (Objects.nonNull(next))
|
|
|
iterator.remove();
|
|
|
}
|
|
|
- //获取当前时间后的维保计划列表,并清除计划
|
|
|
- maintenancePlanService.removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
+ if (CollUtil.isNotEmpty(planList)) {
|
|
|
+ //获取当前时间后的维保计划列表,并清除计划
|
|
|
+ maintenancePlanService.removeByIds(planList.stream().map(MaintenancePlan::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
//按照修改时间重新生成计划
|
|
|
LocalDate beginTime = request.getCurrentTime().plusDays(interval);
|
|
|
List<MaintenancePlan> plans = maintenancePlanService.generatePlan(plan, periods, interval, beginTime, endDate);
|
|
@@ -583,8 +586,12 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
|
|
|
if (CollUtil.isNotEmpty(page.getRecords())) {
|
|
|
List<MtRecordResponse> records = page.getRecords();
|
|
|
for (MtRecordResponse mtRecord : records) {
|
|
|
- String repairDuration = getRepairDuration(mtRecord.getRepairDiff());
|
|
|
- mtRecord.setRepairDuration(repairDuration);
|
|
|
+ if (mtRecord.getRepairDiff() != null) {
|
|
|
+ String repairDuration = getRepairDuration(mtRecord.getRepairDiff());
|
|
|
+ mtRecord.setRepairDuration(repairDuration);
|
|
|
+ } else {
|
|
|
+ mtRecord.setRepairDuration("");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return page;
|
|
@@ -843,7 +850,7 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
|
|
|
return baseMapper.pageByLift(request.getPage(), request);
|
|
|
}
|
|
|
|
|
|
- public void export(MtRecordRequest mtRecordRequest, HttpServletResponse response) {
|
|
|
+ public String export(MtRecordRequest mtRecordRequest) {
|
|
|
Map<String, String> headerAlias = new LinkedHashMap<>();
|
|
|
headerAlias.put("projectName", "项目名称");
|
|
|
headerAlias.put("useCompanyCode", "梯号");
|
|
@@ -904,67 +911,56 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
|
|
|
//处理文件夹路径
|
|
|
String projectName = mtRecordResponse.getProjectName();
|
|
|
String registrationCode = mtRecordResponse.getRegistrationCode();
|
|
|
+ String useCompanyCode = mtRecordResponse.getUseCompanyCode();
|
|
|
projectName = StrUtil.isNotEmpty(projectName) ? projectName.replace(illegalChars, "-") : "[项目]";
|
|
|
registrationCode = StrUtil.isNotEmpty(registrationCode) ? registrationCode.replace(illegalChars, "-") : "[电梯注册代码]";
|
|
|
+ useCompanyCode = useCompanyCode != null ? useCompanyCode : "";
|
|
|
//保养单及图片文件夹 dir/i.ProjectName-RegistrationCode/
|
|
|
-// String imgDir = StrUtil.format("{}{}{}.{}-{}{}", dir, File.separator, (i + 1), projectName, registrationCode, File.separator);
|
|
|
+ String imgDir = StrUtil.format("{}{}{}.{}-{}-", dir, File.separator, (i + 1), projectName, registrationCode);
|
|
|
+ imgDir += useCompanyCode + File.separator;
|
|
|
//生成维保图片
|
|
|
-// List<MtRecordImg> mtRecordImgs = mtRecordResponse.getMtRecordImgs();
|
|
|
-// List<MtRecordImg> imgs = mtRecordImgs.stream().filter(img -> mtRecordResponse.getId().equals(img.getMtRecordId())).collect(Collectors.toList());
|
|
|
-// if (IterUtil.isNotEmpty(imgs)) {
|
|
|
-// for (int n = 0; n < imgs.size(); n++) {
|
|
|
-// String imgUrl = imgs.get(n).getImgUrl();
|
|
|
-// if (StrUtil.isNotEmpty(imgUrl)) {
|
|
|
-// log.info("imgUrl: {}", imgUrl);
|
|
|
-// String filename = imgDir + StrUtil.format("维保图片{}.jpg", (n + 1));
|
|
|
-// log.info("生成维保图片文件: {}", filename);
|
|
|
-// HttpUtil.downloadFile(imgUrl, filename);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ List<MtRecordImg> mtRecordImgs = mtRecordResponse.getMtRecordImgs();
|
|
|
+ List<MtRecordImg> imgs = mtRecordImgs.stream().filter(img -> mtRecordResponse.getId().equals(img.getMtRecordId())).collect(Collectors.toList());
|
|
|
+ if (IterUtil.isNotEmpty(imgs)) {
|
|
|
+ for (int n = 0; n < imgs.size(); n++) {
|
|
|
+ String imgUrl = imgs.get(n).getImgUrl();
|
|
|
+ if (StrUtil.isNotEmpty(imgUrl)) {
|
|
|
+ log.info("imgUrl: {}", imgUrl);
|
|
|
+ String filename = imgDir + StrUtil.format("维保图片{}.jpg", (n + 1));
|
|
|
+ log.info("生成维保图片文件: {}", filename);
|
|
|
+ HttpUtil.downloadFile(imgUrl, filename);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//生成保养单
|
|
|
- String maintenanceExcelDir = StrUtil.format("{}{}{}.{}-{}{}", dir, File.separator, (i + 1), projectName, registrationCode, "保养单.xlsx");
|
|
|
+ String maintenanceExcelDir = imgDir + "保养单.xlsx";
|
|
|
log.info("生成保养单: {}", maintenanceExcelDir);
|
|
|
excelWriter(mtRecordResponse, maintenanceExcelDir);
|
|
|
}
|
|
|
//压缩文件夹
|
|
|
log.info("生成zipFile路径: {}", zip);
|
|
|
ZipUtil.zip(dir, zip);
|
|
|
+ //上传文件到阿里云,并返回路径给前端
|
|
|
+ return AliyunOSS.me().putObject("maintenance/export/zip/" + generateCode + ".zip", readInputStream(new FileInputStream(new File(zip))));
|
|
|
} catch (Exception e) {
|
|
|
- FileUtil.del(zipFile);
|
|
|
- FileUtil.del(baseDir);
|
|
|
log.error("生成保养文件失败", e);
|
|
|
throw Validate.validateException("生成保养文件失败");
|
|
|
- }
|
|
|
- //下载压缩文件
|
|
|
- if (FileUtil.exist(zipFile)) {
|
|
|
- // 设置强制下载不打开, ZIP的application/x-zip-compressed
|
|
|
- response.setContentType("application/force-download");
|
|
|
- // 设置文件名
|
|
|
- response.addHeader("Content-Disposition", "attachment;fileName=" + zipFile.getName());
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- try (FileInputStream fis = new FileInputStream(zipFile);
|
|
|
- BufferedInputStream bis = new BufferedInputStream(fis)) {
|
|
|
- OutputStream os = response.getOutputStream();
|
|
|
- int i;
|
|
|
- while ((i = bis.read(buffer)) != -1) {
|
|
|
- os.write(buffer, 0, i);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("下载保养文件失败", e);
|
|
|
- throw Validate.validateException("下载保养文件失败");
|
|
|
- } finally {
|
|
|
- //删除临时根目录和zip文件
|
|
|
- FileUtil.del(zipFile);
|
|
|
- FileUtil.del(baseDir);
|
|
|
- }
|
|
|
+ } finally {
|
|
|
+ FileUtil.del(zipFile);
|
|
|
+ FileUtil.del(baseDir);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private MtRecordResponse getMtRecordResponse(@RequestBody @Val MtRecordRequest request) {
|
|
|
MtRecordResponse entity = this.infoById(request);
|
|
|
- String repairDuration = this.getRepairDuration(entity.getRepairDiff());
|
|
|
- entity.setRepairDuration(repairDuration);
|
|
|
+ if (entity == null) {
|
|
|
+ throw new ValidateException("维保记录不存在");
|
|
|
+ }
|
|
|
+ if (entity.getRepairDiff() != null) {
|
|
|
+ String repairDuration = this.getRepairDuration(entity.getRepairDiff());
|
|
|
+ entity.setRepairDuration(repairDuration);
|
|
|
+ }
|
|
|
+ entity.setRepairDuration("");
|
|
|
Validate.notNull(entity, ValuePool.MAINTENANCE_RECORD_NOT_EXIST);
|
|
|
/**
|
|
|
* 维保项id:0/1/2, 0:无需保养,1:已保养,2:需要更换
|
|
@@ -997,6 +993,9 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
ExcelWriter writer = new ExcelWriter(wb, "保养单");
|
|
|
|
|
|
+ String stopDate = mtRecordResponse.getStopDate() != null ? mtRecordResponse.getStopDate().toString().replace("T", " ") : "未设置";
|
|
|
+ String recoveryDate = mtRecordResponse.getRecoveryDate() != null ? mtRecordResponse.getRecoveryDate().toString().replace("T", " ") : "未设置";
|
|
|
+ String workDate = mtRecordResponse.getWorkDate() != null ? mtRecordResponse.getWorkDate().toString().replace("T", " ") : "未设置";
|
|
|
writer.setColumnWidth(1, 25);
|
|
|
writer.setColumnWidth(3, 25);
|
|
|
writer.setColumnWidth(4, 25);
|
|
@@ -1006,36 +1005,52 @@ public class MaintenanceRecordService extends ServiceImpl<MaintenanceRecordMappe
|
|
|
writer.merge(1, 1, 4, 5, "设备内部编号:" + (mtRecordResponse.getUseCompanyCode() != null ? mtRecordResponse.getUseCompanyCode() : "未设置"), false);
|
|
|
writer.merge(2, 2, 0, 1, "注册代码:" + mtRecordResponse.getRegistrationCode(), false);
|
|
|
writer.merge(2, 2, 2, 3, "电梯位置:" + mtRecordResponse.getDevicePosition(), false);
|
|
|
- writer.merge(2, 2, 4, 5, "保养类型:" + mtRecordResponse.getType(), false);
|
|
|
- writer.merge(3, 3, 0, 1, "保养时间:" + mtRecordResponse.getWorkDate().toString().replace("T", " "), false);
|
|
|
+ String type = "";
|
|
|
+ switch (mtRecordResponse.getType()) {
|
|
|
+ case 1:
|
|
|
+ type = "半月保";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ type = "季度保";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ type = "半年保";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ type = "全年保";
|
|
|
+ }
|
|
|
+ writer.merge(2, 2, 4, 5, "保养类型:" + type, false);
|
|
|
+ writer.merge(3, 3, 0, 1, "保养时间:" + workDate, false);
|
|
|
writer.merge(3, 3, 2, 3, "项目编号:" + mtRecordResponse.getProjectCode(), false);
|
|
|
writer.merge(3, 3, 4, 5, "项目名称:" + mtRecordResponse.getProjectName(), false);
|
|
|
writer.merge(4, 4, 0, 1, "计划保养时间:" + mtRecordResponse.getPlanDate(), false);
|
|
|
- writer.merge(4, 4, 2, 3, "停梯时间:" + mtRecordResponse.getStopDate().toString().replace("T", " "), false);
|
|
|
- writer.merge(4, 4, 4, 5, "恢梯时间:" + mtRecordResponse.getRecoveryDate().toString().replace("T", " "), false);
|
|
|
+ writer.merge(4, 4, 2, 3, "停梯时间:" + stopDate, false);
|
|
|
+ writer.merge(4, 4, 4, 5, "恢梯时间:" + recoveryDate, false);
|
|
|
writer.writeCellValue(0, 5, "保养时长");
|
|
|
- writer.merge(5, 5, 1, 5, mtRecordResponse.getRepairDuration(), false);
|
|
|
+ writer.merge(5, 5, 1, 5, mtRecordResponse.getRepairDuration() != null ? mtRecordResponse.getRepairDuration() : "", false);
|
|
|
writer.writeCellValue(0, 6, "序号");
|
|
|
writer.merge(6, 6, 1, 2, "维保项目", false);
|
|
|
writer.merge(6, 6, 3, 4, "维保基本要求", false);
|
|
|
writer.writeCellValue(5, 6, "结果");
|
|
|
Collection<MaintenanceOption> mtOptions = mtRecordResponse.getMtOptions();
|
|
|
int i = 0;
|
|
|
- for (MaintenanceOption mtOption : mtOptions) {
|
|
|
- i++;
|
|
|
- writer.writeCellValue(0, 6 + i, i);
|
|
|
- writer.merge(6 + i, 6 + i, 1, 2, mtOption.getItem(), false);
|
|
|
- writer.merge(6 + i, 6 + i, 3, 4, mtOption.getContent(), false);
|
|
|
- String maintenance = "√";
|
|
|
- switch (mtOption.getOpt()) {
|
|
|
- case 0:
|
|
|
- maintenance = "/";
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- maintenance = "X";
|
|
|
- break;
|
|
|
+ if (mtOptions != null) {
|
|
|
+ for (MaintenanceOption mtOption : mtOptions) {
|
|
|
+ i++;
|
|
|
+ writer.writeCellValue(0, 6 + i, i);
|
|
|
+ writer.merge(6 + i, 6 + i, 1, 2, mtOption.getItem(), false);
|
|
|
+ writer.merge(6 + i, 6 + i, 3, 4, mtOption.getContent(), false);
|
|
|
+ String maintenance = "√";
|
|
|
+ switch (mtOption.getOpt()) {
|
|
|
+ case 0:
|
|
|
+ maintenance = "/";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ maintenance = "X";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ writer.writeCellValue(5, 6 + i, maintenance);
|
|
|
}
|
|
|
- writer.writeCellValue(5, 6 + i, maintenance);
|
|
|
}
|
|
|
writer.writeCellValue(0, 7 + i, "保养建议");
|
|
|
writer.merge(7 + i, 7 + i, 1, 2, mtRecordResponse.getMaintenanceAdvice() != null ? mtRecordResponse.getMaintenanceAdvice() : "", false);
|