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

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.pojo.vos.bigdatamodule.BigdataModuleContentVO;
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.bigdatamodule.BigdataModuleDTO;
import com.cm.common.pojo.vos.bigdatamodule.BigdataModuleVO;
import com.cm.common.service.bigdatamodule.IBigdataModuleService;
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: BigdataModuleController
 * @Description: 大数据展示模块
 * @Author: WenG
 * @Date: 2020-10-19 16:18
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "大数据展示模块接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/bigdatamodule")
public class BigdataModuleController extends AbstractController {

    @Autowired
    private IBigdataModuleService bigdataModuleService;
    @Autowired
    private SecurityComponent securityComponent;

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

    @ApiOperation(value = "修改模块内容", notes = "修改模块内容接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataModuleId", value = "模块ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatamodulecontent/{bigdataModuleId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataModuleContent(@PathVariable("bigdataModuleId") String bigdataModuleId, @RequestBody BigdataModuleContentVO bigdataModuleContentVO) throws Exception {
        return bigdataModuleService.updateBigdataModuleContent(bigdataModuleId, bigdataModuleContentVO.getBigdataModuleContent());
    }

    @ApiOperation(value = "新增大数据展示模块", notes = "新增大数据展示模块接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("savebigdatamodule")
    @CheckRequestBodyAnnotation
    public SuccessResult saveBigdataModule(@RequestBody BigdataModuleVO bigdataModuleVO) throws Exception {
        return bigdataModuleService.saveBigdataModule(bigdataModuleVO);
    }

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

    @ApiOperation(value = "修改大数据展示模块", notes = "修改大数据展示模块接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataModuleId", value = "大数据展示模块ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatamodule/{bigdataModuleId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataModule(@PathVariable("bigdataModuleId") String bigdataModuleId, @RequestBody BigdataModuleVO bigdataModuleVO) throws Exception {
        return bigdataModuleService.updateBigdataModule(bigdataModuleId, bigdataModuleVO);
    }

    @ApiOperation(value = "大数据展示模块详情(通过ID)", notes = "大数据展示模块详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataModuleId", value = "大数据展示模块ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getbigdatamodulebyid/{bigdataModuleId}")
    public BigdataModuleDTO getBigdataModuleById(@PathVariable("bigdataModuleId") String bigdataModuleId) throws SearchException {
        return bigdataModuleService.getBigdataModuleById(bigdataModuleId);
    }

    @ApiOperation(value = "大数据展示模块列表", notes = "大数据展示模块列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listbigdatamodule")
    public List<BigdataModuleDTO> listBigdataModule() throws SearchException {
        Map<String, Object> params = requestParams();
        return bigdataModuleService.listBigdataModule(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("listpagebigdatamodule")
    public SuccessResultList<List<BigdataModuleDTO>> listPageBigdataModule(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return bigdataModuleService.listPageBigdataModule(page);
    }

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

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

}