package com.fs.qw.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.his.domain.FsUserInformationCollectionSchedule;
import com.fs.his.enums.CollectionTaskStatusEnum;
import com.fs.hisStore.service.IFsUserInformationCollectionService;
import com.fs.qw.mapper.FsUserInformationCollectionScheduleMapper;
import com.fs.qw.service.IFsUserInformationCollectionScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户信息采集进度Service业务层处理
 *
 * @author fs
 * @date 2025-11-18
 */
@Service
@Slf4j
public class FsUserInformationCollectionScheduleServiceImpl extends ServiceImpl<FsUserInformationCollectionScheduleMapper, FsUserInformationCollectionSchedule> implements IFsUserInformationCollectionScheduleService {

    @Autowired
    private IFsUserInformationCollectionService fsUserInformationCollectionService;
    /**
     * 查询用户信息采集进度
     *
     * @param id 用户信息采集进度主键
     * @return 用户信息采集进度
     */
    @Override
    public FsUserInformationCollectionSchedule selectFsUserInformationCollectionScheduleById(Long id)
    {
        return baseMapper.selectFsUserInformationCollectionScheduleById(id);
    }

    /**
     * 对于每条用户信息采集记录，只获取其最新的任务流程
     *
     * @param fsUserInformationCollectionSchedule 用户信息采集进度
     * @return 用户信息采集进度
     */
    @Override
    public List<FsUserInformationCollectionSchedule> getUserRecordLatestTaskProcess(FsUserInformationCollectionSchedule fsUserInformationCollectionSchedule)
    {
        return baseMapper.getUserRecordLatestTaskProcess(fsUserInformationCollectionSchedule);
    }

    /**
     * 查询用户信息采集进度列表
     *
     * @param fsUserInformationCollectionSchedule 用户信息采集进度
     * @return 用户信息采集进度
     */
    @Override
    public List<FsUserInformationCollectionSchedule> selectFsUserInformationCollectionScheduleList(FsUserInformationCollectionSchedule fsUserInformationCollectionSchedule)
    {
        return baseMapper.getUserRecordLatestTaskProcess(fsUserInformationCollectionSchedule);
    }

    /**
     * 新增用户信息采集进度
     *
     * @param fsUserInformationCollectionSchedule 用户信息采集进度
     * @return 结果
     */
    @Override
    public int insertFsUserInformationCollectionSchedule(FsUserInformationCollectionSchedule fsUserInformationCollectionSchedule)
    {
        fsUserInformationCollectionSchedule.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertFsUserInformationCollectionSchedule(fsUserInformationCollectionSchedule);
    }

    /**
     * 修改用户信息采集进度
     *
     * @param fsUserInformationCollectionSchedule 用户信息采集进度
     * @return 结果
     */
    @Override
    public int updateFsUserInformationCollectionSchedule(FsUserInformationCollectionSchedule fsUserInformationCollectionSchedule)
    {
        return baseMapper.updateFsUserInformationCollectionSchedule(fsUserInformationCollectionSchedule);
    }

    /**
     * 批量删除用户信息采集进度
     *
     * @param ids 需要删除的用户信息采集进度主键
     * @return 结果
     */
    @Override
    public int deleteFsUserInformationCollectionScheduleByIds(Long[] ids)
    {
        return baseMapper.deleteFsUserInformationCollectionScheduleByIds(ids);
    }

    /**
     * 删除用户信息采集进度信息
     *
     * @param id 用户信息采集进度主键
     * @return 结果
     */
    @Override
    public int deleteFsUserInformationCollectionScheduleById(Long id)
    {
        return baseMapper.deleteFsUserInformationCollectionScheduleById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int stopCollectionSchedule(FsUserInformationCollectionSchedule fsUserInformationCollectionSchedule) {
        // "用户信息采集表"状态清空
        //fsUserInformationCollectionService.stopCollection(fsUserInformationCollectionSchedule.getCollectionId(),fsUserInformationCollectionSchedule.getTerminatedBy());
        // "用户采集进度"取消时间
        fsUserInformationCollectionSchedule.setTerminatedTime(DateUtils.getNowDate());
        // "用户采集进度"取消标识
        fsUserInformationCollectionSchedule.setStatus(CollectionTaskStatusEnum.TERMINATED.getCode());
        return baseMapper.updateFsUserInformationCollectionSchedule(fsUserInformationCollectionSchedule);
    }
}
