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.elderlydangermaterialregister.ElderlyDangerMaterialRegisterPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlydangermaterialregister.ElderlyDangerMaterialRegisterRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlydangermaterialregister.ElderlyDangerMaterialRegisterSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyDangerMaterialRegisterService;
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-danger-material-register")
@Validated
public class ElderlyDangerMaterialRegisterController {

    @Resource
    private ElderlyDangerMaterialRegisterService elderlyDangerMaterialRegisterService;

    @PostMapping("/create")
    @Operation(summary = "创建危险物品登记")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyDangerMaterialRegisterSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyDangerMaterialRegisterService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新危险物品登记")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyDangerMaterialRegisterSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyDangerMaterialRegisterService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除危险物品登记")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyDangerMaterialRegisterService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得危险物品登记详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyDangerMaterialRegisterRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyDangerMaterialRegisterService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得危险物品登记分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyDangerMaterialRegisterRespVO>> page(@Valid ElderlyDangerMaterialRegisterPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyDangerMaterialRegisterService.getPage(pageReqVO));
    }
}
