Commit ea06341b authored by tangwei's avatar tangwei

删除无用类

parent 7d3b17df
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import com.alibaba.excel.context.AnalysisContext;
//import com.alibaba.excel.event.AnalysisEventListener;
//import com.alibaba.fastjson.JSON;
//
////如果没有特殊说明,下面的案例将默认使用这个监听器
//public class ExcelListener<T> extends AnalysisEventListener<T> {
//
// List<T> list = new ArrayList<T>();
//
// public List<T> getList() {
// return list;
//}
//
//public void setList(List<T> list) {
// this.list = list;
//}
//
///**
// * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来
// */
// public ExcelListener() {}
//
// /**
// * 这个每一条数据解析都会来调用
// *
// * @param data
// * @param context
// */
// @Override
// public void invoke(T data, AnalysisContext context) {
// list.add(data);
// }
//
// /**
// * 所有数据解析完成了 都会来调用
// *
// * @param context
// */
// @Override
// public void doAfterAllAnalysed(AnalysisContext context) {
//
// }
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.lang.reflect.Field;
//import java.nio.charset.StandardCharsets;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.poi.ss.usermodel.BorderStyle;
//import org.apache.poi.ss.usermodel.HorizontalAlignment;
//import org.apache.poi.ss.usermodel.IndexedColors;
//import org.apache.poi.ss.usermodel.VerticalAlignment;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.alibaba.excel.EasyExcel;
//import com.alibaba.excel.ExcelReader;
//import com.alibaba.excel.read.metadata.ReadSheet;
//import com.alibaba.excel.support.ExcelTypeEnum;
//import com.alibaba.excel.write.metadata.style.WriteCellStyle;
//import com.alibaba.excel.write.metadata.style.WriteFont;
//import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
//import com.yeejoin.amos.boot.module.jcs.api.mapper.DataDictionaryMapper;
//
//public class ExcelUtil {
// /**
// * 生成excel模板
// *
// * @param response
// * @param fileName 下载的文件名,
// * @param sheetName sheet名
// * @param data 导出的数据
// * @param model 导出的头
// * @param heardHeight 头行高
// * @param flag true模板填充下拉 false 不填充
// */
// public static void createTemplate(HttpServletResponse response, String fileName,
// String sheetName, List<? extends Object> data,
// Class<?> model, DataDictionaryMapper dataDictionaryMapper,boolean flag) {
//
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = setMyCellStyle();
// try {
// //下拉列表集合
// Map<Integer, String[]> explicitListConstraintMap = new HashMap<>();
// if(flag) {
// //循环获取对应列得下拉列表信息
// Field[] declaredFields = model.getDeclaredFields();
// for (int i = 0; i < declaredFields.length; i++) {
// Field field = declaredFields[i];
// //解析注解信息
// ExplicitConstraint explicitConstraint = field.getAnnotation(ExplicitConstraint.class);
// resolveExplicitConstraint(explicitListConstraintMap,explicitConstraint,dataDictionaryMapper);
// }
// }
// EasyExcel.write(getOutputStream(fileName, response, ExcelTypeEnum.XLSX), model).
// excelType(ExcelTypeEnum.XLSX).sheet(sheetName)
// .registerWriteHandler(new TemplateCellWriteHandlerDate(explicitListConstraintMap))
// .registerWriteHandler(new TemplateCellWriteHandler())
// .registerWriteHandler(horizontalCellStyleStrategy)
// .doWrite(data);
// } catch (Exception e) {
// e.printStackTrace();
// throw new RuntimeException("系统异常!");
//
// }
// }
// /**
// * 读取 Excel(第一个 sheet) 指定行开始读取
// * @param excel 文件
// * @param rowType 模板实体类
// * @param header 指定不读取的表头行数,
// * @param <T>
// * @return 集合数据
// * @throws ExcelException
// */
// public static <T> List<T> readFirstSheetExcel(MultipartFile excel, Class<T> rowType,int header) throws Exception {
// ExcelReader reader = getReader(excel, header);
// if (reader == null) {
// return new ArrayList<>();
// }
// return readExcel(reader, rowType, 0);
// }
//
//
//
// /**
// * 读取 Excel(多个 sheet)
// * @param reader 读取的excel
// * @param rowModel excel模板实体类
// * @param sheetCount sheet
// * @param <T>
// * @return
// */
// public static <T> List<T> readExcel(ExcelReader reader, Class<T> rowModel, int sheetCount) {
// if (reader == null) {
// return new ArrayList<>();
// }
// ExcelListener<T> excelListener = new ExcelListener<>();
// ReadSheet readSheet = EasyExcel.readSheet(sheetCount)
// .head(rowModel)
// .registerReadListener(excelListener)
// .build();
// reader.read(readSheet);
// return excelListener.getList();
// }
//
//
//
//
// /**
// *
// * @param excel 需要解析的 Excel 文件
// * @param header 指定不读取表头行数,
// * @return
// * @throws ExcelException
// */
// public static ExcelReader getReader(MultipartFile excel,int header) throws Exception {
// String fileName = excel.getOriginalFilename();
// if (fileName == null) {
// throw new Exception("文件不存在!");
// }
// if (!fileName.toLowerCase().endsWith(ExcelTypeEnum.XLS.getValue()) && !fileName.toLowerCase().endsWith(ExcelTypeEnum.XLSX.getValue())) {
// throw new Exception("文件类型异常!");
// }
// InputStream inputStream;
// try {
// inputStream = excel.getInputStream();
// return EasyExcel.read(inputStream).
// headRowNumber(header).
// build();
// } catch (IOException e) {
// //do something
// }
// return null;
// }
//
//
//
// /**
// * 解析注解内容 获取下列表信息
// * @param explicitConstraint
// * @return
// */
// public static Map<Integer, String[]> resolveExplicitConstraint( Map<Integer, String[]> explicitListConstraintMap,ExplicitConstraint explicitConstraint, DataDictionaryMapper dataDictionaryMapper){
// if (explicitConstraint == null) {
// return null;
// }
// //固定下拉信息
// String[] source = explicitConstraint.source();
// if (source.length > 0) {
// explicitListConstraintMap.put(explicitConstraint.indexNum(), source);
// }
// //动态下拉信息
// Class<? extends ExplicitInterface>[] classes = explicitConstraint.sourceClass();
// if (classes.length>0){
// ExplicitInterface explicitInterface = null;
// try {
// explicitInterface = classes[0].newInstance();
// String[] source1 = explicitInterface.source(explicitConstraint.type(),dataDictionaryMapper);
// if (source1.length>0){
// explicitListConstraintMap.put(explicitConstraint.indexNum(), source1);
// }
// } catch (InstantiationException e) {
// e.printStackTrace();
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
// }
// return null;
// }
//
//
//
//
// /**
// * 导出文件时为Writer生成OutputStream
// */
// private static OutputStream getOutputStream(String fileName, HttpServletResponse response, ExcelTypeEnum excelTypeEnum) throws Exception {
// //创建本地文件
// String filePath = fileName + excelTypeEnum.getValue();
// try {
// fileName = new String(filePath.getBytes(), StandardCharsets.ISO_8859_1);
// response.setCharacterEncoding(StandardCharsets.UTF_8.name());
// response.setContentType("application/vnd.ms-excel");
// response.addHeader("Content-Disposition", "filename=" + fileName);
// return response.getOutputStream();
// } catch (IOException e) {
// throw new Exception("系统异常");
// }
// }
//
// /**
// * 创建我的cell 策略
// *
// * @return
// */
// public static HorizontalCellStyleStrategy setMyCellStyle() {
//
//// // 头的策略
//// WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//// // 设置表头居中对齐
//// headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//// // 颜色
//// headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
////
//// WriteFont headWriteFont = new WriteFont();
//// headWriteFont.setFontHeightInPoints((short) 10);
//// // 字体
//// headWriteCellStyle.setWriteFont(headWriteFont);
//// headWriteCellStyle.setWrapped(true);
//// // 内容的策略
//// WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//// // 设置内容靠中对齐
//// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
//// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
//// // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
//// return horizontalCellStyleStrategy;
//
//
// // 表头样式策略
// WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// //设置表头居中对齐
// headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// //表头前景色
// headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
// WriteFont headWriteFont = new WriteFont();
// headWriteFont.setBold(true);
// headWriteFont.setFontName("宋体");
// headWriteFont.setFontHeightInPoints((short) 10);
// headWriteCellStyle.setWriteFont(headWriteFont);
//
// //2 内容样式策略
// WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
// WriteFont contentWriteFont = new WriteFont();
// //内容字体大小
// contentWriteFont.setFontName("宋体");
// contentWriteFont.setFontHeightInPoints((short) 10);
// contentWriteCellStyle.setWriteFont(contentWriteFont);
// //设置自动换行
// contentWriteCellStyle.setWrapped(true);
// //设置垂直居中
// contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// // 头默认了 FillPatternType所以可以不指定。
// // contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
// //设置水平居中
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//
// //设置边框样式
// contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
// contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
// contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
// contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
//
// return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
//
//
//
//
// }
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//import java.lang.annotation.*;
///**
//* 导出模板数据
//*/
//@Documented
//@Retention(RetentionPolicy.RUNTIME)
//@Target({ElementType.FIELD})
//public @interface ExplicitConstraint {
// //定义固定下拉内容
// String[]source()default {};
// //定义动态下拉内容,
// Class[]sourceClass()default {};
// //列标号必须和字段下标一致
// int indexNum() default 0;
// //字典type或接口类型
// String type() default "";
// //从接口获取值时的方法名
// String method() default "";
//
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//
//public interface ExplicitInterface {
// /**
// * 动态下拉列表的内容数组
// * @return
// * type 字典类型
// */
// String[] source(String type,DataDictionaryMapper dataDictionaryMapper);
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//import com.yeejoin.amos.boot.module.common.api.excel.DataSources;
//import com.yeejoin.amos.boot.module.common.api.excel.ExplicitInterface;
//
///***
// *
// * 获取动态值
// *
// * **/
//public class RoleNameExplicitConstraint implements ExplicitInterface {
//
// @Override
// public String[] source(String type, String method, DataSources dataDictionaryMapper) {
//
// return dataDictionaryMapper.selectList(type, method);
// }
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//import com.yeejoin.amos.boot.biz.common.utils.MenuFrom;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.util.List;
//import java.util.stream.Collectors;
//
///***
// *
// * 获取动态值
// *
// * **/
//public class SelectionDataFromInterface implements SelectionDataInterface {
//
//
//
// @Override
// public String[] source(String methodName) {
// switch (methodName) {
// case "getBuildingList":
//// List<MenuFrom> buildingList = equipmentService.getBuildingList();
//// List<String> buildingNameList = buildingList.stream().map(item -> {
//// return item.getName() + "@" + item.getKey();
//// }
//// ).collect(Collectors.toList());
//// String[] buildingNameStr = buildingNameList.toArray(new String[buildingNameList.size()]);
//// return buildingNameStr;
// case "getFireSystemList":
//// List<MenuFrom> fireSystemList = equipmentService.getFireSystemList();
//// List<String> fireSystemNameList = fireSystemList.stream().map(item -> {
//// return item.getName() + "@" + item.getKey();
//// }
//// ).collect(Collectors.toList());
//// String[] fireSystemNameStr = fireSystemNameList.toArray(new String[fireSystemNameList.size()]);
//// return fireSystemNameStr;
// }
// return null;
// }
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//import org.apache.poi.hssf.usermodel.HSSFRichTextString;
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.CellStyle;
//import org.apache.poi.ss.usermodel.DataFormat;
//import org.apache.poi.ss.usermodel.FillPatternType;
//import org.apache.poi.ss.usermodel.Font;
//import org.apache.poi.ss.usermodel.HorizontalAlignment;
//import org.apache.poi.ss.usermodel.IndexedColors;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.VerticalAlignment;
//import org.apache.poi.ss.usermodel.Workbook;
//import com.alibaba.excel.metadata.CellData;
//import com.alibaba.excel.metadata.Head;
//import com.alibaba.excel.write.handler.CellWriteHandler;
//import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
//import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
//
///**
// * excel通用单元格格式类
// */
//public class TemplateCellWriteHandler implements CellWriteHandler {
//
// @Override
// public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
// Head head, int relativeRowIndex, boolean isHead) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData,
// Cell cell, Head head, int relativeRowIndex, boolean isHead) {
// Workbook workbooks = writeSheetHolder.getSheet().getWorkbook();
//
// if (0 == cell.getRowIndex()) {
// writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 20 * 256);
// CellStyle cellStyle = workbooks.createCellStyle();
// cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//居中
// cellStyle.setAlignment(HorizontalAlignment.CENTER);
// cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置前景填充样式
// cellStyle.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex());//前景填充色
// Font font1 = workbooks.createFont();//设置字体
// font1.setBold(true);
// font1.setColor((short)1);
// font1.setFontHeightInPoints((short)15);
// cellStyle.setFont(font1);
// cell.setCellStyle(cellStyle);
// }
//// //其他列
//// if (!isHead){
//// CellStyle style = workbooks.createCellStyle();
//// DataFormat dataFormat = workbooks.createDataFormat();
//// style.setDataFormat(dataFormat.getFormat("@"));
//// style.setVerticalAlignment(VerticalAlignment.CENTER);
//// style.setAlignment(HorizontalAlignment.CENTER);
//// cell.setCellStyle(style);
//// }
//// //设置日期
//// if (!isHead && cell.getColumnIndex()==19 || !isHead && cell.getColumnIndex()==21|| !isHead && cell.getColumnIndex()==20){
//// CellStyle style = workbooks.createCellStyle();
//// DataFormat dataFormat = workbooks.createDataFormat();
//// style.setDataFormat(dataFormat.getFormat("yyyy/mm/dd hh:mm:ss"));
//// style.setVerticalAlignment(VerticalAlignment.CENTER);
//// style.setAlignment(HorizontalAlignment.CENTER);
//// cell.setCellStyle(style);
//// }
//// //设置金额
//// if (!isHead && cell.getColumnIndex()==15 ||!isHead && cell.getColumnIndex()==16||!isHead && cell.getColumnIndex()==22 ||!isHead && cell.getColumnIndex()==24||!isHead && cell.getColumnIndex()==25){
//// CellStyle style = workbooks.createCellStyle();
//// DataFormat dataFormat = workbooks.createDataFormat();
//// style.setDataFormat(dataFormat.getFormat("0.00"));
//// style.setVerticalAlignment(VerticalAlignment.CENTER);
//// style.setAlignment(HorizontalAlignment.CENTER);
//// cell.setCellStyle(style);
//// }
//
// }
//
//
//
//}
//package com.yeejoin.amos.boot.module.jcs.api.excel;
//
//
//import org.apache.poi.ss.usermodel.DataValidationHelper;
//import org.apache.poi.ss.usermodel.Name;
//import org.apache.poi.ss.usermodel.Workbook;
//import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
//import com.alibaba.excel.write.handler.SheetWriteHandler;
//import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
//import org.apache.poi.ss.usermodel.DataValidation;
//import org.apache.poi.ss.usermodel.DataValidationConstraint;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.util.CellRangeAddressList;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * excel通用单元格格式类下拉框赋值
// */
//public class TemplateCellWriteHandlerDate implements SheetWriteHandler {
//
// /**
// * 构造器注入
// */
//
// private Map<Integer, String[]> explicitListConstraintMap = new HashMap<>();
// public TemplateCellWriteHandlerDate(Map<Integer, String[]> explicitListConstraintMap) {
// this.explicitListConstraintMap = explicitListConstraintMap;
// }
// /**
// * 避免生成的导入模板下拉值获取不到
// */
// private static final Integer LIMIT_NUMBER = 50;
//
//
//
// /**
// * 返回excel列标A-Z-AA-ZZ
// *
// * @param num 列数
// * @return java.lang.String
// */
// private String getExcelLine(int num) {
// String line = "";
// int first = num / 26;
// int second = num % 26;
// if (first > 0) {
// line = (char) ('A' + first - 1) + "";
// }
// line += (char) ('A' + second) + "";
// return line;
// }
//
// @Override
// public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
//
// if(explicitListConstraintMap!=null) {
// // 这里可以对cell进行任何操作
// Sheet sheet = writeSheetHolder.getSheet();
// DataValidationHelper helper = sheet.getDataValidationHelper();
//
// // k 为存在下拉数据集的单元格下表 v为下拉数据集
// explicitListConstraintMap.forEach((k, v) -> {
// // 设置下拉单元格的首行 末行 首列 末列
// CellRangeAddressList rangeList = new CellRangeAddressList(1, 65536, k, k);
// // 如果下拉值总数大于100,则使用一个新sheet存储,避免生成的导入模板下拉值获取不到
// if (v.length > LIMIT_NUMBER) {
// //定义sheet的名称
// //1.创建一个隐藏的sheet 名称为 hidden + k
// String sheetName = "hidden" + k;
// Workbook workbook = writeWorkbookHolder.getWorkbook();
// Sheet hiddenSheet = workbook.createSheet(sheetName);
// for (int i = 0, length = v.length; i < length; i++) {
// // 开始的行数i,列数k
// hiddenSheet.createRow(i).createCell(k).setCellValue(v[i]);
// }
// Name category1Name = workbook.createName();
// category1Name.setNameName(sheetName);
// String excelLine = getExcelLine(k);
// // =hidden!$H:$1:$H$50 sheet为hidden的 H1列开始H50行数据获取下拉数组
// String refers = "=" + sheetName + "!$" + excelLine + "$1:$" + excelLine + "$" + (v.length + 1);
// // 将刚才设置的sheet引用到你的下拉列表中
// DataValidationConstraint constraint = helper.createFormulaListConstraint(refers);
// DataValidation dataValidation = helper.createValidation(constraint, rangeList);
// writeSheetHolder.getSheet().addValidationData(dataValidation);
// // 设置存储下拉列值得sheet为隐藏
// int hiddenIndex = workbook.getSheetIndex(sheetName);
// if (!workbook.isSheetHidden(hiddenIndex)) {
// workbook.setSheetHidden(hiddenIndex, true);
// }
// }
// // 下拉列表约束数据
// DataValidationConstraint constraint = helper.createExplicitListConstraint(v);
// // 设置约束
// DataValidation validation = helper.createValidation(constraint, rangeList);
// // 阻止输入非下拉选项的值
// validation.setErrorStyle(DataValidation.ErrorStyle.STOP);
// validation.setShowErrorBox(true);
// validation.setSuppressDropDownArrow(true);
// validation.createErrorBox("提示", "此值与单元格定义格式不一致");
// // validation.createPromptBox("填写说明:","填写内容只能为下拉数据集中的单位,其他单位将会导致无法入仓");
// sheet.addValidationData(validation);
// });
// }
//
//
// }
//
//}
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