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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ImportResultVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.TrainingRecordsPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.TrainingRecordsRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.TrainingRecordsDO;
import cn.iocoder.yudao.module.system.service.biz.TrainingRecordsService;
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.servlet.http.HttpServletResponse;
import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

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




@Tag(name = "管理后台 - 康复训练记录")
@RestController
@RequestMapping("/training/records")
@Validated
public class TrainingRecordsController {

    @Resource
    private TrainingRecordsService recordsService;

    @PostMapping("/create")
    @Operation(summary = "创建康复训练记录")
    @TenantIgnore
    public CommonResult<Boolean> createRecords( @RequestBody TrainingRecordsDO createReqVO) {
        recordsService.createRecords(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新康复训练记录")
    @TenantIgnore
    public CommonResult<Boolean> updateRecords( @RequestBody TrainingRecordsDO updateReqVO) {
        recordsService.updateRecords(updateReqVO);
        return success(true);
    }

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

    @GetMapping("/get")
    @Operation(summary = "获得康复训练记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<TrainingRecordsDO> getRecords(@RequestParam("id") Integer id) {
        TrainingRecordsDO records = recordsService.getRecords(id);
        return success(records);
    }

    @GetMapping("/page")
    @Operation(summary = "获得康复训练记录分页")
    @TenantIgnore
    public CommonResult<PageResult<TrainingRecordsRespVO>> getRecordsPage(@Valid TrainingRecordsPageReqVO pageReqVO) {
        PageResult<TrainingRecordsRespVO> pageResult = recordsService.getRecordsPage(pageReqVO);
        return success(pageResult);
    }

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

    @PostMapping("/import")
    @Operation(summary = "导入康复训练记录")
    @TenantIgnore
    public CommonResult<ImportResultVO> importCareRecords(
            @RequestParam("file") MultipartFile file) throws Exception {
        ImportResultVO result = recordsService.importTrainingRecords(file);
        return success(result);
    }
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出康复训练记录 Excel")
//    @PreAuthorize("@ss.hasPermission('training:records:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportRecordsExcel(@Valid RecordsPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<RecordsDO> list = recordsService.getRecordsPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "康复训练记录.xls", "数据", RecordsRespVO.class,
//                        BeanUtils.toBean(list, RecordsRespVO.class));
//    }

}