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

eddie.woo's avatar
eddie.woo committed
3 4
import com.alibaba.fastjson.JSON;
import org.apache.commons.collections.CollectionUtils;
5 6 7 8
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
9 10 11 12 13 14 15
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
16 17
import org.springframework.web.multipart.MultipartFile;
import pwc.taxtech.atms.common.message.ErrorMessage;
18
import pwc.taxtech.atms.dto.OperationResultDto;
frank.xa.zhang's avatar
frank.xa.zhang committed
19
import pwc.taxtech.atms.dto.TemplateGroupDto;
20
import pwc.taxtech.atms.exception.ServiceException;
eddie.woo's avatar
eddie.woo committed
21
import pwc.taxtech.atms.service.impl.HttpFileService;
22
import pwc.taxtech.atms.service.impl.TemplateGroupServiceImpl;
23

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

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

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

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

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

gary's avatar
gary committed
45
//    @ApiOperation(value = "根据服务类型和行业获取模板分组")
46
    @RequestMapping(value = "getByIndustry/{serviceTypeId}/{industryId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
frank.xa.zhang's avatar
frank.xa.zhang committed
47
    public @ResponseBody
48 49
    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
50
    }
51

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

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

eddie.woo's avatar
eddie.woo committed
77
    @ResponseBody
gary's avatar
gary committed
78
//    @ApiOperation(value = "获取Sheet名称")
eddie.woo's avatar
eddie.woo committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    @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
gary's avatar
gary committed
95
//    @ApiOperation(value = "导入模板")
eddie.woo's avatar
eddie.woo committed
96 97 98
    @RequestMapping(value = "importTemplateGroupExcelFile", method = RequestMethod.POST)
    public OperationResultDto importTemplateGroupExcelFile(@RequestParam MultipartFile file,
                                                           @RequestParam String filename,
99
                                                           @RequestParam Boolean allowManual,
eddie.woo's avatar
eddie.woo committed
100 101 102 103 104 105 106 107 108 109
                                                           @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);
            }
110 111
            if(allowManual == null) allowManual = Boolean.FALSE;
            templateGroupService.importTemplateGroupExcelFile(file, allowManual, templateGroupDto);
eddie.woo's avatar
eddie.woo committed
112 113 114 115 116 117 118 119 120
            return OperationResultDto.success();
        } catch (ServiceException e) {
            return OperationResultDto.error(e.getMessage());
        } catch (Exception e) {
            logger.error("importTemplateGroupExcelFile error.", e);
        }
        return OperationResultDto.error(ErrorMessage.SystemError);
    }

121

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

159
}