package org.dromara.web.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.dromara.web.domain.bo.ConsultantResultTemplateTypeBo;
import org.dromara.web.domain.vo.ConsultantResultTemplateTypeVo;
import org.dromara.web.service.IConsultantResultTemplateTypeService;
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.common.mybatis.core.page.TableDataInfo;

/**
 * 会诊结果模板类型管理
 *
 * @author Lion Li
 * @date 2025-07-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/parameter/basicPublicTemplate/consultantResultTemplateType")
public class ConsultantResultTemplateTypeController extends BaseController {

    private final IConsultantResultTemplateTypeService consultantResultTemplateService;

    /**
     * 查询会诊结果模板类型管理列表
     */
    @SaCheckPermission("basicPublicTemplate:consultantResultTemplateType:list")
    @GetMapping("/list")
    public TableDataInfo<ConsultantResultTemplateTypeVo> list(ConsultantResultTemplateTypeBo bo, PageQuery pageQuery) {
        return consultantResultTemplateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出会诊结果模板类型管理列表
     */
    @SaCheckPermission("basicPublicTemplate:consultantResultTemplateType:export")
    @Log(title = "会诊结果模板类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ConsultantResultTemplateTypeBo bo, HttpServletResponse response) {
        List<ConsultantResultTemplateTypeVo> list = consultantResultTemplateService.queryList(bo);
        ExcelUtil.exportExcel(list, "会诊结果模板类型管理", ConsultantResultTemplateTypeVo.class, response);
    }

    /**
     * 获取会诊结果模板类型管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("basicPublicTemplate:consultantResultTemplateType:query")
    @GetMapping("/{id}")
    public R<ConsultantResultTemplateTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                                     @PathVariable Long id) {
        return R.ok(consultantResultTemplateService.queryById(id));
    }

    /**
     * 新增会诊结果模板类型管理
     */
    @SaCheckPermission("basicPublicTemplate:consultantResultTemplateType:add")
    @Log(title = "会诊结果模板类型管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ConsultantResultTemplateTypeBo bo) {
        return toAjax(consultantResultTemplateService.insertByBo(bo));
    }

    /**
     * 修改会诊结果模板类型管理
     */
    @SaCheckPermission("basicPublicTemplate:consultantResultTemplateType:edit")
    @Log(title = "会诊结果模板类型管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ConsultantResultTemplateTypeBo bo) {
        return toAjax(consultantResultTemplateService.updateByBo(bo));
    }

    /**
     * 删除会诊结果模板类型管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("basicPublicTemplate:consultantResultTemplateType:remove")
    @Log(title = "会诊结果模板类型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(consultantResultTemplateService.deleteWithValidByIds(List.of(ids), true));
    }
}
