package org.dromara.facility.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
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.percentagefacility.FacPercentageFacilityQueryReq;
import org.dromara.facility.domain.vo.percentagefacility.FacPercentageFacilityVo;
import org.dromara.facility.service.IFacPercentageFacilityService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设施-百分比设施
 *
 * @author lcj
 * @date 2025-05-26
 */
@Validated
@RestController
@RequestMapping("/facility/percentageFacility")
public class FacPercentageFacilityController extends BaseController {

    @Resource
    private IFacPercentageFacilityService facPercentageFacilityService;

    /**
     * 查询设施-百分比设施列表
     */
    @SaCheckPermission("facility:percentageFacility:list")
    @GetMapping("/list")
    public TableDataInfo<FacPercentageFacilityVo> list(FacPercentageFacilityQueryReq req, PageQuery pageQuery) {
        return facPercentageFacilityService.queryPageList(req, pageQuery);
    }

    /**
     * 导出设施-百分比设施列表
     */
    @SaCheckPermission("facility:percentageFacility:export")
    @Log(title = "设施-百分比设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FacPercentageFacilityQueryReq req, HttpServletResponse response) {
        List<FacPercentageFacilityVo> list = facPercentageFacilityService.queryList(req);
        ExcelUtil.exportExcel(list, "设施-百分比设施", FacPercentageFacilityVo.class, response);
    }

    /**
     * 获取设施-百分比设施详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("facility:percentageFacility:query")
    @GetMapping("/{id}")
    public R<FacPercentageFacilityVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id) {
        return R.ok(facPercentageFacilityService.queryById(id));
    }

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