package com.younike.merchant;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.system.domain.GoodsComment;
import com.younike.system.domain.vo.GoodsCommentsVO;
import com.younike.system.service.IMerchantGoodsCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 elev
 * @date 2022-01-11
 */
@Api("商品评价接口")
@RestController
@RequestMapping("/system/comment")
public class MerchantGoodsCommentController extends BaseController {
    @Autowired
    private IMerchantGoodsCommentService goodsCommentService;

    /**
     * 查询商品评价列表
     */
    @ApiOperation("查询商品评价列表")
    @PreAuthorize("@ss.hasPermi('system:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsCommentsVO goodsComment) {
        startPage();
        List<GoodsCommentsVO> list = goodsCommentService.selectGoodsCommentList(goodsComment);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    @ApiOperation("导出商品评价列表")
    @PreAuthorize("@ss.hasPermi('system:comment:export')")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsCommentsVO goodsComment) {
        List<GoodsCommentsVO> list = goodsCommentService.selectGoodsCommentList(goodsComment);
        ExcelUtil<GoodsCommentsVO> util = new ExcelUtil<GoodsCommentsVO>(GoodsCommentsVO.class);
        return util.exportExcel(list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @ApiOperation("获取商品评价详细信息")
    @PreAuthorize("@ss.hasPermi('system:comment:query')")
    @GetMapping(value = "/{commontId}")
    public AjaxResult getInfo(@PathVariable("commontId") Long commontId) {
        return AjaxResult.success(goodsCommentService.selectGoodsCommentByCommontId(commontId));
    }

    /**
     * 新增商品评价
     */
    @ApiOperation("新增商品评价")
    @PreAuthorize("@ss.hasPermi('system:comment:add')")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsCommentsVO goodsComment) {
        return toAjax(goodsCommentService.insertGoodsComment(goodsComment));
    }

    /**
     * 修改商品评价
     */
    @ApiOperation("修改商品评价")
    @PreAuthorize("@ss.hasPermi('system:comment:edit')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsCommentsVO goodsComment) {
        return toAjax(goodsCommentService.updateGoodsComment(goodsComment));
    }

    /**
     * 删除商品评价
     */
    @ApiOperation("删除商品评价")
    @PreAuthorize("@ss.hasPermi('system:comment:remove')")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commontIds}")
    public AjaxResult remove(@PathVariable Long[] commontIds) {
        return toAjax(goodsCommentService.deleteGoodsCommentByCommontIds(commontIds));
    }
}
