package org.dromara.elevator.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 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.elevator.domain.vo.EExpertConsultVo;
import org.dromara.elevator.domain.bo.EExpertConsultBo;
import org.dromara.elevator.service.IEExpertConsultService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 专家咨询
 *
 * @author ym
 * @date 2024-10-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/elevator/expertConsult")
public class EExpertConsultController extends BaseController {

    private final IEExpertConsultService eExpertConsultService;

    /**
     * 查询专家咨询列表
     */
    @SaCheckPermission("elevator:expertConsult:list")
    @GetMapping("/list")
    public TableDataInfo<EExpertConsultVo> list(EExpertConsultBo bo, PageQuery pageQuery) {
        return eExpertConsultService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出专家咨询列表
     */
    @SaCheckPermission("elevator:expertConsult:export")
    @Log(title = "专家咨询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EExpertConsultBo bo, HttpServletResponse response) {
        List<EExpertConsultVo> list = eExpertConsultService.queryList(bo);
        ExcelUtil.exportExcel(list, "专家咨询", EExpertConsultVo.class, response);
    }

    /**
     * 获取专家咨询详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("elevator:expertConsult:query")
    @GetMapping("/{id}")
    public R<EExpertConsultVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(eExpertConsultService.queryById(id));
    }

    /**
     * 新增专家咨询
     */
    @SaCheckPermission("elevator:expertConsult:add")
    @Log(title = "专家咨询", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EExpertConsultBo bo) {
        return toAjax(eExpertConsultService.insertByBo(bo));
    }

    /**
     * 修改专家咨询
     */
    @SaCheckPermission("elevator:expertConsult:edit")
    @Log(title = "专家咨询", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EExpertConsultBo bo) {
        return toAjax(eExpertConsultService.updateByBo(bo));
    }

    /**
     * 删除专家咨询
     *
     * @param ids 主键串
     */
    @SaCheckPermission("elevator:expertConsult:remove")
    @Log(title = "专家咨询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(eExpertConsultService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 接收专家咨询工单
     */
    @SaCheckPermission("elevator:expertConsult:edit")
    @Log(title = "接收专家咨询工单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/receive")
    public R<Void> receive(@RequestBody EExpertConsultBo bo) {
        return toAjax(eExpertConsultService.receive(bo));
    }

    /**
     * 完成专家咨询工单
     */
    @SaCheckPermission("elevator:expertConsult:edit")
    @Log(title = "接收专家咨询工单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/complete")
    public R<Void> complete(@RequestBody EExpertConsultBo bo) {
        return toAjax(eExpertConsultService.complete(bo));
    }

    /**
     * 审核专家咨询工单
     */
    @SaCheckPermission("elevator:expertConsult:edit")
    @Log(title = "接收专家咨询工单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/audit")
    public R<Void> audit(@RequestBody EExpertConsultBo bo) {
        return toAjax(eExpertConsultService.audit(bo));
    }
}
