package cn.com.capcloud.api;

import cn.com.capcloud.api.action.ApiImportExportAction;
import cn.com.capcloud.api.action.service.ExecuteService;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;

@CrossOrigin//支持跨域请求
@RestController
@RequestMapping("/api/data")
public class ApiImportExportController {

    @Autowired
    private ApiImportExportAction apiImportExportAction;
    @Autowired
    private ExecuteService executeService;

    @RequestMapping("/importExcelDataNew")
    public KHCResponseEntity importExcelDataNew(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.importExcelDataNew(jsonStr, request), false);
    }

    @RequestMapping("/importJsonData")
    public KHCResponseEntity importJsonData(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.importJsonData(jsonStr, request), false);
    }

    @RequestMapping("/updateJsonData")
    public KHCResponseEntity updateJsonData(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.updateJsonData(jsonStr, request), false);
    }

    @RequestMapping("/exportWordData")
    public KHCResponseEntity exportWordData(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.exportWordData(jsonStr, request), false);
    }

    @RequestMapping("/exportExcelData")
    public KHCResponseEntity exportExcelData(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.exportExcelData(jsonStr, request), false);
    }

    @RequestMapping("/exportExcelOneData")
    public KHCResponseEntity exportExcelOneData(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.exportExcelOneData(jsonStr, request), false);
    }

    @RequestMapping("/exportExcelTemplate")
    public KHCResponseEntity exportExcelTemplate(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.exportExcelTemplate(jsonStr, request), false);
    }

    @RequestMapping("/createOnePdf")
    public KHCResponseEntity createOnePdf(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiImportExportAction.createOnePdf(jsonStr, request), false);
    }

}
