Commit 1516dded authored by frank.xa.zhang's avatar frank.xa.zhang

batch upload for template download -- frank

parent 9c6f75c5
package pwc.taxtech.atms.constant.enums;
public enum BoardMeetingRequirementEnum {
Annual("Annual", 1),
SemiQnnual("Semi Qnnual", 2),
Quarter("Quarter", 3),
Monthly("Monthly", 3);
private String name;
private Integer value;
BoardMeetingRequirementEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum ClassOfSharesEnum {
A("A", 1),
B("B", 2);
private String name;
private Integer value;
ClassOfSharesEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum CommonOrPreferredEnum {
Common("Common", 1),
Preferred("Preferred", 2);
private String name;
private Integer value;
CommonOrPreferredEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum EntityLevelEnum {
InvestmentFund("Investment Fund", 1),
InvestmentHolding("Investment Holding", 2),
PortfolioCompany("Portfolio Company", 3);
private String name;
private Integer value;
EntityLevelEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum ExecutiveEnum {
Y("Y", 1),
N("N", 2);
private String name;
private Integer value;
ExecutiveEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum JurisdictionOfFormationEnum {
HongKong("Hong Kong", 1),
BritishVirginIslands("British Virgin Islands", 2),
CaymanIslands("Cayman Islands", 3);
private String name;
private Integer value;
JurisdictionOfFormationEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum LegalFormEnum {
LimitedPartnership("Limited Partnership", 1),
LimitedCompany("Limited Company", 2),
Trustee("Trustee", 2);
private String name;
private Integer value;
LegalFormEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum OwnershipFormEnum {
OrdinaryShares("Ordinary Shares", 1),
PreferenceShares("Preference Shares", 2);
private String name;
private Integer value;
OwnershipFormEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.constant.enums;
public enum RolesEnum {
CEO("CEO", 1),
CFO("CFO", 2),
NA("NA", 3);
private String name;
private Integer value;
RolesEnum(String name, Integer value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Integer getValue() {
return value;
}
}
package pwc.taxtech.atms.controller;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -10,7 +9,6 @@ import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.service.impl.DataImportService;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/api/v1/DataImport/")
......@@ -20,33 +18,26 @@ public class DataImportController extends BaseController {
private DataImportService dataImportService;
@ResponseBody
@RequestMapping(value = "RLITExcelFile", method = RequestMethod.POST)
public OperationResultDto importRLITExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
@RequestMapping(value = "OrgExcelFile", method = RequestMethod.POST)
public OperationResultDto importRLITExcelFile(@RequestParam MultipartFile file) {
try {
List<String> orgList = (List<String>)JSONArray.parse(orgIds);
String valMsg = valParameter(file,orgList,periodDate);
if(StringUtils.isNotEmpty(valMsg)){
String valMsg = valParameter(file);
if (StringUtils.isNotEmpty(valMsg)) {
return OperationResultDto.error(valMsg);
}
return dataImportService.importRLITExcelFile(file,orgList, periodDate,importType);
return dataImportService.importOrgExcelFile(file);
} catch (ServiceException e) {
return OperationResultDto.error(e.getMessage());
} catch (Exception e) {
logger.error("importRLITExcelFile error.", e);
logger.error("OrgExcelFile error.", e);
return OperationResultDto.error(ErrorMessage.SystemError);
}
}
private String valParameter(MultipartFile file,List<String> orgList,String periodDate){
private String valParameter(MultipartFile file) {
if (null == file) {
return ErrorMessage.NoFile;
}
if(orgList.size()<1){
return ErrorMessage.DidntSelectedCompany;
}
if(StringUtils.isEmpty(periodDate)){
return ErrorMessage.DidntSelectedPeriod;
}
return null;
}
......
package pwc.taxtech.atms.service.impl;
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.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.constant.enums.*;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.organization.dao.OrganizationDirectorMapper;
import pwc.taxtech.atms.organization.dao.OrganizationHKMapper;
import pwc.taxtech.atms.organization.dao.OrganizationShareholderMapper;
import pwc.taxtech.atms.organization.dpo.OrganizationDirectorDto;
import pwc.taxtech.atms.organization.dpo.OrganizationHKDto;
import pwc.taxtech.atms.organization.dpo.OrganizationShareholderDto;
import pwc.taxtech.atms.organization.entity.OrganizationDirector;
import pwc.taxtech.atms.organization.entity.OrganizationHK;
import pwc.taxtech.atms.organization.entity.OrganizationHKExample;
import pwc.taxtech.atms.organization.entity.OrganizationShareholder;
import pwc.taxtech.atms.organization.mapper.OrganizationDirectorTMapper;
import pwc.taxtech.atms.organization.mapper.OrganizationHKTMapper;
import pwc.taxtech.atms.organization.mapper.OrganizationShareholderTMapper;
import javax.annotation.Resource;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class DataImportService extends BaseService {
public OperationResultDto importRLITExcelFile(MultipartFile file, List<String> orgIds, String periodDate, Integer importType) throws ServiceException {
@Autowired
OrganizationHKTMapper organizationHKTMapper;
@Autowired
OrganizationDirectorTMapper organizationDirectorTMapper;
@Autowired
OrganizationShareholderTMapper organizationShareholderTMapper;
@Resource
private
OrganizationHKMapper organizationHKMapper;
@Resource
private
OrganizationDirectorMapper organizationDirectorMapper;
@Resource
private
OrganizationShareholderMapper organizationShareholderMapper;
public OperationResultDto importOrgExcelFile(MultipartFile file) throws ServiceException {
try {
// OperationResultDto operationResultDto = new OperationResultDto();
// InputStream inputStream = file.getInputStream();
// Workbook workbook = WorkbookFactory.create(inputStream);
// FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// if (StringUtils.isBlank(periodDate) || "null".equals(periodDate)) {
// throw new ServiceException(ErrorMessageCN.DoNotSelectPeriod);
// }
// Integer tmsPeriod = DateUtils.strToPeriod(periodDate);
// List<DataImportLog> dataImportLogs = Lists.newArrayList();
// for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
// Sheet sheet = workbook.getSheetAt(i);
// if (isSheetEmpty(sheet)) continue;
// List<RedLetterInfoTable> rlits = generalRLITs(sheet, tmsPeriod, evaluator);
// if (rlits.size() < 1) continue;
// // 根据主体分组处理
// Map<String, List<RedLetterInfoTable>> atsGroupRes =
// rlits.stream().collect(Collectors.groupingBy(RedLetterInfoTable::getSubjectNum));
// atsGroupRes.forEach((k, v) -> processRlits(k, v, orgIds, tmsPeriod, importType, dataImportLogs));
// }
// if (dataImportLogs.size() == 0)
// return OperationResultDto.error(ErrorMessage.NoData);
//
// addDataImportLog(dataImportLogs);
// int isSuccess = (int) dataImportLogs.stream().filter(di -> Boolean.TRUE.equals(di.getImportResult())).count();
// if (isSuccess < 1) {
// return OperationResultDto.error(ErrorMessage.ImportNotMatch);
// }
OperationResultDto operationResultDto = new OperationResultDto();
InputStream inputStream = file.getInputStream();
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheetOrg = workbook.getSheetAt(0);
List<OrganizationHKDto> organizationHKDtos = new ArrayList<>();
if (!isSheetEmpty(sheetOrg)) {
organizationHKDtos = processOrgDto(sheetOrg);
}
Sheet sheetDirector = workbook.getSheetAt(1);
List<OrganizationDirectorDto> organizationDirectorDtos = new ArrayList<>();
if (!isSheetEmpty(sheetDirector)) {
organizationDirectorDtos = precessOrgDirectorDto(sheetDirector);
}
Sheet sheetShareholder = workbook.getSheetAt(2);
List<OrganizationShareholderDto> organizationShareholderDtos = new ArrayList<>();
if (!isSheetEmpty(sheetShareholder)) {
organizationShareholderDtos = processOrgShareholders(sheetShareholder);
}
Date now = LocalDate.now().toDate();
for (OrganizationHKDto organizationHKDto : organizationHKDtos) {
OrganizationHKExample example = new OrganizationHKExample();
example.createCriteria().andIsActiveEqualTo(true).andCodeEqualTo(organizationHKDto.getCode()).andNameEqualTo(organizationHKDto.getName());
if (organizationHKMapper.countByExample(example) == 0) {
OrganizationHK organizationHK = organizationHKTMapper.toOrganiztionHK(organizationHKDto);
organizationHK.setId(idService.nextId());
organizationHK.setUpdateTime(now);
organizationHK.setCreateTime(now);
organizationHKMapper.insertSelective(organizationHK);
}
}
for (OrganizationDirectorDto organizationDirectorDto : organizationDirectorDtos) {
OrganizationHKExample example = new OrganizationHKExample();
example.createCriteria().andIsActiveEqualTo(true).andCodeEqualTo(organizationDirectorDto.getInternalEntityCode()).andNameEqualTo(organizationDirectorDto.getCompanyName());
List<OrganizationHK> organizationHKList = organizationHKMapper.selectByExample(example);
if (organizationHKList.size() > 0) {
long entityId = organizationHKList.get(0).getId();
OrganizationDirector organizationDirector = organizationDirectorTMapper.toOrganizationDirector(organizationDirectorDto);
organizationDirector.setId(idService.nextId());
organizationDirector.setEntityId(entityId);
organizationDirector.setUpdateTime(now);
organizationDirector.setCreateTime(now);
organizationDirectorMapper.insertSelective(organizationDirector);
}
}
for (OrganizationShareholderDto organizationShareholderDto : organizationShareholderDtos) {
OrganizationHKExample example = new OrganizationHKExample();
example.createCriteria().andIsActiveEqualTo(true).andCodeEqualTo(organizationShareholderDto.getInternalEntityCode()).andNameEqualTo(organizationShareholderDto.getCompanyName());
List<OrganizationHK> organizationHKList = organizationHKMapper.selectByExample(example);
example.createCriteria().andNameEqualTo(organizationShareholderDto.getShareholderName()).andIsActiveEqualTo(true);
List<OrganizationHK> organizationInvestList = organizationHKMapper.selectByExample(example);
if (organizationHKList.size() > 0 && organizationInvestList.size() > 0) {
long entityId = organizationHKList.get(0).getId();
long investEntityId = organizationInvestList.get(0).getId();
OrganizationShareholder organizationShareholder = organizationShareholderTMapper.toOrganizationShareholder(organizationShareholderDto);
organizationShareholder.setId(idService.nextId());
organizationShareholder.setEntityId(entityId);
organizationShareholder.setInvestmentEntityId(investEntityId);
organizationShareholder.setUpdateTime(now);
organizationShareholder.setCreateTime(now);
organizationShareholderMapper.insertSelective(organizationShareholder);
}
}
return operationResultDto.success();
} catch (Exception e) {
e.printStackTrace();
return OperationResultDto.error(e.getMessage());
}
}
private List<OrganizationShareholderDto> processOrgShareholders(Sheet sheetShareholder) {
List<OrganizationShareholderDto> organizationShareholderDtoList = new ArrayList<>();
int lastRowNumber = sheetShareholder.getLastRowNum();
for (int i = 0; i < lastRowNumber; i++) {
Row row = sheetShareholder.getRow(i);
int colIndex = 0;
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.setVotingPercentage(getCellValue(row, colIndex + 6));
organizationShareholderDto.setInternalEntityCode(getCellValue(row, colIndex));
organizationShareholderDto.setCompanyName(getCellValue(row, colIndex + 1));
organizationShareholderDto.setShareholderName(getCellValue(row, colIndex + 2));
organizationShareholderDtoList.add(organizationShareholderDto);
}
return organizationShareholderDtoList;
}
private String getCellValue(Row row, int colIndex) {
return StringUtils.trimToEmpty(row.getCell(colIndex).getStringCellValue());
}
private List<OrganizationDirectorDto> precessOrgDirectorDto(Sheet sheetDirector) {
List<OrganizationDirectorDto> organizationDirectorDtos = new ArrayList<>();
int lastRowNumber = sheetDirector.getLastRowNum();
for (int i = 0; i < lastRowNumber; i++) {
Row row = sheetDirector.getRow(i);
OrganizationDirectorDto organizationDirectorDto = new OrganizationDirectorDto();
int colIndex = 0;
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.setInternalEntityCode(getCellValue(row, colIndex));
organizationDirectorDto.setCompanyName(getCellValue(row, colIndex + 1));
organizationDirectorDtos.add(organizationDirectorDto);
}
return organizationDirectorDtos;
}
private List<OrganizationHKDto> processOrgDto(Sheet sheetOrg) {
List<OrganizationHKDto> organizationHKDtos = new ArrayList<>();
int lastRowNumber = sheetOrg.getLastRowNum();
for (int i = 0; i < lastRowNumber; i++) {
Row row = sheetOrg.getRow(i);
int colIndex = 0;
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.setRegisterAddress(getCellValue(row, colIndex + 3));
organizationHKDto.setAuthorisedCapital(Float.valueOf(getCellValue(row, colIndex + 4)));
organizationHKDto.setIssuedCapital(Float.valueOf(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.setDateOfIncorporation(getCellValue(row, colIndex + 8));
organizationHKDto.setJurisdictionOfFormation(JurisdictionOfFormationEnum.valueOf(getCellValue(row, colIndex + 9)).getValue());
organizationHKDto.setFinancialYearEnd(getCellValue(row, colIndex + 10));
organizationHKDto.setAnnualAuditRequirement(getCellValue(row, colIndex + 15));
organizationHKDto.setRegisteredAgent(getCellValue(row, colIndex + 16));
// organizationHKDto.setOwnershipForm("");
organizationHKDto.setResidentSecretary(getCellValue(row, colIndex + 17));
organizationHKDtos.add(organizationHKDto);
}
return organizationHKDtos;
}
private boolean isSheetEmpty(Sheet sheet) {
if (sheet.getLastRowNum() > 0 &&
(null == sheet.getRow(0).getCell(0) || "Version".equals(sheet.getRow(0).getCell(0).getStringCellValue())) &&
null == sheet.getRow(0).getCell(2)) {
return true;
}
return false;
}
}
......@@ -19,4 +19,6 @@ public class OrganizationDirectorDto {
Integer isExecutive;
Integer otherRoles;
String isDelete;
String internalEntityCode;
String companyName;
}
......@@ -20,7 +20,7 @@ public class OrganizationHKDto {
private String code;
private Boolean isActive;
private Long parentId;
private String legalForm;
private Integer legalForm;
private String registerAddress;
private Float authorisedCapital;
private Float issuedCapital;
......@@ -30,9 +30,9 @@ public class OrganizationHKDto {
private String boardMeetingRequirement;
private String businessLicense;
private String renewalOfBusinessLicense;
private String entityLevel;
private Integer entityLevel;
private String dateOfIncorporation;
private String jurisdictionOfFormation;
private Integer jurisdictionOfFormation;
private String financialYearEnd;
private String annualAuditRequirement;
private String registeredAgent;
......
......@@ -17,4 +17,7 @@ public class OrganizationShareholderDto {
Integer commonPreferred;
Integer classOfShares;
String votingPercentage;
String internalEntityCode;
String companyName;
String shareholderName;
}
......@@ -21,4 +21,13 @@ public interface OrganizationHKTMapper {
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")
OrganizationHK toOrganiztionHK(OrganizationHKDto organizationHKDto);
}
......@@ -29,7 +29,7 @@ commonModule.controller('uploadOrgModalController', ['$scope', '$log', '$transla
importExcelF: null
};
$scope.importRLITExcelFile = apiInterceptor.webApiHostUrl + '/DataImport/RLITExcelFile';
$scope.importOrgExcelFile = apiInterceptor.webApiHostUrl + '/DataImport/OrgExcelFile';
$scope.downloadTemplate = function () {
templateService.downloadTemplate().success(function (data, status, headers) {
var octetStreamMime = 'application/octet-stream';
......@@ -81,9 +81,8 @@ commonModule.controller('uploadOrgModalController', ['$scope', '$log', '$transla
Upload.upload({
url: $scope.importRLITExcelFile,
url: $scope.importOrgExcelFile,
data: {
importType: importType
},
file: impExl,
headers: {
......
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