package com.moku;
im
port com.alibaba.fastjson.JSONObject;
im
port com.google.gson.Gson;
im
port com.moku.dao.IAppDao;
im
port com.moku.dao.ITaskDao;
im
port com.moku.model.App;
im
port com.moku.model.PktVo;
im
port com.moku.model.Task;
im
port com.moku.model.Task;
im
port com.moku.service.ICheck;
im
port com.moku.service.SendMsgService;
im
port com.moku.utils.CommonUtils;
im
port com.moku.utils.Constant;
im
port com.moku.utils.StringFormat;
im
port com.moku.utils.ThreadPoolManager;
im
port org.apache.log4j.Logger;
im
port org.springf
ramework.beans.factory.annotation.Autowired;
im
port org.springf
ramework.context.support.ClassPathXmlApplicationContext;
im
port org.springf
ramework.scheduling.annotation.Scheduled;
im
port org.springf
ramework.stereotype.Component;
im
port org.springf
ramework.util.StringUtils;
im
port java.io.IOException;
im
port java.util.ArrayList;
im
port java.util.HashMap;
im
port java.util.List;
im
port java.util.Map;
@Compo
nent("taskJob")
public class QuartzTask {
private static Logger logger = Logger.getLogger(QuartzTask.class);
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map2 = new HashMap<String, Object>();
@Autowired
private ICheck appbaoImpl;
@Autowired
private SendMsgService sendMsgService;
@Autowired
private ICheck market_360Impl;
@Autowired
private ICheck huaweiMarket;
@Autowired
private ICheck xiaoMiMarketImpl;
@Autowired
private ICheck meizuMarketImpl;
@Autowired
private ICheck baiduMarketImpl;
@Autowired
private ICheck wanDouJiaMarketImpl;
Map<String, List<PktVo>> searchList = null; //这里不能直接赋值
@Autowired
private ITaskDao dao;
@Autowired
private IAppDao appDao;
List<String> ids = new ArrayList<>();
List<PktVo> beans = new ArrayList<>();
PktVo bean = null;
private long quaryStart;
private long endquery;
private int size;
public QuartzTask() {
}
private CubbyHole cubbyhole = new CubbyHole();
@Scheduled(cron = "*/1 * * * * ?")
public void testDb() throws IOException { //3分钟查一次
//1.获取查询数据 ,这里使用了全表扫描
logger.info("...................................bbb....................................");
// searchList = getSearchList();
logger.info(" 查询请求列表耗时" + (endquery - quaryStart) / 1000 + "s");
//1.1 查询要匹配的发送记录数
for (String skuId : searchList.keySet()) {
List<PktVo> strlist = searchList.get(skuId);
// logger.info(this.getClass().getName()+strlist);
size = strlist.size();
for (PktVo pkt : strlist) {
//应用宝市场:
if (pkt.getMarket().equals("tencent")) {
productRequest(pkt);
}
//小米市场
if (pkt.getMarket().equals("xiaomi")) {
productRequest(pkt);
}
//华为市场
if (pkt.getMarket().equals("huawei")) {
productRequest(pkt);
}
//魅族市场
if (pkt.getMarket().equals("meizu")) {
productRequest(pkt);
}
//百度市场
if (pkt.getMarket().equals("baiduMobile")) { //baiduMobile
productRequest(pkt);
}
//360市场
if (pkt.getMarket().equals("360Mobile")) {
productRequest(pkt);
}
//豌豆荚市场
if (pkt.getMarket().equals("wandoujia")) {
productRequest(pkt);
}
}
}
}
public void productRequest(PktVo pkt) {
logger.info("产生请求开始");
cubbyhole.put(pkt.getSoftwareName());
logger.info("本周期内产生请求" + pkt.getSoftwareName());
}
@Scheduled(cron = "*/1 * * * * ?")
public void testTask() throws IOException {
System.out.println("1111");
if (searchList == null) {
return; // 通知生产
} else {
System.out.println("Not Null = " + JSONObject.toJSo
nString(searchList));
logger.info("消费执行");
for (int i = 0; i < size; i++) {
logger.info("开始消费" + cubbyhole.get());
//2.进行搜索,以后应考虑异步通知
doTask1();
doTask2();
// Runnable runnable = new Runnable() {
// @Override
// public void run() {
// doTask1();
// }
// };
// Runnable t2 = new Runnable() {
// @Override
// public void run() {
//
// doTask2();
// }
// };
// //这里可以考虑优先级
// ThreadPoolManager.getDefault().addExecuteTask(runnable);
// ThreadPoolManager.getDefault().addExecuteTask(t2);
}
}
}
public void doTask2() {
if (!huaweiMarket.check(cubbyhole.get())
) { //检测华为市场上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "华为应用");
}
if (!baiduMarketImpl.check(cubbyhole.get())
) { //检测百度市场上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "百度应用市场");
}
if (!market_360Impl.check(cubbyhole.get())
) { //检测360上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "360应用市场");
}
if (!wanDouJiaMarketImpl.check(cubbyhole.get())
) { //检测豌豆荚上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "豌豆荚应用市场");
}
}
public void doTask1() {
if (!appbaoImpl.check(cubbyhole.get())) { //检测应用宝上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "应用宝");
}
if (!xiaoMiMarketImpl.check(cubbyhole.get())
) { //检测小米上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "小米应用");
}
if (!meizuMarketImpl.check(cubbyhole.get())
) { //检测魅族市场上的应用下架时,通知信息
do
notifyInfo(cubbyhole.get() + "魅族应用商店");
}
}
public List getInitList(Task user) {
String dataids = user.getApps();
//去除前后的[]
String aa = CommonUtils.tri
m(dataids, "[");
String datas = CommonUtils.tri
m(aa, "]");
//截取获得字符串数组
String[] strArray = datas.split(",");
// ["123","123","123"]
// IN ("123","123","123")
for (int i = 0; i < strArray.length; i++) {
//截取前后的为引号
ids.add(strArray[i].replace(""", ""));
}
//取出
List<App> list = null;
for (int i = 0; i < ids.size(); i++) {
// System.out.println(i + ":" + ids.get(i));
List<App> app = appDao.selectUser1(ids.get(i));
for (int j = 0; j < app.size(); j++) {
//过滤高价
if (app.get(j).getApp_id().equals("9")) {
// System.out.println(app.toString());
if (list == null) {