package com.ruoyi.web.controller.jarvis;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jarvis.domain.TaobaoComment;
import com.ruoyi.jarvis.service.ITaobaoCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 淘宝评论管理 Controller
 */
@RestController
@RequestMapping("/jarvis/taobaoComment")
public class TaobaoCommentController extends BaseController {

    @Autowired
    private ITaobaoCommentService taobaoCommentService;

    /**
     * 查询淘宝评论列表
     */
    @PreAuthorize("@ss.hasPermi('jarvis:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaobaoComment taobaoComment) {
        startPage();
        List<TaobaoComment> list = taobaoCommentService.selectTaobaoCommentList(taobaoComment);
        return getDataTable(list);
    }

    /**
     * 导出淘宝评论列表
     */
    @PreAuthorize("@ss.hasPermi('jarvis:comment:export')")
    @Log(title = "淘宝评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaobaoComment taobaoComment) {
        List<TaobaoComment> list = taobaoCommentService.selectTaobaoCommentList(taobaoComment);
        ExcelUtil<TaobaoComment> util = new ExcelUtil<TaobaoComment>(TaobaoComment.class);
        util.exportExcel(response, list, "淘宝评论数据");
    }

    /**
     * 获取淘宝评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('jarvis:comment:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(taobaoCommentService.selectTaobaoCommentById(id));
    }

    /**
     * 修改评论使用状态
     */
    @PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaobaoComment taobaoComment) {
        return toAjax(taobaoCommentService.updateTaobaoCommentIsUse(taobaoComment));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('jarvis:comment:remove')")
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(taobaoCommentService.deleteTaobaoCommentByIds(ids));
    }

    /**
     * 重置评论使用状态（按商品ID）
     */
    @PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping("/reset/{productId}")
    public AjaxResult resetByProductId(@PathVariable String productId) {
        return toAjax(taobaoCommentService.resetTaobaoCommentIsUseByProductId(productId));
    }
}

