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.TreatmentUserBo;
import org.dromara.web.domain.vo.TreatmentUserVo;
import org.dromara.web.service.ITreatmentUserService;
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-06-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workbench/treatmentUser")
public class TreatmentUserController extends BaseController {

    private final ITreatmentUserService treatmentUserService;

    /**
     * 查询【待诊患者】列表
     */
    @SaCheckPermission("workbench:treatmentUser:list")
    @GetMapping("/list")
    public TableDataInfo<TreatmentUserVo> list(TreatmentUserBo bo, PageQuery pageQuery) {
        return treatmentUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出【待诊患者】列表
     */
    @SaCheckPermission("workbench:treatmentUser:export")
    @Log(title = "【待诊患者】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TreatmentUserBo bo, HttpServletResponse response) {
        List<TreatmentUserVo> list = treatmentUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "【待诊患者】", TreatmentUserVo.class, response);
    }

    /**
     * 获取【待诊患者】详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("workbench:treatmentUser:query")
    @GetMapping("/{id}")
    public R<TreatmentUserVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(treatmentUserService.queryById(id));
    }

    /**
     * 新增【待诊患者】
     */
    @SaCheckPermission("workbench:treatmentUser:add")
    @Log(title = "【待诊患者】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TreatmentUserBo bo) {
        return toAjax(treatmentUserService.insertByBo(bo));
    }

    /**
     * 修改【待诊患者】
     */
    @SaCheckPermission("workbench:treatmentUser:edit")
    @Log(title = "【待诊患者】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TreatmentUserBo bo) {
        return toAjax(treatmentUserService.updateByBo(bo));
    }

    /**
     * 删除【待诊患者】
     *
     * @param ids 主键串
     */
    @SaCheckPermission("workbench:treatmentUser:remove")
    @Log(title = "【待诊患者】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(treatmentUserService.deleteWithValidByIds(List.of(ids), true));
    }
}
