package cn.iocoder.yudao.module.system.controller.app.dishesraw;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.system.controller.admin.dishesraw.vo.DishesRawPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dishesraw.vo.DishesRawRespVO;
import cn.iocoder.yudao.module.system.controller.admin.dishesraw.vo.DishesRawSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dishesraw.DishesRawDO;
import cn.iocoder.yudao.module.system.service.dishesraw.DishesRawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;


@Tag(name = "管理后台 - 菜品原材料")
@RestController
@RequestMapping("/app/t/dishes-raw")
@Validated
public class DishesRawAppController {

    @Resource
    private DishesRawService dishesRawService;

//    @PostMapping("/create")
//    @Operation(summary = "创建菜品原材料")
//    @PreAuthorize("@ss.hasPermission('t:dishes-raw:create')")
//    public CommonResult<Long> createDishesRaw(@Valid @RequestBody List<DishesRawSaveReqVO> createReqVO) {
//        return success(dishesRawService.createDishesRawList(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新菜品原材料")
//    @PreAuthorize("@ss.hasPermission('t:dishes-raw:update')")
//    public CommonResult<Boolean> updateDishesRaw(@Valid @RequestBody DishesRawSaveReqVO updateReqVO) {
//        dishesRawService.updateDishesRaw(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除菜品原材料")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('t:dishes-raw:delete')")
//    public CommonResult<Boolean> deleteDishesRaw(@RequestParam("id") Long id) {
//        dishesRawService.deleteDishesRaw(id);
//        return success(true);
//    }

    @GetMapping("/get")
    @Operation(summary = "获得菜品原材料")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('t:dishes-raw:query')")
    public CommonResult<DishesRawRespVO> getDishesRaw(@RequestParam("id") Long id) {
        DishesRawDO dishesRaw = dishesRawService.getDishesRaw(id);
        return success(BeanUtils.toBean(dishesRaw, DishesRawRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得菜品原材料分页")
//    @PreAuthorize("@ss.hasPermission('t:dishes-raw:query')")
    public CommonResult<PageResult<DishesRawRespVO>> getDishesRawPage(@Valid DishesRawPageReqVO pageReqVO) {
        PageResult<DishesRawDO> pageResult = dishesRawService.getDishesRawPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DishesRawRespVO.class));
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出菜品原材料 Excel")
//    @PreAuthorize("@ss.hasPermission('t:dishes-raw:export')")
//    @OperateLog(type = EXPORT)
//    public void exportDishesRawExcel(@Valid DishesRawPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<DishesRawDO> list = dishesRawService.getDishesRawPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "菜品原材料.xls", "数据", DishesRawRespVO.class,
//                        BeanUtils.toBean(list, DishesRawRespVO.class));
//    }

}