2 Commits 9fbbc581d3 ... 1ad1272586

Auteur SHA1 Bericht Datum
  ‘xugp 1ad1272586 Merge remote-tracking branch 'origin/master' 1 jaar geleden
  ‘xugp 7b23b1f0c6 党建乘数导入,导出 1 jaar geleden

+ 114 - 5
ims-service/ims-eval/src/main/java/com/ims/eval/controller/PartyBuildingMultiplierController.java

@@ -2,23 +2,27 @@ package com.ims.eval.controller;
 
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.ims.eval.cache.CacheContext;
 import com.ims.eval.config.CustomException;
-import com.ims.eval.entity.BinStage;
-import com.ims.eval.entity.Indicator;
 import com.ims.eval.entity.PartyBuildingMultiplier;
 import com.ims.eval.entity.dto.result.R;
-import com.ims.eval.service.IBinStageService;
 import com.ims.eval.service.IPartyBuildingMultiplierService;
+import com.ims.eval.util.ExcelUtil;
+import com.ims.eval.util.ExcelUtils;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.beans.IntrospectionException;
+import java.io.*;
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -60,6 +64,111 @@ public class PartyBuildingMultiplierController {
 
 	}
 
+	/**
+	 * 查询
+	 *
+	 * @param id         主键ID
+	 * @param departId     部门id
+	 * @param sectionId   板块id
+	 * @param year       年度
+	 * @return
+	 */
+	@GetMapping(value = "/export1")
+	public void export1(HttpServletResponse response,
+				  @RequestParam(value = "id", required = false) String id,
+				  @RequestParam(value = "departId", required = false) String departId,
+				  @RequestParam(value = "sectionId", required = false) String sectionId,
+				  @RequestParam(value = "year", required = false) String year) throws IOException, IllegalAccessException, IntrospectionException, InvocationTargetException {
+
+		List<PartyBuildingMultiplier> list = iPartyBuildingMultiplierService.listByParam(id, departId, sectionId, year);
+		if (list.size() > 0){
+			OutputStream out = response.getOutputStream();
+			List<String> titleList = new ArrayList<>();
+			titleList.add("id");
+			titleList.add("单位名称");
+			titleList.add("板块名称");
+			titleList.add("党建乘数");
+			titleList.add("年度");
+			titleList.add("备注");
+			HSSFWorkbook workBook = ExcelUtils.getWorkBook(titleList, list);
+			//响应到客户端
+			try {
+				this.setResponseHeader(response, "党建乘数.xls");
+				OutputStream os = response.getOutputStream();
+				BufferedOutputStream bufferOutput =new BufferedOutputStream(os);
+				bufferOutput.flush();
+				workBook.write(bufferOutput);
+				bufferOutput.close();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}else {
+			throw new CustomException("党建乘数数据为空!");
+		}
+	}
+
+	/**
+	 * 发送响应流方法
+	 */
+	public void setResponseHeader(HttpServletResponse response, String fileName) {
+		try {
+			try {
+				fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
+			} catch (UnsupportedEncodingException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+			response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+			response.addHeader("Pargam", "no-cache");
+			response.addHeader("Cache-Control", "no-cache");
+			response.setHeader("Expires", " 0");
+		} catch (Exception ex) {
+			ex.printStackTrace();
+		}
+	}
+
+
+	@PostMapping(value = "/import")
+	@ResponseBody
+	public R importAlertrule(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
+
+		if (!file.isEmpty()) {
+			try {
+				//获取原始的文件名
+				String originalFilename = file.getOriginalFilename();
+				//获取文件类型
+				String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
+				//默认从第一行开始读取
+				Integer startRows = 1;
+				//获取输入流
+				InputStream is = file.getInputStream();
+				List<PartyBuildingMultiplier> bindingList = new ArrayList<>();
+				//Excel导入导出的单元类
+				List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
+				//遍历Excel表每一行的数据
+				for (String[] str : strings) {
+					PartyBuildingMultiplier partyBuildingMultiplier = new PartyBuildingMultiplier();
+					partyBuildingMultiplier.setId(str[0]);
+					partyBuildingMultiplier.setMultiplier(str[3]);
+					partyBuildingMultiplier.setYear(str[4]);
+					partyBuildingMultiplier.setRemarks(str[5]);
+					bindingList.add(partyBuildingMultiplier);
+				}
+				boolean b = iPartyBuildingMultiplierService.saveOrUpdateBatch(bindingList);
+				if (b) {
+					return R.ok().data(b);
+				} else {
+					return R.error().data("保存失败!");
+				}
+			} catch (Exception e) {
+				log.error("错误", e);
+				return R.customError(e.getMessage()).data("失败!");
+			}
+		}
+		return R.customError("上传文件为空!");
+	}
+
 
 	/**
 	 * 添加

+ 58 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/controller/YearOperatingCoefficientController.java

@@ -4,6 +4,7 @@ package com.ims.eval.controller;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ims.eval.config.CustomException;
 import com.ims.eval.entity.Indicator;
+import com.ims.eval.entity.OrganizationEvaluationInfo;
 import com.ims.eval.entity.YearGroupCoefficient;
 import com.ims.eval.entity.YearOperatingCoefficient;
 import com.ims.eval.entity.dto.request.IndicatorDictionaryDTO;
@@ -13,12 +14,18 @@ import com.ims.eval.service.IIndicatorDictionaryService;
 import com.ims.eval.service.IIndicatorService;
 import com.ims.eval.service.IYearGroupCoefficientService;
 import com.ims.eval.service.IYearOperatingCoefficientService;
+import com.ims.eval.util.ExcelUtil;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -138,4 +145,55 @@ public class YearOperatingCoefficientController {
 		}
 	}
 
+	@PostMapping(value = "/import")
+	@ResponseBody
+	public R importAlertrule(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
+
+		if (!file.isEmpty()) {
+			try {
+				//获取原始的文件名
+				String originalFilename = file.getOriginalFilename();
+				//获取文件类型
+				String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
+				//默认从第一行开始读取
+				Integer startRows = 2;
+				//获取输入流
+				InputStream is = file.getInputStream();
+				List<YearOperatingCoefficient> bindingList = new ArrayList<>();
+				//Excel导入导出的单元类
+				List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
+				//遍历Excel表每一行的数据
+				SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+				for (String[] str : strings) {
+					YearOperatingCoefficient y = new YearOperatingCoefficient();
+					y.setId(str[0]);
+					y.setOrganizationName(str[1]);
+					y.setZzc(Double.parseDouble(str[2]));
+					y.setK1(Double.parseDouble(str[3]));
+					y.setJzs(Double.parseDouble(str[4]));
+					y.setK2(Double.parseDouble(str[5]));
+					y.setZmlrze(Double.parseDouble(str[6]));
+					y.setFdl(Double.parseDouble(str[7]));
+					y.setDdlr(Double.parseDouble(str[8]));
+					y.setK3(Double.parseDouble(str[9]));
+					y.setDy(Double.parseDouble(str[10]));
+					y.setK4(Double.parseDouble(str[11]));
+					y.setK(Double.parseDouble(str[12]));
+					y.setCreateName(str[13]);
+					y.setCreateTime(simpleDateFormat.parse(str[14]));
+					bindingList.add(y);
+				}
+				boolean b = yearOperatingCoefficientService.saveOrUpdateBatch(bindingList);
+				if (b) {
+					return R.ok().data(b);
+				} else {
+					return R.error().data("保存失败!");
+				}
+			} catch (Exception e) {
+				return R.customError(e.getMessage()).data("失败!");
+			}
+		}
+		return R.customError("上传文件为空!");
+	}
+
 }

+ 9 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/PartyBuildingMultiplier.java

@@ -2,6 +2,8 @@ package com.ims.eval.entity;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.ims.eval.util.EnableExcel;
+import com.ims.eval.util.ExcelRow;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -14,6 +16,7 @@ import lombok.EqualsAndHashCode;
  * @since 2023-03-29
  */
 @Data
+@EnableExcel
 @EqualsAndHashCode(callSuper = true)
 public class PartyBuildingMultiplier extends Model {
 
@@ -22,6 +25,7 @@ public class PartyBuildingMultiplier extends Model {
     /**
      * 主键id
      */
+	@ExcelRow(name = "id")
     private String id;
 
     /**
@@ -33,6 +37,7 @@ public class PartyBuildingMultiplier extends Model {
 	/**
 	 * 单位名称
 	 */
+	@ExcelRow(name = "单位名称")
     private String organizationName;
 
 
@@ -44,22 +49,26 @@ public class PartyBuildingMultiplier extends Model {
 	/**
 	 * 板块名称
 	 */
+	@ExcelRow(name = "板块名称")
 	@TableField(exist = false)
 	private String sectionName;
 
     /**
      * 党建乘数
      */
+	@ExcelRow(name = "党建乘数")
     private String multiplier;
 
     /**
      * 备注
      */
+	@ExcelRow(name = "备注")
     private String remarks;
 
     /**
      * 年度
      */
+	@ExcelRow(name = "年度")
     private String year;
 
 	/**

+ 5 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/YearOperatingCoefficient.java

@@ -121,6 +121,11 @@ public class YearOperatingCoefficient extends Model {
      */
     private String createBy;
 
+	/**
+	 * 创建者名称
+	 */
+	private String createName;
+
     /**
      * 更新时间
      */

+ 54 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/dto/response/PartyBuildingMultiplierDto.java

@@ -0,0 +1,54 @@
+package com.ims.eval.entity.dto.response;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 党建乘数配置
+ * </p>
+ *
+ * @author xugp
+ * @since 2023-03-29
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class PartyBuildingMultiplierDto extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键id
+     */
+    private String id;
+
+
+	/**
+	 * 单位名称
+	 */
+    private String organizationName;
+
+
+	/**
+	 * 板块名称
+	 */
+	private String sectionName;
+
+    /**
+     * 党建乘数
+     */
+    private String multiplier;
+
+
+    /**
+     * 年度
+     */
+    private String year;
+
+
+
+
+
+}

+ 5 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IPartyBuildingMultiplierService.java

@@ -3,6 +3,9 @@ package com.ims.eval.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ims.eval.entity.PartyBuildingMultiplier;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.ims.eval.entity.dto.response.PartyBuildingMultiplierDto;
+
+import java.util.List;
 
 /**
  * <p>
@@ -15,4 +18,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IPartyBuildingMultiplierService extends IService<PartyBuildingMultiplier> {
 
     IPage<PartyBuildingMultiplier> listAll(Integer pageNum,Integer pageSize,String id, String departId, String sectionId, String year);
+
+    List<PartyBuildingMultiplier> listByParam(String id, String departId, String sectionId, String year);
 }

+ 29 - 3
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/PartyBuildingMultiplierServiceImpl.java

@@ -5,17 +5,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ims.common.utils.StringUtils;
 import com.ims.eval.config.CustomException;
-import com.ims.eval.dao.OrganizationStructureMapper;
-import com.ims.eval.entity.OrganizationStructure;
 import com.ims.eval.entity.PartyBuildingMultiplier;
 import com.ims.eval.dao.PartyBuildingMultiplierMapper;
-import com.ims.eval.service.IOrganizationEvaluationService;
+import com.ims.eval.entity.dto.response.PartyBuildingMultiplierDto;
 import com.ims.eval.service.IOrganizationStructureService;
 import com.ims.eval.service.IPartyBuildingMultiplierService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -50,4 +49,31 @@ public class PartyBuildingMultiplierServiceImpl extends ServiceImpl<PartyBuildin
 		return list;
 
 	}
+
+	@Override
+	public List<PartyBuildingMultiplier> listByParam(String id, String departId, String sectionId, String year) {
+
+		List<PartyBuildingMultiplierDto> list = new ArrayList<>();
+
+		QueryWrapper<PartyBuildingMultiplier> qw = new QueryWrapper<>();
+
+		if (StringUtils.isNotEmpty(id)) {
+			qw.lambda().eq(PartyBuildingMultiplier::getId, id);
+		}
+
+		if (StringUtils.isNotEmpty(departId)) {
+			qw.lambda().eq(PartyBuildingMultiplier::getDepartId, departId);
+		}
+
+		if (StringUtils.isNotEmpty(sectionId)) {
+			qw.lambda().eq(PartyBuildingMultiplier::getSectionId, sectionId);
+		}
+
+		if (StringUtils.isNotEmpty(year)) {
+			qw.lambda().eq(PartyBuildingMultiplier::getYear, year);
+		}
+
+		List<PartyBuildingMultiplier> partyBuildingMultipliers = baseMapper.selectList(qw);
+		return partyBuildingMultipliers;
+	}
 }

+ 17 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/util/EnableExcel.java

@@ -0,0 +1,17 @@
+package com.ims.eval.util;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *  标记类是否开启Excel
+ * @Author: xugp
+ * @date: 2023/5/10 20:29
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface EnableExcel {
+}

+ 28 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/util/ExcelRow.java

@@ -0,0 +1,28 @@
+package com.ims.eval.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *  excel 表格 列名注解
+ *
+ * @author xugp
+ */
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelRow {
+
+	/**
+	 *  Excel 对应列名
+	 * @return
+	 */
+	String name();
+
+	/**
+	 *  excel 列名备注
+	 * @return
+	 */
+	String note() default "";
+}

+ 137 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/util/ExcelUtil.java

@@ -7,6 +7,7 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -14,6 +15,20 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.util.CellRangeAddress;
 
 public class ExcelUtil {
 
@@ -144,4 +159,126 @@ public class ExcelUtil {
         }
         return str.substring(0, length);
     }
+
+	public static byte[] export(String sheetTitle, String[] title, List<Object> list) {
+
+		HSSFWorkbook wb = new HSSFWorkbook();//创建excel表
+		HSSFSheet sheet = wb.createSheet(sheetTitle);
+		sheet.setDefaultColumnWidth(20);//设置默认行宽
+
+		//表头样式(加粗,水平居中,垂直居中)
+		HSSFCellStyle cellStyle = wb.createCellStyle();
+		cellStyle.setAlignment(HSSFCellStyle.ALIGN_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);//右边框
+
+		HSSFFont fontStyle = wb.createFont();
+		fontStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+
+		cellStyle.setFont(fontStyle);
+
+		//标题样式(加粗,垂直居中)
+		HSSFCellStyle cellStyle2 = wb.createCellStyle();
+		cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
+		cellStyle2.setFont(fontStyle);
+
+		//设置边框样式
+		cellStyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
+		cellStyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
+		cellStyle2.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
+		cellStyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
+
+		//字段样式(垂直居中)
+		HSSFCellStyle cellStyle3 = wb.createCellStyle();
+		cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
+
+		//设置边框样式
+		cellStyle3.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
+		cellStyle3.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
+		cellStyle3.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
+		cellStyle3.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
+
+		//创建表头
+		HSSFRow row = sheet.createRow(0);
+		row.setHeightInPoints(20);//行高
+
+		HSSFCell cell = row.createCell(0);
+		cell.setCellValue(sheetTitle);
+		cell.setCellStyle(cellStyle);
+
+		sheet.addMergedRegion(new CellRangeAddress(0,0,0,(title.length-1)));
+
+		//创建标题
+		HSSFRow rowTitle = sheet.createRow(1);
+		rowTitle.setHeightInPoints(20);
+
+		HSSFCell hc;
+		for (int i = 0; i < title.length; i++) {
+			hc = rowTitle.createCell(i);
+			hc.setCellValue(title[i]);
+			hc.setCellStyle(cellStyle2);
+		}
+
+		byte result[] = null;
+
+		ByteArrayOutputStream out = null;
+
+		try {
+			//创建表格数据
+			Field[] fields;
+			int i = 2;
+
+			for (Object obj : list) {
+				fields = obj.getClass().getDeclaredFields();
+
+				HSSFRow rowBody = sheet.createRow(i);
+				rowBody.setHeightInPoints(20);
+
+				int j = 0;
+				for (Field f : fields) {
+
+					f.setAccessible(true);
+
+					Object va = f.get(obj);
+					if (null == va) {
+						va = "";
+					}
+
+					hc = rowBody.createCell(j);
+					hc.setCellValue(va.toString());
+					hc.setCellStyle(cellStyle3);
+
+					j++;
+				}
+
+				i++;
+			}
+
+			out = new ByteArrayOutputStream();
+			wb.write(out);
+			result =  out.toByteArray();
+		} catch (Exception ex) {
+			Logger.getLogger(ExcelUtil.class.getName()).log(Level.SEVERE, null, ex);
+		} finally{
+			try {
+				if(null != out){
+					out.close();
+				}
+			} catch (IOException ex) {
+				Logger.getLogger(ExcelUtil.class.getName()).log(Level.SEVERE, null, ex);
+			} finally{
+				try {
+					wb.close();
+				} catch (IOException ex) {
+					Logger.getLogger(ExcelUtil.class.getName()).log(Level.SEVERE, null, ex);
+				}
+			}
+		}
+
+		return result;
+	}
 }

+ 131 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/util/ExcelUtils.java

@@ -0,0 +1,131 @@
+package com.ims.eval.util;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author :xugp
+ * @date :Created in 2023/4/14 10:42
+ * @description:
+ * @modified By:
+ * @version: $
+ */
+public class ExcelUtils {
+
+	/**
+	 *  workbook
+	 * @param titleList
+	 * @return
+	 */
+	public static HSSFWorkbook getWorkBook(List<String> titleList){
+		//第一步,创建一个workbook,对应一个Excel文件
+		HSSFWorkbook wb = new HSSFWorkbook();
+		// 一个sheet
+		HSSFSheet sheet = wb.createSheet("sheet1");
+
+		HSSFRow rowTitle = sheet.createRow(0); // 第一行 标题
+
+		// 设置标题
+		for (int i = 0; i < titleList.size(); i++) {
+			HSSFCell cell = rowTitle.createCell(i);
+			cell.setCellValue(titleList.get(i));
+		}
+		//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
+        /*sheet.addMergedRegion(new CellRangeAddress(0,0,0,4));
+        sheet.addMergedRegion(new CellRangeAddress(titleList.size()-1,titleList.size()-1,titleList.size()-1,titleList.size()+1));*/
+		return wb;
+	}
+
+
+	public static <T> HSSFWorkbook getWorkBook(List<String> titleList , List<T> dataList) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
+		if (CollectionUtils.isNotEmpty(dataList)) {
+			T t1 = dataList.get(0);
+			Class<?> t1Class = t1.getClass();
+			EnableExcel enableExcel = t1Class.getAnnotation(EnableExcel.class);
+			if (enableExcel == null) {
+				throw new IllegalArgumentException("EnableExcel 注解没有在实体类启用");
+			}
+			Field[] fields = t1Class.getDeclaredFields();
+			if (fields != null && fields.length > 0) {
+				Map<String , Integer> titleMap = new HashMap<>(titleList.size()); // 存放属性名称对应的下标
+
+				int fieldExcelSize = 0; // 类中ExcelRow 注解的数量
+				for (Field field : fields) {
+					field.setAccessible(true);
+					String fieldName = field.getName();
+					ExcelRow excelRow = field.getAnnotation(ExcelRow.class);
+					if (excelRow != null) {
+						String name = excelRow.name();
+						if (StringUtils.isEmpty(name)) {
+							throw new IllegalArgumentException("ExcelRow 注解name属性不能为空");
+						}
+
+						int index = titleList.indexOf(name.trim());
+						if (index != -1) {
+							fieldExcelSize++;
+							titleMap.put(fieldName , index);
+						}
+					}
+				}
+
+				if (!(titleList.size() == fieldExcelSize)) {
+					throw new IllegalArgumentException("ExcelRow 注解name属性对应的列数不对");
+				}
+
+				HSSFWorkbook workBook = getWorkBook(titleList);
+				HSSFSheet sheet = workBook.getSheetAt(0);
+
+				for (T t : dataList) {
+					int lastRowNum = sheet.getLastRowNum();
+					HSSFRow row = sheet.createRow(lastRowNum + 1);
+					BeanInfo beanInfo = Introspector.getBeanInfo(t.getClass());
+					PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+					for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+						String fieldName = propertyDescriptor.getName();
+						if (titleMap.containsKey(fieldName)) {
+							Method readMethod = propertyDescriptor.getReadMethod();
+							if (readMethod != null) {
+								Class<?> returnType = readMethod.getReturnType();
+								String simpleName = returnType.getSimpleName();
+
+								Object invoke = readMethod.invoke(t);
+								String value = "";
+								// 可以根据不同的类型返回不同的数据
+								if ("date".equalsIgnoreCase(simpleName)) {
+									SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+									if (invoke != null) {
+										value = simpleDateFormat.format(invoke);
+									}
+								}
+								if (invoke != null && "".equals(value)) {
+									value = invoke.toString();
+								}
+								row.createCell(titleMap.get(fieldName)).setCellValue(value);
+							}
+						}
+					}
+				}
+				return workBook;
+			}
+		}
+		return null;
+	}
+}
+
+