Commit a0bd0338 authored by hezhuozhi's avatar hezhuozhi

优化统计bug

parent 3aa5da0e
...@@ -7,7 +7,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; ...@@ -7,7 +7,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -69,6 +69,45 @@ public class ExcelUtils { ...@@ -69,6 +69,45 @@ public class ExcelUtils {
/** /**
* excel 导出 * excel 导出
* *
* @param list 数据
* @param title 标题
* @param sheetName sheet名称
* @param pojoClass pojo类型
* @param fileName 文件名称
* @param response
*/
public static void exportExcelDefaultGroundColor(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
HttpServletResponse response) {
ExportParams exportParams = new ExportParams(title, sheetName);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, list);
if (workbook != null) {
// 设置表头样式
Sheet sheet = workbook.getSheetAt(0);
Row headerRow = sheet.getRow(0);
if (headerRow != null) {
CellStyle headerStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true); // 加粗
headerStyle.setFont(font);
headerStyle.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex()); // 背景色
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 填充模式
// 设置居中对齐
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 设置表头每个单元格的样式
for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) {
Cell cell = headerRow.getCell(i);
if (cell != null) {
cell.setCellStyle(headerStyle);
}
}
}
downLoadExcel(fileName, response, workbook);
}
}
/**
* excel 导出
*
* @param list 数据 * @param list 数据
* @param fileName 文件名称 * @param fileName 文件名称
* @param response * @param response
......
...@@ -198,13 +198,12 @@ on hygf_document_station.preparation_money_id=hygf_preparation_money.sequence_nb ...@@ -198,13 +198,12 @@ on hygf_document_station.preparation_money_id=hygf_preparation_money.sequence_nb
hpsei.real_scale, hpsei.real_scale,
substring_index ( hph.project_address_name, '/', 1 ) AS province, substring_index ( hph.project_address_name, '/', 1 ) AS province,
hph.regional_companies_name, hph.regional_companies_name,
sub.real_name AS serviceAgent hph.developer_name AS serviceAgent
FROM FROM
hygf_peasant_household hph hygf_peasant_household hph
LEFT JOIN hygf_commercial hc ON hc.survey_information_id = hph.survey_information_id LEFT JOIN hygf_commercial hc ON hc.survey_information_id = hph.survey_information_id
LEFT JOIN hygf_work_order_power_station hwops ON hph.sequence_nbr = hwops.peasant_household_id LEFT JOIN hygf_work_order_power_station hwops ON hph.sequence_nbr = hwops.peasant_household_id
LEFT JOIN hygf_power_station_engineering_info hpsei ON hwops.sequence_nbr = hpsei.work_order_power_station_id LEFT JOIN hygf_power_station_engineering_info hpsei ON hwops.sequence_nbr = hpsei.work_order_power_station_id
LEFT JOIN std_user_biz sub ON sub.amos_user_id =hph.developer_user_id
<where> <where>
<if test="statisticsDto.ownersName!=null and statisticsDto.ownersName !=''"> <if test="statisticsDto.ownersName!=null and statisticsDto.ownersName !=''">
and hph.owners_name like concat ('%',#{statisticsDto.ownersName},'%') and hph.owners_name like concat ('%',#{statisticsDto.ownersName},'%')
...@@ -216,7 +215,7 @@ on hygf_document_station.preparation_money_id=hygf_preparation_money.sequence_nb ...@@ -216,7 +215,7 @@ on hygf_document_station.preparation_money_id=hygf_preparation_money.sequence_nb
and hph.regional_companies_name like concat ('%',#{statisticsDto.regionalCompaniesName},'%') and hph.regional_companies_name like concat ('%',#{statisticsDto.regionalCompaniesName},'%')
</if> </if>
<if test="statisticsDto.serviceAgent!=null and statisticsDto.serviceAgent !=''"> <if test="statisticsDto.serviceAgent!=null and statisticsDto.serviceAgent !=''">
and sub.real_name like concat ('%',#{statisticsDto.serviceAgent},'%') and hph.developer_name like concat ('%',#{statisticsDto.serviceAgent},'%')
</if> </if>
</where> </where>
ORDER BY hph.rec_date DESC ,hph.sequence_nbr DESC ORDER BY hph.rec_date DESC ,hph.sequence_nbr DESC
......
...@@ -302,7 +302,7 @@ public class PowerStationStatisticsServiceImpl { ...@@ -302,7 +302,7 @@ public class PowerStationStatisticsServiceImpl {
excelVO.setFhbhEndTime(DateUtils.dateFormat(statisticsDto.getFhbhEndTime(), DateUtils.DATE_TIME_PATTERN)); excelVO.setFhbhEndTime(DateUtils.dateFormat(statisticsDto.getFhbhEndTime(), DateUtils.DATE_TIME_PATTERN));
dataList.add(excelVO); dataList.add(excelVO);
} }
ExcelUtils.exportExcel(dataList, null, "电站时间统计", PowerStationTimeStatisticsExcelVO.class, "电站时间统计" + DateUtils.dateFormat(new Date(), "YYYY-MM-dd-HH-mm") + ".xlsx", response); ExcelUtils.exportExcelDefaultGroundColor(dataList, null, "电站时间统计", PowerStationTimeStatisticsExcelVO.class, "电站时间统计" + DateUtils.dateFormat(new Date(), "YYYY-MM-dd-HH-mm") + ".xlsx", response);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new BadRequest("导出失败,失败原因[" + e.getMessage() + "]"); throw new BadRequest("导出失败,失败原因[" + e.getMessage() + "]");
......
...@@ -17,11 +17,11 @@ public class PowerStationTimeStatisticsExcelVO implements Serializable { ...@@ -17,11 +17,11 @@ public class PowerStationTimeStatisticsExcelVO implements Serializable {
@ApiModelProperty(value = "电站名称") @ApiModelProperty(value = "电站名称")
private String ownersName; private String ownersName;
@Excel(name = "电站安装规模(KW)", width = 30, orderNum = "2") @Excel(name = "电站安装规模(kW)", width = 30, orderNum = "2")
@ApiModelProperty(value = "电站安装规模") @ApiModelProperty(value = "电站安装规模")
private String scale; private String scale;
@Excel(name = "电站实际规模(KW)", width = 30, orderNum = "3") @Excel(name = "电站实际规模(kW)", width = 30, orderNum = "3")
@ApiModelProperty(value = "电站实际规模") @ApiModelProperty(value = "电站实际规模")
private String realScale; private String realScale;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment