package com.fs.sop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.common.annotation.DataSource;
import com.fs.common.enums.DataSourceType;
import com.fs.sop.domain.QwSopTempDay;
import com.fs.sop.mapper.QwSopTempDayMapper;
import com.fs.sop.service.IQwSopTempDayService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * sop任务模板规则Service业务层处理
 *
 * @author fs
 * @date 2025-02-06
 */
@Service
@AllArgsConstructor
@DataSource(DataSourceType.SOP)
public class QwSopTempDayServiceImpl extends ServiceImpl<QwSopTempDayMapper, QwSopTempDay> implements IQwSopTempDayService {


    @Autowired
    private QwSopTempDayMapper qwSopTempDayMapper;

    @Override
    @DataSource(DataSourceType.SOP)
    public void saveList(List<QwSopTempDay> list) {
        super.saveBatch(list);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public List<QwSopTempDay> listByTempId(String id) {
        return list(new QueryWrapper<QwSopTempDay>().eq("temp_id", id).orderByAsc("day_num"));
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public void insertBatch(List<QwSopTempDay> dayList) {
        super.saveBatch(dayList);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public QwSopTempDay info(Long id) {
        return getById(id);
    }
    @Override
    @DataSource(DataSourceType.SOP)
    public boolean saveOrUpdate(QwSopTempDay day) {
        if(day.getId() == null){
            return baseMapper.insert(day) > 0;
        }else{
            return baseMapper.updateById(day) > 0;
        }
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public void addOrUpdateBatch(List<QwSopTempDay> days) {
        super.saveOrUpdateBatch(days);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public void removeById(Long id) {
        super.removeById(id);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public List<QwSopTempDay> listById(List<Long> dayIds) {
        return list(new QueryWrapper<QwSopTempDay>().in("id", dayIds));
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public int getDayNumByIdLimitOne(String tempId) {
        return  qwSopTempDayMapper.getDayNumByIdLimitOne(tempId);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public void removeByTempIds(Collection<String> tempIds) {
        this.remove(new QueryWrapper<QwSopTempDay>().in("temp_id", tempIds));
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public void removeByWrapper(LambdaQueryWrapper<QwSopTempDay> wrapper) {
        this.remove(wrapper);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public List<QwSopTempDay> listByTempIds(LambdaQueryWrapper<QwSopTempDay> wrapper) {
        return this.list(wrapper);
    }

    @Override
    @DataSource(DataSourceType.SOP)
    public List<QwSopTempDay> listByTempById(LambdaQueryWrapper<QwSopTempDay> wrapper) {
        return this.list(wrapper);
    }


    @Override
    @DataSource(DataSourceType.SOP)
    public void updateByWrapper(UpdateWrapper<QwSopTempDay> wrapper) {
        this.update(wrapper);
    }

}
