package com.lantone.daqe.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.daqe.dto.GetMatchingOperationPageDTO;
import com.lantone.daqe.dto.GetOperationByIdDTO;
import com.lantone.daqe.dto.GetOperationPageDTO;
import com.lantone.daqe.facade.OperationManagementFacade;
import com.lantone.daqe.vo.AddOperationVO;
import com.lantone.daqe.vo.DelOperationByIdVO;
import com.lantone.daqe.vo.GetMatchingOperationVO;
import com.lantone.daqe.vo.GetOperationByIdVO;
import com.lantone.daqe.vo.GetOperationPageVO;
import com.lantone.daqe.vo.MatchingOperationVO;
import com.lantone.daqe.vo.UpOperationByIdVO;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Description: 手术管理API
 * @author: songxl
 * @time: 2021/7/20 12:39
 */
@RestController
@Api(value = "手术管理API", tags = { "手术管理API" })
@RequestMapping("/operationManage")
public class OperationManagementController {

    @Autowired
    private OperationManagementFacade operationManagementFacade;

    @ApiOperation(value = "获取手术分页列表 [by:songxl]")
    @PostMapping("/getOperationPage")
    public CommonResult<IPage<GetOperationPageDTO>> getOperationPage(@RequestBody GetOperationPageVO getOperationPageVO) {
        return CommonResult.success(operationManagementFacade.getOperationPage(getOperationPageVO));
    }

    @ApiOperation(value = "新增手术 [by:songxl]")
    @PostMapping("/addOperation")
    public CommonResult<Boolean> addOperation(@RequestBody @Valid AddOperationVO addOperationVO) {
        return CommonResult.success(operationManagementFacade.addOperation(addOperationVO));
    }

    @ApiOperation(value = "通过id修改手术 [by:songxl]")
    @PostMapping("/upOperationById")
    public CommonResult<Boolean> upOperationById(@RequestBody @Valid UpOperationByIdVO upOperationByIdVO) {
        return CommonResult.success(operationManagementFacade.upOperationById(upOperationByIdVO));
    }

    @ApiOperation(value = "通过id删除手术 [by:songxl]")
    @PostMapping("/delOperationById")
    public CommonResult<Boolean> delOperationById(@RequestBody @Valid DelOperationByIdVO delOperationByIdVO) {
        return CommonResult.success(operationManagementFacade.delOperationById(delOperationByIdVO));
    }

    @ApiOperation(value = "匹配手术信息 [by:songxl]", notes = "匹配手术信息")
    @PostMapping("/matchingOperation")
    public CommonResult<Boolean> matchingOperation(@RequestBody MatchingOperationVO matchingOperationVO) {
        return CommonResult.success(operationManagementFacade.matchingOperation(matchingOperationVO));
    }

    @ApiOperation(value = "医院手术标准词匹配信息导入 [by:songxl]", notes = "医院手术标准词匹配信息导入")
    @PostMapping("/importOperation")
    @Transactional
    public void importOperation(HttpServletResponse response, @RequestParam("file") MultipartFile file) {
        operationManagementFacade.importOperation(response, file);
    }

    @ApiOperation(value = "获取手术匹配信息分页列表 [by:songxl]")
    @PostMapping("/getMatchingOperationPage")
    public CommonResult<IPage<GetMatchingOperationPageDTO>> getMatchingOperationPage(@RequestBody GetMatchingOperationVO getMatchingOperationVO) {
        return CommonResult.success(operationManagementFacade.getMatchingOperationPage(getMatchingOperationVO));
    }

    @ApiOperation(value = "手术匹配信息查看 [by:songxl]")
    @PostMapping("/getOperationById")
    public CommonResult<GetOperationByIdDTO> getOperationById(@RequestBody GetOperationByIdVO getOperationByIdVO) {
        return CommonResult.success(operationManagementFacade.getOperationById(getOperationByIdVO));
    }

}