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.CommunicationRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.CommunicationRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ImportResultVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.FamilyCommunicationRecordDO;
import cn.iocoder.yudao.module.system.service.biz.FamilyCommunicationRecordService;
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.constraints.*;
import javax.validation.*;


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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 家属沟通记录")
@RestController
@RequestMapping("/family/communicationRecord")
@Validated
public class FamilyCommunicationRecordController {

    @Resource
    private FamilyCommunicationRecordService communicationRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建家属沟通记录")
    @TenantIgnore
    public CommonResult<Boolean> createCommunicationRecord(@RequestBody FamilyCommunicationRecordDO createReqVO) {
        communicationRecordService.createCommunicationRecord(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新家属沟通记录")
    @TenantIgnore
    public CommonResult<Boolean> updateCommunicationRecord(@RequestBody FamilyCommunicationRecordDO updateReqVO) {
        communicationRecordService.updateCommunicationRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除家属沟通记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteCommunicationRecord(@RequestParam("id") Integer id) {
        communicationRecordService.deleteCommunicationRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得家属沟通记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<FamilyCommunicationRecordDO> getCommunicationRecord(@RequestParam("id") Integer id) {
        FamilyCommunicationRecordDO communicationRecord = communicationRecordService.getCommunicationRecord(id);
        return success(communicationRecord);
    }

    @GetMapping("/page")
    @Operation(summary = "获得家属沟通记录分页")
    @TenantIgnore
    public CommonResult<PageResult<CommunicationRecordRespVO>> getCommunicationRecordPage(@Valid CommunicationRecordPageReqVO pageReqVO) {
        PageResult<CommunicationRecordRespVO> pageResult = communicationRecordService.getCommunicationRecordPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/import-template")
    @Operation(summary = "下载家属沟通记录导入模板")
    @TenantIgnore
    public void importTemplate(HttpServletResponse response) throws IOException {
        communicationRecordService.exportImportTemplate(response);
    }

    @PostMapping("/import")
    @Operation(summary = "导入家属沟通记录")
    @TenantIgnore
    public CommonResult<ImportResultVO> importCareRecords(
            @RequestParam("file") MultipartFile file) throws Exception {
        ImportResultVO result = communicationRecordService.importFamilyCommunicationRecord(file);
        return success(result);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出家属沟通记录 Excel")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportCommunicationRecordExcel(@Valid CommunicationRecordPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CommunicationRecordDO> list = communicationRecordService.getCommunicationRecordPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "家属沟通记录.xls", "数据", CommunicationRecordRespVO.class,
//                        BeanUtils.toBean(list, CommunicationRecordRespVO.class));
//    }

}