package com.unis.crk.common.controller;

import com.unis.crk.common.service.IDataCenterUploadService;
import com.unis.crk.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Api(value = "数据中心上传",tags = {"数据中心上传"})
@RestController
@RequestMapping("dataCenterUpload")
public class DataCenterUploadController {

    @Autowired
    private IDataCenterUploadService dataCenterUploadService;

    @ApiOperation(value="查询", notes="查询")
    @GetMapping("getome/{unitId}/{topic}/{tableNames}")
    public ResultUtil getScpc(@PathVariable("unitId") String unitId,@PathVariable("topic") String topic,@PathVariable(value = "tableNames",required = false) String tableNames){
        ResultUtil data = new ResultUtil();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的单位id为空");
            return data;
        }
        data.success(this.dataCenterUploadService.uploadSjzxData(unitId,topic,tableNames));
        return data;
    }
    @ApiOperation(value="删除", notes="删除")
    @GetMapping("del/{unitId}/{topic}")
    public ResultUtil del(@PathVariable("unitId") String unitId,@PathVariable("topic") String topic){
        ResultUtil data = new ResultUtil();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的单位id为空");
            return data;
        }
        data.success(this.dataCenterUploadService.deleteSjzxData(unitId,topic));
        return data;
    }
    @ApiOperation(value="查询", notes="查询")
    @GetMapping("getome/{unitId}")
    public ResultUtil getScpc(@PathVariable("unitId") String unitId){
        ResultUtil data = new ResultUtil();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的单位id为空");
            return data;
        }
        data.success(this.dataCenterUploadService.uploadSjzxData(unitId,"",""));
        return data;
    }
    @ApiOperation(value="查询", notes="查询")
    @GetMapping("test/{unitId}")
    public ResultUtil test(@PathVariable("unitId") String unitId){
        ResultUtil data = new ResultUtil();
        if (StringUtils.isEmpty(unitId)){
            data.failed("传入的单位id为空");
            return data;
        }
        data.success(this.dataCenterUploadService.test(unitId));
        return data;
    }


}
