package com.diagbot.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.QcCasesEntrySimpleDTO;
import com.diagbot.dto.QcTypeDTO;
import com.diagbot.dto.QcTypePageDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.QcQuestionInfo;
import com.diagbot.facade.QcTypeFacade;
import com.diagbot.vo.DeleteQcTypeVO;
import com.diagbot.vo.QcEntryHospitalVO;
import com.diagbot.vo.QcTypeIndexVO;
import com.diagbot.vo.QcTypePageVO;
import com.diagbot.vo.QcTypeSaveVO;
import com.diagbot.vo.QcTypeVO;
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 springfox.documentation.annotations.ApiIgnore;

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

/**
 * <p>
 * 质控类型标准 前端控制器
 * </p>
 *
 * @author zhoutg
 * @since 2020-05-14
 */
@RestController
@RequestMapping("/qc/qcType")
@SuppressWarnings("unchecked")
@Api(value = "质控类型相关API", tags = { "质控类型相关API" })
public class QcTypeController {

    @Autowired
    QcTypeFacade qcTypeFacade;

    @ApiOperation(value = "新增或更新[by:gaodm]",
            notes = "")
    @PostMapping("/saveOrUpdate")
    @SysLogger("saveOrUpdate")
    @Transactional
    public RespDTO<Boolean> saveOrUpdate(@RequestBody QcTypeSaveVO qcTypeSaveVO) {
        qcTypeFacade.saveOrUpdate(qcTypeSaveVO);
        return RespDTO.onSuc(true);
    }
    @ApiOperation(value = "质控类型-新增[by:gaodm]",
            notes = "")
    @PostMapping("/add")
    @SysLogger("add")
    @Transactional
    public RespDTO<Boolean> add(@RequestBody QcTypeSaveVO qcTypeSaveVO) {
        qcTypeFacade.saveOrUpdate(qcTypeSaveVO);
        return RespDTO.onSuc(true);
    }
    @ApiOperation(value = "质控类型-更新[by:gaodm]",
            notes = "")
    @PostMapping("/update")
    @SysLogger("update")
    @Transactional
    public RespDTO<Boolean> update(@RequestBody QcTypeSaveVO qcTypeSaveVO) {
        qcTypeFacade.saveOrUpdate(qcTypeSaveVO);
        return RespDTO.onSuc(true);
    }
    @ApiOperation(value = "质控类型-复制[by:gaodm]",
            notes = "")
    @PostMapping("/copy")
    @SysLogger("copy")
    @Transactional
    public RespDTO<Boolean> copy(@RequestBody QcTypeSaveVO qcTypeSaveVO) {
        qcTypeFacade.saveOrUpdate(qcTypeSaveVO);
        return RespDTO.onSuc(true);
    }

    @ApiOperation(value = "分页列表[by:gaodm]",
            notes = "    // 名称\n" +
                    "     String name;")
    @PostMapping("/page")
    @SysLogger("page")
    public RespDTO<IPage<QcTypePageDTO>> list(@RequestBody QcTypePageVO qcTypePageVO) {
        IPage<QcTypePageDTO> data = qcTypeFacade.getListFac(qcTypePageVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "新增时质控条目分组信息[by:gaodm]",
            notes = "")
    @PostMapping("/getEntryByHospital")
    @SysLogger("getEntryByHospital")
    public RespDTO<Map<String, List<QcCasesEntrySimpleDTO>>> getEntryByHospital(@RequestBody QcEntryHospitalVO qcEntryHospitalVO) {
        Map<String, List<QcCasesEntrySimpleDTO>> data = qcTypeFacade.getEntryByHospital(qcEntryHospitalVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "质控条目检索[by:gaodm]",
            notes = "    // 界面输入\n" +
                    "     String input;\n" +
                    "    // 过滤caseEntryId\n" +
                    "     List<Long> notIds;")
    @PostMapping("/index")
    @SysLogger("index")
    @ApiIgnore
    public RespDTO<List<QcQuestionInfo>> index(@RequestBody QcTypeIndexVO qcTypeIndexVO) {
        List<QcCasesEntrySimpleDTO> data = qcTypeFacade.indexFac(qcTypeIndexVO);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "删除[by:gaodm]",
            notes = "")
    @PostMapping("/delete")
    @SysLogger("delete")
    @Transactional
    public RespDTO<Boolean> delete(@Valid @RequestBody DeleteQcTypeVO deleteQcTypeVO) {
        qcTypeFacade.deleteByIdsFac(deleteQcTypeVO);
        return RespDTO.onSuc(true);
    }

    @ApiOperation(value = "根据id返回内容[by:gaodm]",
            notes = "id: qcTypeId<br>" )
    @PostMapping("/getById")
    @SysLogger("getById")
    public RespDTO<QcTypeDTO> getById(@RequestBody QcTypeVO qcTypeVO) {
        QcTypeDTO data = qcTypeFacade.getById(qcTypeVO);
        return RespDTO.onSuc(data);
    }
}
