package com.ozs.kpim.controller.common;

import com.ozs.kpim.dto.common.RuleTypeDTO;
import com.ozs.kpim.dto.common.SignDTO;
import com.ozs.kpim.dto.common.TypeDTO;
import com.ozs.kpim.dto.common.UserDTO;
import com.ozs.kpim.service.common.CommonService;
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.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;

/**
 * @ClassName CommonController
 * @Desc 通用接口
 * @Author jade
 * @Date 2019/2/18
 * @Version 1.0
 */
@RestController
@Api(tags = { "通用接口" })
public class CommonController {

    @Resource
    private CommonService commonService;

    @ApiOperation("查询配置类型列表")
    @GetMapping("/kpim/common/listTypes")
    public R<List<TypeDTO>> listTypes(){
        try {
            return commonService.listTypes();
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR);
        }
    }

    @ApiOperation("查询符号列表")
    @GetMapping("/kpim/common/listSigns")
    public R<List<SignDTO>> listSigns(){
        try {
            return commonService.listSigns();
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR);
        }
    }


    @ApiOperation("根据KPI类型查询规则类型列表")
    @ApiImplicitParam(name = "kpiType", value = "KPI类型", required = false, paramType = "query", dataType = "int")
    @GetMapping("/kpim/common/listRuleTypesByKpiType")
    public R<List<RuleTypeDTO>> listRuleTypes(@RequestParam(required = false,defaultValue = "1") Integer kpiType){
        try {
            return commonService.listRuleTypes(kpiType);
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR);
        }
    }

    @ApiOperation("查询普通管理员列表")
    @GetMapping("/kpim/common/listAdministrativeUsers")
    public R<List<UserDTO>> listAdministrativeUsers(@RequestParam(required = false,defaultValue = "2") Integer userType){
        try {
            return commonService.listAdministrativeUsers(userType);
        } catch (Exception e) {
            e.printStackTrace();
            return new R<>(S.ERROR);
        }
    }



}
