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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.dailycleandisinfectrecord.ElderlyDailyCleanDisinfectRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.dailycleandisinfectrecord.ElderlyDailyCleanDisinfectRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.dailycleandisinfectrecord.ElderlyDailyCleanDisinfectRecordSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyDailyCleanDisinfectRecordService;
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.*;

import javax.annotation.Resource;
import javax.validation.Valid;

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

@Tag(name = "管理后台 - 每日清洁消毒记录")
@RestController
@RequestMapping("/elderly-daily-clean-disinfect-record")
@Validated
public class ElderlyDailyCleanDisinfectRecordController {

    @Resource
    private ElderlyDailyCleanDisinfectRecordService elderlyDailyCleanDisinfectRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建每日清洁消毒记录")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyDailyCleanDisinfectRecordSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyDailyCleanDisinfectRecordService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新每日清洁消毒记录")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyDailyCleanDisinfectRecordSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyDailyCleanDisinfectRecordService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除每日清洁消毒记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyDailyCleanDisinfectRecordService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得每日清洁消毒记录详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyDailyCleanDisinfectRecordRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyDailyCleanDisinfectRecordService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得每日清洁消毒记录分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyDailyCleanDisinfectRecordRespVO>> page(@Valid ElderlyDailyCleanDisinfectRecordPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyDailyCleanDisinfectRecordService.getPage(pageReqVO));
    }
}
