提交 71bfa9d9 authored 作者: 133's avatar 133

[exl] 提交新的代码

上级 a385e05b
package com.tykj.dev.device.excel.controller; package com.tykj.dev.device.excel.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.tykj.dev.config.swagger.AutoDocument; import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.excel.entity.DeviceExcel;
import com.tykj.dev.device.excel.entity.TrainExcel; import com.tykj.dev.device.excel.entity.TrainExcel;
import com.tykj.dev.device.excel.entity.TrainUserExcel; import com.tykj.dev.device.excel.entity.TrainUserExcel;
import com.tykj.dev.device.excel.utils.ExcelStyleUtil; import com.tykj.dev.device.excel.utils.ExcelStyleUtil;
...@@ -11,13 +15,17 @@ import com.tykj.dev.device.excel.utils.ExcelUtil; ...@@ -11,13 +15,17 @@ import com.tykj.dev.device.excel.utils.ExcelUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T; import org.apache.poi.ss.formula.functions.T;
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.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -37,29 +45,58 @@ public class ExeclController { ...@@ -37,29 +45,58 @@ public class ExeclController {
@GetMapping(value ="/test") @GetMapping(value ="/test")
@ApiOperation(value = "下载培训excel", notes = "下载培训excel") @ApiOperation(value = "下载培训excel", notes = "下载培训excel")
public ResponseEntity saveDeviceDestroyBill(HttpServletRequest request, HttpServletResponse response){ public ResponseEntity saveDeviceDestroyBill(HttpServletRequest request, HttpServletResponse response){
TrainExcel tableInfoVo = new TrainExcel();
tableInfoVo.setName("xxx培训");
List<TrainUserExcel> tableInfoVos = new ArrayList<>(); List<DeviceExcel> excelList=new ArrayList<>();
for (int i=0;i<6;i++){ for (int i=0;i<6;i++){
TrainUserExcel trainUserExcel=new TrainUserExcel(); DeviceExcel deviceExcel=new DeviceExcel();
trainUserExcel.setIdCard("123123123131"); deviceExcel.setId(i);
trainUserExcel.setMobel("15171636570"); deviceExcel.setLifeStatus(1);
trainUserExcel.setName("占金明"); deviceExcel.setModel("1");
trainUserExcel.setSex("男"); excelList.add(deviceExcel);
trainUserExcel.setNumber(i);
tableInfoVos.add(trainUserExcel);
} }
tableInfoVo.setTrainUserExcels(tableInfoVos);
List<TrainExcel> list=new ArrayList<>(); ExportParams exportParams = new ExportParams("xxx","xxx", ExcelType.XSSF);
list.add(tableInfoVo);
ExportParams exportParams = new ExportParams(tableInfoVo.getName(), tableInfoVo.getName(), ExcelType.XSSF);
exportParams.setSecondTitle(tableInfoVo.getName());
exportParams.setStyle(ExcelStyleUtil.class); exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, TrainExcel.class, list); Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcel.class, excelList);
ExcelUtil.downloadExcel(request, response, workbook, tableInfoVo.getName()); ExcelUtil.downloadExcel(request, response, workbook, "xxx");
// List<TrainUserExcel> tableInfoVos = new ArrayList<>();
// for (int i=0;i<6;i++){
// TrainUserExcel trainUserExcel=new TrainUserExcel();
// trainUserExcel.setIdCard("123123123131");
// trainUserExcel.setMobel("15171636570");
// trainUserExcel.setName("占金明");
// trainUserExcel.setSex("男");
// trainUserExcel.setNumber(i);
// tableInfoVos.add(trainUserExcel);
// }
// ExportParams exportParams = new ExportParams("xxx","xxx", ExcelType.XSSF);
// exportParams.setStyle(ExcelStyleUtil.class);
// Workbook workbook = ExcelExportUtil.exportExcel(exportParams, TrainUserExcel.class, tableInfoVos);
// ExcelUtil.downloadExcel(request, response, workbook, "xxx");
return ResponseEntity.ok("ok"); return ResponseEntity.ok("ok");
} }
@PostMapping(value ="/test1")
@ApiOperation(value = "下载培训excel", notes = "下载培训excel")
public ResponseEntity importExcel(MultipartFile file) throws Exception {
ImportParams params = new ImportParams();
params.setTitleRows(1);
params.setHeadRows(1);
// 开启Excel校验
// params.setNeedVerfiy(true);
// params.setVerifyHandler(excelVerifyHandle);
Workbook workbook = WorkbookFactory.create(file.getInputStream());
Sheet sheet = workbook.getSheet(workbook.getSheetName(0));
//获取第一行
// Row titlerow = sheet.getRow(0);
// String tableName = titlerow.getCell(0).getStringCellValue();
ExcelImportResult<DeviceExcel> result = ExcelImportUtil.importExcelMore(file.getInputStream(), DeviceExcel.class,
params);
List<DeviceExcel> deviceExcels= result.getList();
return ResponseEntity.ok(deviceExcels.size());
}
} }
package com.tykj.dev.device.excel.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
/**
* entity class for device_library
* 装备库
*/
@Data
@ApiModel("装备库")
@AllArgsConstructor
@NoArgsConstructor
public class DeviceExcel {
/**
* 主键id
*/
@Id
@Excel(name = "id", orderNum = "1", width = 30, needMerge = true)
private Integer id;
/**
* 型号
*/
@ApiModelProperty(value = "型号")
@Excel(name = "型号", orderNum = "1", width = 30, needMerge = true)
private String model;
/**
* 密级
*/
@ApiModelProperty(value = "密级")
@Excel(name = "密级", orderNum = "1", width = 30, needMerge = true)
private Integer secretLevel;
/**
* 装备名称
*/
@ApiModelProperty(value = "装备名称")
@Excel(name = "装备名称", orderNum = "1", width = 30, needMerge = true)
private String name;
/**
* 装备序列号
*/
@ApiModelProperty(value = "装备序列号")
@Excel(name = "装备序列号", orderNum = "1", width = 30, needMerge = true)
private String seqNumber;
/**
* rfid表面号
*/
@ApiModelProperty(value = "rfid表面号")
@Excel(name = "rfid表面号", orderNum = "1", width = 30, needMerge = true)
private String rfidSurfaceId;
/**
* 类型
*/
@ApiModelProperty(value = "类型")
@Excel(name = "类型", orderNum = "1", width = 30, needMerge = true)
private Integer type;
/**
* 生命状态,0-入库待审核,1-入库审核失败,2-在库,3-配发,4-维修,5,维修失败,6-退回,7-待退装,8-退装,9-待销毁,10-已销毁,11-丢失 12.清退
*/
@ApiModelProperty(value = "生命状态,0-入库待审核,1-入库审核失败,2-在库,3-配发,4-维修,5,维修失败,6-退回,7-待退装,8-退装,9-待销毁,10-已销毁,11-丢失")
@Excel(name = "生命状态", orderNum = "1", width = 30, needMerge = true)
private Integer lifeStatus;
}
...@@ -19,8 +19,6 @@ import java.util.List; ...@@ -19,8 +19,6 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class TrainExcel { public class TrainExcel {
@Excel(name = "培训标题", orderNum = "1", width = 30, needMerge = true)
private String name;
@ExcelCollection(name = "参加培训用户信息", orderNum = "2") @ExcelCollection(name = "参加培训用户信息", orderNum = "2")
private List<TrainUserExcel> trainUserExcels; private List<TrainUserExcel> trainUserExcels;
......
...@@ -9,13 +9,14 @@ import lombok.NoArgsConstructor; ...@@ -9,13 +9,14 @@ import lombok.NoArgsConstructor;
* @author zjm * @author zjm
* @version 1.0.0 * @version 1.0.0
* @ClassName TrainExcel.java * @ClassName TrainExcel.java
* @Description TODO * @Description excel导出实体类
* @createTime 2021年04月29日 15:22:00 * @createTime 2021年04月29日 15:22:00
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class TrainUserExcel { public class TrainUserExcel {
@Excel(name = "序号", orderNum = "1", width = 30, needMerge = true) @Excel(name = "序号", orderNum = "1", width = 30, needMerge = true)
private Integer number; private Integer number;
...@@ -33,4 +34,12 @@ public class TrainUserExcel { ...@@ -33,4 +34,12 @@ public class TrainUserExcel {
@Excel(name = "身份证", orderNum = "6", width = 30, needMerge = true) @Excel(name = "身份证", orderNum = "6", width = 30, needMerge = true)
private String idCard; private String idCard;
@Excel(name = "房间号", orderNum = "6", width = 30, needMerge = true)
private String roomCode;
@Excel(name = "备注", orderNum = "6", width = 30, needMerge = true)
private String des;
} }
...@@ -18,6 +18,7 @@ import java.util.List; ...@@ -18,6 +18,7 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
@Data @Data
public class Confirm { public class Confirm {
@ApiModelProperty(name = "抬头") @ApiModelProperty(name = "抬头")
private String title; private String title;
......
...@@ -49,6 +49,9 @@ public class DocumentDevice { ...@@ -49,6 +49,9 @@ public class DocumentDevice {
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
@ApiModelProperty(value = "校对")
private String proofreading;
public Integer getLen(){ public Integer getLen(){
return deviceSerialNumber.length(); return deviceSerialNumber.length();
} }
......
...@@ -37,6 +37,7 @@ public class PdfServiceImpl implements PdfService { ...@@ -37,6 +37,7 @@ public class PdfServiceImpl implements PdfService {
} }
private DocumentDevice toDocDev(ScriptSaveVo scriptSaveVo){ private DocumentDevice toDocDev(ScriptSaveVo scriptSaveVo){
return new DocumentDevice(null,scriptSaveVo.getModel(),null,scriptSaveVo.getType(),scriptSaveVo.getSecretLevel(),scriptSaveVo.getInvisibleRange(),scriptSaveVo.getNum(),scriptSaveVo.getSeqNumber(),null,scriptSaveVo.getRemark()); return new DocumentDevice(null,scriptSaveVo.getModel(),null,scriptSaveVo.getType(),scriptSaveVo.getSecretLevel(),scriptSaveVo.getInvisibleRange(),scriptSaveVo.getNum(),scriptSaveVo.getSeqNumber(),null,scriptSaveVo.getRemark(),null);
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论