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.GoodsCommentResource;
import com.younike.system.domain.vo.GoodsCommentResourceVo;
import com.younike.system.service.IMerchantGoodsCommentResourceService;
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 jubs
 * @date 2022-01-12
 */
@Api("评价资源接口")
@RestController
@RequestMapping("/system/resource")
public class MerchantGoodsCommentResourceController extends BaseController {
    @Autowired
    private IMerchantGoodsCommentResourceService goodsCommentResourceService;

    /**
     * 查询评价资源列表
     */
    @ApiOperation("查询评价资源列表")
    @PreAuthorize("@ss.hasPermi('system:resource:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsCommentResourceVo goodsCommentResource) {
        startPage();
        List<GoodsCommentResourceVo> list = goodsCommentResourceService.selectGoodsCommentResourceList(goodsCommentResource);
        return getDataTable(list);
    }

    /**
     * 导出评价资源列表
     */
    @ApiOperation("导出评价资源列表")
    @PreAuthorize("@ss.hasPermi('system:resource:export')")
    @Log(title = "评价资源", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsCommentResourceVo goodsCommentResource) {
        List<GoodsCommentResourceVo> list = goodsCommentResourceService.selectGoodsCommentResourceList(goodsCommentResource);
        ExcelUtil<GoodsCommentResourceVo> util = new ExcelUtil<GoodsCommentResourceVo>(GoodsCommentResourceVo.class);
        return util.exportExcel(list, "评价资源数据");
    }

    /**
     * 获取评价资源详细信息
     */
    @ApiOperation("获取评价资源详细信息")
    @PreAuthorize("@ss.hasPermi('system:resource:query')")
    @GetMapping(value = "/{recourceId}")
    public AjaxResult getInfo(@PathVariable("recourceId") Long recourceId) {
        return AjaxResult.success(goodsCommentResourceService.selectGoodsCommentResourceByRecourceId(recourceId));
    }

    /**
     * 新增评价资源
     */
    @ApiOperation("新增评价资源")
    @PreAuthorize("@ss.hasPermi('system:resource:add')")
    @Log(title = "评价资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsCommentResourceVo goodsCommentResource) {
        return toAjax(goodsCommentResourceService.insertGoodsCommentResource(goodsCommentResource));
    }

    /**
     * 修改评价资源
     */
    @ApiOperation("修改评价资源")
    @PreAuthorize("@ss.hasPermi('system:resource:edit')")
    @Log(title = "评价资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsCommentResourceVo goodsCommentResource) {
        return toAjax(goodsCommentResourceService.updateGoodsCommentResource(goodsCommentResource));
    }

    /**
     * 删除评价资源
     */
    @ApiOperation("删除评价资源")
    @PreAuthorize("@ss.hasPermi('system:resource:remove')")
    @Log(title = "评价资源", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recourceIds}")
    public AjaxResult remove(@PathVariable Long[] recourceIds) {
        return toAjax(goodsCommentResourceService.deleteGoodsCommentResourceByRecourceIds(recourceIds));
    }
}
