CellTemplateController.java 2.6 KB
Newer Older
1 2 3 4 5 6
package pwc.taxtech.atms.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
7 8 9 10 11 12
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
13
import pwc.taxtech.atms.dto.CellTemplateConfigDto;
14
import pwc.taxtech.atms.dto.OperationResultDto;
15
import pwc.taxtech.atms.service.impl.CellTemplateServiceImpl;
16 17 18 19 20 21

import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping(value = "api/v1/celltemplate")
22
public class CellTemplateController extends BaseController {
23 24
    private static final Logger logger = LoggerFactory.getLogger(AccountController.class);
    @Autowired
25
    CellTemplateServiceImpl cellTemplateService;
26

27
    @RequestMapping(value = "configList/{templateId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
28
    public @ResponseBody
29
    OperationResultDto<List<CellTemplateConfigDto>> getConfigList(@PathVariable Long templateId) {
30 31
        OperationResultDto<List<CellTemplateConfigDto>> result = new OperationResultDto<>();

32
        if (!isParamValid(templateId)) {
33 34 35 36
            result.setData(Collections.emptyList());
        }

        try {
37
            return cellTemplateService.getCellConfigList(templateId);
38 39 40 41 42 43 44
        } catch (Exception e) {
            logger.error("CellTemplateController.GetCellConfigList", e);
        }

        return result;
    }

45
    @RequestMapping(value = "config/{cellTemplateId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
46
    public @ResponseBody
47 48
    OperationResultDto<CellTemplateConfigDto> getConfig(@PathVariable Long cellTemplateId) {
        if (!isParamValid(cellTemplateId)) {
49
            return new OperationResultDto<>();
50 51 52
        }

        try {
53
            return cellTemplateService.getCellConfig(cellTemplateId);
54
        } catch (Exception e) {
55
            logger.error("CellTemplateController.GetConfig", e);
56 57
        }

58
        return new OperationResultDto<>();
59
    }
60

61
    @RequestMapping(value = "config", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
62
    public @ResponseBody
63
    OperationResultDto postConfig(@RequestBody CellTemplateConfigDto cellTemplateConfigDto) {
64 65
        return cellTemplateService.saveOrEdit(cellTemplateConfigDto);
    }
66
}