package com.willalp.web.controller.canteen;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
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.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.enums.BusinessType;
import com.willalp.canteen.domain.HsCanteenEvaluate;
import com.willalp.canteen.service.IHsCanteenEvaluateService;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.common.core.page.TableDataInfo;

/**
 * 菜品评价Controller
 *
 * @author songyu
 * @date 2021-11-26
 */
@RestController
@RequestMapping("/canteen/evaluate")
public class HsCanteenEvaluateController extends BaseController
{
    @Autowired
    private IHsCanteenEvaluateService hsCanteenEvaluateService;

    /**
     * 查询菜品评价列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:evaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsCanteenEvaluate hsCanteenEvaluate)
    {
        startPage();
        List<HsCanteenEvaluate> list = hsCanteenEvaluateService.selectHsCanteenEvaluateList(hsCanteenEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出菜品评价列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:evaluate:export')")
    @Log(title = "菜品评价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsCanteenEvaluate hsCanteenEvaluate)
    {
        List<HsCanteenEvaluate> list = hsCanteenEvaluateService.selectHsCanteenEvaluateList(hsCanteenEvaluate);
        ExcelUtil<HsCanteenEvaluate> util = new ExcelUtil<HsCanteenEvaluate>(HsCanteenEvaluate.class);
        return util.exportExcel(list, "菜品评价数据");
    }

    /**
     * 获取菜品评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('canteen:evaluate:query')")
    @GetMapping(value = "/{evaluateId}")
    public AjaxResult getInfo(@PathVariable("evaluateId") String evaluateId)
    {
        return AjaxResult.success(hsCanteenEvaluateService.getById(evaluateId));
    }

    /**
     * 新增菜品评价
     */
    @PreAuthorize("@ss.hasPermi('canteen:evaluate:add')")
    @Log(title = "菜品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsCanteenEvaluate hsCanteenEvaluate)
    {
        while (true) {
            String idStr = IdWorker.getIdStr();
            HsCanteenEvaluate byId = hsCanteenEvaluateService.getById(idStr);
            if (null == byId) {
                hsCanteenEvaluate.setEvaluateId(idStr);
                break;
            }
        }
        return toAjax(hsCanteenEvaluateService.save(hsCanteenEvaluate));
    }

    /**
     * 修改菜品评价
     */
    @PreAuthorize("@ss.hasPermi('canteen:evaluate:edit')")
    @Log(title = "菜品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsCanteenEvaluate hsCanteenEvaluate)
    {
        return toAjax(hsCanteenEvaluateService.updateById(hsCanteenEvaluate));
    }

    /**
     * 删除菜品评价
     */
    @PreAuthorize("@ss.hasPermi('canteen:evaluate:remove')")
    @Log(title = "菜品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evaluateIds}")
    public AjaxResult remove(@PathVariable String[] evaluateIds)
    {
        return toAjax(hsCanteenEvaluateService.removeByIds(Arrays.asList(evaluateIds)));
    }
}
