package org.dromara.elevator.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
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.excel.utils.ExcelUtil;
import org.dromara.elevator.domain.vo.EPassengerFeedbackVo;
import org.dromara.elevator.domain.bo.EPassengerFeedbackBo;
import org.dromara.elevator.service.IEPassengerFeedbackService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 乘客反馈信息;
 *
 * @author zy
 * @date 2024-07-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/feedback/passengerFeedback")
public class EPassengerFeedbackController extends BaseController {

    private final IEPassengerFeedbackService ePassengerFeedbackService;

    /**
     * 查询乘客反馈信息;列表
     */
//    @SaCheckPermission("elevator:passengerFeedback:list")
    @GetMapping("/list")
    public TableDataInfo<EPassengerFeedbackVo> list(EPassengerFeedbackBo bo, PageQuery pageQuery) {
        return ePassengerFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出乘客反馈信息;列表
     */
//    @SaCheckPermission("elevator:passengerFeedback:export")
//    @Log(title = "乘客反馈信息;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EPassengerFeedbackBo bo, HttpServletResponse response) {
        List<EPassengerFeedbackVo> list = ePassengerFeedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "乘客反馈信息;", EPassengerFeedbackVo.class, response);
    }

    /**
     * 获取乘客反馈信息;详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("elevator:passengerFeedback:query")
    @GetMapping("/{id}")
    public R<EPassengerFeedbackVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(ePassengerFeedbackService.queryById(id));
    }

    /**
     * 新增乘客反馈信息;
     */
//    @SaCheckPermission("elevator:passengerFeedback:add")
//    @Log(title = "乘客反馈信息;", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EPassengerFeedbackBo bo) {
        return toAjax(ePassengerFeedbackService.insertByBo(bo));
    }

    /**
     * 修改乘客反馈信息;
     */
//    @SaCheckPermission("elevator:passengerFeedback:edit")
//    @Log(title = "乘客反馈信息;", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EPassengerFeedbackBo bo) {
        return toAjax(ePassengerFeedbackService.updateByBo(bo));
    }

    /**
     * 删除乘客反馈信息;
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("elevator:passengerFeedback:remove")
//    @Log(title = "乘客反馈信息;", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(ePassengerFeedbackService.deleteWithValidByIds(List.of(ids), true));
    }
}
