500 컬러 데이터 인터페이스
11192 단어 500 인터페이스
package org.framework.task.lottery;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.framework.constants.LotteryTemp;
import org.framework.core.http.HttpClient;
import org.framework.core.util.DateUtils;
import org.framework.task.xml.XmlReader;
import org.framework.web.entity.ProductQuery;
import org.framework.web.service.LotteryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
* https://kaijiang.500.com/index3.shtml
*
* @author: [email protected]
* @date: 2017/12/11 22:28
*/
@Component
public class CaiPiao500Task {
protected Logger logger = Logger.getLogger(CaiPiao500Task.class);
private static final String BASE_URL = "http://kaijiang.500.com";
@Autowired
private HttpClient httpClient;
@Autowired
public LotteryService lotteryService;
@Value("${product}")
private String product;
@Scheduled(cron = "0/10 * * * * ?")
public void lotteryProc() throws Exception {
if ("false".equals(product)) {
return;
}
//http://kaijiang.500.com/static/info/kaijiang/xml/shdsyxw/newlyopen.xml
//Element eleXuan5 = tbody.get(14); // 11 5
XmlReader eleXuan5 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/shdsyxw/newlyopen.xml", null), LotteryTemp.SD_11_5);
updatProductQuery(eleXuan5);
//http://kaijiang.500.com/static/info/kaijiang/xml/dlc/newlyopen.xml
//Element jx11xuan5 = tbody.get(13); // 11 5
XmlReader jx11xuan5 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/dlc/newlyopen.xml", null), LotteryTemp.JX_11_5);
updatProductQuery(jx11xuan5);
//http://kaijiang.500.com/static/info/kaijiang/xml/gdsyxw/newlyopen.xml
//Element gd11xuan5 = tbody.get(18);// 11 5
XmlReader gd11xuan5 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/gdsyxw/newlyopen.xml", null), LotteryTemp.GD_11_5);
updatProductQuery(gd11xuan5);
//http://kaijiang.500.com/static/info/kaijiang/xml/hljsyxw/newlyopen.xml
//Element hlj11xuan5 = tbody.get(7);// [ 11 5]
XmlReader hlj11xuan5 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/hljsyxw/newlyopen.xml", null), LotteryTemp.HLJ_11_5);
updatProductQuery(hlj11xuan5);
//http://kaijiang.500.com/static/info/kaijiang/xml/zjsyxw/newlyopen.xml
//Element zj11xuan5 = tbody.get(10); // [ 11 5]
XmlReader zj11xuan5 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/zjsyxw/newlyopen.xml", null), LotteryTemp.ZJ_11_5);
updatProductQuery(zj11xuan5);
//Element ln11xuan5 = tbody.get(10); // 11 5
XmlReader ln11xuan5 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/lnsyxw/newlyopen.xml", null), LotteryTemp.LN_11_5);
updatProductQuery(ln11xuan5);
/*Element kuai3 = trs.get(5);*/
//http://kaijiang.500.com/static/info/kaijiang/xml/jsk3/newlyopen.xml
//Element jskuai3 = tbody.get(9); // [ 3]
XmlReader jskuai3 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/jsk3/newlyopen.xml", null), LotteryTemp.JS_KUAI_3);
updatProductQuery(jskuai3);
//http://kaijiang.500.com/static/info/kaijiang/xml/gxk3/newlyopen.xml
//Element gxkuai3 = tbody.get(19); //
XmlReader gxkuai3 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/gxk3/newlyopen.xml", null), LotteryTemp.GX_KUAI_3);
updatProductQuery(gxkuai3);
//http://kaijiang.500.com/static/info/kaijiang/xml/hbk3/newlyopen.xml
//Element hbkuai3 = tbody.get(16); //
XmlReader hbkuai3 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/hbk3/newlyopen.xml", null), LotteryTemp.HB_KUAI_3);
updatProductQuery(hbkuai3);
//http://kaijiang.500.com/static/info/kaijiang/xml/nmgk3/newlyopen.xml
//Element nmgkuai3 = tbody.get(4); //
XmlReader nmgkuai3 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/nmgk3/newlyopen.xml", null), LotteryTemp.NMG_KUAI_3);
updatProductQuery(nmgkuai3);
//http://kaijiang.500.com/static/info/kaijiang/xml/ahk3/newlyopen.xml
//Element ahkuai3 = tbody.get(11); //
XmlReader ahkuai3 = xmlReader(httpClient.getExchange(BASE_URL + "/static/info/kaijiang/xml/ahk3/newlyopen.xml", null), LotteryTemp.AH_KUAI_3);
updatProductQuery(ahkuai3);
//http://kaijiang.500.com/static/public/ssc/xml/newlyopen.xml
//Element cqssc = tbody.get(20).getElementsByTag("tr").get(0);//
XmlReader cqssc = xmlReader(httpClient.getExchange(BASE_URL + "/static/public/ssc/xml/newlyopen.xml", null), LotteryTemp.CQ_SSC);
updatProductQuery(cqssc);
//http://kaijiang.500.com/static/info/kaijiang/xml/ynssc/newlyopen.xml
XmlReader ynssc = xmlReader(httpClient.getExchange(BASE_URL+"/static/info/kaijiang/xml/ynssc/newlyopen.xml" , null) , LotteryTemp.YN_SSC);
updatProductQuery(ynssc);
//http://kaijiang.500.com/static/info/kaijiang/xml/tjssc/newlyopen.xml
XmlReader tjssc = xmlReader(httpClient.getExchange(BASE_URL+"/static/info/kaijiang/xml/tjssc/newlyopen.xml" , null) , LotteryTemp.TJ_SSC);
tjssc.setExpect(tjssc.getExpect().substring(2,11));
updatProductQuery(tjssc);
//http://kaijiang.500.com/static/info/kaijiang/xml/xjssc/newlyopen.xml
XmlReader xjssc = xmlReader(httpClient.getExchange(BASE_URL+"/static/info/kaijiang/xml/xjssc/newlyopen.xml" , null) , LotteryTemp.XJ_SSC);
xjssc.setExpect(DateUtils.getYear()+xjssc.getExpect());
xjssc.setExpect(xjssc.getExpect().substring(2,11));
xjssc.setExpect(xjssc.getExpect().substring(0,6)+xjssc.getExpect().substring(7,9));
updatProductQuery(xjssc);
//http://kaijiang.500.com/static/info/kaijiang/xml/bjpkshi/newlyopen.xml PK10
XmlReader bjpk10 = xmlReader(httpClient.getExchange(BASE_URL+"/static/info/kaijiang/xml/bjpkshi/newlyopen.xml" , null) , LotteryTemp.BJ_PK10);
updatProductQuery(bjpk10);
}
public void updatProductQuery(XmlReader xmlReader) {
ProductQuery pq = new ProductQuery();
pq.setUts(new Date());
pq.setSpell(xmlReader.getSpell());
pq.setLotteryNo(xmlReader.getExpect());
//500
pq.setFrom(3);
pq.setLotteryNums(xmlReader.getOpencode());
try {
lotteryService.updateProductQuery(pq);
} catch (Exception e) {
e.printStackTrace();
}
}
private XmlReader xmlReader(String text, String spell) throws DocumentException {
XmlReader xmlReader = new XmlReader();
Document document = DocumentHelper.parseText(text);
Element row = document.getRootElement().element("row");
String expect = row.attributeValue("expect");
switch (spell) {
case LotteryTemp.CQ_SSC:
expect = expect.substring(2, expect.length());
break;
case LotteryTemp.GX_KUAI_3:
expect = DateUtils.formatDate().substring(0, 2) + expect;
break;
case LotteryTemp.LN_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.HLJ_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.ZJ_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.JX_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.SD_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.GD_11_5:
expect = expect.replaceAll("-", "");
break;
default:
break;
}
xmlReader.setExpect(expect);
xmlReader.setOpencode(arrayToStr(row.attributeValue("opencode").split(",")));
xmlReader.setSpell(spell);
return xmlReader;
}
private String arrayToStr(String[] array) {
StringBuffer sbf = new StringBuffer();
for (String str : array) {
sbf.append(str);
}
return sbf.toString();
}
private void getXml(String date) throws DocumentException {
String url = "http://kaijiang.500.com/static/info/kaijiang/xml/zjsyxw/" + date + ".xml";
String spell = LotteryTemp.ZJ_11_5;
String text = httpClient.getExchange(url, null);
try {
Document document = DocumentHelper.parseText(text);
Element element = document.getRootElement();
logger.info(element);
List elements = element.elements();
logger.info(elements.size());
XmlReader xmlReader = null;
for (Element element1 : elements) {
xmlReader = new XmlReader();
String expect = element1.attributeValue("expect");
switch (spell) {
case LotteryTemp.CQ_SSC:
expect = expect.substring(2, expect.length());
break;
case LotteryTemp.GX_KUAI_3:
expect = DateUtils.formatDate().substring(0, 2) + expect;
break;
case LotteryTemp.LN_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.HLJ_11_5:
expect = expect.replaceAll("-", "");
break;
case LotteryTemp.ZJ_11_5:
expect = expect.replaceAll("-", "");
break;
default:
break;
}
xmlReader.setExpect(expect);
xmlReader.setOpencode(arrayToStr(element1.attributeValue("opencode").split(",")));
this.updatProductQuery(xmlReader);
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
}