///**
// *
// */
//package org.springblade.etl.controller.bi;
//
//import java.util.List;
//
//import org.springblade.core.boot.ctrl.BladeController;
//import org.springblade.core.tool.api.R;
//import org.springblade.etl.dto.DataApiInsertParamDTO;
//import org.springblade.etl.entity.DataApi;
//import org.springblade.etl.entity.ReportDatasource;
//import org.springblade.etl.service.DataApiInsertService;
//import org.springblade.etl.service.DataApiService;
//import org.springblade.etl.service.ReportDatasourceService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RestController;
//
//import com.alibaba.fastjson2.JSON;
//import com.alibaba.fastjson2.JSONObject;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//
//import io.swagger.annotations.ApiOperation;
//import springfox.documentation.annotations.ApiIgnore;
//
///**
// * @author wookvn
// *
// */
//@ApiIgnore
//@RestController
//public class DataApiInsertController extends BladeController {
//
//	@Autowired
//	private DataApiService dataApiService;
//
//	@Autowired
//	private ReportDatasourceService reportDatasourceService;
//
//	@Autowired
//	private DataApiInsertService dataApiInsertService;
//
//	/**
//	 *
//	 * @param apiKey
//	 * @param dataList
//	 * @return
//	 */
//	@PostMapping("/data-api/{apiKey}")
//	@ApiOperation(value = "对外暴露的接口")
//	public R<String> doSave(@PathVariable("apiKey") String apiKey, @RequestBody List<JSONObject> dataList) {
//		if(dataList == null || dataList.isEmpty()) {
//			return R.fail("数据不能为空");
//		}
//		DataApi dataApi = dataApiService.getOne(Wrappers.<DataApi>lambdaQuery().eq(DataApi::getApiKey, apiKey));
//		if(dataApi == null) {
//			return R.fail("接口不存在");
//		}
//		if(dataApi.getApiType() != 3) {
//			return R.fail("接口类型不正确");
//		}
//		if(dataApi.getApiStatus() != 1) {
//			return R.fail("接口不可用");
//		}
//		ReportDatasource datasource = reportDatasourceService.getById(dataApi.getDatasourceId());
//		if (null == datasource) {
//			return R.fail("接口数据源不存在");
//		}
//		List<DataApiInsertParamDTO> dataInsertParamList = JSON.parseArray(dataApi.getQueryParam(), DataApiInsertParamDTO.class);
//		JSONObject jsonObject = dataList.get(0);
//		//规整参数顺序
//		DataApiInsertParamDTO[] insertSqlParamArray = dataInsertParamList.stream().filter(it -> jsonObject.containsKey(it.getParamName())).toArray(DataApiInsertParamDTO[]::new);
//		dataApiInsertService.batchSave(datasource, dataApi.getQueryTable(), insertSqlParamArray, dataList);
//		return R.status(true);
//	}
//}
