Ver código fonte

[task-1618] 导出模板功能修改

Li Yuan 2 anos atrás
pai
commit
fe861e8521

+ 11 - 0
ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/entity/params/ExcelExportEntity.java

@@ -60,6 +60,9 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc
      */
     private boolean                 isStatistics;
 
+    //批注
+    private String comment;
+
     private List<ExcelExportEntity> list;
 
     public ExcelExportEntity() {
@@ -177,6 +180,14 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc
         this.isStatistics = isStatistics;
     }
 
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+
     @Override
     public int compareTo(ExcelExportEntity prev) {
         return this.getOrderNum() - prev.getOrderNum();

+ 54 - 8
ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/export/ExcelExportServer.java

@@ -8,12 +8,9 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 
 import com.lc.ibps.components.poi.annotation.ExcelTarget;
@@ -25,6 +22,8 @@ import com.lc.ibps.components.poi.excel.export.styler.IExcelExportStyler;
 import com.lc.ibps.components.poi.exception.excel.ExcelExportException;
 import com.lc.ibps.components.poi.exception.excel.enums.ExcelExportEnum;
 import com.lc.ibps.components.poi.util.PoiPublicUtil;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 
 /**
  * Excel导出服务。
@@ -220,11 +219,11 @@ public class ExcelExportServer extends ExcelExportBase {
                                List<ExcelExportEntity> excelParams) {
         Row row = sheet.createRow(index);
         int rows = getRowNums(excelParams);
-        row.setHeight((short) 450);
+        row.setHeight((short) 600);
         Row listRow = null;
         if (rows == 2) {
             listRow = sheet.createRow(index + 1);
-            listRow.setHeight((short) 450);
+            listRow.setHeight((short) 600);
         }
         int cellIndex = 0;
         CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor());
@@ -232,6 +231,11 @@ public class ExcelExportServer extends ExcelExportBase {
             ExcelExportEntity entity = excelParams.get(i);
             if (StringUtils.isNotBlank(entity.getName())) {
                 createStringCell(row, cellIndex, entity.getName(), titleStyle, entity);
+                Cell cell = row.getCell(cellIndex);
+                if(StringUtils.isNotBlank(entity.getComment())){
+                    createTitleCellComment(sheet, cell,entity.getComment());
+                }
+
             }
             if (entity.getList() != null) {
                 List<ExcelExportEntity> sTitel = entity.getList();
@@ -256,4 +260,46 @@ public class ExcelExportServer extends ExcelExportBase {
 
     }
 
+    private void createTitleCellComment(Sheet sheet, Cell cell, String value) {
+        cell.removeCellComment();
+        if (type.equals(ExcelType.HSSF)) {
+            ClientAnchor anchor = new HSSFClientAnchor();
+            // 关键修改
+            anchor.setDx1(0);
+            anchor.setDx2(0);
+            anchor.setDy1(0);
+            anchor.setDy2(0);
+            anchor.setCol1(cell.getColumnIndex());
+            anchor.setRow1(cell.getRowIndex());
+            anchor.setCol2(cell.getColumnIndex() + 5);
+            anchor.setRow2(cell.getRowIndex() + 6);
+            // 结束
+            Drawing drawing = sheet.createDrawingPatriarch();
+            Comment comment = drawing.createCellComment(anchor);
+            // 输入批注信息
+            comment.setString(new HSSFRichTextString(value));
+            // 将批注添加到单元格对象中
+            cell.setCellComment(comment);
+        } else  {
+            ClientAnchor anchor = new XSSFClientAnchor();
+            // 关键修改
+            anchor.setDx1(0);
+            anchor.setDx2(0);
+            anchor.setDy1(0);
+            anchor.setDy2(0);
+            anchor.setCol1(cell.getColumnIndex());
+            anchor.setRow1(cell.getRowIndex());
+            anchor.setCol2(cell.getColumnIndex() + 5);
+            anchor.setRow2(cell.getRowIndex() + 6);
+            // 结束
+            Drawing drawing = sheet.createDrawingPatriarch();
+            Comment comment = drawing.createCellComment(anchor);
+            // 输入批注信息
+            comment.setString(new XSSFRichTextString(value));
+            // 将批注添加到单元格对象中
+            cell.setCellComment(comment);
+        }
+    }
+
+
 }

+ 8 - 0
ibps-component-root/modules/comp-poi/src/main/java/com/lc/ibps/components/poi/excel/export/styler/ExcelExportStylerColorImpl.java

@@ -25,6 +25,10 @@ public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler
     @Override
     public CellStyle getHeaderStyle(short headerColor) {
         CellStyle titleStyle = workbook.createCellStyle();
+        titleStyle.setBorderLeft((short) 1); // 左边框
+        titleStyle.setBorderRight((short) 1); // 右边框
+        titleStyle.setBorderBottom((short) 1);
+        titleStyle.setBorderTop((short) 1);
         Font font = workbook.createFont();
         font.setFontHeightInPoints((short) 24);
         titleStyle.setFont(font);
@@ -53,6 +57,10 @@ public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler
     @Override
     public CellStyle getTitleStyle(short color) {
         CellStyle titleStyle = workbook.createCellStyle();
+        titleStyle.setBorderLeft((short) 1); // 左边框
+        titleStyle.setBorderRight((short) 1); // 右边框
+        titleStyle.setBorderBottom((short) 1);
+        titleStyle.setBorderTop((short) 1);
         titleStyle.setFillForegroundColor(color); // 填充的背景颜色
         titleStyle.setAlignment(CellStyle.ALIGN_CENTER);
         titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

+ 29 - 42
ibps-provider-root/modules/provider-form/src/main/java/com/lc/ibps/form/provider/DataTemplateProvider.java

@@ -15,7 +15,11 @@ import java.util.Map;
 import javax.annotation.Resource;
 
 import com.lc.ibps.base.framework.table.ICommonDao;
+import com.lc.ibps.components.poi.excel.entity.enmus.ExcelType;
+import com.lc.ibps.components.poi.excel.export.styler.ExcelExportStylerColorImpl;
+import com.lc.ibps.components.poi.excel.export.styler.ExcelExportStylerDefaultImpl;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -1290,7 +1294,7 @@ public class DataTemplateProvider extends GenericProvider implements IDataTempla
 	 * @param exportColumns
 	 * @return
 	 */
-	private List<ExcelExportEntity> getEntityList(String exportColumns) {
+	private List<ExcelExportEntity> getEntityList(String exportColumns,double width,boolean isWrap) {
 		List<ExcelExportEntity> entityList = new ArrayList<ExcelExportEntity>();
 		if (JsonUtil.isEmpty(exportColumns)) {
 			return entityList;
@@ -1301,7 +1305,21 @@ public class DataTemplateProvider extends GenericProvider implements IDataTempla
 			JSONObject jsonObject = (JSONObject) obj;
 			String name = JsonUtil.getString(jsonObject, "name");
 			if (StringUtil.isNotEmpty(name)) {
-				entityList.add(new ExcelExportEntity(JsonUtil.getString(jsonObject, "label"), name));
+				ExcelExportEntity entity = new ExcelExportEntity(JsonUtil.getString(jsonObject, "label"), name);
+				String labelDesc = JsonUtil.getString(jsonObject, "labelDesc");
+				if (StringUtil.isNotEmpty(labelDesc)) {
+					entity.setComment(labelDesc);
+				}
+				double labelWidth = JsonUtil.getDouble(jsonObject, "labelWidth");
+				entity.setWidth(labelWidth == 0 ? width : labelWidth);
+				String lineWrap = JsonUtil.getString(jsonObject, "lineWrap");
+				if(StringUtil.isNotEmpty(lineWrap)){
+					entity.setWrap(BooleanUtils.toBoolean(lineWrap));
+				}else{
+					entity.setWrap(isWrap);
+				}
+
+				entityList.add(entity);
 			}
 			
 			// 收集字段权限信息
@@ -1607,12 +1625,15 @@ public class DataTemplateProvider extends GenericProvider implements IDataTempla
 
 		String pk = JsonUtil.getString(responseData, "unique", "ID_");
 
+		double width = JsonUtil.getDouble(responseData, "labelWidth", 10);
+		boolean isWrap = JsonUtil.getBoolean(responseData, "lineWrap", false);
+
 		String datasetKey = JsonUtil.getString(responseData, "datasetKey");
 		DatasetPo datasetPo = datasetRepository.getDatasetByKey(datasetKey);
 
 		responseData.element("isExport", true);
 		List<?> list;
-		if ("exportMuBan".equals(action)){
+		if ("exportTemplate".equals(action)){
 			 list = new ArrayList<>();
 		}else {
 			 list = dataTemplateRepository.queryForList(new ResponseDataTemplateVo(responseData, queryFilter));
@@ -1621,7 +1642,7 @@ public class DataTemplateProvider extends GenericProvider implements IDataTempla
 			throw new RuntimeException(I18nUtil.getMessage("com.lc.ibps.form.provider.DataTemplateProvider.exportDataMap.error.exportColumns"));
 		}
 		// 导出字段对象的实体
-		List<ExcelExportEntity> entityList = getEntityList(JsonUtil.getString(exportColumns, "fields"));
+		List<ExcelExportEntity> entityList = getEntityList(JsonUtil.getString(exportColumns, "fields"),width,isWrap);
 		if(BeanUtils.isEmpty(entityList)){
 			throw new RuntimeException(I18nUtil.getMessage("com.lc.ibps.form.provider.DataTemplateProvider.exportDataMap.error.entityList"));
 		}
@@ -1636,46 +1657,12 @@ public class DataTemplateProvider extends GenericProvider implements IDataTempla
 
 		HashMap<String, Object> resultMap = new HashMap<>();
 		resultMap.put(PoiViewConstants.FILE_NAME, label + "_" + DateUtil.getCurrentTime("yyyyMMddHHmmss"));
-		resultMap.put(PoiViewConstants.PARAMS, new ExportParams(label));
+		ExportParams exportParams = new ExportParams(label);
+		exportParams.setType(ExcelType.XSSF);
+		exportParams.setStyle(ExcelExportStylerColorImpl.class);
+		resultMap.put(PoiViewConstants.PARAMS, exportParams);
 		resultMap.put(PoiViewConstants.ENTITY_LIST, entityList);
 
-		//  物料基本信息  和 物料库存信息 导出 excel 供应商字段值id --> name 查询修改
-		String menu = (String) responseData.get("key");
-		// 罗湖  wljbxx    wlkcxx
-		// 明鉴  mjwljbxx
-		if (menu.equals("wljbxx") || menu.equals("mjwljbxx") || menu.equals("wlkcxx") || menu.equals("wljbxx1") || menu.equals("bzwzgltz") || menu.equals("llckwlxx")) {
-			String sql = " SELECT id_,gong_ying_shang_m FROM t_gysml ";
-			List<Map<String, Object>> gysList = (List<Map<String, Object>>) commonDao.query(sql);
-			for (Map<String, Object> objectMap : listMap) {
-				String gysName = "";
-				String gysIds = "";
-				if (objectMap.get("gong_ying_shang_") != null){
-					gysIds = objectMap.get("gong_ying_shang_").toString();
-				}
-				String[] providers = {};
-				if (gysIds != null && !gysIds.equals("")) {
-					providers = gysIds.split(",");
-				}
-				if (providers.length==1) {
-					for (Map<String, Object> objMap : gysList) {
-						if (objMap.get("id_").equals(gysIds)) {
-							gysName = objMap.get("gong_ying_shang_m").toString();
-						}
-					}
-				}
-				if (providers.length > 1) {
-					for (String str : providers) {
-						for (Map<String, Object> objMap : gysList) {
-							if (objMap.get("id_").equals(str)) {
-								gysName = gysName + "/" + objMap.get("gong_ying_shang_m");
-							}
-						}
-					}
-					gysName = gysName.substring(1);
-				}
-				objectMap.put("gong_ying_shang_", gysName==null?"": gysName);
-			}
-		}
 		resultMap.put(PoiViewConstants.MAP_LIST, listMap);
 		return resultMap;
 	}