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.OntologyField;
import com.wx.application.core.service.OntologyFieldService;
import com.wx.application.nebula.graph.base.Generators;
/**
 *   @description : OntologyField 默认控制器,仅供生成器使用
 *   ---------------------------------
 *   @since 2022-09-25
 */
/*@Slf4j*/
@RestController("coreOntologyFieldController")
@RequestMapping("/ontology-field")
public class OntologyFieldController extends BaseController {

    @Autowired
    private OntologyFieldService ontologyFieldService;

    /**
     * 查询树形
     * @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(ontologyFieldService.queryList(ontologyConceptQ));
    }
    
    /**
     * 模糊匹配
     * @param ontologyId
     * @param ontologyQ
     * @return
     */
    @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_comment", ontologyQ.getLabel());
        return success(ontologyFieldService.queryList(mQ));
    }
    
    /**
     * 删除树形节点
     * @param ownId
     * @return
     */
    @GetMapping(value = "/delete/{id}")
    public ResponseData delete(@PathVariable("id") Long id) {
    	ontologyFieldService.deleteConceptField(id);
        return success();
    }

    
    /**
     * 修改
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/modify")
    public ResponseData modify(@RequestBody OntologyField ontologyField) {
    	ontologyFieldService.modifyOntologyField(ontologyField);
        return success();
    }

    
    /**
     * 创
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/createconceptfield")
    public ResponseData createConceptField(@RequestBody OntologyField ontologyField) {
    	ontologyFieldService.createConceptField(ontologyField);
        return success();
    }
    
    /**
     * 创建关系名称
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/create")
    public ResponseData create(@RequestBody OntologyField ontologyField) {
    	if(StringUtils.isBlank(ontologyField.getField())) {
    		ontologyField.setField(Generators.fieldname(ontologyField.getComment()));
    	}
        return success(ontologyFieldService.createOntologyField(ontologyField));
    }
}
