package com.djhk.uav.label.controller;

import com.djhk.common.core.domain.R;
import com.djhk.common.core.web.controller.BaseController;
import com.djhk.common.core.web.page.TableDataInfo;
import com.djhk.uav.label.domain.CatalogueDto;
import com.djhk.uav.label.domain.Plotting;
import com.djhk.uav.label.domain.PlottingQuery;
import com.djhk.uav.label.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author jwh
 * @version 1.0
 * @description
 * @date 2023/7/26 11:03:55
 */
@RestController
@RequestMapping("/plot")
public class LabelController extends BaseController {

    @Autowired
    private LabelService labelService;


    /**
     * 导出kml文件
     *
     *
     * @return
     */
    @GetMapping(value = "/downloadPlot")
    public R listCatalogue(@RequestParam List folderIds) {
        return labelService.downloadPlot(folderIds);
    }

    @PostMapping("/importPlot")
    public R uploadFile(@RequestParam("file") MultipartFile file){
        return labelService.uploadPlot(file);
    }

    /**
     * 添加标注目录
     *
     * @param catalogueDto
     * @return
     */
    @PostMapping("/addDir")
    public R addCatalogue(@RequestBody CatalogueDto catalogueDto) {
        return labelService.addCatalogue(catalogueDto);
    }

    /**
     * 删除目录
     *
     * @param ids
     * @return
     */
    @GetMapping("/{ids}")
    public R delete(@PathVariable Integer[] ids) {
        return labelService.deleteCatalogue(ids);
    }

    /**
     * 修改目录名称
     *
     * @param catalogueDto
     * @return
     */
    @PostMapping("/updateDir")
    public R updateCatalogue(@RequestBody CatalogueDto catalogueDto) {
        return labelService.updateCatalogue(catalogueDto);
    }

    /**
     * 查询目录列表--不分页
     *
     * @param catalogueDto
     * @return
     */
    @GetMapping("/listdir")
    public R listCatalogue(CatalogueDto catalogueDto) {
        return labelService.listCatalogue(catalogueDto);
    }

    /**
     * 修改目录锁定状态
     *
     * @param id
     * @param lockStatus
     */
    @GetMapping("/changeLockStatusDir")
    public R changeLockStatus(@RequestParam("id") Integer id, @RequestParam("lockStatus") Integer lockStatus) {
        return labelService.changeLockStatusCatalogue(id, lockStatus);
    }

    /**
     * 修改目录显示/隐藏状态
     *
     * @param id
     * @param showStatus
     * @return
     */
    @GetMapping("/changeShowStatusDir")
    public R changeShowStatus(@RequestParam("id") Integer id, @RequestParam("showStatus") Integer showStatus) {
        return labelService.changeShowStatusCatalogue(id, showStatus);
    }

    /**
     * 修改目录分享状态
     *
     * @param id
     * @param shareStatus
     * @return
     */
    @GetMapping("/changeShareStatusDir")
    public R changeShareStatus(@RequestParam("id") Integer id, @RequestParam("shareStatus") Integer shareStatus) {
        return labelService.changeShareStatusCatalogue(id, shareStatus);
    }


    /**
     * 添加标注目录
     *
     * @param catalogueDto
     * @return
     */
    @PostMapping("/addPlotWeb")
    public R addPlot(@RequestBody CatalogueDto catalogueDto) {
        return labelService.addPlotWeb(catalogueDto);
    }

    /**
     * 删除目录
     *
     * @param ids
     * @return
     */
    @GetMapping("/deletePlot/{ids}")
    public R deletePlot(@PathVariable Integer[] ids) {
        return labelService.deletePlot(ids);
    }

    /**
     * 删除目录下的所有标绘
     *
     * @param ids
     * @return
     */
    @GetMapping("/deleteDirInner/{ids}")
    public R deleteDirInner(@PathVariable Integer[] ids) {
        return labelService.deleteDirInner(ids);
    }

    /**
     * 修改目录名称
     *
     * @param catalogueDto
     * @return
     */
    @PostMapping("/updatePlot")
    public R updatePlot(@RequestBody CatalogueDto catalogueDto) {
        return labelService.updatePlot(catalogueDto);
    }
    /**
     * 修改标绘数据ByUUID
     *
     * @param catalogueDto
     * @return
     */
    @PostMapping("/updatePlotByUUID")
    public R updatePlotByUUID(@RequestBody Map<String,Object> catalogueDto) {
        return labelService.updatePlotByUUID(catalogueDto);
    }

    @PostMapping("/updateOrder")
    public R updateOrder(@RequestBody List<HashMap<String,Object>> list){
        R result = labelService.updateOrder(list);
        return result;
    }

    /**
     * 查询目录列表--不分页
     *
     * @param folderId
     * @return
     */
    @GetMapping("/listPlot")
    public TableDataInfo listPlot(@RequestParam(required = false) Integer folderId,@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        return labelService.listPlot(folderId,pageNum,pageSize);
    }
    /**
     * 查询标绘列表
     *
     * @return
     */
    @GetMapping("/plottings")
    public R plottings() {
        return labelService.listAllPlot();
    }

    /**
     * 修改标绘锁定状态
     *
     * @param id
     * @param lockStatus
     */
    @GetMapping("/changeLockStatusPlot")
    public R changeLockStatusPlot(@RequestParam("id") Integer id, @RequestParam("lockStatus") Integer lockStatus) {
        return labelService.changeLockStatusPlot(id, lockStatus);
    }

    /**
     * 修改标绘显示/隐藏状态
     *
     * @param id
     * @param showStatus
     * @return
     */
    @GetMapping("/changeShowStatusPlot")
    public R changeShowStatusPlot(@RequestParam("id") Integer id, @RequestParam("showStatus") Integer showStatus) {
        return labelService.changeShowStatusPlot(id, showStatus);
    }

    /**
     * 修改标绘分享状态
     *
     * @param id
     * @param shareStatus
     * @return
     */
    @GetMapping("/changeShareStatusPlot")
    public R changeShareStatusPlot(@RequestParam("id") Integer id, @RequestParam("shareStatus") Integer shareStatus) {
        return labelService.changeShareStatusPlot(id, shareStatus);
    }

    @GetMapping("/collection")
    public R plotCollection(@RequestParam Map<String,Object> params) {
        return labelService.plotCollection(params);
    }

    @GetMapping("/infoByUuid")
    public R<Plotting> infoByUuid(@RequestParam("uuid") String uuid) {
        return labelService.infoByUuid(uuid);
    }

    @GetMapping("/deleteByUuid")
    public R deleteByUuid(@RequestParam("uuid") String uuid) {
        return labelService.deleteByUuid(uuid);
    }

    @GetMapping("/count")
    public R count(PlottingQuery query) {
        return labelService.count(query);
    }

}
