package cn.iocoder.yudao.module.system.controller.admin.biz;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
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.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.*;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.excel.DailyExpensesExportExcelVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.DailyExpensesDO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyOrderFoodService;
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.validation.annotation.Validated;
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.PutMapping;
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;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.Objects;

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

@Tag(name = "管理后台 - 长者报餐记录")
@RestController
@RequestMapping("/elderly/order-food")
@Validated
public class ElderlyOrderFoodController {

    @Resource
    private ElderlyOrderFoodService elderlyOrderFoodService;

    @PostMapping("/commit")
    @Operation(summary = "创建长者报餐记录")
    @TenantIgnore
    @PermitAll
    public CommonResult<String> commit(@RequestBody List<ElderlyOrderFoodCommitVO> voList) {
        return success(elderlyOrderFoodService.create(voList));
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除长者报餐记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyOrderFoodService.delete(id);
        return success(true);
    }

    @PostMapping("/get")
    @Operation(summary = "获得长者报餐记录")
    @TenantIgnore
    @PermitAll
    public CommonResult<List<ElderlyOrderFoodGetResVO>> get(@RequestBody ElderlyOrderFoodGetReqVO reqVO) {
        return success(elderlyOrderFoodService.get(reqVO));
    }

    @GetMapping("/page")
    @Operation(summary = "获得长者报餐记录分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyOrderFoodRespVO>> getPage(@Valid ElderlyOrderFoodPageReqVO pageReqVO) {
        return success(elderlyOrderFoodService.getPage(pageReqVO));
    }

    @GetMapping("/exportExcel")
    @Operation(summary = "导出Excel")
    @ApiAccessLog(operateType = EXPORT)
    public void exportExcel(@Valid ElderlyOrderFoodPageReqVO reqVO,HttpServletResponse response) throws IOException {
        List<ElderOrderFoodExportExcelVO> list = elderlyOrderFoodService.getList(reqVO);
        // 导出 Excel
        ExcelUtils.write(response, "长者点餐.xls", "数据", ElderOrderFoodExportExcelVO.class, list);
    }
}

