package com.ltgk.boat.controller;

import cn.hutool.core.collection.CollUtil;
import com.ltgk.boat.domain.dto.DeleteByIdsReq;
import com.ltgk.boat.domain.dto.DsOutPortDTO;
import com.ltgk.boat.domain.dto.GetOutPortReq;
import com.ltgk.boat.domain.dto.SetConfirmReq;
import com.ltgk.boat.domain.entity.DsOutPort;
import com.ltgk.boat.service.IDsOutPortService;
import com.ltgk.common.annotation.Log;
import com.ltgk.common.annotation.RepeatSubmit;
import com.ltgk.common.constant.Constants;
import com.ltgk.common.constant.ReturnMsgConstants;
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.utils.DateUtils;
import com.ltgk.common.utils.SecurityUtils;
import com.ltgk.common.validation.groups.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 渔船出港信息 前端控制器
 *
 * @author Qi ChengBin
 * @date 2024-12-19
 */
@Api(tags = "渔船出港信息")
@RestController
@RequestMapping("/fishingPort/dsOutPort")
public class DsOutPortController extends BaseController {

    @Resource
    private IDsOutPortService dsOutPortService;

    /**
     * 分页查询渔船出港信息列表
     *
     * @param getOutPortReq: 渔船出港信息数据传输对象
     * @return com.ltgk.common.core.page.TableDataInfo
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询渔船出港信息列表")
    public TableDataInfo page(@RequestBody GetOutPortReq getOutPortReq) {
        getOutPortReq.queryCheck();
        List<DsOutPort> dsOutPortList = dsOutPortService.selectByPage(getOutPortReq);
        return getDataTable(dsOutPortList);
    }

    /**
     * 导出渔船出港信息列表
     *
     * @param getOutPortReq:
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @Log(title = "渔船出港信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation(value = "导出渔船出港信息数据")
    public void export(HttpServletResponse response, @ModelAttribute GetOutPortReq getOutPortReq) {
        dsOutPortService.export(response, getOutPortReq);
    }

    /**
     * 获取渔船出港信息详细信息
     *
     * @param id:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @GetMapping(value = "/detail/{id}")
    @ApiOperation(value = "获取渔船出港信息详细数据")
    public AjaxResult detail(@PathVariable Long id) {
        return success(dsOutPortService.getById(id));
    }

    /**
     * 新增渔船出港信息信息
     *
     * @param dsOutPorDTO:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @RepeatSubmit(message = "请勿重复提交")
    @Log(title = "新增渔船出港信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation(value = "新增渔船出港信息数据")
    public AjaxResult add(@RequestBody DsOutPortDTO dsOutPorDTO) {
        return toAjax(dsOutPortService.addByApp(dsOutPorDTO));
    }

    /**
     * 修改渔船出港信息信息
     *
     * @param dsOutPort:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @Log(title = "修改渔船出港信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation(value = "修改渔船出港信息数据")
    public AjaxResult edit(@Validated(Update.class) @RequestBody DsOutPort dsOutPort) {
        dsOutPort.setUpdateBy(SecurityUtils.getUsername())
                .setUpdateAt(DateUtils.getNowDate());
        return toAjax(dsOutPortService.updateById(dsOutPort));
    }

    /**
     * 删除渔船出港信息信息
     *
     * @param deleteByIdsReq:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @Log(title = "删除渔船出港信息", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @ApiOperation(value = "删除渔船出港信息")
    public AjaxResult delete(@Validated @RequestBody DeleteByIdsReq deleteByIdsReq) {
        List<String> idList = Arrays.asList(deleteByIdsReq.getIds().split(","));
        if (CollUtil.isEmpty(idList)) {
            return AjaxResult.error(ReturnMsgConstants.DELETE_ID_NOT_EMPTY);
        }
        return toAjax(dsOutPortService.removeByIds(idList));
    }

    /**
     * 移动端添加渔船出港报备信息
     *
     * @param dsOutPortDTO:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024/12/19 14:40
     */
    @RepeatSubmit(message = "请勿重复提交")
    @Log(title = "移动端添加渔船出港报备信息", businessType = BusinessType.INSERT)
    @PostMapping("/addByApp")
    @ApiOperation(value = "移动端添加渔船出港报备信息")
    public AjaxResult addByApp(@RequestBody DsOutPortDTO dsOutPortDTO) {
        return toAjax(dsOutPortService.addByApp(dsOutPortDTO));
    }

    /**
     * 渔船出港报备审核确认
     *
     * @param setConfirmReq:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024/12/19 16:01
     */
    @Log(title = "渔船出港报备审核确认", businessType = BusinessType.INSERT)
    @PostMapping("/confirm")
    @ApiOperation(value = "渔船出港报备审核确认")
    public AjaxResult confirm(@Validated(Update.class) @RequestBody SetConfirmReq setConfirmReq) {
        return toAjax(dsOutPortService.confirm(setConfirmReq));
    }


    /**
     * 外地渔船出港登记
     *
     * @param dsOutPortDTO：
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2025/3/4
     */
    @Log(title = "外地渔船出港登记", businessType = BusinessType.INSERT)
    @PostMapping("/registrationNotLocalBoat")
    @ApiOperation(value = "外地渔船出港登记")
    public AjaxResult registrationNotLocalBoat(@RequestBody DsOutPortDTO dsOutPortDTO) {
        dsOutPortDTO.setIsLocal(Constants.NON_LOCAL);
        return success(dsOutPortService.doRegistrationNotLocalBoat(dsOutPortDTO));
    }
}
