package com.repair.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.repair.mapper.RepairClassesSettingsMapper;
import com.repair.model.pojo.RepairClassesSettings;
import com.repair.model.pojo.RepairShiftSettings;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.ClassesDataVo;
import com.repair.model.vo.ClassesSettingVo;
import com.repair.services.RepairClassesSettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-07-13
 */
@Service
public class RepairClassesSettingsServiceImpl extends ServiceImpl<RepairClassesSettingsMapper, RepairClassesSettings> implements RepairClassesSettingsService {

    @Autowired
    private RepairClassesSettingsMapper repairClassesSettingsMapper;

    @Override
    public int insertRepairClassesSettings(RepairClassesSettings rcs) {
        int result = repairClassesSettingsMapper.insert(rcs);
        return result;
    }

    @Override
    public int updateRepairClassesSettings(RepairClassesSettings rcs) {
        int result = repairClassesSettingsMapper.updateById(rcs);
        return result;
    }

    @Override
    public PageUtils<RepairClassesSettings> queryPageRepairClassesSettingss(int currentPage, int pageCount, String name) {
        Page<RepairClassesSettings> page = new Page<>(currentPage, pageCount);
        QueryWrapper<RepairClassesSettings> queryWrapper = new QueryWrapper<>();
        String str = "user_id in (select id from repair_user where user_name like '%" + name + "%')";
        queryWrapper.apply(StringUtils.hasText(name), str);
        IPage<RepairClassesSettings> result = repairClassesSettingsMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }

    @Override
    public int deleteRepairClassesSettingsById(int id) {
        int result = repairClassesSettingsMapper.deleteById(id);
        return result;
    }

    @Override
    public int getRepairByUserId(int userId, String dateNow) {
        QueryWrapper<RepairClassesSettings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("start_date", dateNow);
        int result = repairClassesSettingsMapper.selectCount(queryWrapper);
        return result;
    }


    @Override
    public RepairClassesSettings getRepairById(int id) {
        RepairClassesSettings result = repairClassesSettingsMapper.selectById(id);
        return result;
    }

    @Override
    public List<ClassesSettingVo> getRepairByUserIds(List<Integer> userIds, String startTime, String endTime) {
        List<ClassesSettingVo> result = repairClassesSettingsMapper.queryClassesSettingList(userIds, startTime, endTime);
        return result;
    }

    @Override
    public List<RepairClassesSettings> getRepairByMonths(String monthDate) {
        QueryWrapper<RepairClassesSettings> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("start_date", monthDate);
        List<RepairClassesSettings> result = repairClassesSettingsMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<ClassesDataVo> queryClassesDatas(List<Integer> userIds, Integer startDate) {
        List<ClassesDataVo> result = repairClassesSettingsMapper.queryClassesDatas(userIds, startDate);
        return result;
    }

    @Override
    public ClassesDataVo queryClassesData(Integer userId) {
        ClassesDataVo result = repairClassesSettingsMapper.queryClassesData(userId);
        return result;
    }
}
