|
|
@ -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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|