package com.ltgk.port.controller;

import com.ltgk.common.annotation.Log;
import com.ltgk.common.annotation.RepeatSubmit;
import com.ltgk.common.core.controller.BaseController;
import com.ltgk.common.core.domain.AjaxResult;
import com.ltgk.common.core.page.TableDataInfo;
import com.ltgk.common.enums.BusinessType;
import com.ltgk.port.domain.dto.ExportWaterAreaInfoReq;
import com.ltgk.port.domain.dto.RemoveByIdReq;
import com.ltgk.port.domain.dto.SaveWaterAreaInfoReq;
import com.ltgk.port.domain.dto.WaterAreaInfoListReq;
import com.ltgk.port.service.WaterAreaInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * @Author: wan kun
 * @Description: 水野保护区
 * @Date: 2025/2/12 8:36
 * @Version: 1.0
 */
@Api(tags = "水野保护区")
@RestController
@RequestMapping("/fishingPort/waterAreaInfo")
@Validated
public class WaterAreaInfoController extends BaseController {
    @Autowired
    private WaterAreaInfoService waterAreaInfoService;

    @RepeatSubmit(message = "请勿重复提交")
    @Log(title = "新增修改电子围栏", businessType = BusinessType.INSERT_OR_UPDATE)
    @PostMapping("/save")
    @ApiOperation(value = "新增修改电子围栏")
    public AjaxResult save(@Valid @RequestBody SaveWaterAreaInfoReq saveWaterAreaInfoReq) {
        return waterAreaInfoService.save(saveWaterAreaInfoReq);
    }

    @Log(title = "查询电子围栏", businessType = BusinessType.QUERY)
    @PostMapping("/list")
    @ApiOperation(value = "查询电子围栏")
    public TableDataInfo list(@Valid @RequestBody WaterAreaInfoListReq waterAreaInfoListReq) {
        return getDataTable(waterAreaInfoService.list(waterAreaInfoListReq));
    }

    @Log(title = "删除电子围栏", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @ApiOperation(value = "删除电子围栏")
    public AjaxResult delete(@Valid @RequestBody RemoveByIdReq removeByIdReq) {
        return AjaxResult.success(waterAreaInfoService.removeById(removeByIdReq.getId()));
    }

    @Log(title = "导出电子围栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出电子围栏")
    public void export(HttpServletResponse response, ExportWaterAreaInfoReq exportWaterAreaInfoReq) {
        waterAreaInfoService.export(response, exportWaterAreaInfoReq);
    }

    @Log(title = "导出导入电子围栏模板", businessType = BusinessType.EXPORT)
    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出导入电子围栏模板")
    public void importTemplate(HttpServletResponse response) {
        waterAreaInfoService.importTemplate(response);
    }

    @RepeatSubmit(message = "请勿重复提交")
    @Log(title = "导入电子围栏数据", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @ApiOperation(value = "导入电子围栏数据")
    public AjaxResult importData(@RequestBody MultipartFile file) throws IOException {
        return AjaxResult.success(waterAreaInfoService.importData(file));
    }
}
