package com.cm.common.controller.apis.bigdatatemplate;

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.common.pojo.dtos.bigdatatemplate.BigdataTemplateDTO;
import com.cm.common.pojo.vos.bigdatatemplate.BigdataTemplateVO;
import com.cm.common.service.bigdatatemplate.IBigdataTemplateService;
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: BigdataTemplateController
 * @Description: 大数据展示的模板管理
 * @Author: WenG
 * @Date: 2020-10-20 10:49
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "大数据展示的模板管理接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/bigdatatemplate")
public class BigdataTemplateController extends AbstractController {

    @Autowired
    private IBigdataTemplateService bigdataTemplateService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "更改显示方式", notes = "更改显示方式")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatatemplatepublishstatus/{bigdataTemplateId}/{bigdataTemplatePublishStatus}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataTemplatePublishStatus(@PathVariable("bigdataTemplateId") String bigdataTemplateId, @PathVariable("bigdataTemplatePublishStatus") Boolean bigdataTemplatePublishStatus) throws Exception {
        return bigdataTemplateService.updateBigdataTemplatePublishStatus(bigdataTemplateId, bigdataTemplatePublishStatus);
    }

    @ApiOperation(value = "新增大数据展示的模板管理", notes = "新增大数据展示的模板管理接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("savebigdatatemplate")
    @CheckRequestBodyAnnotation
    public SuccessResult saveBigdataTemplate(@RequestBody BigdataTemplateVO bigdataTemplateVO) throws Exception {
        return bigdataTemplateService.saveBigdataTemplate(bigdataTemplateVO);
    }

    @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("removebigdatatemplate/{ids}")
    public SuccessResult removeBigdataTemplate(@PathVariable("ids") String ids) throws RemoveException {
        return bigdataTemplateService.removeBigdataTemplate(ids);
    }

    @ApiOperation(value = "修改大数据展示的模板管理", notes = "修改大数据展示的模板管理接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataTemplateId", value = "大数据展示的模板管理ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatatemplate/{bigdataTemplateId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataTemplate(@PathVariable("bigdataTemplateId") String bigdataTemplateId, @RequestBody BigdataTemplateVO bigdataTemplateVO) throws Exception {
        return bigdataTemplateService.updateBigdataTemplate(bigdataTemplateId, bigdataTemplateVO);
    }

    @ApiOperation(value = "大数据展示的模板管理详情(通过ID)", notes = "大数据展示的模板管理详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataTemplateId", value = "大数据展示的模板管理ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getbigdatatemplatebyid/{bigdataTemplateId}")
    public BigdataTemplateDTO getBigdataTemplateById(@PathVariable("bigdataTemplateId") String bigdataTemplateId) throws SearchException {
        return bigdataTemplateService.getBigdataTemplateById(bigdataTemplateId);
    }

    @ApiOperation(value = "大数据展示的模板管理列表", notes = "大数据展示的模板管理列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listbigdatatemplate")
    public List<BigdataTemplateDTO> listBigdataTemplate() throws SearchException {
        Map<String, Object> params = requestParams();
        return bigdataTemplateService.listBigdataTemplate(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("listpagebigdatatemplate")
    public SuccessResultList<List<BigdataTemplateDTO>> listPageBigdataTemplate(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return bigdataTemplateService.listPageBigdataTemplate(page);
    }

    @ApiOperation(value = "大数据展示的模板管理统计", notes = "大数据展示的模板管理统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("countbigdatatemplate")
    SuccessResultData<Integer> countBigdataTemplate() throws SearchException {
        Map<String, Object> params = requestParams();
        return bigdataTemplateService.countBigdataTemplate(params);
    }

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

}