package com.fs.hisStore.controller.store;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.hisStore.utils.UserUtil;
import com.fs.user.domain.FsUserComplaint;
import com.fs.user.domain.param.FsUserComplaintParam;
import com.fs.user.domain.vo.FsUserComplaintVo;
import com.fs.user.service.IFsUserComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户投诉Controller
 *
 * @author fs
 * @date 2025-08-27
 */
@RestController
@RequestMapping("/store/complaint")
public class FsUserComplaintController extends BaseController
{
    @Autowired
    private IFsUserComplaintService fsUserComplaintService;

    /**
     * 查询用户投诉列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody FsUserComplaintParam param)
    {
        param.setStoreId(UserUtil.getLoginUserStoreID());
        param.setComplaintType(1); //店铺仅能看咨询的
        startPage();
        List<FsUserComplaintVo> list = fsUserComplaintService.selectFsUserComplaintVoList(param);
        return getDataTable(list);
    }

    /**
     * 导出用户投诉列表
     */
    @Log(title = "用户投诉", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserComplaint fsUserComplaint)
    {
        fsUserComplaint.setStoreId(UserUtil.getLoginUserStoreID());
        List<FsUserComplaint> list = fsUserComplaintService.selectFsUserComplaintList(fsUserComplaint);
        ExcelUtil<FsUserComplaint> util = new ExcelUtil<FsUserComplaint>(FsUserComplaint.class);
        return util.exportExcel(list, "用户投诉数据");
    }

    /**
     * 获取用户投诉详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserComplaintService.selectFsUserComplaintVoById(id));
    }



    /**
     * 修改用户投诉
     */
    @PreAuthorize("@ss.hasPermi('user:complaint:edit')")
    @Log(title = "用户投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserComplaint fsUserComplaint)
    {
        return toAjax(fsUserComplaintService.updateFsUserComplaint(fsUserComplaint));
    }


}
