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.common.enums.WarnAreaInfoAreaTypeEnums;
import com.ltgk.common.utils.enums.EnumUtil;
import com.ltgk.port.domain.dto.RemoveByIdReq;
import com.ltgk.port.domain.dto.WarnAreaInfoListReq;
import com.ltgk.port.domain.entity.WarnAreaInfo;
import com.ltgk.port.service.WarnAreaInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * @Author: wan kun
 * @Description: 电子围栏信息
 * @Date: 2025/2/11 16:46
 * @Version: 1.0
 */
@Api(tags = "电子围栏")
@RestController
@RequestMapping("/fishingPort/warnAreaInfo")
@Validated
public class WarnAreaInfoController extends BaseController {
    @Resource
    private WarnAreaInfoService warnAreaInfoService;


    @PostMapping("/findWarnAreaInfoAreaTypeEnumList")
    @ApiOperation(value = "查询电子围栏中 类型 的 枚举类")
    public AjaxResult findWarnAreaInfoAreaTypeEnumList() {
        return success(EnumUtil.getEnumsVOList(WarnAreaInfoAreaTypeEnums.class));
    }


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

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

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

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

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

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

}
