package com.fuyuanshen.app.controller;

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 com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.log.annotation.Log;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.log.enums.BusinessType;
import com.fuyuanshen.common.excel.utils.ExcelUtil;
import com.fuyuanshen.equipment.domain.vo.AppBusinessFileVo;
import com.fuyuanshen.equipment.domain.bo.AppBusinessFileBo;
import com.fuyuanshen.equipment.service.IAppBusinessFileService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * app业务文件
 *
 * @author Lion Li
 * @date 2025-07-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/businessFile")
public class AppBusinessFileController extends BaseController {

    private final IAppBusinessFileService appBusinessFileService;

    /**
     * 查询app业务文件列表
     */
    @SaCheckPermission("app:businessFile:list")
    @GetMapping("/list")
    public TableDataInfo<AppBusinessFileVo> list(AppBusinessFileBo bo, PageQuery pageQuery) {
        return appBusinessFileService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出app业务文件列表
     */
    @SaCheckPermission("app:businessFile:export")
    @Log(title = "app业务文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppBusinessFileBo bo, HttpServletResponse response) {
        List<AppBusinessFileVo> list = appBusinessFileService.queryList(bo);
        ExcelUtil.exportExcel(list, "app业务文件", AppBusinessFileVo.class, response);
    }

    /**
     * 获取app业务文件详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:businessFile:query")
    @GetMapping("/{id}")
    public R<AppBusinessFileVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(appBusinessFileService.queryById(id));
    }

    /**
     * 新增app业务文件
     */
    @SaCheckPermission("app:businessFile:add")
    @Log(title = "app业务文件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppBusinessFileBo bo) {
        return toAjax(appBusinessFileService.insertByBo(bo));
    }

    /**
     * 修改app业务文件
     */
    @SaCheckPermission("app:businessFile:edit")
    @Log(title = "app业务文件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppBusinessFileBo bo) {
        return toAjax(appBusinessFileService.updateByBo(bo));
    }

    /**
     * 删除app业务文件
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:businessFile:remove")
    @Log(title = "app业务文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(appBusinessFileService.deleteWithValidByIds(List.of(ids), true));
    }
}
