package com.lantone.security.web;


import com.lantone.common.api.CommonResult;
import com.lantone.security.dto.GetHospitalByIdDTO;
import com.lantone.security.dto.GetHospitalListInfoDTO;
import com.lantone.security.vo.AddHospitalVO;
import com.lantone.security.vo.GetHospitalListInfoVO;
import com.lantone.security.vo.UpdateHospitalVO;
import com.lantone.security.facade.HospitalManagementFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
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.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * 组织管理API
 */
@RestController
@Api(value = "组织管理API", tags = "组织管理API")
@RequestMapping("/hospitalManage")
@EnableAsync
public class HospitalManagementController {
    @Autowired
    private HospitalManagementFacade hospitalManagementFacade;
    @ApiOperation(value = "添加组织 [by:songxl]")
    @PostMapping("/addHospital")
    @Transactional
    public CommonResult<Boolean> addHospital(@RequestBody @Valid AddHospitalVO addHospitalVO) {
        return CommonResult.success(hospitalManagementFacade.addHospital(addHospitalVO));
    }
    @ApiOperation(value = "修改组织 [by:songxl]")
    @PostMapping("/updateHospital")
    @Transactional
    public CommonResult<Boolean> updateHospital(@RequestBody @Valid UpdateHospitalVO updateHospitalVO) {
        return CommonResult.success(hospitalManagementFacade.updateHospital(updateHospitalVO));
    }

    @ApiOperation(value = "删除组织 [by:songxl]",
            notes = "type:组织机构类型（0:AI病案质控平台 1:集团医院 2:医共 3:医联 4:医院 5:科室），必填<br>")
    @PostMapping("/deleteHospital")
    @Transactional
    public CommonResult<Boolean> deleteHospital(@RequestParam @Valid @NotNull(message = "组织编号为空") Long HospitalId,
                                                @RequestParam @Valid @NotBlank(message = "组织机构类型为空") String type) {
        return CommonResult.success(hospitalManagementFacade.deleteHospital(HospitalId,type));
    }


    @ApiOperation(value = "禁用|启用组织 [by:songxl]",
            notes = "type:组织机构类型（0:AI病案质控平台 1:集团医院 2:医共 3:医联 4:医院 5:科室），必填<br>")
    @PostMapping("/disableHospital")
    @Transactional
    public CommonResult<Boolean> disableHospital(@RequestParam @Valid @NotNull(message = "组织编号为空") Long HospitalId,
                                                 @RequestParam @Valid @NotBlank(message = "启用禁用status为空") String status,
                                                 @RequestParam @Valid @NotBlank(message = "组织机构类型为空") String type) {
        return CommonResult.success(hospitalManagementFacade.disableHospital(HospitalId,status,type));
    }

    @ApiOperation(value = "查看功能 [by:songxl]",
            notes = "type:组织机构类型（0:AI病案质控平台 1:集团医院 2:医共 3:医联 4:医院 5:科室），必填<br>")
    @PostMapping("/getHospitalById")
    public CommonResult<GetHospitalByIdDTO> getHospitalById(@RequestParam @Valid @NotNull(message = "组织编号为空") Long HospitalId,@RequestParam @Valid @NotNull(message = "组织类型为空") int type) {
        return CommonResult.success(hospitalManagementFacade.getHospitalById(HospitalId,type));
    }

    @ApiOperation(value = "组织管理列表页管理员下拉框筛选类型、病区、职称查询 [by:songxl]")
    @PostMapping("/getManagerBoxInfo")
    public CommonResult<Map<String,Object>> getManagerBoxInfo() {
        return CommonResult.success(hospitalManagementFacade.getManagerBoxInfo());
    }
    @ApiOperation(value = "组织管理列表页查询 [by:songxl]")
    @PostMapping("/getHospitalListInfo")
    public CommonResult<List<GetHospitalListInfoDTO>> getHospitalListInfo(@RequestBody GetHospitalListInfoVO getHospitalListInfoVO) {
        return CommonResult.success(hospitalManagementFacade.getHospitalListInfo(getHospitalListInfoVO));
    }

    @ApiOperation(value = "重置密码 [by:songxl]")
    @PostMapping("/resetPassword")
    @Transactional
    public CommonResult<Boolean> resetPassword(@RequestParam @Valid @NotNull(message = "组织编号为空") Long HospitalId) {
        return CommonResult.success(hospitalManagementFacade.resetPassword(HospitalId));
    }
}
