Commit 92d44427 authored by chase's avatar chase

收入类型配置导出

parent 9bb49a2d
package pwc.taxtech.atms.controller;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.constant.enums.EnumImportType;
import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.dto.input.CamelPagingResultDto;
import pwc.taxtech.atms.dto.revenuconf.RevConfAddDto;
......@@ -11,6 +13,9 @@ import pwc.taxtech.atms.service.impl.RevenueConfService;
import pwc.taxtech.atms.vat.entity.RevenueConfig;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
@RestController
......@@ -46,9 +51,33 @@ public class RevenueConfController extends BaseController {
revenueConfService.delConfig(idList);
return ApiResultDto.success();
}
@PostMapping("upload")
public ApiResultDto upload(@RequestParam MultipartFile file, @RequestParam Integer type) throws Exception {
List<String> unSuccessList = revenueConfService.upload(file, type);
return ApiResultDto.success(unSuccessList);
}
@GetMapping("export")
public void export(HttpServletResponse response) throws Exception {
OutputStream ouputStream = null;
try {
InputStream inputStream = this.getClass().getResourceAsStream("/document/DataImport/" + EnumImportType.RevenueConfig.name() + ".xlsx");
Workbook tWorkbook = revenueConfService.export(inputStream);
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName=" + EnumImportType.RevenueConfig.name() + ".xlsx");
ouputStream = response.getOutputStream();
tWorkbook.write(ouputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (ouputStream != null) {
ouputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
......@@ -9,6 +9,7 @@ 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.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.CommonUtils;
......@@ -19,6 +20,7 @@ import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.dto.revenuconf.RevConfAddDto;
import pwc.taxtech.atms.dto.revenuconf.RevenueConfParam;
import pwc.taxtech.atms.dto.revenuconf.RevenueConfResult;
import pwc.taxtech.atms.exception.Exceptions;
import pwc.taxtech.atms.vat.dao.RevenueConfigMapper;
import pwc.taxtech.atms.vat.entity.RevenueConfig;
import pwc.taxtech.atms.vat.entity.RevenueConfigExample;
......@@ -26,10 +28,7 @@ import pwc.taxtech.atms.vat.entity.RevenueConfigExample;
import javax.annotation.Resource;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -266,4 +265,55 @@ public class RevenueConfService extends BaseService {
}
return msg;
}
public Workbook export(InputStream is){
Workbook tWorkbook = new XSSFWorkbook();
try {
tWorkbook = WorkbookFactory.create(is);
Sheet sheet = tWorkbook.getSheetAt(0);
Row sourceRow = sheet.getRow(1);
//查询公司map
List<OrgSelectDto> orgDtoList = organizationService.getMyOrgList();
Map<String, String> orgMap = orgDtoList.stream().collect(Collectors.toMap(OrgSelectDto::getId, OrgSelectDto::getName, (value1, value2) -> {
return value2;
}));
if(CollectionUtils.isNotEmpty(orgDtoList)){
RevenueConfigExample example = new RevenueConfigExample();
example.createCriteria().andOrgIdIn(orgDtoList.stream().map(OrgSelectDto::getId).collect(Collectors.toList()));
example.setOrderByClause("org_id");
List<RevenueConfig> dataList = revenueConfigMapper.selectByExample(example);
if(CollectionUtils.isNotEmpty(dataList)){
for(int i = dataList.size()-1;i>=0;i--){
RevenueConfig revenueConfig = dataList.get(i);
Row row = POIUtil.createAndCloneRow(tWorkbook, sheet, 1, sourceRow);
row.getCell(RevenueConfEnum.EXECLColumn.Column_1.getIndex()).setCellValue(revenueConfig.getName());
row.getCell(RevenueConfEnum.EXECLColumn.Column_2.getIndex()).setCellValue(orgMap.get(revenueConfig.getOrgId()));
row.getCell(RevenueConfEnum.EXECLColumn.Column_3.getIndex()).setCellValue(RevenueConfEnum.AccountType.MAPPING.get(revenueConfig.getAccountType()));
row.getCell(RevenueConfEnum.EXECLColumn.Column_4.getIndex()).setCellValue(revenueConfig.getTbSegment3());
row.getCell(RevenueConfEnum.EXECLColumn.Column_5.getIndex()).setCellValue(revenueConfig.getTbSegment5());
row.getCell(RevenueConfEnum.EXECLColumn.Column_6.getIndex()).setCellValue(revenueConfig.getTbSegment6());
row.getCell(RevenueConfEnum.EXECLColumn.Column_7.getIndex()).setCellValue(String.valueOf(revenueConfig.getTaxRate().multiply(new BigDecimal(100)).intValue())+"%");
row.getCell(RevenueConfEnum.EXECLColumn.Column_8.getIndex()).setCellValue(RevenueConfEnum.TaxBase.MAPPING.get(revenueConfig.getTaxBase()));
if(revenueConfig.getTaxBase().intValue() == 4){
row.getCell(RevenueConfEnum.EXECLColumn.Column_9.getIndex()).setCellValue(revenueConfig.getBaseDrCode());
}else if(revenueConfig.getTaxBase().intValue() == 5){
row.getCell(RevenueConfEnum.EXECLColumn.Column_9.getIndex()).setCellValue(revenueConfig.getBaseCrCode());
}else{
row.getCell(RevenueConfEnum.EXECLColumn.Column_9.getIndex()).setCellValue("");
}
row.getCell(RevenueConfEnum.EXECLColumn.Column_10.getIndex()).setCellValue(RevenueConfEnum.RevenueType.MAPPING.get(revenueConfig.getRevenueType()));
row.getCell(RevenueConfEnum.EXECLColumn.Column_11.getIndex()).setCellValue(RevenueConfEnum.TaxType.MAPPING.get(revenueConfig.getTaxType()));
row.getCell(RevenueConfEnum.EXECLColumn.Column_12.getIndex()).setCellValue(RevenueConfEnum.Status.MAPPING.get(revenueConfig.getStatus()));
row.getCell(RevenueConfEnum.EXECLColumn.Column_13.getIndex()).setCellValue(revenueConfig.getStartDate());
row.getCell(RevenueConfEnum.EXECLColumn.Column_14.getIndex()).setCellValue(revenueConfig.getEndDate());
}
}
}
sheet.removeRow(sourceRow);
return tWorkbook;
} catch (Exception e) {
logger.error("export error.", e);
throw Exceptions.SERVER_ERROR_EXCEPTION;
}
}
}
......@@ -85,6 +85,34 @@
});
};
$scope.exportRevenueConf = function () {
$http.get('/revenueConf/export', apiConfig.create({ responseType: 'arraybuffer' })).success(function (data, status, headers) {
var octetStreamMime = 'application/octet-stream';
var contentType = headers('content-type') || octetStreamMime;
if (window.navigator.msSaveBlob) {
var blob = new Blob([data], {
type: contentType
});
navigator.msSaveBlob(blob, "收入类型配置报表");
} else {
var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
if (urlCreator) {
var a = document.createElement('a');
var blob = new Blob([data], {
type: contentType
});
var url = urlCreator.createObjectURL(blob);
a.href = url;
a.target = '_blank';
a.download = "收入类型配置报表.xlsx";
document.body.appendChild(a);
a.click();
}
}
}).error(function () {
SweetAlert.error($translate.instant('PleaseContactAdministrator'));
});
};
//表格配置
$scope.revenueGridOptions = $.extend(true, {}, dxDataGridService.BASIC_GRID_OPTIONS, {
columns: [
......
......@@ -17,6 +17,9 @@
<button type="button" class="btn btn-in-grid inline-div" ng-click="downloadTemplate()"><i
class="fa fa-download" aria-hidden="true"></i>下载模板
</button>
<button type="button" class="btn btn-in-grid inline-div" ng-click="exportRevenueConf()"><i
class="fa fa-download" aria-hidden="true"></i>导出报表
</button>
</div>
</form>
......
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