Commit d772e68a authored by chase's avatar chase

税金计算表功能

parent fb049e40
......@@ -2,14 +2,12 @@ package pwc.taxtech.atms.common;
import org.apache.commons.lang3.StringUtils;
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.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Iterator;
import java.util.Optional;
public class POIUtil {
......@@ -119,6 +117,89 @@ public class POIUtil {
return row;
}
public static Row createAndCloneRow(Workbook wb ,Sheet sheet, Integer destRowIndex,Row fromRow) {
Row toRow = null;
if (sheet.getRow(destRowIndex) != null) {
int lastRowNo = sheet.getLastRowNum();
sheet.shiftRows(destRowIndex, lastRowNo, 1);
}
toRow = sheet.createRow(destRowIndex);
for (Iterator cellIt = fromRow.cellIterator(); cellIt.hasNext();) {
Cell tmpCell = (Cell) cellIt.next();
Cell newCell = toRow.createCell(tmpCell.getColumnIndex());
copyCell(wb, tmpCell, newCell, false);
}
return toRow;
}
public static void copyCell(Workbook wb,Cell srcCell, Cell distCell,
boolean copyValueFlag) {
CellStyle newstyle=wb.createCellStyle();
copyCellStyle(wb,srcCell.getCellStyle(), newstyle);
if(srcCell.getColumnIndex()==7){
newstyle.setLocked(false);
}
// distCell.setEncoding(srcCell.getEncoding());
//样式
distCell.setCellStyle(newstyle);
//评论
if (srcCell.getCellComment() != null) {
distCell.setCellComment(srcCell.getCellComment());
}
// 不同数据类型处理
int srcCellType = srcCell.getCellType();
distCell.setCellType(srcCellType);
if (copyValueFlag) {
if (srcCellType == Cell.CELL_TYPE_NUMERIC) {
if (DateUtil.isCellDateFormatted(srcCell)) {
distCell.setCellValue(srcCell.getDateCellValue());
} else {
distCell.setCellValue(srcCell.getNumericCellValue());
}
} else if (srcCellType == Cell.CELL_TYPE_STRING) {
distCell.setCellValue(srcCell.getRichStringCellValue());
} else if (srcCellType == Cell.CELL_TYPE_BLANK) {
// nothing21
} else if (srcCellType == Cell.CELL_TYPE_BOOLEAN) {
distCell.setCellValue(srcCell.getBooleanCellValue());
} else if (srcCellType == Cell.CELL_TYPE_ERROR) {
distCell.setCellErrorValue(srcCell.getErrorCellValue());
} else if (srcCellType == Cell.CELL_TYPE_FORMULA) {
distCell.setCellFormula(srcCell.getCellFormula());
} else { // nothing29
}
}
}
public static void copyCellStyle(Workbook wb,CellStyle fromStyle,
CellStyle toStyle) {
toStyle.setAlignment(HorizontalAlignment.forInt(fromStyle.getAlignment()));
//边框和边框颜色
toStyle.setBorderBottom(BorderStyle.valueOf(fromStyle.getBorderBottom()));
toStyle.setBorderLeft(BorderStyle.valueOf(fromStyle.getBorderLeft()));
toStyle.setBorderRight(BorderStyle.valueOf(fromStyle.getBorderRight()));
toStyle.setBorderTop(BorderStyle.valueOf(fromStyle.getBorderTop()));
toStyle.setTopBorderColor(fromStyle.getTopBorderColor());
toStyle.setBottomBorderColor(fromStyle.getBottomBorderColor());
toStyle.setRightBorderColor(fromStyle.getRightBorderColor());
toStyle.setLeftBorderColor(fromStyle.getLeftBorderColor());
//背景和前景
toStyle.setFillBackgroundColor(fromStyle.getFillBackgroundColor());
toStyle.setFillForegroundColor(fromStyle.getFillForegroundColor());
//
toStyle.setDataFormat(fromStyle.getDataFormat());
toStyle.setFillPattern(FillPatternType.forInt(fromStyle.getFillPattern()));
toStyle.setFont(wb.getFontAt(fromStyle.getFontIndex()));
toStyle.setHidden(fromStyle.getHidden());
toStyle.setIndention(fromStyle.getIndention());//首行缩进
toStyle.setLocked(fromStyle.getLocked());
toStyle.setRotation(fromStyle.getRotation());//旋转
toStyle.setVerticalAlignment(VerticalAlignment.forInt(fromStyle.getVerticalAlignment()));
toStyle.setWrapText(fromStyle.getWrapText());
}
}
package pwc.taxtech.atms.constant.enums;
import java.util.HashMap;
import java.util.Map;
public class TaxesCalculateReportEnum {
public enum Column {
Column_1(0, "序号"),
Column_2(1, "收入类型名称"),
Column_3(2, "税金项目"),
Column_4(3, "账载收入-明细"),
Column_5(4, "销项开票收入数-专票"),
Column_6(5, "销项开票收入数-普票"),
Column_7(6, "计税基数(应税收入)"),
Column_8(7, "税率"),
Column_9(8, "税额(元)"),
Column_10(9, "收入类别"),
Column_11(10, "计税方式"),
Column_12(11, "备注")
;
private Integer index;
private String name;
public static final Map<Integer, String> MAPPING = new HashMap<>();
Column(Integer index, String name) {
this.index = index;
this.name = name;
}
public Integer getIndex() {
return index;
}
public String getName() {
return name;
}
static {
for (TaxesCalculateReportEnum.Column accountType : TaxesCalculateReportEnum.Column.values()) {
MAPPING.put(accountType.getIndex(), accountType.getName());
}
}
}
}
......@@ -19,7 +19,6 @@ import org.springframework.stereotype.Component;
import pwc.taxtech.atms.common.POIUtil;
import pwc.taxtech.atms.common.util.SpringContextUtil;
import pwc.taxtech.atms.constant.enums.CellDataSourceType;
import pwc.taxtech.atms.constant.enums.FileUploadEnum;
import pwc.taxtech.atms.dao.ProjectMapper;
import pwc.taxtech.atms.dto.didiFileUpload.DidiFileIUploadParam;
import pwc.taxtech.atms.dto.didiFileUpload.DidiFileUploadDetailResult;
......@@ -34,7 +33,10 @@ import pwc.taxtech.atms.vat.dpo.PeriodCellTemplateConfigExtendDto;
import pwc.taxtech.atms.vat.entity.*;
import pwc.taxtech.atms.vat.service.impl.report.functions.*;
import java.io.*;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
......@@ -47,31 +49,32 @@ import static pwc.taxtech.atms.dto.vatdto.WrapPeriodJobDto.*;
@Component
public class ReportGeneratorImpl {
private static final Logger logger = LoggerFactory.getLogger(ReportGeneratorImpl.class);
@Autowired
@Resource
private ProjectMapper projectMapper;
@Autowired
private HttpFileService httpFileService;
@Autowired
private FormulaAgent formulaAgent;
@Autowired
@Resource
private PeriodCellDataMapper periodCellDataMapper;
@Autowired
@Resource
private PeriodFormulaBlockMapper periodFormulaBlockMapper;
@Autowired
private PeriodDataSourceMapper periodDataSourceMapper;
@Autowired
@Resource
private RevenueConfigMapper revenueConfigMapper;
@Resource
private PeriodCellTemplateConfigMapper periodCellTemplateConfigMapper;
@Autowired
@Resource
private PeriodCellTemplateMapper periodCellTemplateMapper;
@Autowired
@Resource
private PeriodTemplateMapper periodTemplateMapper;
@Autowired
private DistributedIdService distributedIdService;
@Autowired
@Resource
private PeriodJobMapper periodJobMapper;
@Autowired
private DidiFileUploadService didiFileUploadService;
public FormulaContext initContext(PeriodResources resources, Integer period) {
return FormulaContext.extractContextFromProject(resources.getProject()).fixedFormula(period, resources.getTemplateGroupId(),
formulaAgent);
......@@ -509,26 +512,7 @@ public class ReportGeneratorImpl {
}
}
}
//TODO 当是税金计算表时动态添加行
if ("VAT8002".equals(a.getCode())) {
tWorkbook = assembleTaxWorkBook(tWorkbook);
//覆盖template地址
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
tWorkbook.write(bout);
FileUpload fileUpload = didiFileUploadService.uploadFile(bout.toByteArray(), a.getCode() + "_" + a.getName() + ".xlsx", FileUploadEnum.BizSource.PERIOD_REPORT_TEMPLATE_UPLOAD.name());
a.setPath(fileUpload.getUid());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
bout.close();
} catch (Exception e) {
}
}
periodTemplateMapper.updateByPrimaryKey(a);
}
POIUtil.cloneSheet(tWorkbook.getSheetAt(0), workbook.createSheet(a.getCode()));
});
......@@ -542,29 +526,6 @@ public class ReportGeneratorImpl {
}
}
public Workbook assembleTaxWorkBook(Workbook tWorkbook) {
Sheet sheet = tWorkbook.getSheetAt(0);
Row row = POIUtil.createRow(sheet, 3);
Cell cell = row.createCell(0);
cell.setCellValue("test");
return tWorkbook;
}
private void saveExcel(Workbook wb) {
FileOutputStream fileOut;
try {
fileOut = new FileOutputStream("");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 注册所有的自定义方法到工作簿
......
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