123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package com.chinacreator.process.job;
- import java.net.URLEncoder;
- import java.util.List;
- import java.util.concurrent.CountDownLatch;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.LinkedBlockingQueue;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
- import org.apache.log4j.Logger;
- import org.quartz.DisallowConcurrentExecution;
- import org.quartz.PersistJobDataAfterExecution;
- import org.springframework.beans.factory.annotation.Autowired;
- import com.chinacreator.process.dao.ActiveMango3Dao;
- import com.chinacreator.process.dao.ActiveMango3JSDao;
- import com.chinacreator.process.util.DesUtil;
- import com.chinacreator.process.util.SHAUtil;
- import com.chinacreator.process.util.URLUtil;
- @PersistJobDataAfterExecution
- @DisallowConcurrentExecution
- public class ActiveMango3JSJob {
- private static Logger log = Logger.getLogger(ActiveMango3JSJob.class);
-
- @Autowired
- private ActiveMango3JSDao dao;
-
-
- public void doProcess() throws Exception {
- log.info("开始查询参加过芒果3天活动");
- List<String> list = null;
- long stime = System.currentTimeMillis();
-
- try {
- list = dao.queryNeedSmsDeal();
- log.info("需要芒果3天活动===="+(list == null ? 0 : list.size()));
- if(list != null && list.size() > 0){
- CountDownLatch threadSignal = new CountDownLatch(list.size());
- ExecutorService executorService = new ThreadPoolExecutor(8, 15, 10L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy());
- for (String userid : list) {
- ActiveMango3JSService fakeidService = new ActiveMango3JSService(list.size(),threadSignal,userid,dao);
- executorService.execute(fakeidService);
- }
- executorService.shutdown();
- try {
- executorService.awaitTermination(1L, TimeUnit.MINUTES);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- log.info("电商伪码查询结束===="+((System.currentTimeMillis())-stime));
- }
-
-
- }
- class ActiveMango3JSService implements Runnable {
-
- private static Logger logger = Logger.getLogger(ActiveMango3JSService.class);
- private int totalSize;
- private CountDownLatch threadSignal;
- private String userid;
- private ActiveMango3JSDao dao;
-
-
- public ActiveMango3JSService(int totalSize,CountDownLatch threadSignal,String userid,ActiveMango3JSDao dao){
- this.totalSize = totalSize;
- this.threadSignal = threadSignal;
- this.userid = userid;
- this.dao = dao;
- }
-
- public void run() {
- long startime = System.currentTimeMillis();
-
- try {
- boolean flag = this.dao.queryOrderRelation16(userid);
- if(!flag) {
- try {
- String smsid="5003102";
- String key= "soews92d";
- String baseurl ="http://111.206.133.54/smsbusi/sms/send";
- String content = "【中国联通】"+this.userid+",您的芒果TV会员即将到期。订购芒果TV定向流量会员包继续享受会员权益,还可免流看视频,同时还有759元惊喜大礼包等您来拿。快来点击订购吧 https://v.wo.cn/mg16hd20";
- String timestamp = System.currentTimeMillis()/1000+"";
-
- String usermob = DesUtil.encode(userid, key);
- String sign = SHAUtil.shaEncode(smsid+usermob+timestamp+content+key).toLowerCase();
-
- usermob = URLEncoder.encode(usermob,"utf-8");
- content = URLEncoder.encode(content,"utf-8");
- String url = baseurl + "?userid="+usermob+"&smsid="+smsid+"×tamp="+timestamp+"&sign="+sign+"&content="+content;
- String resp = URLUtil.get(url);
-
- System.out.println(url+","+resp);
-
- dao.sendSmsSuccess(this.userid);
- } catch (Exception e) {
- e.printStackTrace();
-
- dao.sendSmsfail(this.userid);
- }
- }else {
- dao.sendSmsNot(this.userid);
- }
- } catch (Exception e) {
- e.printStackTrace();
-
- dao.sendSmsExeception(this.userid);
- }
-
-
- threadSignal.countDown();
- logger.info("["+this.userid+"],["+ totalSize+"/"+(totalSize - threadSignal.getCount())+"],花费时间:"+(System.currentTimeMillis()-startime+"/ms"));
- }
- }
-
|