Commit 41db656d authored by Memorydoc's avatar Memorydoc

#

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