package cn.cslg.pas.service;

import cn.cslg.pas.common.model.vo.ProjectKeywordVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.StringUtils;
import cn.cslg.pas.domain.ProjectKeyword;
import cn.cslg.pas.mapper.ProjectKeywordMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 专题库关键词表 服务实现类
 * </p>
 *
 * @author 王岩
 * @since 2022-01-24
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ProjectKeywordService extends ServiceImpl<ProjectKeywordMapper, ProjectKeyword> {

    public IPage<ProjectKeyword> getPageList(ProjectKeywordVO params) {
        LambdaQueryWrapper<ProjectKeyword> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(params.getName())) {
            queryWrapper.like(ProjectKeyword::getName, params.getName());
        }
        queryWrapper.eq(ProjectKeyword::getProjectId, params.getProjectId());
        IPage<ProjectKeyword> pageList = this.page(new Page<>(params.getCurrent(), params.getSize()), queryWrapper);

        return pageList;
    }

    public String add(ProjectKeyword projectKeyword) {
        projectKeyword.insert();
        return Response.success(projectKeyword.getId());
    }

    public String edit(ProjectKeyword projectKeyword) {
        projectKeyword.updateById();
        return Response.success();
    }

    public String delete(Integer id) {
        this.removeById(id);
        return Response.success();
    }
}
