package com.diagbot.web;


import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.ConceptDTO;
import com.diagbot.dto.LibraryInfoDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.Concept;
import com.diagbot.facade.ConceptFacade;
import com.diagbot.vo.AmendTermVo;
import com.diagbot.vo.ConceptVo;
import com.diagbot.vo.TermVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.baomidou.mybatisplus.core.metadata.*;

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

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Weixuan Huang
 * @since 2019-01-30
 */
@RestController
@RequestMapping("/concept")
@Api(value = "医学标准术语API", tags = { "医学标准术语API" })

public class ConceptController {
    @Autowired
    private ConceptFacade conceptFacade;


    @ApiOperation(value = "查询所有术语名称")
    @PostMapping("getAllConcept")
    @SysLogger("getAllConcept")
    public RespDTO<IPage<LibraryInfoDTO>> getAllConcept(@RequestBody ConceptVo conceptVo) {
        IPage<LibraryInfoDTO> data = conceptFacade.getAllConcepts(conceptVo);

        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "查询所有术语信息",
            notes = "Term：术语名称, 选填<br>Type：术语类型, 选填<br>")
    @PostMapping("getAllInformation")
    @SysLogger("getAllInformation")
    public RespDTO<IPage<LibraryInfoDTO>> getAllInformation(@RequestBody ConceptVo conceptVo) {
        IPage<LibraryInfoDTO> data = conceptFacade.getAllInformation(conceptVo);

        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "术语基本信息查询",
            notes = "Term：术语名称, 必填<br>Type：术语类型, 必填<br>")
    @PostMapping("/getConceptInfo")
    @SysLogger("getConceptInfo")
    public RespDTO<List<ConceptDTO>> getConceptInfo(@Valid @RequestBody TermVo termvo) {
        List<ConceptDTO> data = conceptFacade.getConceptInfo(termvo);

        return RespDTO.onSuc(data);
    }

    /*
    @ApiOperation(value = "术语静态知识查询",
            notes = "Term：术语名称, 必填<br>Type：术语类型, 必填<br>")
    @PostMapping("/getConceptKnowledge")
    @SysLogger("getConceptKnowledge")
    public RespDTO<TermDTO> getConceptKnowledge(@Valid @RequestBody TermVo termvo) {
        ConceptDTO data = conceptFacade.getConceptKnowledge(termvo);

        return RespDTO.onSuc(data);
    }
    */


    @ApiOperation(value = "术语基本信息删除",
            notes = "Term：术语名称, 必填<br>Type：术语类型, 必填<br>")
    @PostMapping("/removeConceptInfo")
    @SysLogger("removeConceptInfo")
    public RespDTO<ConceptDTO> removeConceptInfo(@Valid @RequestBody TermVo termvo) {
        ConceptDTO data = conceptFacade.removeConceptInfo(termvo);

        return RespDTO.onSuc(data);
    }

    /*
    @ApiOperation(value = "术语医学关系查询",
            notes = "Term：术语名称, 必填<br>Type：术语类型, 必填<br>")
    @PostMapping("/getConceptRelation")
    @SysLogger("getConceptRelation")
    public RespDTO<TermDTO> getConceptRelation(@Valid @RequestBody TermVo termvo) {
        ConceptDTO data = conceptFacade.getConceptRelation(termvo);

        return RespDTO.onSuc(data);
    }
    */

    @ApiOperation(value = "术语基本信息添加或修改",
            notes = "Concept: 概念名称，必填<br/>NewTerm: 新的术语名称, 必填<br/>" +
                    "NewType: 新的术语类型, 必填<br/>")
    @PostMapping("/upsertConceptInfo")
    @SysLogger("upsertConceptInfo")
    public RespDTO<ConceptDTO> upsertConceptInfo(@Valid @RequestBody AmendTermVo amendTermVo) {
        ConceptDTO data = conceptFacade.upsertConceptInfo(amendTermVo);

        return RespDTO.onSuc(data);
    }


    @ApiOperation(value = "术语导入", notes = "导入术语信息")
    @PostMapping("/importTermExcel")
    public RespDTO<ConceptDTO> lisExcelAnalysis(@RequestParam("uploadfile") MultipartFile file) {
        ConceptDTO data = conceptFacade.importBatch(file);

        return RespDTO.onSuc(data);
    }

}
