package cn.iocoder.yudao.module.system.service.worklog;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statisticsrecord.LogStatisticsRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.statisticsrecord.LogStatisticsRecordSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogStatisticsRecordDO;
import cn.iocoder.yudao.module.system.dal.mysql.worklog.LogStatisticsRecordMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工作日志统计记录 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class LogStatisticsRecordServiceImpl implements LogStatisticsRecordService {

    @Resource
    private LogStatisticsRecordMapper logStatisticsRecordMapper;

    @Override
    public Long createLogStatisticsRecord(LogStatisticsRecordSaveReqVO createReqVO) {
        // 插入
        LogStatisticsRecordDO logStatisticsRecord = BeanUtils.toBean(createReqVO, LogStatisticsRecordDO.class);
        logStatisticsRecordMapper.insert(logStatisticsRecord);
        // 返回
        return logStatisticsRecord.getId();
    }

    @Override
    public void updateLogStatisticsRecord(LogStatisticsRecordSaveReqVO updateReqVO) {
        // 更新
        LogStatisticsRecordDO updateObj = BeanUtils.toBean(updateReqVO, LogStatisticsRecordDO.class);
        logStatisticsRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteLogStatisticsRecord(Long id) {
        // 删除
        logStatisticsRecordMapper.deleteById(id);
    }

    @Override
    public LogStatisticsRecordDO getLogStatisticsRecord(Long id) {
        return logStatisticsRecordMapper.selectById(id);
    }

    @Override
    public PageResult<LogStatisticsRecordDO> getLogStatisticsRecordPage(LogStatisticsRecordPageReqVO pageReqVO) {
        return logStatisticsRecordMapper.selectPage(pageReqVO);
    }

    @Override
    public List<LogStatisticsRecordDO> getByFormIdsAndTime(List<Long> formIds, String thisTime) {
        return logStatisticsRecordMapper.selectList(new LambdaQueryWrapper<LogStatisticsRecordDO>()
                .in(LogStatisticsRecordDO::getFormId, formIds)
                .eq(LogStatisticsRecordDO::getTime, thisTime));
    }

}