package com.yunyan.business.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunyan.business.domain.ReportFile;
import com.yunyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yunyan.business.mapper.ReportExplainMapper;
import com.yunyan.business.domain.ReportExplain;
import com.yunyan.business.service.IReportExplainService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import com.yunyan.common.core.domain.AjaxResultVo;
import org.springframework.beans.BeanUtils;
import com.yunyan.common.core.domain.model.LoginUser;
import com.yunyan.common.utils.SecurityUtils;
import com.yunyan.common.enums.DataContentType;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import com.yunyan.common.annotation.DataScope;

/**
 * 报告-格数据,情况说明Service业务层处理
 *
 * @author yunyan
 * @date 2023-12-15
 */
@Slf4j
@Service
public class ReportExplainServiceImpl extends ServiceImpl<ReportExplainMapper, ReportExplain> implements IReportExplainService
{
    @Autowired
    private ReportExplainMapper reportExplainMapper;

    /**
     * 查询报告-格数据,情况说明列表
     *
     * @param reportExplain 报告-格数据,情况说明
     * @return 报告-格数据,情况说明
     */    @Override
    public List<ReportExplain> selectReportExplainList(ReportExplain reportExplain)
    {
        return reportExplainMapper.selectReportExplainList(reportExplain);
    }

    /**
    * 新增
    * @param
    * @return
    */
    @Override
    public AjaxResultVo add(ReportExplain dto) {
        ReportExplain entity = dto;

        this.save(entity);
        return AjaxResultVo.success();
    }

    /**
     * 编辑
     * @param
     * @return
     */
    @Override
    public AjaxResultVo edit(ReportExplain dto) {

        ReportExplain entity = this.getById(dto.getId());
        if(null == entity) {
            return AjaxResultVo.error("非法操作");
        }

        entity = new ReportExplain();
        BeanUtils.copyProperties(dto, entity);

        this.updateById(entity);
        return AjaxResultVo.success();
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @Override
    public AjaxResultVo info(Long id) {
        ReportExplain entity = this.getById(id);
        if(null == entity) {
            return AjaxResultVo.error("数据查询异常~");
        }

        return AjaxResultVo.success(entity);
    }

    @Override
    public ReportExplain getReportExplainByReportId(Long reportId) {
        LambdaQueryWrapper<ReportExplain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ReportExplain::getReportId, reportId);
        queryWrapper.last("and rownum = 1 order by create_time desc");
        ReportExplain reportExplain = this.getOne(queryWrapper);
        return reportExplain;
    }
}
