package com.lantone.daqe.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.daqe.dto.GetDiseaseInfoByIdDTO;
import com.lantone.daqe.dto.GetDiseasePageDTO;
import com.lantone.daqe.dto.GetMatchingDiseasePageDTO;
import com.lantone.daqe.facade.DiseaseManagementFacade;
import com.lantone.daqe.vo.AddDiseaseVO;
import com.lantone.daqe.vo.DelDiseaseByIdVO;
import com.lantone.daqe.vo.GetDiseaseInfoByIdVO;
import com.lantone.daqe.vo.GetDiseasePageVO;
import com.lantone.daqe.vo.GetMatchingDiseasePageVO;
import com.lantone.daqe.vo.MatchingDiseaseVO;
import com.lantone.daqe.vo.UpDiseaseByIdVO;
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("/diseaseManage")
public class DiseaseManagementController {

    @Autowired
    private DiseaseManagementFacade diseaseManagementFacade;

    @ApiOperation(value = "获取诊断分页列表 [by:songxl]", notes = "获取诊断分页列表")
    @PostMapping("/getDiseasePage")
    public CommonResult<IPage<GetDiseasePageDTO>> getDiseasePage(@RequestBody GetDiseasePageVO getDiseasePageVO) {
        return CommonResult.success(diseaseManagementFacade.getDiseasePage(getDiseasePageVO));
    }

    @ApiOperation(value = "新增诊断 [by:songxl]", notes = "新增诊断")
    @PostMapping("/addDisease")
    public CommonResult<Boolean> addDisease(@RequestBody @Valid AddDiseaseVO addDiseaseVO) {
        return CommonResult.success(diseaseManagementFacade.addDisease(addDiseaseVO));
    }

    @ApiOperation(value = "通过id修改诊断 [by:songxl]", notes = "通过id修改诊断")
    @PostMapping("/upDiseaseById")
    public CommonResult<Boolean> upDiseaseById(@RequestBody @Valid UpDiseaseByIdVO upDiseaseByIdVO) {
        return CommonResult.success(diseaseManagementFacade.upDiseaseById(upDiseaseByIdVO));
    }

    @ApiOperation(value = "通过id删除诊断 [by:songxl]", notes = "通过id删除诊断")
    @PostMapping("/delDiseaseById")
    public CommonResult<Boolean> delDiseaseById(@RequestBody @Valid DelDiseaseByIdVO delDiseaseByIdVO) {
        return CommonResult.success(diseaseManagementFacade.delDiseaseById(delDiseaseByIdVO));
    }

    @ApiOperation(value = "匹配诊断信息列表 [by:songxl]", notes = "匹配诊断信息列表")
    @PostMapping("/getMatchingDiseasePage")
    public CommonResult<IPage<GetMatchingDiseasePageDTO>> getMatchingDiseasePage(@RequestBody GetMatchingDiseasePageVO getMatchingDiseasePageVO) {
        return CommonResult.success(diseaseManagementFacade.getMatchingDiseasePage(getMatchingDiseasePageVO));
    }

    @ApiOperation(value = "匹配诊断 [by:songxl]", notes = "匹配诊断")
    @PostMapping("/matchingDisease")
    public CommonResult<Boolean> matchingDisease(@RequestBody MatchingDiseaseVO matchingDiseaseVO) {
        return CommonResult.success(diseaseManagementFacade.matchingDisease(matchingDiseaseVO));
    }

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

    @ApiOperation(value = "已匹配诊断信息查看 [by:songxl]", notes = "已匹配诊断信息查看")
    @PostMapping("/getDiseaseInfoById")
    public CommonResult<GetDiseaseInfoByIdDTO> getDiseaseInfoById(@RequestBody GetDiseaseInfoByIdVO getDiseaseInfoByIdVO) {
        return CommonResult.success(diseaseManagementFacade.getDiseaseInfoById(getDiseaseInfoByIdVO));
    }
}