package com.ozs.kpim.controller.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ozs.kpim.dto.common.KpiFunctionDTO;
import com.ozs.kpim.dto.kpiconfig.KpiConfigForListDTO;
import com.ozs.kpim.service.common.KpiFunctionService;
import com.ozs.kpim.util.R;
import com.ozs.kpim.util.S;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @ClassName: KpiFunctionController
 * @Description:KPI函数相关接口
 * @author: Zhao You Kai
 * @date: May 10, 2019 4:58:22 PM
 */
@RestController
@Api(tags = { "KPI函数相关接口" })
public class KpiFunctionController {
	@Resource
	private KpiFunctionService kpiFunctionService;

	@ApiOperation("查询函数列表")
	@GetMapping("/kpim/kpiFunction/list")
	public R<List<KpiFunctionDTO>> listKpiFunction() {
		try {
			return kpiFunctionService.listKpiFunction();
		} catch (Exception e) {
			e.printStackTrace();
			return new R<>(S.ERROR);
		}
	}

	@ApiOperation("查询KPI配置列表（分页）")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "functionName", value = "函数名称（模糊搜索）", required = false, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, paramType = "query", dataType = "String") })
	@GetMapping("/kpim/kpiFunction/pageList")
	public R<List<KpiConfigForListDTO>> listKpiFunctionPage(@RequestParam(required = false) String functionName,
			@RequestParam(required = false, defaultValue = "1") Integer page,
			@RequestParam(required = false, defaultValue = "10") Integer pageSize) throws Exception {
		try {
			return kpiFunctionService.listKpiFunctionPage(functionName, page, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
			return new R<>(S.ERROR, e.getMessage());
		}
	}

	@ApiOperation("查询函数详情")
	@ApiImplicitParam(name = "id", value = "函数ID", required = false, paramType = "path", dataType = "String")
	@GetMapping("/kpim/kpiFunction/{id}")
	public R<KpiFunctionDTO> getKpiFunction(@PathVariable("id") String id) {
		try {
			return kpiFunctionService.getKpiFunction(id);
		} catch (Exception e) {
			e.printStackTrace();
			return new R<>(S.ERROR);
		}
	}

}
