package com.ozs.kpim.controller.kpiconfig;

import com.ozs.kpim.dto.kpiconfig.KpiConfigDTO;
import com.ozs.kpim.dto.kpiconfig.KpiConfigForListDTO;
import com.ozs.kpim.service.kpiconfig.KpiConfigService;
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;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName KpiConfigManagerToRemoteController
 * @Desc 对其他微服务提供的接口
 * @Author jade
 * @Date 2019/2/27
 * @Version 1.0
 */
@Api(tags = { "KPI配置管理接口(提供给微服务的接口)" })
@RestController
public class KpiConfigToRemoteController {

    @Resource
    private KpiConfigService kpiConfigService;

    @ApiOperation("判断字段是否在KPI配置使用")
    @ApiImplicitParam(name = "id", value = "字段ID", required = true, paramType = "query", dataType = "String")
    @GetMapping("/kpim/kpiConfig/ifColumnInUse")
    public R<String> ifColumnInUse(@RequestParam(required = true) String id){

        try {
            return new R<>(S.OK,S.getMsg(S.OK),kpiConfigService.ifColumnInUse(id));
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR,e.getMessage());
        }
    }

    @ApiOperation("判断字段是否在KPI配置使用(批量)")
    @ApiImplicitParam(name = "ids", value = "字段列表", required = true, paramType = "query", allowMultiple = true,dataType = "String")
    @GetMapping("/kpim/kpiConfig/ifColumnsInUse")
    public R<Map<String,Object>> ifColumnsInUse(@RequestParam(required = true) List<String> ids){

        try {
            return new R<>(S.OK,S.getMsg(S.OK),kpiConfigService.ifColumnsInUse(ids));
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR,e.getMessage());
        }
    }


    @ApiImplicitParam(name = "ids", value = "字段列表", required = true, paramType = "query", allowMultiple = true,dataType = "String")
    @GetMapping("/kpim/kpiConfig/listKpiConfigByKpiIds")
    public List<KpiConfigDTO> listKpiConfigByKpiIds(@RequestParam(required = true) List<String> ids){

        try {
            return kpiConfigService.listKpiConfigByKpiIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    @ApiOperation("根据主题查询启用状态的KPI列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "topicId", value = "主题ID", required = false, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "topicCode", value = "主题编码", required = false, paramType = "query", dataType = "String")
    })
    @GetMapping("/kpim/kpiConfig/listKpiConfigsByTopic")
    public R<List<KpiConfigForListDTO>> listKpiConfigsByTopic(@RequestParam(required = false) String topicId,@RequestParam(required = false) String topicCode){
        try {
            Integer enableStatus = 1;
            return kpiConfigService.listKpiConfigsByTopic(topicId,topicCode,enableStatus);
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR,e.getMessage());
        }
    }


}
