Commit 703733d3 authored by neo's avatar neo

[dev] financeDataUpload impl and importFinancedata impl

parent 1119f37d
package pwc.taxtech.atms.common.util;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.exception.ApiException;
import pwc.taxtech.atms.exception.FormulaException;
......
......@@ -6,6 +6,8 @@ public class VatErpImportValidation {
public static final String BalanceTb = "Balance";
public static final String AccountRemapTb = "AccountRemap";
public static final String VoucherTbName = "Voucher";
public static final String ImportMethod_OneClick = "oneClick";
public static final String ImportMethod_Universal = "universal";
public static final String Const_ComBalanceAcctValidate = "试算平衡表科目存在于企业科目列表中";
public static final String Const_ComBalanceAcctUnValidate = "试算平衡表中出现的科目不在科目表中";
......
package pwc.taxtech.atms.constant.enums;
public enum ImportType {
Override(0),
Append(1);
private Integer code;
ImportType(Integer code) {
this.code = code;
}
public Integer getCode() {
return code;
}
}
package pwc.taxtech.atms.vat.service.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.constant.VatErpImportValidation;
import pwc.taxtech.atms.constant.enums.EnumValidationType;
import pwc.taxtech.atms.constant.enums.ErpCheckType;
import pwc.taxtech.atms.constant.enums.ImageType;
import pwc.taxtech.atms.dto.FieldsMapper;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.vatdto.DataCheckDto;
import pwc.taxtech.atms.dto.vatdto.ImportDataDto;
import pwc.taxtech.atms.dto.vatdto.VoucherAccountMto;
import pwc.taxtech.atms.dto.vatdto.VoucherBalanceDto;
import pwc.taxtech.atms.dto.vatdto.VoucherDto;
......@@ -21,10 +30,13 @@ import pwc.taxtech.atms.vat.entity.VoucherExample;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import javax.sound.sampled.DataLine;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Comparator;
......@@ -45,6 +57,9 @@ public class FinanceDataImportServiceImpl {
private ValidationInfoMapper validationInfoMapper;
@Autowired
private VoucherMapper voucherMapper;
@Autowired
private SqlSessionTemplate dynamicSqlSessionTemplate;
private Logger logger = LoggerFactory.getLogger(FinanceDataImportServiceImpl.class);
public OperationResultDto<List<DataCheckDto>> getBasicValidationResults(String userId) {
Integer number = 1;
......@@ -322,4 +337,105 @@ public class FinanceDataImportServiceImpl {
private List<ValidationInfo> getValidationData(Integer typeId) {
return getValidationData(typeId, null);
}
public Boolean ClearTable(int period, Boolean isClearCustTb) {
if (isClearCustTb == null) isClearCustTb = true;
ClearCustTable(period, VatErpImportValidation.CompanyBalanceTbName);
if (isClearCustTb) {
ClearCustTable(period, VatErpImportValidation.CustBalanceTb);
}
ClearCustTable(period, VatErpImportValidation.BalanceTb);
ClearVoucherTable(period);
ClearRemapTable(period);
return true;
}
private void ClearVoucherTable(int period) {
String command = IsImportByPeriod(period)
? "DELETE FROM " + VatErpImportValidation.VoucherTbName + " WHERE Period = " + period
: "TRUNCATE TABLE " + VatErpImportValidation.VoucherTbName;
exeCommand(command);
}
private boolean IsImportByPeriod(int period) {
return period >= 0;
}
private void ClearRemapTable(int period) {
String command = IsImportByPeriod(period)
? "DELETE FROM " + VatErpImportValidation.AccountRemapTb + " WHERE Period = " + period
: "TRUNCATE TABLE " + VatErpImportValidation.AccountRemapTb;
exeCommand(command);
}
private void ClearCustTable(int period, String tbName) {
String command = "";
if (IsImportByPeriod(period) && tbName != VatErpImportValidation.BalanceTb) {
if (tbName == VatErpImportValidation.CompanyBalanceTbName) {
command = String.format("DELETE FROM %s WHERE PeriodId = %s", tbName, period);
}
if (tbName == VatErpImportValidation.CustBalanceTb) {
command = String.format("DELETE FROM %s WHERE PeriodId >= %s", tbName, period);
}
} else {
command = "TRUNCATE TABLE " + tbName;
}
exeCommand(command);
}
private void exeCommand(String command) {
try (SqlSession sqlSession = dynamicSqlSessionTemplate.getSqlSessionFactory().openSession();) {
ScriptRunner scriptRunner = new ScriptRunner(sqlSession.getConnection());
scriptRunner.setAutoCommit(true);
scriptRunner.runScript(new StringReader(command));
}
}
public void DeleteErpValidation() {
List<Integer> deleteTypes = Lists.<Integer>newArrayList(EnumValidationType.ErpBasicCheck.getCode(),
EnumValidationType.ErpCorrect.getCode(),
EnumValidationType.ErpDuplicate.getCode());
ValidationInfoExample example = new ValidationInfoExample();
example.createCriteria().andImportTypeIdIn(deleteTypes);
validationInfoMapper.deleteByExample(example);
}
public ImportDataDto ImportData(String projectYear, String importMethod, String importType, Integer period,
String fileFullPath, MultipartFile f, String schemaPath, String userId) {
logger.info("开始导入数据: importMethod: {0}, importType: {1}", importMethod, importType);
ImportDataDto importResult = new ImportDataDto();
String ZipFileFolder = "";
try {
if (importMethod == VatErpImportValidation.ImportMethod_OneClick) {
// UnZipDataFile(fileFullPath, schemaPath);//todo: import data tobe continue(neo)
// ImportBalance(ZipFileFolder, period);
// ImportVoucher(ZipFileFolder, period);
}
if (importMethod == VatErpImportValidation.ImportMethod_Universal) {
// UniversalImportData(period, fileFullPath, f.getName(), schemaPath);
}
// SynAccountFromTaxAdmin(period, userId);
importResult.Result = true;
} catch (Exception ex) {
importResult.Result = false;
}
return importResult;
}
public void UpdateCompanyBalanceNullValue() {
String command = "UPDATE CompanyBalance SET BegDebitBal = 0 WHERE BegDebitBal IS NULL"
+ " UPDATE CompanyBalance SET BegCreditBal = 0 WHERE BegCreditBal IS NULL"
+ " UPDATE CompanyBalance SET BegBal = 0 WHERE BegBal IS NULL"
+ " UPDATE CompanyBalance SET EndBal = 0 WHERE EndBal IS NULL"
+ " UPDATE CompanyBalance SET EndDebitBal = 0 WHERE EndDebitBal IS NULL"
+ " UPDATE CompanyBalance SET EndCreditBal = 0 WHERE EndCreditBal IS NULL"
+ " UPDATE CompanyBalance SET DebitBal = 0 WHERE DebitBal IS NULL"
+ " UPDATE CompanyBalance SET CreditBal = 0 WHERE CreditBal IS NULL";
exeCommand(command);
}
}
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