package com.jeeplus.psimanage.dishManage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import com.jeeplus.psimanage.dishManage.domain.PsiDishLibrary;
import com.jeeplus.psimanage.dishManage.service.PsiDishLibraryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 菜品库管理
 */
@RestController
@Api(tags = "菜品库管理")
@RequestMapping(value = "/psi/dish")
public class PsiDishLibraryController {

    @Resource
    private PsiDishLibraryService service;

    @ApiOperation(value = "列表查询")
    @GetMapping("/list")
    public ResponseEntity<IPage<PsiDishLibrary>> list(Page<PsiDishLibrary> page, PsiDishLibrary info) {
        return ResponseEntity.ok(service.list(page, info));
    }

    @ApiLog(value = "保存菜品", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "新增/修改")
    @PreAuthorize("hasAnyAuthority('psi:dish:add','psi:dish:edit')")
    @PostMapping("/save")
    public ResponseEntity<String> save(@RequestBody PsiDishLibrary info) {
        return ResponseEntity.ok(service.saveDish(info));
    }

    @ApiOperation(value = "查询详情")
    @GetMapping("/findById")
    public ResponseEntity<PsiDishLibrary> findById(@RequestParam String id) {
        return ResponseEntity.ok(service.findById(id));
    }

    @ApiLog(value = "删除菜品", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "删除")
    @PreAuthorize("hasAuthority('psi:dish:del')")
    @DeleteMapping("/delete")
    public ResponseEntity<String> delete(@RequestParam String ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }

    @ApiLog(value = "修改菜品状态", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "启用/停用")
    @PreAuthorize("hasAuthority('psi:dish:edit')")
    @GetMapping("/changeStatus")
    public ResponseEntity<String> changeStatus(@RequestParam String id, @RequestParam String status) {
        return ResponseEntity.ok(service.changeStatus(id, status));
    }
}
