DataPreviewSerivceImpl.java 39 KB
Newer Older
gary's avatar
gary committed
1 2
package pwc.taxtech.atms.service.impl;

Ken you's avatar
Ken you committed
3
import com.github.pagehelper.Page;
gary's avatar
gary committed
4 5 6 7
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;
gary's avatar
gary committed
8 9 10
import pwc.taxtech.atms.common.message.ErrorMessage;
import pwc.taxtech.atms.constant.CountTypeConstant;
import pwc.taxtech.atms.constant.ExportTemplatePathConstant;
Ken you's avatar
Ken you committed
11
import pwc.taxtech.atms.dao.OrganizationMapper;
12 13
import pwc.taxtech.atms.dto.vatdto.*;
import pwc.taxtech.atms.dto.vatdto.dd.*;
gary's avatar
gary committed
14
import pwc.taxtech.atms.dto.vatdto.dd.TrialBalanceDto;
Ken you's avatar
Ken you committed
15
import pwc.taxtech.atms.dto.vatdto.excelheader.CashFlowHeader;
gary's avatar
gary committed
16
import pwc.taxtech.atms.dto.vatdto.excelheader.CertifiedInvoicesListHeader;
Ken you's avatar
Ken you committed
17
import pwc.taxtech.atms.entity.Organization;
gary's avatar
gary committed
18
import pwc.taxtech.atms.exception.ServiceException;
19
import pwc.taxtech.atms.thirdparty.ExcelUtil;
20 21
import pwc.taxtech.atms.vat.dao.*;
import pwc.taxtech.atms.vat.dpo.*;
22 23
import pwc.taxtech.atms.vat.dpo.TrialBalanceCondition;
import pwc.taxtech.atms.vat.entity.*;
gary's avatar
gary committed
24 25

import javax.annotation.Resource;
Ken you's avatar
Ken you committed
26
import javax.servlet.http.HttpServletResponse;
27
import java.io.OutputStream;
gary's avatar
gary committed
28
import java.math.BigDecimal;
Ken you's avatar
Ken you committed
29
import java.util.*;
30
import java.util.stream.Collectors;
gary's avatar
gary committed
31 32 33 34 35 36 37 38 39 40 41 42

/**
 * @Auther: Gary J Li
 * @Date: 01/02/2019 10:36
 * @Description:
 */
@Service
public class DataPreviewSerivceImpl extends BaseService {

    @Resource
    private TrialBalanceMapper trialBalanceMapper;

43
    @Resource
gary's avatar
gary committed
44
    private ProfitLossStatementPrcMapper profitLossStatementPrcMapper;
45 46 47 48 49

    @Resource
    private JournalEntryMapper journalEntryMapper;

    @Resource
gary's avatar
gary committed
50
    private BalanceSheetPrcMapper balanceSheetPrcMapper;
51

52 53
    @Resource
    private CashFlowMapper cashFlowMapper;
54 55 56 57 58 59 60 61 62 63 64 65 66

    @Resource
    private InvoiceRecordMapper invoiceRecordMapper;

    @Resource
    private RedLetterInfoTableMapper redLetterInfoTableMapper;

    @Resource
    private CoupaPurchasingReportMapper coupaPurchasingReportMapper;

    @Resource
    private CertifiedInvoicesListMapper certifiedInvoicesListMapper;

gary's avatar
gary committed
67 68 69
    @Resource
    private InvoiceDataMapper invoiceDataMapper;

Ken you's avatar
Ken you committed
70 71
    @Resource
    private OrganizationMapper organizationMapper;
72

73 74
    @Resource
    private CommonDocumentHelper commonDocumentHelper;
gary's avatar
gary committed
75 76 77

    public PageInfo<TrialBalanceDto> getTBDataForDisplay(TrialBalanceParam param) {

78
        TrialBalanceCondition condition = beanUtil.copyProperties(param, new TrialBalanceCondition());
gary's avatar
gary committed
79

80
        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());
81
        List<TrialBalance> trialBalances = trialBalanceMapper.selectByCondition(condition);
gary's avatar
gary committed
82 83 84 85 86 87 88 89
        List<TrialBalanceDto> trialBalanceDtos = Lists.newArrayList();

        trialBalances.forEach(tb -> {
            TrialBalanceDto trialBalanceDto = new TrialBalanceDto();
            beanUtil.copyProperties(tb, trialBalanceDto);
            trialBalanceDtos.add(trialBalanceDto);
        });

90 91 92 93 94
        PageInfo<TrialBalanceDto> pageInfo =new PageInfo<>(trialBalanceDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
gary's avatar
gary committed
95
    }
96 97 98

    public PageInfo<ProfitLossStatementDto> getPLDataForDisplay(ProfitLossStatementParam param) {

99
        ProfitLossStatementCondition condition = beanUtil.copyProperties(param, new ProfitLossStatementCondition());
100

101
        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());
102
        List<ProfitLossStatementPrc> profitLossStatements = profitLossStatementPrcMapper.selectByCondition(condition);
103 104 105 106 107 108 109 110
        List<ProfitLossStatementDto> profitLossDtos = Lists.newArrayList();

        profitLossStatements.forEach(pl -> {
            ProfitLossStatementDto profitLossDto = new ProfitLossStatementDto();
            beanUtil.copyProperties(pl, profitLossDto);
            profitLossDtos.add(profitLossDto);
        });

111 112 113 114 115
        PageInfo<ProfitLossStatementDto> pageInfo =new PageInfo<>(profitLossDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
116 117
    }

118
    public PageInfo<CashFlowDto> getCFDataForDisplay(CashFlowParam param) {
Ken you's avatar
Ken you committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        CashFlowCondition condition = new CashFlowCondition();
        beanUtil.copyProperties(param, condition);
        //Integer totalCount=cashFlowMapper.selectCountByCondition(condition);
        List<CashFlowDto> cashFlowDtos = Lists.newArrayList();
        Page page = PageHelper.startPage(param.getPageInfo().getPageIndex(), param.getPageInfo().getPageSize());
        List<CashFlow> cashFlows = cashFlowMapper.selectByCondition(condition);
        //使用page的getTotal()
        Long total = page.getTotal();
        cashFlows.forEach(cf -> {
            CashFlowDto cashFlowDto = new CashFlowDto();
            beanUtil.copyProperties(cf, cashFlowDto);
            cashFlowDtos.add(cashFlowDto);
        });
        PageInfo<CashFlowDto> pageInfo=new PageInfo<>(cashFlowDtos);
        pageInfo.setTotal(total);
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());
        return pageInfo;
    }

138
    public HttpServletResponse exportCashFlowList(HttpServletResponse response, CashFlowParam param, String fileName) {
Ken you's avatar
Ken you committed
139 140 141
        //Boolean isEn = StringUtils.equals(language, "en-us");
        logger.debug("start export input invoice list to excel");
        //String excelTemplatePathInClassPath = "/vat_excel_template/cash_flow"+(isEn?"":"_cn") + ".xlsx";
gary's avatar
gary committed
142
        String excelTemplatePathInClassPath = ExportTemplatePathConstant.CASH_FLOW;
143 144 145 146 147 148 149 150 151 152
        CashFlowCondition condition = new CashFlowCondition();
        beanUtil.copyProperties(param, condition);
        PageHelper.startPage(param.getPageInfo().getPageIndex(), param.getPageInfo().getPageSize());
        List<CashFlow> cashFlows = cashFlowMapper.selectByCondition(condition);
        List<CashFlowDto> cashFlowDtos = Lists.newArrayList();
        cashFlows.forEach(cf -> {
            CashFlowDto cashFlowDto = new CashFlowDto();
            beanUtil.copyProperties(cf, cashFlowDto);
            cashFlowDtos.add(cashFlowDto);
        });
Ken you's avatar
Ken you committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        CashFlowHeader cashFlowHeader=new CashFlowHeader();
        if(cashFlowDtos.size()>0){
            Organization org = organizationMapper.selectByPrimaryKey(param.getOrgId());
            cashFlowHeader.setCompanyNameCn(org.getName());
            cashFlowHeader.setPeriodStart(param.getPeriodStart());
            cashFlowHeader.setPeriodEnd(param.getPeriodEnd());
            cashFlowHeader.setLedgerName(cashFlowDtos.get(0).getLedgerName());
            cashFlowHeader.setLedgerCurrencyCode(cashFlowDtos.get(0).getLedgerCurrencyCode());
            cashFlowHeader.setStatus(cashFlowDtos.get(0).getStatus());
        }
        OutputStream outputStream = commonDocumentHelper.toXlsxFileUsingJxls(cashFlowHeader, cashFlowDtos, excelTemplatePathInClassPath);

        try {
            return responseMessageBuilder.getDownloadTmpResponseMessage(response, outputStream, fileName);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return null;
172
    }
173

174 175
    public PageInfo<JournalEntryDto> getJEDataForDisplay(JournalEntryParam param) {

176
        JournalEntryCondition condition = beanUtil.copyProperties(param, new JournalEntryCondition());
177

178
        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());
179 180 181 182 183 184 185 186 187
        List<JournalEntry> journalEntrys = journalEntryMapper.selectByCondition(condition);
        List<JournalEntryDto> journalEntryDtos = Lists.newArrayList();

        journalEntrys.forEach(je -> {
            JournalEntryDto journalEntryDto = new JournalEntryDto();
            beanUtil.copyProperties(je, journalEntryDto);
            journalEntryDtos.add(journalEntryDto);
        });

188 189 190 191 192
        PageInfo<JournalEntryDto> pageInfo =new PageInfo<>(journalEntryDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
193 194 195 196
    }

    public PageInfo<BalanceSheetDto> getBSDataForDisplay(BalanceSheetParam param) {

197
        BalanceSheetCondition condition = beanUtil.copyProperties(param, new BalanceSheetCondition());
198

199
        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());
200
        List<BalanceSheetPrc> bsPrcList = balanceSheetPrcMapper.selectByCondition(condition);
201 202
        List<BalanceSheetDto> balanceSheetDtos = Lists.newArrayList();

203
        bsPrcList.forEach(bs -> {
204 205 206 207 208
            BalanceSheetDto balanceSheetDto = new BalanceSheetDto();
            beanUtil.copyProperties(bs, balanceSheetDto);
            balanceSheetDtos.add(balanceSheetDto);
        });

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
        PageInfo<BalanceSheetDto> pageInfo =new PageInfo<>(balanceSheetDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
    }

    public PageInfo<InvoiceRecordDto> getIRDataForDisplay(InvoiceRecordParam param) {

        InvoiceRecordCondition condition = beanUtil.copyProperties(param, new InvoiceRecordCondition());

        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());

        List<InvoiceRecord> invoiceRecords = invoiceRecordMapper.selectByCondition(condition);

        List<InvoiceRecordDto> invoiceRecordDtos = Lists.newArrayList();

        invoiceRecords.forEach(bs -> {
            InvoiceRecordDto balanceSheetDto = beanUtil.copyProperties(bs, new InvoiceRecordDto());
            invoiceRecordDtos.add(balanceSheetDto);
        });

        PageInfo<InvoiceRecordDto> pageInfo =new PageInfo<>(invoiceRecordDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
    }

    public PageInfo<RedLetterInfoTableDto> getRLITDataForDisplay(RedLetterInfoTableParam param) {

        RedLetterInfoTableCondition condition = beanUtil.copyProperties(param, new RedLetterInfoTableCondition());

        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());

        List<RedLetterInfoTable> redLetterInfoTables = redLetterInfoTableMapper.selectByCondition(condition);
        List<RedLetterInfoTableDto> redLetterInfoDtos = Lists.newArrayList();

        redLetterInfoTables.forEach(bs -> {
            RedLetterInfoTableDto redLetterInfoDto = beanUtil.copyProperties(bs, new RedLetterInfoTableDto());
            redLetterInfoDtos.add(redLetterInfoDto);
        });

        PageInfo<RedLetterInfoTableDto> pageInfo =new PageInfo<>(redLetterInfoDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
    }


    public PageInfo<CoupaPurchasingReportDto> getCPRDataForDisplay(CoupaPurchasingReportParam param) {

        CoupaPurchasingReportCondition condition = beanUtil.copyProperties(param, new CoupaPurchasingReportCondition());

        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());

        List<CoupaPurchasingReport> coupaPurchasingReports = coupaPurchasingReportMapper.selectByCondition(condition);
        List<CoupaPurchasingReportDto> coupaPurchasingReportDtos = Lists.newArrayList();

        coupaPurchasingReports.forEach(cpr -> {
            CoupaPurchasingReportDto coupaPurchasingReportDto = beanUtil.copyProperties(cpr, new CoupaPurchasingReportDto());
            coupaPurchasingReportDtos.add(coupaPurchasingReportDto);
        });

        PageInfo<CoupaPurchasingReportDto> pageInfo =new PageInfo<>(coupaPurchasingReportDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());

        return pageInfo;
    }


    public PageInfo<CertifiedInvoicesListDto> getCILDataForDisplay(CertifiedInvoicesListParam param) {

        CertifiedInvoicesListCondition condition = beanUtil.copyProperties(param, new CertifiedInvoicesListCondition());

        Page page = PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());
        List<CertifiedInvoicesList> certifiedInvoicesLists = certifiedInvoicesListMapper.selectByCondition(condition);
        List<CertifiedInvoicesListDto> certifiedInvoicesListDtos = Lists.newArrayList();

        certifiedInvoicesLists.forEach(cil -> {
            CertifiedInvoicesListDto CertifiedInvoicesListDto = beanUtil.copyProperties(cil, new CertifiedInvoicesListDto());
            certifiedInvoicesListDtos.add(CertifiedInvoicesListDto);
        });
        PageInfo<CertifiedInvoicesListDto> pageInfo =new PageInfo<>(certifiedInvoicesListDtos);
        pageInfo.setTotal(page.getTotal());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());
        return pageInfo;
298 299
    }

gary's avatar
gary committed
300 301 302 303 304 305 306 307 308 309
    /**
     * 28/02/2019 10:18
     * 导入时纵向存的,因为需求是行数一般不会增加,列数可能增加。查询时90度旋转
     * 后续增加列 1、添加CountTypeConstant(按列递增) 2、增加setIDValue case 3、js添加column
     * [param]
     * @author Gary J Li
     * @return
     */
    public PageInfo<InvoiceDataDto> getIDDataForDisplay(InvoiceDataParam param) {
        InvoiceDataCondition condition = beanUtil.copyProperties(param, new InvoiceDataCondition());
gary's avatar
gary committed
310
        PageHelper.startPage(condition.getPageInfo().getPageIndex(), condition.getPageInfo().getPageSize());
gary's avatar
gary committed
311 312
        List<InvoiceData> invoiceDatas = invoiceDataMapper.selectByCondition(condition);
        List<InvoiceDataDto> invoiceDataDtos = generalIDDtoList();
gary's avatar
gary committed
313
        generalIDDtoList(invoiceDatas, invoiceDataDtos);
gary's avatar
gary committed
314 315 316 317 318 319
        PageInfo<InvoiceDataDto> pageInfo =new PageInfo<>(invoiceDataDtos);
        pageInfo.setTotal(invoiceDataDtos.size());
        pageInfo.setPageNum(param.getPageInfo().getPageIndex());
        return pageInfo;
    }

320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
    public int getTBDownloadFilePath(TrialBalanceParam param, OutputStream os) {
        try {
            TrialBalanceCondition condition = new TrialBalanceCondition();
            beanUtil.copyProperties(param, condition);
            List<TrialBalance> trialBalances = trialBalanceMapper.selectByCondition(condition);

            Map<String, String> header = generalTBHeader();
            List<TrialBalanceExportDto> cellList = new ArrayList<>();
            trialBalances.forEach(tb -> {
                TrialBalanceExportDto d = new TrialBalanceExportDto();
                d = beanUtil.copyProperties(tb, d);
                cellList.add(d);
            });
            ExcelUtil.exportExcel(header, cellList, os);
            return cellList.size();
        } catch (Exception e) {
            logger.error("科目余额表导出转换Excel异常: %s", e.getMessage());
            return 0;
        }
    }


    public int getPLDownloadFilePath(ProfitLossStatementParam param, OutputStream os) {
        try {

            ProfitLossStatementCondition condition = new ProfitLossStatementCondition();
            beanUtil.copyProperties(param, condition);
347
            List<ProfitLossStatementPrc> profitLossStatements = profitLossStatementPrcMapper.selectByCondition(condition);
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
            Map<String, String> header = generalPLHeader();
            List<ProfitLossStatementExportDto> cellList = new ArrayList<>();
            profitLossStatements.forEach(pl -> {
                ProfitLossStatementExportDto d = new ProfitLossStatementExportDto();
                d = beanUtil.copyProperties(pl, d);
                cellList.add(d);
            });
            ExcelUtil.exportExcel(header, cellList, os);
            return cellList.size();
        } catch (Exception e) {
            logger.error("利润表导出转换Excel异常: %s", e.getMessage());
            return 0;
        }
    }

    public int getJEDownloadFilePath(JournalEntryParam param, OutputStream os) {
        try {
            JournalEntryCondition condition = new JournalEntryCondition();
            beanUtil.copyProperties(param, condition);
            List<JournalEntry> journalEntries = journalEntryMapper.selectByCondition(condition);

            Map<String, String> header = generalJEHeader();
            List<JournalEntryExportDto> cellList = new ArrayList<>();
            journalEntries.forEach(tb -> {
                JournalEntryExportDto d = new JournalEntryExportDto();
                d = beanUtil.copyProperties(tb, d);
                cellList.add(d);
            });
            ExcelUtil.exportExcel(header, cellList, os);
            return cellList.size();
        } catch (Exception e) {
            logger.error("日记账导出转换Excel异常: %s", e.getMessage());
            return 0;
        }
    }

    public int getBSDownloadFilePath(BalanceSheetParam param, OutputStream os) {
        try {
            BalanceSheetCondition condition = new BalanceSheetCondition();
            beanUtil.copyProperties(param, condition);
388
            List<BalanceSheetPrc> balanceSheets = balanceSheetPrcMapper.selectByCondition(condition);
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
            Map<String, String> header = generalBSHeader();
            List<BalanceSheetExportDto> cellList = new ArrayList<>();
            balanceSheets.forEach(bs -> {
                BalanceSheetExportDto d = new BalanceSheetExportDto();
                d = beanUtil.copyProperties(bs, d);
                cellList.add(d);
            });
            ExcelUtil.exportExcel(header, cellList, os);
            return cellList.size();
        } catch (Exception e) {
            logger.error("资产负债表导出转换Excel异常: %s", e.getMessage());
            return 0;
        }
    }

gary's avatar
gary committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    public HttpServletResponse exportInvoiceRecordList(HttpServletResponse response, InvoiceRecordParam param, String fileName) {
        //String excelTemplatePathInClassPath = "/vat_excel_template/cash_flow"+(isEn?"":"_cn") + ".xlsx";
        String excelTemplatePathInClassPath = ExportTemplatePathConstant.INVOICES_RECORD;
        InvoiceRecordCondition condition = beanUtil.copyProperties(param, new InvoiceRecordCondition());
        List<InvoiceRecord> invoiceDatas = invoiceRecordMapper.selectByCondition(condition);
        List<InvoiceRecordDto> invoiceDataDtos = Lists.newArrayList();
        invoiceDatas.forEach(id -> {
            InvoiceRecordDto invoiceRecordDto = beanUtil.copyProperties(id, new InvoiceRecordDto());
            invoiceDataDtos.add(invoiceRecordDto);
        });
        OutputStream outputStream = commonDocumentHelper.toXlsxFileUsingJxls(invoiceDataDtos, excelTemplatePathInClassPath);
        try {
            return responseMessageBuilder.getDownloadTmpResponseMessage(response, outputStream, fileName);
        } catch (Exception e) {
            logger.error(String.format("导出发票记录异常:%s",e.getMessage()));
        }
        return null;
    }

    public HttpServletResponse exportCILList(HttpServletResponse response, CertifiedInvoicesListParam param, String fileName) {
        //String excelTemplatePathInClassPath = "/vat_excel_template/cash_flow"+(isEn?"":"_cn") + ".xlsx";
        String excelTemplatePathInClassPath = ExportTemplatePathConstant.CERTIFIED_INVOICES_LIST;
        CertifiedInvoicesListCondition condition = beanUtil.copyProperties(param, new CertifiedInvoicesListCondition());
        List<CertifiedInvoicesList> datas = certifiedInvoicesListMapper.selectByCondition(condition);
        if(datas.size()<1){
            throw new ServiceException(ErrorMessage.ExportFailed);
        }
        CertifiedInvoicesListHeader header = new CertifiedInvoicesListHeader();
        Organization org = organizationMapper.selectByPrimaryKey(param.getOrgId());
        header.setTaxPayerNumber(org.getTaxPayerNumber());
        header.setPeriod(param.getPeriodStart());
        header.setUnit(datas.get(0).getUnit());
        List<CertifiedInvoicesListDto> dtoList = Lists.newArrayList();
        datas.forEach(cil -> {
            CertifiedInvoicesListDto dto = beanUtil.copyProperties(cil, new CertifiedInvoicesListDto());
            dtoList.add(dto);
        });
        OutputStream outputStream = commonDocumentHelper.toXlsxFileUsingJxls(header,dtoList, excelTemplatePathInClassPath);
        try {
            return responseMessageBuilder.getDownloadTmpResponseMessage(response, outputStream, fileName);
        } catch (Exception e) {
            logger.error(String.format("导出已认证发票清单异常:%s",e.getMessage()));
        }
        return null;
    }

    public HttpServletResponse exportCPRList(HttpServletResponse response, CoupaPurchasingReportParam param, String fileName) {
        //String excelTemplatePathInClassPath = "/vat_excel_template/cash_flow"+(isEn?"":"_cn") + ".xlsx";
        String excelTemplatePathInClassPath = ExportTemplatePathConstant.COUPA_PURCHASING_REPORT;
        CoupaPurchasingReportCondition condition = beanUtil.copyProperties(param, new CoupaPurchasingReportCondition());
        List<CoupaPurchasingReport> datas = coupaPurchasingReportMapper.selectByCondition(condition);
        if(datas.size()<1){
            throw new ServiceException(ErrorMessage.ExportFailed);
        }
        List<CoupaPurchasingReportDto> dtos = Lists.newArrayList();
        datas.forEach(d -> {
            CoupaPurchasingReportDto dto = beanUtil.copyProperties(d, new CoupaPurchasingReportDto());
            dtos.add(dto);
        });
        OutputStream outputStream = commonDocumentHelper.toXlsxFileUsingJxls(dtos, excelTemplatePathInClassPath);
        try {
            return responseMessageBuilder.getDownloadTmpResponseMessage(response, outputStream, fileName);
        } catch (Exception e) {
            logger.error(String.format("导出Coupa发票报告异常:%s",e.getMessage()));
        }
        return null;
    }

    public HttpServletResponse exportRLITList(HttpServletResponse response, RedLetterInfoTableParam param, String fileName) {
        //String excelTemplatePathInClassPath = "/vat_excel_template/cash_flow"+(isEn?"":"_cn") + ".xlsx";
        String excelTemplatePathInClassPath = ExportTemplatePathConstant.RED_LETTER_INFO_TAB;
        RedLetterInfoTableCondition condition = beanUtil.copyProperties(param, new RedLetterInfoTableCondition());
        List<RedLetterInfoTable> datas = redLetterInfoTableMapper.selectByCondition(condition);
        if(datas.size()<1){
            throw new ServiceException(ErrorMessage.ExportFailed);
        }
        List<RedLetterInfoTableDto> dtos = Lists.newArrayList();
        datas.forEach(d -> {
            RedLetterInfoTableDto dto = beanUtil.copyProperties(d, new RedLetterInfoTableDto());
            dtos.add(dto);
        });
        OutputStream outputStream = commonDocumentHelper.toXlsxFileUsingJxls(dtos, excelTemplatePathInClassPath);
        try {
            return responseMessageBuilder.getDownloadTmpResponseMessage(response, outputStream, fileName);
        } catch (Exception e) {
            logger.error(String.format("导出红字信息表异常:%s",e.getMessage()));
        }
        return null;
    }

    public HttpServletResponse exportIDList(HttpServletResponse response, InvoiceDataParam param, String fileName) {
        //String excelTemplatePathInClassPath = "/vat_excel_template/cash_flow"+(isEn?"":"_cn") + ".xlsx";
        String excelTemplatePathInClassPath = ExportTemplatePathConstant.INVOICE_DATA;
        InvoiceDataCondition condition = beanUtil.copyProperties(param, new InvoiceDataCondition());
        List<InvoiceData> datas = invoiceDataMapper.selectByCondition(condition);
        if(datas.size()<1){
            throw new ServiceException(ErrorMessage.ExportFailed);
        }
        List<InvoiceDataDto> dtos = generalIDDtoList();
        generalIDDtoList(datas, dtos);
        OutputStream outputStream = commonDocumentHelper.toXlsxFileUsingJxls(dtos, excelTemplatePathInClassPath);
        try {
            return responseMessageBuilder.getDownloadTmpResponseMessage(response, outputStream, fileName);
        } catch (Exception e) {
            logger.error(String.format("导出发票资料异常:%s",e.getMessage()));
        }
        return null;
    }

513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
    private Map<String, String> generalTBHeader() {
        Map<String, String> header = new LinkedHashMap<>();
        header.put("Date","数据日期");
        header.put("Source","来源");
        header.put("Period","期间");
        header.put("LedgerId","账套ID");
        header.put("LedgerName","账套名称");
        header.put("CurrencyCode","账套币种");
        header.put("Status","关账标识");
        header.put("Category","主体性质");
        header.put("AccountCategory","科目性质");
        header.put("AcctCode1","一级科目代码");

        header.put("AcctName1","一级科目说明");
        header.put("AcctName2","二级科目说明");
        header.put("AcctName3","三级科目说明");
        header.put("Segment1","主体代码");
        header.put("Segment2","成本中心代码");
        header.put("Segment3","科目代码");
        header.put("Segment4","辅助科目代码");
        header.put("Segment5","利润中心代码");
        header.put("Segment6","产品代码");
        header.put("Segment7","项目代码");

        header.put("Segment8","公司间代码");
        header.put("Segment9","备用1代码");
        header.put("Segment10","备用2代码");
        header.put("Segment1Name","主体说明");
        header.put("Segment2Name","成本中心说明");
        header.put("Segment3Name","科目说明");
        header.put("Segment4Name","辅助科目说明");
        header.put("Segment5Name","利润中心说明");
        header.put("Segment6Name","产品说明");
        header.put("Segment7Name","项目说明");

        header.put("Segment8Name","公司间说明");
        header.put("Segment9Name","备用1说明");
        header.put("Segment10Name","备用2说明");
        header.put("BegBal","原币本期期初余额");
        header.put("PeriodDr","原币本期借方发生额");
        header.put("PeriodCr","原币本期贷方发生额");
        header.put("EndBal","原币本期期末余额");
        header.put("QtdDr","原币本季借方发生额");
        header.put("QtdCr","原币本季贷方发生额");
        header.put("YtdDr","原币本年借方发生额");

        header.put("YtdCr","原币本年贷方发生额");
        header.put("BegBalBeq","本位币本期期初余额");
        header.put("PeriodDrBeq","本位币本期借方发生额");
        header.put("PeriodCrBeq","本位币本期贷方发生额");
        header.put("EndBalBeq","本位币本期期末余额");
        header.put("QtdDrBeq","本位币本季借方发生额");
        header.put("QtdCrBeq","本位币本季贷方发生额");
        header.put("YtdDrBeq","本位币本年借方发生额");
        header.put("YtdCrBeq","本位币本年贷方发生额");
        return header;
    }

    private Map<String, String> generalBSHeader() {
        Map<String, String> header = new LinkedHashMap<>();
        header.put("Date","数据日期");
        header.put("Source","来源");
        header.put("Period","期间");
        header.put("Status","关账标识");
        header.put("LedgerId","账套ID");
        header.put("LedgerName","账套名称");
        header.put("LedgerCurrencyCode","账套币种");
        header.put("EntityCode","机构编码");
        header.put("EntityName","机构名称");
        header.put("Category","主体性质");
        header.put("Frequency","频度");
        header.put("ItemName","项目名称");
        header.put("EndBal","期末余额");
        header.put("BegBal","年初余额");
        header.put("PrcFlag","是否为国外");
        return header;
    }



    private Map<String, String> generalPLHeader() {
        Map<String, String> header = new LinkedHashMap<>();
        header.put("Date","数据日期");
        header.put("Source","来源");
        header.put("Period","期间");
        header.put("Status","关账标识");
        header.put("LedgerId","账套ID");
        header.put("LedgerName","账套名称");
        header.put("LedgerCurrencyCode","账套币种");
        header.put("EntityCode","机构编码");
        header.put("EntityName","机构名称");
        header.put("Category","主体性质");

        header.put("Frequency","频度");
        header.put("ItemName","项目名称");
        header.put("PeriodAmt","本期发生额");
        header.put("YtdAmt","本年累计");
        header.put("PrcFlag","是否为国外");
        return header;
    }



    private Map<String, String> generalJEHeader() {
        Map<String, String> header = new LinkedHashMap<>();
        header.put("Date","数据日期");
        header.put("Source","来源");
        header.put("LedgerId","账套ID");
        header.put("LedgerName","账套名称");
        header.put("CurrencyCode","账套币种");
        header.put("Status","关账标识");
        header.put("HeaderId","日记账头ID");
        header.put("LineNum","日记账行号");
        header.put("ApprovalStatus","审批状态");
        header.put("PostedStatus","过账");

        header.put("Period","会计期间");
        header.put("AccountingDate","凭证日期");
        header.put("JournalSource","日记账来源");
        header.put("Category","日记账类别");
        header.put("Name","日记账名称");
        header.put("VoucherNum","凭证编号");
        header.put("Description","摘要");
        header.put("Segment1","主体代码");
        header.put("Segment2","成本中心");
        header.put("Segment3","科目代码");

        header.put("Segment4","辅助科目");
        header.put("Segment5","利润中心");
        header.put("Segment6","产品");
        header.put("Segment7","项目");
        header.put("Segment8","公司间");
        header.put("Segment9","备用1");
        header.put("Segment10","备用2");
        header.put("Segment1Name","主体说明");
        header.put("Segment2Name","成本中心说明");
        header.put("Segment3Name","科目说明");

        header.put("Segment4Name","辅助科目说明");
        header.put("Segment5Name","利润中心说明");
        header.put("Segment6Name","产品说明");
        header.put("Segment7Name","项目说明");
        header.put("Segment8Name","公司间说明");
        header.put("Segment9Name","备用1说明");
        header.put("Segment10Name","备用2说明");
        header.put("JournalCurrencyCode","币种");
        header.put("SobCurrencyCode","本位币币种");
        header.put("AccountedDr","借方金额");

        header.put("AccountedCr","贷方金额");
        header.put("EnteredDr","本位币借方金额");
        header.put("EnteredCr","本位币贷方金额");
        header.put("CfItem","现金流量表项");
        header.put("Attribute1","城市");
        header.put("Attribute2","交易日期");
        header.put("Attribute3","对方银行账号");
        header.put("Attribute4","银行流水号");
        header.put("Attribute5","供应商编号");
        header.put("Attribute6","交易单号");

        header.put("Attribute7","供应商名称");
        header.put("Attribute8","接收编码");
        header.put("Attribute9","制单人");
        header.put("Attribute10","审核人");
        header.put("Attribute11","成本中心部门描述1");
        header.put("Attribute12","成本中心部门描述2");
        header.put("Attribute13","成本中心部门描述3");
        header.put("Attribute14","成本中心部门描述4");
        header.put("Attribute15","成本中心部门描述5");
        header.put("Attribute16","成本中心部门描述6");

        header.put("CreatedBy","创建人");
        header.put("CreatedDate","创建日期");
        header.put("LateUpdatedBy","最后更新人");
        header.put("LateUpdatedDate","最后更新日期");
gary's avatar
gary committed
688
        header.put("tmsPeriod","税务系统期间");
689 690
        return header;
    }
gary's avatar
gary committed
691

gary's avatar
gary committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
    private void generalIDDtoList(List<InvoiceData> invoiceDatas, List<InvoiceDataDto> invoiceDataDtos) {
        if(invoiceDatas.size()>0){
            invoiceDatas.forEach(id -> {
                setIDValue(invoiceDataDtos,"专票正数发票份数",id.getCountType(),id.getSpecialInvoiceAmount1());
                setIDValue(invoiceDataDtos,"专票负数发票份数",id.getCountType(),id.getSpecialInvoiceAmount2());
                setIDValue(invoiceDataDtos,"专票正数废票份数",id.getCountType(),id.getSpecialInvoiceAmount3());
                setIDValue(invoiceDataDtos,"专票负数废票份数",id.getCountType(),id.getSpecialInvoiceAmount4());
                setIDValue(invoiceDataDtos,"专票销项正废金额",id.getCountType(),id.getSpecialInvoiceSalesAmount1());
                setIDValue(invoiceDataDtos,"专票销项正数金额",id.getCountType(),id.getSpecialInvoiceSalesAmount2());
                setIDValue(invoiceDataDtos,"专票销项负废金额",id.getCountType(),id.getSpecialInvoiceSalesAmount3());
                setIDValue(invoiceDataDtos,"专票销项负数金额",id.getCountType(),id.getSpecialInvoiceSalesAmount4());
                setIDValue(invoiceDataDtos,"专票实际销项金额",id.getCountType(),id.getSpecialInvoiceSalesAmount5());
                setIDValue(invoiceDataDtos,"专票销项正废税额",id.getCountType(),id.getSpecialInvoiceTaxAmount1());
                setIDValue(invoiceDataDtos,"专票销项正数税额",id.getCountType(),id.getSpecialInvoiceTaxAmount2());
                setIDValue(invoiceDataDtos,"专票销项负废税额",id.getCountType(),id.getSpecialInvoiceTaxAmount3());
                setIDValue(invoiceDataDtos,"专票销项负数税额",id.getCountType(),id.getSpecialInvoiceTaxAmount4());
                setIDValue(invoiceDataDtos,"专票实际销项税额",id.getCountType(),id.getSpecialInvoiceTaxAmount5());
                setIDValue(invoiceDataDtos,"普票正数发票份数",id.getCountType(),id.getInvoiceAmount1());
                setIDValue(invoiceDataDtos,"普票负数发票份数",id.getCountType(),id.getInvoiceAmount2());
                setIDValue(invoiceDataDtos,"普票正数废票份数",id.getCountType(),id.getInvoiceAmount3());
                setIDValue(invoiceDataDtos,"普票负数废票份数",id.getCountType(),id.getInvoiceAmount4());
                setIDValue(invoiceDataDtos,"普票销项正废金额",id.getCountType(),id.getInvoiceSalesAmount1());
                setIDValue(invoiceDataDtos,"普票销项正数金额",id.getCountType(),id.getInvoiceSalesAmount2());
                setIDValue(invoiceDataDtos,"普票销项负废金额",id.getCountType(),id.getInvoiceSalesAmount3());
                setIDValue(invoiceDataDtos,"普票销项负数金额",id.getCountType(),id.getInvoiceSalesAmount4());
                setIDValue(invoiceDataDtos,"普票实际销项金额",id.getCountType(),id.getInvoiceSalesAmount5());
                setIDValue(invoiceDataDtos,"普票销项正废税额",id.getCountType(),id.getInvoiceTaxAmount1());
                setIDValue(invoiceDataDtos,"普票销项正数税额",id.getCountType(),id.getInvoiceTaxAmount2());
                setIDValue(invoiceDataDtos,"普票销项负废税额",id.getCountType(),id.getInvoiceTaxAmount3());
                setIDValue(invoiceDataDtos,"普票销项负数税额",id.getCountType(),id.getInvoiceTaxAmount4());
                setIDValue(invoiceDataDtos,"普票实际销项税额",id.getCountType(),id.getInvoiceTaxAmount5());
            });
        }
    }
gary's avatar
gary committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802

    private List<InvoiceDataDto> generalIDDtoList() {
        List<InvoiceDataDto> invoiceDataDtos = Lists.newArrayList();
        invoiceDataDtos.add(new InvoiceDataDto("专票正数发票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("专票负数发票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("专票正数废票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("专票负数废票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("专票销项正废金额"));

        invoiceDataDtos.add(new InvoiceDataDto("专票销项正数金额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票销项负废金额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票销项负数金额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票实际销项金额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票销项正废税额"));

        invoiceDataDtos.add(new InvoiceDataDto("专票销项正数税额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票销项负废税额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票销项负数税额"));
        invoiceDataDtos.add(new InvoiceDataDto("专票实际销项税额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票正数发票份数"));

        invoiceDataDtos.add(new InvoiceDataDto("普票负数发票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("普票正数废票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("普票负数废票份数"));
        invoiceDataDtos.add(new InvoiceDataDto("普票销项正废金额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票销项正数金额"));

        invoiceDataDtos.add(new InvoiceDataDto("普票销项负废金额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票销项负数金额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票实际销项金额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票销项正废税额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票销项正数税额"));

        invoiceDataDtos.add(new InvoiceDataDto("普票销项负废税额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票销项负数税额"));
        invoiceDataDtos.add(new InvoiceDataDto("普票实际销项税额"));
        return invoiceDataDtos;
    }

    private void setIDValue(List<InvoiceDataDto> idDtos, String column, Integer row, Object value) {
        for(InvoiceDataDto idto : idDtos){
            if(idto.getProjectName().equals(column)){
                switch (row) {
                    case CountTypeConstant.TOTAL:
                        idto.setTotalAmount(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.SIXTEEN_PERCENT:
                        idto.setAmount1(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.TEN_PERCENT:
                        idto.setAmount2(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.SIX_PERCENT:
                        idto.setAmount3(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.THREE_PERCENT:
                        idto.setAmount4(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.SEVENTEEN_PERCENT:
                        idto.setAmount5(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.ELEVEN_PERCENT:
                        idto.setAmount6(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.FIVE_PERCENT:
                        idto.setAmount7(new BigDecimal (value.toString()));
                        break;
                    case CountTypeConstant.OTHER:
                        idto.setOtherAmount(new BigDecimal (value.toString()));
                        break;
                    default:
                        break;
                }
                break;
            }
        }
    }
gary's avatar
gary committed
803
}