TemplateGroupController.java 7.5 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;
10 11 12 13 14 15 16
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
eddie.woo's avatar
eddie.woo committed
17 18
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.message.ErrorMessage;
19
import pwc.taxtech.atms.dto.OperationResultDto;
frank.xa.zhang's avatar
frank.xa.zhang committed
20
import pwc.taxtech.atms.dto.TemplateGroupDto;
21
import pwc.taxtech.atms.exception.ServiceException;
eddie.woo's avatar
eddie.woo committed
22
import pwc.taxtech.atms.service.impl.HttpFileService;
23
import pwc.taxtech.atms.service.impl.TemplateGroupServiceImpl;
24

frank.xa.zhang's avatar
frank.xa.zhang committed
25 26
import java.util.List;

27 28 29
@RestController
@RequestMapping("/api/v1/templateGroup/")
public class TemplateGroupController {
frank.xa.zhang's avatar
frank.xa.zhang committed
30 31 32
    private static final Logger logger = LoggerFactory.getLogger(TemplateGroupController.class);

    @Autowired
33
    TemplateGroupServiceImpl templateGroupService;
frank.xa.zhang's avatar
frank.xa.zhang committed
34

35
    @Autowired
eddie.woo's avatar
eddie.woo committed
36
    private HttpFileService httpFileService;
37

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

frank.xa.zhang's avatar
frank.xa.zhang committed
46
    @ApiOperation(value = "根据服务类型和行业获取模板分组")
47
    @RequestMapping(value = "getByIndustry/{serviceTypeId}/{industryId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
frank.xa.zhang's avatar
frank.xa.zhang committed
48
    public @ResponseBody
49 50
    List<TemplateGroupDto> getTemplateGroupByIndustry(@PathVariable int serviceTypeId, @RequestParam Integer taxPayType, @PathVariable String industryId) {
        return templateGroupService.get(serviceTypeId, taxPayType, industryId);
frank.xa.zhang's avatar
frank.xa.zhang committed
51
    }
52

53 54
    @RequestMapping(value = "updateTemplateGroupName", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody
55
    OperationResultDto<Object> updateTemplateGroupName(@RequestBody TemplateGroupDto templateGroupDto) {
56 57 58
        return templateGroupService.updateTemplateGroupName(templateGroupDto);
    }

59 60
    @RequestMapping(value = "deleteTemplateGroup", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody
61
    OperationResultDto<Object> deleteTemplateGroup(@RequestBody TemplateGroupDto templateGroupDto) {
62 63 64 65
        OperationResultDto<Object> result = templateGroupService.deleteTemplateGroup(templateGroupDto);
        if (result.getResult()) {
            List<String> pathList = (List<String>) result.getData();
            if (pathList != null && pathList.size() > 0) {
66
                for (String path : pathList) {
67
                    try {
eddie.woo's avatar
eddie.woo committed
68 69
                        //todo
                        //httpFileService.delete(path);
70
                    } catch (Exception e) {
71 72 73 74 75 76
                    }
                }
            }
        }
        return result;
    }
77

eddie.woo's avatar
eddie.woo committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    @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,
100
                                                           @RequestParam Boolean allowManual,
eddie.woo's avatar
eddie.woo committed
101 102 103 104 105 106 107 108 109 110
                                                           @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);
            }
111 112
            if(allowManual == null) allowManual = Boolean.FALSE;
            templateGroupService.importTemplateGroupExcelFile(file, allowManual, templateGroupDto);
eddie.woo's avatar
eddie.woo committed
113 114 115 116 117 118 119 120 121
            return OperationResultDto.success();
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importTemplateGroupExcelFile error.", e);
        }
        return OperationResultDto.error(ErrorMessage.SystemError);
    }

122

eddie.woo's avatar
eddie.woo committed
123 124 125 126
    @ResponseBody
    @ApiOperation(value = "导入报表")
    @RequestMapping(value = "importTemplateExcelFile", method = RequestMethod.POST)
    public OperationResultDto importTemplateExcelFile(@RequestParam MultipartFile file,
sherlock's avatar
sherlock committed
127
                                                      @RequestParam Long templateGroupID,
eddie.woo's avatar
eddie.woo committed
128
                                                      @RequestParam String sheetList,
129
                                                      @RequestParam Boolean allowManual,
eddie.woo's avatar
eddie.woo committed
130 131 132 133
                                                      @RequestParam String tempFileName,
                                                      @RequestParam String reportType,
                                                      @RequestParam String filename) {
        try {
134 135
            if(allowManual == null) allowManual = Boolean.FALSE;
            templateGroupService.importTemplateExcelFile(file, allowManual, templateGroupID, reportType, sheetList);
eddie.woo's avatar
eddie.woo committed
136 137 138 139 140 141 142 143 144
            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
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    @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);
    }

160
}