DataImportController.java 11.9 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2
package pwc.taxtech.atms.controller;

gary's avatar
gary committed
3
import com.alibaba.fastjson.JSONArray;
4
import org.apache.commons.lang3.StringUtils;
gary's avatar
gary committed
5
import org.springframework.web.bind.annotation.*;
6
import com.google.common.collect.Lists;
gary's avatar
gary committed
7 8
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.message.ErrorMessage;
eddie.woo's avatar
eddie.woo committed
9
import pwc.taxtech.atms.dpo.PagingDto;
gary's avatar
gary committed
10 11 12
import pwc.taxtech.atms.dto.*;
import pwc.taxtech.atms.dto.dataimport.DataImportParam;
import pwc.taxtech.atms.dto.input.CamelPagingResultDto;
eddie.woo's avatar
eddie.woo committed
13 14
import pwc.taxtech.atms.dto.vatdto.TrialBalanceDto;
import pwc.taxtech.atms.dto.vatdto.TrialBalanceParam;
gary's avatar
gary committed
15
import pwc.taxtech.atms.exception.ServiceException;
eddie.woo's avatar
eddie.woo committed
16
import pwc.taxtech.atms.service.impl.DataImportService;
eddie.woo's avatar
eddie.woo committed
17
import pwc.taxtech.atms.service.impl.LgGlBalanceService;
eddie.woo's avatar
eddie.woo committed
18 19

import javax.annotation.Resource;
eddie.woo's avatar
eddie.woo committed
20
import java.util.List;
eddie.woo's avatar
eddie.woo committed
21 22 23

@RestController
@RequestMapping("/api/v1/DataImport/")
eddie.woo's avatar
eddie.woo committed
24
public class DataImportController extends BaseController {
eddie.woo's avatar
eddie.woo committed
25 26 27

    @Resource
    private DataImportService dataImportService;
eddie.woo's avatar
eddie.woo committed
28 29
    @Resource
    private LgGlBalanceService lgGlBalanceService;
eddie.woo's avatar
eddie.woo committed
30 31

    @PostMapping("GetBalanceDataForDisplay")
eddie.woo's avatar
eddie.woo committed
32
    public PagingResultDto<TrialBalanceDto> getBalanceDataForDisplay(@RequestBody TrialBalanceParam param) {
eddie.woo's avatar
eddie.woo committed
33
        PagingResultDto<TrialBalanceDto> resultDto = new PagingResultDto<>();
eddie.woo's avatar
eddie.woo committed
34 35 36 37 38
        List<TrialBalanceDto> list = dataImportService.getBalanceDataForDisplay(param);
        PagingDto pagingDto = new PagingDto();
//        pagingDto.setPageIndex(1);
//        pagingDto.setPageSize(100);
//        pagingDto.setTotalCount(list);
eddie.woo's avatar
eddie.woo committed
39
        resultDto.setPageInfo(pagingDto);
eddie.woo's avatar
eddie.woo committed
40 41
        resultDto.setList(list);
        resultDto.setCalculateData(dataImportService.calculateData(list));
eddie.woo's avatar
eddie.woo committed
42 43 44 45 46 47
        return resultDto;
    }

    @PostMapping("queryGlBalance")
    public ApiResultDto queryGlBalance(@RequestBody TrialBalanceParam param) {
        ApiResultDto resultDto = new ApiResultDto();
48
        lgGlBalanceService.queryGlBalance(param.getOrgId(), param.getPeriodStart(), param.getPeriodEnd());
eddie.woo's avatar
eddie.woo committed
49
        return resultDto;
eddie.woo's avatar
eddie.woo committed
50
    }
gary's avatar
gary committed
51 52 53

    @ResponseBody
    @RequestMapping(value = "PLExcelFile", method = RequestMethod.POST)
54
    public OperationResultDto importPLExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
gary's avatar
gary committed
55
        try {
56 57 58 59 60
            // 这里可以写aop简化代码,我没时间先不写了:)
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
gary's avatar
gary committed
61
            }
62
            return dataImportService.importPLExcelFile(file, orgList,periodDate,importType);
gary's avatar
gary committed
63 64 65
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
66 67
            logger.error("importPLExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
gary's avatar
gary committed
68 69 70 71 72
        }
    }

    @ResponseBody
    @RequestMapping(value = "BSExcelFile", method = RequestMethod.POST)
73
    public OperationResultDto importBSExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
gary's avatar
gary committed
74
        try {
75 76 77 78
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
gary's avatar
gary committed
79
            }
80
            return dataImportService.importBSExcelFile(file,orgList, periodDate,importType);
gary's avatar
gary committed
81 82 83
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
84 85 86 87 88 89 90
            logger.error("importBSExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

    @ResponseBody
    @RequestMapping(value = "RLITExcelFile", method = RequestMethod.POST)
gary's avatar
gary committed
91
    public OperationResultDto importRLITExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
92
        try {
gary's avatar
gary committed
93
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
94 95 96 97
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
            }
gary's avatar
gary committed
98
            return dataImportService.importRLITExcelFile(file,orgList, periodDate,importType);
99 100 101 102 103 104 105 106 107 108
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importRLITExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

    @ResponseBody
    @RequestMapping(value = "ATExcelFile", method = RequestMethod.POST)
gary's avatar
gary committed
109
    public OperationResultDto importATExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
110
        try {
gary's avatar
gary committed
111
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
112 113 114 115
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
            }
gary's avatar
gary committed
116
            return dataImportService.importATExcelFile(file, orgList,periodDate,importType);
117 118 119 120 121
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importATExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
gary's avatar
gary committed
122 123 124
        }
    }

gary's avatar
gary committed
125 126
    @ResponseBody
    @RequestMapping(value = "CFExcelFile", method = RequestMethod.POST)
127
    public OperationResultDto importCFExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
gary's avatar
gary committed
128
        try {
129 130 131 132
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
gary's avatar
gary committed
133
            }
134
            return dataImportService.importCFExcelFile(file,orgList, periodDate,importType);
gary's avatar
gary committed
135 136 137
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
138
            logger.error("importCFExcelFile error.", e);
gary's avatar
gary committed
139 140 141 142 143 144
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

    @ResponseBody
    @RequestMapping(value = "CPRExcelFile", method = RequestMethod.POST)
gary's avatar
gary committed
145
    public OperationResultDto importCPRExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
gary's avatar
gary committed
146
        try {
gary's avatar
gary committed
147
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
148 149 150 151
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
            }
gary's avatar
gary committed
152
            return dataImportService.importCPRExcelFile(file,orgList, periodDate,importType);
gary's avatar
gary committed
153 154 155 156 157 158 159 160
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importATExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

161 162
    @ResponseBody
    @RequestMapping(value = "IDExcelFile", method = RequestMethod.POST)
163
    public OperationResultDto importIDExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
164
        try {
165 166 167 168
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
169
            }
170
            return dataImportService.importIDExcelFile(file,orgList, periodDate,importType);
171 172 173 174 175 176 177 178
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importIDExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

gary's avatar
gary committed
179 180 181 182 183
    @ResponseBody
    @RequestMapping(value = "IRExcelFile", method = RequestMethod.POST)
    public OperationResultDto importIRExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
        try {
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
184 185 186 187
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
            }
gary's avatar
gary committed
188 189 190 191 192 193 194 195 196 197 198
            return dataImportService.importIRExcelFile(file,orgList, periodDate,importType);
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importIRExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

    @ResponseBody
    @RequestMapping(value = "CILExcelFile", method = RequestMethod.POST)
199
    public OperationResultDto importCILExcelFile(@RequestParam MultipartFile file,@RequestParam String orgIds,@RequestParam String periodDate,@RequestParam Integer importType) {
gary's avatar
gary committed
200
        try {
201 202 203 204
            List<String> orgList = (List<String>)JSONArray.parse(orgIds);
            String valMsg = valParameter(file,orgList,periodDate);
            if(StringUtils.isNotEmpty(valMsg)){
                return OperationResultDto.error(valMsg);
gary's avatar
gary committed
205
            }
206
            return dataImportService.importCILExcelFile(file,orgList, periodDate,importType);
gary's avatar
gary committed
207 208 209 210 211 212 213 214
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importCILExcelFile error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

gary's avatar
gary committed
215
    @ResponseBody
gary's avatar
gary committed
216 217 218 219 220 221 222 223
    @RequestMapping(value = "displayImportLog", method = RequestMethod.POST)
    public CamelPagingResultDto<DataImportLogDto> displayImportLog(@RequestBody DataImportParam param) {
        return new CamelPagingResultDto<>(dataImportService.displayImportLog(param));
    }

    @ResponseBody
    @RequestMapping(value = "callExtractFinancialData", method = RequestMethod.POST)
    public OperationResultDto callExtractFinancialData(@RequestBody DataExtractParam dataExtractParam) {
gary's avatar
gary committed
224
        try {
gary's avatar
gary committed
225 226 227
            return dataImportService.callExtractFinancialData(dataExtractParam);
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
gary's avatar
gary committed
228
        } catch (Exception e) {
gary's avatar
gary committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
            logger.error("callExtractFinancialData error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
        }
    }

    @ResponseBody
    @RequestMapping(value = "callExtractInvoiceData", method = RequestMethod.POST)
    public OperationResultDto callExtractInvoiceData(@RequestBody DataExtractParam dataExtractParam) {
        try {
            return dataImportService.callExtractInvoiceData(dataExtractParam);
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("callExtractInvoiceData error.", e);
            return OperationResultDto.error(ErrorMessage.SystemError);
gary's avatar
gary committed
244 245
        }
    }
246 247 248 249 250 251 252 253 254 255 256 257 258

    private String valParameter(MultipartFile file,List<String> orgList,String periodDate){
        if (null == file) {
            return ErrorMessage.NoFile;
        }
        if(orgList.size()<1){
            return ErrorMessage.DidntSelectedCompany;
        }
        if(StringUtils.isEmpty(periodDate)){
            return ErrorMessage.DidntSelectedPeriod;
        }
        return null;
    }
eddie.woo's avatar
eddie.woo committed
259
}