package cn.com.tenlion.buildingpictures.controller.apis.picturestemplatearea;

import cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplatearea.PicturesTemplateAreaDTO;
import cn.com.tenlion.buildingpictures.pojo.vos.picturestemplatearea.PicturesTemplateAreaAllVO;
import cn.com.tenlion.buildingpictures.pojo.vos.picturestemplatearea.PicturesTemplateAreaPiointVO;
import cn.com.tenlion.buildingpictures.pojo.vos.picturestemplatearea.PicturesTemplateAreaVO;
import cn.com.tenlion.buildingpictures.service.picturestemplatearea.IPicturesTemplateAreaService;
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 java.util.List;
import java.util.Map;

/**
 * @ClassName: PicturesTemplateAreaController
 * @Description: 图片套版模板的区域设置
 * @Author: WenG
 * @Date: 2020-10-20 15:08
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "图片套版模板的区域设置接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/picturestemplatearea")
public class PicturesTemplateAreaController extends DefaultBaseController {

    @Autowired
    private IPicturesTemplateAreaService picturesTemplateAreaService;
    @Autowired
    private SecurityComponent securityComponent;

    @ApiOperation(value = "区域统一修改", notes = "区域统一修改接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateId", value = "模板ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatepicturestemplateareaall/{picturesTemplateId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updatePicturesTemplateAreaAll(@PathVariable("picturesTemplateId") String picturesTemplateId, @RequestBody PicturesTemplateAreaAllVO picturesTemplateAreaAllVO) throws Exception {
        return picturesTemplateAreaService.updatePicturesTemplateAreaAll(picturesTemplateId, picturesTemplateAreaAllVO);
    }

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

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

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

    @ApiOperation(value = "新增图片套版模板的区域设置", notes = "新增图片套版模板的区域设置接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("savepicturestemplatearea")
    @CheckRequestBodyAnnotation
    public SuccessResult savePicturesTemplateArea(@RequestBody PicturesTemplateAreaVO picturesTemplateAreaVO) throws Exception {
        return picturesTemplateAreaService.savePicturesTemplateArea(picturesTemplateAreaVO);
    }

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

    @ApiOperation(value = "修改图片套版模板的区域设置", notes = "修改图片套版模板的区域设置接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateAreaId", value = "图片套版模板的区域设置ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("updatepicturestemplatearea/{picturesTemplateAreaId}")
    @CheckRequestBodyAnnotation
    public SuccessResult updatePicturesTemplateArea(@PathVariable("picturesTemplateAreaId") String picturesTemplateAreaId, @RequestBody PicturesTemplateAreaVO picturesTemplateAreaVO) throws Exception {
        return picturesTemplateAreaService.updatePicturesTemplateArea(picturesTemplateAreaId, picturesTemplateAreaVO);
    }

    @ApiOperation(value = "图片套版模板的区域设置详情(通过ID)", notes = "图片套版模板的区域设置详情(通过ID)接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "picturesTemplateAreaId", value = "图片套版模板的区域设置ID", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("getpicturestemplateareabyid/{picturesTemplateAreaId}")
    public PicturesTemplateAreaDTO getPicturesTemplateAreaById(@PathVariable("picturesTemplateAreaId") String picturesTemplateAreaId) throws SearchException {
        return picturesTemplateAreaService.getPicturesTemplateAreaById(picturesTemplateAreaId);
    }

    @ApiOperation(value = "图片套版模板的区域设置列表", notes = "图片套版模板的区域设置列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpicturestemplatearea")
    public List<PicturesTemplateAreaDTO> listPicturesTemplateArea() throws SearchException {
        Map<String, Object> params = requestParams();
        return picturesTemplateAreaService.listPicturesTemplateArea(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("listpagepicturestemplatearea")
    public SuccessResultList<List<PicturesTemplateAreaDTO>> listPagePicturesTemplateArea(ListPage page) throws SearchException {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return picturesTemplateAreaService.listPagePicturesTemplateArea(page);
    }

    @ApiOperation(value = "图片套版模板的区域设置统计", notes = "图片套版模板的区域设置统计接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("countpicturestemplatearea")
    SuccessResultData<Integer> countPicturesTemplateArea() throws SearchException {
        Map<String, Object> params = requestParams();
        return picturesTemplateAreaService.countPicturesTemplateArea(params);
    }

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

}