package cn.com.tenlion.bigdata.controller.apis.bigdatatemplatearea;

import cn.com.tenlion.bigdata.pojo.dtos.bigdatatemplatearea.BigdataTemplateAreaDTO;
import cn.com.tenlion.bigdata.pojo.vos.bigdatatemplatearea.BigdataTemplateAreaPiointVO;
import cn.com.tenlion.bigdata.pojo.vos.bigdatatemplatearea.BigdataTemplateAreaVO;
import cn.com.tenlion.bigdata.service.bigdatatemplatearea.IBigdataTemplateAreaService;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.component.SecurityComponent;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.CurrentUserIdInfoDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.AbstractController;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: BigdataTemplateAreaController
 * @Description: 大数据展示模板的区域设置
 * @Author: WenG
 * @Date: 2020-10-20 15:08
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "大数据展示模板的区域设置接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/bigdatatemplatearea")
public class BigdataTemplateAreaController extends DefaultBaseController {

    @Autowired
    private IBigdataTemplateAreaService bigdataTemplateAreaService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "修改大数据模块区域配置参数", notes = "修改大数据模块区域配置参数接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "showTemplateAreaId", value = "大数据模块区域ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatatemplateareapointmoduledata/{bigdataTemplateAreaId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataTemplateAreaPointModuleData(@PathVariable("bigdataTemplateAreaId") String bigdataTemplateAreaId, @RequestBody String templateAreaModuleData) throws Exception {
        return bigdataTemplateAreaService.updateBigdataTemplateAreaPointModuleData(bigdataTemplateAreaId, templateAreaModuleData.replaceAll("\"", ""));
    }

    @ApiOperation(value = "修改大数据模块区域", notes = "修改大数据模块区域接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "showTemplateAreaId", value = "大数据模块区域ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("copybigdatatemplatearea/{bigdataTemplateAreaId}")
    @CheckRequestBodyAnnotation
    public SuccessResult copyBigdataTemplateAreaPoint(@PathVariable("bigdataTemplateAreaId") String bigdataTemplateAreaId) throws Exception {
        return bigdataTemplateAreaService.copyBigdataTemplateAreaPoint(bigdataTemplateAreaId);
    }

    @ApiOperation(value = "修改大数据模块区域", notes = "修改大数据模块区域接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "showTemplateAreaId", value = "大数据模块区域ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatatemplateareapoint/{bigdataTemplateAreaId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataTemplateAreaPoint(@PathVariable("bigdataTemplateAreaId") String bigdataTemplateAreaId, @RequestBody BigdataTemplateAreaPiointVO bigdataTemplateAreaPiointVO) throws Exception {
        return bigdataTemplateAreaService.updateBigdataTemplateAreaPoint(bigdataTemplateAreaId, bigdataTemplateAreaPiointVO);
    }

    @ApiOperation(value = "新增大数据展示模板的区域设置", notes = "新增大数据展示模板的区域设置接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("savebigdatatemplatearea")
    @CheckRequestBodyAnnotation
    public SuccessResult saveBigdataTemplateArea(@RequestBody BigdataTemplateAreaVO bigdataTemplateAreaVO) throws Exception {
        return bigdataTemplateAreaService.saveBigdataTemplateArea(bigdataTemplateAreaVO);
    }

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

    @ApiOperation(value = "修改大数据展示模板的区域设置", notes = "修改大数据展示模板的区域设置接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataTemplateAreaId", value = "大数据展示模板的区域设置ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatebigdatatemplatearea/{bigdataTemplateAreaId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updateBigdataTemplateArea(@PathVariable("bigdataTemplateAreaId") String bigdataTemplateAreaId, @RequestBody BigdataTemplateAreaVO bigdataTemplateAreaVO) throws Exception {
        return bigdataTemplateAreaService.updateBigdataTemplateArea(bigdataTemplateAreaId, bigdataTemplateAreaVO);
    }

    @ApiOperation(value = "大数据展示模板的区域设置详情(通过ID)", notes = "大数据展示模板的区域设置详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bigdataTemplateAreaId", value = "大数据展示模板的区域设置ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getbigdatatemplateareabyid/{bigdataTemplateAreaId}")
    public BigdataTemplateAreaDTO getBigdataTemplateAreaById(@PathVariable("bigdataTemplateAreaId") String bigdataTemplateAreaId) throws SearchException {
        return bigdataTemplateAreaService.getBigdataTemplateAreaById(bigdataTemplateAreaId);
    }

    @ApiOperation(value = "大数据展示模板的区域设置列表", notes = "大数据展示模板的区域设置列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listbigdatatemplatearea")
    public List<BigdataTemplateAreaDTO> listBigdataTemplateArea() throws SearchException {
        Map<String, Object> params = requestParams();
        return bigdataTemplateAreaService.listBigdataTemplateArea(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("listpagebigdatatemplatearea")
    public SuccessResultList<List<BigdataTemplateAreaDTO>> listPageBigdataTemplateArea(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return bigdataTemplateAreaService.listPageBigdataTemplateArea(page);
    }

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

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

}