TemplateGroupController.java 6.75 KB
Newer Older
1 2
package pwc.taxtech.atms.controller;

eddie.woo's avatar
eddie.woo committed
3
import com.alibaba.fastjson.JSON;
frank.xa.zhang's avatar
frank.xa.zhang committed
4
import io.swagger.annotations.ApiOperation;
eddie.woo's avatar
eddie.woo committed
5
import org.apache.commons.collections.CollectionUtils;
6 7 8 9
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
frank.xa.zhang's avatar
frank.xa.zhang committed
10
import org.springframework.web.bind.annotation.*;
eddie.woo's avatar
eddie.woo committed
11
import org.springframework.web.multipart.MultipartFile;
12
import pwc.taxtech.atms.exception.ServiceException;
13
import pwc.taxtech.atms.common.ftp.FTPClientPool;
eddie.woo's avatar
eddie.woo committed
14
import pwc.taxtech.atms.common.message.ErrorMessage;
15
import pwc.taxtech.atms.dto.OperationResultDto;
frank.xa.zhang's avatar
frank.xa.zhang committed
16
import pwc.taxtech.atms.dto.TemplateGroupDto;
17 18
import pwc.taxtech.atms.service.TemplateGroupService;

frank.xa.zhang's avatar
frank.xa.zhang committed
19 20
import java.util.List;

21 22 23
@RestController
@RequestMapping("/api/v1/templateGroup/")
public class TemplateGroupController {
frank.xa.zhang's avatar
frank.xa.zhang committed
24 25 26 27 28
    private static final Logger logger = LoggerFactory.getLogger(TemplateGroupController.class);

    @Autowired
    TemplateGroupService templateGroupService;

29 30 31
    @Autowired
    FTPClientPool ftpClientPool;

frank.xa.zhang's avatar
frank.xa.zhang committed
32 33 34
    @ApiOperation(value = "获取所有的模板分组")
    @RequestMapping(value = "getall", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody
35
    List<TemplateGroupDto> get() {
frank.xa.zhang's avatar
frank.xa.zhang committed
36
        logger.debug("TemplateGroupController Get");
37
        return templateGroupService.get();
frank.xa.zhang's avatar
frank.xa.zhang committed
38
    }
39

frank.xa.zhang's avatar
frank.xa.zhang committed
40
    @ApiOperation(value = "根据服务类型和行业获取模板分组")
41
    @RequestMapping(value = "getByIndustry/{serviceTypeID}/{industryID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
frank.xa.zhang's avatar
frank.xa.zhang committed
42 43
    public @ResponseBody
    List<TemplateGroupDto> getTemplateGroupByIndustry(@PathVariable int serviceTypeID, @RequestParam Integer taxPayType, @PathVariable String industryID) {
44
        return templateGroupService.get(serviceTypeID, taxPayType, industryID);
frank.xa.zhang's avatar
frank.xa.zhang committed
45
    }
46

47 48
    @RequestMapping(value = "updateTemplateGroupName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody
49
    OperationResultDto<Object> updateTemplateGroupName(@RequestBody TemplateGroupDto templateGroupDto) {
50 51 52
        return templateGroupService.updateTemplateGroupName(templateGroupDto);
    }

53 54
    @RequestMapping(value = "deleteTemplateGroup", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody
55
    OperationResultDto<Object> deleteTemplateGroup(@RequestBody TemplateGroupDto templateGroupDto) {
56 57 58 59 60 61
        OperationResultDto<Object> result = templateGroupService.deleteTemplateGroup(templateGroupDto);
        if (result.getResult()) {
            List<String> pathList = (List<String>) result.getData();
            if (pathList != null && pathList.size() > 0) {
                for(String path:pathList){
                    try {
62
                        ftpClientPool.delete(path);
63 64 65 66 67 68 69 70
                    }
                    catch(Exception e){
                    }
                }
            }
        }
        return result;
    }
eddie.woo's avatar
eddie.woo committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    @ResponseBody
    @ApiOperation(value = "获取Sheet名称")
    @RequestMapping(value = "getSheetNameList", method = RequestMethod.POST)
    public OperationResultDto getSheetNameList(@RequestParam MultipartFile file,
                                               @RequestParam String filename,
                                               @RequestParam String tempFileName) {
        try {
            if (null == file) {
                return OperationResultDto.error(ErrorMessage.NoFile);
            }
            return OperationResultDto.success(templateGroupService.getSheetNameList(file));
        } catch (Exception e) {
            logger.error("getSheetNameList error.", e);
        }
        return OperationResultDto.error();
    }

    @ResponseBody
    @ApiOperation(value = "导入模板")
    @RequestMapping(value = "importTemplateGroupExcelFile", method = RequestMethod.POST)
    public OperationResultDto importTemplateGroupExcelFile(@RequestParam MultipartFile file,
                                                           @RequestParam String filename,
                                                           @RequestParam String tempFileName,
                                                           @RequestParam String jsonModel) {
        try {
            if (null == file) {
                return OperationResultDto.error(ErrorMessage.NoFile);
            }
            TemplateGroupDto templateGroupDto = JSON.parseObject(jsonModel, TemplateGroupDto.class);
            if (CollectionUtils.isEmpty(templateGroupDto.getSheetNameList())) {
                return OperationResultDto.error(ErrorMessage.NoSelectSheet);
            }
            templateGroupService.importTemplateGroupExcelFile(file, templateGroupDto);
            return OperationResultDto.success();
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importTemplateGroupExcelFile error.", e);
        }
        return OperationResultDto.error(ErrorMessage.SystemError);
    }

    @ResponseBody
    @ApiOperation(value = "导入报表")
    @RequestMapping(value = "importTemplateExcelFile", method = RequestMethod.POST)
    public OperationResultDto importTemplateExcelFile(@RequestParam MultipartFile file,
117
                                                      @RequestParam Long templateGroupID,
eddie.woo's avatar
eddie.woo committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
                                                      @RequestParam String sheetList,
                                                      @RequestParam String tempFileName,
                                                      @RequestParam String reportType,
                                                      @RequestParam String filename) {
        try {
            templateGroupService.importTemplateExcelFile(file, templateGroupID, reportType, sheetList);
            return OperationResultDto.success();
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importTemplateExcelFile error.", e);
        }
        return OperationResultDto.error(ErrorMessage.SystemError);
    }

eddie.woo's avatar
eddie.woo committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    @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);
    }

148
}