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

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.AssessmentsPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ImportResultVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.RehabilitationAssessmentsRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.RehabilitationAssessmentsDO;
import cn.iocoder.yudao.module.system.service.biz.RehabilitationAssessmentsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import org.springframework.web.multipart.MultipartFile;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 康复评估记录")
@RestController
@RequestMapping("/rehabilitation/assessments")
@Validated
public class RehabilitationAssessmentsController {

    @Resource
    private RehabilitationAssessmentsService assessmentsService;

    @PostMapping("/create")
    @Operation(summary = "创建康复评估记录")
    @TenantIgnore
    public CommonResult<Integer> createAssessments(@Valid @RequestBody RehabilitationAssessmentsDO createReqVO) {
        return success(assessmentsService.createAssessments(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新康复评估记录")
    @TenantIgnore
    public CommonResult<Boolean> updateAssessments(@Valid @RequestBody RehabilitationAssessmentsDO updateReqVO) {
        assessmentsService.updateAssessments(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除康复评估记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteAssessments(@RequestParam("id") Integer id) {
        assessmentsService.deleteAssessments(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得康复评估记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<RehabilitationAssessmentsDO> getAssessments(@RequestParam("id") Integer id) {
        RehabilitationAssessmentsDO assessments = assessmentsService.getAssessments(id);
        return success(assessments);
    }

    @GetMapping("/page")
    @Operation(summary = "获得康复评估记录分页")
    @TenantIgnore
    public CommonResult<PageResult<RehabilitationAssessmentsRespVO>> getAssessmentsPage(@Valid AssessmentsPageReqVO pageReqVO) {
        PageResult<RehabilitationAssessmentsRespVO> pageResult = assessmentsService.getAssessmentsPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/import-template")
    @Operation(summary = "下载康复评估记录导入模板")
    @TenantIgnore
    public void importTemplate(HttpServletResponse response) throws IOException {
        assessmentsService.exportImportTemplate(response);
    }

    @PostMapping("/import")
    @Operation(summary = "导入康复评估记录")
    @TenantIgnore
    public CommonResult<ImportResultVO> importCareRecords(
            @RequestParam("file") MultipartFile file) throws Exception {
        ImportResultVO result = assessmentsService.importRehabilitationAssessments(file);
        return success(result);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出康复评估记录 Excel")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportAssessmentsExcel(@Valid AssessmentsPageReqVO pageReqVO,
//                                       HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<RehabilitationAssessmentsDO> list = assessmentsService.getAssessmentsPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "康复评估记录.xls", "数据", RehabilitationAssessmentsDO.class,
//                BeanUtils.toBean(list, RehabilitationAssessmentsDO.class));
//    }

}