package com.ruoyi.ibs.grid.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.grid.DrawGridAddDTO;
import com.ruoyi.ibs.grid.domain.dto.SecRegionGridDTO;
import com.ruoyi.ibs.grid.domain.dto.TopRegionGridDTO;
import com.ruoyi.ibs.grid.domain.dto.virtual.VirtualGridDTO;
import com.ruoyi.ibs.grid.domain.vo.GridRedisStateVO;
import com.ruoyi.ibs.grid.domain.vo.SecRegionGridRedisVO;
import com.ruoyi.ibs.grid.service.GridInfoRedisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 吴凯程
 * @Date 2024/11/1
 **/
@Api(tags = "网格信息暂存")
@RestController
@RequestMapping("/info/redis")
public class GridInfoRedisController extends BaseController {

    @Resource
    private GridInfoRedisService gridInfoRedisService;

    @ApiOperation("暂存一级网格")
    @PostMapping("/top/save")
    public R<String> saveTopRegionGridToRedis(@RequestBody TopRegionGridDTO topRegionGridDTO) {
        return R.ok(gridInfoRedisService.saveTopRegionGridToRedis(topRegionGridDTO));
    }

    @ApiOperation("获取一级网格")
    @Log(title = "获取一级网格", businessType = BusinessType.OTHER)
    @GetMapping("/top/get")
    public R<TopRegionGridDTO> getTopRegionGridFromRedis() {
        TopRegionGridDTO topRegionGridFromRedis = gridInfoRedisService.getTopRegionGridFromRedis();
        return R.ok(topRegionGridFromRedis);
    }

    @ApiOperation("暂存二级网格")
    @PostMapping("/sec/save")
    public R<String> saveSecRegionGridToRedis(@RequestBody SecRegionGridDTO secRegionGridDTO) {
        return R.ok(gridInfoRedisService.saveSecRegionGridToRedis(secRegionGridDTO));
    }

    @ApiOperation("获取二级网格")
    @GetMapping("/sec/get")
    public R<SecRegionGridRedisVO> getSecRegionGridFromRedis() {
        return R.ok(gridInfoRedisService.getSecRegionGridFromRedis());
    }

    @ApiOperation("暂存虚拟网格")
    @PostMapping("/virtual/save")
    public R<String> saveVirtualGridToRedis(@RequestBody VirtualGridDTO virtualGridDTO) {
        return R.ok(gridInfoRedisService.saveVirtualGridToRedis(virtualGridDTO));
    }

    @ApiOperation("获取虚拟网格")
    @GetMapping("/virtual/get")
    public R<VirtualGridDTO> getVirtualGridFromRedis() {
        VirtualGridDTO virtualGridFromRedis = gridInfoRedisService.getVirtualGridFromRedis();
        return R.ok(virtualGridFromRedis);
    }

    @ApiOperation("暂存特色网格")
    @PostMapping("/draw/save")
    public R<String> saveDrawGridToRedis(@RequestBody DrawGridAddDTO drawGridAddDTO) {
        return R.ok(gridInfoRedisService.saveDrawGridToRedis(drawGridAddDTO));
    }

    @ApiOperation("获取特色网格")
    @GetMapping("/draw/get")
    public R<DrawGridAddDTO> getDrawGridFromRedis() {
        DrawGridAddDTO drawGridFromRedis = gridInfoRedisService.getDrawGridFromRedis();
        return R.ok(drawGridFromRedis);
    }

    @ApiOperation("清空暂存信息")
    @PostMapping("/clean")
    public R<String> cleanGridInfo(@ApiParam(value = "网格类型(1一级网格 2二级网格 3虚拟网格 4特色网格)", name = "gridType") @RequestParam String gridType) {
        return R.ok(gridInfoRedisService.cleanGridInfo(gridType));
    }

    @ApiOperation("是否存在暂存网格信息")
    @GetMapping("/state")
    public R<GridRedisStateVO> getUserRedisState() {
        return R.ok(gridInfoRedisService.getUserRedisState());
    }
}
