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.OntologyConcept;
import com.wx.application.core.service.OntologyConceptService;
/**
 *   @description : OntologyConcept 默认控制器,仅供生成器使用
 *   ---------------------------------
 *   @since 2022-09-25
 */
/*@Slf4j*/
@RestController("coreOntologyConceptController")
@RequestMapping("/ontology-concept")
public class OntologyConceptController extends BaseController {

    @Autowired
    private OntologyConceptService ontologyConceptService;

    /**
     * 查询树形
     * @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(ontologyConceptService.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(ontologyConceptService.queryList(mQ));
    }
    
    
    
    /**
     * 概念数量 对象属性数量 值属性数量
     * @param ontologyId
     * @return
     */
    @GetMapping(value = "/countallbyontologyid/{ontologyId}")
    public ResponseData countAllByOntologyId(@PathVariable("ontologyId") Long ontologyId) {
        return success(ontologyConceptService.countAllByOntologyId(ontologyId));
    }
    
    /**
     * 统计次级概念数量
     */
    @GetMapping(value = "/countchildbyid/{id}")
    public ResponseData countChildbyid(@PathVariable("id") Long id) {
        return success(ontologyConceptService.countChildbyid(id));
    }
    
    /**
     * 删除树形节点
     * @param ownId
     * @return
     */
    @GetMapping(value = "/delete/{id}")
    public ResponseData delete(@PathVariable("id") Long id) {
        return success(ontologyConceptService.deleteOntologyConcept(id));
    }

    
    /**
     * 修改
     * @param ontologyConcept
     * @return
     * 
     * 传修改 改成 传 {ownId，label}
     */
    @PostMapping(value = "/modify")
    public ResponseData modify(@RequestBody OntologyConcept ontologyConcept) {
        return success(ontologyConceptService.modifyOntologyConcept(ontologyConcept));
    }

    
    /**
     * 创建
     * @param ontologyConcept
     * @return
     */
    @PostMapping(value = "/create")
    public ResponseData create(@RequestBody OntologyConcept ontologyConcept) {
        return success(ontologyConceptService.createOntologyConcept(ontologyConcept));
    }
    
    
}
