Commit 8acff898 authored by neo's avatar neo

[dev] delete some unused java file

parent ccd54f84
package pwc.taxtech.atms.common;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
@Component
public class CorsFilter extends OncePerRequestFilter {
@Autowired
private AtmsApiSettings atmsApiSettings;
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
response.setHeader("Access-Control-Allow-Origin", atmsApiSettings.getWebUrl());
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.setHeader("Access-Control-Allow-Headers",
"origin, content-type, accept, x-requested-with, authorization, x-xsrf-token, X-HTTP-Method-Override, withcredentials, access-control-allow-origin,from");
response.setHeader("Access-Control-Allow-Credentials", "true");
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return;
}
chain.doFilter(request, response);
}
}
package pwc.taxtech.atms.common;
public enum ModelTypeEnum {
SystemCommon(1,"SystemCommon","系统公共模型"),
OrganizationCommon(2,"OrganizationCommon","机构公共模型"),
OrganizationCustomize(3,"OrganizationCustomize","机构自定义模型");
private Integer code;
private String name;
private String displayName;
ModelTypeEnum(Integer code,String name,String displayName){
this.code= code;
this.name= name;
this.displayName = displayName;
}
public String toName() {
return this.name == null ? this.name() : this.name;
}
public Integer toCode() {
return this.code == null ? this.ordinal() : this.code;
}
public String toDisplayName() {
return this.displayName == null ? this.name() : this.displayName;
}
}
package pwc.taxtech.atms.common.util;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.exception.ApiException;
import pwc.taxtech.atms.exception.FormulaException;
......
package pwc.taxtech.atms.common.util;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
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.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import pwc.taxtech.atms.constant.VATCommon;
import pwc.taxtech.atms.vat.dao.DataImportModel;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import static org.apache.poi.ss.usermodel.CellType.NUMERIC;
import static pwc.taxtech.atms.constant.Constant.DEFAULT_RESULT;
public class NPOIHelper {
public static DataImportModel renderTBDataTableFromExcel(FileInputStream fis, Integer selectedSheetIndex,
int headerRowIndex, boolean haveHeader, Integer topRowNumber) {
DataImportModel dataImportModel = new DataImportModel();
Workbook workbook = null;
try {
workbook = WorkbookFactory.create(fis);
Sheet sheet = workbook.getSheetAt(selectedSheetIndex);
dataImportModel.setDataList(new ArrayList<>());
dataImportModel.setSheetNameList(new ArrayList<>());
dataImportModel.setResult(DEFAULT_RESULT);
try {
//TODO:should be replace by biz exception (neo)
if (!(workbook instanceof XSSFWorkbook)) throw new RuntimeException("not support workbook type");
XSSFFormulaEvaluator eva = new XSSFFormulaEvaluator((XSSFWorkbook) workbook);
int numberOfSheets = workbook.getNumberOfSheets();
for (int index = 0; index < numberOfSheets; index++) {
dataImportModel.getSheetNameList().add(workbook.getSheetAt(index).getSheetName());
}
//判断文件是否为空
if (sheet.getPhysicalNumberOfRows() == 0) {
dataImportModel.setResult(false);
dataImportModel.setResultMsg(VATCommon.Const_ImportFileError);
} else {
//var headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = 0;
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (row != null && row.getPhysicalNumberOfCells() > cellCount) {
cellCount = row.getPhysicalNumberOfCells();
}
}
List<String> rowList = new ArrayList<>();
//dataImportModel.dataList.Add(rowList);
dataImportModel.setLastRowIndex(sheet.getLastRowNum());
int RowStart = sheet.getFirstRowNum();
for (int i = RowStart; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (row != null) {
rowList = getOutputInvoiceRowValueList(eva, row, cellCount);
dataImportModel.getDataList().add(rowList);
}
}
}
} catch (Exception ex) {
dataImportModel.setResult(false);
dataImportModel.setResultMsg(VATCommon.Const_ImportFileError);
}
if (topRowNumber > 0) {
//第一行为列头的话就多输出一行
int startIndex = (haveHeader ? topRowNumber + 1 : topRowNumber)-1;
int endIndex=dataImportModel.getDataList().size() - 1;
if (startIndex < dataImportModel.getDataList().size()) {
dataImportModel.setDataList(dataImportModel.getDataList().subList(startIndex, endIndex));
}
// dataImportModel.setDataList(dataImportModel.getDataList().subList(0,topRowNumber));
}
return dataImportModel;
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
}
return null;
}
private static List<String> getOutputInvoiceRowValueList(XSSFFormulaEvaluator eva, Row row, int cellCount) {
List<String> rowList = new ArrayList<>();
for (int j = 0; j < cellCount; j++) {
if (row.getCell(j) != null) {
rowList.add(getStringCellValue(eva, row.getCell(j)));
} else {
rowList.add(null);
}
}
return rowList;
}
private static String getStringCellValue(XSSFFormulaEvaluator eva, Cell cell) {
// 获取单元格数据内容为字符串类型的数据
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strCell = "";
switch (cell.getCellTypeEnum()) {
case NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
strCell = sdf.format(cell.getDateCellValue());
} else {
long longVal = Math.round(cell.getNumericCellValue());
if (Double.parseDouble(longVal + ".0") == cell.getNumericCellValue())
strCell = longVal + "";
else
strCell = cell.getNumericCellValue() + "";
}
break;
case FORMULA:
try {
if (eva.evaluate(cell).getCellTypeEnum() == NUMERIC) {
strCell = eva.evaluate(cell).getNumberValue() + "";
} else {
strCell = eva.evaluate(cell).getStringValue();
}
} catch (Exception ex) {
strCell = "#N/A";
}
break;
default:
strCell = cell.toString();
break;
}
return strCell;
}
}
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