package com.ruoyi.web.controller.info;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.FilePathSplicingType;
import com.ruoyi.common.filepathsplicing.FilePathSplicing;
import com.ruoyi.common.wrapper.DictTextWrapper;
import com.ruoyi.common.wrapper.Wrapper;
import com.ruoyi.info.quicklink.domain.bo.QuickLinkBo;
import com.ruoyi.info.quicklink.domain.vo.QuickLinkVo;
import com.ruoyi.info.quicklink.service.IQuickLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 金刚区Controller
 *
 * @author wuchao
 * @date 2023-12-20
 */
@Validated
@Api(value = "金刚区控制器", tags = {"金刚区管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/info/quick/link")
public class QuickLinkController extends BaseController {

    private final IQuickLinkService iQuickLinkService;

    /**
     * 分页查询金刚区列表
     */
    @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
    @ApiOperation("查询金刚区列表")
    @Wrapper(value= DictTextWrapper.class)
    @SaCheckPermission("quick:link:list")
    @GetMapping("/page")
    public TableDataInfo<QuickLinkVo> page(@Validated(QueryGroup.class) QuickLinkBo bo, PageQuery pageQuery) {
        return iQuickLinkService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取金刚区详细信息
     */
    @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
    @ApiOperation("获取金刚区详细信息")
    @SaCheckPermission("quick:link:query")
    @GetMapping("/info/{id}")
    public R<QuickLinkVo> getInfo(@ApiParam("主键") @NotNull(message = "主键不能为空")
                                  @PathVariable("id") Long id) {
        return R.ok(iQuickLinkService.queryById(id));
    }

    /**
     * 新增金刚区
     */
    @FilePathSplicing(type = FilePathSplicingType.REQUEST)
    @ApiOperation("新增金刚区")
    @SaCheckPermission("quick:link:add")
    @Log(title = "金刚区", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody QuickLinkBo bo) {
        return toAjax(iQuickLinkService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改金刚区
     */
    @FilePathSplicing(type = FilePathSplicingType.REQUEST)
    @ApiOperation("修改金刚区")
    @SaCheckPermission("quick:link:edit")
    @Log(title = "金刚区", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody QuickLinkBo bo) {
        return toAjax(iQuickLinkService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除金刚区
     */
    @ApiOperation("删除金刚区")
    @SaCheckPermission("quick:link:remove")
    @Log(title = "金刚区", businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串") @NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iQuickLinkService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 修改金刚区状态
     */
    @ApiOperation("修改金刚区状态")
    @SaCheckPermission("quick:link:update")
    @Log(title = "金刚区状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStatus/{id}")
    public R<Void> updateStatus(@ApiParam("主键") @NotNull(message = "主键不能为空")
                                    @PathVariable("id") Long id) {
        iQuickLinkService.updateStatus(id);
        return R.ok();
    }

}
