package com.wx.application.core.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 com.wx.application.adapter.dto.qo.OntologyQ;
import com.wx.application.base.BaseController;
import com.wx.application.base.ResponseData;
import com.wx.application.core.entity.OntologyRelation;
import com.wx.application.core.service.OntologyRelationService;
/**
 *   @description : OntologyRelation 默认控制器,仅供生成器使用
 *   ---------------------------------
 *   @since 2022-09-25
 */
/*@Slf4j*/
@RestController("coreOntologyRelationController")
@RequestMapping("/ontology-relation")
public class OntologyRelationController extends BaseController {

    @Autowired
    private OntologyRelationService ontologyRelationService;

    /**
     * 查询树形
     * @param ontologyId
     * @param ontologyConceptQ
     * @return
     */
    @PostMapping(value = "/query_list/{ontologyId}")
    public ResponseData queryList(@PathVariable("ontologyId") Long ontologyId,
    		@RequestBody Map ontologyConceptQ) {
    	ontologyConceptQ.put("EQL_ontologyId", ontologyId);
        return success(ontologyRelationService.queryList(ontologyConceptQ));
    }

    /**
     * 模糊匹配
     */
    @PostMapping(value = "/like_list/{ontologyId}")
    public ResponseData likeList(@PathVariable("ontologyId") Long ontologyId,
    		@RequestBody OntologyQ ontologyQ) {
    	if(StringUtils.isBlank(ontologyQ.getLabel())) {
    		return success();
    	}
    	Map mQ = new HashMap<>();
    	mQ.put("EQL_ontologyId", ontologyId);
    	mQ.put("LIKES_label", ontologyQ.getLabel());
        return success(ontologyRelationService.queryList(mQ));
    }
    
    /**
     * 删除树形节点
     * @param ownId
     * @return
     */
    @GetMapping(value = "/delete/{id}")
    public ResponseData delete(@PathVariable("id") Long id) {
        return success(ontologyRelationService.deleteOntologyRelation(id));
    }

    
    /**
     * 修改
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/modify")
    public ResponseData modify(@RequestBody OntologyRelation ontologyRelation) {
        return success(ontologyRelationService.modifyOntologyRelation(ontologyRelation));
    }

    
    /**
     * 创建关系 选择头节点和尾节点
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/createrelations")
    public ResponseData createRelations(@RequestBody OntologyRelation ontologyRelation) {
        return success(ontologyRelationService.createRelations(ontologyRelation));
    }
    
    /**
     * 创建关系名称
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/create")
    public ResponseData create(@RequestBody OntologyRelation ontologyRelation) {
        return success(ontologyRelationService.createOntologyRelation(ontologyRelation));
    }
    
}
