package com.diagbot.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RelationDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.facade.RelationFacade;
import com.diagbot.vo.AllRelationVo;
import com.diagbot.vo.RelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

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

public class RelationController {
    @Autowired
    RelationFacade relationFacade;

    @ApiOperation(value = "按标准术语查询关系",
            notes = "Term：术语名称, 必填<br>Type：术语类型, 必填<br>")
    @PostMapping("/getConceptRelation")
    @SysLogger("getConceptRelation")
    public RespDTO<List<RelationDTO>> getConceptRelation(@Valid @RequestBody RelationVo relationVo) {
        List<RelationDTO> data = relationFacade.getRelations(relationVo);

        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "所有术语关系查询")
    @PostMapping("/getAllRelation")
    @SysLogger("getAllRelation")
    public RespDTO<IPage<RelationDTO>> getAllRelation(@RequestBody AllRelationVo allrelationVo) {
        IPage<RelationDTO> data = relationFacade.getAllRelations(allrelationVo);

        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "标准术语关系删除",
            notes = "StartTerm：起始术语名称, 必填<br>StartType：起始术语类型, 必填<br>Relation：关系名称, 必填<br>" +
                    "EndTerm：终点术语名称, 必填<br>EndType：终点术语类型, 必填<br>")
    @PostMapping("/removeRelation")
    @SysLogger("removeRelation")
    public RespDTO<RelationDTO> removeRelation(@Valid @RequestBody RelationVo relationVo) {
        RelationDTO data = relationFacade.removeRelations(relationVo);

        return RespDTO.onSuc(data);
    }

}
