Commit 036fac7f authored by frank.xa.zhang's avatar frank.xa.zhang

batch upload for template download -- frank

parent a642cb5d
package pwc.taxtech.atms.service.impl;
import com.google.common.primitives.Floats;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -27,7 +25,9 @@ import pwc.taxtech.atms.organization.mapper.OrganizationHKTMapper;
import pwc.taxtech.atms.organization.mapper.OrganizationShareholderTMapper;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -57,9 +57,10 @@ public class DataImportService extends BaseService {
OrganizationShareholderMapper organizationShareholderMapper;
public OperationResultDto importOrgExcelFile(MultipartFile file) throws ServiceException {
InputStream inputStream = null;
try {
OperationResultDto operationResultDto = new OperationResultDto();
InputStream inputStream = file.getInputStream();
inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheetOrg = workbook.getSheetAt(0);
List<OrganizationHKDto> organizationHKDtos = new ArrayList<>();
......@@ -79,6 +80,7 @@ public class DataImportService extends BaseService {
Date now = LocalDate.now().toDate();
for (OrganizationHKDto organizationHKDto : organizationHKDtos) {
if (StringUtils.isNotBlank(organizationHKDto.getName())) {
OrganizationHKExample example = new OrganizationHKExample();
example.createCriteria().andIsActiveEqualTo(true).andCodeEqualTo(organizationHKDto.getCode()).andNameEqualTo(organizationHKDto.getName());
if (organizationHKMapper.countByExample(example) == 0) {
......@@ -89,8 +91,10 @@ public class DataImportService extends BaseService {
organizationHKMapper.insertSelective(organizationHK);
}
}
}
for (OrganizationDirectorDto organizationDirectorDto : organizationDirectorDtos) {
if (StringUtils.isNotBlank(organizationDirectorDto.getCompanyName()) && StringUtils.isNotBlank(organizationDirectorDto.getInternalEntityCode())) {
OrganizationHKExample example = new OrganizationHKExample();
example.createCriteria().andIsActiveEqualTo(true).andCodeEqualTo(organizationDirectorDto.getInternalEntityCode()).andNameEqualTo(organizationDirectorDto.getCompanyName());
List<OrganizationHK> organizationHKList = organizationHKMapper.selectByExample(example);
......@@ -104,8 +108,12 @@ public class DataImportService extends BaseService {
organizationDirectorMapper.insertSelective(organizationDirector);
}
}
}
for (OrganizationShareholderDto organizationShareholderDto : organizationShareholderDtos) {
if (StringUtils.isNotBlank(organizationShareholderDto.getShareholderName())
&& StringUtils.isNotBlank(organizationShareholderDto.getInternalEntityCode())
&& StringUtils.isNotBlank(organizationShareholderDto.getCompanyName())) {
OrganizationHKExample example = new OrganizationHKExample();
example.createCriteria().andIsActiveEqualTo(true).andCodeEqualTo(organizationShareholderDto.getInternalEntityCode()).andNameEqualTo(organizationShareholderDto.getCompanyName());
List<OrganizationHK> organizationHKList = organizationHKMapper.selectByExample(example);
......@@ -125,23 +133,37 @@ public class DataImportService extends BaseService {
organizationShareholderMapper.insertSelective(organizationShareholder);
}
}
}
return operationResultDto.success();
} catch (Exception e) {
e.printStackTrace();
return OperationResultDto.error(e.getMessage());
} finally {
try {
inputStream.close();
} catch (IOException ex) {
}
}
}
private List<OrganizationShareholderDto> processOrgShareholders(Sheet sheetShareholder) {
List<OrganizationShareholderDto> organizationShareholderDtoList = new ArrayList<>();
int lastRowNumber = sheetShareholder.getLastRowNum();
for (int i = 0; i < lastRowNumber; i++) {
for (int i = 1; i < lastRowNumber; i++) {
Row row = sheetShareholder.getRow(i);
int colIndex = 0;
if (row == null) {
continue;
}
if (row.getCell(colIndex) == null) {
continue;
}
OrganizationShareholderDto organizationShareholderDto = new OrganizationShareholderDto();
organizationShareholderDto.setOwnershipForm(OwnershipFormEnum.valueOf(getCellValue(row, colIndex + 3)).getValue());
organizationShareholderDto.setCommonPreferred(CommonOrPreferredEnum.valueOf(getCellValue(row, colIndex + 4)).getValue());
organizationShareholderDto.setClassOfShares(ClassOfSharesEnum.valueOf(getCellValue(row, colIndex + 5)).getValue());
organizationShareholderDto.setOwnershipForm(getEnumCodeByName(OwnershipFormEnum.class, getCellValue(row, colIndex + 3)));
organizationShareholderDto.setCommonPreferred(getEnumCodeByName(CommonOrPreferredEnum.class, getCellValue(row, colIndex + 4)));
organizationShareholderDto.setClassOfShares(getEnumCodeByName(ClassOfSharesEnum.class, getCellValue(row, colIndex + 5)));
organizationShareholderDto.setVotingPercentage(getCellValue(row, colIndex + 6));
organizationShareholderDto.setInternalEntityCode(getCellValue(row, colIndex));
organizationShareholderDto.setCompanyName(getCellValue(row, colIndex + 1));
......@@ -152,22 +174,47 @@ public class DataImportService extends BaseService {
}
private String getCellValue(Row row, int colIndex) {
return StringUtils.trimToEmpty(row.getCell(colIndex).getStringCellValue());
if (row.getCell(colIndex) == null) {
return null;
}
if (row.getCell(colIndex).getCellTypeEnum().equals(CellType.STRING)) {
String result = StringUtils.trimToEmpty(row.getCell(colIndex).getStringCellValue());
if (StringUtils.isEmpty(result)) {
return null;
} else {
return result;
}
} else if (row.getCell(colIndex).getCellTypeEnum().equals(CellType.NUMERIC)) {
String result = StringUtils.trimToEmpty(String.valueOf(row.getCell(colIndex).getNumericCellValue()));
if (StringUtils.isEmpty(result)) {
return null;
} else {
return result;
}
}
return null;
}
private List<OrganizationDirectorDto> precessOrgDirectorDto(Sheet sheetDirector) {
List<OrganizationDirectorDto> organizationDirectorDtos = new ArrayList<>();
int lastRowNumber = sheetDirector.getLastRowNum();
for (int i = 0; i < lastRowNumber; i++) {
for (int i = 1; i < lastRowNumber; i++) {
Row row = sheetDirector.getRow(i);
OrganizationDirectorDto organizationDirectorDto = new OrganizationDirectorDto();
int colIndex = 0;
if (row == null) {
continue;
}
if (row.getCell(colIndex) == null) {
continue;
}
organizationDirectorDto.setDirectorName(getCellValue(row, colIndex + 2));
organizationDirectorDto.setResidency(getCellValue(row, colIndex + 3));
organizationDirectorDto.setDateOfAppointment(getCellValue(row, colIndex + 4));
organizationDirectorDto.setDateOfResignation(getCellValue(row, colIndex + 5));
organizationDirectorDto.setIsExecutive(ExecutiveEnum.valueOf(getCellValue(row, colIndex + 6)).getValue());
organizationDirectorDto.setOtherRoles(RolesEnum.valueOf(getCellValue(row, colIndex + 7)).getValue());
organizationDirectorDto.setIsExecutive(getEnumCodeByName(ExecutiveEnum.class, getCellValue(row, colIndex + 6)));
organizationDirectorDto.setOtherRoles(getEnumCodeByName(RolesEnum.class, getCellValue(row, colIndex + 7)));
organizationDirectorDto.setInternalEntityCode(getCellValue(row, colIndex));
organizationDirectorDto.setCompanyName(getCellValue(row, colIndex + 1));
organizationDirectorDtos.add(organizationDirectorDto);
......@@ -178,25 +225,34 @@ public class DataImportService extends BaseService {
private List<OrganizationHKDto> processOrgDto(Sheet sheetOrg) {
List<OrganizationHKDto> organizationHKDtos = new ArrayList<>();
int lastRowNumber = sheetOrg.getLastRowNum();
for (int i = 0; i < lastRowNumber; i++) {
for (int i = 1; i < lastRowNumber; i++) {
Row row = sheetOrg.getRow(i);
int colIndex = 0;
if (row == null) {
continue;
}
if (row.getCell(colIndex) == null) {
continue;
}
OrganizationHKDto organizationHKDto = new OrganizationHKDto();
organizationHKDto.setName(getCellValue(row, colIndex + 1));
organizationHKDto.setCode(getCellValue(row, colIndex));
organizationHKDto.setLegalForm(LegalFormEnum.valueOf(getCellValue(row, colIndex + 2)).getValue());
// organizationHKDto.setLegalForm(LegalFormEnum.valueOf(getCellValue(row, colIndex + 2)).getValue());
organizationHKDto.setLegalForm(getEnumCodeByName(LegalFormEnum.class, getCellValue(row, colIndex + 2)));
organizationHKDto.setRegisterAddress(getCellValue(row, colIndex + 3));
organizationHKDto.setAuthorisedCapital(Float.valueOf(getCellValue(row, colIndex + 4)));
organizationHKDto.setIssuedCapital(Float.valueOf(getCellValue(row, colIndex + 5)));
organizationHKDto.setAuthorisedCapital(Floats.tryParse(getCellValue(row, colIndex + 4)));
organizationHKDto.setIssuedCapital(Floats.tryParse(getCellValue(row, colIndex + 5)));
// organizationHKDto.setIndustry("");
organizationHKDto.setPaymentOfAnnualGovernmentFee(getCellValue(row, colIndex + 12));
organizationHKDto.setAnnualReturnFillings(getCellValue(row, colIndex + 11));
organizationHKDto.setBoardMeetingRequirement(getCellValue(row, colIndex + 14));
organizationHKDto.setBusinessLicense(getCellValue(row, colIndex + 7));
organizationHKDto.setRenewalOfBusinessLicense(getCellValue(row, colIndex + 13));
organizationHKDto.setEntityLevel(EntityLevelEnum.valueOf(getCellValue(row, colIndex + 6)).getValue());
organizationHKDto.setEntityLevel(getEnumCodeByName(EntityLevelEnum.class, getCellValue(row, colIndex + 6)));
organizationHKDto.setDateOfIncorporation(getCellValue(row, colIndex + 8));
organizationHKDto.setJurisdictionOfFormation(JurisdictionOfFormationEnum.valueOf(getCellValue(row, colIndex + 9)).getValue());
organizationHKDto.setJurisdictionOfFormation(getEnumCodeByName(JurisdictionOfFormationEnum.class, getCellValue(row, colIndex + 9)));
organizationHKDto.setFinancialYearEnd(getCellValue(row, colIndex + 10));
organizationHKDto.setAnnualAuditRequirement(getCellValue(row, colIndex + 15));
organizationHKDto.setRegisteredAgent(getCellValue(row, colIndex + 16));
......@@ -207,6 +263,22 @@ public class DataImportService extends BaseService {
return organizationHKDtos;
}
private <E extends Enum<E>> int getEnumCodeByName(Class<E> enumClass, String name) {
try {
for (Enum<E> enumVal : enumClass.getEnumConstants()) {
if (enumVal.name().equals(name)) {
Class<?> clzz = enumVal.getClass();
Method method = clzz.getDeclaredMethod("getValue");
return (Integer) method.invoke(enumVal);
}
}
return 0;
} catch (Exception ex) {
return 0;
}
}
private boolean isSheetEmpty(Sheet sheet) {
if (sheet.getLastRowNum() > 0 &&
(null == sheet.getRow(0).getCell(0) || "Version".equals(sheet.getRow(0).getCell(0).getStringCellValue())) &&
......
......@@ -11,13 +11,13 @@ import pwc.taxtech.atms.organization.entity.OrganizationDirector;
public interface OrganizationDirectorTMapper {
OrganizationDirectorTMapper ORGANIZATION_DIRECTOR_T_MAPPER = Mappers.getMapper(OrganizationDirectorTMapper.class);
@Mapping(source = "dateOfAppointment", target = "dateOfAppointment", dateFormat = "yyyy/MM/dd")
@Mapping(source = "dateOfResignation", target = "dateOfResignation", dateFormat = "yyyy/MM/dd")
@Mapping(source = "dateOfAppointment", target = "dateOfAppointment", dateFormat = "MM/dd/yyyy")
@Mapping(source = "dateOfResignation", target = "dateOfResignation", dateFormat = "MM/dd/yyyy")
OrganizationDirectorDto toOrganizationDirectorDto(OrganizationDirector organizationDirector);
OrgDirectorDto toOrgDirectorDto(OrganizationDirector organizationDirector);
@Mapping(source = "dateOfAppointment", target = "dateOfAppointment", dateFormat = "yyyy/MM/dd")
@Mapping(source = "dateOfResignation", target = "dateOfResignation", dateFormat = "yyyy/MM/dd")
@Mapping(source = "dateOfAppointment", target = "dateOfAppointment", dateFormat = "MM/dd/yyyy")
@Mapping(source = "dateOfResignation", target = "dateOfResignation", dateFormat = "MM/dd/yyyy")
OrganizationDirector toOrganizationDirector(OrganizationDirectorDto organizationDirectorDto);
}
......@@ -11,23 +11,23 @@ import pwc.taxtech.atms.organization.entity.OrganizationHK;
public interface OrganizationHKTMapper {
OrganizationHKTMapper ORGANIZATION_HK_MAPPER = Mappers.getMapper(OrganizationHKTMapper.class);
@Mapping(source = "createTime", target = "createTime", dateFormat = "yyyy/MM/dd")
@Mapping(source = "updateTime", target = "updateTime", dateFormat = "yyyy/MM/dd")
@Mapping(source = "dateOfIncorporation", target = "dateOfIncorporation", dateFormat = "yyyy/MM/dd")
@Mapping(source = "paymentOfAnnualGovernmentFee", target = "paymentOfAnnualGovernmentFee", dateFormat = "yyyy/MM/dd")
@Mapping(source = "annualReturnFillings", target = "annualReturnFillings", dateFormat = "yyyy/MM/dd")
@Mapping(source = "renewalOfBusinessLicense", target = "renewalOfBusinessLicense", dateFormat = "yyyy/MM/dd")
@Mapping(source = "annualAuditRequirement", target = "annualAuditRequirement", dateFormat = "yyyy/MM/dd")
@Mapping(source = "createTime", target = "createTime", dateFormat = "MM/dd/yyyy")
@Mapping(source = "updateTime", target = "updateTime", dateFormat = "MM/dd/yyyy")
@Mapping(source = "dateOfIncorporation", target = "dateOfIncorporation", dateFormat = "MM/dd/yyyy")
@Mapping(source = "paymentOfAnnualGovernmentFee", target = "paymentOfAnnualGovernmentFee", dateFormat = "MM/dd/yyyy")
@Mapping(source = "annualReturnFillings", target = "annualReturnFillings", dateFormat = "MM/dd/yyyy")
@Mapping(source = "renewalOfBusinessLicense", target = "renewalOfBusinessLicense", dateFormat = "MM/dd/yyyy")
@Mapping(source = "annualAuditRequirement", target = "annualAuditRequirement", dateFormat = "MM/dd/yyyy")
OrganizationHKDto toOrganizationHKDto(OrganizationHK organizationHK);
OrgInfoDto toOrgInfoDto(OrganizationHK organizationHK);
@Mapping(source = "createTime", target = "createTime", dateFormat = "yyyy/MM/dd")
@Mapping(source = "updateTime", target = "updateTime", dateFormat = "yyyy/MM/dd")
@Mapping(source = "dateOfIncorporation", target = "dateOfIncorporation", dateFormat = "yyyy/MM/dd")
@Mapping(source = "paymentOfAnnualGovernmentFee", target = "paymentOfAnnualGovernmentFee", dateFormat = "yyyy/MM/dd")
@Mapping(source = "annualReturnFillings", target = "annualReturnFillings", dateFormat = "yyyy/MM/dd")
@Mapping(source = "renewalOfBusinessLicense", target = "renewalOfBusinessLicense", dateFormat = "yyyy/MM/dd")
@Mapping(source = "annualAuditRequirement", target = "annualAuditRequirement", dateFormat = "yyyy/MM/dd")
@Mapping(source = "createTime", target = "createTime", dateFormat = "MM/dd/yyyy" , defaultValue = "01/01/1900")
@Mapping(source = "updateTime", target = "updateTime", dateFormat = "MM/dd/yyyy" , defaultValue = "01/01/1900")
@Mapping(source = "dateOfIncorporation", target = "dateOfIncorporation", dateFormat = "MM/dd/yyyy", defaultValue = "01/01/1900")
@Mapping(source = "paymentOfAnnualGovernmentFee", target = "paymentOfAnnualGovernmentFee", dateFormat = "MM/dd/yyyy" , defaultValue = "01/01/1900")
@Mapping(source = "annualReturnFillings", target = "annualReturnFillings", dateFormat = "MM/dd/yyyy" , defaultValue = "01/01/1900")
@Mapping(source = "renewalOfBusinessLicense", target = "renewalOfBusinessLicense", dateFormat = "MM/dd/yyyy" , defaultValue = "01/01/1900")
@Mapping(source = "annualAuditRequirement", target = "annualAuditRequirement", dateFormat = "MM/dd/yyyy" , defaultValue = "01/01/1900")
OrganizationHK toOrganiztionHK(OrganizationHKDto organizationHKDto);
}
commonModule.controller('uploadOrgModalController', ['$scope', '$log', '$translate', '$timeout', 'apiInterceptor', 'Upload', 'ackUibModal', '$q', 'SweetAlert','templateService',
function ($scope, $log, $translate, $timeout, apiInterceptor, Upload, ackUibModal, $q, SweetAlert,templateService) {
commonModule.controller('uploadOrgModalController', ['$scope', '$log', '$translate', '$timeout', 'apiInterceptor', 'Upload', 'ackUibModal', '$q', 'SweetAlert', 'templateService',
function ($scope, $log, $translate, $timeout, apiInterceptor, Upload, ackUibModal, $q, SweetAlert, templateService) {
'use strict';
$log.debug('uploadOrgModalController.ctor()...');
......@@ -79,11 +79,10 @@ commonModule.controller('uploadOrgModalController', ['$scope', '$log', '$transla
});
}*/
$('#busy-indicator-container').show();
Upload.upload({
url: $scope.importOrgExcelFile,
data: {
},
data: {},
file: impExl,
headers: {
'Access-Control-Allow-Origin': '*',
......@@ -117,6 +116,8 @@ commonModule.controller('uploadOrgModalController', ['$scope', '$log', '$transla
}
SweetAlert.error($translate.instant('ImportFail'));
console.log('Error status: ' + resp.status);
$scope.fileName = '';
$scope.upload.importExcelF = null;
}, function (evt) {
deferred.resolve();
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
......
......@@ -3,7 +3,7 @@
<div class="modal-header">
<h4 class="modal-title" style="margin-top: 5px;">{{'BatchUpload' | translate}}</h4>
</div>
<div class="modal-body" id="modal-body" style="height:335px;width:600px">
<div class="modal-body" id="modal-body" style="height:100px;width:600px">
<div class="form-group">
<button ng-model="upload.importExcelF" ngf-select=""
accept=".xls,.xlsx"
......@@ -16,8 +16,10 @@
<!--ng-click="doUploadRLIT(importEnum.CoverImport)"></button>-->
<button type="button" class="btn btn-vat-primary " translate="AddImportBtn"
ng-click="doUploadRLIT(importEnum.AddImport)"></button>
</div>
<div>
<span ng-show="fileName" class="marTop"
title="{{fileName}}">{{'FileName' | translate}}{{fileName | limitString:10}}</span>
title="{{fileName}}">{{'FileName' | translate}}{{fileName | limitString:100}}</span>
</div>
</div>
<div class="modal-footer">
......
......@@ -12,7 +12,7 @@
.modal-dialog {
width: 653px;
height: 409px;
height: 200px;
.modal-body {
height: 100%;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment