diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java
index 800f911..df269e3 100644
--- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java
+++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java
@@ -37,19 +37,7 @@ public class RehearsalExportDTO {
@ExcelProperty(value = "演练地点", index = 4)
private String location;
- @ApiModelProperty("参演人数")
- @ExcelProperty(value = "参演人数", index = 5)
- private Integer peopleNum;
-
- @ApiModelProperty("演练实际开始时间")
- @ExcelProperty(value = "演练实际开始时间", index = 6)
- private Date actualStartTime;
-
- @ApiModelProperty("演练实际结束时间")
- @ExcelProperty(value = "演练实际结束时间", index = 7)
- private Date actualEndTime;
-
@ApiModelProperty("演练状态")
- @ExcelProperty(value = "演练状态", index = 8)
+ @ExcelProperty(value = "演练状态", index = 5)
private String rehearsalStatus;
}
diff --git a/hzims-service/safeproduct/pom.xml b/hzims-service/safeproduct/pom.xml
index a048dd1..cfede4f 100644
--- a/hzims-service/safeproduct/pom.xml
+++ b/hzims-service/safeproduct/pom.xml
@@ -160,6 +160,14 @@
false
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ true
+
+
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java
index 20ce27e..88779d5 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java
@@ -120,7 +120,6 @@ public class CarController extends BladeController {
@GetMapping("/carMaintenancePage")
@ApiImplicitParams({
- @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "carId", value = "车辆id", dataType = "query", paramType = "string")
@@ -169,7 +168,6 @@ public class CarController extends BladeController {
@GetMapping("/carUsedRecordPage")
@ApiImplicitParams({
- @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "carId", value = "车辆id", dataType = "query", paramType = "string")
})
@ApiOperation(value = "用车记录分页")
@@ -244,14 +242,14 @@ public class CarController extends BladeController {
@GetMapping("/exportCarUsedRecordData")
@ApiOperation(value = "导出用车记录单")
@ApiOperationSupport(order = 25)
- public void exportCarUsedRecordData() {
-
+ public void exportCarUsedRecordData(@RequestParam Long id, HttpServletResponse response) {
+ carUsedRecordService.exportCarUsedRecordData(id, response);
}
@GetMapping("/exportCarCheckRecordData")
@ApiOperation(value = "导出车检记录单")
@ApiOperationSupport(order = 26)
- public void exportCarCheckRecordData() {
-
+ public void exportCarCheckRecordData(@RequestParam Long id, HttpServletResponse response) {
+ carCheckRecordService.exportCarCheckRecordData(id, response);
}
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java
index 86c7e55..93132b0 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/CarJob.java
@@ -1,12 +1,18 @@
package com.hnac.hzims.safeproduct.jobs;
+import com.alibaba.excel.util.CollectionUtils;
import com.hnac.hzims.safeproduct.entity.CarEntity;
+import com.hnac.hzims.safeproduct.entity.CarMaintenanceEntity;
+import com.hnac.hzims.safeproduct.enums.CarInsuranceStatusEnum;
+import com.hnac.hzims.safeproduct.enums.CarMaintenanceStatusEnum;
+import com.hnac.hzims.safeproduct.service.ICarMaintenanceService;
import com.hnac.hzims.safeproduct.service.ICarService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@@ -23,9 +29,13 @@ public class CarJob {
@Autowired
ICarService carService;
+ @Autowired
+ ICarMaintenanceService carMaintenanceService;
+
/**
* 车辆台账自动变更
*/
+ @Transactional(rollbackFor = Exception.class)
@XxlJob("autoChangeCarStatus")
public ReturnT autoChangeCarStatus(String param) {
// 获取时间范围
@@ -33,9 +43,26 @@ public class CarJob {
Date before = DateUtil.minusDays(current, 1);
String today = DateUtil.format(current, "yyyy-mm-dd");
String yesterday = DateUtil.format(before, "yyyy-mm-dd");
+ // 车包状态变更
List uninsuredCarList = carService.getCarListByInsuranceTime(today, yesterday);
-// uninsuredCarList.forEach(car -> car.setInsuranceStatus());
-// List carListByMaintenanceTime = carService.getCarListByMaintenanceTime(today, yesterday);
- return ReturnT.SUCCESS;
+ uninsuredCarList.forEach(car -> car.setInsuranceStatus(CarInsuranceStatusEnum.UNINSURED.getValue()));
+ boolean insuranceUpdate = carService.updateBatchById(uninsuredCarList);
+ if (!insuranceUpdate) {
+ return ReturnT.FAIL;
+ }
+ // 维保状态变更
+ List unMaintainedCarList = carService.getCarListByMaintenanceTime(today, yesterday);
+ unMaintainedCarList.forEach(car -> {
+ // 查询车辆在两次维保时间内是否有确认过的维保记录
+ String lastMaintenanceTime = DateUtil.format(car.getMaintenanceLastTime(), "yyyy-mm-dd");
+ String nextMaintenanceTime = DateUtil.format(car.getMaintenanceNextTime(), "yyyy-mm-dd");
+ List carMaintenanceList = carMaintenanceService.getCarMaintenanceByCarIdAndTime(car.getId(),
+ lastMaintenanceTime, nextMaintenanceTime);
+ // 若无维保记录,说明在规定范围内未进行有效维保
+ if (CollectionUtils.isEmpty(carMaintenanceList)) {
+ car.setMaintenanceStatus(CarMaintenanceStatusEnum.UNMAINTAINED.getValue());
+ }
+ });
+ return carService.updateBatchById(unMaintainedCarList) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml
index 0122ec9..695be59 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml
@@ -44,7 +44,7 @@
\ No newline at end of file
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml
index 38b8ac3..8ff4810 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml
@@ -73,23 +73,21 @@
\ No newline at end of file
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckRecordService.java
index e9dfc26..0e734d5 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckRecordService.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckRecordService.java
@@ -8,6 +8,7 @@ import com.hnac.hzims.safeproduct.vo.CarCheckRecordDetailVO;
import com.hnac.hzims.safeproduct.vo.CarCheckRecordPageVO;
import org.springblade.core.mp.support.Query;
+import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
@@ -60,4 +61,11 @@ public interface ICarCheckRecordService extends IService {
* @return true-成功,false-失败
*/
boolean removeCarCheckRecord(Long id);
+
+ /**
+ * 导出车检记录单
+ * @param id 车检记录id
+ * @param response 响应类
+ */
+ void exportCarCheckRecordData(Long id, HttpServletResponse response);
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarMaintenanceService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarMaintenanceService.java
index a925669..dcccb68 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarMaintenanceService.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarMaintenanceService.java
@@ -10,6 +10,7 @@ import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import javax.servlet.http.HttpServletResponse;
+import java.util.List;
import java.util.Map;
/**
@@ -55,4 +56,13 @@ public interface ICarMaintenanceService extends IService {
* @param response 响应类
*/
void exportCarMaintenanceData(Long id, HttpServletResponse response);
+
+ /**
+ * 根据车辆id和时间查询相关维保记录
+ * @param carId 车辆id
+ * @param lastTime 上次维保时间
+ * @param nextTime 下次维保时间
+ * @return 车辆维保记录列表
+ */
+ List getCarMaintenanceByCarIdAndTime(Long carId, String lastTime, String nextTime);
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java
index ce6daed..e25b6d6 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java
@@ -32,4 +32,12 @@ public interface ICarService extends IService {
* @return 车辆列表数据
*/
List getCarListByInsuranceTime(String today, String yesterday);
+
+ /**
+ * 根据维保时间查询车辆列表
+ * @param today 当天
+ * @param yesterday 昨天
+ * @return 车辆列表数据
+ */
+ List getCarListByMaintenanceTime(String today, String yesterday);
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarUsedRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarUsedRecordService.java
index 53af9f1..3e849ab 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarUsedRecordService.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarUsedRecordService.java
@@ -9,6 +9,7 @@ import com.hnac.hzims.safeproduct.vo.CarUsedRecordPageVO;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
+import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
@@ -54,4 +55,11 @@ public interface ICarUsedRecordService extends IService {
* @return true-成功,false-失败
*/
boolean updateCarUsedRecord(CarUsedRecordEntity carUsedRecordEntity);
+
+ /**
+ * 导出用车记录单
+ * @param id 用车记录id
+ * @param response 响应类
+ */
+ void exportCarUsedRecordData(Long id, HttpServletResponse response);
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java
index 5e6db20..4f69d47 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java
@@ -15,18 +15,18 @@ import com.hnac.hzims.safeproduct.mapper.CarMapper;
import com.hnac.hzims.safeproduct.service.ICarCheckItemService;
import com.hnac.hzims.safeproduct.service.ICarCheckRecordService;
import com.hnac.hzims.safeproduct.utils.BaseUtil;
-import com.hnac.hzims.safeproduct.vo.CarCheckItemVO;
import com.hnac.hzims.safeproduct.vo.CarCheckRecordDetailVO;
import com.hnac.hzims.safeproduct.vo.CarCheckRecordPageVO;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -46,6 +46,9 @@ public class CarCheckRecordServiceImpl extends ServiceImpl params = BaseUtil.obj2Map(carCheckRecordEntity);
+ String templateFile = "template/车检记录单.docx";
+ String wordPath = savePath + "/车检记录单.docx";
+ String pdfPath = savePath + "/车检记录单.pdf";
+ BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
+ }
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java
index 79836c5..b3001f4 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java
@@ -1,10 +1,7 @@
package com.hnac.hzims.safeproduct.service.impl;
import cn.hutool.core.date.DatePattern;
-import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.util.CollectionUtils;
-import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -19,23 +16,15 @@ import com.hnac.hzims.safeproduct.service.ICarService;
import com.hnac.hzims.safeproduct.utils.BaseUtil;
import com.hnac.hzims.safeproduct.vo.CarMaintenanceDetailVO;
import com.hnac.hzims.safeproduct.vo.CarMaintenancePageVO;
-import com.hnac.hzims.ticket.constants.WorkTicketConstants;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
-import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -52,6 +41,9 @@ public class CarMaintenanceServiceImpl extends ServiceImpl params = BaseUtil.convertObjectToMap(carMaintenanceEntity);
-// String templateFile = ""
- try {
- List res = new ArrayList<>();
- XWPFDocument document = BaseUtil.fillDocument("template/", params);
- res.add(document);
- BaseUtil.exportWord(res, "");
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-// String pdfPath = this.getFileSavePath() + params.get("code") + "_" + params.get("addressEquName") +".pdf";
-// AsposeUtil.wordToPdf(wordPath, pdfPath);
-// PdfUtils.readPdf(response,pdfPath);
-// ServletOutputStream outputStream = null;
-// try {
-// outputStream = response.getOutputStream();
-// CarMaintenanceDetailVO carMaintenance = getCarMaintenance(id);
-// // 设置响应头
-// // URLEncoder.encode防止中文乱码
-// String fileName = URLEncoder.encode("车辆维保记录单", "UTF-8");
-// response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
-// response.setContentType("application/vnd.ms-excel");
-// response.setCharacterEncoding("UTF-8");
-// List dataList = new ArrayList<>();
-// dataList.add(carMaintenance);
-// String templatePath = "template/车辆维保记录单.xlsx";
-// Resource resource = new ClassPathResource(templatePath);
-// // ExcelWriter初始化
-// ExcelWriter excelWriter = EasyExcel
-// .write(response.getOutputStream(), CarMaintenanceDetailVO.class)
-// .autoCloseStream(Boolean.TRUE)
-// .withTemplate(resource.getInputStream())
-// .build();
-// WriteSheet writeSheet = EasyExcel.writerSheet(1, "车辆维保记录单").build();
-// excelWriter.write(dataList, writeSheet);
-// excelWriter.finish();
-// } catch (Exception e) {
-// // 重置response
-// response.reset();
-// response.setContentType("application/json");
-// response.setCharacterEncoding("utf-8");
-// throw new ServiceException("车辆维保记录单导出异常: " + e.getMessage());
-// } finally {
-// if (outputStream != null) {
-// try {
-// outputStream.close();
-// } catch (IOException e) {
-// log.error("车辆维保记录单导出响应头输出流关闭异常: " + e.getMessage());
-// }
-// }
-// }
+ Map params = BaseUtil.obj2Map(carMaintenanceEntity);
+ String templateFile = "template/车辆维保记录单.docx";
+ String wordPath = savePath + "/车辆维保记录单.docx";
+ String pdfPath = savePath + "/车辆维保记录单.pdf";
+ BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
+ }
+
+ /**
+ * 根据车辆id和时间查询相关维保记录
+ */
+ @Override
+ public List getCarMaintenanceByCarIdAndTime(Long carId, String lastTime, String nextTime) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.lambda().eq(CarMaintenanceEntity::getCarId, carId)
+ .ge(CarMaintenanceEntity::getEndTime, lastTime)
+ .le(CarMaintenanceEntity::getEndTime, nextTime)
+ .eq(CarMaintenanceEntity::getMaintenanceStatus, CarMaintenanceStatusEnum.MAINTAINED.getValue())
+ .orderByDesc(CarMaintenanceEntity::getCreateTime);
+ return this.list(queryWrapper);
}
/**
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java
index d9e8adf..376c288 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java
@@ -110,8 +110,19 @@ public class CarServiceImpl extends ServiceImpl implements
@Override
public List getCarListByInsuranceTime(String today, String yesterday) {
QueryWrapper queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().le(CarEntity::getInsurancePayLastTime, today)
- .ge(CarEntity::getInsurancePayNextTime, today);
+ queryWrapper.lambda().lt(CarEntity::getInsurancePayNextTime, today)
+ .ge(CarEntity::getInsurancePayNextTime, yesterday);
+ return this.list(queryWrapper);
+ }
+
+ /**
+ * 根据维保时间查询车辆列表
+ */
+ @Override
+ public List getCarListByMaintenanceTime(String today, String yesterday) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.lambda().lt(CarEntity::getMaintenanceNextTime, today)
+ .ge(CarEntity::getMaintenanceNextTime, yesterday);
return this.list(queryWrapper);
}
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java
index d8f2295..b2bcfd6 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java
@@ -11,15 +11,20 @@ import com.hnac.hzims.safeproduct.entity.CarUsedRecordEntity;
import com.hnac.hzims.safeproduct.enums.CarUsedRecordEnum;
import com.hnac.hzims.safeproduct.mapper.CarUsedRecordMapper;
import com.hnac.hzims.safeproduct.service.ICarUsedRecordService;
+import com.hnac.hzims.safeproduct.utils.AsposeUtil;
import com.hnac.hzims.safeproduct.utils.BaseUtil;
import com.hnac.hzims.safeproduct.vo.CarUsedRecordDetailVO;
import com.hnac.hzims.safeproduct.vo.CarUsedRecordPageVO;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -33,6 +38,9 @@ import java.util.Map;
@Service
public class CarUsedRecordServiceImpl extends ServiceImpl implements ICarUsedRecordService {
+ @Value("${hzims.car.savePath}")
+ private String savePath;
+
/**
* 新增用车记录
*/
@@ -98,6 +106,19 @@ public class CarUsedRecordServiceImpl extends ServiceImpl params = BaseUtil.obj2Map(carUsedRecordEntity);
+ String templateFile = "template/用车记录单.docx";
+ String wordPath = savePath + "/用车记录单.docx";
+ String pdfPath = savePath + "/用车记录单.pdf";
+ BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
+ }
+
+ /**
* 查询是否存在同月编号
* @param currentMonth 当月
* @return 存在则返回上一编号,否则返回null
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java
index 9df05c4..eeaa00a 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java
@@ -51,12 +51,13 @@ public class TestServiceImpl extends ServiceImpl impleme
if (trainPlanEntity.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_NO_TEST)) {
return R.fail("该培训计划无法新增考试");
}
- // 获取当月时间(yyyymm)
- String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date());
+ // 获取当月时间
+ String currentNormMonth = DatePattern.NORM_MONTH_FORMAT.format(new Date());
+ String currentSimpleMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date());
// 查询是否存在同月编号
- String lastCode = getLastCode(currentMonth);
+ String lastCode = getLastCode(currentNormMonth);
// 若不存在,新增编号
- String code = BaseUtil.getUniqueCode("KSJL", lastCode, currentMonth);
+ String code = BaseUtil.getUniqueCode("KSJL", lastCode, currentSimpleMonth);
testEntity.setCode(code);
boolean saveTest = this.save(testEntity);
// 若新增考试记录成功,添加相关的参考人员数据
@@ -195,8 +196,7 @@ public class TestServiceImpl extends ServiceImpl impleme
* @return 存在则返回上一编号,否则返回null
*/
private String getLastCode(String currentMonth) {
- String month = currentMonth.substring(currentMonth.length() - 2);
- List list = getTestByMonth(month);
+ List list = getTestByMonth(currentMonth);
if (CollectionUtils.isEmpty(list)) {
return null;
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java
index 3405311..c2312e4 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java
@@ -56,12 +56,13 @@ public class TrainRecordServiceImpl extends ServiceImpl list = getTrainByMonth(month);
+ List list = getTrainByMonth(currentMonth);
if (CollectionUtils.isEmpty(list)) {
return null;
}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/AsposeUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/AsposeUtil.java
new file mode 100644
index 0000000..43295f3
--- /dev/null
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/AsposeUtil.java
@@ -0,0 +1,53 @@
+package com.hnac.hzims.safeproduct.utils;
+
+import cn.hutool.system.SystemUtil;
+import com.aspose.words.Document;
+import com.aspose.words.FontSettings;
+import com.aspose.words.License;
+import com.aspose.words.SaveFormat;
+import lombok.SneakyThrows;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+
+/**
+ *
+ */
+public class AsposeUtil {
+
+ /**
+ * 加载license 用于破解 不生成水印
+ *
+ * @author LCheng
+ * @date 2020/12/25 13:51
+ */
+ @SneakyThrows
+ private static void getLicense() {
+ try (InputStream is = AsposeUtil.class.getClassLoader().getResourceAsStream("License.xml")) {
+ License license = new License();
+ license.setLicense(is);
+ }
+ }
+
+ /**
+ * word转pdf
+ *
+ * @param wordPath word文件保存的路径
+ * @param pdfPath 转换后pdf文件保存的路径
+ * @author LCheng
+ * @date 2020/12/25 13:51
+ */
+ @SneakyThrows
+ public static void wordToPdf(String wordPath, String pdfPath) {
+ getLicense();
+ File file = new File(pdfPath);
+ try (FileOutputStream os = new FileOutputStream(file)) {
+ if(SystemUtil.getOsInfo().isLinux()) {
+ FontSettings.setFontsFolder("/usr/share/fonts/chinese", true);
+ }
+ Document doc = new Document(wordPath);
+ doc.save(os, SaveFormat.PDF);
+ }
+ }
+}
diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java
index e36ac90..2f26680 100644
--- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java
+++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java
@@ -2,16 +2,21 @@ package com.hnac.hzims.safeproduct.utils;
import cn.afterturn.easypoi.word.WordExportUtil;
import com.hnac.hzims.common.logs.utils.StringUtils;
+import com.hnac.hzims.ticket.annotation.DateTimeToMap;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.core.tool.utils.ObjectUtil;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 公用工具类
@@ -50,26 +55,6 @@ public class BaseUtil {
}
/**
- * 对象转map
- * @param entity 对象
- * @return map
- */
- public static Map convertObjectToMap(Object entity) {
- Map map = new HashMap<>();
- Field[] fields = entity.getClass().getFields();
- try {
- for (Field field : fields) {
- field.setAccessible(true);
- Object value = field.get(entity);
- map.put(field.getName(), value);
- }
- } catch (IllegalAccessException e) {
- log.info("对象转map异常: {}", e.getMessage());
- }
- return map;
- }
-
- /**
* 文件导出
* @param documents doc文件
* @param savePath 存储路径
@@ -81,7 +66,6 @@ public class BaseUtil {
for (XWPFDocument document : documents) {
document.write(out);
}
- out.close();
} catch (IOException e) {
log.error("文件导出异常: {}", e.getMessage());
} finally {
@@ -109,4 +93,125 @@ public class BaseUtil {
}
return xwpfDocument;
}
+
+ /**
+ * 读取本地pdf,这里设置的是预览
+ * @param response 响应类
+ * @param filePath 文件路径
+ */
+ public static void readPdf(HttpServletResponse response, String filePath) {
+ response.reset();
+ response.setContentType("application/pdf");
+ FileInputStream fileInputStream = null;
+ OutputStream outputStream = null;
+ try {
+ File file = new File(filePath);
+ fileInputStream = new FileInputStream(file);
+ outputStream = response.getOutputStream();
+ IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream);
+ response.setHeader("Content-Disposition",
+ "inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8"));
+ outputStream.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (fileInputStream != null) {
+ fileInputStream.close();
+ }
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static Map obj2Map(Object obj) {
+ if(ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) {
+ Map result = new HashMap<>();
+ List fieldList = new ArrayList<>();
+ Class> clazz = obj.getClass();
+ while(clazz != null) {
+ fieldList.addAll(Arrays.asList(clazz.getDeclaredFields()));
+ clazz = clazz.getSuperclass();
+ }
+ fieldList.forEach(field -> {
+ field.setAccessible(true);
+ Object value;
+ try {
+ value = field.get(obj);
+ } catch (IllegalAccessException e) {
+ throw new ServiceException("获取属性性出错");
+ }
+ if(value instanceof List) {
+ List