Browse Source

update: 车辆管理添加年度历程数据导出

zhongwei
liwen 10 months ago
parent
commit
11e3b2d097
  1. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java
  2. 10
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java
  3. 59
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

7
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java

@ -252,4 +252,11 @@ public class CarController extends BladeController {
public void exportCarCheckRecordData(@RequestParam Long id, HttpServletResponse response) { public void exportCarCheckRecordData(@RequestParam Long id, HttpServletResponse response) {
carCheckRecordService.exportCarCheckRecordData(id, response); carCheckRecordService.exportCarCheckRecordData(id, response);
} }
@GetMapping("/exportCarMilesData")
@ApiOperation(value = "导出年度里程数据")
@ApiOperationSupport(order = 27)
public void exportCarMilesData(@ApiIgnore @RequestParam Map<String, Object> param, Query query, HttpServletResponse response) {
carService.exportCarMilesData(param, query, response);
}
} }

10
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java

@ -7,7 +7,9 @@ import com.hnac.hzims.safeproduct.vo.CarMilesYearVO;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 车辆管理服务类 * 车辆管理服务类
@ -62,4 +64,12 @@ public interface ICarService extends IService<CarEntity> {
* @return true-成功false-失败 * @return true-成功false-失败
*/ */
boolean removeCar(Long id); boolean removeCar(Long id);
/**
* 导出年度里程数据
* @param param 参数
* @param query 分页类
* @param response 响应类
*/
void exportCarMilesData(Map<String, Object> param, Query query, HttpServletResponse response);
} }

59
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

@ -1,17 +1,25 @@
package com.hnac.hzims.safeproduct.service.impl; package com.hnac.hzims.safeproduct.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.converters.longconverter.LongStringConverter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.safeproduct.dto.CarMilesYearDTO; import com.hnac.hzims.safeproduct.dto.CarMilesYearDTO;
import com.hnac.hzims.safeproduct.dto.RehearsalExportDTO;
import com.hnac.hzims.safeproduct.entity.CarEntity; import com.hnac.hzims.safeproduct.entity.CarEntity;
import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum;
import com.hnac.hzims.safeproduct.mapper.CarMapper; import com.hnac.hzims.safeproduct.mapper.CarMapper;
import com.hnac.hzims.safeproduct.service.ICarCheckRecordService; import com.hnac.hzims.safeproduct.service.ICarCheckRecordService;
import com.hnac.hzims.safeproduct.service.ICarMaintenanceService; import com.hnac.hzims.safeproduct.service.ICarMaintenanceService;
import com.hnac.hzims.safeproduct.service.ICarService; import com.hnac.hzims.safeproduct.service.ICarService;
import com.hnac.hzims.safeproduct.service.ICarUsedRecordService; import com.hnac.hzims.safeproduct.service.ICarUsedRecordService;
import com.hnac.hzims.safeproduct.vo.CarMilesYearVO; import com.hnac.hzims.safeproduct.vo.CarMilesYearVO;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -19,9 +27,14 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -194,4 +207,50 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
} }
return false; return false;
} }
/**
* 导出年度里程数据
*/
@Override
public void exportCarMilesData(Map<String, Object> param, Query query, HttpServletResponse response) {
ServletOutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
String unit = String.valueOf(param.get("unit"));
String year = String.valueOf(param.get("year"));
IPage<CarMilesYearVO> page = milesDataByYear(year, unit, query);
List<CarMilesYearVO> list = page.getRecords();
// 设置响应头
// 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");
// ExcelWriter初始化
ExcelWriter excelWriter = EasyExcel
.write(response.getOutputStream())
.autoCloseStream(Boolean.TRUE)
.registerConverter(new LongStringConverter())
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(25))
.build();
WriteSheet writeSheet = EasyExcel.writerSheet(1, "年度里程统计表").head(CarMilesYearVO.class)
.build();
excelWriter.write(list, 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());
}
}
}
}
} }

Loading…
Cancel
Save