package com.education.api.controller.admin.education;

import com.alibaba.fastjson.JSON;
import com.education.api.config.util.KnowledgePointConverter;
import com.education.auth.annotation.Logical;
import com.education.auth.annotation.RequiresPermissions;
import com.education.business.service.education.ExtKnowledgePointService;
import com.education.common.annotation.SystemLog;
import com.education.common.base.BaseController;
import com.education.common.utils.Result;
import com.education.model.dto.ExtKnowledgePointDto;
import com.education.model.entity.ExtKnowledgePoint;
import com.education.model.request.PageParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 知识点管理
 */
@RequestMapping("/system/extKnowledgePoint")
@RestController
public class ExtKnowledgePointController extends BaseController {

    @Resource
    private ExtKnowledgePointService extKnowledgePointService;

    /**
     * 知识点分页列表
     * @param pageParam
     * @param extKnowledgePoint
     * @return
     */
    @GetMapping
    //@RequiresPermissions("system:extKnowledgePoint:list")
    public Result selectPage(PageParam pageParam, ExtKnowledgePoint extKnowledgePoint) {
        return Result.success(extKnowledgePointService.selectPageList(pageParam, extKnowledgePoint));
    }

    /**
     * 添加或修改
     * @param extKnowledgePointDto
     * @return
     */
    @PostMapping
    //@RequiresPermissions(value = {"system:extKnowledgePoint:save","system:extKnowledgePoint:update"}, logical = Logical.OR)
    public Result saveOrUpdate(@RequestBody ExtKnowledgePointDto extKnowledgePointDto) {
        extKnowledgePointService.saveOrUpdate(extKnowledgePointDto);
        return Result.success();
    }


    /**
     * 根据id查看知识图谱信息
     * @param id
     * @return
     */
    @GetMapping("selectById")
    @SystemLog(describe = "根据id查看知识图谱信息")
    public Result selectById(Integer id) {

        List<ExtKnowledgePoint> list =  extKnowledgePointService.selectById(id);
        if (list == null && list.isEmpty()) {
            return Result.fail();
        }
        return Result.success( JSON.parseObject(KnowledgePointConverter.convert(list)));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    //@RequiresPermissions("system:extKnowledgePoint:deleteById")
    public Result deleteById(@PathVariable Integer id) {
        extKnowledgePointService.removeById(id);
        return Result.success();
    }
}