Commit aef2ca5c authored by zhkwei's avatar zhkwei

CIT固定资产-资产清单补充及优化以及部分导入工具类

parent 15fef97a
......@@ -146,41 +146,29 @@ public class AssetListServiceImpl extends BaseService {
*/
public OperationResultDto assetsImport(InputStream inputStream, String fileName, String projectId) throws IOException, InvalidFormatException, ParseException {
logger.debug("导入excel文件开始");
String filePath = FileUtils.getTempDirectory().getAbsolutePath() + File.separator + "citAsset" + File.separator
+ CommonUtils.getUUID() + "_" + fileName;
//保存导入的文件
OperationResultDto<Object> saveResult = fileService.saveFile(inputStream, filePath);
//判断是否成功导入
if (saveResult.getResult() != null && !saveResult.getResult()) {
return saveResult;
}
//获取保存文件的输入流
InputStream newInputStream = Files.findFileAsStream(filePath);
//用CustomerController中的方法获取Excel文件的数据
// Collection<Map> excelMapCollection = fileService.readExcelAndClose(newInputStream);
//定义返回变量
OperationResultDto<Object> importResult = new OperationResultDto<>();
//通过输入流获取当前workbook
Workbook workbook = WorkbookFactory.create(newInputStream);
Workbook workbook = fileService.getWorkbook(inputStream, fileName, "citAsset");
if(workbook == null){
importResult.setResult(false);
importResult.setResultMsg("读取Excel出现内部错误");
return importResult;
}
//目前资产导入只有一个Sheet页,所以只取第一个Sheet即可
Sheet sheet = workbook.getSheetAt(0);
if (sheet == null) {
saveResult.setResult(false);
return saveResult;
importResult.setResult(false);
importResult.setResultMsg("读取Excel出现内部错误");
return importResult;
}
//在循环取数据外定义资产类别map,防止map重新定义,不能过滤重复资产类别
Set assetNameSet = new HashSet();
List<CitAssetGroupResult> citAssetGroupResults = selectGroupResult(projectId);
//计算当前期间
Calendar now = Calendar.getInstance();
StringBuilder sb = new StringBuilder();
sb.append(now.get(Calendar.YEAR));
if(now.get(Calendar.MONTH) + 1 < 10){
sb.append(0);
}
sb.append(now.get(Calendar.MONTH) + 1);
StringBuilder periodSb = CitCommonUtil.getPeriod();
List<CitAssetsList> citAssetsLists = new ArrayList<>();
StringBuilder errorMsgSb = new StringBuilder("第");
//通过循环来完成sheet获取每一行每一列数据并进行相关逻辑处理
......@@ -190,18 +178,18 @@ public class AssetListServiceImpl extends BaseService {
//赋值projectId
citAsset.setProjectId(projectId);
citAsset.setPeriod(Integer.valueOf(sb.toString()));
citAsset.setPeriod(Integer.valueOf(periodSb.toString()));
//获取该行数据
Row rowData = sheet.getRow(rowNum);
//因模板固定,则按照写死的做法处理数据单元格数据
citAsset = cellToCitAsset(rowData, citAsset, assetNameSet, citAssetGroupResults);
if(citAsset == null){
saveResult.setResult(false);
importResult.setResult(false);
errorMsgSb.append(rowNum+",");
}
if(!saveResult.getResult()){
saveResult.setResultMsg("行数据为空或格式错误!");
if(!importResult.getResult()){
importResult.setResultMsg("行数据为空或格式错误!");
}
//目前没有进行税法分类,标注状态
citAsset.setStatus(0);
......@@ -224,12 +212,12 @@ public class AssetListServiceImpl extends BaseService {
CitAssetGroupResult citAssetGroupResult = new CitAssetGroupResult();
citAssetGroupResult.setId(idService.nextId());
citAssetGroupResult.setProjectId(projectId);
citAssetGroupResult.setPeriod(Integer.valueOf(sb.toString()));
citAssetGroupResult.setPeriod(Integer.valueOf(periodSb.toString()));
citAssetGroupResult.setAssetName(it.next());
assetGroupResultMapper.insertSelective(citAssetGroupResult);
}
saveResult.setResult(true);
return saveResult;
importResult.setResult(true);
return importResult;
}
/**
......@@ -243,58 +231,58 @@ public class AssetListServiceImpl extends BaseService {
//获取资产编号
Cell cell = rowData.getCell(1);
Object value = getValue(cell);
Object value = CitCommonUtil.getValue(cell);
if (value == null) {
return null;
}
citAsset.setAssetNumber(value.toString());
//获取资产描述
citAsset.setAssetDescription(getValue(rowData.getCell(5)).toString());
citAsset.setAssetDescription(CitCommonUtil.getValue(rowData.getCell(5)).toString());
//获取资产类别
String assetName = getValue(rowData.getCell(7)).toString();
String assetName = CitCommonUtil.getValue(rowData.getCell(7)).toString();
citAsset.setAssetGroupName(assetName);
//获取购入日期
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
citAsset.setBuyDate(sdf.parse(getValue(rowData.getCell(15)).toString()));
citAsset.setBuyDate(sdf.parse(CitCommonUtil.getValue(rowData.getCell(15)).toString()));
//获取开始折旧日期,DD没有提供,我们要根据购入日期和税法分类做预处理自己转化
// citAsset.setDepreciationDate(sdf.parse(getValue(rowData.getCell(15)).toString()));
// citAsset.setDepreciationDate(sdf.parse(CitCommonUtil.getValue(rowData.getCell(15)).toString()));
//获取折旧期限,接下来计算需要用到,所以赋给一个对象
Integer depreciationPeriod = Integer.valueOf(getValue(rowData.getCell(30)).toString());
Integer depreciationPeriod = Integer.valueOf(CitCommonUtil.getValue(rowData.getCell(30)).toString());
citAsset.setDepreciationPeriod(depreciationPeriod);
//获取原值,接下来计算需要用到,所以赋给一个对象
BigDecimal acquisitionValue = new BigDecimal(getValue(rowData.getCell(16)).toString());
BigDecimal acquisitionValue = new BigDecimal(CitCommonUtil.getValue(rowData.getCell(16)).toString());
citAsset.setAcquisitionValue(acquisitionValue);
//获取原值调整值0----列数待定,滴滴无调整值
// citAsset.setAdjustmentValue(new BigDecimal(getValue(rowData.getCell(32)).toString()));
// citAsset.setAdjustmentValue(new BigDecimal(CitCommonUtil.getValue(rowData.getCell(32)).toString()));
//获取报废日期
Cell cell1 = rowData.getCell(37);
if (rowData.getCell(37) != null && getValue(rowData.getCell(37)) != null) {
citAsset.setDisposedDate(sdf.parse(getValue(rowData.getCell(37)).toString()));
if (rowData.getCell(37) != null && CitCommonUtil.getValue(rowData.getCell(37)) != null) {
citAsset.setDisposedDate(sdf.parse(CitCommonUtil.getValue(rowData.getCell(37)).toString()));
}
//获取残值额,原为残值率现为残值额,接下来计算需要用到,所以赋给一个对象
BigDecimal residualRate = new BigDecimal(getValue(rowData.getCell(20)).toString());
BigDecimal residualRate = new BigDecimal(CitCommonUtil.getValue(rowData.getCell(20)).toString());
citAsset.setResidualRate(residualRate);
//获取本年折旧额
citAsset.setYearDepreciationAmount(new BigDecimal(getValue(rowData.getCell(24)).toString()));
citAsset.setYearDepreciationAmount(new BigDecimal(CitCommonUtil.getValue(rowData.getCell(24)).toString()));
// 获取本年调整额----列数待定 滴滴无本年调整额
// citAsset.setYearAdjustmentAmount(new BigDecimal(getValue(rowData.getCell(25)).toString()));
// citAsset.setYearAdjustmentAmount(new BigDecimal(CitCommonUtil.getValue(rowData.getCell(25)).toString()));
//获取财务原值---计算方法:原值+原值调整值,暂时不考虑调整值
citAsset.setAccountAcquisitionValue(acquisitionValue);
//获取财务每月折旧额----(原值-残值额)/折旧期限
citAsset.setAccountMonthDepreciationAmount(acquisitionValue.subtract(residualRate).divide(new BigDecimal(depreciationPeriod), 2));
//获取财务本年折旧额
citAsset.setAccountYearDepreciationAmount(new BigDecimal(getValue(rowData.getCell(24)).toString()));
citAsset.setAccountYearDepreciationAmount(new BigDecimal(CitCommonUtil.getValue(rowData.getCell(24)).toString()));
//获取财务累计折旧额,接下来计算需要用到,所以赋给一个对象
BigDecimal accountTotalDepreciationAmount = new BigDecimal(getValue(rowData.getCell(25)).toString());
BigDecimal accountTotalDepreciationAmount = new BigDecimal(CitCommonUtil.getValue(rowData.getCell(25)).toString());
citAsset.setAccountTotalDepreciationAmount(accountTotalDepreciationAmount);
//年终剩余价值,
citAsset.setYearEndValue(acquisitionValue.subtract(accountTotalDepreciationAmount));
......@@ -314,32 +302,6 @@ public class AssetListServiceImpl extends BaseService {
return citAsset;
}
/**
* 导入Excel时根据单元格类型获取单元格的值
* @param cell
* @return
*/
public static Object getValue(Cell cell) {
Object obj = null;
switch (cell.getCellTypeEnum()) {
case BOOLEAN:
obj = cell.getBooleanCellValue();
break;
case ERROR:
obj = cell.getErrorCellValue();
break;
case NUMERIC:
obj = cell.getNumericCellValue();
break;
case STRING:
obj = cell.getStringCellValue();
break;
default:
break;
}
return obj;
}
/**
* 根据projectId获取资产类别数据
......
package pwc.taxtech.atms.service.impl;
import org.apache.poi.ss.usermodel.Cell;
import java.util.Calendar;
/**
* @author ZhiKai Z Wei
*/
public class CitCommonUtil {
/**
* 计算当前期间
* @return
*/
public static StringBuilder getPeriod(){
//计算当前期间
Calendar now = Calendar.getInstance();
StringBuilder sb = new StringBuilder();
sb.append(now.get(Calendar.YEAR));
if(now.get(Calendar.MONTH) + 1 < 10){
sb.append(0);
}
sb.append(now.get(Calendar.MONTH) + 1);
return sb;
}
/**
* 导入Excel时根据单元格类型获取单元格的值
* @param cell
* @return
*/
public static Object getValue(Cell cell) {
Object obj = null;
switch (cell.getCellTypeEnum()) {
case BOOLEAN:
obj = cell.getBooleanCellValue();
break;
case ERROR:
obj = cell.getErrorCellValue();
break;
case NUMERIC:
obj = cell.getNumericCellValue();
break;
case STRING:
obj = cell.getStringCellValue();
break;
default:
break;
}
return obj;
}
}
package pwc.taxtech.atms.service.impl;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.nutz.lang.Files;
......@@ -198,4 +203,22 @@ public class FileService {
}
}
public Workbook getWorkbook(InputStream inputStream, String fileName, String fileDir) throws IOException, InvalidFormatException {
String filePath = FileUtils.getTempDirectory().getAbsolutePath() + File.separator + fileDir + File.separator
+ CommonUtils.getUUID() + "_" + fileName;
//保存导入的文件
OperationResultDto<Object> saveResult = saveFile(inputStream, filePath);
//判断是否成功导入
if (saveResult.getResult() != null && !saveResult.getResult()) {
return null;
}
//获取保存文件的输入流
InputStream newInputStream = Files.findFileAsStream(filePath);
//通过输入流获取当前workbook
Workbook workbook = WorkbookFactory.create(newInputStream);
return workbook;
}
}
......@@ -143,6 +143,7 @@ public class MenuServiceImpl {
menuIds.add("a9b1cd87-89ef-4dae-b798-b19e9bbe0821");
menuIds.add("a9b1cd87-89ef-4dae-b798-b19e9bbe0822");
menuIds.add("a9b1cd87-89ef-4dae-b798-b19e9bbe0823");
menuIds.add("a9b1cd87-89ef-4dae-b798-b19e9bbe0824");
menuIds.add("b8c74ee9-e5d7-467b-8565-e77efe6a499f");
// List<MenuDto> menus = getMenus(moduleId).stream().filter(x -> permissionNames.contains(x.getName())).collect(Collectors.toList());
return menuIds;
......
<div id="app-data-import" class="app-data-import ">
<nav class="navbar navbar-custom" role="navigation"
style="margin-bottom: 0; background-image:url(../../../app-resources/images/leftbarbg.png); height:100%;width: 260px">
style="margin-bottom: 0; background-image:url(../../../app-resources/images/leftbarbg.png); height:auto;width: 260px">
<div class="sidebar navbarfix" role="navigation">
<div class="sidebar-nav navbar-collapse" id="sidebar-area" style="height:100%;width: 260px">
<div class="app-data-import-side-bar" style="height: 100%">
......
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