SendFaceBatchTask2.java 3.6 KB
package com.example.dahua.async;

import com.example.dahua.bean.StudentBean;
import com.example.dahua.bean.UserInfoBean;
import com.example.dahua.dao.UserDao;
import com.example.dahua.utils.DateFormatUtil;
import com.example.dahua.xiananDao.SearchMapper;
import com.example.dahua.xiananDao.SendRecordDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;

/**
 * 多线程执行卡下发
 * @author xuquan
 * @date 2021/01/12 15:56
 */
@Slf4j
public class SendFaceBatchTask2 implements Runnable {


    CountDownLatch begin;
    CountDownLatch end;
    UserDao userDao;
    SendRecordDao sendRecordDao;
    SearchMapper searchMapper;
    Integer schoolId;
    Integer roomId;
    Integer type;
    Integer outof;
    String intime;
    String clintId;
    String startTime;
    String endTime;

    public SendFaceBatchTask2(UserDao userDao, SendRecordDao sendRecordDao, SearchMapper searchMapper, Integer schoolId, Integer roomId,
                              Integer type, Integer outof, String intime, String clintId, String startTime, String endTime, CountDownLatch begin, CountDownLatch end){
        this.begin=begin;
        this.end=end;
        this.userDao=userDao;
        this.sendRecordDao=sendRecordDao;
        this.searchMapper=searchMapper;
        this.schoolId=schoolId;
        this.roomId=roomId;
        this.type= type;
        this.outof=outof;
        this.intime=intime;
        this.clintId=clintId;
        this.startTime=startTime;
        this.endTime=endTime;
    }

    @Override
    public void run() {
        try {
            begin.await();
            int num= (int)(Math.random()*50)+150;
            List<StudentBean> studentIds = userDao.getStudentList(schoolId,1,null);
            if(!CollectionUtils.isEmpty(studentIds)){
                System.out.println("总数:"+studentIds.size());
                for(int i=0;i<=studentIds.size();i++){
                    if(i==num){
                        return;
                    }
                    String cardNum = studentIds.get(i).getStudent_num();
                    String userId = studentIds.get(i).getUser_id();
                    String com = studentIds.get(i).getStudent_id();
                    String classId = studentIds.get(i).getClass_id();
                    String className = studentIds.get(i).getClass_name();
                    String name= studentIds.get(i).getName();
                    String mobile= studentIds.get(i).getParentMobile();
                    String sex = String.valueOf(studentIds.get(i).getSex());
                    String cid= UUID.randomUUID().toString().toUpperCase();
                    int count = sendRecordDao.getKaoQin(schoolId,cardNum,type,outof,startTime,endTime);;
                    System.out.println("count: "+count);
                    System.out.println("cardNum "+cardNum);
                    if(count ==0){
                        intime = DateFormatUtil.getDateAdd(intime);
                        searchMapper.insert(userId,String.valueOf(schoolId),com,cardNum,type,outof,intime,cid,classId,clintId,name,mobile,className,sex,intime);
                        i++;
                    }
                }
            }
        }catch (Exception e){
            log.error("异常,信息:",e);
        }finally {
            end.countDown();
        }
    }

    public static void main(String[] args) {
        for(int i=1;i<20;i++){
            int num= (int)(Math.random()*50)+150;
//            int num= (int)(Math.random()*20)+30;
            System.out.println(num);
        }
    }

}