package com.boyue.hasfj.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.boyue.common.annotation.Log;
import com.boyue.common.core.controller.BaseController;
import com.boyue.common.core.domain.AjaxResult;
import com.boyue.common.enums.BusinessType;
import com.boyue.hasfj.domain.UserFeedback;
import com.boyue.hasfj.service.IUserFeedbackService;
import com.boyue.common.utils.poi.ExcelUtil;
import com.boyue.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.ModelAttribute;

/**
 * 用户留言Controller
 * 
 * @author boyue
 * @date 2025-07-04
 */
@RestController
@RequestMapping("/hasfj/feedback")
@Tag(name = "【用户留言】管理")
public class UserFeedbackController extends BaseController
{
    @Autowired
    private IUserFeedbackService userFeedbackService;

    /**
     * 查询用户留言列表
     */
    @Operation(summary = "查询用户留言列表")
    @PreAuthorize("@ss.hasPermi('hasfj:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserFeedback userFeedback)
    {
        startPage();
        List<UserFeedback> list = userFeedbackService.selectUserFeedbackList(userFeedback);
        return getDataTable(list);
    }

    /**
     * 导出用户留言列表
     */
    @Operation(summary = "导出用户留言列表")
    @PreAuthorize("@ss.hasPermi('hasfj:feedback:export')")
    @Log(title = "用户留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserFeedback userFeedback)
    {
        List<UserFeedback> list = userFeedbackService.selectUserFeedbackList(userFeedback);
        ExcelUtil<UserFeedback> util = new ExcelUtil<UserFeedback>(UserFeedback.class);
        util.exportExcel(response, list, "用户留言数据");
    }

    /**
     * 获取用户留言详细信息
     */
    @Operation(summary = "获取用户留言详细信息")
    @PreAuthorize("@ss.hasPermi('hasfj:feedback:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userFeedbackService.selectUserFeedbackById(id));
    }

    /**
     * 新增用户留言
     */
    @Operation(summary = "新增用户留言")
    @PreAuthorize("@ss.hasPermi('hasfj:feedback:add')")
    @Log(title = "用户留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFeedback userFeedback)
    {
        userFeedbackService.insertUserFeedback(userFeedback);
        return success(userFeedback);
    }

    /**
     * 修改用户留言
     */
    @Operation(summary = "修改用户留言")
    @PreAuthorize("@ss.hasPermi('hasfj:feedback:edit')")
    @Log(title = "用户留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFeedback userFeedback)
    {
        return toAjax(userFeedbackService.updateUserFeedback(userFeedback));
    }

    /**
     * 删除用户留言
     */
    @Operation(summary = "删除用户留言")
    @PreAuthorize("@ss.hasPermi('hasfj:feedback:remove')")
    @Log(title = "用户留言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable( name = "ids" ) Long[] ids) 
    {
        return toAjax(userFeedbackService.deleteUserFeedbackByIds(ids));
    }

    /**
     * 用户前端
     * 前端用户留言提交
     */
    @Operation(summary = "前端用户留言提交")
    @Log(title = "用户留言", businessType = BusinessType.INSERT)
    @PostMapping("/user/submit")
    public AjaxResult useradd(@RequestBody UserFeedback userFeedback)
    {
        userFeedbackService.insertUserFeedback(userFeedback);
        return success(userFeedback);
    }

    /**
     * 用户前端
     * 获取用户留言编号
     */
    @Operation(summary = "获取用户留言编号")
    @GetMapping(value = "/user/getById/{id}")
    public AjaxResult getUserFeedbackById(@PathVariable("id") Long id)
    {
        return success(userFeedbackService.selectUserFeedbackById(id));
    }

    /**
     * 用户前端
     * 通过留言编号、姓名、身份证号、手机号获取用户留言详情
     */
    @Operation(summary = "通过留言编号、姓名、身份证号、手机号获取用户留言详情")
    @GetMapping(value = "/user/queryDetail")
    public AjaxResult getUserFeedbackDetail(@ModelAttribute UserFeedback userFeedback)
    {
        List<UserFeedback> list = userFeedbackService.selectUserFeedbackList(userFeedback);
        return success(list.isEmpty() ? null : list.get(0));
    }
}
