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.CareRecordsPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ImportResultVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.MedicalCareRecordsRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.MedicalCareRecordsDO;
import cn.iocoder.yudao.module.system.service.biz.MedicalCareRecordsService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
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.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;

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


@Tag(name = "管理后台 - 医疗护理记录")
@RestController
@RequestMapping("/medical/careRecords")
@Validated
public class MedicalCareRecordsController {

    @Resource
    private MedicalCareRecordsService careRecordsService;

    @PostMapping("/create")
    @Operation(summary = "创建医疗护理记录")
    @TenantIgnore
    public CommonResult<Boolean> createCareRecords( @RequestBody MedicalCareRecordsDO createReqVO) {
        careRecordsService.createCareRecords(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新医疗护理记录")
    @TenantIgnore
    public CommonResult<Boolean> updateCareRecords( @RequestBody MedicalCareRecordsDO updateReqVO) {
        careRecordsService.updateCareRecords(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除医疗护理记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteCareRecords(@RequestParam("id") Integer id) {
        careRecordsService.deleteCareRecords(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得医疗护理记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<MedicalCareRecordsDO> getCareRecords(@RequestParam("id") Integer id) {
        MedicalCareRecordsDO careRecords = careRecordsService.getCareRecords(id);
        return success(careRecords);
    }

    @GetMapping("/page")
    @Operation(summary = "获得医疗护理记录分页")
    @TenantIgnore
    public CommonResult<PageResult<MedicalCareRecordsRespVO>> getCareRecordsPage(@Valid CareRecordsPageReqVO pageReqVO) {
        PageResult<MedicalCareRecordsRespVO> pageResult = careRecordsService.getCareRecordsPage(pageReqVO);
        return success(pageResult);
    }


    @GetMapping("/import-template")
    @Operation(summary = "下载医疗护理记录导入模板")
    @TenantIgnore
    public void importTemplate(HttpServletResponse response) throws IOException {
        careRecordsService.exportImportTemplate(response);
    }

    @PostMapping("/import")
    @Operation(summary = "导入医疗护理记录")
    @TenantIgnore
    public CommonResult<ImportResultVO> importCareRecords(
            @RequestParam("file") MultipartFile file) throws IOException {
        ImportResultVO result = careRecordsService.importCareRecords(file);
        return success(result);
    }
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出医疗护理记录主 Excel")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportCareRecordsExcel(@Valid CareRecordsPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CareRecordsDO> list = careRecordsService.getCareRecordsPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "医疗护理记录主.xls", "数据", CareRecordsRespVO.class,
//                        BeanUtils.toBean(list, CareRecordsRespVO.class));
//    }

}