package org.dromara.system.controller.info;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.OrientationInfoVo;
import org.dromara.system.domain.bo.OrientationInfoBo;
import org.dromara.system.service.IOrientationInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 定位信息
 *
 * @author boman
 * @date 2023-08-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/orientation/info")
public class OrientationInfoController extends BaseController {

    private final IOrientationInfoService orientationInfoService;

    /**
     * 查询定位信息列表
     */
    @SaCheckPermission("orientation:info:list")
    @GetMapping("/list")
    public TableDataInfo<OrientationInfoVo> list(OrientationInfoBo bo, PageQuery pageQuery) {
        return orientationInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出定位信息列表
     */
    @SaCheckPermission("orientation:info:export")
    @Log(title = "定位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OrientationInfoBo bo, HttpServletResponse response) {
        List<OrientationInfoVo> list = orientationInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "定位信息", OrientationInfoVo.class, response);
    }

    /**
     * 获取定位信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("orientation:info:query")
    @GetMapping("/{id}")
    public R<OrientationInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(orientationInfoService.queryById(id));
    }

    /**
     * 新增定位信息
     */
    @SaCheckPermission("orientation:info:add")
    @Log(title = "定位信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OrientationInfoBo bo) {
        return toAjax(orientationInfoService.insertByBo(bo));
    }

    /**
     * 修改定位信息
     */
    @SaCheckPermission("orientation:info:edit")
    @Log(title = "定位信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OrientationInfoBo bo) {
        return toAjax(orientationInfoService.updateByBo(bo));
    }

    /**
     * 删除定位信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("orientation:info:remove")
    @Log(title = "定位信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(orientationInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
