Commit 961dacb1 authored by frank.xa.zhang's avatar frank.xa.zhang

Merge branch 'dev' into dev_frank

parents b6a1b65e f92cb007
......@@ -15,6 +15,7 @@ import org.springframework.core.io.ClassPathResource;
import pwc.taxtech.atms.dto.epaccount.EnterpriseAccountSetOrgDto;
public class CommonUtils {
public static final int BATCH_NUM = 500;
public static String getUUID() {
return UUID.randomUUID().toString().toUpperCase();
......@@ -136,4 +137,22 @@ public class CommonUtils {
}
return text;
}
public static <T> List<List<T>> subListWithLen(List<T> source, int len) {
if (source == null || source.size() == 0 || len < 1) {
return null;
}
List<List<T>> result = new ArrayList<>();
int count = (source.size() + len - 1) / len;
for (int i = 0; i < count; i++) {
List<T> value;
if ((i + 1) * len < source.size()) {
value = source.subList(i * len, (i + 1) * len);
} else {
value = source.subList(i * len, source.size());
}
result.add(value);
}
return result;
}
}
package pwc.taxtech.atms.common;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
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.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Optional;
public class POIUtil {
private static final Logger logger = LoggerFactory.getLogger(POIUtil.class);
public static final String XLSX = ".xlsx";
public static final String XLS = ".xls";
public static Optional<Workbook> cloneNewSheet(Sheet sheet, String fileName) {
Workbook workbook;
try {
if (StringUtils.endsWith(fileName, XLSX)) {
workbook = new XSSFWorkbook();
} else if (StringUtils.endsWith(fileName, XLS)) {
workbook = new HSSFWorkbook();
} else {
return Optional.empty();
}
Sheet tmpSheet = workbook.createSheet(sheet.getSheetName());
cloneSheet(sheet, tmpSheet);
return Optional.of(workbook);
} catch (Exception e) {
logger.error("cloneNewSheet error.", e);
}
return Optional.empty();
}
public static void cloneSheet(Sheet sheet, Sheet targetSheet) {
for (int r = sheet.getFirstRowNum(); r <= sheet.getLastRowNum(); r++) {
Row row = sheet.getRow(r);
Row targetRow = targetSheet.createRow(r);
for (int c = row.getFirstCellNum(); c <= row.getLastCellNum(); c++) {
Cell cell = row.getCell(c);
if (null == cell){
continue;
}
Cell targetCell = targetRow.createCell(c);
targetCell.setCellType(cell.getCellTypeEnum());
switch (cell.getCellTypeEnum()) {
case STRING:
targetCell.setCellValue(cell.getStringCellValue());
break;
case NUMERIC:
targetCell.setCellValue(cell.getNumericCellValue());
break;
case BOOLEAN:
targetCell.setCellValue(cell.getBooleanCellValue());
break;
case FORMULA:
targetCell.setCellFormula(cell.getCellFormula());
break;
// case ERROR:
//// case BLANK:
//// case _NONE:
default:
break;
}
if (null != cell.getCellComment()) {
targetCell.setCellComment(cell.getCellComment());
}
if (null != cell.getCellStyle()) {
targetCell.getCellStyle().cloneStyleFrom(cell.getCellStyle());
}
if (null != cell.getHyperlink()) {
targetCell.setHyperlink(cell.getHyperlink());
}
}
}
}
public static String getCellFormulaString(Cell cell) {
switch (cell.getCellTypeEnum()) {
case STRING:
case FORMULA:
case BLANK:
return cell.getStringCellValue();
case NUMERIC:
return String.valueOf(cell.getNumericCellValue());
case BOOLEAN:
return String.valueOf(cell.getBooleanCellValue());
default:
return StringUtils.EMPTY;
}
}
public static Optional<String> getFileSuffix(String fileName) {
if (StringUtils.endsWith(fileName, XLSX)) {
return Optional.of(XLSX);
} else if (StringUtils.endsWith(fileName, XLS)) {
return Optional.of(XLS);
} else {
return Optional.empty();
}
}
}
......@@ -17,6 +17,7 @@ public class FTPClientPool {
private GenericObjectPoolConfig config;
private GenericObjectPool<FTPClient> pool;
private String ftpRootPath;
private static final String SYMBOL = "/";
@Value("${ftp.host}")
private String ftpHost;
......@@ -58,6 +59,9 @@ public class FTPClientPool {
} else {
upPath = filePath;
}
if (!StringUtils.endsWith(upPath, SYMBOL)) {
upPath = upPath + SYMBOL;
}
FTPClient client = getClient();
if (!isExist(upPath, client)) {
mkDir(upPath, client);
......
package pwc.taxtech.atms.common.message;
public class TemplateMessage {
public static final String TemplateGroupIDNotMatch = "TemplateGroupIDNotMatch";
public static final String SameCodeTemplateRepeat = "SameCodeTemplateRepeat";
public static final String SameNameTemplateRepeat = "SameNameTemplateRepeat";
public static final String TemplateGroupNameExist = "TemplateGroupNameExist";
public static final String SystemTypeCannotDelete = "SystemTypeCannotDelete";
public static final String OrganizationUsedTemplateGroup = "OrganizationUsedTemplateGroup";
}
package pwc.taxtech.atms.controller;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.ServiceException;
import pwc.taxtech.atms.common.ftp.FTPClientPool;
import pwc.taxtech.atms.common.message.ErrorMessage;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.TemplateGroupDto;
import pwc.taxtech.atms.service.TemplateGroupService;
......@@ -63,4 +68,66 @@ public class TemplateGroupController {
}
return result;
}
@ResponseBody
@ApiOperation(value = "获取Sheet名称")
@RequestMapping(value = "getSheetNameList", method = RequestMethod.POST)
public OperationResultDto getSheetNameList(@RequestParam MultipartFile file,
@RequestParam String filename,
@RequestParam String tempFileName) {
try {
if (null == file) {
return OperationResultDto.error(ErrorMessage.NoFile);
}
return OperationResultDto.success(templateGroupService.getSheetNameList(file));
} catch (Exception e) {
logger.error("getSheetNameList error.", e);
}
return OperationResultDto.error();
}
@ResponseBody
@ApiOperation(value = "导入模板")
@RequestMapping(value = "importTemplateGroupExcelFile", method = RequestMethod.POST)
public OperationResultDto importTemplateGroupExcelFile(@RequestParam MultipartFile file,
@RequestParam String filename,
@RequestParam String tempFileName,
@RequestParam String jsonModel) {
try {
if (null == file) {
return OperationResultDto.error(ErrorMessage.NoFile);
}
TemplateGroupDto templateGroupDto = JSON.parseObject(jsonModel, TemplateGroupDto.class);
if (CollectionUtils.isEmpty(templateGroupDto.getSheetNameList())) {
return OperationResultDto.error(ErrorMessage.NoSelectSheet);
}
templateGroupService.importTemplateGroupExcelFile(file, templateGroupDto);
return OperationResultDto.success();
} catch (ServiceException e) {
return OperationResultDto.error(e.getMessage());
} catch (Exception e) {
logger.error("importTemplateGroupExcelFile error.", e);
}
return OperationResultDto.error(ErrorMessage.SystemError);
}
@ResponseBody
@ApiOperation(value = "导入报表")
@RequestMapping(value = "importTemplateExcelFile", method = RequestMethod.POST)
public OperationResultDto importTemplateExcelFile(@RequestParam MultipartFile file,
@RequestParam String templateGroupID,
@RequestParam String sheetList,
@RequestParam String tempFileName,
@RequestParam String reportType,
@RequestParam String filename) {
try {
templateGroupService.importTemplateExcelFile(file, templateGroupID, reportType, sheetList);
return OperationResultDto.success();
} catch (ServiceException e) {
return OperationResultDto.error(e.getMessage());
} catch (Exception e) {
logger.error("importTemplateExcelFile error.", e);
}
return OperationResultDto.error(ErrorMessage.SystemError);
}
}
......@@ -109,4 +109,6 @@ public interface CellTemplateConfigMapper extends MyMapper {
List<CellTemplateConfig> getCellTemplateConfigByTemplateID(@Param("templateID") String templateID);
int deleteCellTemplateConfigByCellTemplate(@Param("templateDbID") String templateDbID);
void batchInsert(List<CellTemplateConfig> list);
}
\ No newline at end of file
......@@ -106,5 +106,7 @@ public interface CellTemplateMapper extends MyMapper {
*/
int updateByPrimaryKey(CellTemplate record);
void batchInsert(List<CellTemplate> list);
}
\ No newline at end of file
package pwc.taxtech.atms.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.TemplateMapper;
import pwc.taxtech.atms.entitiy.Template;
import pwc.taxtech.atms.entitiy.TemplateExample;
import java.util.List;
@Service
public class TemplateDao {
@Autowired
private TemplateMapper mapper;
public List<Template> getByName(String name) {
TemplateExample example = new TemplateExample();
TemplateExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(name);
return mapper.selectByExample(example);
}
public List<Template> getByCode(String code) {
TemplateExample example = new TemplateExample();
TemplateExample.Criteria criteria = example.createCriteria();
criteria.andCodeEqualTo(code);
return mapper.selectByExample(example);
}
}
package pwc.taxtech.atms.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.TemplateGroupMapper;
import pwc.taxtech.atms.entitiy.TemplateGroup;
import pwc.taxtech.atms.entitiy.TemplateGroupExample;
import java.util.List;
@Service
public class TemplateGroupDao {
@Autowired
private TemplateGroupMapper mapper;
public List<TemplateGroup> getByGroupName(String name) {
TemplateGroupExample example = new TemplateGroupExample();
TemplateGroupExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(name);
return mapper.selectByExample(example);
}
}
package pwc.taxtech.atms.service;
import java.io.InputStream;
public interface FileSystemService {
/**
* 上传用户报表模板
*
* @param fileName 文件名
* @param inputStream InputStream
* @return 文件路径
* @throws Exception ex
*/
String uploadUserTemplate(String fileName, InputStream inputStream) throws Exception;
/**
* 下载用户报表模板
*
* @param filePath 文件路径
* @return InputStream
* @throws Exception ex
*/
InputStream downloadUserTemplate(String filePath) throws Exception;
}
package pwc.taxtech.atms.service;
import pwc.taxtech.atms.dto.OperationResultDto;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.ServiceException;
import pwc.taxtech.atms.dto.TemplateGroupDto;
import java.util.List;
......@@ -13,4 +15,11 @@ public interface TemplateGroupService {
OperationResultDto<Object> updateTemplateGroupName(TemplateGroupDto templateGroupDto);
OperationResultDto<Object> deleteTemplateGroup(TemplateGroupDto templateGroupDto);
List<String> getSheetNameList(MultipartFile file);
void importTemplateGroupExcelFile(MultipartFile file, TemplateGroupDto templateGroupDto) throws ServiceException;
void importTemplateExcelFile(MultipartFile file, String templateGroupID,
String reportType, String sheetList) throws ServiceException;
}
package pwc.taxtech.atms.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.common.ftp.FTPClientPool;
import pwc.taxtech.atms.service.FileSystemService;
import java.io.InputStream;
@Service
public class FTPFileSystemServiceImpl implements FileSystemService {
private static final String USER_TEMPLATE_PATH = "pwc/userTemplate/";
@Autowired
private FTPClientPool ftpClientPool;
@Override
public String uploadUserTemplate(String fileName, InputStream inputStream) throws Exception {
ftpClientPool.upload(USER_TEMPLATE_PATH, fileName, inputStream);
return USER_TEMPLATE_PATH + fileName;
}
@Override
public InputStream downloadUserTemplate(String filePath) throws Exception {
return ftpClientPool.download(filePath);
}
}
......@@ -544,4 +544,24 @@ WHERE
c.ReportTemplateID = #{templateDbID,jdbcType=VARCHAR}
) x)
</delete>
<insert id="batchInsert" parameterType="pwc.taxtech.atms.entitiy.CellTemplateConfig">
insert into CellTemplateConfig (ID, CellTemplateID, ReportTemplateID,
DataSourceType, Formula, FormulaDescription,
AccountCodes, InvoiceType, TaxRate,
InvoiceAmountType, ModelIDs, Creator,
CreateTime, Updater, UpdateTime,
InvoiceCategory, FormulaDataSource, Validation,
ValidationDescription, VoucherKeyword)
values
<foreach collection ="list" item="item" separator =",">
(#{item.ID,jdbcType=VARCHAR}, #{item.cellTemplateID,jdbcType=VARCHAR}, #{item.reportTemplateID,jdbcType=VARCHAR},
#{item.dataSourceType,jdbcType=INTEGER}, #{item.formula,jdbcType=VARCHAR}, #{item.formulaDescription,jdbcType=VARCHAR},
#{item.accountCodes,jdbcType=VARCHAR}, #{item.invoiceType,jdbcType=INTEGER}, #{item.taxRate,jdbcType=VARCHAR},
#{item.invoiceAmountType,jdbcType=INTEGER}, #{item.modelIDs,jdbcType=VARCHAR}, #{item.creator,jdbcType=VARCHAR},
#{item.createTime,jdbcType=TIMESTAMP}, #{item.updater,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP},
#{item.invoiceCategory,jdbcType=VARCHAR}, #{item.formulaDataSource,jdbcType=VARCHAR}, #{item.validation,jdbcType=VARCHAR},
#{item.validationDescription,jdbcType=VARCHAR}, #{item.voucherKeyword,jdbcType=VARCHAR})
</foreach>
</insert>
</mapper>
\ No newline at end of file
......@@ -398,4 +398,20 @@
order by ${orderByClause}
</if>
</select>
<insert id="batchInsert">
insert into CellTemplate (ID, ReportTemplateID, RowIndex,
RowName, ColumnIndex, ColumnName,
Comment, CreateTime, UpdateTime,
CopyFromID, DataType, IsReadOnly
)
values
<foreach collection ="list" item="item" separator =",">
(#{item.ID,jdbcType=VARCHAR}, #{item.reportTemplateID,jdbcType=VARCHAR}, #{item.rowIndex,jdbcType=INTEGER},
#{item.rowName,jdbcType=VARCHAR}, #{item.columnIndex,jdbcType=INTEGER}, #{item.columnName,jdbcType=VARCHAR},
#{item.comment,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP},
#{item.copyFromID,jdbcType=VARCHAR}, #{item.dataType,jdbcType=INTEGER}, #{item.isReadOnly,jdbcType=INTEGER}
)
</foreach >
</insert>
</mapper>
\ No newline at end of file
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