package com.goomood.phm.controller;

import com.goomood.common.annotation.Log;
import com.goomood.common.annotation.RepeatSubmit;
import com.goomood.common.core.controller.BaseController;
import com.goomood.common.core.domain.AjaxResult;
import com.goomood.common.enums.BusinessType;
import com.goomood.phm.domain.KGraphEntity;
import com.goomood.phm.service.IKGraphEntityService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/kGraphEntity")
public class KGraphEntityController extends BaseController {

    @Resource
    private IKGraphEntityService kGraphEntityService;

    /**
     * 查询知识图谱实体关系列表
     */

    @GetMapping("/list")
    public AjaxResult list(KGraphEntity po) {
        return success(kGraphEntityService.selectPage(po));
    }

    /**
     * 获取知识图谱实体关系详细信息
     */

    @GetMapping(value = "/selectOne/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(kGraphEntityService.selectById(id));
    }
    /**
     * 获取知识图谱实体关系详细信息
     */
    @GetMapping(value = "/selectListByTaskId/{id}")
    public AjaxResult selectListByTaskId(@PathVariable Long id) {
        return success(kGraphEntityService.selectListByTaskId(id));
    }

    /**
     * 新增知识图谱实体关系
     */

    @Log(title = "知识图谱实体关系", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody KGraphEntity po) {
        kGraphEntityService.insert(po);
        return success("ok");
    }

    /**
     * 新增知识图谱实体关系
     */
    @RepeatSubmit()
    @PostMapping("/saveBatch")
    public AjaxResult saveBatch(@Valid @RequestBody List<KGraphEntity> kGraphEntityBoList) {
        return success(kGraphEntityService.saveBatch(kGraphEntityBoList));
    }

    /**
     * 修改知识图谱实体关系
     */

    @Log(title = "知识图谱实体关系", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/update")
    public AjaxResult edit(@Validated @RequestBody KGraphEntity po) {
        return success(kGraphEntityService.update(po));
    }

    /**
     * 删除知识图谱实体关系
     */
    @Log(title = "知识图谱实体关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(kGraphEntityService.deleteByIds(ids));
    }
}
