package cn.cslg.pas.service;

import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
import cn.cslg.pas.mapper.PatentAnnotationMapper;
import cn.cslg.pas.common.utils.DateUtils;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.domain.PatentAnnotation;
import cn.cslg.pas.common.model.vo.PatentAnnotationVO;
import cn.dev33.satoken.stp.StpUtil;
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-03-24
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PatentAnnotationService extends ServiceImpl<PatentAnnotationMapper, PatentAnnotation> {
    private final LoginUtils loginUtils;

    public IPage<PatentAnnotation> getPageList(PatentAnnotationVO params) {
        IPage<PatentAnnotation> pageList = baseMapper.getPageList(new Page<>(params.getCurrent(), params.getSize()), params);
        return pageList;
    }

    public String add(PatentAnnotation patentAnnotation) {
        patentAnnotation.setCreateBy(loginUtils.getId());
        patentAnnotation.setCreateTime(DateUtils.getDateTime());
        patentAnnotation.insert();
        return Response.success(patentAnnotation.getId());
    }

    public String edit(PatentAnnotation patentAnnotation) {
        patentAnnotation.updateById();
        return Response.success();
    }

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