PushDataServiceImpl.java 10.5 KB
package com.subsidy.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.subsidy.dto.renshe.*;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.PushDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.service.RenshejuHistoryService;
import com.subsidy.util.RenSheJuConstant;
import com.subsidy.util.SMSUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * <p>
 * 问题答疑表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2023-12-01
 */
@Service
public class PushDataServiceImpl extends ServiceImpl<PushAnsweringDataMapper, PushAnsweringDataDO> implements PushDataService {

    @Autowired
    private RenshejuHistoryMapper renshejuHistoryMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private PushOprDataMapper pushOprDataMapper;

    @Autowired
    private PushVodDataMapper pushVodDataMapper;

    @Autowired
    private ClassDictMapper classDictMapper;

    @Autowired
    private PushDetectionDataMapper pushDetectionDataMapper;

    @Autowired
    private PushExerciseDataMapper pushExerciseDataMapper;

    @Autowired
    private PushImageDataMapper pushImageDataMapper;

    @Autowired
    private PushAnsweringDataMapper pushAnsweringDataMapper;

    @Autowired
    private SMSUtils smsUtils;

    @Transactional(rollbackFor = Exception.class)
    public void post4() {

        RenshejuHistoryDO renshejuHistoryDO = renshejuHistoryMapper.dailyData(RenSheJuConstant.POST_4);
//        RenshejuHistoryDO renshejuHistoryDO =renshejuHistoryMapper.selectById(5362);
        String input = renshejuHistoryDO.getInputParam();
        Gson gson = new Gson();
        ClassHourBehaviorDTO classHourBehaviorDTO = gson.fromJson(input, ClassHourBehaviorDTO.class);

        List<ClassHourBasic> classHourBasics = classHourBehaviorDTO.getClassHourBasic();
        for (ClassHourBasic chb : classHourBasics) {
            MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                    .lambda()
                    .eq(MemberDO::getIdCard, chb.getIdentity())
            );
            ClassDictDO classDictDO = classDictMapper.selectOne(new QueryWrapper<ClassDictDO>()
                    .lambda()
                    .eq(ClassDictDO::getClassCode, chb.getClassCode()));

            List<LoginList> loginLists = chb.getLoginList();
            if (loginLists.size() > 0) {
                LoginList loginList = loginLists.get(0);
                Date loginInTime = new Date(loginList.getStartTime());
                Date loginOutTime = new Date(loginList.getEndTime());
                String ip = loginList.getIp();
                //opr
                pushOprDataMapper.insertData(memberDO.getId(), "登录", ip, loginInTime);
                pushOprDataMapper.insertData(memberDO.getId(), "登出", null, loginOutTime);

                //回写视频数据
                List<ChapterList3> chapterList = loginList.getChapterList();
                for (ChapterList3 chapter : chapterList) {
                    pushVodDataMapper.insertData(classDictDO.getId(), Long.valueOf(chapter.getChapterCode()), memberDO.getId(), (chapter.getEndTime().intValue() - chapter.getStartTime().intValue()) / 1000, chapter.getPauseTime().intValue(), 0, new Date(chapter.getEndTime()), ip);
                }
            }
            //回写活跃度数据
            List<ActivityList> activityLists = chb.getActivityList();
            for (ActivityList activityList : activityLists) {
                pushDetectionDataMapper.insertData(classDictDO.getId(), activityList.getActivityDetection(), memberDO.getId(), new Date(activityList.getActivityTime()));
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void post5() {
        RenshejuHistoryDO renshejuHistoryDO = renshejuHistoryMapper.dailyData(RenSheJuConstant.POST_5);
//        RenshejuHistoryDO renshejuHistoryDO = renshejuHistoryMapper.selectById(5365);
        String input = renshejuHistoryDO.getInputParam();
        Gson gson = new Gson();
        UploadChapterBehaviorDTO uploadChapterBehaviorDTO = gson.fromJson(input, UploadChapterBehaviorDTO.class);
        System.out.println(uploadChapterBehaviorDTO);

        List<ChapterExamBasic> chapterExamBasics = uploadChapterBehaviorDTO.getChapterExamBasic();
        for (ChapterExamBasic ceb : chapterExamBasics) {

            MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                    .lambda()
                    .eq(MemberDO::getIdCard, ceb.getIdentity())
            );
            ClassDictDO classDictDO = classDictMapper.selectOne(new QueryWrapper<ClassDictDO>()
                    .lambda()
                    .eq(ClassDictDO::getClassCode, ceb.getClassCode()));

            //考试活跃度  学时里已经推过全部的活跃度了
//            List<ActivityList> activityLists = ceb.getActivityList();
//            for (ActivityList activityList : activityLists) {
//                pushDetectionDataMapper.insertData(classDictDO.getId(), activityList.getActivityDetection(), memberDO.getId(), new Date(activityList.getActivityTime()));
//            }

            //考试表
            List<ExamList> examLists = ceb.getExamList();
            for (ExamList examList : examLists) {
                pushExerciseDataMapper.pushExamData(classDictDO.getId(), new Date(examList.getStartTime()), memberDO.getId(), new Date(examList.getEndTime()), ceb.getExamTime().intValue());
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void post6() {
        RenshejuHistoryDO renshejuHistoryDO = renshejuHistoryMapper.dailyData(RenSheJuConstant.POST_6);
//        RenshejuHistoryDO renshejuHistoryDO = renshejuHistoryMapper.selectById(5366);
        String input = renshejuHistoryDO.getInputParam();
        Gson gson = new Gson();
        UploadClassAnswerQuestionBehaviorDTO uploadClassAnswerQuestionBehaviorDTO = gson.fromJson(input, UploadClassAnswerQuestionBehaviorDTO.class);
        System.out.println(uploadClassAnswerQuestionBehaviorDTO);

        List<AnswerBasic> answerBasics = uploadClassAnswerQuestionBehaviorDTO.getAnswerBasic();
        for (AnswerBasic ab : answerBasics) {

            ClassDictDO classDictDO = classDictMapper.selectOne(new QueryWrapper<ClassDictDO>()
                    .lambda()
                    .eq(ClassDictDO::getClassCode, ab.getClassCode()));

            MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                    .lambda()
                    .eq(MemberDO::getIdCard, ab.getIdentity())
            );
            List<AnswerAndQuestionList> answerAndQuestionLists = ab.getAnswerAndQuestionList();
            for (AnswerAndQuestionList aaql : answerAndQuestionLists) {
                pushAnsweringDataMapper.insertAnswerData(classDictDO.getId(), memberDO.getId(), new Date(aaql.getQuestion()), new Date(aaql.getAnswer()));
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void post7() {

        List<RenshejuHistoryDO> renshejuHistoryDOS = renshejuHistoryMapper.dailyDatas(RenSheJuConstant.POST_7);
//        List<Long> longs = new ArrayList<Long>();
//        longs.add(5370L);
//        longs.add(5372L);
//        longs.add(5373L);
//        longs.add(5376L);
//        longs.add(5377L);
//        List<RenshejuHistoryDO> renshejuHistoryDOS = renshejuHistoryMapper.selectList(new QueryWrapper<RenshejuHistoryDO>()
//        .lambda()
//        .in(RenshejuHistoryDO::getId,longs));
        for (RenshejuHistoryDO renshejuHistoryDO : renshejuHistoryDOS) {
            String input = renshejuHistoryDO.getInputParam();
            Gson gson = new Gson();
            UploadImageDTO uploadImageDTO = gson.fromJson(input, UploadImageDTO.class);
            System.out.println(uploadImageDTO);

            ClassDictDO classDictDO = classDictMapper.selectOne(new QueryWrapper<ClassDictDO>()
                    .lambda()
                    .eq(ClassDictDO::getClassCode, uploadImageDTO.getClassCode()));

            List<ImageDetailList> imageDetailList = uploadImageDTO.getImageDetailList();
            for (ImageDetailList idl : imageDetailList) {
                MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                        .lambda()
                        .eq(MemberDO::getIdCard, idl.getIdentity())
                );
                pushImageDataMapper.pushImageData(classDictDO.getId(), idl.getDetectionType(), memberDO.getId(), idl.getProcessType(), new Date(idl.getActivityTime()));
            }
        }
    }

    public void sendWarning() {

        HashMap<String, List<Long>> hashMap = new HashMap();

        //视频
        List<Long> vodList = pushVodDataMapper.vodIds();


        //答疑
        List<Long> answerList = pushAnsweringDataMapper.answerList();

        //考试
        List<Long> examList = pushExerciseDataMapper.examList();

        //活跃度
        List<Long> activityList = pushDetectionDataMapper.activityList();

        //人脸
        List<Long> imageList = pushImageDataMapper.imageList();

        if (vodList.size()+answerList.size()+examList.size()+activityList.size()+imageList.size()>0){
            List<String> telephones = Arrays.asList(new String[]{"15201936167", "18201963812"});
            for (String telephone : telephones) {
                smsUtils.sendWarning("SMS_460945631", telephone, null);
            }
        }

    }



    public HashMap<String, List<Long>> check() {

        HashMap<String, List<Long>> hashMap = new HashMap();

        //视频
        List<Long> vodList = pushVodDataMapper.vodIds();
        hashMap.put("视频", vodList);

        //答疑
        List<Long> answerList = pushAnsweringDataMapper.answerList();
        hashMap.put("答疑", answerList);

        //考试
        List<Long> examList = pushExerciseDataMapper.examList();
        hashMap.put("考试", examList);

        //活跃度
        List<Long> activityList = pushDetectionDataMapper.activityList();
        hashMap.put("活跃度", activityList);

        //人脸
        List<Long> imageList = pushImageDataMapper.imageList();
        hashMap.put("人脸", imageList);

        return hashMap;
    }
}