Commit 41db656d authored by Memorydoc's avatar Memorydoc

#

parent c47bd1cc
......@@ -35,4 +35,8 @@ public class CommonUtil {
}
return flag;
}
public static BigDecimal BigDecimal2Fix(BigDecimal bigDecimal){
return bigDecimal.setScale(2, BigDecimal.ROUND_DOWN);
}
}
......@@ -88,4 +88,7 @@ public class StringUtil {
//ARE_YOU_DOU_BI_YELLOWCONG
System.out.println(camel2Underline(camel));
}*/
}
package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
......@@ -101,7 +102,7 @@ public class DataImportService extends BaseService {
private static String ebsCallUrl;
@Value("${ebs_call_url}")
public void setEbsCallUrl(String url){
public void setEbsCallUrl(String url) {
this.ebsCallUrl = url;
}
......@@ -114,8 +115,8 @@ public class DataImportService extends BaseService {
private static BaseThreadFactory factory = new BaseThreadFactory("callEbs");
private static ExecutorService executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize,
0L,TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(qSize),factory,new ThreadPoolExecutor.AbortPolicy());
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(qSize), factory, new ThreadPoolExecutor.AbortPolicy());
/**
* TB表查询
......@@ -240,15 +241,15 @@ public class DataImportService extends BaseService {
* 14/02/2019 14:57
* 导入利润表
* [file, periodDate]
* @author Gary J Li
* @return
* remark:1、period为 201812 201813 记录 tms_period 201812
* 2、可以考虑加index,未来若需预览可保证顺序
*
* @return remark:1、period为 201812 201813 记录 tms_period 201812
* 2、可以考虑加index,未来若需预览可保证顺序
* errorList:
* 1、存在非选择期间数据
* 2、未映射到主体
* @author Gary J Li
*/
public OperationResultDto importPLExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importPLExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -280,8 +281,8 @@ public class DataImportService extends BaseService {
Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
DataImportLog dataImportLog = generalDataImportLog(companyCode, orgId, taxPayerId,
EnumImportType.ProfitLoss.getCode(), period/100,
tmsPeriod%100, period%100,
EnumImportType.ProfitLoss.getCode(), period / 100,
tmsPeriod % 100, period % 100,
companyName, fileType);
//添加导入类型
dataImportLog.setImportType(importType);
......@@ -382,7 +383,7 @@ public class DataImportService extends BaseService {
if (addDataImportLog(dataImportLogs) < 1) {
return OperationResultDto.error(ErrorMessage.ImportFailed);
}
if(!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()){
if (!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()) {
return OperationResultDto.error();
}
return OperationResultDto.success();
......@@ -425,7 +426,7 @@ public class DataImportService extends BaseService {
* 2、未映射到主体
* @author Gary J Li
*/
public OperationResultDto importBSExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importBSExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -458,8 +459,8 @@ public class DataImportService extends BaseService {
Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
DataImportLog dataImportLog = generalDataImportLog(companyCode, orgId, taxPayerId,
EnumImportType.BalanceSheet.getCode(), period/100,
tmsPeriod%100, period%100,
EnumImportType.BalanceSheet.getCode(), period / 100,
tmsPeriod % 100, period % 100,
companyName, fileType);
//添加导入类型
dataImportLog.setImportType(importType);
......@@ -558,7 +559,7 @@ public class DataImportService extends BaseService {
if (addDataImportLog(dataImportLogs) < 1) {
return OperationResultDto.error(ErrorMessage.SystemError);
}
if(!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()){
if (!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()) {
return OperationResultDto.error();
}
return OperationResultDto.success();
......@@ -574,10 +575,11 @@ public class DataImportService extends BaseService {
* 16/02/2019 11:57
* 导入现金流量表
* [file, periodDate, importType]
* @author Gary J Li
*
* @return
* @author Gary J Li
*/
public OperationResultDto importCFExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importCFExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -611,8 +613,8 @@ public class DataImportService extends BaseService {
Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
DataImportLog dataImportLog = generalDataImportLog(companyCode, orgId, taxPayerId,
EnumImportType.CashFlow.getCode(), period/100,
tmsPeriod%100, period%100,
EnumImportType.CashFlow.getCode(), period / 100,
tmsPeriod % 100, period % 100,
companyName, fileType);
//添加导入类型
dataImportLog.setImportType(importType);
......@@ -708,7 +710,7 @@ public class DataImportService extends BaseService {
if (addDataImportLog(dataImportLogs) < 1) {
return OperationResultDto.error(ErrorMessage.SystemError);
}
if(!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()){
if (!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()) {
return OperationResultDto.error();
}
return OperationResultDto.success();
......@@ -721,15 +723,15 @@ public class DataImportService extends BaseService {
}
/**
* 18/02/2019 12:36
* 导入发票资料
* [file, periodDate, importType]
* @author Gary J Li
*
* @return OperationResultDto
* @author Gary J Li
*/
public OperationResultDto importIDExcelFile(MultipartFile file,List<String> orgIds ,String periodDate, Integer importType) throws ServiceException{
public OperationResultDto importIDExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -762,15 +764,15 @@ public class DataImportService extends BaseService {
companyCode = organizations.get(0).getCode();
}
String periodStr = sheetName[1].substring(0,6);
String periodStr = sheetName[1].substring(0, 6);
String fileType = "发票资料";
Integer period = Integer.valueOf(periodStr);
Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
DataImportLog dataImportLog = generalDataImportLog(companyCode, orgId, taxPayerId,
EnumImportType.InvoiceData.getCode(), period/100,
tmsPeriod%100, period%100,
EnumImportType.InvoiceData.getCode(), period / 100,
tmsPeriod % 100, period % 100,
companyName, fileType);
//添加导入类型
dataImportLog.setImportType(importType);
......@@ -927,7 +929,7 @@ public class DataImportService extends BaseService {
if (addDataImportLog(dataImportLogs) < 1) {
return OperationResultDto.error(ErrorMessage.SystemError);
}
if(!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()){
if (!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()) {
return OperationResultDto.error();
}
return OperationResultDto.success();
......@@ -940,7 +942,7 @@ public class DataImportService extends BaseService {
}
public OperationResultDto importRLITExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException{
public OperationResultDto importRLITExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
OperationResultDto operationResultDto = new OperationResultDto();
InputStream inputStream = file.getInputStream();
......@@ -958,36 +960,36 @@ public class DataImportService extends BaseService {
// 根据主体分组处理
Map<String, List<RedLetterInfoTable>> atsGroupRes =
rlits.stream().collect(Collectors.groupingBy(RedLetterInfoTable::getSubjectNum));
atsGroupRes.forEach((k, v) -> processRlits(k, v, orgIds, tmsPeriod, importType,dataImportLogs));
atsGroupRes.forEach((k, v) -> processRlits(k, v, orgIds, tmsPeriod, importType, dataImportLogs));
}
addDataImportLog(dataImportLogs);
int isSuccess = (int)dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
int isSuccess = (int) dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
if (isSuccess < 1) {
return OperationResultDto.error(ErrorMessage.ImportFailed);
}
return operationResultDto.success();
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
return OperationResultDto.error(e.getMessage());
}
}
private void processRlits(String companyCode, List<RedLetterInfoTable> rlits, List<String> orgIds,
Integer tmsPeriod, Integer importType,List<DataImportLog> dataImportLogs ) {
Integer tmsPeriod, Integer importType, List<DataImportLog> dataImportLogs) {
OrganizationExample organizationExample = new OrganizationExample();
organizationExample.createCriteria().andCodeEqualTo(companyCode);
Integer period = rlits.get(0).getPeriod();
List<Organization> orgs = organizationMapper.selectByExample(organizationExample);
DataImportLog dataImportLog = generalDataImportLog(rlits.get(0).getSubjectNum(),"", "",
EnumImportType.RedLetterInfoTable.getCode(), period/100,
tmsPeriod%100, period%100,
DataImportLog dataImportLog = generalDataImportLog(rlits.get(0).getSubjectNum(), "", "",
EnumImportType.RedLetterInfoTable.getCode(), period / 100,
tmsPeriod % 100, period % 100,
rlits.get(0).getSubjectName(), "");
dataImportLog.setRecordSize(rlits.size());
//添加导入类型
dataImportLog.setImportType(importType);
if(orgs.size()<1){
if (orgs.size() < 1) {
dataImportLog.setErrorMsg(ErrorMessageCN.NoCompanyError);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1005,7 +1007,7 @@ public class DataImportService extends BaseService {
return;
}
if(!orgIds.contains(orgId)){
if (!orgIds.contains(orgId)) {
dataImportLog.setErrorMsg(ErrorMessageCN.DoNotSelectCompany);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1036,7 +1038,7 @@ public class DataImportService extends BaseService {
rlit.setTmsPeriod(tmsPeriod);
rlit.setProjectId(projId);
}
if (validateRes&&EnumTbImportType.CoverImport.getCode().equals(importType)) {
if (validateRes && EnumTbImportType.CoverImport.getCode().equals(importType)) {
RedLetterInfoTableExample redLetterInfoTableExample = new RedLetterInfoTableExample();
redLetterInfoTableExample.createCriteria().andSubjectNumEqualTo(companyCode).andFillInDateEqualTo(rlits.get(0).getFillInDate());
redLetterInfoTableMapper.deleteByExample(redLetterInfoTableExample);
......@@ -1046,7 +1048,7 @@ public class DataImportService extends BaseService {
dataImportLogs.add(dataImportLog);
}
public OperationResultDto importATExcelFile(MultipartFile file,List<String> orgIds,String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importATExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -1063,35 +1065,35 @@ public class DataImportService extends BaseService {
// 根据主体分组处理
Map<String, List<AdjustmentTable>> atsGroupRes =
ats.stream().collect(Collectors.groupingBy(AdjustmentTable::getSegment1));
atsGroupRes.forEach((k, v) -> processAts(k, v, orgIds, tmsPeriod, importType,dataImportLogs));
atsGroupRes.forEach((k, v) -> processAts(k, v, orgIds, tmsPeriod, importType, dataImportLogs));
}
addDataImportLog(dataImportLogs);
int isSuccess = (int)dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
int isSuccess = (int) dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
if (isSuccess < 1) {
return OperationResultDto.error(ErrorMessage.ImportFailed);
}
return OperationResultDto.success();
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
} catch (Exception e) {
logger.error("importATExcelFile error.", e);
throw new ServiceException(ErrorMessage.SystemError);
}
}
private void processAts(String companyCode, List<AdjustmentTable> ats, List<String> orgIds,
Integer tmsPeriod, Integer importType,List<DataImportLog> dataImportLogs) {
Integer tmsPeriod, Integer importType, List<DataImportLog> dataImportLogs) {
OrganizationExample organizationExample = new OrganizationExample();
organizationExample.createCriteria().andCodeEqualTo(companyCode);
List<Organization> orgs = organizationMapper.selectByExample(organizationExample);
DataImportLog dataImportLog = generalDataImportLog(ats.get(0).getSegment1(),"", "",
EnumImportType.AdjustmentTable.getCode(), ats.get(0).getPeriod()/100,
tmsPeriod%100, ats.get(0).getPeriod()%100,
DataImportLog dataImportLog = generalDataImportLog(ats.get(0).getSegment1(), "", "",
EnumImportType.AdjustmentTable.getCode(), ats.get(0).getPeriod() / 100,
tmsPeriod % 100, ats.get(0).getPeriod() % 100,
ats.get(0).getSegment1Name(), "");
dataImportLog.setRecordSize(ats.size());
//添加导入类型
dataImportLog.setImportType(importType);
if(orgs.size()<1){
if (orgs.size() < 1) {
dataImportLog.setErrorMsg(ErrorMessageCN.NoCompanyError);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1109,7 +1111,7 @@ public class DataImportService extends BaseService {
return;
}
if(!orgIds.contains(orgId)){
if (!orgIds.contains(orgId)) {
dataImportLog.setErrorMsg(ErrorMessageCN.DoNotSelectCompany);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1140,7 +1142,7 @@ public class DataImportService extends BaseService {
at.setTmsPeriod(tmsPeriod);
at.setProjectId(projId);
}
if (validateRes&&EnumTbImportType.CoverImport.getCode().equals(importType)) {
if (validateRes && EnumTbImportType.CoverImport.getCode().equals(importType)) {
AdjustmentTableExample adjustmentTableExample = new AdjustmentTableExample();
adjustmentTableExample.createCriteria().andSegment1EqualTo(companyCode).andPeriodEqualTo(ats.get(0).getPeriod());
adjustmentTableMapper.deleteByExample(adjustmentTableExample);
......@@ -1150,7 +1152,7 @@ public class DataImportService extends BaseService {
dataImportLogs.add(dataImportLog);
}
public OperationResultDto importCPRExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importCPRExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -1167,9 +1169,9 @@ public class DataImportService extends BaseService {
// 根据主体分组处理
Map<String, List<CoupaPurchasingReport>> atsGroupRes =
ats.stream().collect(Collectors.groupingBy(CoupaPurchasingReport::getCompanyCode));
atsGroupRes.forEach((k, v) -> processCprs(k, v,orgIds, tmsPeriod, importType,dataImportLogs));
atsGroupRes.forEach((k, v) -> processCprs(k, v, orgIds, tmsPeriod, importType, dataImportLogs));
}
int isSuccess = (int)dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
int isSuccess = (int) dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
addDataImportLog(dataImportLogs);
if (isSuccess < 1) {
return OperationResultDto.error(ErrorMessage.ImportFailed);
......@@ -1177,26 +1179,26 @@ public class DataImportService extends BaseService {
return OperationResultDto.success();
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
} catch (Exception e) {
logger.error("importCPRExcelFile error.", e);
throw new ServiceException(ErrorMessage.SystemError);
}
}
private void processCprs(String companyCode, List<CoupaPurchasingReport> cprs,List<String> orgIds,
Integer tmsPeriod, Integer importType,List<DataImportLog> dataImportLogs) {
private void processCprs(String companyCode, List<CoupaPurchasingReport> cprs, List<String> orgIds,
Integer tmsPeriod, Integer importType, List<DataImportLog> dataImportLogs) {
OrganizationExample organizationExample = new OrganizationExample();
organizationExample.createCriteria().andCodeEqualTo(companyCode);
List<Organization> orgs = organizationMapper.selectByExample(organizationExample);
DataImportLog dataImportLog = generalDataImportLog(cprs.get(0).getCompanyCode(),"", "",
EnumImportType.CoupaPurchasingReport.getCode(), cprs.get(0).getPeriod()/100,
tmsPeriod%100, cprs.get(0).getPeriod()%100,
DataImportLog dataImportLog = generalDataImportLog(cprs.get(0).getCompanyCode(), "", "",
EnumImportType.CoupaPurchasingReport.getCode(), cprs.get(0).getPeriod() / 100,
tmsPeriod % 100, cprs.get(0).getPeriod() % 100,
"", "");
dataImportLog.setRecordSize(cprs.size());
//添加导入类型
dataImportLog.setImportType(importType);
if(orgs.size()<1){
if (orgs.size() < 1) {
dataImportLog.setErrorMsg(ErrorMessageCN.NoCompanyError);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1214,7 +1216,7 @@ public class DataImportService extends BaseService {
return;
}
if(!orgIds.contains(orgId)){
if (!orgIds.contains(orgId)) {
dataImportLog.setErrorMsg(ErrorMessageCN.DoNotSelectCompany);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1247,7 +1249,7 @@ public class DataImportService extends BaseService {
cpr.setTmsPeriod(tmsPeriod);
cpr.setProjectId(projId);
}
if (validateRes&&EnumTbImportType.CoverImport.getCode().equals(importType)) {
if (validateRes && EnumTbImportType.CoverImport.getCode().equals(importType)) {
CoupaPurchasingReportExample coupaPurchasingReportExample = new CoupaPurchasingReportExample();
coupaPurchasingReportExample.createCriteria().andCompanyCodeEqualTo(companyCode).andPeriodEqualTo(cprs.get(0).getPeriod());
coupaPurchasingReportMapper.deleteByExample(coupaPurchasingReportExample);
......@@ -1261,10 +1263,11 @@ public class DataImportService extends BaseService {
* 22/02/2019 12:50
* 导入发票记录表
* [file, periodDate, importType]
* @author Gary J Li
*
* @return
* @author Gary J Li
*/
public OperationResultDto importCILExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importCILExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
InputStream inputStream = file.getInputStream();
......@@ -1296,8 +1299,8 @@ public class DataImportService extends BaseService {
Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
DataImportLog dataImportLog = generalDataImportLog(companyCode, orgId, tayPayerIdNum,
EnumImportType.CertifiedInvoicesList.getCode(), period/100,
tmsPeriod%100, period%100,
EnumImportType.CertifiedInvoicesList.getCode(), period / 100,
tmsPeriod % 100, period % 100,
"", fileType);
//添加导入类型
dataImportLog.setImportType(importType);
......@@ -1328,7 +1331,7 @@ public class DataImportService extends BaseService {
dataImportLog.setCompanyName(companyName);
// 所选期间与导入文件期间不相等 且非 所选期间12期导入文件为13期
boolean isThirteenPeriod = period % 100 == 13 && tmsPeriod % 100 == 12;
if (!tmsPeriod.equals(period) && !isThirteenPeriod) {
if (!tmsPeriod.equals(period) && !isThirteenPeriod) {
dataImportLog.setImportResult(false);
dataImportLog.setErrorMsg(ErrorMessageCN.ExistDataPeriodsError);
dataImportLogs.add(dataImportLog);
......@@ -1360,10 +1363,10 @@ public class DataImportService extends BaseService {
cil.setInvoiceNum(getCellStringValue(cell3));
Cell cell4 = row.getCell(3);
try{
try {
String BillingDate = format.format(cell4.getDateCellValue());
cil.setBillingDate(DateUtils.strToDate4(BillingDate));
}catch (Exception e){
} catch (Exception e) {
cil.setBillingDate(DateUtils.strToDate4(getCellStringValue(cell4)));
}
Cell cell5 = row.getCell(4);
......@@ -1378,14 +1381,22 @@ public class DataImportService extends BaseService {
Cell cell8 = row.getCell(7);
cil.setTaxAmount(getCellBigDecimalValue(cell8));
Cell cell9 = row.getCell(8);
cil.setVerificationMethod(getCellStringValue(cell9));
Cell cell10 = row.getCell(9);
/*
Date dateCellValue = cell10.getDateCellValue();
String format1 = format.format(dateCellValue);
cil.setCertifiedDate(DateUtils.strToDate4(format1));
cil.setCertifiedDate(DateUtils.strToDate4(format1));*/
try {
String certDate = format.format(cell10.getDateCellValue());
cil.setCertifiedDate(DateUtils.strToDate4(certDate));
} catch (Exception e) {
cil.setCertifiedDate(DateUtils.strToDate4(getCellStringValue(cell10)));
}
Cell cell11 = row.getCell(10);
cil.setInvoiceType(getCellStringValue(cell11));
......@@ -1416,7 +1427,7 @@ public class DataImportService extends BaseService {
if (addDataImportLog(dataImportLogs) < 1) {
return OperationResultDto.error(ErrorMessage.SystemError);
}
if(!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()){
if (!dataImportLogs.stream().filter(dil -> !dil.getImportResult()).collect(Collectors.toList()).isEmpty()) {
return OperationResultDto.error();
}
return OperationResultDto.success();
......@@ -1428,7 +1439,7 @@ public class DataImportService extends BaseService {
}
}
public OperationResultDto importIRExcelFile(MultipartFile file,List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
public OperationResultDto importIRExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
try {
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
......@@ -1445,9 +1456,9 @@ public class DataImportService extends BaseService {
// 根据主体分组处理
Map<String, List<InvoiceRecord>> atsGroupRes =
irs.stream().collect(Collectors.groupingBy(InvoiceRecord::getBillingBody));
atsGroupRes.forEach((k, v) -> processIrs(k, v,orgIds, tmsPeriod, importType,dataImportLogs));
atsGroupRes.forEach((k, v) -> processIrs(k, v, orgIds, tmsPeriod, importType, dataImportLogs));
}
int isSuccess = (int)dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
int isSuccess = (int) dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
addDataImportLog(dataImportLogs);
if (isSuccess < 1) {
return OperationResultDto.error(ErrorMessage.ImportFailed);
......@@ -1455,26 +1466,26 @@ public class DataImportService extends BaseService {
return OperationResultDto.success();
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
} catch (Exception e) {
logger.error("importIRExcelFile error.", e);
throw new ServiceException(ErrorMessage.SystemError);
}
}
private void processIrs(String billingBody, List<InvoiceRecord> irs,List<String> orgIds,
Integer tmsPeriod, Integer importType,List<DataImportLog> dataImportLogs) {
private void processIrs(String billingBody, List<InvoiceRecord> irs, List<String> orgIds,
Integer tmsPeriod, Integer importType, List<DataImportLog> dataImportLogs) {
OrganizationExample organizationExample = new OrganizationExample();
organizationExample.createCriteria().andNameEqualTo(billingBody);
List<Organization> orgs = organizationMapper.selectByExample(organizationExample);
DataImportLog dataImportLog = generalDataImportLog("","", "",
EnumImportType.InvoiceRecord.getCode(), irs.get(0).getPeriod()/100,
tmsPeriod%100, irs.get(0).getPeriod()%100,
DataImportLog dataImportLog = generalDataImportLog("", "", "",
EnumImportType.InvoiceRecord.getCode(), irs.get(0).getPeriod() / 100,
tmsPeriod % 100, irs.get(0).getPeriod() % 100,
irs.get(0).getBillingBody(), "");
dataImportLog.setRecordSize(irs.size());
//添加导入类型
dataImportLog.setImportType(importType);
if(orgs.size()<1){
if (orgs.size() < 1) {
dataImportLog.setErrorMsg(ErrorMessageCN.NoCompanyError);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1492,7 +1503,7 @@ public class DataImportService extends BaseService {
return;
}
if(!orgIds.contains(orgId)){
if (!orgIds.contains(orgId)) {
dataImportLog.setErrorMsg(ErrorMessageCN.DoNotSelectCompany);
dataImportLog.setImportResult(false);
dataImportLogs.add(dataImportLog);
......@@ -1509,7 +1520,7 @@ public class DataImportService extends BaseService {
boolean validateRes = true;
for (InvoiceRecord ir : irs) {
// 校验该主体导入所有记录区间是否一致
if(null==ir.getPeriod()){
if (null == ir.getPeriod()) {
dataImportLog.setImportResult(false);
dataImportLog.setErrorMsg(ErrorMessageCN.DoNotInputPeriod);
validateRes = false;
......@@ -1532,7 +1543,7 @@ public class DataImportService extends BaseService {
ir.setProjectId(projId);
ir.setTmsPeriod(tmsPeriod);
}
if (validateRes&&EnumTbImportType.CoverImport.getCode().equals(importType)) {
if (validateRes && EnumTbImportType.CoverImport.getCode().equals(importType)) {
InvoiceRecordExample invoiceRecordExample = new InvoiceRecordExample();
invoiceRecordExample.createCriteria().andBillingBodyEqualTo(billingBody).andPeriodEqualTo(irs.get(0).getPeriod());
invoiceRecordMapper.deleteByExample(invoiceRecordExample);
......@@ -1555,7 +1566,7 @@ public class DataImportService extends BaseService {
rlit.setSubjectNum(getCellStringValue(row.getCell(0)));
rlit.setSubjectName(getCellStringValue(row.getCell(1)));
Object value = CitCommonUtil.getValue(row.getCell(2));
if(!"".equals(value)){
if (!"".equals(value)) {
rlit.setRedLetterInvoiceInfoTableNum(new BigDecimal(value.toString()).toPlainString());
}
rlit.setPeriod(DateUtils.dateToPeriod(row.getCell(3).getDateCellValue()));
......@@ -1575,7 +1586,7 @@ public class DataImportService extends BaseService {
private List<InvoiceRecord> generalIRs(Sheet sheet) {
List<InvoiceRecord> irs = Lists.newArrayList();
Set<String> orgsNot=new HashSet<>();
Set<String> orgsNot = new HashSet<>();
for (int j = 1; j <= sheet.getLastRowNum(); j++) {
InvoiceRecord ir = new InvoiceRecord();
Long irId = idService.nextId();
......@@ -1586,11 +1597,11 @@ public class DataImportService extends BaseService {
ir.setId(irId);
ir.setSeqNo(getCellIntegerValue(row.getCell(0)));
//所属机构
if(StringUtils.isBlank(getCellStringValue(row.getCell(1)))){
if (StringUtils.isBlank(getCellStringValue(row.getCell(1)))) {
continue;
}
//如果存在有错误的机构也跳过
if(validIRExcelCell(row,orgsNot).contains(getCellStringValue(row.getCell(1)))){
if (validIRExcelCell(row, orgsNot).contains(getCellStringValue(row.getCell(1)))) {
continue;
}
ir.setBillingBody(getCellStringValue(row.getCell(1)));
......@@ -1626,32 +1637,32 @@ public class DataImportService extends BaseService {
* 导入分发-已开增值税发票记录,校验1-发票类型、开票内容、所属机构、税率、税额、开票金额任意不为空;
* 且校验2-校验发票类型的值只能包含“增值税专用发票”、“增值税普通发票”、“增值税电子发票”和“机动车发票”,
* 存在校验1或校验2不通过的机构不进行导入
*
* @param row
* @return
*/
private Set<String> validIRExcelCell(Row row,Set<String> orgsNot ){
List<String> invoiceTypes=Arrays.asList(new String[]{"增值税专用发票","增值税普通发票","增值税电子发票","机动车发票"});
String orgName=getCellStringValue(row.getCell(1));
private Set<String> validIRExcelCell(Row row, Set<String> orgsNot) {
List<String> invoiceTypes = Arrays.asList(new String[]{"增值税专用发票", "增值税普通发票", "增值税电子发票", "机动车发票"});
String orgName = getCellStringValue(row.getCell(1));
//发票类型
if(StringUtils.isBlank(getCellStringValue(row.getCell(3)))){
if (StringUtils.isBlank(getCellStringValue(row.getCell(3)))) {
orgsNot.add(orgName);
}
else if(!invoiceTypes.contains(getCellStringValue(row.getCell(3)))){
} else if (!invoiceTypes.contains(getCellStringValue(row.getCell(3)))) {
orgsNot.add(orgName);
}
//开票内容
if(StringUtils.isBlank(getCellStringValue(row.getCell(4)))){
if (StringUtils.isBlank(getCellStringValue(row.getCell(4)))) {
orgsNot.add(orgName);
}
//开票金额
if(StringUtils.isBlank(getCellStringValue(row.getCell(5)))){
if (StringUtils.isBlank(getCellStringValue(row.getCell(5)))) {
orgsNot.add(orgName);
}
//税额
if(StringUtils.isBlank(getCellStringValue(row.getCell(20)))){
if (StringUtils.isBlank(getCellStringValue(row.getCell(20)))) {
orgsNot.add(orgName);
}
return orgsNot;
return orgsNot;
}
private List<AdjustmentTable> generalATs(Sheet sheet) {
......@@ -1670,9 +1681,9 @@ public class DataImportService extends BaseService {
// at.setPeriod(period);
Object value = CitCommonUtil.getValue(row.getCell(0));
if(!"".equals(value)){
if (!"".equals(value)) {
String periodStr = value.toString();
Integer period = Integer.valueOf(periodStr.substring(0,4)+periodStr.substring(5,7));
Integer period = Integer.valueOf(periodStr.substring(0, 4) + periodStr.substring(5, 7));
at.setPeriod(period);
}
......@@ -1729,7 +1740,7 @@ public class DataImportService extends BaseService {
cpr.setCurrency(getCellStringValue(row.getCell(12)));
String billNum = getCellStringValue(row.getCell(13));
cpr.setBillNum(billNum);
cpr.setCompanyCode(StringUtils.isNotEmpty(billNum)?billNum.substring(0,6):"");
cpr.setCompanyCode(StringUtils.isNotEmpty(billNum) ? billNum.substring(0, 6) : "");
cpr.setPaid(getCellBolleanValue(row.getCell(14)));
cpr.setAmortization(getCellBolleanValue(row.getCell(15)));
cpr.setPrepayments(getCellBolleanValue(row.getCell(16)));
......@@ -1752,21 +1763,21 @@ public class DataImportService extends BaseService {
}
private String getCellStringValue(Cell cell) {
if(null==cell){
if (null == cell) {
return "";
}
if (cell.getCellTypeEnum().equals(CellType.STRING)) {
return cell.getStringCellValue().trim();
} else if(cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
} else if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
// 取整
return String.valueOf((int)cell.getNumericCellValue()).trim();
return String.valueOf((int) cell.getNumericCellValue()).trim();
}
logger.warn("获取单元格数据类型未匹配");
return null;
}
private Boolean getCellBolleanValue(Cell cell) {
if(null==cell){
if (null == cell) {
return false;
}
if (cell.getCellTypeEnum().equals(CellType.STRING)) {
......@@ -1782,7 +1793,7 @@ public class DataImportService extends BaseService {
default:
return null;
}
}else if (cell.getCellTypeEnum().equals(CellType.BOOLEAN)) {
} else if (cell.getCellTypeEnum().equals(CellType.BOOLEAN)) {
return cell.getBooleanCellValue();
}
logger.warn("获取单元格数据类型未匹配");
......@@ -1790,25 +1801,25 @@ public class DataImportService extends BaseService {
}
private Integer getCellIntegerValue(Cell cell) {
if(null==cell){
if (null == cell) {
return null;
}
if (cell.getCellTypeEnum().equals(CellType.STRING)) {
return Integer.valueOf(cell.getStringCellValue().trim());
} else if(cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
return (int)cell.getNumericCellValue();
} else if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
return (int) cell.getNumericCellValue();
}
logger.warn("获取单元格数据类型未匹配");
return null;
}
private BigDecimal getCellBigDecimalValue(Cell cell) {
if(null==cell){
if (null == cell) {
return null;
}
if (cell.getCellTypeEnum().equals(CellType.STRING)) {
return new BigDecimal(cell.getStringCellValue().trim());
} else if(cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
} else if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
return new BigDecimal(cell.getNumericCellValue());
}
logger.warn("获取单元格数据类型未匹配");
......@@ -1816,12 +1827,12 @@ public class DataImportService extends BaseService {
}
private Long getCellLongDecimalValue(Cell cell) {
if(null==cell){
if (null == cell) {
return null;
}
if (cell.getCellTypeEnum().equals(CellType.STRING)) {
return Long.valueOf(cell.getStringCellValue().trim());
} else if(cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
} else if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) {
return new Double(cell.getNumericCellValue()).longValue();
}
logger.warn("获取单元格数据类型未匹配");
......@@ -1840,24 +1851,24 @@ public class DataImportService extends BaseService {
/**
* 25/02/2019 18:52
*
* <p>
* [type]
* @author Gary J Li
* @return
*
* @return
* @author Gary J Li
*/
public PageInfo<DataImportLogDto> displayImportLog(DataImportParam param) {
DataImportLogExample example = new DataImportLogExample();
DataImportLogExample.Criteria criteria =example.createCriteria();
DataImportLogExample.Criteria criteria = example.createCriteria();
List<String> orgIds = organizationService.getMyOrgList().stream().map(OrgSelectDto::getId).collect(Collectors.toList());
// 这里会导致任何人都可以看到未映射到主体的数据
orgIds.add("");
if(!EnumImportType.Undefined.getCode().equals(param.getType())){
criteria.andTypeEqualTo(param.getType()).andDisplayEqualTo(true);
criteria.andOrganizationIdIn(orgIds);
if (!EnumImportType.Undefined.getCode().equals(param.getType())) {
criteria.andTypeEqualTo(param.getType()).andDisplayEqualTo(true);
criteria.andOrganizationIdIn(orgIds);
}
example.setOrderByClause("update_time desc");
Page page = PageHelper.startPage(param.getPageInfo().getPageIndex(), param.getPageInfo().getPageSize());
......@@ -1870,11 +1881,11 @@ public class DataImportService extends BaseService {
/**
* 25/02/2019 18:52
*
* <p>
* [type]
* @author Gary J Li
* @return
*
* @return
* @author Gary J Li
*/
public PageInfo<DataImportLogDto> displayImportLogAll(DataImportAllParam param) {
......@@ -1883,12 +1894,12 @@ public class DataImportService extends BaseService {
DataImportLogExample example = new DataImportLogExample();
DataImportLogExample.Criteria criteria =example.createCriteria();
DataImportLogExample.Criteria criteria = example.createCriteria();
Page page = PageHelper.startPage(param.getPageInfo().getPageIndex(), param.getPageInfo().getPageSize());
List<String> orgIds = organizationService.getMyOrgList().stream().map(OrgSelectDto::getId).collect(Collectors.toList());
criteria.andOrganizationIdIn(orgIds).andCreateTimeBetween(strDate,endDate);
criteria.andOrganizationIdIn(orgIds).andCreateTimeBetween(strDate, endDate);
example.setOrderByClause("update_time desc");
PageInfo<DataImportLogDto> pageInfo = new PageInfo<>(dataImportLogMapper.selectByExample(example).stream()
......@@ -1900,11 +1911,11 @@ public class DataImportService extends BaseService {
/**
* 25/02/2019 18:52
*
* <p>
* [type]
* @author Gary J Li
* @return
*
* @return
* @author Gary J Li
*/
public PageInfo<DataValidateLogDto> displayProcessLog(DataProcessParam param) {
......@@ -1913,14 +1924,14 @@ public class DataImportService extends BaseService {
DataValidateLogExample example = new DataValidateLogExample();
DataValidateLogExample.Criteria criteria =example.createCriteria();
DataValidateLogExample.Criteria criteria = example.createCriteria();
Page page = PageHelper.startPage(param.getPageInfo().getPageIndex(), param.getPageInfo().getPageSize());
List<String> orgIds = organizationService.getMyOrgList().stream().map(OrgSelectDto::getId).collect(Collectors.toList());
// 这里会导致任何人都可以看到未映射到主体的数据
orgIds.add("");
criteria.andOrganizationIdIn(orgIds).andCreateTimeBetween(strDate,endDate);
criteria.andOrganizationIdIn(orgIds).andCreateTimeBetween(strDate, endDate);
example.setOrderByClause("update_time desc");
PageInfo<DataValidateLogDto> pageInfo = new PageInfo<>(dataValidateLogMapper.selectByExample(example).stream()
......@@ -1936,8 +1947,9 @@ public class DataImportService extends BaseService {
* 2、定长线程池超过最长时丢弃记录日志
* 3、调用成功使用taskId作为日志id,未成功使用随机id
* [param]
* @author Gary J Li
*
* @return
* @author Gary J Li
*/
public OperationResultDto callExtractFinancialData(DataExtractParam param) {
OrganizationExample example = new OrganizationExample();
......@@ -1954,8 +1966,8 @@ public class DataImportService extends BaseService {
dataTypes.forEach(type -> {
orgs.forEach(o -> {
try {
Callable callEbs = new CallEbsThread(type, o,ebsCallUrl,dataImportLogMapper,authUserHelper,
idService,dtsTokenService,period, effectiveDateFrom, effectiveDateTo, operator);
Callable callEbs = new CallEbsThread(type, o, ebsCallUrl, dataImportLogMapper, authUserHelper,
idService, dtsTokenService, period, effectiveDateFrom, effectiveDateTo, operator);
executorService.submit(callEbs);
// resList.add(future);
} catch (RejectedExecutionException rje) {
......@@ -1983,7 +1995,7 @@ public class DataImportService extends BaseService {
dil.setDisplay(false);
DataImportLogExample e = new DataImportLogExample();
e.createCriteria().andCreateTimeLessThan(DateUtils.getThreeDayZero());
dataImportLogMapper.updateByExampleSelective(dil,e);
dataImportLogMapper.updateByExampleSelective(dil, e);
});
// 校验是否全部调用成功 这里有点问题
/*int res = 0;
......@@ -1998,17 +2010,17 @@ public class DataImportService extends BaseService {
}catch (Exception e){
logger.error("获取结果异常");
}*/
resList=null;
resList = null;
return OperationResultDto.success();
}
/**
* 25/02/2019 18:26
*
* <p>
* [orgIds, period, dataTypes]
*
* @return remark:1、这里重复写了,因为可能调用场景不同?
* @author Gary J Li
* @return
* remark:1、这里重复写了,因为可能调用场景不同?
*/
public OperationResultDto callExtractInvoiceData(DataExtractParam dataExtractParam) {
// todo 调用滴滴的http发票数据抽取调用接口 List<String> codes, Integer period, List<Integer> dataTypes
......@@ -2031,11 +2043,11 @@ public class DataImportService extends BaseService {
return false;
}
private String getProjId(String orgId, Integer tmsPeriod) {
private String getProjId(String orgId, Integer tmsPeriod) {
ProjectExample pExample = new ProjectExample();
pExample.createCriteria().andOrganizationIdEqualTo(orgId).andYearEqualTo(tmsPeriod/100);
pExample.createCriteria().andOrganizationIdEqualTo(orgId).andYearEqualTo(tmsPeriod / 100);
List<Project> pList = projectMapper.selectByExample(pExample);
if(!pList.isEmpty()){
if (!pList.isEmpty()) {
return pList.get(0).getId();
}
return "";
......@@ -2045,11 +2057,11 @@ public class DataImportService extends BaseService {
/**
* "http://172.20.201.201:8020/ebs-proxy-test/dts/glMonthlyBal?ledgerId=2021&companyCode=120200&period=2018-11"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/fsgCash/?ledgerId=2021&companyCode=120200&period=2019-02"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/fsgAsset?ledgerId=2021&period=2018-12&companyCode=120113&prcFlag=N"
* "http://172.20.201.201:8020/ebs-proxy-test/dts//fsgProfit?ledgerId=2021&companyCode=120200&period=2018-10&prcFlag=Y"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/glJeLines/?ledgerId=2041&companyCode=110100&effectiveDateFrom=2018-02-01&effectiveDateTo=2018-02-10"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/dailyRates?period=2018-10"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/fsgCash/?ledgerId=2021&companyCode=120200&period=2019-02"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/fsgAsset?ledgerId=2021&period=2018-12&companyCode=120113&prcFlag=N"
* "http://172.20.201.201:8020/ebs-proxy-test/dts//fsgProfit?ledgerId=2021&companyCode=120200&period=2018-10&prcFlag=Y"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/glJeLines/?ledgerId=2041&companyCode=110100&effectiveDateFrom=2018-02-01&effectiveDateTo=2018-02-10"
* "http://172.20.201.201:8020/ebs-proxy-test/dts/dailyRates?period=2018-10"
*/
private static class CallEbsThread implements Callable {
......@@ -2078,7 +2090,7 @@ public class DataImportService extends BaseService {
CallEbsThread(int type, Organization org, String ebsCallUrl, DataImportLogMapper dataImportLogMapper,
AuthUserHelper authUserHelper, DistributedIdService idService, DtsTokenService dtsTokenService,
String period,String effectiveDateFrom, String effectiveDateTo, String operator) {
String period, String effectiveDateFrom, String effectiveDateTo, String operator) {
this.type = type;
this.org = org;
this.period = period;
......@@ -2093,7 +2105,7 @@ public class DataImportService extends BaseService {
}
@Override
public Integer call(){
public Integer call() {
String response = null;
String ledgerId = org.getEnterpriseAccountCode();
String code = org.getCode();
......@@ -2116,7 +2128,7 @@ public class DataImportService extends BaseService {
if (StringUtils.isEmpty(org.getEnterpriseAccountCode())) {
log.setImportResult(false);
log.setErrorMsg(String.format(EnumApiCodeMsg.CALLFAILED.getMsg(), ErrorMessageCN.NoLedgerID));
}else if(StringUtils.isEmpty(org.getCode())) {
} else if (StringUtils.isEmpty(org.getCode())) {
log.setImportResult(false);
log.setErrorMsg(String.format(EnumApiCodeMsg.CALLFAILED.getMsg(), ErrorMessageCN.NoCompanyCode));
}
......@@ -2125,45 +2137,45 @@ public class DataImportService extends BaseService {
return 0;
}
String secureToken = dtsTokenService.encryptInput();
Map<String,String> headers = new HashMap<>();
headers.put("secureToken",secureToken);
Map<String, String> headers = new HashMap<>();
headers.put("secureToken", secureToken);
switch (type) {
case EbsExtractTypeConstant.TB:
response = HttpUtil.post(ebsCallUrl + "/glMonthlyBal?ledgerId="+ledgerId+"&companyCode="+ code + "&period=" + period,
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/glMonthlyBal?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period,
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.JE:
// 这里BA反馈可按期间获取当月日记账即可
String effecDateFrom = DateUtils.getFirstDayOfMonth(year,month);
String effecDateTo = DateUtils.getLastDayOfMonth(year,month);
response = HttpUtil.post(ebsCallUrl + "/glJeLines"+"?ledgerId=" + ledgerId + "&companyCode=" + code + "&effectiveDateFrom=" + effecDateFrom+"&effectiveDateTo="+effecDateTo,
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
String effecDateFrom = DateUtils.getFirstDayOfMonth(year, month);
String effecDateTo = DateUtils.getLastDayOfMonth(year, month);
response = HttpUtil.post(ebsCallUrl + "/glJeLines" + "?ledgerId=" + ledgerId + "&companyCode=" + code + "&effectiveDateFrom=" + effecDateFrom + "&effectiveDateTo=" + effecDateTo,
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.BSPRC:
response = HttpUtil.post(ebsCallUrl + "/fsgAsset"+"?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period+"&prcFlag=Y",
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/fsgAsset" + "?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period + "&prcFlag=Y",
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.PLPRC:
response = HttpUtil.post(ebsCallUrl + "/fsgProfit"+"?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period+"&prcFlag=Y",
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/fsgProfit" + "?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period + "&prcFlag=Y",
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.BS:
response = HttpUtil.post(ebsCallUrl + "/fsgAsset"+"?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period+"&prcFlag=N",
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/fsgAsset" + "?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period + "&prcFlag=N",
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.PL:
response = HttpUtil.post(ebsCallUrl + "/fsgProfit"+"?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period+"&prcFlag=N",
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/fsgProfit" + "?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period + "&prcFlag=N",
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.CF:
response = HttpUtil.post(ebsCallUrl + "/fsgCash"+"?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period,
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/fsgCash" + "?ledgerId=" + ledgerId + "&companyCode=" + code + "&period=" + period,
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
case EbsExtractTypeConstant.OCTB:
break;
case EbsExtractTypeConstant.RATE:
response = HttpUtil.post(ebsCallUrl + "/dailyRates"+"?period=" + period,
headers,"application/json;charset=utf-8", "UTF-8", 10000, 10000);
response = HttpUtil.post(ebsCallUrl + "/dailyRates" + "?period=" + period,
headers, "application/json;charset=utf-8", "UTF-8", 10000, 10000);
break;
default:
break;
......@@ -2176,8 +2188,8 @@ public class DataImportService extends BaseService {
log.setImportResult(false);
log.setErrorMsg(String.format(EnumApiCodeMsg.CALLFAILED.getMsg(), resp.getTaskDesc()));
} else {
if(EbsExtractTypeConstant.JE==type){
resp.setCompanyCode(null!=resp.getSegment1()?resp.getSegment1():"");
if (EbsExtractTypeConstant.JE == type) {
resp.setCompanyCode(null != resp.getSegment1() ? resp.getSegment1() : "");
}
log.setId(taskId);
log.setImportResult(true);
......@@ -2196,5 +2208,4 @@ public class DataImportService extends BaseService {
}
}
......@@ -9,11 +9,7 @@ import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
......@@ -1738,6 +1734,82 @@ public class ReportServiceImpl extends BaseService {
return ebitDataDto;
}
public EbitDataDto calculateEbitDataByEbit(List<EbitCellData> ebitCellData, String specialConsiderations, String ebitRate) {
EbitDataDto ebitDataDto = new EbitDataDto();
try {
BigDecimal spec = new BigDecimal(0);
double rate = 0.01; //ebitRate
if ("".equals(specialConsiderations)) {
specialConsiderations = "0";
}
if (!ebitRate.isEmpty()) {
int _index = ebitRate.indexOf("%");
if (_index != -1) {
rate = Double.parseDouble(ebitRate.substring(0, _index)) / 100;
} else {
rate = Double.parseDouble(ebitRate) / 100;
}
}
spec = new BigDecimal(specialConsiderations);
BigDecimal yysr = new BigDecimal(0);//营业收入
BigDecimal yycb = new BigDecimal(0);//营业成本
BigDecimal yysjfj = new BigDecimal(0);//营业税金附加
BigDecimal xsfy = new BigDecimal(0);//销售费用
BigDecimal glfy = new BigDecimal(0);//管理费用
BigDecimal yffy = new BigDecimal(0);//研发费用
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());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 12) {//减:营业成本
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());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 14) {//销售费用
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());
continue;
}
if (ebitCellData1.getCol() == 2 && ebitCellData1.getRow() == 16) {//研发费用
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());
continue;
}
}
BigDecimal subtract = yysr.subtract(yycb).add(yysjfj).add(xsfy).add(glfy).add(yffy).add(zcjzss);
ebitDataDto.setEbitSubtraction(subtract);
ebitDataDto.setSpecialFactors(subtract.add(spec));
ebitDataDto.setEbitRate(String.valueOf(rate));
ebitDataDto.setTransactionAmount(ebitDataDto.getSpecialFactors().multiply(new BigDecimal(ebitDataDto.getEbitRate())));
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.setSpecialConsiderations(specialConsiderations);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ebitDataDto;
}
private Integer convertType(Integer dataSourceType) {
if (dataSourceType.equals(FormulaDataSourceDetailType.InputInvoiceDataSourceDto.getCode())) {
return CellDataSourceType.InputInvoice.getCode();
......@@ -2583,7 +2655,7 @@ public class ReportServiceImpl extends BaseService {
EbitCellDataExample cellDataExample = new EbitCellDataExample();
cellDataExample.createCriteria().andPeriodEqualTo(requestParameterDto.getPeriod());
List<EbitCellData> list2 = ebitCellDataMapper.selectByExample(cellDataExample);
Map<String, List<EbitCellData>> collect1 = list2.stream().collect(Collectors.groupingBy(EbitCellData::getOrganizationId));
Map<String, List<EbitCellData>> collect1 = list2.stream().filter(x -> (x.getOrganizationId() != "null" && x.getOrganizationId() != null)).collect(Collectors.groupingBy(EbitCellData::getOrganizationId));
Map<String, List<ProfitLossStatementPrc>> newMap = new HashMap<>();
///如果ebitCellData 中已经存在当前机构的数,将取 ebit中,否则取利润表中
......@@ -2607,14 +2679,29 @@ public class ReportServiceImpl extends BaseService {
sheetAt = workbook1.getSheetAt(0);
List<Integer> cols = Lists.newArrayList();
FileExcelUtil.deleteColumn(sheetAt, 1, cols);
//var profileList = ["EBIT考虑资产减值损失", "", "", "", "", "", ""];
List<String> ebitTitle = Lists.newArrayList("EBIT考虑资产减值损失", "加:特殊因素考虑", "EBIT(考虑特殊因素)", "EBIT rate", "关联交易金额", "6%增值税", "价税合计金额");
//给第一个sheet创建ebit 行
for (int i = 37; i <= 43; i++) {
sheetAt.createRow(i).createCell(0).setCellValue(ebitTitle.get(i - 37));
}
List<EbitDataDto> ebitCellDataList = new ArrayList<>();
for (Map.Entry<String, List<EbitCellData>> entry : finalMap.entrySet()) {
for (int m = 0; m < sheetAt.getLastRowNum(); m++) {
//加载计算ebit数据
ebitCellDataList.add(calculateEbitDataByEbit(entry.getValue(), specialConsideration, ebitRate));
for (int m = 0; m <= sheetAt.getLastRowNum(); m++) {
switch (m) {
case 7:
try{
sheetAt.getRow(m).getCell(_index + 1).setCellValue(getOrgName(entry.getKey()));
}catch (Exception e){
if (sheetAt.getRow(m) == null) {
sheetAt.createRow(m).createCell(_index + 1).setCellValue(getOrgName(entry.getKey()));
} else {
if (sheetAt.getRow(m).getCell(_index + 1) == null) {
sheetAt.getRow(m).createCell(_index + 1).setCellValue(getOrgName(entry.getKey()));
} else {
sheetAt.getRow(m).getCell(_index + 1).setCellValue(getOrgName(entry.getKey()));
}
}
break;
case 8:
......@@ -2630,9 +2717,9 @@ public class ReportServiceImpl extends BaseService {
if (sheetAt.getRow(m) != null && sheetAt.getRow(m).getCell(_index + 1) != null) {
for (EbitCellData ebitCellData : entry.getValue()) {
if (m == ebitCellData.getRow() && ebitCellData.getCol() == (_index + 1)) {
try{
try {
sheetAt.getRow(m).getCell(_index + 1).setCellValue(ebitCellData.getData());
}catch (Exception e){
} catch (Exception e) {
sheetAt.getRow(m).createCell(_index + 1).setCellValue(ebitCellData.getData());
}
}
......@@ -2640,6 +2727,31 @@ public class ReportServiceImpl extends BaseService {
}
//cell.setCellType(cellStyle.getAlignment());
}
for (EbitDataDto ebitCellData : ebitCellDataList) {
switch (m){
case 37:
cellAndOrCreate(m, _index+1, ebitCellData.getEbitSubtraction().toString(), sheetAt);
break;
case 38:
cellAndOrCreate(m, _index+1, ebitCellData.getSpecialConsiderations(), sheetAt);
break;
case 39:
cellAndOrCreate(m, _index+1, ebitCellData.getSpecialFactors().toString(), sheetAt);
break;
case 40:
cellAndOrCreate(m, _index+1, ebitCellData.getEbitRate(), sheetAt);
break;
case 41:
cellAndOrCreate(m, _index+1, ebitCellData.getTransactionAmount().toString(), sheetAt);
break;
case 42:
cellAndOrCreate(m, _index+1, ebitCellData.getSixAddTax().toString(), sheetAt);
break;
case 43:
cellAndOrCreate(m, _index+1, ebitCellData.getTotalAmountTax().toString(), sheetAt);
break;
}
}
}
_index++;
}
......@@ -2682,6 +2794,14 @@ public class ReportServiceImpl extends BaseService {
FileExcelUtil.downloadExcel(request, response, requestParameterDto.getPeriod() + "-汇总利润表.xlsx", workbook1);
}
public void 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);
}
}
/* public void insertData(String templateId, Integer period, Sheet sheet, int beginCell) {
......
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