Commit 0c5c5fa1 authored by eddie.woo's avatar eddie.woo

modify

parent 96eece88
package pwc.taxtech.atms.common; package pwc.taxtech.atms.common;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
...@@ -140,7 +136,7 @@ public class CommonUtils { ...@@ -140,7 +136,7 @@ public class CommonUtils {
public static <T> List<List<T>> subListWithLen(List<T> source, int len) { public static <T> List<List<T>> subListWithLen(List<T> source, int len) {
if (source == null || source.size() == 0 || len < 1) { if (source == null || source.size() == 0 || len < 1) {
return null; return Collections.emptyList();
} }
List<List<T>> result = new ArrayList<>(); List<List<T>> result = new ArrayList<>();
int count = (source.size() + len - 1) / len; int count = (source.size() + len - 1) / len;
......
...@@ -130,4 +130,19 @@ public class TemplateGroupController { ...@@ -130,4 +130,19 @@ public class TemplateGroupController {
return OperationResultDto.error(ErrorMessage.SystemError); return OperationResultDto.error(ErrorMessage.SystemError);
} }
@ResponseBody
@ApiOperation(value = "模板另存为")
@RequestMapping(value = "addTemplateGroup", method = RequestMethod.POST)
public OperationResultDto addTemplateGroup(@RequestBody TemplateGroupDto templateGroupDto) {
try {
templateGroupService.addTemplateGroup(templateGroupDto);
return OperationResultDto.success();
} catch (ServiceException e) {
return OperationResultDto.error(e.getMessage());
} catch (Exception e) {
logger.error("addTemplateGroup error.", e);
}
return OperationResultDto.error(ErrorMessage.SystemError);
}
} }
package pwc.taxtech.atms.dao.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pwc.taxtech.atms.dao.CellTemplateConfigMapper;
import pwc.taxtech.atms.entitiy.CellTemplateConfig;
import pwc.taxtech.atms.entitiy.CellTemplateConfigExample;
import java.util.List;
@Service
public class CellTemplateConfigDao {
@Autowired
private CellTemplateConfigMapper mapper;
public List<CellTemplateConfig> getByTemplateID(String id) {
CellTemplateConfigExample example = new CellTemplateConfigExample();
CellTemplateConfigExample.Criteria criteria = example.createCriteria();
criteria.andReportTemplateIDEqualTo(id);
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.CellTemplateMapper;
import pwc.taxtech.atms.entitiy.CellTemplate;
import pwc.taxtech.atms.entitiy.CellTemplateExample;
import java.util.List;
@Service
public class CellTemplateDao {
@Autowired
private CellTemplateMapper mapper;
public List<CellTemplate> getByTemplateID(String id) {
CellTemplateExample example = new CellTemplateExample();
CellTemplateExample.Criteria criteria = example.createCriteria();
criteria.andReportTemplateIDEqualTo(id);
return mapper.selectByExample(example);
}
}
...@@ -27,4 +27,11 @@ public class TemplateDao { ...@@ -27,4 +27,11 @@ public class TemplateDao {
return mapper.selectByExample(example); return mapper.selectByExample(example);
} }
public List<Template> getByGroupID(String groupID) {
TemplateExample example = new TemplateExample();
TemplateExample.Criteria criteria = example.createCriteria();
criteria.andTemplateGroupIDEqualTo(groupID);
return mapper.selectByExample(example);
}
} }
...@@ -22,4 +22,6 @@ public interface TemplateGroupService { ...@@ -22,4 +22,6 @@ public interface TemplateGroupService {
void importTemplateExcelFile(MultipartFile file, String templateGroupID, void importTemplateExcelFile(MultipartFile file, String templateGroupID,
String reportType, String sheetList) throws ServiceException; String reportType, String sheetList) throws ServiceException;
void addTemplateGroup(TemplateGroupDto templateGroupDto) throws ServiceException;
} }
...@@ -2,6 +2,7 @@ package pwc.taxtech.atms.service.impl; ...@@ -2,6 +2,7 @@ package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
...@@ -20,6 +21,9 @@ import pwc.taxtech.atms.dao.CellTemplateConfigMapper; ...@@ -20,6 +21,9 @@ import pwc.taxtech.atms.dao.CellTemplateConfigMapper;
import pwc.taxtech.atms.dao.CellTemplateMapper; import pwc.taxtech.atms.dao.CellTemplateMapper;
import pwc.taxtech.atms.dao.TemplateGroupMapper; import pwc.taxtech.atms.dao.TemplateGroupMapper;
import pwc.taxtech.atms.dao.TemplateMapper; import pwc.taxtech.atms.dao.TemplateMapper;
import pwc.taxtech.atms.dao.dao.CellTemplateConfigDao;
import pwc.taxtech.atms.dao.dao.CellTemplateDao;
import pwc.taxtech.atms.dao.dao.TemplateDao;
import pwc.taxtech.atms.dao.dao.TemplateGroupDao; import pwc.taxtech.atms.dao.dao.TemplateGroupDao;
import pwc.taxtech.atms.dto.OperationResultDto; import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.TemplateGroupDto; import pwc.taxtech.atms.dto.TemplateGroupDto;
...@@ -44,9 +48,15 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -44,9 +48,15 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
@Autowired @Autowired
private TemplateMapper templateMapper; private TemplateMapper templateMapper;
@Autowired @Autowired
private TemplateDao templateDao;
@Autowired
private CellTemplateMapper cellTemplateMapper; private CellTemplateMapper cellTemplateMapper;
@Autowired @Autowired
private CellTemplateDao cellTemplateDao;
@Autowired
private CellTemplateConfigMapper cellTemplateConfigMapper; private CellTemplateConfigMapper cellTemplateConfigMapper;
@Autowired
private CellTemplateConfigDao cellTemplateConfigDao;
@Override @Override
public List<TemplateGroupDto> get() { public List<TemplateGroupDto> get() {
...@@ -254,9 +264,9 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -254,9 +264,9 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
} }
List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM); List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM);
tmpList.stream().forEach(list -> cellTemplateMapper.batchInsert(list)); tmpList.forEach(list -> cellTemplateMapper.batchInsert(list));
List<List<CellTemplateConfig>> tmpConfigList = CommonUtils.subListWithLen(cellTemplateConfigList, CommonUtils.BATCH_NUM); List<List<CellTemplateConfig>> tmpConfigList = CommonUtils.subListWithLen(cellTemplateConfigList, CommonUtils.BATCH_NUM);
tmpConfigList.stream().forEach(list -> cellTemplateConfigMapper.batchInsert(list)); tmpConfigList.forEach(list -> cellTemplateConfigMapper.batchInsert(list));
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -265,6 +275,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -265,6 +275,7 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
} }
@Transactional
@Override @Override
public void importTemplateExcelFile(MultipartFile file, String templateGroupID, String reportType, String sheetList) throws ServiceException { public void importTemplateExcelFile(MultipartFile file, String templateGroupID, String reportType, String sheetList) throws ServiceException {
if (null == file) { if (null == file) {
...@@ -344,9 +355,9 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -344,9 +355,9 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
} }
List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM); List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList, CommonUtils.BATCH_NUM);
tmpList.stream().forEach(list -> cellTemplateMapper.batchInsert(list)); tmpList.forEach(list -> cellTemplateMapper.batchInsert(list));
List<List<CellTemplateConfig>> tmpConfigList = CommonUtils.subListWithLen(cellTemplateConfigList, CommonUtils.BATCH_NUM); List<List<CellTemplateConfig>> tmpConfigList = CommonUtils.subListWithLen(cellTemplateConfigList, CommonUtils.BATCH_NUM);
tmpConfigList.stream().forEach(list -> cellTemplateConfigMapper.batchInsert(list)); tmpConfigList.forEach(list -> cellTemplateConfigMapper.batchInsert(list));
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("importTemplateExcelFile error.", e); logger.error("importTemplateExcelFile error.", e);
...@@ -354,4 +365,66 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat ...@@ -354,4 +365,66 @@ public class TemplateGroupServiceImpl extends AbstractService implements Templat
} }
} }
@Transactional
@Override
public void addTemplateGroup(TemplateGroupDto templateGroupDto) throws ServiceException {
List<TemplateGroup> groupList = templateGroupDao.getByGroupName(templateGroupDto.getName());
if (CollectionUtils.isNotEmpty(groupList)) {
throw new ServiceException(TemplateMessage.TemplateGroupNameExist);
}
try {
String uid = authUserHelper.getCurrentUserID();
TemplateGroup templateGroup = templateGroupMapper.selectByPrimaryKey(templateGroupDto.getCopyFrom());
String newGroupID = CommonUtils.getUUID();
String groupID = templateGroup.getID();
Date now = new Date();
templateGroup.setCopyFrom(groupID);
templateGroup.setID(newGroupID);
templateGroup.setCreateTime(now);
templateGroup.setUpdateTime(now);
templateGroupMapper.insertSelective(templateGroup);
List<Template> templateList = templateDao.getByGroupID(groupID);
templateList.stream().forEach(item -> {
String itemID = item.getID();
String newItemID = CommonUtils.getUUID();
item.setID(newItemID);
item.setCreateTime(now);
item.setUpdateTime(now);
templateMapper.insertSelective(item);
List<CellTemplate> cellTemplateList = cellTemplateDao.getByTemplateID(itemID);
Map<String, String> idMapper = Maps.newHashMap();
List<List<CellTemplate>> tmpList = CommonUtils.subListWithLen(cellTemplateList.stream().map(cell -> {
String cellID = cell.getID();
String newCellID = CommonUtils.getUUID();
cell.setCopyFromID(cellID);
cell.setID(newCellID);
cell.setReportTemplateID(newItemID);
cell.setCreateTime(now);
cell.setUpdateTime(now);
idMapper.put(cellID, newCellID);
return cell;
}).collect(Collectors.toList()), CommonUtils.BATCH_NUM);
tmpList.forEach(list -> cellTemplateMapper.batchInsert(list));
List<CellTemplateConfig> configList = cellTemplateConfigDao.getByTemplateID(itemID);
List<List<CellTemplateConfig>> tmpConfigList = CommonUtils.subListWithLen(configList.stream().map(cell -> {
String newCellID = CommonUtils.getUUID();
cell.setCreator(uid);
cell.setUpdater(uid);
cell.setID(newCellID);
cell.setReportTemplateID(newItemID);
cell.setCellTemplateID(idMapper.get(cell.getCellTemplateID()));
cell.setCreateTime(now);
cell.setUpdateTime(now);
return cell;
}).collect(Collectors.toList()), CommonUtils.BATCH_NUM);
tmpConfigList.forEach(list -> cellTemplateConfigMapper.batchInsert(list));
});
} catch (Exception e) {
logger.error("addTemplateGroup error.", e);
throw new ServiceException(ErrorMessage.SystemError);
}
}
} }
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