package com.ruoyi.school.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.school.course.domain.ScClaTimeAttend;
import com.ruoyi.school.course.domain.req.time.ReqClaTimeCount;
import com.ruoyi.school.course.mapper.ScClaTimeAttendMapper;
import com.ruoyi.school.course.service.IScClaTimeAttendService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * <p>
 * 上课出勤表 服务实现类
 * </p>
 *
 * @author zhangby
 * @since 2020-09-30 02:33:26
 */
@Service
public class ScClaTimeAttendServiceImpl extends ServiceImpl<ScClaTimeAttendMapper, ScClaTimeAttend> implements IScClaTimeAttendService {

    @Override
    public int studentCourseAttendCount(Long studentCourseId, String beginDate, String endDate) {
        return baseMapper.selectStudentAttendCount(studentCourseId, beginDate, endDate);
    }

    @Override
    public Integer getNeedAttendCount(String beginDate, String endDate) {
        return baseMapper.selectNeedAttendCount(beginDate, endDate, SecurityUtils.getLoginUser().getNowTenantId());
    }

    @Override
    public Integer getAttendCount(String beginDate, String endDate, String[] attendStatus) {
        return baseMapper.selectAttendCount(beginDate, endDate, attendStatus, SecurityUtils.getLoginUser().getNowTenantId());
    }

    @Override
    public BigDecimal getAttendCostHour(String beginDate, String endDate) {
        //会员卡 划扣课时现金价值 +划扣金额
        BigDecimal a= baseMapper.selectAttendCostHour(beginDate, endDate, SecurityUtils.getLoginUser().getNowTenantId());
       //按天的周期卡 每天的价值
        BigDecimal b=baseMapper.selectMemberByDay(SecurityUtils.getLoginUser().getNowTenantId());
        return a.add(b).setScale(2, RoundingMode.HALF_UP);
    }

    @Override
    public BigDecimal getTeacherGetHour(ReqClaTimeCount reqClaTimeCount) {
        return baseMapper.selectTeacherSumGetHour(reqClaTimeCount);
    }

    @Override
    public List<ScClaTimeAttend> getAttendList(Long courseTimeId) {
        QueryWrapper<ScClaTimeAttend> qwAttend = new QueryWrapper<>();
        qwAttend.eq("course_time_id", courseTimeId);
        return this.list(qwAttend);
    }
}
