/*
 * Copyright ©2023 CJB-CNIT Team. All rights reserved
 */
package com.openhis.web.basedatamanage.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.common.core.domain.R;
import com.core.common.utils.MessageUtils;
import com.openhis.common.constant.PromptMsgConstant;
import com.openhis.web.basedatamanage.appservice.IBodyStructureAppService;
import com.openhis.web.basedatamanage.dto.BodyStructureDto;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 身体部位管理controller
 *
 * @author
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/base-data-manage/body-structure")
@Slf4j
@AllArgsConstructor
public class BodyStructureController {

    private final IBodyStructureAppService bodyStructureService;

    /**
     * 身体部位分页列表
     *
     * @param pageNo 当前页码
     * @param pageSize 查询条数
     * @return 身体部位分页列表
     */
    @GetMapping(value = "/body")
    public R<?> getBodyStructurePage(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
        @RequestParam(value = "pageSize", defaultValue = "100") Integer pageSize, HttpServletRequest request) {
        Page<BodyStructureDto> bodyStructureTree = bodyStructureService.getBodyStructureTree(pageNo, pageSize, request);
        return R.ok(bodyStructureTree,
            MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"身体部位信息"}));
    }

    /**
     * 获取身体部位需要编辑的信息
     *
     * @param id 身体部位信息
     * @return 操作结果
     */
    @GetMapping("/body-getById")
    public R<?> getOrgInfo(@Validated @RequestParam Long id) {
        return bodyStructureService.getBodyStructureInfo(id);
    }

    /**
     * 添加/编辑身体部位
     *
     * @param bodyStructureDto 身体部位信息
     * @return 操作结果
     */
    @PostMapping("/body")
    public R<?> addOrEditInventoryReceipt(@Validated @RequestBody BodyStructureDto bodyStructureDto) {
        return bodyStructureService.addOrEditBodyStructure(bodyStructureDto);
    }

    /**
     * 删除身体部位
     *
     * @param ids 需要删除的Id
     * @return 操作结果
     */
    @DeleteMapping("/body")
    public R<?> deleteBodyStructure(@RequestParam String ids) {
        return bodyStructureService.deleteBodyStructure(ids);
    }

    /**
     * 身体部位启用
     * 
     * @param id 启用数据的Id
     * @return 操作结果
     *
     */
    @PutMapping("/body-active")
    public R<?> activeBodyStructure(@RequestParam Long id) {
        return bodyStructureService.activeBodyStructure(id);
    }

    /**
     * 身体部位停用
     * 
     * @param id 停用数据的Id
     * @return 操作结果
     *
     */
    @PutMapping("/body-inactive")
    public R<?> inactiveBodyStructure(@RequestParam Long id) {
        return bodyStructureService.inactiveBodyStructure(id);
    }

}
