Browse Source

Merge branch 'dev_resi_export' of http://git.elinkit.com.cn:7070/r/epmet-cloud into dev_resi_export

master
wangxianzhang 4 years ago
parent
commit
58093e0b03
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/EasyPoiExcelExportStylerImpl.java
  2. 96
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/handler/ColumnWidthStyleStrategy.java
  3. 5
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/IcBuildingListFormDTO.java
  4. 4
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/IcHouseListFormDTO.java
  5. 5
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml
  6. 5
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml
  7. 15
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/EasyPoiExcelExportStylerImpl.java

@ -50,7 +50,7 @@ public class EasyPoiExcelExportStylerImpl extends AbstractExcelExportStyler
titleStyle.setFont(font);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
return null;
return titleStyle;
}
/**

96
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/handler/ColumnWidthStyleStrategy.java

@ -0,0 +1,96 @@
package com.epmet.commons.tools.utils.poi.excel.handler;
/**
* desc:设置columnWith宽度
*
* @author: LiuJanJun
* @date: 2022/4/28 5:05 下午
* @version: 1.0
*/
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Take the width of the longest column as the width.
* <p>
* This is not very useful at the moment, for example if you have Numbers it will cause a newline.And the length is not
* exactly the same as the actual length.
*
* @author Jiaju Zhuang
*/
public class ColumnWidthStyleStrategy extends AbstractColumnWidthStyleStrategy {
private static final int MAX_COLUMN_WIDTH = 255;
/**
* 是否 根据内容设置宽度
*/
private boolean isSetContentWidth = false;
private final Map<Integer, Map<Integer, Integer>> cache = MapUtils.newHashMapWithExpectedSize(8);
@Override
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<WriteCellData<?>> cellDataList, Cell cell,
Head head,
Integer relativeRowIndex, Boolean isHead) {
boolean needSetWidth = (isHead || isSetContentWidth) && CollectionUtils.isNotEmpty(cellDataList);
if (!needSetWidth) {
return;
}
Map<Integer, Integer> maxColumnWidthMap = cache.computeIfAbsent(writeSheetHolder.getSheetNo(), k -> new HashMap<>(16));
Integer columnWidth = dataLength(cellDataList, cell, isHead);
if (columnWidth < 0) {
return;
}
if (columnWidth > MAX_COLUMN_WIDTH) {
columnWidth = MAX_COLUMN_WIDTH;
}
Integer maxColumnWidth = maxColumnWidthMap.get(cell.getColumnIndex());
if (maxColumnWidth == null || columnWidth > maxColumnWidth) {
maxColumnWidthMap.put(cell.getColumnIndex(), columnWidth);
writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 256);
}
}
private Integer dataLength(List<WriteCellData<?>> cellDataList, Cell cell, Boolean isHead) {
if (isHead) {
return cell.getStringCellValue().getBytes().length+3;
}
WriteCellData<?> cellData = cellDataList.get(0);
CellDataTypeEnum type = cellData.getType();
if (type == null) {
return -1;
}
switch (type) {
case STRING:
return cellData.getStringValue().getBytes().length;
case BOOLEAN:
return cellData.getBooleanValue().toString().getBytes().length;
case NUMBER:
return cellData.getNumberValue().toString().getBytes().length;
default:
return -1;
}
}
public ColumnWidthStyleStrategy() {
}
public ColumnWidthStyleStrategy(boolean isSetContentWidth) {
this.isSetContentWidth = isSetContentWidth;
}
}

5
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/IcBuildingListFormDTO.java

@ -26,4 +26,9 @@ public class IcBuildingListFormDTO extends PageFormDTO {
* 房主电话
*/
private String ownerPhone;
/**
* asc正序desc倒序
*/
private String sortType;
}

4
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/IcHouseListFormDTO.java

@ -65,5 +65,9 @@ public class IcHouseListFormDTO extends PageFormDTO {
*/
private String keyword;
/**
* asc正序desc倒序
*/
private String sortType;
}

5
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml

@ -121,7 +121,10 @@
</if>
AND a.DEL_FLAG = '0'
</where>
ORDER BY a.sort,
ORDER BY
<if test='sortType == null '>a.sort,</if>
<if test='sortType != null and sortType == "asc" '>a.sort,</if>
<if test='sortType != null and sortType == "desc" '>a.sort DESC,</if>
CAST(b.NEIGHBOR_HOOD_NAME AS SIGNED),CONVERT(b.NEIGHBOR_HOOD_NAME using gbk),
CAST(a.BUILDING_NAME AS SIGNED),CONVERT(a.BUILDING_NAME USING gbk)
</select>

5
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml

@ -158,7 +158,10 @@
and a.del_flag = '0'
</where>
#排序规则:根据小区、楼栋、单元、门牌号(分别按照数字和中文)分别升序排序
ORDER BY a.sort,
ORDER BY
<if test='sortType == null '>a.sort,</if>
<if test='sortType != null and sortType == "asc" '>a.sort,</if>
<if test='sortType != null and sortType == "desc" '>a.sort DESC,</if>
CONVERT(c.NEIGHBOR_HOOD_NAME using gbk),
CONVERT(b.BUILDING_NAME USING gbk),
CONVERT(d.UNIT_NAME USING gbk),

15
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java

@ -8,6 +8,7 @@ import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.Constant;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.form.IcExportTemplateSaveFormDTO;
@ -20,6 +21,7 @@ import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Md5Util;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.utils.SpringContextUtils;
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter;
@ -190,18 +192,21 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService {
FormItemResult formItemResult = exportResiUserItemDTO.getItemMap().get(columnName);
String newValue = vauleStr;
if (Constant.OPITON_SOURCE_REMOTE.equals(sqlColumn.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) {
putRemoteValue(exportResiUserItemDTO.getRemoteItemConditionMap().get(itemId), staffInfoCacheResult.getAgencyId(), o, originalConditionMap, formItemResult, columnName, vauleStr);
newValue = String.valueOf(o.get(columnName));
} else if (Constant.OPITON_SOURCE_LOCAL.equals(sqlColumn.getOptionSourceType())) {
newValue = putOptionValue(formItemResult, vauleStr);
}
if (FieldConstant.ID.equals(key)) {
newValue = Md5Util.md5(vauleStr);
}
singleRowData.add(newValue);
});
resultData.add(singleRowData);
});
excelWriter.write(resultData, writeSheet);
break;
} while (mapListPage.getResult().size() == searchForm.getPageSize());
} catch (IOException e) {
log.error("exportIcResiUser exception", e);
@ -242,10 +247,10 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService {
}
IcCustomExportResultDTO data = exportConfigResult.getData();
//添加一个虚拟列Id 用于分组
data.getShowSqlColumns().add(0, new IcCustomExportResultDTO.SqlColumn(null, "ic_resi_user", false, "ID", "local"));
//添加一个虚拟列Id 用于分组 合并单元格
data.getShowSqlColumns().add(0, new IcCustomExportResultDTO.SqlColumn(null, "ic_resi_user", false, FieldConstant.ID, "local"));
List<String> id = new ArrayList<>();
id.add("ID");
id.add(FieldConstant.ID);
data.getHeaders().add(0, id);
return exportConfigResult;
}
@ -278,7 +283,6 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService {
List<String> listOptions = new ArrayList<>();
String[] split = vauleStr.split(StrConstant.COMMA);
Arrays.stream(split).forEach((value) -> {
//todo 看看怎么更好的利用本地缓存
OptionResultDTO optionResultDTO = remoteOptionMap.get(value);
if (optionResultDTO != null) {
listOptions.add(optionResultDTO.getLabel());
@ -338,6 +342,7 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService {
}
break;
default:
return valueStr;
}
return valueStr;
}

Loading…
Cancel
Save