|
@@ -175,10 +175,18 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
|
@Override
|
|
|
public String test(String param, String param1) throws Exception {
|
|
|
- ExecutorService pool = Executors.newFixedThreadPool(2);
|
|
|
- ThreadPool threadPool = new ThreadPool(2);
|
|
|
- pool.execute(threadPool);
|
|
|
- pool.shutdown();
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ doSomething1();
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ doSomething2();
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
// try{
|
|
|
// List<ShopOrder> shopOrders = shopOrderMapper.selectList(new EntityWrapper<ShopOrder>()
|
|
|
// .eq("dang_order_status","未发货")
|
|
@@ -489,226 +497,183 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
-
|
|
|
- class ThreadPool implements Runnable {
|
|
|
-
|
|
|
- /*
|
|
|
- * 创建步骤如下:
|
|
|
- * 1,定义Runnable接口的实现类,或者定义(继承Runnable接口的类)的实现类,并且实现run方法,这个方法是线程执行体
|
|
|
- * 2,创建一个自定义线程个数的线程池
|
|
|
- * 3,实例化Runnable接口的实现类
|
|
|
- * 4,将3步的实例,作为线程池实例的execute方法的command参数,开启线程
|
|
|
- * 5,关闭线程池
|
|
|
- *
|
|
|
- * 调用示例:
|
|
|
- * ExecutorService pool = Executors.newFixedThreadPool(2);
|
|
|
- * ThreadPool threadPool = new ThreadPool("AA");
|
|
|
- * ThreadPool threadPoo2 = new ThreadPool("BB");
|
|
|
- * pool.execute(threadPool);
|
|
|
- * pool.execute(threadPoo2);
|
|
|
- * pool.shutdown();
|
|
|
- *
|
|
|
- * 说明:
|
|
|
- * 示例中创建的是2个线程的线程池
|
|
|
- * execute方法是开启线程方法,实参要求是实现Runnable的类。所以,继承Thread类的子类也可以以线程池的方式开启线程
|
|
|
- *
|
|
|
- * */
|
|
|
- public Integer flag;
|
|
|
- public ThreadPool(Integer flag) {
|
|
|
- this.flag = flag;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if(flag == 1){
|
|
|
- doSomething1();
|
|
|
- }
|
|
|
- else{
|
|
|
- doSomething2();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 需要处理的任务
|
|
|
- * */
|
|
|
- private void doSomething1() {
|
|
|
- try{
|
|
|
- List<ShopAccount> list = shopAccountMapper.selectList(new EntityWrapper<>());
|
|
|
- for (ShopAccount shopAccount:list
|
|
|
- ) {
|
|
|
- flushCookie(shopAccount);
|
|
|
- List<ShopOrder> shopOrders = shopOrderMapper.selectList(new EntityWrapper<ShopOrder>()
|
|
|
- .eq("dang_order_status","未发货")
|
|
|
- .eq("account_id",shopAccount.getId())
|
|
|
- .eq("order_status_name","卖家已发货"));
|
|
|
- for (ShopOrder qqq:shopOrders
|
|
|
- ) {
|
|
|
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
- HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=1&pageShow=9999&orderId="+qqq.getOrderId());
|
|
|
- //这里可以设置请求参数,token等
|
|
|
- get.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
|
- get.addHeader("cookie",shopAccount.getFuziCookie());
|
|
|
- get.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
- CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
- try{
|
|
|
-
|
|
|
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){//根据状态码处理
|
|
|
- String strTmp= EntityUtils.toString(response.getEntity(),"UTF-8");
|
|
|
- //返回字符串
|
|
|
- String res = unicodeToString(strTmp);
|
|
|
- JSONObject datas = JSONObject.parseObject(res);//转换成JSON格式
|
|
|
- Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
|
- List<ShopOrder> data = JSONArray.parseArray(datas.get("data").toString(),ShopOrder.class);//"data"是根据返回值设定
|
|
|
- for (ShopOrder tmp: data
|
|
|
+ private void doSomething1() {
|
|
|
+ try{
|
|
|
+ List<ShopAccount> list = shopAccountMapper.selectList(new EntityWrapper<>());
|
|
|
+ for (ShopAccount shopAccount:list
|
|
|
+ ) {
|
|
|
+ flushCookie(shopAccount);
|
|
|
+ List<ShopOrder> shopOrders = shopOrderMapper.selectList(new EntityWrapper<ShopOrder>()
|
|
|
+ .eq("dang_order_status","未发货")
|
|
|
+ .eq("account_id",shopAccount.getId())
|
|
|
+ .eq("order_status_name","卖家已发货"));
|
|
|
+ for (ShopOrder qqq:shopOrders
|
|
|
+ ) {
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=1&pageShow=9999&orderId="+qqq.getOrderId());
|
|
|
+ //这里可以设置请求参数,token等
|
|
|
+ get.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
|
+ get.addHeader("cookie",shopAccount.getFuziCookie());
|
|
|
+ get.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
+ CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
+ try{
|
|
|
+
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){//根据状态码处理
|
|
|
+ String strTmp= EntityUtils.toString(response.getEntity(),"UTF-8");
|
|
|
+ //返回字符串
|
|
|
+ String res = unicodeToString(strTmp);
|
|
|
+ JSONObject datas = JSONObject.parseObject(res);//转换成JSON格式
|
|
|
+ Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
|
+ List<ShopOrder> data = JSONArray.parseArray(datas.get("data").toString(),ShopOrder.class);//"data"是根据返回值设定
|
|
|
+ for (ShopOrder tmp: data
|
|
|
+ ) {
|
|
|
+ //正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串
|
|
|
+ String regEx="[^0-9]+";
|
|
|
+ Pattern pattern = Pattern.compile(regEx);
|
|
|
+ //用定义好的正则表达式拆分字符串,把字符串中的数字留出来
|
|
|
+ String[] cs = pattern.split(tmp.getRemarkText());
|
|
|
+ String dangOrder = "";
|
|
|
+ for (String str:cs
|
|
|
) {
|
|
|
- //正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串
|
|
|
- String regEx="[^0-9]+";
|
|
|
- Pattern pattern = Pattern.compile(regEx);
|
|
|
- //用定义好的正则表达式拆分字符串,把字符串中的数字留出来
|
|
|
- String[] cs = pattern.split(tmp.getRemarkText());
|
|
|
- String dangOrder = "";
|
|
|
- for (String str:cs
|
|
|
- ) {
|
|
|
- if(dangOrder.length()>= 11 || str.equals("*")){
|
|
|
- break;
|
|
|
- }
|
|
|
- dangOrder += str;
|
|
|
+ if(dangOrder.length()>= 11 || str.equals("*")){
|
|
|
+ break;
|
|
|
}
|
|
|
- tmp.setDangOrder(dangOrder);
|
|
|
- tmp.setAccountId(shopAccount.getId());
|
|
|
- Long time = Long.parseLong(tmp.getShippingTime());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
- String time1 = sdf.format(new Date(time * 1000));
|
|
|
- tmp.setShippingTime(time1);
|
|
|
- tmp.setDeleteFlag(0);
|
|
|
- tmp.setGmtUpdate(new Date());
|
|
|
- tmp.setGmtCreate(new Date());
|
|
|
- if(tmp.getShippingComName().equals("快递包裹")||tmp.getShippingComName().equals("挂号印刷品")){
|
|
|
- tmp.setShippingComName("中国邮政");
|
|
|
- }
|
|
|
- ShopOrder tt = new ShopOrder();
|
|
|
- tt.setOrderId(tmp.getOrderId());
|
|
|
- tt = shopOrderMapper.selectOne(tt);
|
|
|
- if(tt == null){
|
|
|
- shopOrderMapper.insert(tmp);
|
|
|
- }
|
|
|
- else{
|
|
|
- if(!tt.getDangOrder().equals(tmp.getDangOrder())||!tt.getShippingComName().equals(tmp.getShippingComName())){
|
|
|
- shopOrderMapper.update(tmp,new EntityWrapper<ShopOrder>().eq("order_id",tt.getOrderId()));
|
|
|
- }
|
|
|
- dangOrderDeal(shopAccount,qqq);
|
|
|
+ dangOrder += str;
|
|
|
+ }
|
|
|
+ tmp.setDangOrder(dangOrder);
|
|
|
+ tmp.setAccountId(shopAccount.getId());
|
|
|
+ Long time = Long.parseLong(tmp.getShippingTime());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
+ String time1 = sdf.format(new Date(time * 1000));
|
|
|
+ tmp.setShippingTime(time1);
|
|
|
+ tmp.setDeleteFlag(0);
|
|
|
+ tmp.setGmtUpdate(new Date());
|
|
|
+ tmp.setGmtCreate(new Date());
|
|
|
+ if(tmp.getShippingComName().equals("快递包裹")||tmp.getShippingComName().equals("挂号印刷品")){
|
|
|
+ tmp.setShippingComName("中国邮政");
|
|
|
+ }
|
|
|
+ ShopOrder tt = new ShopOrder();
|
|
|
+ tt.setOrderId(tmp.getOrderId());
|
|
|
+ tt = shopOrderMapper.selectOne(tt);
|
|
|
+ if(tt == null){
|
|
|
+ shopOrderMapper.insert(tmp);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ if(!tt.getDangOrder().equals(tmp.getDangOrder())||!tt.getShippingComName().equals(tmp.getShippingComName())){
|
|
|
+ shopOrderMapper.update(tmp,new EntityWrapper<ShopOrder>().eq("order_id",tt.getOrderId()));
|
|
|
}
|
|
|
+ dangOrderDeal(shopAccount,qqq);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- } catch (IOException e) {
|
|
|
- throw e;
|
|
|
- }
|
|
|
- finally {
|
|
|
- response.close();
|
|
|
- httpClient.close();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ response.close();
|
|
|
+ httpClient.close();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception e) {
|
|
|
- ShopLog shopLog = new ShopLog();
|
|
|
- shopLog.setGmtCreate(new Date());
|
|
|
- shopLog.setTitle("同步定时任务异常");
|
|
|
- shopLog.setContent(e.getMessage());
|
|
|
- shopLogMapper.insert(shopLog);
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- private void doSomething2() {
|
|
|
- try{
|
|
|
- List<ShopAccount> list = shopAccountMapper.selectList(new EntityWrapper<>());
|
|
|
- for (ShopAccount shopAccount:list
|
|
|
- ) {
|
|
|
- flushCookie(shopAccount);
|
|
|
- for (int i = 1; i <= 5; i++) {
|
|
|
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
- HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=" + i + "&pageShow=300&orderStatus=ShippedToReceipt");
|
|
|
- //这里可以设置请求参数,token等
|
|
|
- get.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
|
- get.addHeader("cookie", shopAccount.getFuziCookie());
|
|
|
-
|
|
|
- CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
- try {
|
|
|
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {//根据状态码处理
|
|
|
- String strTmp = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
- //返回字符串
|
|
|
- String res = unicodeToString(strTmp);
|
|
|
- JSONObject datas = JSONObject.parseObject(res);//转换成JSON格式
|
|
|
- Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
|
- List<ShopOrder> data = JSONArray.parseArray(datas.get("data").toString(), ShopOrder.class);//"data"是根据返回值设定
|
|
|
- if (data.size() == 0) {
|
|
|
- break;
|
|
|
- }
|
|
|
- for (ShopOrder tmp : data
|
|
|
+ catch (Exception e) {
|
|
|
+ ShopLog shopLog = new ShopLog();
|
|
|
+ shopLog.setGmtCreate(new Date());
|
|
|
+ shopLog.setTitle("同步定时任务异常");
|
|
|
+ shopLog.setContent(e.getMessage());
|
|
|
+ shopLogMapper.insert(shopLog);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void doSomething2() {
|
|
|
+ try{
|
|
|
+ List<ShopAccount> list = shopAccountMapper.selectList(new EntityWrapper<>());
|
|
|
+ for (ShopAccount shopAccount:list
|
|
|
+ ) {
|
|
|
+ flushCookie(shopAccount);
|
|
|
+ for (int i = 1; i <= 5; i++) {
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=" + i + "&pageShow=300&orderStatus=ShippedToReceipt");
|
|
|
+ //这里可以设置请求参数,token等
|
|
|
+ get.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
|
+ get.addHeader("cookie", shopAccount.getFuziCookie());
|
|
|
+
|
|
|
+ CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
+ try {
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {//根据状态码处理
|
|
|
+ String strTmp = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
+ //返回字符串
|
|
|
+ String res = unicodeToString(strTmp);
|
|
|
+ JSONObject datas = JSONObject.parseObject(res);//转换成JSON格式
|
|
|
+ Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
|
+ List<ShopOrder> data = JSONArray.parseArray(datas.get("data").toString(), ShopOrder.class);//"data"是根据返回值设定
|
|
|
+ if (data.size() == 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (ShopOrder tmp : data
|
|
|
+ ) {
|
|
|
+ //正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串
|
|
|
+ String regEx = "[^0-9]+";
|
|
|
+ Pattern pattern = Pattern.compile(regEx);
|
|
|
+ //用定义好的正则表达式拆分字符串,把字符串中的数字留出来
|
|
|
+ String[] cs = pattern.split(tmp.getRemarkText());
|
|
|
+ String dangOrder = "";
|
|
|
+ for (String str : cs
|
|
|
) {
|
|
|
- //正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串
|
|
|
- String regEx = "[^0-9]+";
|
|
|
- Pattern pattern = Pattern.compile(regEx);
|
|
|
- //用定义好的正则表达式拆分字符串,把字符串中的数字留出来
|
|
|
- String[] cs = pattern.split(tmp.getRemarkText());
|
|
|
- String dangOrder = "";
|
|
|
- for (String str : cs
|
|
|
- ) {
|
|
|
- if (dangOrder.length() >= 11 || str.equals("*")) {
|
|
|
- break;
|
|
|
- }
|
|
|
- dangOrder += str;
|
|
|
- }
|
|
|
- tmp.setDangOrder(dangOrder);
|
|
|
- tmp.setAccountId(shopAccount.getId());
|
|
|
- Long time = Long.parseLong(tmp.getShippingTime());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
- String time1 = sdf.format(new Date(time * 1000));
|
|
|
- tmp.setShippingTime(time1);
|
|
|
- tmp.setDeleteFlag(0);
|
|
|
- tmp.setGmtUpdate(new Date());
|
|
|
- tmp.setGmtCreate(new Date());
|
|
|
- if (tmp.getShippingComName().equals("快递包裹") || tmp.getShippingComName().equals("挂号印刷品")) {
|
|
|
- tmp.setShippingComName("中国邮政");
|
|
|
+ if (dangOrder.length() >= 11 || str.equals("*")) {
|
|
|
+ break;
|
|
|
}
|
|
|
- ShopOrder tt = new ShopOrder();
|
|
|
- tt.setOrderId(tmp.getOrderId());
|
|
|
- tt = shopOrderMapper.selectOne(tt);
|
|
|
- if (tt == null) {
|
|
|
- shopOrderMapper.insert(tmp);
|
|
|
- } else {
|
|
|
- if (tt.getDangOrderStatus().equals("未发货") && !tt.getDangOrder().equals(tmp.getDangOrder())) {
|
|
|
- shopOrderMapper.update(tmp, new EntityWrapper<ShopOrder>().eq("order_id", tt.getOrderId()));
|
|
|
- }
|
|
|
+ dangOrder += str;
|
|
|
+ }
|
|
|
+ tmp.setDangOrder(dangOrder);
|
|
|
+ tmp.setAccountId(shopAccount.getId());
|
|
|
+ Long time = Long.parseLong(tmp.getShippingTime());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
+ String time1 = sdf.format(new Date(time * 1000));
|
|
|
+ tmp.setShippingTime(time1);
|
|
|
+ tmp.setDeleteFlag(0);
|
|
|
+ tmp.setGmtUpdate(new Date());
|
|
|
+ tmp.setGmtCreate(new Date());
|
|
|
+ if (tmp.getShippingComName().equals("快递包裹") || tmp.getShippingComName().equals("挂号印刷品")) {
|
|
|
+ tmp.setShippingComName("中国邮政");
|
|
|
+ }
|
|
|
+ ShopOrder tt = new ShopOrder();
|
|
|
+ tt.setOrderId(tmp.getOrderId());
|
|
|
+ tt = shopOrderMapper.selectOne(tt);
|
|
|
+ if (tt == null) {
|
|
|
+ shopOrderMapper.insert(tmp);
|
|
|
+ } else {
|
|
|
+ if (tt.getDangOrderStatus().equals("未发货") && !tt.getDangOrder().equals(tmp.getDangOrder())) {
|
|
|
+ shopOrderMapper.update(tmp, new EntityWrapper<ShopOrder>().eq("order_id", tt.getOrderId()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- throw e;
|
|
|
- } finally {
|
|
|
- response.close();
|
|
|
- httpClient.close();
|
|
|
}
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ response.close();
|
|
|
+ httpClient.close();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception e){
|
|
|
- ShopLog shopLog = new ShopLog();
|
|
|
- shopLog.setGmtCreate(new Date());
|
|
|
- shopLog.setTitle("爬取定时任务异常");
|
|
|
- shopLog.setContent(e.getMessage());
|
|
|
- shopLogMapper.insert(shopLog);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ ShopLog shopLog = new ShopLog();
|
|
|
+ shopLog.setGmtCreate(new Date());
|
|
|
+ shopLog.setTitle("爬取定时任务异常");
|
|
|
+ shopLog.setContent(e.getMessage());
|
|
|
+ shopLogMapper.insert(shopLog);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|