AnalysisController.java 5.46 KB
Newer Older
gary's avatar
gary committed
1
package pwc.taxtech.atms.controller;
gary's avatar
gary committed
2 3 4

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.http.MediaType;
gary's avatar
gary committed
6 7 8 9 10 11
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.message.ErrorMessage;
import pwc.taxtech.atms.controller.BaseController;
import pwc.taxtech.atms.dto.ApiResultDto;
import pwc.taxtech.atms.dto.OperationResultDto;
12
import pwc.taxtech.atms.dto.analysis.AnalysisDomesticlParam;
gary's avatar
gary committed
13
import pwc.taxtech.atms.dto.analysis.AnalysisInternationlParam;
14
import pwc.taxtech.atms.dto.vatdto.CertifiedInvoicesListParam;
gary's avatar
gary committed
15 16 17
import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.service.impl.AnalysisServiceImpl;

18
import javax.servlet.http.HttpServletResponse;
gary's avatar
gary committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import java.util.List;

/**
 * @Auther: Gary J Li
 * @Date: 14/03/2019 11:29
 * @Description:
 */
@RestController
@RequestMapping("/api/v1/Analysis/")
public class AnalysisController extends BaseController {

    @Autowired
    private AnalysisServiceImpl analysisServiceImpl;

    @ResponseBody
gary's avatar
gary committed
34 35
    @RequestMapping(value = "displayAnalysisImportData", method = RequestMethod.POST)
    public ApiResultDto displayAnalysisImportData(@RequestBody AnalysisDomesticlParam param) {
gary's avatar
gary committed
36
        try{
gary's avatar
gary committed
37
            return ApiResultDto.success(analysisServiceImpl.displayAnalysisImportData(param));
gary's avatar
gary committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
        }catch (Exception e){
            return ApiResultDto.fail();
        }
    }

    @ResponseBody
    @RequestMapping(value = "displayAnalysisInternationalImportData", method = RequestMethod.POST)
    public ApiResultDto displayAnalysisInternationalImportData(@RequestBody AnalysisInternationlParam param) {
        try{
            return ApiResultDto.success(analysisServiceImpl.displayAnalysisInternationalImportData(param));
        }catch (Exception e){
            return ApiResultDto.fail();
        }
    }

53
    @RequestMapping(value = "downloadDomesticFile/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
gary's avatar
gary committed
54
    public void downloadDomesticFile(@RequestBody AnalysisDomesticlParam param, HttpServletResponse response) {
55 56 57 58 59
        logger.debug("enter downloadDomesticFile");
        String fileName="testFile";
        analysisServiceImpl.downloadDomesticFile(response, param, fileName);
    }

gary's avatar
gary committed
60 61 62 63 64 65 66
    @RequestMapping(value = "downloadInternationalFile/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void downloadInternationalFile(@RequestBody AnalysisInternationlParam param, HttpServletResponse response) {
        logger.debug("enter downloadInternationalFile");
        String fileName="testFile";
        analysisServiceImpl.downloadInternationalFile(response, param, fileName);
    }

67

gary's avatar
gary committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81
    @ResponseBody
    @RequestMapping(value = "getAnalysisInternationalCompanyList", method = RequestMethod.GET)
    public List<String> getAnalysisInternationalCompanyList(@RequestParam Integer type, @RequestParam String period) {
        return analysisServiceImpl.getAnalysisInternationalCompanyList(type,period);
    }

    @ResponseBody
    @RequestMapping(value = "getAnalysisInternationalCountryList", method = RequestMethod.GET)
    public List<String> getAnalysisInternationalCountryList(@RequestParam Integer type, @RequestParam String period) {
        return analysisServiceImpl.getAnalysisInternationalCountryList(type,period);
    }

    @ResponseBody
    @RequestMapping(value = "DomesitcExcelFile", method = RequestMethod.POST)
gary's avatar
gary committed
82
    public OperationResultDto importDomesitcExcelFile(@RequestParam MultipartFile file, @RequestParam String period, @RequestParam Integer type) {
gary's avatar
gary committed
83 84 85 86 87
        try {
            String valMsg = valParameter(file,period,type);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
            }
gary's avatar
gary committed
88
            return analysisServiceImpl.importDomesitcExcelFile(file,period, type);
gary's avatar
gary committed
89 90 91 92 93 94 95 96
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importDomesitcExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    @ResponseBody
    @RequestMapping(value = "InternationalExcelFile", method = RequestMethod.POST)
    public OperationResultDto importDomesitcExcelFile(@RequestParam MultipartFile file, @RequestParam String period,
                                                      @RequestParam Integer type,@RequestParam String companyName,@RequestParam String country) {
        try {
            String valMsg = valParameter(file,period,type);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
            }
            return analysisServiceImpl.importInterNationalExcelFile(file,period, type,companyName,country);
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importDomesitcExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

gary's avatar
gary committed
115 116 117 118 119 120 121 122 123 124 125 126 127
    private String valParameter(MultipartFile file,String periodDate,Integer type){
        if (null == file) {
            return ErrorMessage.NoFile;
        }
        if(StringUtils.isEmpty(periodDate)){
            return ErrorMessage.DidntSelectedPeriod;
        }
        if(null==type){
            return ErrorMessage.DidntSelectedImportType;
        }
        return null;
    }
}