package com.lantone.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.security.dto.GetRealHospitalDTO;
import com.lantone.security.vo.GetHospitalSetVO;
import com.lantone.security.vo.SaveHospitalSetVO;
import com.lantone.security.entity.HospitalSet;
import com.lantone.security.facade.HospitalSetManagementFacade;
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 springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Description: 参数管理API
 * @author: cy
 * @time: 2021/7/20 12:39
 */
@RestController
@Api(value = "参数管理API", tags = { "参数管理API" })
@RequestMapping("/hospitalSetManage")
public class HospitalSetManagementController {
    @Autowired
    private HospitalSetManagementFacade hospitalSetManagementFacade;

    @ApiOperation(value = "新增参数[by:cy]")
    @PostMapping("/addHospitalSet")
    @Transactional
    public CommonResult<Object> addHospitalSet(@RequestBody @Valid SaveHospitalSetVO saveHospitalSetVO) {
        return CommonResult.success(hospitalSetManagementFacade.addHospitalSet(saveHospitalSetVO));
    }

    @ApiOperation(value = "修改参数[by:cy]")
    @PostMapping("/updateHospitalSet")
    @Transactional
    public CommonResult<Object> updateHospitalSet(@RequestBody @Valid SaveHospitalSetVO saveHospitalSetVO) {
        return CommonResult.success(hospitalSetManagementFacade.updateHospitalSet(saveHospitalSetVO));
    }

    @ApiOperation(value = "查看参数管理[by:cy]")
    @PostMapping("/getHospitalSet")
    public CommonResult<IPage<HospitalSet>> getDictionary(@RequestBody GetHospitalSetVO getHospitalSetVO) {
        return CommonResult.success(hospitalSetManagementFacade.getHospitalSet(getHospitalSetVO));
    }

    @ApiOperation(value = "删除参数管理[by:cy]")
    @PostMapping("/deleteHospitalSet")
    @Transactional
    public CommonResult<Boolean> deleteHospitalSet(@RequestParam("id") @Valid @NotNull(message = "参数id不能为空") Integer id) {
        return CommonResult.success(hospitalSetManagementFacade.deleteHospitalSet(id));
    }

    @ApiOperation(value = "查看参数管理所属组织[by:cy]")
    @PostMapping("/getHospitalNames")
    public CommonResult<List<GetRealHospitalDTO>> getHospitalNames(@RequestParam("hospitalName") String hospitalName) {
        return CommonResult.success(hospitalSetManagementFacade.getHospitalNames(hospitalName));
    }

    @ApiOperation(value = "加载所有组织机构参数配置信息[by:cy]")
    @PostMapping("/initHospitalSetMap")
    @ApiIgnore
    public CommonResult<Boolean> initHospitalSetMap() {
        return CommonResult.success(hospitalSetManagementFacade.initHospitalSetMap());
    }

}