package com.djhk.uav.feedback.controller;


import com.djhk.common.annotation.Log;
import com.djhk.common.core.controller.BaseController;
import com.djhk.common.core.domain.AjaxResult;
import com.djhk.common.core.domain.entity.SysUser;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.enums.BusinessType;
import com.djhk.common.utils.SecurityUtils;
import com.djhk.common.utils.poi.ExcelUtil;
import com.djhk.system.service.ISysUserService;
import com.djhk.uav.feedback.domain.QuestionFeedback;
import com.djhk.uav.feedback.service.IQuestionFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.djhk.common.utils.PageUtils.startPage;

/**
 * 问题反馈Controller
 * 
 * @author qpc
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/feedback")
public class QuestionFeedbackController extends BaseController
{
    @Autowired
    private IQuestionFeedbackService questionFeedbackService;

    @Autowired
    private ISysUserService userService;


    /**
     * 查询问题反馈列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QuestionFeedback questionFeedback)
    {
        startPage();
        List<QuestionFeedback> list = questionFeedbackService.selectQuestionFeedbackList(questionFeedback);
        return getDataTable(list);
    }

    /**
     * 导出问题反馈列表
     */
    @Log(title = "问题反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionFeedback questionFeedback)
    {
        List<QuestionFeedback> list = questionFeedbackService.selectQuestionFeedbackList(questionFeedback);
        ExcelUtil<QuestionFeedback> util = new ExcelUtil<QuestionFeedback>(QuestionFeedback.class);
        util.exportExcel(response, list, "问题反馈数据");
    }

    /**
     * 获取问题反馈详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        return AjaxResult.success(questionFeedbackService.selectQuestionFeedbackById(id));
    }

    /**
     * 新增问题反馈
     */
    @Log(title = "问题反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionFeedback questionFeedback)
    {
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        questionFeedback.setDeptId(sysUser.getDeptId().toString());
        return toAjax(questionFeedbackService.insertQuestionFeedback(questionFeedback));
    }

    /**
     * 修改问题反馈
     */
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionFeedback questionFeedback)
    {
        return toAjax(questionFeedbackService.updateQuestionFeedback(questionFeedback));
    }

    /**
     * 删除问题反馈
     */
    @Log(title = "问题反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(questionFeedbackService.deleteQuestionFeedbackByIds(ids));
    }
}
