package com.ltgk.boat.controller;

import cn.hutool.core.collection.CollUtil;
import com.ltgk.boat.domain.dto.DeleteByIdsReq;
import com.ltgk.boat.domain.dto.DsEnterPortDTO;
import com.ltgk.boat.domain.dto.GetEnterPortReq;
import com.ltgk.boat.domain.dto.SetConfirmReq;
import com.ltgk.boat.domain.entity.DsEnterPort;
import com.ltgk.boat.service.IDsEnterPortService;
import com.ltgk.common.annotation.Log;
import com.ltgk.common.annotation.RepeatSubmit;
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.Add;
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/dsEnterPort")
public class DsEnterPortController extends BaseController {

    @Resource
    private IDsEnterPortService dsEnterPortService;

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

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

    /**
     * 获取渔船进港信息详细信息
     *
     * @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(dsEnterPortService.getById(id));
    }

    /**
     * 新增渔船进港信息信息
     *
     * @param dsEnterPortDTO:
     * @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 DsEnterPortDTO dsEnterPortDTO) {
        return toAjax(dsEnterPortService.addByApp(dsEnterPortDTO));
    }

    /**
     * 修改渔船进港信息信息
     *
     * @param dsEnterPort: 渔船进港信息实体对象
     * @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 DsEnterPort dsEnterPort) {
        dsEnterPort.setUpdateBy(SecurityUtils.getUsername())
                .setUpdateAt(DateUtils.getNowDate());
        return toAjax(dsEnterPortService.updateById(dsEnterPort));
    }

    /**
     * 删除渔船进港信息信息
     *
     * @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(dsEnterPortService.removeByIds(idList));
    }

    /**
     * 移动端添加渔船进港报备信息
     *
     * @param dsEnterPortDTO: 渔船进港信息数据传输对象
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024/12/20 09:06
     */
    @RepeatSubmit(message = "请勿重复提交")
    @Log(title = "移动端添加渔船进港报备信息", businessType = BusinessType.INSERT)
    @PostMapping("/addByApp")
    @ApiOperation(value = "移动端添加渔船进港报备信息")
    public AjaxResult addByApp(@Validated(Add.class) @RequestBody DsEnterPortDTO dsEnterPortDTO) {
        return toAjax(dsEnterPortService.addByApp(dsEnterPortDTO));
    }

    /**
     * 渔船进港信息审核确认
     *
     * @param setConfirmReq:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024/12/20 10:19
     */
    @Log(title = "渔船进港信息审核确认", businessType = BusinessType.UPDATE)
    @PostMapping("/confirm")
    @ApiOperation(value = "渔船进港信息审核确认")
    public AjaxResult confirm(@Validated(Update.class) @RequestBody SetConfirmReq setConfirmReq) {
        setConfirmReq.queryCheck();
        return toAjax(dsEnterPortService.confirm(setConfirmReq));
    }

    /**
     * 根据归港指引主键修改归港指引状态
     *
     * @param dsEnterPort:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2025/7/15
     */
    @Log(title = "根据渔船进出港主键修改归港指引状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateRegressPortStatus")
    @ApiOperation(value = "根据渔船进出港主键修改归港指引状态")
    public AjaxResult updateRegressPortStatus(@RequestBody DsEnterPort dsEnterPort) {
        return toAjax(dsEnterPortService.updateById(dsEnterPort));
    }
}
