package com.lantone.daqe.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.daqe.dto.GetDrugByIdDTO;
import com.lantone.daqe.dto.GetDrugPageDTO;
import com.lantone.daqe.dto.GetMatchingDrugPageDTO;
import com.lantone.daqe.facade.DrugManagementFacade;
import com.lantone.daqe.vo.AddDrugVO;
import com.lantone.daqe.vo.DelDrugByIdVO;
import com.lantone.daqe.vo.GetDrugByIdVO;
import com.lantone.daqe.vo.GetDrugPageVO;
import com.lantone.daqe.vo.GetMatchingDrugPageVO;
import com.lantone.daqe.vo.MatchingDrugVO;
import com.lantone.daqe.vo.UpDrugByIdVO;
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("/drugManage")
public class DrugManagementController {

    @Autowired
    private DrugManagementFacade drugManagementFacade;

    @ApiOperation(value = "获取药品分页列表 [by:songxl]")
    @PostMapping("/getDrugPage")
    public CommonResult<IPage<GetDrugPageDTO>> getDrugPage(@RequestBody GetDrugPageVO getDrugPageVO) {
        return CommonResult.success(drugManagementFacade.getDrugPage(getDrugPageVO));
    }

    @ApiOperation(value = "新增药品 [by:songxl]")
    @PostMapping("/addDrug")
    public CommonResult<Boolean> addDrug(@RequestBody @Valid AddDrugVO addDrugVO) {
        return CommonResult.success(drugManagementFacade.addDrug(addDrugVO));
    }

    @ApiOperation(value = "通过id修改药品 [by:songxl]")
    @PostMapping("/upDrugById")
    public CommonResult<Boolean> upDrugById(@RequestBody @Valid UpDrugByIdVO upDrugByIdVO) {
        return CommonResult.success(drugManagementFacade.upDrugById(upDrugByIdVO));
    }

    @ApiOperation(value = "通过id删除药品 [by:songxl]")
    @PostMapping("/delDrugById")
    public CommonResult<Boolean> delDrugById(@RequestBody @Valid DelDrugByIdVO delDrugByIdVO) {
        return CommonResult.success(drugManagementFacade.delDrugById(delDrugByIdVO));
    }

    @ApiOperation(value = "匹配药品信息 [by:songxl]")
    @PostMapping("/matchingDrug")
    public CommonResult<Boolean> matchingDrug(@RequestBody @Valid MatchingDrugVO matchingDrugVO) {
        return CommonResult.success(drugManagementFacade.matchingDrug(matchingDrugVO));
    }

    @ApiOperation(value = "药品匹配信息导入 [by:songxl]", notes = "药品匹配信息导入")
    @PostMapping("/importDrug")
    @Transactional
    public void importDrug(HttpServletResponse response, @RequestParam("file") MultipartFile file) {
        drugManagementFacade.importDrug(response, file);
    }

    @ApiOperation(value = "获取药品匹配分页列表 [by:songxl]")
    @PostMapping("/getMatchingDrugPage")
    public CommonResult<IPage<GetMatchingDrugPageDTO>> getMatchingDrugPage(@RequestBody GetMatchingDrugPageVO getMatchingDrugPageVO) {
        return CommonResult.success(drugManagementFacade.getMatchingDrugPage(getMatchingDrugPageVO));
    }

    @ApiOperation(value = "已匹配药品信息查看 [by:songxl]")
    @PostMapping("/getDrugById")
    public CommonResult<GetDrugByIdDTO> getDrugById(@RequestBody GetDrugByIdVO getDrugByIdVO) {
        return CommonResult.success(drugManagementFacade.getDrugById(getDrugByIdVO));
    }

}