package com.ltgk.boat.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltgk.boat.domain.entity.DsDynamicNew;
import com.ltgk.boat.service.IDsDynamicNewService;
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.utils.SecurityUtils;
import com.ltgk.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 渔船最新动态 前端控制器
 *
 * @author Qi ChengBin
 * @date 2024-12-19
 */
@Api(tags = "渔船最新动态")
@RestController
@RequestMapping("/fishingPort/dsDynamicNew")
@Validated
public class DsDynamicNewController extends BaseController {

    @Resource
    private IDsDynamicNewService dsDynamicNewService;

    /**
     * 分页查询渔船最新动态列表
     *
     * @param dsDynamicNew:
     * @return com.ltgk.common.core.page.TableDataInfo
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询渔船最新动态列表")
    public TableDataInfo page(@RequestBody DsDynamicNew dsDynamicNew) {
        LambdaQueryWrapper<DsDynamicNew> wrapper = new LambdaQueryWrapper<>(dsDynamicNew);
        startPage();
        List<DsDynamicNew> dsDynamicNewList = dsDynamicNewService.list(wrapper);
        return getDataTable(dsDynamicNewList);
    }

    /**
     * 导出渔船最新动态列表
     *
     * @param dsDynamicNew:
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @Log(title = "渔船最新动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出渔船最新动态数据")
    public void export(HttpServletResponse response, DsDynamicNew dsDynamicNew) {
        LambdaQueryWrapper<DsDynamicNew> wrapper = new LambdaQueryWrapper<>(dsDynamicNew);
        List<DsDynamicNew> dsDynamicNewList = dsDynamicNewService.list(wrapper);
        ExcelUtil<DsDynamicNew> util = new ExcelUtil<DsDynamicNew>(DsDynamicNew.class);
        util.exportExcel(response, dsDynamicNewList, "渔船最新动态数据");
    }

    /**
     * 获取渔船最新动态详细信息
     *
     * @param id:
     * @return com.ltgk.common.core.domain.AjaxResult
     * @author Qi ChengBin
     * @date 2024-12-19
     */
    @PostMapping(value = "/detail")
    @ApiOperation(value = "获取渔船最新动态详细数据")
    public AjaxResult detail(@NotNull(message = "id 不能为空！") Long id) {
        return success(dsDynamicNewService.getById(id));
    }

    /**
     * 新增渔船最新动态信息
     *
     * @param dsDynamicNew:
     * @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 DsDynamicNew dsDynamicNew) {
        String userName = SecurityUtils.getLoginUser().getUser().getNickName();
        dsDynamicNew.setCreateBy(userName)
                .setCreateTime(new Date())
                .setUpdateBy(userName)
                .setUpdateTime(new Date());
        return toAjax(dsDynamicNewService.save(dsDynamicNew));
    }

    /**
     * 修改渔船最新动态信息
     *
     * @param dsDynamicNew:
     * @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(@RequestBody DsDynamicNew dsDynamicNew) {
        String userName = SecurityUtils.getLoginUser().getUser().getNickName();
        dsDynamicNew.setUpdateBy(userName)
                .setUpdateTime(new Date());
        return toAjax(dsDynamicNewService.updateById(dsDynamicNew));
    }

    /**
     * 删除渔船最新动态信息
     *
     * @param uuids:
     * @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(@ApiParam("ID 逗号隔开") @RequestParam("ids") String uuids) {
        return toAjax(dsDynamicNewService.removeByIds(Arrays.asList(uuids.split(","))));
    }
}
