package com.goomood.phm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.goomood.common.utils.StringUtils;
import com.goomood.phm.domain.KGraphClause;
import com.goomood.phm.mapper.KGraphClauseMapper;
import com.goomood.phm.service.IKGraphClauseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
@Slf4j
public class KGraphClauseServiceImpl implements IKGraphClauseService {
    @Resource
    private KGraphClauseMapper kGraphClauseMapper;

    /**
     * 查询知识图谱分句结果列表
     *
     * @param po 知识图谱分句结果Bo
     * @return 知识图谱分句结果集合
     */
    @Override
    public List<KGraphClause> selectList(KGraphClause po) {
        QueryWrapper<KGraphClause> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(ObjectUtils.isNotEmpty(po.getId()),KGraphClause::getId,po.getId())
                .eq(ObjectUtils.isNotEmpty(po.getTaskId()), KGraphClause::getTaskId, po.getTaskId())
                .like(ObjectUtils.isNotEmpty(po.getStatus()),KGraphClause::getStatus,po.getStatus());
        List<KGraphClause> list = kGraphClauseMapper.selectList(wrapper);
        return list;
    }
    /**
     * 修改知识图谱分句结果
     *
     * @param po 知识图谱分句结果Bo
     * @return 结果:true 更新成功，false 更新失败
     */
    @Override
    public Boolean update(KGraphClause po) {
        if (ObjectUtils.isNotEmpty(po) && ObjectUtils.isNotEmpty(po.getId())) {
            kGraphClauseMapper.updateById(po);
        }
        return true;
    }
    /**
     * 查询知识图谱分句结果
     *
     * @param id 知识图谱分句结果主键
     * @return 知识图谱分句结果
     */
    @Override
    public KGraphClause selectById(Long id) {
        return  kGraphClauseMapper.selectById(id);
    }

    @Override
    public Boolean saveBatch(List<KGraphClause> graphClauseList) {
        kGraphClauseMapper.insert(graphClauseList, 100);
        return true;
    }
    /**
     * 新增知识图谱分句结果
     *
     * @param po 知识图谱分句结果Bo
     * @return 结果:true 操作成功，false 操作失败
     */
    @Override
    public boolean insert(KGraphClause po) {
        int insert = kGraphClauseMapper.insert(po);
        return insert>0;
    }
    /**
     * 批量删除知识图谱分句结果
     *
     * @param ids 需要删除的知识图谱分句结果主键集合
     * @return 结果:true 删除成功，false 删除失败
     */
    @Transactional
    @Override
    public boolean deleteByIds(Long[] ids) {
        kGraphClauseMapper.deleteByIds(Arrays.asList(ids));
        return false;
    }

//    /**
//     * 新增知识图谱分句结果，前台提供主键值，一般用于导入的场合
//     *
//     * @param po 知识图谱分句结果Bo
//     * @return 结果:true 操作成功，false 操作失败
//     */
//    @Override
//    public boolean insertWithPk(KGraphClause po) {
//        //前台传来主键值
//        return kGraphClauseMapper.insertWithPk(kGraphClause) > 0;
//    }
}
