package com.lantone.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.security.dto.ViewRegionDTO;
import com.lantone.security.vo.CheckSolveRegionVO;
import com.lantone.security.vo.GetRegionVO;
import com.lantone.security.vo.SaveRegionVO;
import com.lantone.security.vo.UpdateRegionVO;
import com.lantone.security.facade.RegionManagementFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @Description: 病区管理API
 * @author: cy
 * @time: 2021/7/20 12:39
 */
@RestController
@Api(value = "病区管理API", tags = { "病区管理API" })
@RequestMapping("/regionManage")
public class RegionManagementController {
    @Autowired
    private RegionManagementFacade sysRegionFacade;

    @ApiOperation(value = "新增病区[by:cy]")
    @PostMapping("/addRegion")
    @Transactional
    public CommonResult<Object> addRegion(@RequestBody @Valid SaveRegionVO saveRegionVo) {
        return CommonResult.success(sysRegionFacade.addRegion(saveRegionVo));
    }

    @ApiOperation(value = "修改病区[by:cy]")
    @PostMapping("/updateRegion")
    @Transactional
    public CommonResult<Object> updateRegion(@RequestBody UpdateRegionVO updateRegionVO) {
        return CommonResult.success(sysRegionFacade.updateRegion(updateRegionVO));
    }

    @ApiOperation(value = "校验/禁用/启用病区管理[by:cy]")
    @PostMapping("/checkSolveRegion")
    public CommonResult<Object> checkSolveRegion(@RequestBody @Valid CheckSolveRegionVO checkSolveRegionVO) {
        return CommonResult.success(sysRegionFacade.checkSolveRegion(checkSolveRegionVO));
    }


    @ApiOperation(value = "查看病区管理[by:cy]")
    @PostMapping("/getRegion")
    public CommonResult<IPage<ViewRegionDTO>> getRegion(@RequestBody GetRegionVO getRegionVO) {
        return CommonResult.success(sysRegionFacade.getRegion(getRegionVO));
    }


    @ApiOperation(value = "删除病区管理[by:cy]")
    @PostMapping("/deleteRegion")
    @Transactional
    public CommonResult<Boolean> deleteRegion(@RequestParam @Valid @NotNull(message = "病区id为空") Integer id) {
        return CommonResult.success(sysRegionFacade.deleteRegion(id));
    }
}
