package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.*;
import com.diagbot.facade.LibraryDetailFacade;
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 javax.validation.Valid;


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

public class LibraryDetailController {
    @Autowired
    private LibraryDetailFacade libraryDetailFacade;

    @ApiOperation(value = "查询所有术语静态知识")
    @PostMapping("getAllKnowledge")
    @SysLogger("getAllKnowledge")
    public RespDTO<IPage<LibraryDetailDTO>> getAllKnowledge(@RequestBody ConceptVo conceptVo) {
        IPage<LibraryDetailDTO> data = libraryDetailFacade.getAllLibraryDetail(conceptVo);

        return RespDTO.onSuc(data);
    }


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

        return RespDTO.onSuc(data);
    }


    @ApiOperation(value = "术语静态知识修改",
            notes = "OldTerm: 原来的术语名称, 必填<br/>NewTerm: 新的术语名称, 必填<br/>" +
                    "OldType: 原来的术语类型, 必填<br/>NewType: 新的术语类型, 必填<br/>")
    @PostMapping("/upsertConceptKnowledge")
    @SysLogger("upsertConceptKnowledge")
    public RespDTO<ConceptDTO> upsertConceptKnowledge(@Valid @RequestBody AmendTermVo amendTermVo) {
        ConceptDTO data = libraryDetailFacade.upsertConceptKnowledge(amendTermVo);

        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "术语静态知识删除",
            notes = "Term: 术语名称, 必填<br/>Type: 术语类型, 必填<br/>")
    @PostMapping("/removeConceptKnowledge")
    @SysLogger("removeConceptKnowledge")
    public RespDTO<ConceptDTO> removeConceptKnowledge(@Valid @RequestBody TermVo termVo) {
        Boolean result = libraryDetailFacade.removeConceptKnowledge(termVo);

        return RespDTO.onSuc(result);
    }
}
