package com.ruoyi.ibs.draw.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ibs.draw.domain.dto.draw.LayerAddDTO;
import com.ruoyi.ibs.draw.domain.dto.draw.LayerEditInfoDTO;
import com.ruoyi.ibs.draw.domain.dto.draw.LayerGridDTO;
import com.ruoyi.ibs.draw.domain.dto.draw.LayerListDTO;
import com.ruoyi.ibs.draw.domain.entity.DrawGrid;
import com.ruoyi.ibs.draw.domain.vo.DrawLayerVO;
import com.ruoyi.ibs.draw.domain.vo.LayerRuleVO;
import com.ruoyi.ibs.draw.domain.vo.MapCustCountVO;
import com.ruoyi.ibs.draw.service.DrawLayerService;
import com.ruoyi.ibs.grid.domain.dto.DeleteDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author 吴凯程
 * @Date 2024/12/20
 **/
@Api(tags = "绘制图层接口")
@RestController
@RequestMapping("/draw/layer")
public class DrawLayerController extends BaseController {
    @Resource
    private DrawLayerService drawLayerService;

    @ApiOperation("创建图层")
    @Log(title = "区域绘制-创建图层", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<String> addLayer(@RequestBody @Valid LayerAddDTO layerAddDTO) {
        return R.ok(drawLayerService.addLayer(layerAddDTO.getLayerName(), layerAddDTO.getLayerColor()));
    }

    @ApiOperation("编辑图层信息")
    @Log(title = "区域绘制-编辑图层信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/info")
    public R<String> editLayerName(@RequestBody @Valid LayerEditInfoDTO layerEditInfoDTO) {
        return R.ok(drawLayerService.editLayerInfo(layerEditInfoDTO));
    }


    @Log(title = "区域绘制-校验图层名称是否可用")
    @ApiOperation("校验图层名称是否可用")
    @GetMapping("/check/name")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "layerName", value = "图层名称", dataType = "String", dataTypeClass = String.class, required = true)
    })
    public R<Boolean> checkLayerNameValid(@RequestParam String layerName) {
        return R.ok(drawLayerService.checkLayerNameValid(layerName));
    }
    @Log(title = "区域绘制-校验图层颜色是否可用")
    @ApiOperation("校验图层颜色是否可用")
    @GetMapping("/check/color")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "layerColor", value = "图层颜色", dataType = "String", dataTypeClass = String.class, required = true)
    })
    public R<Boolean> checkLayerColorValid(@RequestParam String layerColor) {
        return R.ok(drawLayerService.checkLayerColorValid(layerColor));
    }

    @ApiOperation("批量删除图层")
    @Log(title = "区域绘制-删除图层", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public R<String> deleteLayer(@RequestBody @Valid DeleteDTO deleteDTO) {
        return R.ok(drawLayerService.deleteLayer(deleteDTO.getIdList()));
    }
    @Log(title = "区域绘制-获取图层列表")
    @ApiOperation("获取图层列表")
    @GetMapping("/list")
    public R<List<DrawLayerVO>> getDrawLayerList(LayerListDTO layerListDTO) {
        return R.ok(drawLayerService.getDrawLayerList(layerListDTO));
    }

    @Log(title = "区域绘制-获取图层可选列表")
    @ApiOperation("获取图层可选列表")
    @GetMapping("/valid/list")
    public R<List<DrawLayerVO>> getValidDrawLayerList(@RequestParam String opsDept) {
        return R.ok(drawLayerService.getValidDrawLayerList(opsDept));
    }
    @Log(title = "区域绘制-获取图层类型列表")
    @ApiOperation("获取图层类型列表")
    @GetMapping("/name")
    public R<List<String>> getDrawLayerNameList() {
        LayerListDTO layerListDTO = new LayerListDTO();
        List<String> collect = drawLayerService.getDrawLayerList(layerListDTO).stream().map(DrawLayerVO::getLayerName).collect(Collectors.toList());
        return R.ok(collect);
    }
    @Log(title = "区域绘制-根据业务部室和图层id反显网格")
    @ApiOperation("根据业务部室和图层id反显网格")
    @GetMapping("/grid/list")
    public R<List<DrawGrid>> getDrawGridList(LayerGridDTO layerGridDTO) {
        return R.ok(drawLayerService.getDrawGridList(layerGridDTO));
    }
    @Log(title = "区域绘制-特色网格分配规则反显图层名称")
    @ApiOperation("特色网格分配规则反显图层名称")
    @GetMapping("/rule")
    public R<List<LayerRuleVO>> getLayerList(String opsDept) {
        return R.ok(drawLayerService.getLayerList(opsDept));
    }

    @Log(title = "区域绘制-地图热力图数据")
    @ApiOperation("区域绘制-地图热力图数据")
    @GetMapping("/map/cust/count")
    public R<List<MapCustCountVO>> queryBusinessFreqList() {
        return R.ok(drawLayerService.queryBusinessFreqList());
    }

}
