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.core.page.TableDataInfo;
import com.goomood.common.enums.BusinessType;
import com.goomood.phm.domain.KGraphClause;
import com.goomood.phm.service.IKGraphClauseService;
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;

/**
 * 知识图谱分句结果Controller
 *
 * @author wgk
 * @date 2025-01-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/kGraphClause")
public class KGraphClauseController extends BaseController {

    @Resource
    private IKGraphClauseService kGraphClauseService;

    /**
     * 查询知识图谱分句结果列表
     */
    @GetMapping("/list")
    public TableDataInfo list(KGraphClause po) {
        startPage();
        List<KGraphClause> list = kGraphClauseService.selectList(po);
        return getDataTable(list);
    }
    /**
     * 获取知识图谱分句结果详细信息
     */
    @GetMapping(value = "/selectOne/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(kGraphClauseService.selectById(id));
    }

    /**
     * 新增知识图谱分句结果
     */
    @RepeatSubmit
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody KGraphClause po) {
        boolean inserted = kGraphClauseService.insert(po);
        if (!inserted) {
            return AjaxResult.error("新增知识图谱分句结果记录失败！");
        }
        return success();
    }
    /**
     * 新增知识图谱分句结果
     */
    @RepeatSubmit()
    @PostMapping("/saveBatch")
    public AjaxResult saveBatch(@Valid @RequestBody List<KGraphClause> kGraphClauseList) {
        boolean inserted = kGraphClauseService.saveBatch(kGraphClauseList);
        if (!inserted) {
            return AjaxResult.error("新增知识图谱分句结果记录失败！");
        }
        return success();
    }
    /**
     * 修改知识图谱分句结果
     */
    @Log(title = "知识图谱分句结果", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/update")
    public AjaxResult edit(@Validated @RequestBody KGraphClause po) {
        boolean updated = kGraphClauseService.update(po);
        if (!updated) {
            return AjaxResult.error("修改知识图谱分句结果记录失败!");
        }
        return success();
    }

    /**
     * 删除知识图谱分句结果
     */
    @Log(title = "知识图谱分句结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        boolean deleted = kGraphClauseService.deleteByIds(ids);
        if (!deleted) {
            return AjaxResult.error("删除知识图谱分句结果记录失败!");
        }
        return success();
    }
}
