Java导出合并单元格
作者:互联网
Java导出合并单元格
1、 要求单元格格式:
2、详细代码
public class MyElectricAccountingBiz extends BaseBiz<MyElectricAccountingMapper, MyElectricAccounting> {
/**
* @version:v1.0.1
*/
public HashDto getRefrigerationList(Dto dto) {
List<HashDto> list = mapper.getAllRefrigeration(dto);
Map<String, String> hashMap = Maps.newHashMap();
List<HashDto> allElectricityData = mapper.getAllElectricityData(dto);
//获取页面传递的开始时间和结束时间
String startTime = dto.getString("startTime");
String endTime = dto.getString("endTime");
//获取两个时间之间的所有日期的集合,同时添加到map集合中
List<String> betweenTimeList = getBetweenTime(startTime, endTime, hashMap);
Map<String, Map<String, String>> collect = null;
if (CollectionUtil.isNotEmpty(hashMap)) {
collect = allElectricityData.stream().collect(Collectors.groupingBy
(e -> e.getString("instrumentName"), Collectors.toMap(e -> e.getString("readDate"),
e -> e.getString("consumeValue"), (key1, key2) -> key1)));
}
//处理list中的map集合
List<HashDto> refrigerationMergeNum = mapper.getRefrigerationMergeNum(dto);
List<HashDto> refrigerationMergeInfo = mapper.getRefrigerationMergeInfo(dto);
handleMapOfList(dto, list, hashMap, collect, refrigerationMergeNum, refrigerationMergeInfo, betweenTimeList);
HashDto hashDto = new HashDto();
//将时间的集合放进map集合
hashDto.put("dateList", betweenTimeList);
//将数据的集合放进map集合
hashDto.put("dataList", list);
return hashDto;
}
/**
* @version:v1.0.1
*/
public ObjectRestResponse exportAmmoniaData(Dto dto, HttpServletResponse response) {
HashDto refrigerationList = this.getRefrigerationList(dto);
List<HashDto> list = (List<HashDto>) refrigerationList.getList("dataList");
//处理表头
List<String> dateList = (List<String>) refrigerationList.getList("dateList");
List<String> headList = Lists.newArrayList("核算主体", "核算明细", "仪表名称", "制冷机房名称");
//处理数据
Map<Integer, String> headMap = new HashMap<>();
headMap.put(0, "accountingSubject");
headMap.put(1, "accountingWorkshop");
headMap.put(2, "instrumentName");
headMap.put(3, "refrigerationName");
for (int i = 0; i < dateList.size(); i++) {
headList.add(dateList.get(i));
headMap.put(4 + i, dateList.get(i));
}
headList.add("总计(kw/h)");
headMap.put(headList.size() - 1, "colTotal");
List<HashDto> mergeNum = mapper.getRefrigerationMergeNum(dto);
String titleName = "";
String startTime = dto.getString("startTime");
String endTime = dto.getString("endTime");
if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
titleName = "制冷机房的电表数据(" + startTime + " - " + endTime + ")";
} else {
titleName = "制冷机房的电表数据(总消耗)";
}
exportMergeExcel(response, list, headList, headMap, mergeNum,
"氨压机", titleName, "制冷机房的电能消耗.xls");
return new ObjectRestResponse().rel(true).message("导出成功!");
}
/**
* @version:v1.0.1
*/
public HashDto getEvaporatorData(Dto dto) {
List<HashDto> list = mapper.getAllEvaporatorName(dto);
Map<String, String> hashMap = Maps.newHashMap();
//获取页面传递的开始时间和结束时间
String startTime = dto.getString("startTime");
String endTime = dto.getString("endTime");
//获取两个时间之间的所有日期的集合,同时添加到map集合中
List<String> betweenTimeList = getBetweenTime(startTime, endTime, hashMap);
List<HashDto> allElectricityData = mapper.getAllElectricityData(dto);
Map<String, Map<String, String>> collect = allElectricityData.stream().collect(Collectors.groupingBy
(e -> e.getString("instrumentName"), Collectors.toMap(e -> e.getString("readDate"),
e -> e.getString("consumeValue"), (key1, key2) -> key1)));
//处理list中的map集合
List<HashDto> evaporatorMergeNum = mapper.getEvaporatorMergeNum(dto);
List<HashDto> evaporatorMergeInfo = mapper.getEvaporatorMergeInfo(dto);
handleMapOfList(dto, list, hashMap, collect, evaporatorMergeNum, evaporatorMergeInfo, betweenTimeList);
HashDto hashDto = new HashDto();
//将时间的集合放进map集合
hashDto.put("dateList", betweenTimeList);
//将数据的集合放进map集合
hashDto.put("dataList", list);
return hashDto;
}
/**
* @version:v1.0.1
*/
public ObjectRestResponse exportEvaporatorData(Dto dto, HttpServletResponse response) {
HashDto evaporatorData = this.getEvaporatorData(dto);
List<HashDto> list = (List<HashDto>) evaporatorData.getList("dataList");
//处理表头
List<String> dateList = (List<String>) evaporatorData.getList("dateList");
List<String> headList = Lists.newArrayList("核算主体", "核算明细", "仪表名称", "蒸发器名称", "配电柜名称");
//创建map集合顺序存放对应的字段名
Map<Integer, String> headMap = new HashMap<>();
headMap.put(0, "accountingSubject");
headMap.put(1, "accountingWorkshop");
headMap.put(2, "instrumentName");
headMap.put(3, "evaporatorName");
headMap.put(4, "distributionCabinetName");
for (int i = 0; i < dateList.size(); i++) {
headList.add(dateList.get(i));
headMap.put(5 + i, dateList.get(i));
}
headList.add("总计(kw/h)");
headMap.put(headList.size() - 1, "colTotal");
List<HashDto> mergeNum = mapper.getEvaporatorMergeNum(dto);
String titleName = "";
String startTime = dto.getString("startTime");
String endTime = dto.getString("endTime");
if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
titleName = "蒸发器的电表数据(" + startTime + " - " + endTime + ")";
} else {
titleName = "蒸发器的电表数据(总消耗)";
}
exportMergeExcel(response, list, headList, headMap, mergeNum,
"蒸发器", titleName, "蒸发器的电能消耗.xls");
return new ObjectRestResponse().rel(true).message("导出成功!");
}
/**
* @version:v1.0.1
*/
private void exportMergeExcel(HttpServletResponse response,
List<HashDto> list,
List<String> headList,
Map<Integer, String> headMap,
List<HashDto> hashDtos,
String sheetName,
String titleName,
String fileName) {
/* List<HashDto> list 原始数据
* List<String> headList 表头数据
* Map<Integer, String> headMap 表头对应
* List<HashDto> hashDtos 合并的数据
* */
String headStr = headMap.get(3);
int lastCol = 3;
if (!headStr.equals("refrigerationName")) {
lastCol = 4;
}
//创建工作簿对象
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(sheetName);
//设置列宽
sheet.setColumnWidth(0, 3000);
sheet.setColumnWidth(1, 5500);
sheet.setColumnWidth(2, 4000);
if (headStr.equals("refrigerationName")) {
sheet.setColumnWidth(3, 6000);
} else {
sheet.setColumnWidth(3, 13000);
}
if (lastCol == 4) {
sheet.setColumnWidth(lastCol, 9500);
}
for (int i = lastCol + 1; i < headList.size() - 1; i++) {
sheet.setColumnWidth(i, 2800);
}
sheet.setColumnWidth(headList.size() - 1, 5000);
HSSFRow firstRow = sheet.createRow(0);
//行高设置成460px
firstRow.setHeight((short) 460);
CellRangeAddress region = new CellRangeAddress(0, 0, (short) 0, (short) headList.size() - 1); //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列
sheet.addMergedRegion(region);
HSSFCell firstRowCell = firstRow.createCell(0);
firstRowCell.setCellValue(titleName);
//添加标题样式
HSSFCellStyle titleCellStyle = workbook.createCellStyle();
//设置居中
titleCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//设置字体大小
HSSFFont font = workbook.createFont();
font.setFontName("仿宋_GB2312");
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
font.setFontHeightInPoints((short) 15); //字体大小
titleCellStyle.setFont(font);//选择需要用到的字体格式
//设置第一行样式
firstRowCell.setCellStyle(titleCellStyle);
//创建全局样式
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//添加边框
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
//创建标题行
HSSFRow headRow = sheet.createRow(1);
//行高设置成360px
headRow.setHeight((short) 360);
for (int i = 0; i < headList.size(); i++) {
HSSFCell headRowCell = headRow.createCell(i);
headRowCell.setCellValue(headList.get(i));
headRowCell.setCellStyle(cellStyle);
}
int firstRowSpan = 0;
int firstRowStart = 0;
int secondRowStart = 0;
int secondRowSpan = 0;
//第一列的对比初始值
String upCompareField = "";
//第二行对比初始值
String preString = "";
//创建数据行
HSSFRow dataRow;
HSSFCell cell;
for (int i = 0; i < list.size(); i++) {
dataRow = sheet.createRow(i + 2);
HashDto hashDto2 = list.get(i);
for (int j = 0; j < headList.size(); j++) {
cell = dataRow.createCell(j);
String value = hashDto2.getString(headMap.get(j));
if (value.endsWith("合计(kw/h)")) {
sheet.addMergedRegion(new CellRangeAddress(2 + i, 2 + i, (short) 2, (short) lastCol));
}
cell.setCellValue(value);
//行高设置成360px
dataRow.setHeight((short) 360);
cell.setCellStyle(cellStyle);
//第一列每行中的对比值
String compareField = "";
if (j == 0) {
if (compareField.equals(upCompareField)) {
firstRowSpan++;
} else {
upCompareField = compareField;
firstRowStart = firstRowSpan;
firstRowSpan = 0;
}
}
}
for (HashDto hashDto : hashDtos) {
String secondValue = list.get(i).getString(headMap.get(1));
String countStr = hashDto.getString(headMap.get(1));
if (StringUtils.isNotEmpty(countStr)) {
if (countStr.equals(secondValue)) {
String countNum = hashDto.getString("countNum");
if (StringUtils.isNotEmpty(countNum)) {
int count = Integer.parseInt(countNum);
if (!secondValue.equals(preString)) {
sheet.addMergedRegion(new CellRangeAddress(2 + secondRowStart, 2 + count + secondRowStart, (short) 1, (short) 1));
secondRowStart += count;
secondRowStart += 1;
preString = secondValue;
}
}
}
}
}
}
sheet.addMergedRegion(new CellRangeAddress(firstRowStart + 2, firstRowSpan + 1, (short) 0, (short) 0));
//合并最后一行的单元格格式
sheet.addMergedRegion(new CellRangeAddress(list.size() + 1, list.size() + 1, 1, lastCol));
//写入excel表
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
workbook.write(response.getOutputStream());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
/**
* @version:v1.0.1
*/
public static List<String> getBetweenTime(String startTime, String endTime, Map<String, String> hashMap) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List<String> betweenTime = new ArrayList<String>();
try {
Date sdate = sdf.parse(startTime);
Date edate = sdf.parse(endTime);
Calendar sCalendar = Calendar.getInstance();
sCalendar.setTime(sdate);
int year = sCalendar.get(Calendar.YEAR);
int month = sCalendar.get(Calendar.MONTH);
int day = sCalendar.get(Calendar.DATE);
sCalendar.set(year, month, day, 0, 0, 0);
Calendar eCalendar = Calendar.getInstance();
eCalendar.setTime(edate);
year = eCalendar.get(Calendar.YEAR);
month = eCalendar.get(Calendar.MONTH);
day = eCalendar.get(Calendar.DATE);
eCalendar.set(year, month, day, 0, 0, 0);
while (sCalendar.before(eCalendar)) {
String date = sdf.format(sCalendar.getTime());
betweenTime.add(date);
hashMap.put(date, "0.00");
sCalendar.add(Calendar.DAY_OF_YEAR, 1);
}
betweenTime.add(sdf.format(eCalendar.getTime()));
hashMap.put(sdf.format(eCalendar.getTime()), "0.00");
} catch (Exception e) {
e.printStackTrace();
}
return betweenTime;
}
/**
* @version:v1.0.1
*/
private void handleMapOfList(Dto dto,
List<HashDto> list,
Map<String, String> hashMap,
Map<String, Map<String, String>> collect,
List<HashDto> mergeNumList,
List<HashDto> mergeInfoList,
List<String> betweenTimeList) {
/*
* list -》源数据集合
* hashMap -》存放查询时间段所有日期的对象
* collect -》处理后的键值对数据集合
* mergeNumList -》合并数量的集合
* mergeInfoList -》合并信息的集合
* betweenTimeList -》存放查询时间段所有日期的集合
* */
//让Double类型保留两位输出
DecimalFormat df = new DecimalFormat("0.00");
if (CollectionUtil.isNotEmpty(list)) {
//创建一个对象用来存放总计数据
HashDto totalHashDto = new HashDto();
Double totalAll = 0.00;
for (HashDto hashDto : list) {
hashDto.put("countNum", 0.00);
hashDto.putAll(hashMap);
String name = hashDto.getString("instrumentName");
Double sum = 0.00;
if (CollectionUtil.isNotEmpty(collect)) {
Map<String, String> stringStringMap = collect.get(name);
if (CollectionUtil.isNotEmpty(stringStringMap)) {
hashDto.putAll(stringStringMap);
for (Map.Entry<String, String> stringStringEntry : stringStringMap.entrySet()) {
String value = stringStringEntry.getValue();
if (StringUtils.isNotEmpty(value)) {
sum += Double.parseDouble(value);
}
}
}
}
//让Double类型保留两位输出
Double count = Double.parseDouble(df.format(sum));
hashDto.put("colTotal", df.format(count));
}
for (HashDto hashDto : mergeNumList) {
String accountingSubject = hashDto.getString("accountingSubject");
String accountingWorkshop = hashDto.getString("accountingWorkshop");
Double sum = 0.00;
hashDto.putAll(hashMap);
hashDto.put("instrumentName", accountingSubject + " - " + accountingWorkshop + " - 合计(kw/h)");
totalHashDto.put("accountingSubject", accountingSubject);
totalHashDto.put("accountingWorkshop", accountingSubject + " - 总计(kw/h)");
if (CollectionUtil.isNotEmpty(mergeInfoList)) {
for (HashDto hashDto1 : mergeInfoList) {
String accountingSubject1 = hashDto1.getString("accountingSubject");
String accountingWorkshop1 = hashDto1.getString("accountingWorkshop");
if (accountingSubject.equals(accountingSubject1) && accountingWorkshop.equals(accountingWorkshop1)) {
String countNum = hashDto.getString("countNum");
String consumeValue = hashDto1.getString("consumeValue");
String readDate = hashDto1.getString("readDate");
if (StringUtils.isNotEmpty(readDate) && CollectionUtil.isNotEmpty(collect)) {
sum += Double.parseDouble(consumeValue);
hashDto.put(readDate, df.format(Double.parseDouble(consumeValue)));
}
}
}
}
//让Double类型保留两位输出
Double count = Double.parseDouble(df.format(sum));
hashDto.put("colTotal", df.format(count));
list.add(hashDto);
totalHashDto.put("countNum", list.size());
}
//将list集合按照核算主体,核算详情排序
Collections.sort(list, new Comparator<Map>() {
@Override
public int compare(Map o1, Map o2) {
int result = o1.get("accountingSubject").toString().compareTo(o2.get("accountingSubject").toString());
int result2 = o1.get("accountingWorkshop").toString().compareTo(o2.get("accountingWorkshop").toString());
return result2 == 0 ? o1.get("countNum").toString().compareTo(o2.get("countNum").toString()) : result2;
}
});
//为集合添加一个合计数据
for (String readDate : betweenTimeList) {
Double total = 0.00;
for (HashDto hashDto : list) {
String instrumentName = hashDto.getString("instrumentName");
if (instrumentName.endsWith("合计(kw/h)")) {
Double value = Double.parseDouble(hashDto.getString(readDate));
total += value;
}
}
totalAll += total;
//让Double类型保留两位输出
Double count = Double.parseDouble(df.format(total));
totalHashDto.put(readDate, df.format(count));
}
//让Double类型保留两位输出
Double count = Double.parseDouble(df.format(totalAll));
totalHashDto.put("colTotal", df.format(count));
list.add(totalHashDto);
}
}
}
3、mapper层映射
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cn.platform.slaughter.device.mapper.electric.MyElectricAccountingMapper">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.cn.platform.slaughter.device.entity.electric.MyElectricAccounting" id="myElectricAccountingMap">
<result property="id" column="id"/>
<result property="accountingSubject" column="accounting_subject"/>
<result property="accountingWorkshop" column="accounting_workshop"/>
<result property="instrumentName" column="instrument_name"/>
<result property="instrumentUse" column="instrument_use"/>
<result property="factoryCode" column="factory_code"/>
</resultMap>
<sql id="Base_Column_List">
id, accounting_subject, accounting_workshop, instrument_name, instrument_use, factory_code
</sql>
<select id="getList" resultMap="myElectricAccountingMap" parameterType="map">
select
<include refid="Base_Column_List" />
from
my_electric_accounting
<where>
<if test="id != null and id != ''">
and id = #{id}
</if>
<if test="accountingSubject != null and accountingSubject != ''">
and accounting_subject = #{accountingSubject}
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and accounting_workshop = #{accountingWorkshop}
</if>
<if test="instrumentName != null and instrumentName != ''">
and instrument_name = #{instrumentName}
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and instrument_use = #{instrumentUse}
</if>
<if test="factoryCode != null and factoryCode != ''">
and factory_code = #{factoryCode}
</if>
</where>
</select>
<!--获取氨压机对照的制冷机房名称-->
<select id="getAllRefrigeration" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT
t2.accounting_subject AS accountingSubject,
t2.accounting_workshop AS accountingWorkshop,
t2.instrument_name AS instrumentName,
t2.instrument_use AS instrumentUse,
t1.refrigeration_name AS refrigerationName
FROM
my_base_refrigeration_evaporator t1
LEFT JOIN my_electric_accounting t2 ON t1.instrument_name = t2.instrument_name
<where>
t1.refrigeration_name IS NOT NULL
AND t1.refrigeration_name != ''
<if test="accountingSubject != null and accountingSubject != ''">
and t2.accounting_subject LIKE CONCAT('%',#{accountingSubject},'%')
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and t2.accounting_workshop LIKE CONCAT('%',#{accountingWorkshop},'%')
</if>
<if test="instrumentName != null and instrumentName != ''">
and t2.instrument_name LIKE CONCAT('%',#{instrumentName},'%')
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and t2.instrument_use LIKE CONCAT('%',#{instrumentUse},'%')
</if>
<if test="factoryCode != null and factoryCode != ''">
and t2.factory_code = #{factoryCode}
</if>
<if test="refrigerationName != null and refrigerationName != ''">
and t1.refrigeration_name LIKE CONCAT('%',#{refrigerationName},'%')
</if>
</where>
</select>
<!--获取所有的蒸发器对应的电表数据-->
<select id="getAllEvaporatorName" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT
t2.accounting_subject AS accountingSubject,
t2.accounting_workshop AS accountingWorkshop,
t2.instrument_name AS instrumentName,
t2.instrument_use AS instrumentUse,
t1.evaporator_name AS evaporatorName,
t1.distribution_cabinet_name AS distributionCabinetName
FROM
my_base_refrigeration_evaporator t1
LEFT JOIN my_electric_accounting t2 ON t1.instrument_name = t2.instrument_name
<where>
t1.evaporator_name IS NOT NULL
AND t1.evaporator_name !=''
<if test="accountingSubject != null and accountingSubject != ''">
and t2.accounting_subject LIKE CONCAT('%',#{accountingSubject},'%')
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and t2.accounting_workshop LIKE CONCAT('%',#{accountingWorkshop},'%')
</if>
<if test="instrumentName != null and instrumentName != ''">
and t2.instrument_name LIKE CONCAT('%',#{instrumentName},'%')
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and t2.instrument_use LIKE CONCAT('%',#{instrumentUse},'%')
</if>
<if test="factoryCode != null and factoryCode != ''">
and t2.factory_code = #{factoryCode}
</if>
<if test="evaporatorName != null and evaporatorName != ''">
and t1.evaporator_name LIKE CONCAT('%',#{evaporatorName},'%')
</if>
<if test="distributionCabinetName != null and distributionCabinetName != ''">
and t1.distribution_cabinet_name LIKE CONCAT('%',#{distributionCabinetName},'%')
</if>
</where>
</select>
<!--获取能耗数据-->
<select id="getAllElectricityData" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT DISTINCT
CONVERT ( VARCHAR ( 10 ), read_date, 23 ) AS readDate,
CONVERT ( VARCHAR ( 20 ), CONVERT ( DECIMAL ( 18, 2 ), SUM ( consume_value ) ) ) AS consumeValue,
instrument_name AS instrumentName
FROM
my_energy_consume_for_day
<where>
<if test="startTime != null and startTime != ''">
<![CDATA[ and CONVERT(VARCHAR(10),read_date,23) >= #{startTime} ]]>
</if>
<if test="endTime != null and endTime != ''">
<![CDATA[ and CONVERT(VARCHAR(10),read_date,23) <= #{endTime} ]]>
</if>
<if test="factoryCode != null and factoryCode != ''">
and slaughter_factory_code = #{factoryCode}
</if>
</where>
GROUP BY
read_date,
instrument_name,
consume_value
</select>
<!--获取蒸发器需要合并的数量-->
<select id="getEvaporatorMergeNum" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT
t1.accounting_subject AS accountingSubject,
t1.accounting_workshop AS accountingWorkshop,
COUNT ( t1.accounting_workshop ) AS countNum
FROM
my_electric_accounting t1
LEFT JOIN my_base_refrigeration_evaporator t2 ON t1.instrument_name = t2.instrument_name
WHERE
t2.evaporator_name IS NOT NULL
AND t2.evaporator_name != ''
<if test="accountingSubject != null and accountingSubject != ''">
and t1.accounting_subject LIKE CONCAT('%',#{accountingSubject},'%')
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and t1.accounting_workshop LIKE CONCAT('%',#{accountingWorkshop},'%')
</if>
<if test="instrumentName != null and instrumentName != ''">
and t1.instrument_name LIKE CONCAT('%',#{instrumentName},'%')
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and t1.instrument_use LIKE CONCAT('%',#{instrumentUse},'%')
</if>
<if test="factoryCode != null and factoryCode != ''">
and t1.factory_code = #{factoryCode}
</if>
<if test="evaporatorName != null and evaporatorName != ''">
and t2.evaporator_name LIKE CONCAT('%',#{evaporatorName},'%')
</if>
<if test="distributionCabinetName != null and distributionCabinetName != ''">
and t2.distribution_cabinet_name LIKE CONCAT('%',#{distributionCabinetName},'%')
</if>
GROUP BY
t1.accounting_subject,
t1.accounting_workshop
</select>
<!--获取蒸发器需要合并的信息-->
<select id="getEvaporatorMergeInfo" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT
t1.accounting_subject AS accountingSubject,
t1.accounting_workshop AS accountingWorkshop,
CONVERT(DECIMAL(18,2), SUM ( t2.consume_value )) AS consumeValue,
CONVERT(varchar(10),t2.read_date,23) AS readDate
FROM
my_electric_accounting t1
LEFT JOIN my_energy_consume_for_day t2 ON t1.instrument_name = t2.instrument_name
LEFT JOIN my_base_refrigeration_evaporator t3 ON t2.instrument_name= t3.instrument_name
WHERE
t3.evaporator_name IS NOT NULL
AND t3.evaporator_name != ''
<if test="accountingSubject != null and accountingSubject != ''">
and t1.accounting_subject LIKE CONCAT('%',#{accountingSubject},'%')
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and t1.accounting_workshop LIKE CONCAT('%',#{accountingWorkshop},'%')
</if>
<if test="instrumentName != null and instrumentName != ''">
and t1.instrument_name LIKE CONCAT('%',#{instrumentName},'%')
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and t1.instrument_use LIKE CONCAT('%',#{instrumentUse},'%')
</if>
<if test="factoryCode != null and factoryCode != ''">
and t1.factory_code = #{factoryCode}
and t2.slaughter_factory_code = #{factoryCode}
</if>
<if test="evaporatorName != null and evaporatorName != ''">
and t3.evaporator_name LIKE CONCAT('%',#{evaporatorName},'%')
</if>
<if test="startTime != null and startTime != ''">
<![CDATA[ and CONVERT(VARCHAR(10),t2.read_date,23) >= #{startTime} ]]>
</if>
<if test="endTime != null and endTime != ''">
<![CDATA[ and CONVERT(VARCHAR(10),t2.read_date,23) <= #{endTime} ]]>
</if>
<if test="distributionCabinetName != null and distributionCabinetName != ''">
and t3.distribution_cabinet_name LIKE CONCAT('%',#{distributionCabinetName},'%')
</if>
GROUP BY
t1.accounting_subject,
t1.accounting_workshop,
t2.read_date
</select>
<!--获取氨压机需要合并的数量-->
<select id="getRefrigerationMergeNum" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT
t1.accounting_subject AS accountingSubject,
t1.accounting_workshop AS accountingWorkshop,
COUNT ( t1.accounting_workshop ) AS countNum
FROM
my_electric_accounting t1
LEFT JOIN my_base_refrigeration_evaporator t2 ON t1.instrument_name = t2.instrument_name
WHERE
t2.refrigeration_name IS NOT NULL
AND t2.refrigeration_name != ''
<if test="accountingSubject != null and accountingSubject != ''">
and t1.accounting_subject LIKE CONCAT('%',#{accountingSubject},'%')
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and t1.accounting_workshop LIKE CONCAT('%',#{accountingWorkshop},'%')
</if>
<if test="instrumentName != null and instrumentName != ''">
and t1.instrument_name LIKE CONCAT('%',#{instrumentName},'%')
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and t1.instrument_use LIKE CONCAT('%',#{instrumentUse},'%')
</if>
<if test="factoryCode != null and factoryCode != ''">
and t1.factory_code = #{factoryCode}
</if>
<if test="refrigerationName != null and refrigerationName != ''">
and t2.refrigeration_name LIKE CONCAT('%',#{refrigerationName},'%')
</if>
GROUP BY
t1.accounting_subject,
t1.accounting_workshop
</select>
<!--获取氨压机需要合并的信息-->
<select id="getRefrigerationMergeInfo" resultType="com.muyuan.platform.common.typewrap.HashDto">
SELECT
accounting_subject AS accountingSubject,
accounting_workshop AS accountingWorkshop,
CONVERT ( DECIMAL ( 18, 2 ), SUM ( t2.consume_value ) ) AS consumeValue,
CONVERT ( VARCHAR ( 10 ), t2.read_date, 23 ) AS readDate
FROM
my_electric_accounting t1
LEFT JOIN my_energy_consume_for_day t2 ON t1.instrument_name = t2.instrument_name
LEFT JOIN my_base_refrigeration_evaporator t3 ON t2.instrument_name = t3.instrument_name
WHERE
t3.refrigeration_name IS NOT NULL
AND t3.refrigeration_name != ''
<if test="accountingSubject != null and accountingSubject != ''">
and t1.accounting_subject LIKE CONCAT('%',#{accountingSubject},'%')
</if>
<if test="accountingWorkshop != null and accountingWorkshop != ''">
and t1.accounting_workshop LIKE CONCAT('%',#{accountingWorkshop},'%')
</if>
<if test="instrumentName != null and instrumentName != ''">
and t1.instrument_name LIKE CONCAT('%',#{instrumentName},'%')
</if>
<if test="instrumentUse != null and instrumentUse != ''">
and t1.instrument_use LIKE CONCAT('%',#{instrumentUse},'%')
</if>
<if test="factoryCode != null and factoryCode != ''">
and t1.factory_code = #{factoryCode}
and t2.slaughter_factory_code = #{factoryCode}
</if>
<if test="refrigerationName != null and refrigerationName != ''">
and t3.refrigeration_name LIKE CONCAT('%',#{refrigerationName},'%')
</if>
<if test="startTime != null and startTime != ''">
<![CDATA[ and CONVERT(VARCHAR(10),t2.read_date,23) >= #{startTime} ]]>
</if>
<if test="endTime != null and endTime != ''">
<![CDATA[ and CONVERT(VARCHAR(10),t2.read_date,23) <= #{endTime} ]]>
</if>
GROUP BY
t1.accounting_subject,
t1.accounting_workshop,
t2.read_date
</select>
</mapper>
标签:Java,name,t2,单元格,导出,t1,instrument,accounting,String 来源: https://blog.csdn.net/weixin_43704154/article/details/113758177