package com.cm.central.control.controller.apis.clientexception;

import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.component.SecurityComponent;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.RemoveException;
import com.cm.common.exception.SearchException;
import com.cm.common.pojo.ListPage;
import com.cm.common.pojo.dtos.CurrentUserIdInfoDTO;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import com.cm.central.control.pojo.dtos.clientexception.ClientExceptionDTO;
import com.cm.central.control.pojo.vos.clientexception.ClientExceptionVO;
import com.cm.central.control.service.clientexception.IClientExceptionService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @ClassName: ClientExceptionController
 * @Description: 客户端异常
 * @Author: WenG
 * @Date: 2020-07-30 19:13
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "客户端异常接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/clientexception")
public class ClientExceptionController extends AbstractController {

    @Autowired
    private IClientExceptionService clientExceptionService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "删除客户端异常(id列表)", notes = "删除客户端异常(id列表)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID列表，用下划线分隔", paramType = "path", example = "1_2_3")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @DeleteMapping("removeclientexception/{ids}")
    public SuccessResult removeClientException(@PathVariable("ids") String ids) throws RemoveException {
        return clientExceptionService.removeClientException(ids);
    }

    @ApiOperation(value = "修改客户端异常", notes = "修改客户端异常接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "clientExceptionId", value = "客户端异常ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updateclientexception/{clientExceptionId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateClientException(@PathVariable("clientExceptionId") String clientExceptionId, @RequestBody ClientExceptionVO clientExceptionVO) throws Exception {
        return clientExceptionService.updateClientException(clientExceptionId, clientExceptionVO);
    }

    @ApiOperation(value = "客户端异常详情(通过ID)", notes = "客户端异常详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "clientExceptionId", value = "客户端异常ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getclientexceptionbyid/{clientExceptionId}")
    public ClientExceptionDTO getClientExceptionById(@PathVariable("clientExceptionId") String clientExceptionId) throws SearchException {
        return clientExceptionService.getClientExceptionById(clientExceptionId);
    }

    @ApiOperation(value = "客户端异常列表", notes = "客户端异常列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listclientexception")
    public List<ClientExceptionDTO> listClientException() throws SearchException {
        Map<String, Object> params = requestParams();
        return clientExceptionService.listClientException(params);
    }

    @ApiOperation(value = "客户端异常分页列表", notes = "客户端异常分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpageclientexception")
    public SuccessResultList<List<ClientExceptionDTO>> listPageClientException(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return clientExceptionService.listPageClientException(page);
    }

    @ApiOperation(value = "客户端异常统计", notes = "客户端异常统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("countclientexception")
    SuccessResultData<Integer> countClientException() throws SearchException {
        Map<String, Object> params = requestParams();
        return clientExceptionService.countClientException(params);
    }

    @ApiOperation(value = "当前用户id信息", notes = "当前用户id信息接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getcurrentuseridinfo")
    public CurrentUserIdInfoDTO getCurrentUserIdInfo() {
        return securityComponent.getCurrentUserIdInfo();
    }

    @ApiOperation(value = "标记处理成功", notes = "标记处理成功接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updateishandlerbyclientexceptionid/{clientExceptionId}")
    public SuccessResult updateIsHandlerByClientExceptionId(@PathVariable("clientExceptionId") String clientExceptionId) {
        return clientExceptionService.updateIsHandlerByClientExceptionId(clientExceptionId);
    }

}