package com.fuint.module.backendApi.controller;

import com.fuint.common.dto.ext.TableCategoryDto;
import com.fuint.common.param.PageParam;
import com.fuint.common.service.TableCategoryService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.PageResult;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.bean.TableCategoryBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutionException;

/**
 * 餐桌分类表管理类controller
 *
 * Created by pzg
 * CopyRight https://www.fuint.cn
 */
@Api(tags="管理端-餐桌分类表相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/tableCategory")
public class BackendTableCategoryController extends BaseController {

    /**
     * 餐桌分类表服务接口
     */
    private TableCategoryService tableCategoryService;

    /**
     * 餐桌分类表列表查询
     *
     * @param  categoryName 分类名称
     * @return 餐桌分类表列表
     */
    @ApiOperation(value = "餐桌分类表列表查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('tableCategory:list')")
    public  PageResult<TableCategoryBean> list(@RequestParam(value = "categoryName",defaultValue = "") String categoryName, PageParam pageParam) throws BusinessCheckException, ExecutionException, InterruptedException {
       return  tableCategoryService.selectTableCategoryList(categoryName,pageParam);
    }

    /**
     * 更新餐桌分类表状态
     *
     * @return
     */
    @ApiOperation(value = "更新餐桌分类")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('tableCategory:edit')")
    public ResponseObject updateStatus(@RequestBody TableCategoryDto tableCategoryDto) throws BusinessCheckException {
        tableCategoryService.updateStatus(tableCategoryDto);
        return getSuccessResult(true);
    }

    /**
     * 保存餐桌分类表
     *
     * @param tableCategoryDto 参数
     * @return
     */
    @ApiOperation(value = "新增餐桌分类表")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('tableCategory:add')")
    public ResponseObject saveHandler(@RequestBody TableCategoryDto tableCategoryDto) throws BusinessCheckException {
        tableCategoryService.saveHandler(tableCategoryDto);
        return getSuccessResult(true);
    }


    /**
     * 根据id删除餐桌分类数据
     *
     * @param id id
     * @return
     */
    @ApiOperation(value = "根据id删除餐桌分类")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('tableCategory:delete')")
    public ResponseObject deleteHandler(@PathVariable("id") Long id) throws BusinessCheckException {
        tableCategoryService.deleteHandler(id);
        return getSuccessResult(true);
    }

}
