Commit a7b3f127 authored by neo.wang's avatar neo.wang

Merge branch 'dev_neo' into 'dev'

Dev neo

See merge request root/atms!80
parents 649d4716 d44833f1
......@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.constant.enums.EnumModule;
import pwc.taxtech.atms.dto.PagingResultDto;
import pwc.taxtech.atms.dto.vatdto.ImportOutputInvoiceDto;
......@@ -24,6 +25,7 @@ import pwc.taxtech.atms.vat.service.impl.OutputInvoiceServiceImpl;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -114,23 +116,19 @@ public class OutputInvoiceController {
}
@RequestMapping(value = "UploadEvidenceFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity UploadEvidenceFile() {
public ResponseEntity UploadEvidenceFile(String fileName, String tempFileName, String period) {
String userID = identityService.getIdentityUser().getID();
String fullPath = fileUploadAdapter.uploadEvidence(this, EnumModule.Evidence, UUID.randomUUID().toString());
if (!StringUtil.isNotEmpty(fullPath)) {
// string fileName = HttpContext.Current.Request.Form["filename"];
// string _tempFileName = HttpContext.Current.Request.Form["tempFileName"];
ImportFile fileDto = new ImportFile();
// {
// FileID = _tempFileName.Substring(1, _tempFileName.Length - 5),
// FilePath = fullPath,
// FileName = fileName,
// PeriodID = Convert.ToInt32(HttpContext.Current.Request.Form["period"]),
// FileType = Path.GetExtension(fileName),
// FileImportType = (int)EnumModule.Evidence,
// CreatorID = userID,
// CreateTime = DateTime.Now
// };
fileDto.setFileID(tempFileName.substring(1, tempFileName.length() - 5));
fileDto.setFilePath(fullPath);
fileDto.setFileName(fileName);
fileDto.setPeriodID(Integer.parseInt(period));
fileDto.setFileType(GetExtension(fileName));
fileDto.setFileImportType(EnumModule.Evidence.getCode());
fileDto.setCreatorID(userID);
fileDto.setCreateTime(new Date());
return ResponseEntity.ok(outputInvoiceService.addImportFile(fileDto));
}
return ResponseEntity.ok(false);
......@@ -141,5 +139,9 @@ public class OutputInvoiceController {
return ResponseEntity.ok(outputInvoiceService.GetOutputInvoiceList(period));
}
private String GetExtension(String file) {
return file.substring(file.lastIndexOf(".") + 1, file.length()
- file.lastIndexOf("."));
}
}
package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.vat.entity.InputVATInvoiceItem;
import java.util.List;
public class ImportInputInvoiceItemDto {
public List<InputVATInvoiceItemDto> InputInvoiceItemList;
public List<InputVATInvoiceItem> InputInvoiceItemList;
public int ImportType ;
}
package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.vat.entity.OutputVATInvoice;
import pwc.taxtech.atms.vat.entity.OutputVATInvoiceItem;
import java.util.List;
public class ImportOutputInvoiceDto {
public List<OutputVATInvoiceDto> OutputInvoiceList ;
public List<OutputVATInvoiceItemDto> OutputInvoiceItemList ;
public List<OutputVATInvoice> OutputInvoiceList ;
public List<OutputVATInvoiceItem> OutputInvoiceItemList ;
public Integer ImportType ;
}
package pwc.taxtech.atms.dto.vatdto;
import pwc.taxtech.atms.constant.enums.EnumInvoiceType;
import pwc.taxtech.atms.vat.entity.InputVATInvoice;
import java.math.BigDecimal;
import java.util.Date;
......@@ -137,4 +138,25 @@ public class InputVATInvoiceDto extends InputVATInvoiceBaseDto {
public String getInvoiceTypeName() {
return EnumInvoiceType.values()[this.invoiceType].getName();
}
public InputVATInvoice extractInvoice(){
InputVATInvoice invoice = new InputVATInvoice();
invoice.setID(getID());
invoice.setPeriodID(getPeriodID());
invoice.setInvoiceCode(getInvoiceCode());
invoice.setInvoiceNumber(getInvoiceNumber());
invoice.setInvoiceDate(getInvoiceDate());
invoice.setSellerTaxNumber(getSellerTaxNumber());
invoice.setAmount(getAmount());
invoice.setTaxAmount(getTaxAmount());
invoice.setInvoiceType(getInvoiceType());
invoice.setCertificationResult(getCertificationResult());
invoice.setCertificationDate(getCertificationDate());
invoice.setCreatorID(getCreatorID());
invoice.setCreateTime(getCreateTime());
// invoice.setStatus(getStatus());
// invoice.setPartAccntedPeriod(getPartAccntedPeriod());
// invoice.setAccntedPeriod(getAccntedPeriod());
return invoice;
}
}
package pwc.taxtech.atms.dto.vatdto;
import java.math.BigDecimal;
import java.util.Date;
public class OutputVATInvoiceItemDto {
public String ItemID ;
public String InvoiceID ;
public String CodeVersion ;
public String ProductName ;
public String DocumentNum ;
public String ProductStandard ;
public String Unit ;
public Integer Quantity ;
public Double UnitPrice ;
public BigDecimal Amount ;
public BigDecimal TaxRate ;
public BigDecimal TaxAmount ;
public int SeqNo ;
public String TaxClassCode ;
public String CreatorID ;
public Date CreateTime ;
public int PeriodID ;
}
package pwc.taxtech.atms.vat.service.impl;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.constant.enums.EnumTbImportType;
import pwc.taxtech.atms.constant.enums.EnumValidationType;
import pwc.taxtech.atms.dto.FieldsMapper;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.PagingResultDto;
......@@ -13,12 +19,20 @@ import pwc.taxtech.atms.vat.entity.InputVATInvoiceExample;
import pwc.taxtech.atms.vat.entity.InputVATInvoiceItem;
import pwc.taxtech.atms.vat.entity.InputVATInvoiceItemExample;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service
public class InputInvoiceDataImportServiceImpl extends VatAbstractService {
private static final String _tableName = "InputVATInvoice";
private static final String _itemTableName = "InputVATInvoiceItem";
private static final String _validationTableName = "ValidationInfo";
@Autowired
private SqlSessionTemplate dynamicSqlSessionTemplate;
public PagingResultDto<InputVATInvoiceDto> getInputInvoiceTreeViewData(InputInvoicePreviewQueryParam paras) {
PagingResultDto<InputVATInvoiceDto> qResult = new PagingResultDto<>();
......@@ -75,11 +89,86 @@ public class InputInvoiceDataImportServiceImpl extends VatAbstractService {
return inputVATInvoiceItemMapper.selectByExample(example);
}
public OperationResultDto ImportInputInvoiceItemData(List<InputVATInvoiceItemDto> inputInvoiceItemList, int importType, String id) {
return null;
public OperationResultDto ImportInputInvoiceItemData(List<InputVATInvoiceItem> inputInvoiceItemDtoList, int importType, String userID) {
if (inputInvoiceItemDtoList.size() > 0) {
int period = Integer.parseInt(inputInvoiceItemDtoList.get(0).getID());
inputInvoiceItemDtoList.forEach(item -> {
//导入之前需要将汇总表的主键更新到明细表中,如果找不到汇总信息,则设置为空
InputVATInvoiceExample example = new InputVATInvoiceExample();
example.createCriteria().andInvoiceCodeEqualTo(item.getInvoiceCode()).andInvoiceNumberEqualTo(item.getInvoiceNumber());
InputVATInvoice invoiceTotal = inputVATInvoiceMapper.selectByExample(example).stream().findFirst().get();
item.setInputVATInvoiceID(invoiceTotal == null ? "" : invoiceTotal.getID());
item.setID(UUID.randomUUID().toString());
item.setCreatorID(userID);
item.setCreateTime(new Date());
});
//如果是覆盖导入,则先删除该期间的数据,再进行数据导入
if (importType == EnumTbImportType.CoverImport.getCode()) {
ClearTableData(period, _itemTableName, EnumValidationType.InputVoiceItem.getCode());
}
//将进项发票明细数据转换为datatable
//调用sqlBulk进行快速导入
inputInvoiceItemDtoList.forEach(m -> inputVATInvoiceItemMapper.insert(m));
// ValidateInputInvoiceItemInfo(period, userID);//todo:[validation] to be continue (neo)
}
return new OperationResultDto(true);
}
public OperationResultDto ImportInputInvoiceData(List<InputVATInvoiceDto> inputInvoiceList, int importType, String id) {
return null;
public OperationResultDto ImportInputInvoiceData(List<InputVATInvoiceDto> inputInvoiceDtoList, int importType, String userID) {
if (inputInvoiceDtoList.size() > 0) {
int period = inputInvoiceDtoList.get(0).getPeriodID();
inputInvoiceDtoList.forEach(item -> {
item.setID(UUID.randomUUID().toString());
if (item.getCertificationDate().equals(new Date(0))) {
item.setCertificationDate(null);
}
item.setCreatorID(userID);
item.setCreateTime(new Date());
});
//如果是覆盖导入,则先删除该期间的数据,再进行数据导入
if (importType == EnumTbImportType.CoverImport.getCode()) {
ClearTableData(period, _tableName, EnumValidationType.InputVoice.getCode());
}
// DealWithTheDuplicateData(inputInvoiceDtoList);//todo:[validation] to be continue (neo)
//导入之前转换为与数据库字段一致的dto
//将进项发票数据转换为datatable
inputInvoiceDtoList.forEach(m -> inputVATInvoiceMapper.insert(m.extractInvoice()));
//验证发票信息,包括重复验证和错误验证
// ValidateInputInvoiceInfo(period, userID);//todo:[validation] to be continue (neo)
}
return new OperationResultDto(true);
}
private void ClearTableData(int period, String tableName, int importTypeId) {
String clearCommand = "";
if (tableName != _validationTableName) {
//删除主数据表中的数据
clearCommand += "DELETE FROM " + tableName + " WHERE PeriodID = " + period + ";";
//如果是删除主表信息,则还需要删除明细表数据
if (tableName == _tableName) {
clearCommand += "DELETE FROM " + _itemTableName + " WHERE PeriodID = " + period + ";";
}
}
//删除验证信息表中的数据
clearCommand += "DELETE FROM " + _validationTableName + " WHERE PeriodID = " + period + " AND ImportTypeId = " + importTypeId + ";";
exeCommand(clearCommand);
}
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));
}
}
}
package pwc.taxtech.atms.vat.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.reflections.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.common.PagingList;
import pwc.taxtech.atms.constant.enums.EnumTbImportType;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.PagingResultDto;
import pwc.taxtech.atms.dto.vatdto.ImportOutputInvoiceDto;
......@@ -19,10 +23,12 @@ import pwc.taxtech.atms.vat.entity.OutputVATInvoiceExample;
import pwc.taxtech.atms.vat.entity.OutputVATInvoiceItem;
import pwc.taxtech.atms.vat.entity.OutputVATInvoiceItemExample;
import java.io.StringReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -32,6 +38,10 @@ import java.util.stream.Stream;
public class OutputInvoiceServiceImpl extends VatAbstractService {
@Autowired
private ImportFileMapper importFileMapper;
private static final String _tableName = "OutputVATInvoice";
private static final String _itemTableName = "OutputVATInvoiceItem";
@Autowired
private SqlSessionTemplate dynamicSqlSessionTemplate;
public PagingResultDto<OutputVATInvoiceInfoDto> queryOutputInvoiceList(QueryOutputDto queryDto) {
PagingResultDto<OutputVATInvoiceInfoDto> qResult = new PagingResultDto<>();
......@@ -198,15 +208,60 @@ public class OutputInvoiceServiceImpl extends VatAbstractService {
return stream.sorted(Comparator.comparing(OutputVATInvoiceInfoDto::getInvoiceDate)).collect(Collectors.toList());
}
public OperationResultDto ImportOutputInvoiceData(ImportOutputInvoiceDto importDto, String id) {
return null;
public OperationResultDto ImportOutputInvoiceData(ImportOutputInvoiceDto importDto, String userID) {
if (importDto.OutputInvoiceList.size() > 0) {
int period = importDto.OutputInvoiceList.get(0).getPeriodID();
importDto.OutputInvoiceList.forEach(item -> {
item.setCreatorID(userID);
item.setCreateTime(new Date());
});
importDto.OutputInvoiceItemList.forEach(item -> {
item.setCreatorID(userID);
item.setCreateTime(new Date());
});
//如果是覆盖导入,则先删除该期间的数据,再进行数据导入
if (importDto.ImportType == EnumTbImportType.CoverImport.getCode()) {
ClearTableData(period, _tableName);
ClearTableData(period, _itemTableName);
}
// DeleteOutputValidation(period, 2);//todo:[validation] to be continue (neo)
//将发票数据转换为datatable
importDto.OutputInvoiceList.forEach(item -> outputVATInvoiceMapper.insert(item));
importDto.OutputInvoiceItemList.forEach(item -> outputVATInvoiceItemMapper.insert(item));
// ValidataionDuplicationData(period, userID);//todo:[validation] to be continue (neo)
// TaxRateValidation(period, userID);//todo:[validation] to be continue (neo)
// StartToSendMessage(period);//todo:[validation] to be continue (neo)
}
return new OperationResultDto(true);
}
public Boolean addImportFile(ImportFile fileDto) {
return null;
importFileMapper.insert(fileDto);
return true;
}
public OperationResultDto<List<OutputVATInvoiceInfoDto>> GetOutputInvoiceList(int period) {
return null;
}
private void ClearTableData(int period, String tableName) {
String clearCommand = "";
if (period > 0) {
clearCommand = "DELETE FROM " + tableName + " WHERE PeriodID = " + period;
} else {
clearCommand = "TRUNCATE TABLE " + tableName;
}
}
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));
}
}
}
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