package com.diagbot.web;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.AnalyzeDTO;
import com.diagbot.dto.GetDefectDeptDTO;
import com.diagbot.dto.GetMedDefectFeedbackPageDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.his.DoctorHosDTO;
import com.diagbot.facade.MedDefectFeedbackFacade;
import com.diagbot.facade.SysDictionaryFacade;
import com.diagbot.facade.his.DoctorHosFacade;
import com.diagbot.util.SysUserUtils;
import com.diagbot.vo.ChangeQcResultVO;
import com.diagbot.vo.GetDefectDeptModeVO;
import com.diagbot.vo.GetMedDefectFeedbackPageVO;
import com.diagbot.vo.UPdDefectBackByIDVO;
import com.diagbot.vo.his.DoctorHosVO;
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.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 缺陷反馈表 前端控制器
 * </p>
 *
 * @author songxl
 * @since 2022-04-21
 */
@RestController
@RequestMapping("/medDefectFeedback")
@Api(value = "缺陷反馈模块相关接口API", tags = { "缺陷反馈模块相关接口API" })
public class MedDefectFeedbackController {
    @Autowired
    private DoctorHosFacade doctorHosFacade;
    @Autowired
    private MedDefectFeedbackFacade medDefectFeedbackFacade;
    @Autowired
    private SysDictionaryFacade sysDictionaryFacade;

    @ApiOperation(value = "获取His医生信息[by:songxl]",
            notes = "获取His医生信息")
    @PostMapping("/getHisDoctorInfo")
    @SysLogger("getHisDoctorInfo")
    public RespDTO<List<DoctorHosDTO>> getDoctorInfo(@RequestBody DoctorHosVO doctorHosVO) {
        return RespDTO.onSuc(doctorHosFacade.getDoctorInfo(doctorHosVO));
    }

    @ApiOperation(value = "新增已有质控条目[by:songxl]",
            notes = "optResultAlgVO：操作条目，casesEntryId、msg、score必填<br>")
    @PostMapping("/addHavingCase")
    @SysLogger("addHavingCase")
    @Transactional
    public RespDTO<AnalyzeDTO> addHavingCase(@RequestBody @Valid ChangeQcResultVO changeQcResultVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.changeQcResult(changeQcResultVO));
    }

    @ApiOperation(value = "新增缺失质控条目[by:songxl]",
            notes = "")
    @PostMapping("/addNotHavingCase")
    @SysLogger("addNotHavingCase")
    @Transactional
    public RespDTO<AnalyzeDTO> addNotHavingCase(@RequestBody @Valid ChangeQcResultVO changeQcResultVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.changeQcResult(changeQcResultVO));
    }


    @ApiOperation(value = "删除质控条目[by:songxl]",
            notes = "optResultAlgVO：操作条目，casesEntryId、msg、score必填<br>")
    @PostMapping("/delCase")
    @SysLogger("delCase")
    @Transactional
    public RespDTO<AnalyzeDTO> delCase(@RequestBody @Valid ChangeQcResultVO changeQcResultVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.changeQcResult(changeQcResultVO));
    }

    @ApiOperation(value = "恢复质控条目[by:songxl]",
            notes = "optResultAlgVO：操作条目，casesEntryId、msg、score必填<br>")
    @PostMapping("/recoverCase")
    @SysLogger("recoverCase")
    @Transactional
    public RespDTO<AnalyzeDTO> recoverCase(@RequestBody @Valid ChangeQcResultVO changeQcResultVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.changeQcResult(changeQcResultVO));
    }

    @ApiOperation(value = "修改质控条目[by:songxl]",
            notes = "optResultAlgVO：操作条目，casesEntryId、msg、score必填<br>")
    @PostMapping("/updCase")
    @SysLogger("updCase")
    @Transactional
    public RespDTO<AnalyzeDTO> updCase(@RequestBody @Valid ChangeQcResultVO changeQcResultVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.changeQcResult(changeQcResultVO));
    }

    @ApiOperation(value = "确认缺陷反馈[by:songxl]",
            notes = "")
    @PostMapping("/updDefectBackByID")
    @SysLogger("updDefectBackByID")
    @Transactional
    public RespDTO<Boolean> updDefectBackByID(@RequestBody @Valid UPdDefectBackByIDVO uPdDefectBackByIDVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.updDefectBackByID(uPdDefectBackByIDVO));
    }


    @ApiOperation(value = "获取缺陷反馈记录列表操作类型、状态下拉框内容[by:zhanghang]",
            notes = "获取缺陷反馈记录列表操作类型、状态下拉框内容")
    @PostMapping("/getOperationType")
    public RespDTO<Map<String, String>> getOperationStatusType() {
        Map<String, Map<String, String>> operationStatusType = sysDictionaryFacade.getOperationStatusType("36", "缺陷反馈");
        return RespDTO.onSuc(operationStatusType);
    }

    @ApiOperation(value = "获取缺陷反馈记录[by:zhanghang]",
            notes = "获取缺陷反馈记录列表")
    @PostMapping("/getMedDefectFeedbackPage")
    public RespDTO<Page<GetMedDefectFeedbackPageDTO>> getMedDefectFeedbackPage(@RequestBody GetMedDefectFeedbackPageVO getMedDefectFeedbackPageVO) {
        String hospitalID = SysUserUtils.getCurrentHospitalID();
        getMedDefectFeedbackPageVO.setHospitalId(Long.valueOf(hospitalID));
        return RespDTO.onSuc(medDefectFeedbackFacade.getMedDefectFeedbackPage(getMedDefectFeedbackPageVO));
    }

    @ApiOperation(value = "获取缺陷反馈记录列表-科室下拉框内容[by:zhanghang]",
            notes = "获取缺陷反馈记录列表-科室下拉框内容")
    @PostMapping("/getDefectDept")
    public RespDTO<List<GetDefectDeptDTO>> getDefectDept(@RequestBody GetDefectDeptModeVO getDefectDeptModeVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.getDefectDept(getDefectDeptModeVO));
    }

    @ApiOperation(value = "获取缺陷反馈记录列表-缺陷模块下拉框内容[by:zhanghang]",
            notes = "获取缺陷反馈记录列表-缺陷模块下拉框内容")
    @PostMapping("/getDefectMode")
    public RespDTO<List<GetDefectDeptDTO>> getDefectMode(@RequestBody GetDefectDeptModeVO getDefectDeptModeVO) {
        return RespDTO.onSuc(medDefectFeedbackFacade.getDefectMode(getDefectDeptModeVO));
    }

}
