package com.dxhy.core.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.utils.PageUtils;
import com.dxhy.common.utils.Query;
import com.dxhy.core.job.dao.ScheduleJobLogDao;
import com.dxhy.core.job.entity.ScheduleJobLogEntity;
import com.dxhy.core.job.service.ScheduleJobLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author user
 */
@Service("scheduleJobLogService")
public class ScheduleJobLogServiceImpl extends ServiceImpl<ScheduleJobLogDao, ScheduleJobLogEntity>
    implements ScheduleJobLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        String jobId = (String)params.get("jobId");

        IPage<ScheduleJobLogEntity> page = this.page(new Query<ScheduleJobLogEntity>().getPage(params),
            new QueryWrapper<ScheduleJobLogEntity>().like(StringUtils.isNotBlank(jobId), "job_id", jobId));
        return new PageUtils(page);
    }

    @Override
    public ScheduleJobLogEntity queryById(Long id) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        return baseMapper.selectById(id);
    }

    @Override
    public void insertLog(ScheduleJobLogEntity log) {
        DynamicContextHolder.push(DbConstant.BASICS_WRITE);
        this.insertScheduleLog(log);
    }

    public void insertScheduleLog(ScheduleJobLogEntity log) {
        baseMapper.insert(log);
    }

}
