package com.dayou.service.impl;

import com.dayou.entity.ReportSectionTemplate;
import com.dayou.mapper.ReportSectionTemplateMapper;
import com.dayou.service.IReportSectionTemplateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dayou.utils.LoginContext;
import com.dayou.vo.HeadlineSectionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Arrays;

/**
 * <p>
 * 报告段落模板 服务实现类
 * </p>
 *
 * @author wucl
 * @since 2023-08-25
 */
@Service
public class ReportSectionTemplateServiceImpl extends ServiceImpl<ReportSectionTemplateMapper, ReportSectionTemplate> implements IReportSectionTemplateService {

    @Autowired
    private ReportSectionTemplateMapper reportSectionMapper;

    @Override
    @SuppressWarnings("unchecked")
    public Page<HeadlineSectionVO> getPage(Page page, HeadlineSectionVO reportSection){
        return reportSectionMapper.getPage(page,reportSection);
    }


    @Override
    public ReportSectionTemplate detail(Long id){
        ReportSectionTemplate section = this.getById(id);
        section.setHeadlines(Arrays.asList(section.getHeadlineIds().split(",")));
        return section;
    }

    @Override
    public Boolean add(ReportSectionTemplate reportSectionTemplate){
        reportSectionTemplate.setUserId(LoginContext.getCurrentUserId());
        return  this.save(reportSectionTemplate);
    }

    @Override
    public Boolean update(ReportSectionTemplate reportSectionTemplate){
        return  this.updateById(reportSectionTemplate);
    }

    @Override
    public Boolean delete(Long id){
        //逻辑删除
        return this.removeById(id);
    }
}
