package com.fs.store.controller;

import java.util.List;

import cn.hutool.core.date.DateTime;
import com.fs.store.vo.FsStoreProductReplyVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.domain.FsStoreProductReply;
import com.fs.store.service.IFsStoreProductReplyService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 评论Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/storeProductReply")
public class FsStoreProductReplyController extends BaseController
{
    @Autowired
    private IFsStoreProductReplyService fsStoreProductReplyService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductReply:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreProductReply fsStoreProductReply)
    {
        startPage();
        fsStoreProductReply.setIsDel(0);
        List<FsStoreProductReplyVO> list = fsStoreProductReplyService.selectFsStoreProductReplyListVO(fsStoreProductReply);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductReply:export')")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreProductReply fsStoreProductReply)
    {
        List<FsStoreProductReply> list = fsStoreProductReplyService.selectFsStoreProductReplyList(fsStoreProductReply);
        ExcelUtil<FsStoreProductReply> util = new ExcelUtil<FsStoreProductReply>(FsStoreProductReply.class);
        return util.exportExcel(list, "storeProductReply");
    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductReply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsStoreProductReplyService.selectFsStoreProductReplyById(id));
    }

    /**
     * 新增评论
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductReply:add')")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreProductReply fsStoreProductReply)
    {
        return toAjax(fsStoreProductReplyService.insertFsStoreProductReply(fsStoreProductReply));
    }

    /**
     * 修改评论
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductReply:edit')")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreProductReply fsStoreProductReply)
    {
        return toAjax(fsStoreProductReplyService.updateFsStoreProductReply(fsStoreProductReply));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductReply:remove')")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsStoreProductReplyService.deleteFsStoreProductReplyByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('store:storeProductReply:reply')")
    @Log(title = "评论回复", businessType = BusinessType.INSERT)
    @PostMapping("/reply")
    public AjaxResult reply(@RequestBody FsStoreProductReply fsStoreProductReply)
    {
        fsStoreProductReply.setIsReply(1);
        fsStoreProductReply.setReplyTime(new DateTime());
        return toAjax(fsStoreProductReplyService.updateFsStoreProductReply(fsStoreProductReply));
    }
}
