package com.ruoyi.project.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.business.domain.train.TtTrainTarget;
import com.ruoyi.project.business.domain.vo.train.TtTrainTargetVo;
import com.ruoyi.project.business.enums.train.TrainCompleteFlagEnum;
import com.ruoyi.project.business.mapper.TtTrainTargetMapper;
import com.ruoyi.project.business.service.ITtTrainTargetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 考核对象Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-18
 */
@Service
@RequiredArgsConstructor
public class TtTrainTargetServiceImpl extends ServiceImpl<TtTrainTargetMapper, TtTrainTarget>
        implements ITtTrainTargetService {
    private final TtTrainTargetMapper ttTrainTargetMapper;

    /**
     * 查询考核对象
     *
     * @param id 考核对象主键
     * @return 考核对象
     */
    @Override
    public TtTrainTarget selectTtTrainTargetById(Long id) {
        return ttTrainTargetMapper.selectTtTrainTargetById(id);
    }

    /**
     * 查询考核对象列表
     *
     * @param ttTrainTarget 考核对象
     * @return 考核对象
     */
    @Override
    public List<TtTrainTargetVo> selectTtTrainTargetList(TtTrainTarget ttTrainTarget) {
        return ttTrainTargetMapper.selectTtTrainTargetList(ttTrainTarget);
    }

    /**
     * 新增考核对象
     *
     * @param ttTrainTarget 考核对象
     * @return 结果
     */
    @Override
    public int insertTtTrainTarget(TtTrainTarget ttTrainTarget) {
        ttTrainTarget.setCreateTime(DateUtils.getNowDate());
        return ttTrainTargetMapper.insertTtTrainTarget(ttTrainTarget);
    }

    /**
     * 修改考核对象
     *
     * @param ttTrainTarget 考核对象
     * @return 结果
     */
    @Override
    public int updateTtTrainTarget(TtTrainTarget ttTrainTarget) {
        ttTrainTarget.setUpdateTime(DateUtils.getNowDate());
        return ttTrainTargetMapper.updateTtTrainTarget(ttTrainTarget);
    }

    /**
     * 批量删除考核对象
     *
     * @param ids 需要删除的考核对象主键
     * @return 结果
     */
    @Override
    public int deleteTtTrainTargetByIds(Long[] ids) {
        return ttTrainTargetMapper.deleteTtTrainTargetByIds(ids);
    }

    /**
     * 删除考核对象信息
     *
     * @param id 考核对象主键
     * @return 结果
     */
    @Override
    public int deleteTtTrainTargetById(Long id) {
        return ttTrainTargetMapper.deleteTtTrainTargetById(id);
    }

    /**
     * 更新考核对象状态为，已完成
     * @param ttTrainTarget
     * @return
     */
    @Override
    public int updateEditTargetStatus(TtTrainTarget ttTrainTarget) {
        TtTrainTarget query = new TtTrainTarget();
        query.setId(ttTrainTarget.getId());
        query.setTrainCompleteFlag(TrainCompleteFlagEnum.FINISHED.getCode());
        query.setUpdateBy(SecurityUtils.getLoginUser().getUserId().toString());
        query.setUpdateTime(DateUtils.getNowDate());
        return ttTrainTargetMapper.updateById(query);
    }

}
