Commit f585cc0b authored by kevin's avatar kevin

Merge branch 'dev_mysql' of https://gitee.com/Memorydoc/atms into dev_mysql

parents 85734248 fe0fcfc1
......@@ -6,12 +6,16 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.grapecity.documents.excel.V;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -1734,6 +1738,40 @@ public class ReportServiceImpl extends BaseService {
return ebitDataDto;
}
public EbitDataDto ebitCellDataToEbitDataDto(List<EbitCellData> ebitCellData) {
EbitDataDto ebitDataDto = new EbitDataDto();
for (EbitCellData ebitCellData1 : ebitCellData) {
if (ebitCellData1.getCol() == 1)
continue;
switch (ebitCellData1.getRow()) {
case 37:
ebitDataDto.setEbitSubtraction(new BigDecimal(ebitCellData1.getData()).setScale(2, BigDecimal.ROUND_HALF_UP));
if ((new BigDecimal(ebitCellData1.getData()).setScale(2, BigDecimal.ROUND_HALF_UP)).compareTo(new BigDecimal("0.0000")) == -1) {
return null;
}
break;
case 38:
ebitDataDto.setSpecialConsiderations(ebitCellData1.getData());
break;
case 39:
ebitDataDto.setSpecialFactors(new BigDecimal(ebitCellData1.getData()).setScale(2, BigDecimal.ROUND_HALF_UP));
break;
case 40:
ebitDataDto.setEbitRate(ebitCellData1.getData());
break;
case 41:
ebitDataDto.setTransactionAmount(new BigDecimal(ebitCellData1.getData()).setScale(2, BigDecimal.ROUND_HALF_UP));
break;
case 42:
ebitDataDto.setSixAddTax(new BigDecimal(ebitCellData1.getData()).setScale(2, BigDecimal.ROUND_HALF_UP));
break;
case 43:
ebitDataDto.setTotalAmountTax(new BigDecimal(ebitCellData1.getData()).setScale(2, BigDecimal.ROUND_HALF_UP));
break;
}
}
return ebitDataDto;
}
public EbitDataDto calculateEbitDataByEbit(List<EbitCellData> ebitCellData, String specialConsiderations, String ebitRate) {
EbitDataDto ebitDataDto = new EbitDataDto();
......@@ -1761,46 +1799,48 @@ public class ReportServiceImpl extends BaseService {
BigDecimal zcjzss = new BigDecimal(0); //资产减值损失
for (EbitCellData ebitCellData1 : ebitCellData) {
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 11) { //一、营业收入
if(StringUtils.isNotEmpty(ebitCellData1.getData())) yysr = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData())) yysr = new BigDecimal(ebitCellData1.getData());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 12) {//减:营业成本
if(StringUtils.isNotEmpty(ebitCellData1.getData()))yycb = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData())) yycb = new BigDecimal(ebitCellData1.getData());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 13) {//营业税金及附加
if(StringUtils.isNotEmpty(ebitCellData1.getData())) yysjfj = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData()))
yysjfj = new BigDecimal(ebitCellData1.getData());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 14) {//销售费用
if(StringUtils.isNotEmpty(ebitCellData1.getData())) xsfy = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData())) xsfy = new BigDecimal(ebitCellData1.getData());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 15) {//管理费用
if(StringUtils.isNotEmpty(ebitCellData1.getData())) glfy = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData())) glfy = new BigDecimal(ebitCellData1.getData());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 16) {//研发费用
if(StringUtils.isNotEmpty(ebitCellData1.getData()))yffy = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData())) yffy = new BigDecimal(ebitCellData1.getData());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 18) {//资产减值损失
if(StringUtils.isNotEmpty(ebitCellData1.getData()))zcjzss = new BigDecimal(ebitCellData1.getData());
if (StringUtils.isNotEmpty(ebitCellData1.getData()))
zcjzss = new BigDecimal(ebitCellData1.getData());
continue;
}
}
BigDecimal subtract = yysr.subtract(yycb).add(yysjfj).add(xsfy).add(glfy).add(yffy).add(zcjzss);
BigDecimal subtract = yysr.subtract(yycb).subtract(yysjfj).subtract(xsfy).subtract(glfy).subtract(yffy).subtract(zcjzss);
ebitDataDto.setEbitSubtraction(subtract);
ebitDataDto.setSpecialFactors(subtract.add(spec));
ebitDataDto.setEbitRate(String.valueOf(rate));
ebitDataDto.setTransactionAmount(ebitDataDto.getSpecialFactors().multiply(new BigDecimal(ebitDataDto.getEbitRate())));
ebitDataDto.setTransactionAmount(ebitDataDto.getSpecialFactors().multiply(new BigDecimal(ebitDataDto.getEbitRate())).setScale(2, BigDecimal.ROUND_HALF_UP));
if (ebitRate.indexOf("%") != -1) {
ebitDataDto.setEbitRate(ebitRate);
} else {
ebitDataDto.setEbitRate(ebitRate + "%");
}
ebitDataDto.setSixAddTax(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(0.06).setScale(2, BigDecimal.ROUND_UP)));
ebitDataDto.setTotalAmountTax(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(1.06).setScale(2, BigDecimal.ROUND_UP)));
ebitDataDto.setSixAddTax(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(0.06)).setScale(2, BigDecimal.ROUND_HALF_UP));
ebitDataDto.setTotalAmountTax(ebitDataDto.getTransactionAmount().multiply(new BigDecimal(1.06)).setScale(2, BigDecimal.ROUND_HALF_UP));
ebitDataDto.setSpecialConsiderations(specialConsiderations);
} catch (Exception e) {
e.printStackTrace();
......@@ -2534,7 +2574,6 @@ public class ReportServiceImpl extends BaseService {
didiFileUploadService.delData(ebitSpreadData1.get(0).getFileKey());
ebitSpreadDataMapper.deleteByExample(example);
}*/
EbitCellDataExample exampleCellData = new EbitCellDataExample();
exampleCellData.createCriteria().andPeriodEqualTo(period).andOrganizationIdEqualTo(orgId);
if (ebitCellDataMapper.selectByExample(exampleCellData).size() != 0) {
......@@ -2555,7 +2594,7 @@ public class ReportServiceImpl extends BaseService {
/* if (j <= 36)
continue;*/
for (int k = 1; k < sheet.getRow(0).getLastCellNum(); k++) {
if (k ==1 || k == 2){
if (k == 1 || k == 2) {
EbitCellData ebitCellData1 = new EbitCellData();
ebitCellData1.setId(idService.nextId());
ebitCellData1.setOrganizationId(orgId);
......@@ -2563,7 +2602,7 @@ public class ReportServiceImpl extends BaseService {
ebitCellData1.setCreateTime(new Date());
ebitCellData1.setCol(k);
ebitCellData1.setRow(j);
ebitCellData1.setData(getCellStringValue(sheet.getRow(j).getCell(k)));
ebitCellData1.setData(getCellStringValue(sheet.getRow(j).getCell(k)).equals("") == true ? "0" : getCellStringValue(sheet.getRow(j).getCell(k)));
ebitCellDataList.add(ebitCellData1);
}//这里只保存两列{}
}
......@@ -2605,6 +2644,7 @@ public class ReportServiceImpl extends BaseService {
@Autowired
private JdbcTemplate jdbcTemplate;
private static CellStyle cellStyle1 = null;
/**
* 批量导出Excel ebit利润表
......@@ -2680,20 +2720,34 @@ public class ReportServiceImpl extends BaseService {
List<Integer> cols = Lists.newArrayList();
FileExcelUtil.deleteColumn(sheetAt, 1, cols);
//var profileList = ["EBIT考虑资产减值损失", "", "", "", "", "", ""];
List<String> ebitTitle = Lists.newArrayList("EBIT考虑资产减值损失", "加:特殊因素考虑", "EBIT(考虑特殊因素)", "EBIT rate", "关联交易金额", "6%增值税", "价税合计金额");
//设置单元格居右
cellStyle1 = workbook1.createCellStyle();//创建样式
cellStyle1.setAlignment(HorizontalAlignment.RIGHT);
CellStyle headerCellType = workbook1.createCellStyle();
//给第一个sheet创建ebit 行
for (int i = 37; i <= 43; i++) {
sheetAt.createRow(i).createCell(0).setCellValue(ebitTitle.get(i - 37));
}
List<EbitDataDto> ebitCellDataList = new ArrayList<>();
if (finalMap.size() == 0)
throw new Exception("没有利润表模板,无法批量导出,请上传模板");
for (Map.Entry<String, List<EbitCellData>> entry : finalMap.entrySet()) {
//加载计算ebit数据
EbitCellDataExample example = new EbitCellDataExample();
example.createCriteria().andPeriodEqualTo(requestParameterDto.getPeriod()).andOrganizationIdEqualTo(entry.getKey());
List<EbitCellData> ebitCellDataList1 = ebitCellDataMapper.selectByExample(example);
if (ebitCellDataList1.size() != 0) {
EbitDataDto ebitDataDto = ebitCellDataToEbitDataDto(entry.getValue());
if (ebitDataDto == null) {
continue;
} else {
ebitCellDataList.add(ebitDataDto);
}
} else {
ebitCellDataList.add(calculateEbitDataByEbit(entry.getValue(), specialConsideration, ebitRate));
}
//加载计算ebit数据
for (int m = 0; m <= sheetAt.getLastRowNum(); m++) {
switch (m) {
case 7:
......@@ -2725,41 +2779,49 @@ public class ReportServiceImpl extends BaseService {
} catch (Exception e) {
sheetAt.getRow(m).createCell(_index + 1).setCellValue(ebitCellData.getData());
}
System.out.println(ebitCellData.getData());
}
}
}
//cell.setCellType(cellStyle.getAlignment());
}
if (m >= 37) {//加载ebit数据
for (EbitDataDto ebitCellData : ebitCellDataList) {
switch (m){
switch (m) {
case 37:
cellAndOrCreate(m, _index+1, ebitCellData.getEbitSubtraction().toString(), sheetAt);
addFormula(cellAndOrCreate(m, _index + 1,
ebitCellData.getEbitSubtraction().toString(),
sheetAt), Lists.newArrayList("12- ", "13- ", "14- ", "15- ", "16- ", "18"), _index + 1);
break;
case 38:
cellAndOrCreate(m, _index+1, ebitCellData.getSpecialConsiderations(), sheetAt);
cellAndOrCreate(m, _index + 1, ebitCellData.getSpecialConsiderations(), sheetAt);
break;
case 39:
cellAndOrCreate(m, _index+1, ebitCellData.getSpecialFactors().toString(), sheetAt);
addFormula(cellAndOrCreate(m, _index + 1, ebitCellData.getSpecialFactors().toString(), sheetAt),
Lists.newArrayList("38+ ", "39"), _index + 1);
break;
case 40:
cellAndOrCreate(m, _index+1, ebitCellData.getEbitRate(), sheetAt);
cellAndOrCreate(m, _index + 1, ebitCellData.getEbitRate(), sheetAt);
break;
case 41:
cellAndOrCreate(m, _index+1, ebitCellData.getTransactionAmount().toString(), sheetAt);
addFormula(cellAndOrCreate(m, _index + 1, ebitCellData.getTransactionAmount().toString(), sheetAt),
Lists.newArrayList("40 * ", "41"), _index + 1);
break;
case 42:
cellAndOrCreate(m, _index+1, ebitCellData.getSixAddTax().toString(), sheetAt);
addFormula(cellAndOrCreate(m, _index + 1, ebitCellData.getSixAddTax().toString(), sheetAt), Lists.newArrayList("42 * 0.06"), _index + 1);
break;
case 43:
cellAndOrCreate(m, _index+1, ebitCellData.getTotalAmountTax().toString(), sheetAt);
addFormula(cellAndOrCreate(m, _index + 1, ebitCellData.getTotalAmountTax().toString(), sheetAt), Lists.newArrayList("42 * 1.06"), _index + 1);
break;
}
}
}
}
_index++;
}
///合并单元格
insertExcelOne(headerCellType, workbook1, sheetAt, _index, requestParameterDto);
/* for (int i = 0; i < ebitSpreadData.size(); i++) {
DidiFileIUploadParam fileParam = new DidiFileIUploadParam();
fileParam.setUuids(Arrays.asList(ebitSpreadData.get(i).getFileKey()));
......@@ -2798,17 +2860,24 @@ public class ReportServiceImpl extends BaseService {
FileExcelUtil.downloadExcel(request, response, requestParameterDto.getPeriod() + "-汇总利润表.xlsx", workbook1);
}
public void cellAndOrCreate(Integer row, Integer col,String data, Sheet sheetAt){
public void addFormula(Cell cell, List<String> mulaList, Integer col) {
StringBuilder stringBuilder = new StringBuilder();
mulaList.forEach(x -> {
stringBuilder.append(LetterExcelUtil.NumToExcel(col)+ x);
});
cell.setCellFormula(stringBuilder.toString());
}
public Cell cellAndOrCreate(Integer row, Integer col, String data, Sheet sheetAt) {
if (sheetAt.getRow(row).getCell(col) == null) {
sheetAt.getRow(row).createCell(col).setCellValue(data);
} else {
sheetAt.getRow(row).getCell(col).setCellValue(data);
}
sheetAt.getRow(row).getCell(col).setCellStyle(cellStyle1);
return sheetAt.getRow(row).getCell(col);
}
/* public void insertData(String templateId, Integer period, Sheet sheet, int beginCell) {
List<Project> projects = projectMapper.selectByExample(example1);
for (EbitCell project : ebitCellData) {
String projectId = getProjId(project.getOrganizationId(), period);
......@@ -2868,34 +2937,22 @@ public class ReportServiceImpl extends BaseService {
}*/
public void insertExcelOne(Sheet sheetAt, List<EbitSpreadData> spreadData, XSSFWorkbook workbook, Integer period) {
XSSFCellStyle cellStyle = workbook.createCellStyle();
XSSFFont font = workbook.createFont();
font.setFontHeight(20);
public void insertExcelOne(CellStyle headerCellType, XSSFWorkbook workbook1, Sheet sheetAt, Integer _index, RequestParameterDto requestParameterDto) {
headerCellType.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直
headerCellType.setAlignment(HorizontalAlignment.CENTER);// 水平
XSSFFont font = workbook1.createFont();
font.setBold(true);
cellStyle.setAlignment(HorizontalAlignment.CENTER);// 设置居中
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setFont(font);
if (spreadData.size() != 0) {
sheetAt.getRow(6).getCell(1).setCellValue(getOrgName(spreadData.get(0).getOrganizationId()));
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
sheetAt.getRow(8).getCell(1).setCellValue("本年累计");
sheetAt.getRow(0).createCell(4).setCellValue("日期:" + format.format(new Date()));
for (int m = 0; m < 3; m++) {
if (sheetAt.getRow(m) == null)
continue;
}
sheetAt.createRow(2).createCell(3).setCellValue("本期" + period);
POIStyleUtil.setCellBackgroundColor(workbook, sheetAt.createRow(2).createCell(3), new XSSFColor(java.awt.Color.YELLOW));//设置背景颜色
sheetAt.getRow(0).getCell(1).setCellValue("");
sheetAt.getRow(0).createCell(3).setCellValue("利润表汇总");
sheetAt.getRow(0).getCell(3).setCellStyle(cellStyle);
font.setFontHeight(30);
headerCellType.setFont(font);
sheetAt.addMergedRegion(new CellRangeAddress(0, 0, 1, _index + 4));
sheetAt.getRow(0).getCell(1).setCellStyle(headerCellType);
POIStyleUtil.setCellBackgroundColor(workbook1, sheetAt.getRow(2).createCell(_index + 1), new XSSFColor(java.awt.Color.YELLOW));
sheetAt.getRow(2).getCell(_index + 1).setCellValue("本期:" + requestParameterDto.getPeriod());
}
public String getCellStringValue(Cell cell) {
String cellValue = null;
String cellValue = "";
try {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING://字符串类型
cellValue = cell.getStringCellValue();
......@@ -2919,6 +2976,11 @@ public class ReportServiceImpl extends BaseService {
default:
break;
}
} catch (Exception e) {
//e.printStackTrace();
logger.warn("单元格取值失败");
return "";
}
return cellValue;
}
......
......@@ -3140,7 +3140,7 @@
sheet.setValue(40, 2, $scope._ebitResult.rate + "%");
sheet.setValue(41, 2, $scope._ebitResult.gljyye);
sheet.setValue(42, 2, $scope._ebitResult.sixAddtax);
sheet.setValue(43, 2, $scope._ebitResult.klzcjsz);
sheet.setValue(43, 2, $scope._ebitResult.tsklys);
}
setTimeout(function(){spreadTODb();}, 1000)
}
......
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