package org.dromara.facility.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.facility.domain.dto.photovoltaicpanelcolumn.FacPhotovoltaicPanelColumnCreateReq;
import org.dromara.facility.domain.dto.photovoltaicpanelcolumn.FacPhotovoltaicPanelColumnQueryReq;
import org.dromara.facility.domain.dto.photovoltaicpanelcolumn.FacPhotovoltaicPanelColumnUpdateReq;
import org.dromara.facility.domain.vo.photovoltaicpanelcolumn.FacPhotovoltaicPanelColumnVo;
import org.dromara.facility.service.IFacPhotovoltaicPanelColumnService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设施-光伏板立柱
 *
 * @author lcj
 * @date 2025-04-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/facility/photovoltaicPanelColumn")
public class FacPhotovoltaicPanelColumnController extends BaseController {

    private final IFacPhotovoltaicPanelColumnService facPhotovoltaicPanelColumnService;

    /**
     * 查询设施-光伏板立柱列表
     */
    @SaCheckPermission("facility:photovoltaicPanelColumn:list")
    @GetMapping("/list")
    public TableDataInfo<FacPhotovoltaicPanelColumnVo> list(FacPhotovoltaicPanelColumnQueryReq req, PageQuery pageQuery) {
        return facPhotovoltaicPanelColumnService.queryPageList(req, pageQuery);
    }

    /**
     * 导出设施-光伏板立柱列表
     */
    @SaCheckPermission("facility:photovoltaicPanelColumn:export")
    @Log(title = "设施-光伏板立柱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FacPhotovoltaicPanelColumnQueryReq req, HttpServletResponse response) {
        List<FacPhotovoltaicPanelColumnVo> list = facPhotovoltaicPanelColumnService.queryList(req);
        ExcelUtil.exportExcel(list, "设施-光伏板立柱", FacPhotovoltaicPanelColumnVo.class, response);
    }

    /**
     * 获取设施-光伏板立柱详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("facility:photovoltaicPanelColumn:query")
    @GetMapping("/{id}")
    public R<FacPhotovoltaicPanelColumnVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable Long id) {
        return R.ok(facPhotovoltaicPanelColumnService.queryById(id));
    }

    /**
     * 新增设施-光伏板立柱
     */
    @SaCheckPermission("facility:photovoltaicPanelColumn:add")
    @Log(title = "设施-光伏板立柱", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Long> add(@Validated(AddGroup.class) @RequestBody FacPhotovoltaicPanelColumnCreateReq req) {
        return R.ok(facPhotovoltaicPanelColumnService.insertByBo(req));
    }

    /**
     * 修改设施-光伏板立柱
     */
    @SaCheckPermission("facility:photovoltaicPanelColumn:edit")
    @Log(title = "设施-光伏板立柱", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FacPhotovoltaicPanelColumnUpdateReq req) {
        return toAjax(facPhotovoltaicPanelColumnService.updateByBo(req));
    }

    /**
     * 删除设施-光伏板立柱
     *
     * @param ids 主键串
     */
    @SaCheckPermission("facility:photovoltaicPanelColumn:remove")
    @Log(title = "设施-光伏板立柱", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(facPhotovoltaicPanelColumnService.deleteWithValidByIds(List.of(ids), true));
    }
}
