package com.huatek.busi.controller;

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

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

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.entity.FaultCategory;
import com.huatek.busi.entity.FaultCoefficient;
import com.huatek.busi.service.BusiFaultService;
import com.huatek.busi.vo.FaultCauseVo;
import com.huatek.busi.vo.FaultShowsVo;
import com.huatek.busi.vo.FaultSubtypesVo;
import com.huatek.busi.vo.FaultTypesVo;
import com.huatek.busi.vo.R;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 故障相关配置信息控制层
 *
 * @author edward_luo
 * @date Jul 04, 2019 14:00:23 PM
 */
@Api(tags = { Tags.BUSI_FAULT })
@Slf4j
@RestController
@RequestMapping("/api/busiFault")
public class BusiFaultController {

    @Reference(check = false)
    private BusiFaultService busiFaultService;

    @ApiOperation(value = "故障主分类-缺陷部件", response = FaultTypesVo.class)
    @GetMapping(value = "/FaultTypes/list")
    public Map<String, Object> faultTypesList() {
        List<FaultTypesVo> faultTypesList = busiFaultService.faultTypesList();
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", faultTypesList);
    }

    @ApiOperation(value = "故障子分类", response = FaultSubtypesVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "masterId", value = "主分类ID")
    })
    @GetMapping(value = "/FaultSubtypes/list")
    public Map<String, Object> faultSubtypesList(@RequestParam(value = "masterId", required = true) String masterId) {
        log.debug("faultSubtypesList: {}", masterId);
        List<FaultSubtypesVo> faultSubtypesList = busiFaultService.faultSubtypesList(masterId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", faultSubtypesList);
    }

    @ApiOperation(value = "故障表现分类", response = FaultShowsVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "subId", value = "故障子分类ID")
    })
    @GetMapping(value = "/FaultShows/list")
    public Map<String, Object> faultShowsList(@RequestParam(value = "subId", required = true) String subId) {
        log.debug("faultShowsList: {}", subId);
        List<FaultShowsVo> faultShowsList = busiFaultService.faultShowsList(subId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", faultShowsList);
    }

    @ApiOperation(value = "故障原因", response = FaultCauseVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "masterId", value = "故障主分类ID"),
        @ApiImplicitParam(name = "subId", value = "故障子分类ID"),
        @ApiImplicitParam(name = "modeId", value = "故障表现分类ID")
    })
    @GetMapping(value = "/FaultCause/list")
    public Map<String, Object> faultCauseList(@RequestParam(value = "masterId", required = true) String masterId,
            @RequestParam(value = "subId", required = true) String subId,
            @RequestParam(value = "modeId", required = true) String modeId) {
        log.debug("faultCauseList masterId: {}, subId{}, modeId:{}", masterId, subId, modeId);
        List<FaultCauseVo> faultCauseList = busiFaultService.faultCauseList(masterId, subId, modeId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", faultCauseList);
    }

    /**
     * 缺陷类别
     * 
     * @return
     */
    @ApiOperation(value = "缺陷类别", response = FaultCategory.class)
    @GetMapping("/queryFaultCategory")
    public R queryFaultCategory() {
        List<FaultCategory> list = busiFaultService.findFaultCategory();
        return R.success().put("faultCategoryList", list);
    }

    /**
     * 缺陷系数
     * 
     * @return
     */
    @ApiOperation(value = "缺陷系数", response = FaultCoefficient.class)
    @GetMapping("/queryFaultCoefficient")
    public R queryFaultCoefficient() {
        List<FaultCoefficient> list = busiFaultService.findFaultCoefficient();
        return R.success().put("faultCoefficientList", list);
    }
}
