ClassHourDictServiceImpl.java 3.19 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.RedisPrefixConstant;
import com.subsidy.mapper.ClassHourDictMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.mapper.VodPlayHistoryMapper;
import com.subsidy.model.ClassHourDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.VodPlayHistoryDO;
import com.subsidy.service.ClassHourDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.RedisUtil;
import com.subsidy.vo.hour.PollingGetVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * <p>
 * 课时 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-11-26
 */
@Service
public class ClassHourDictServiceImpl extends ServiceImpl<ClassHourDictMapper, ClassHourDictDO> implements ClassHourDictService {

    @Autowired
    private VodPlayHistoryMapper vodPlayHistoryMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private RedisUtil redisUtil;

    public ClassHourDictDO getSetting(ClassHourDictDO classHourDictDO) {
        return (ClassHourDictDO) redisUtil.get(RedisPrefixConstant.SUBSIDY_SETTINGS_PREFIX + classHourDictDO.getCompanyId());
    }

    @Async
    public String updateSetting(ClassHourDictDO classHourDictDO) {

        ClassHourDictDO classHourDictDO1 = (ClassHourDictDO) redisUtil.get(RedisPrefixConstant.SUBSIDY_SETTINGS_PREFIX + classHourDictDO.getCompanyId());
        BeanUtils.copyProperties(classHourDictDO, classHourDictDO1);
        redisUtil.set(RedisPrefixConstant.SUBSIDY_SETTINGS_PREFIX + classHourDictDO.getCompanyId(), classHourDictDO1);
        return ConstantUtils.SET_SUCCESS;
    }

    public PollingGetVO pollingGet(VodPlayHistoryDO vodPlayHistoryDO) {

        PollingGetVO pollingGetVO = new PollingGetVO();

        MemberDO memberDO = memberMapper.selectById(vodPlayHistoryDO.getMemberId());

        //查看系统设定的时长
        ClassHourDictDO classHourDictDO = (ClassHourDictDO) redisUtil.get(RedisPrefixConstant.SUBSIDY_SETTINGS_PREFIX + memberDO.getCompanyId());

        if (classHourDictDO.getStatus() == 0) {
            pollingGetVO.setBool(false);
            return pollingGetVO;
        }

        //查看当天这个人看了多少时间
        Integer total = vodPlayHistoryMapper.memberDailyStudyLength(memberDO.getId());

        //是否超过时长  没超过  false 超过 true
        if (classHourDictDO == null) {
            pollingGetVO.setBool(true);
        } else {
            if (total + vodPlayHistoryDO.getPlayLength() <= classHourDictDO.getClassHour() * 3600) {
                pollingGetVO.setBool(false);
            } else {
                pollingGetVO.setBool(true);
            }
        }
        return pollingGetVO;
    }

}