bug修复==》 表单内 3.1 和 部分3.2 bug修复

This commit is contained in:
yuezhihang
2022-03-01 14:45:32 +08:00
parent 5316e6aeb3
commit dbaf142f03
4 changed files with 327 additions and 7 deletions
@@ -0,0 +1,52 @@
package com.adc.da.slrs.processModel.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
@Data
public class importExcelDTO {
@Excel(name = "企标类别" ,orderNum = "0" , width = 20.0 )
private String bussSort;
private String bussSortId;
@Excel(name = "企标名称",orderNum = "1", width = 20.0)
private String esName;
private String esNameId;
@Excel(name = "制修订类型",orderNum = "2", width = 20.0)
private String reviseStatus;
private String reviseStatusId;
@Excel(name = "起草责任单位" , orderNum = "3", width = 20.0)
private String unitName;
private String unit;
@Excel(name = "起草人" , orderNum = "4", width = 20.0)
private String drafterName;
private String drafter;
@Excel(name = "评审责任人" , orderNum = "5", width = 20.0)
private String resPersonName;
private String resPerson;
@Excel(name = "工作组组长" , orderNum = "6", width = 20.0)
private String wgLeaderName;
private String wgLeader;
@Excel(name = "计划初稿完成日期" , orderNum = "7", width = 20.0)
private String draftTime;
@Excel(name = "计划标准发布时间", orderNum = "8", width = 18.0)
private String releaseTime;
@Excel(name = "立项完成时间" ,orderNum = "9", width = 18.0)
private String endTime;
}
@@ -4,27 +4,34 @@ import com.adc.da.excel.poi.excel.entity.ExportParams;
import com.adc.da.excel.poi.excel.entity.enums.ExcelType;
import com.adc.da.slrs.msgDynamicInfo.common.ReadExcel;
import com.adc.da.slrs.processModel.entity.exportExcel;
import com.adc.da.slrs.processModel.entity.importExcelDTO;
import com.adc.da.slrs.processModel.utils.ExcelExportUtilByWk;
import com.adc.da.slrs.processModel.utils.ExcelImportUtilByWk;
import com.adc.da.slrs.standardSplit.entity.SarFileSplitInfoEO;
import com.adc.da.slrs.standardSplit.entity.SarFileSplitItemsEO;
import com.adc.da.sys.service.IDicTypeEOService;
import com.adc.da.util.exception.AdcDaBaseException;
import com.adc.da.util.http.ResponseMessage;
import com.adc.da.util.http.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@Api(description = "|SapMeeting|")
@RequestMapping("/api/exportWkExcel")
@RequestMapping("/api/importWkExcel")
public class exportWkExcel {
@@ -32,17 +39,17 @@ public class exportWkExcel {
private IDicTypeEOService dicTypeEOService;
@ApiOperation(value = "|SysCorpEO|导出excel")
@GetMapping(value = "/exportqbzxdjh")
@PostMapping(value = "/exportqbzxdjh")
public void exportMsgDynamicInfoExcel( HttpServletResponse response, HttpServletRequest request) {
OutputStream os = null;
HSSFWorkbook workbook = null;
try {
String exportName="企标制修订计划模板";
response.setHeader("Content-Disposition",
"attachment; filename=" + ReadExcel.encodeFileName(exportName+".xlsx", request));
"attachment; filename=" + ReadExcel.encodeFileName(exportName+".xls", request));
response.setContentType("application/force-download");
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
exportParams.setType(ExcelType.HSSF);
exportParams.setSheetName(exportName);
Map<String, Object> dicTypeEO = dicTypeEOService.getDicTypeListCode();
@@ -56,4 +63,15 @@ public class exportWkExcel {
IOUtils.closeQuietly(os);
}
}
@ApiOperation(value = "|SarFileSplitItemsEO|导入")
@PostMapping(value = "/importData")
public ResponseMessage<List<importExcelDTO>> importSplitItemsZip(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
List<importExcelDTO> res =new ArrayList<>();
Map<String, Object> dicTypeEO = dicTypeEOService.getDicTypeListCode();
ExcelImportUtilByWk.readExcel(file);
return Result.success(res);
}
}
@@ -0,0 +1,232 @@
package com.adc.da.slrs.processModel.utils;
import com.adc.da.slrs.processModel.entity.importExcelDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
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.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class ExcelImportUtilByWk {
private static final String XLS = "xls";
private static final String XLSX = "xlsx";
/**
* 读取Excel文件内容
* @param file 上传的Excel文件
* @return 读取结果列表,读取失败时返回null
*/
public static List<importExcelDTO> readExcel(MultipartFile file) {
Workbook workbook = null;
try {
// 获取Excel后缀名
String fileName = file.getOriginalFilename();
if (fileName == null || fileName.isEmpty() || fileName.lastIndexOf(".") < 0) {
log.warn("解析Excel失败,因为获取到的Excel文件名非法!");
return null;
}
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
// 获取Excel工作簿
workbook = getWorkbook(file.getInputStream(), fileType);
// 读取excel中的数据
List<importExcelDTO> resultDataList = parseExcel(workbook);
return resultDataList;
} catch (Exception e) {
log.warn("解析Excel失败,文件名:" + file.getOriginalFilename() + " 错误信息:" + e.getMessage());
return null;
} finally {
try {
if (null != workbook) {
workbook.close();
}
} catch (Exception e) {
log.warn("关闭数据流出错!错误信息:" + e.getMessage());
return null;
}
}
}
/**
* 根据文件后缀名类型获取对应的工作簿对象
* @param inputStream 读取文件的输入流
* @param fileType 文件后缀名类型(xls或xlsx
* @return 包含文件数据的工作簿对象
* @throws
*/
public static Workbook getWorkbook(InputStream inputStream, String fileType) throws IOException {
Workbook workbook = null;
if (fileType.equalsIgnoreCase(XLS)) {
workbook = new HSSFWorkbook(inputStream);
} else if (fileType.equalsIgnoreCase(XLSX)) {
workbook = new XSSFWorkbook(inputStream);
}
return workbook;
}
/**
* 解析Excel数据
* @param workbook Excel工作簿对象
* @return 解析结果
*/
private static List<importExcelDTO> parseExcel(Workbook workbook) {
List<importExcelDTO> resultDataList = new ArrayList<>();
// 解析sheet
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
Sheet sheet = workbook.getSheetAt(sheetNum);
// 校验sheet是否合法
if (sheet == null) {
continue;
}
// 获取第一行数据
int firstRowNum = sheet.getFirstRowNum();
Row firstRow = sheet.getRow(firstRowNum);
if (null == firstRow) {
log.warn("解析Excel失败,在第一行没有读取到任何数据!");
}
// 解析每一行的数据,构造数据对象
int rowStart = firstRowNum + 1;
int rowEnd = sheet.getPhysicalNumberOfRows();
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
Row row = sheet.getRow(rowNum);
if (null == row) {
continue;
}
importExcelDTO resultData = convertRowToData(row);
if (null == resultData) {
log.warn("" + row.getRowNum() + "行数据不合法,已忽略!");
continue;
}
resultDataList.add(resultData);
}
}
return resultDataList;
}
/**
* 提取每一行中需要的数据,构造成为一个结果数据对象
*
* 当该行中有单元格的数据为空或不合法时,忽略该行的数据
*
* @param row 行数据
* @return 解析后的行数据对象,行数据错误时返回null
*/
private static importExcelDTO convertRowToData(Row row) {
importExcelDTO resultData = new importExcelDTO();
Cell cell;
int cellNum = 0;
// 获取企标类型
cell = row.getCell(cellNum++);
String bussSort = convertCellValueToString(cell);
resultData.setBussSort(bussSort);
// 获取企标名称
cell = row.getCell(cellNum++);
String esName = convertCellValueToString(cell);
resultData.setEsName(esName);
//获取制修订类型
cell = row.getCell(cellNum++);
String reviseStatus = convertCellValueToString(cell);
resultData.setReviseStatus(reviseStatus);
//获取起草责任单位
cell = row.getCell(cellNum++);
String unitName = convertCellValueToString(cell);
resultData.setUnitName(unitName);
//获取起草人
cell = row.getCell(cellNum++);
String drafterName = convertCellValueToString(cell);
resultData.setDrafterName(drafterName);
//获取评审责任人
cell = row.getCell(cellNum++);
String resPersonName = convertCellValueToString(cell);
resultData.setResPersonName(resPersonName);
//获取工作组组长
cell = row.getCell(cellNum++);
String wgLeaderName = convertCellValueToString(cell);
resultData.setWgLeaderName(wgLeaderName);
//获取计划初稿完成日期
cell = row.getCell(cellNum++);
String draftTime = convertCellValueToString(cell);
resultData.setDraftTime(draftTime);
//获取计划标准发布时间
cell = row.getCell(cellNum++);
String releaseTime = convertCellValueToString(cell);
resultData.setReleaseTime(releaseTime);
//获取立项完成时间
cell = row.getCell(cellNum++);
String endTime = convertCellValueToString(cell);
resultData.setEndTime(endTime);
return resultData;
}
/**
* 将单元格内容转换为字符串
* @param cell
* @return
*/
private static String convertCellValueToString(Cell cell) {
if(cell==null){
return null;
}
String returnValue = null;
switch (cell.getCellType()) {
case NUMERIC: //数字
Double doubleValue = cell.getNumericCellValue();
// 格式化科学计数法,取一位整数
DecimalFormat df = new DecimalFormat("0");
returnValue = df.format(doubleValue);
break;
case STRING: //字符串
returnValue = cell.getStringCellValue();
break;
case BOOLEAN: //布尔
Boolean booleanValue = cell.getBooleanCellValue();
returnValue = booleanValue.toString();
break;
case BLANK: // 空值
break;
case FORMULA: // 公式
returnValue = cell.getCellFormula();
break;
case ERROR: // 故障
break;
default:
break;
}
return returnValue;
}
}
@@ -21,6 +21,7 @@ import com.adc.da.util.LoginUserUtil;
import com.adc.da.util.UUIDUtils;
import com.adc.da.utils.util.*;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
@@ -765,4 +766,21 @@ public class SarStandardsInfoController extends BaseController<SarStandardsInfo>
return "1";
}
@ApiOperation(value = "|SarStandardsInfoEO|自定义分页查询")
@GetMapping("/checkIsOnly")
public ResponseMessage checkIsOnly (SarStandardsInfoEOPage page){
QueryWrapper<SarStandardsInfo> wrapper=new QueryWrapper<>();
wrapper .eq("STAND_TYPE",page.getStandType())
.eq(null!=page.getStandSort(),"STAND_SORT",page.getStandSort())
.eq(null!=page.getStandNumber(),"STAND_NUMBER",page.getStandNumber())
.eq(null!=page.getStandYear(),"STAND_YEAR",page.getStandYear());
Integer s=sarStandardsInfoEOService.count(wrapper);
if (s>0){
return Result.error();
}else {
return Result.success();
}
}
}